mirror of https://github.com/rusefi/RomRaider.git
updated ramtune test app
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@653 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
012cbdce69
commit
4bd1856494
|
@ -9,11 +9,14 @@ import static enginuity.io.protocol.SSMProtocol.ECU_INIT_COMMAND;
|
|||
import static enginuity.io.protocol.SSMProtocol.HEADER;
|
||||
import static enginuity.io.protocol.SSMProtocol.READ_ADDRESS_COMMAND;
|
||||
import static enginuity.io.protocol.SSMProtocol.READ_ADDRESS_RESPONSE;
|
||||
import static enginuity.io.protocol.SSMProtocol.READ_MEMORY_COMMAND;
|
||||
import static enginuity.io.protocol.SSMProtocol.READ_MEMORY_RESPONSE;
|
||||
import static enginuity.io.protocol.SSMProtocol.REQUEST_NON_DATA_BYTES;
|
||||
import static enginuity.io.protocol.SSMProtocol.RESPONSE_NON_DATA_BYTES;
|
||||
import static enginuity.io.protocol.SSMProtocol.WRITE_MEMORY_COMMAND;
|
||||
import static enginuity.io.protocol.SSMProtocol.WRITE_MEMORY_RESPONSE;
|
||||
import enginuity.logger.ecu.exception.SerialCommunicationException;
|
||||
import static enginuity.util.ByteUtil.asInt;
|
||||
import static enginuity.util.HexUtil.asBytes;
|
||||
import static enginuity.util.HexUtil.asHex;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
|
@ -47,6 +50,8 @@ public final class TestSSMConnectionImpl implements SerialConnection {
|
|||
return asBytes(ECU_INIT_RESPONSE).length;
|
||||
} else if (isReadAddressRequest()) {
|
||||
return request.length + (RESPONSE_NON_DATA_BYTES + calculateNumResponseDataBytes());
|
||||
} else if (isReadMemoryRequest()) {
|
||||
return request.length + (RESPONSE_NON_DATA_BYTES + asInt(request[9]) + 1);
|
||||
} else if (isWriteMemoryRequest()) {
|
||||
return request.length + (RESPONSE_NON_DATA_BYTES + (request.length - 6 - ADDRESS_SIZE));
|
||||
} else {
|
||||
|
@ -64,7 +69,7 @@ public final class TestSSMConnectionImpl implements SerialConnection {
|
|||
byte[] response = asBytes("0x80F01006E83EC74A760033");
|
||||
System.arraycopy(response, 0, bytes, request.length, response.length);
|
||||
} else if (isReadAddressRequest()) {
|
||||
byte[] responseData = generateResponseData();
|
||||
byte[] responseData = generateResponseData(calculateNumResponseDataBytes());
|
||||
int i = 0;
|
||||
byte[] response = new byte[RESPONSE_NON_DATA_BYTES + calculateNumResponseDataBytes()];
|
||||
response[i++] = HEADER;
|
||||
|
@ -76,6 +81,19 @@ public final class TestSSMConnectionImpl implements SerialConnection {
|
|||
response[i += responseData.length] = calculateChecksum(response);
|
||||
System.arraycopy(request, 0, bytes, 0, request.length);
|
||||
System.arraycopy(response, 0, bytes, request.length, response.length);
|
||||
} else if (isReadMemoryRequest()) {
|
||||
byte[] responseData = generateResponseData(asInt(request[9]) + 1);
|
||||
int i = 0;
|
||||
byte[] response = new byte[RESPONSE_NON_DATA_BYTES + responseData.length];
|
||||
response[i++] = HEADER;
|
||||
response[i++] = DIAGNOSTIC_TOOL_ID;
|
||||
response[i++] = ECU_ID;
|
||||
response[i++] = (byte) (1 + responseData.length);
|
||||
response[i++] = READ_MEMORY_RESPONSE;
|
||||
System.arraycopy(responseData, 0, response, i, responseData.length);
|
||||
response[i += responseData.length] = calculateChecksum(response);
|
||||
System.arraycopy(request, 0, bytes, 0, request.length);
|
||||
System.arraycopy(response, 0, bytes, request.length, response.length);
|
||||
} else if (isWriteMemoryRequest()) {
|
||||
int numDataBytes = request.length - 6 - ADDRESS_SIZE;
|
||||
byte[] response = new byte[RESPONSE_NON_DATA_BYTES + numDataBytes];
|
||||
|
@ -123,8 +141,8 @@ public final class TestSSMConnectionImpl implements SerialConnection {
|
|||
return hex.startsWith("8010F011A8") && hex.contains("FFA6FCFFA6FDFFA6FEFFA6FF");
|
||||
}
|
||||
|
||||
private byte[] generateResponseData() {
|
||||
byte[] responseData = new byte[calculateNumResponseDataBytes()];
|
||||
private byte[] generateResponseData(int dataLength) {
|
||||
byte[] responseData = new byte[dataLength];
|
||||
for (int i = 0; i < responseData.length; i++) {
|
||||
responseData[i] = (byte) RANDOM.nextInt(255);
|
||||
}
|
||||
|
@ -140,6 +158,10 @@ public final class TestSSMConnectionImpl implements SerialConnection {
|
|||
return isCommand(READ_ADDRESS_COMMAND);
|
||||
}
|
||||
|
||||
private boolean isReadMemoryRequest() {
|
||||
return isCommand(READ_MEMORY_COMMAND);
|
||||
}
|
||||
|
||||
private boolean isWriteMemoryRequest() {
|
||||
return isCommand(WRITE_MEMORY_COMMAND);
|
||||
}
|
||||
|
|
|
@ -203,7 +203,8 @@ public final class RamTuneTestApp extends JFrame implements WindowListener {
|
|||
(String) portsComboBox.getSelectedItem());
|
||||
CommandGenerator commandGenerator = (CommandGenerator) commandComboBox.getSelectedItem();
|
||||
if (validateInput(commandGenerator) && confirmCommandExecution(commandGenerator)) {
|
||||
byte[] command = commandGenerator.createCommand(asBytes(addressField.getText()), asBytes(dataField.getText()));
|
||||
byte[] command = commandGenerator.createCommand(asBytes(addressField.getText()), asBytes(dataField.getText()),
|
||||
Integer.parseInt(lengthField.getText().trim()));
|
||||
responseField.append("SND [" + commandGenerator + "]:\t" + asHex(command) + "\n");
|
||||
byte[] result = commandExecutor.executeCommand(command);
|
||||
responseField.append("RCV [" + commandGenerator + "]:\t" + asHex(result) + "\n");
|
||||
|
@ -229,6 +230,18 @@ public final class RamTuneTestApp extends JFrame implements WindowListener {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (isReadCommandGenerator) {
|
||||
try {
|
||||
int length = Integer.parseInt(lengthField.getText().trim());
|
||||
if (length <= 0) {
|
||||
showErrorDialog("Invalid length - must be greater then zero.");
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
showErrorDialog("Invalid length.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (isWriteCommandGenerator) {
|
||||
String data = dataField.getText().trim();
|
||||
int dataLength = data.length();
|
||||
|
|
|
@ -2,5 +2,5 @@ package enginuity.ramtune.test.command.generator;
|
|||
|
||||
public interface CommandGenerator {
|
||||
|
||||
byte[] createCommand(byte[] address, byte[] data);
|
||||
byte[] createCommand(byte[] address, byte[] data, int length);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ public final class EcuInitCommandGenerator extends AbstractCommandGenerator {
|
|||
super(protocol);
|
||||
}
|
||||
|
||||
public byte[] createCommand(byte[] address, byte[] data) {
|
||||
public byte[] createCommand(byte[] address, byte[] data, int length) {
|
||||
return protocol.constructEcuInitRequest();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package enginuity.ramtune.test.command.generator;
|
||||
|
||||
import enginuity.io.protocol.Protocol;
|
||||
import static enginuity.util.ParamChecker.checkGreaterThanZero;
|
||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||
|
||||
public final class ReadCommandGenerator extends AbstractCommandGenerator {
|
||||
|
@ -9,9 +10,10 @@ public final class ReadCommandGenerator extends AbstractCommandGenerator {
|
|||
super(protocol);
|
||||
}
|
||||
|
||||
public byte[] createCommand(byte[] address, byte[] data) {
|
||||
public byte[] createCommand(byte[] address, byte[] data, int length) {
|
||||
checkNotNullOrEmpty(address, "address");
|
||||
return protocol.constructReadAddressRequest(new byte[][]{address});
|
||||
checkGreaterThanZero(length, "length");
|
||||
return length == 1 ? protocol.constructReadAddressRequest(new byte[][]{address}) : protocol.constructReadMemoryRequest(address, length);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
@ -9,7 +9,7 @@ public final class WriteCommandGenerator extends AbstractCommandGenerator {
|
|||
super(protocol);
|
||||
}
|
||||
|
||||
public byte[] createCommand(byte[] address, byte[] data) {
|
||||
public byte[] createCommand(byte[] address, byte[] data, int length) {
|
||||
checkNotNullOrEmpty(address, "address");
|
||||
checkNotNullOrEmpty(data, "data");
|
||||
return protocol.constructWriteMemoryRequest(address, data);
|
||||
|
|
Loading…
Reference in New Issue