updated ramtune test app

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@664 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
kascade 2007-04-25 09:57:33 +00:00
parent 956e9e3213
commit 97a24ecef9
9 changed files with 89 additions and 42 deletions

View File

@ -39,9 +39,11 @@ public interface Protocol {
byte[] preprocessResponse(byte[] request, byte[] response);
void checkValidEcuInitResponse(byte[] bytes) throws InvalidResponseException;
byte[] parseResponseData(byte[] processedResponse);
EcuInit parseEcuInitResponse(byte[] response);
void checkValidEcuInitResponse(byte[] processedResponse) throws InvalidResponseException;
EcuInit parseEcuInitResponse(byte[] processedResponse);
ConnectionProperties getDefaultConnectionProperties();
}

View File

@ -91,21 +91,24 @@ public final class SSMProtocol implements Protocol {
return filterRequestFromResponse(request, response);
}
public void checkValidEcuInitResponse(byte[] response) throws InvalidResponseException {
public byte[] parseResponseData(byte[] processedResponse) {
checkNotNullOrEmpty(processedResponse, "processedResponse");
return extractResponseData(processedResponse);
}
public void checkValidEcuInitResponse(byte[] processedResponse) throws InvalidResponseException {
// response_header 3_unknown_bytes 5_ecu_id_bytes readable_params_switches... checksum
// 80F01039FF A21011315258400673FACB842B83FEA800000060CED4FDB060000F200000000000DC0000551E30C0F222000040FB00E10000000000000000 59
checkNotNullOrEmpty(response, "response");
validateResponse(response);
byte responseType = response[4];
checkNotNullOrEmpty(processedResponse, "processedResponse");
validateResponse(processedResponse);
byte responseType = processedResponse[4];
if (responseType != ECU_INIT_RESPONSE) {
throw new InvalidResponseException("Unexpected ECU Init response type: " + asHex(new byte[]{responseType}));
}
}
public EcuInit parseEcuInitResponse(byte[] response) {
checkNotNullOrEmpty(response, "response");
byte[] responseData = extractResponseData(response);
return new SSMEcuInit(responseData);
public EcuInit parseEcuInitResponse(byte[] processedResponse) {
return new SSMEcuInit(parseResponseData(processedResponse));
}
public ConnectionProperties getDefaultConnectionProperties() {

View File

@ -56,6 +56,7 @@ import java.awt.event.WindowListener;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.List;
/*
* This is a test app! Use at your own risk!!
@ -203,14 +204,15 @@ public final class RamTuneTestApp extends JFrame implements WindowListener {
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
CommandExecutor commandExecutor = new CommandExecutorImpl(protocol.getDefaultConnectionProperties(),
(String) portsComboBox.getSelectedItem());
CommandExecutor commandExecutor = new CommandExecutorImpl(protocol, (String) portsComboBox.getSelectedItem());
CommandGenerator commandGenerator = (CommandGenerator) commandComboBox.getSelectedItem();
if (validateInput(commandGenerator) && confirmCommandExecution(commandGenerator)) {
byte[] command = commandGenerator.createCommand(getAddress(), getData(), getLength());
responseField.append("SND [" + commandGenerator + "]:\t" + asHex(command) + "\n");
byte[] result = commandExecutor.executeCommand(command);
responseField.append("RCV [" + commandGenerator + "]:\t" + asHex(result) + "\n");
List<byte[]> commands = commandGenerator.createCommands(getData(), getAddress(), getLength());
for (byte[] command : commands) {
responseField.append("SND [" + commandGenerator + "]:\t" + asHex(command) + "\n");
byte[] result = commandExecutor.executeCommand(command);
responseField.append("RCV [" + commandGenerator + "]:\t" + asHex(result) + "\n");
}
}
} catch (Exception ex) {
reportError(ex);

View File

@ -1,41 +1,30 @@
package enginuity.ramtune.test.command.executor;
import enginuity.io.connection.ConnectionProperties;
import enginuity.io.connection.EcuConnection;
import enginuity.io.connection.EcuConnectionImpl;
import static enginuity.util.HexUtil.asBytes;
import static enginuity.util.HexUtil.asHex;
import enginuity.io.protocol.Protocol;
import static enginuity.util.ParamChecker.checkNotNull;
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
public final class CommandExecutorImpl implements CommandExecutor {
private final ConnectionProperties connectionProperties;
private final Protocol protocol;
private final String port;
public CommandExecutorImpl(ConnectionProperties connectionProperties, String port) {
checkNotNull(connectionProperties);
public CommandExecutorImpl(Protocol protocol, String port) {
checkNotNull(protocol);
checkNotNullOrEmpty(port, "port");
this.connectionProperties = connectionProperties;
this.protocol = protocol;
this.port = port;
}
public byte[] executeCommand(byte[] command) {
EcuConnection ecuConnection = new EcuConnectionImpl(connectionProperties, port);
EcuConnection ecuConnection = new EcuConnectionImpl(protocol.getDefaultConnectionProperties(), port);
try {
byte[] result = ecuConnection.send(command);
return stripCommandHeader(result, command);
byte[] response = ecuConnection.send(command);
return protocol.parseResponseData(protocol.preprocessResponse(command, response));
} finally {
ecuConnection.close();
}
}
private byte[] stripCommandHeader(byte[] result, byte[] command) {
String resultHex = asHex(result);
String commandHex = asHex(command);
if (resultHex.startsWith(commandHex)) {
return asBytes(resultHex.replaceFirst(commandHex, ""));
} else {
return result;
}
}
}

View File

@ -1,7 +1,9 @@
package enginuity.ramtune.test.command.generator;
import java.util.List;
public interface CommandGenerator {
byte[] createCommand(byte[] address, byte[] data, int length);
List<byte[]> createCommands(byte[] data, byte[] address, int length);
}

View File

@ -2,14 +2,17 @@ package enginuity.ramtune.test.command.generator;
import enginuity.io.protocol.Protocol;
import static java.util.Arrays.asList;
import java.util.List;
public final class EcuInitCommandGenerator extends AbstractCommandGenerator {
public EcuInitCommandGenerator(Protocol protocol) {
super(protocol);
}
public byte[] createCommand(byte[] address, byte[] data, int length) {
return protocol.constructEcuInitRequest();
public List<byte[]> createCommands(byte[] data, byte[] address, int length) {
return asList(protocol.constructEcuInitRequest());
}
public String toString() {

View File

@ -4,16 +4,57 @@ import enginuity.io.protocol.Protocol;
import static enginuity.util.ParamChecker.checkGreaterThanZero;
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
import java.math.BigInteger;
import java.util.ArrayList;
import static java.util.Arrays.asList;
import java.util.List;
public final class ReadCommandGenerator extends AbstractCommandGenerator {
private static final int INCREMENT_SIZE = 32;
public ReadCommandGenerator(Protocol protocol) {
super(protocol);
}
public byte[] createCommand(byte[] address, byte[] data, int length) {
public List<byte[]> createCommands(byte[] data, byte[] address, int length) {
checkNotNullOrEmpty(address, "address");
checkGreaterThanZero(length, "length");
return length == 1 ? protocol.constructReadAddressRequest(new byte[][]{address}) : protocol.constructReadMemoryRequest(address, length);
if (length == 1) {
return asList(createCommandForAddress(address));
} else {
return createCommandsForRange(address, length);
}
}
private byte[] createCommandForAddress(byte[] address) {
return protocol.constructReadAddressRequest(new byte[][]{address});
}
private List<byte[]> createCommandsForRange(byte[] address, int length) {
List<byte[]> commands = new ArrayList<byte[]>();
byte[] readAddress = copy(address);
int i = 0;
while (i < length) {
int readLength = (length - i) > INCREMENT_SIZE ? INCREMENT_SIZE : length - i;
if (readLength == 1) {
commands.add(createCommandForAddress(readAddress));
} else {
commands.add(protocol.constructReadMemoryRequest(readAddress, readLength));
}
i += INCREMENT_SIZE;
System.arraycopy(incrementAddress(readAddress, readLength), 0, readAddress, 0, readAddress.length);
}
return commands;
}
private byte[] copy(byte[] bytes) {
byte[] bytes2 = new byte[bytes.length];
System.arraycopy(bytes, 0, bytes2, 0, bytes2.length);
return bytes2;
}
private byte[] incrementAddress(byte[] address, int increment) {
return new BigInteger(address).add(new BigInteger(String.valueOf(increment))).toByteArray();
}
public String toString() {

View File

@ -3,16 +3,19 @@ package enginuity.ramtune.test.command.generator;
import enginuity.io.protocol.Protocol;
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
import static java.util.Arrays.asList;
import java.util.List;
public final class WriteCommandGenerator extends AbstractCommandGenerator {
public WriteCommandGenerator(Protocol protocol) {
super(protocol);
}
public byte[] createCommand(byte[] address, byte[] data, int length) {
public List<byte[]> createCommands(byte[] data, byte[] address, int length) {
checkNotNullOrEmpty(address, "address");
checkNotNullOrEmpty(data, "data");
return protocol.constructWriteMemoryRequest(address, data);
return asList(protocol.constructWriteMemoryRequest(address, data));
}
public String toString() {

View File

@ -22,12 +22,14 @@
package enginuity.util;
import enginuity.newmaps.ecumetadata.Scale;
import java.nio.ByteBuffer;
@SuppressWarnings({"UnnecessaryBoxing"})
public final class ByteUtil {
private ByteUtil() {
throw new UnsupportedOperationException();
}
public static int asUnsignedInt(byte[] bytes, int endian) {