diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java index cd74f23de6..937d84c90b 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocol.java @@ -198,7 +198,7 @@ public class BinaryProtocol { String msg = "load TS_CONFIG_VERSION"; byte[] response = executeCommand(Fields.TS_OUTPUT_COMMAND, packet, msg); - if (!checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK) || response.length != requestSize + 1) { + if (!checkResponseCode(response) || response.length != requestSize + 1) { close(); return "Failed to " + msg; } @@ -346,7 +346,7 @@ public class BinaryProtocol { 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) || response.length != requestSize + 1) { if (extractCode(response) == TS_RESPONSE_OUT_OF_RANGE) { throw new IllegalStateException("TS_RESPONSE_OUT_OF_RANGE ECU/console version mismatch?"); } @@ -427,7 +427,7 @@ public class BinaryProtocol { byte[] packet = createRequestCrcPayload(configSize); byte[] response = executeCommand(Fields.TS_CRC_CHECK_COMMAND, packet, "get CRC32"); - if (checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK) && response.length == 5) { + if (checkResponseCode(response) && response.length == 5) { ByteBuffer bb = ByteBuffer.wrap(response, 1, 4); // that's unusual - most of the protocol is LITTLE_ENDIAN bb.order(ByteOrder.BIG_ENDIAN); @@ -511,7 +511,7 @@ public class BinaryProtocol { long start = System.currentTimeMillis(); while (!isClosed && (System.currentTimeMillis() - start < Timeouts.BINARY_IO_TIMEOUT)) { byte[] response = executeCommand(Fields.TS_CHUNK_WRITE_COMMAND, packet, "writeImage"); - if (!checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK) || response.length != 1) { + if (!checkResponseCode(response) || response.length != 1) { log.error("writeData: Something is wrong, retrying..."); continue; } diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocolLogger.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocolLogger.java index 9abf5cd931..f18d1abac0 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocolLogger.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocolLogger.java @@ -100,7 +100,7 @@ public class BinaryProtocolLogger { isCompositeLoggerEnabled = true; byte[] response = binaryProtocol.executeCommand(Fields.TS_GET_COMPOSITE_BUFFER_DONE_DIFFERENTLY, "composite log"); - if (checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK)) { + if (checkResponseCode(response)) { List events = CompositeParser.parse(response); createCompositesIfNeeded(); for (StreamFile composite : compositeLogs) diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/IoHelper.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/IoHelper.java index df39b5b974..f74a4008e1 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/IoHelper.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/IoHelper.java @@ -1,6 +1,7 @@ package com.rusefi.binaryprotocol; import com.devexperts.logging.Logging; +import com.rusefi.config.generated.Fields; import com.rusefi.util.HexBinary; import java.util.zip.CRC32; @@ -67,6 +68,10 @@ public class IoHelper { packet[offset] = (byte) (value >> 8); } + public static boolean checkResponseCode(byte[] response) { + return checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK); + } + /** * @return true if packet has the expected response code */