better TS_RESPONSE_OUT_OF_RANGE handling

This commit is contained in:
rusefillc 2022-12-17 09:37:26 -05:00
parent 850415ad6c
commit 1853142c00
1 changed files with 11 additions and 2 deletions

View File

@ -299,7 +299,7 @@ public class BinaryProtocol {
return; return;
} }
setController(image); setController(image);
log.info("Got configuration from controller."); log.info("Got configuration from controller " + size + " byte(s)");
ConnectionStatusLogic.INSTANCE.setValue(ConnectionStatusValue.CONNECTED); ConnectionStatusLogic.INSTANCE.setValue(ConnectionStatusValue.CONNECTED);
} }
@ -334,6 +334,9 @@ public class BinaryProtocol {
byte[] response = executeCommand(Fields.TS_READ_COMMAND, packet, "load image offset=" + offset); byte[] response = executeCommand(Fields.TS_READ_COMMAND, packet, "load image offset=" + offset);
if (!checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK) || response.length != requestSize + 1) { if (!checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK) || response.length != requestSize + 1) {
if (extractCode(response) == TS_RESPONSE_OUT_OF_RANGE) {
throw new IllegalStateException("TS_RESPONSE_OUT_OF_RANGE ECU/console version mismatch?");
}
String code = (response == null || response.length == 0) ? "empty" : "ERROR_CODE=" + getCode(response); String code = (response == null || response.length == 0) ? "empty" : "ERROR_CODE=" + getCode(response);
String info = response == null ? "NO RESPONSE" : (code + " length=" + response.length); String info = response == null ? "NO RESPONSE" : (code + " length=" + response.length);
log.info("readImage: ERROR UNEXPECTED Something is wrong, retrying... " + info); log.info("readImage: ERROR UNEXPECTED Something is wrong, retrying... " + info);
@ -360,7 +363,7 @@ public class BinaryProtocol {
} }
private static String getCode(byte[] response) { private static String getCode(byte[] response) {
int b = response[0] & 0xff; int b = extractCode(response);
switch (b) { switch (b) {
case TS_RESPONSE_CRC_FAILURE: case TS_RESPONSE_CRC_FAILURE:
return "CRC_FAILURE"; return "CRC_FAILURE";
@ -376,6 +379,12 @@ public class BinaryProtocol {
return Integer.toString(b); return Integer.toString(b);
} }
private static int extractCode(byte[] response) {
if (response == null || response.length < 1)
return -1;
return response[0] & 0xff;
}
private ConfigurationImage getAndValidateLocallyCached() { private ConfigurationImage getAndValidateLocallyCached() {
if (DISABLE_LOCAL_CONFIGURATION_CACHE) if (DISABLE_LOCAL_CONFIGURATION_CACHE)
return null; return null;