From cee496a9dfbda9d5c3c61159df6ef490263153aa Mon Sep 17 00:00:00 2001 From: rusefillc Date: Wed, 23 Nov 2022 21:19:15 -0500 Subject: [PATCH] =?UTF-8?q?Full=20Optimized=20=E2=80=93=20High=20Speed=20#?= =?UTF-8?q?4818?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactoring - nicer API --- .../java/com/rusefi/binaryprotocol/BinaryProtocol.java | 10 ++++------ .../main/java/com/rusefi/io/commands/ByteRange.java | 6 ++++++ 2 files changed, 10 insertions(+), 6 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 ace365317d..add634a467 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 @@ -13,6 +13,7 @@ import com.rusefi.config.generated.Fields; import com.rusefi.core.Pair; import com.rusefi.core.SensorCentral; import com.rusefi.io.*; +import com.rusefi.io.commands.ByteRange; import com.rusefi.io.commands.GetOutputsCommand; import com.rusefi.io.commands.HelloCommand; import com.rusefi.core.FileUtil; @@ -328,8 +329,7 @@ public class BinaryProtocol { int requestSize = Math.min(remainingSize, Fields.BLOCKING_FACTOR); byte[] packet = new byte[4]; - putShort(packet, 0, swap16(offset)); - putShort(packet, 2, swap16(requestSize)); + ByteRange.packOffsetAndSize(offset, requestSize, packet); byte[] response = executeCommand(Fields.TS_READ_COMMAND, packet, "load image offset=" + offset); @@ -422,8 +422,7 @@ public class BinaryProtocol { public static byte[] createCrcCommand(int size) { byte[] packet = new byte[4]; - putShort(packet, 0, swap16(/*offset = */ 0)); - putShort(packet, 2, swap16(size)); + ByteRange.packOffsetAndSize(0, size, packet); return packet; } @@ -477,8 +476,7 @@ public class BinaryProtocol { isBurnPending = true; byte[] packet = new byte[4 + size]; - putShort(packet, 0, swap16(ecuOffset)); - putShort(packet, 2, swap16(size)); + ByteRange.packOffsetAndSize(ecuOffset, size, packet); System.arraycopy(content, contentOffset, packet, 4, size); diff --git a/java_console/io/src/main/java/com/rusefi/io/commands/ByteRange.java b/java_console/io/src/main/java/com/rusefi/io/commands/ByteRange.java index a3a75ae26b..72941142a3 100644 --- a/java_console/io/src/main/java/com/rusefi/io/commands/ByteRange.java +++ b/java_console/io/src/main/java/com/rusefi/io/commands/ByteRange.java @@ -6,6 +6,7 @@ import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; +import static com.rusefi.binaryprotocol.IoHelper.putShort; import static com.rusefi.binaryprotocol.IoHelper.swap16; public class ByteRange { @@ -22,6 +23,11 @@ public class ByteRange { return new DataInputStream(new ByteArrayInputStream(payload, 1, payload.length - 1)); } + public static void packOffsetAndSize(int offset, int requestSize, byte[] packet) { + putShort(packet, 0, swap16(offset)); + putShort(packet, 2, swap16(requestSize)); + } + public int getOffset() { return offset; }