From 6a704897bb7249f7bd1ed73d4c9f6c59fd15129f Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 31 Jul 2020 10:26:14 -0400 Subject: [PATCH] refactoring --- .../com/rusefi/binaryprotocol/BinaryProtocol.java | 12 +++++++----- .../binaryprotocol/BinaryProtocolCommands.java | 10 +++------- .../rusefi/binaryprotocol/IncomingDataBuffer.java | 2 +- .../java/com/rusefi/io/tcp/BinaryProtocolServer.java | 4 ++-- 4 files changed, 13 insertions(+), 15 deletions(-) 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 60e9ad546e..1e9eb3582c 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 @@ -85,6 +85,8 @@ public class BinaryProtocol implements BinaryProtocolCommands { public static String findCommand(byte command) { switch (command) { + case Fields.TS_COMMAND_F: + return "PROTOCOL"; case Fields.TS_CRC_CHECK_COMMAND: return "CRC_CHECK"; case Fields.TS_BURN_COMMAND: @@ -352,10 +354,10 @@ public class BinaryProtocol implements BinaryProtocolCommands { return null; int remainingSize = image.getSize() - offset; - int requestSize = Math.min(remainingSize, BLOCKING_FACTOR); + int requestSize = Math.min(remainingSize, Fields.BLOCKING_FACTOR); byte packet[] = new byte[7]; - packet[0] = COMMAND_READ; + packet[0] = Fields.TS_READ_COMMAND; putShort(packet, 1, 0); // page putShort(packet, 3, swap16(offset)); putShort(packet, 5, swap16(requestSize)); @@ -454,9 +456,9 @@ public class BinaryProtocol implements BinaryProtocolCommands { } public void writeData(byte[] content, Integer offset, int size) { - if (size > BLOCKING_FACTOR) { - writeData(content, offset, BLOCKING_FACTOR); - writeData(content, offset + BLOCKING_FACTOR, size - BLOCKING_FACTOR); + if (size > Fields.BLOCKING_FACTOR) { + writeData(content, offset, Fields.BLOCKING_FACTOR); + writeData(content, offset + Fields.BLOCKING_FACTOR, size - Fields.BLOCKING_FACTOR); return; } diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocolCommands.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocolCommands.java index 4fcb296db4..def211dd50 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocolCommands.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/BinaryProtocolCommands.java @@ -7,17 +7,13 @@ import com.rusefi.config.generated.Fields; * 6/21/2017. */ public interface BinaryProtocolCommands { - // see BLOCKING_FACTOR in firmware code - int BLOCKING_FACTOR = Fields.BLOCKING_FACTOR; byte RESPONSE_OK = Fields.TS_RESPONSE_OK; byte RESPONSE_BURN_OK = Fields.TS_RESPONSE_BURN_OK; byte RESPONSE_COMMAND_OK = Fields.TS_RESPONSE_COMMAND_OK; - char COMMAND_PROTOCOL = 'F'; + char COMMAND_PROTOCOL = Fields.TS_COMMAND_F; // todo: make crc32CheckCommand shorted one day later - no need in 6 empty bytes char COMMAND_CRC_CHECK_COMMAND = Fields.TS_CRC_CHECK_COMMAND; - char COMMAND_PAGE = 'P'; - char COMMAND_READ = Fields.TS_READ_COMMAND; - char COMMAND_CHUNK_WRITE = 'C'; // pageChunkWrite - char COMMAND_BURN = 'B'; // burnCommand + char COMMAND_CHUNK_WRITE = Fields.TS_CHUNK_WRITE_COMMAND; + char COMMAND_BURN = Fields.TS_BURN_COMMAND; char COMMAND_GET_STRUCT = '9'; // TS_GET_STRUCT } diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java index d6a63e4417..75ed985335 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/IncomingDataBuffer.java @@ -64,7 +64,7 @@ public class IncomingDataBuffer { log.debug(loggingPrefix + "Got packet size " + packetSize); if (packetSize < 0) return null; - if (!allowLongResponse && packetSize > Math.max(BinaryProtocolCommands.BLOCKING_FACTOR, Fields.TS_OUTPUT_SIZE) + 10) + if (!allowLongResponse && packetSize > Math.max(Fields.BLOCKING_FACTOR, Fields.TS_OUTPUT_SIZE) + 10) return null; isTimeout = waitForBytes(loggingPrefix + msg + " body", start, packetSize + 4); diff --git a/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java b/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java index 6046850649..6f8e02aeeb 100644 --- a/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java +++ b/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java @@ -159,9 +159,9 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { stream.sendPacket((TS_OK + "rusEFI proxy").getBytes()); } else if (command == COMMAND_CRC_CHECK_COMMAND) { handleCrc(linkManager, stream); - } else if (command == COMMAND_PAGE) { + } else if (command == Fields.TS_PAGE_COMMAND) { stream.sendPacket(TS_OK.getBytes()); - } else if (command == COMMAND_READ) { + } else if (command == Fields.TS_READ_COMMAND) { DataInputStream dis = new DataInputStream(new ByteArrayInputStream(payload, 1, payload.length - 1)); handleRead(linkManager, dis, stream); } else if (command == Fields.TS_CHUNK_WRITE_COMMAND) {