diff --git a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java index 8ce6f23c23..8295085f72 100644 --- a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java +++ b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java @@ -96,7 +96,7 @@ public class BinaryProtocol implements BinaryProtocolCommands { public boolean isClosed; /** * Snapshot of current gauges status - * @see BinaryProtocolCommands#COMMAND_OUTPUTS + * @see Fields#TS_OUTPUT_COMMAND */ public byte[] currentOutputs; private SensorCentral.SensorListener rpmListener = value -> { @@ -552,7 +552,7 @@ public class BinaryProtocol implements BinaryProtocolCommands { return false; byte packet[] = new byte[5]; - packet[0] = COMMAND_OUTPUTS; + packet[0] = Fields.TS_OUTPUT_COMMAND; putShort(packet, 1, 0); // offset putShort(packet, 3, swap16(Fields.TS_OUTPUT_SIZE)); diff --git a/java_console/io/src/com/rusefi/binaryprotocol/IoHelper.java b/java_console/io/src/com/rusefi/binaryprotocol/IoHelper.java index 6a2ad1724b..cf1366a9d1 100644 --- a/java_console/io/src/com/rusefi/binaryprotocol/IoHelper.java +++ b/java_console/io/src/com/rusefi/binaryprotocol/IoHelper.java @@ -36,7 +36,7 @@ public class IoHelper { } public static int swap16(int x) { - return (((x & 0xFF) << 8) | ((x) >> 8)); + return (((x & 0xff) << 8) | ((x >> 8) & 0xff)); } static int swap32(int x) { diff --git a/java_console/io/src/com/rusefi/binaryprotocol/test/IoHelperTest.java b/java_console/io/src/com/rusefi/binaryprotocol/test/IoHelperTest.java new file mode 100644 index 0000000000..deeb7014b0 --- /dev/null +++ b/java_console/io/src/com/rusefi/binaryprotocol/test/IoHelperTest.java @@ -0,0 +1,21 @@ +package com.rusefi.binaryprotocol.test; + +import com.rusefi.binaryprotocol.IoHelper; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; + +public class IoHelperTest { + @Test + public void testSwap16() throws IOException { + byte packet[] = {-12, 0}; + DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet)); + short a = dis.readShort(); + int x = IoHelper.swap16(a); + assertEquals(244, x); + } +}