From 4984c9161b5441a6fff717b8f04ee2c3fc9c637c Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 3 Mar 2017 21:23:40 -0500 Subject: [PATCH] non-CRC mode --- .../rusefi/binaryprotocol/BinaryProtocol.java | 30 ++++++++++++++----- .../rusefi/io/tcp/BinaryProtocolServer.java | 12 ++++---- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java index 7acaa889ef..c4ca42b6a6 100644 --- a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java +++ b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java @@ -32,6 +32,17 @@ import static com.rusefi.binaryprotocol.IoHelper.*; * 3/6/2015 */ public class BinaryProtocol { + + private static final String PROTOCOL_PLAIN = "protocol.plain"; + /** + * This properly allows to switch to non-CRC32 mode + * todo: finish this feature, assuming we even need it. + */ + private static boolean PLAIN_PROTOCOL = Boolean.getBoolean(PROTOCOL_PLAIN); + static { + FileLog.MAIN.logLine(PROTOCOL_PLAIN + ": " + PLAIN_PROTOCOL); + } + // see BLOCKING_FACTOR in firmware code private static final int BLOCKING_FACTOR = 400; private static final byte RESPONSE_OK = 0; @@ -50,7 +61,7 @@ public class BinaryProtocol { public static final char COMMAND_PROTOCOL = 'F'; public static final char COMMAND_CRC_CHECK_COMMAND = 'k'; public static final char COMMAND_PAGE = 'P'; - public static final char COMMAND_READ = 'R'; + public static final char COMMAND_READ = 'R'; // 082 decimal public static final char COMMAND_CHUNK_WRITE = 'C'; public static final char COMMAND_BURN = 'B'; @@ -341,7 +352,7 @@ public class BinaryProtocol { try { dropPending(); - sendCrcPacket(packet); + sendPacket(packet); return receivePacket(msg, allowLongResponse); } catch (InterruptedException e) { throw new IllegalStateException(e); @@ -419,13 +430,18 @@ public class BinaryProtocol { } } - private void sendCrcPacket(byte[] command) throws IOException { - sendCrcPacket(command, logger, stream); + private void sendPacket(byte[] command) throws IOException { + sendPacket(command, logger, stream); } - public static void sendCrcPacket(byte[] command, Logger logger, IoStream stream) throws IOException { - byte[] packet = IoHelper.makeCrc32Packet(command); - logger.info("Sending packet " + printHexBinary(command)); + public static void sendPacket(byte[] plainPacket, Logger logger, IoStream stream) throws IOException { + byte[] packet; + if (PLAIN_PROTOCOL) { + packet = plainPacket; + } else { + packet = IoHelper.makeCrc32Packet(plainPacket); + } + logger.info("Sending packet " + printHexBinary(plainPacket)); stream.write(packet); } diff --git a/java_console/io/src/com/rusefi/io/tcp/BinaryProtocolServer.java b/java_console/io/src/com/rusefi/io/tcp/BinaryProtocolServer.java index fd14d25129..0b0174e6d8 100644 --- a/java_console/io/src/com/rusefi/io/tcp/BinaryProtocolServer.java +++ b/java_console/io/src/com/rusefi/io/tcp/BinaryProtocolServer.java @@ -90,10 +90,10 @@ public class BinaryProtocolServer { TcpIoStream stream = new TcpIoStream(clientSocket.getInputStream(), clientSocket.getOutputStream()); if (command == BinaryProtocol.COMMAND_HELLO) { - BinaryProtocol.sendCrcPacket((TS_OK + TS_SIGNATURE).getBytes(), FileLog.LOGGER, stream); + BinaryProtocol.sendPacket((TS_OK + TS_SIGNATURE).getBytes(), FileLog.LOGGER, stream); } else if (command == BinaryProtocol.COMMAND_PROTOCOL) { // System.out.println("Ignoring crc F command"); - BinaryProtocol.sendCrcPacket((TS_OK + TS_PROTOCOL).getBytes(), FileLog.LOGGER, stream); + BinaryProtocol.sendPacket((TS_OK + TS_PROTOCOL).getBytes(), FileLog.LOGGER, stream); } else if (command == BinaryProtocol.COMMAND_CRC_CHECK_COMMAND) { short page = dis.readShort(); short offset = dis.readShort(); @@ -104,9 +104,9 @@ public class BinaryProtocolServer { ByteArrayOutputStream response = new ByteArrayOutputStream(); response.write(TS_OK.charAt(0)); new DataOutputStream(response).write(result); - BinaryProtocol.sendCrcPacket(response.toByteArray(), FileLog.LOGGER, stream); + BinaryProtocol.sendPacket(response.toByteArray(), FileLog.LOGGER, stream); } else if (command == BinaryProtocol.COMMAND_PAGE) { - BinaryProtocol.sendCrcPacket(TS_OK.getBytes(), FileLog.LOGGER, stream); + BinaryProtocol.sendPacket(TS_OK.getBytes(), FileLog.LOGGER, stream); } else if (command == BinaryProtocol.COMMAND_READ) { short page = dis.readShort(); short offset = swap16(dis.readShort()); @@ -119,7 +119,7 @@ public class BinaryProtocolServer { byte[] response = new byte[1 + count]; response[0] = (byte) TS_OK.charAt(0); System.arraycopy(bp.getController().getContent(), offset, response, 1, count); - BinaryProtocol.sendCrcPacket(response, FileLog.LOGGER, stream); + BinaryProtocol.sendPacket(response, FileLog.LOGGER, stream); } } else if (command == BinaryProtocol.COMMAND_OUTPUTS) { @@ -128,7 +128,7 @@ public class BinaryProtocolServer { byte[] currentOutputs = BinaryProtocol.currentOutputs; if (currentOutputs != null) System.arraycopy(currentOutputs, 1, response, 1, Fields.TS_OUTPUT_SIZE); - BinaryProtocol.sendCrcPacket(response, FileLog.LOGGER, stream); + BinaryProtocol.sendPacket(response, FileLog.LOGGER, stream); } else { FileLog.MAIN.logLine("Error: unknown command " + command); }