diff --git a/firmware/config/boards/kinetis/config/controllers/algo/rusefi_generated.h b/firmware/config/boards/kinetis/config/controllers/algo/rusefi_generated.h index 2b38948c9c..352922de78 100644 --- a/firmware/config/boards/kinetis/config/controllers/algo/rusefi_generated.h +++ b/firmware/config/boards/kinetis/config/controllers/algo/rusefi_generated.h @@ -1291,6 +1291,9 @@ #define TS_PERF_TRACE_GET_BUFFER 'b' #define TS_PROTOCOL "001" #define TS_READ_COMMAND 'R' +#define TS_RESPONSE_BURN_OK 4 +#define TS_RESPONSE_COMMAND_OK 7 +#define TS_RESPONSE_OK 0 #define TS_SET_LOGGER_SWITCH 'l' #define ts_show_analog_divider true #define ts_show_auxserial_pins true diff --git a/firmware/console/binary/tunerstudio_io.h b/firmware/console/binary/tunerstudio_io.h index 63b4d06409..ee9541fa1c 100644 --- a/firmware/console/binary/tunerstudio_io.h +++ b/firmware/console/binary/tunerstudio_io.h @@ -14,10 +14,6 @@ #include "pin_repository.h" #endif -#define TS_RESPONSE_OK 0x00 -#define TS_RESPONSE_BURN_OK 0x04 -#define TS_RESPONSE_COMMAND_OK 0x07 - #define TS_RESPONSE_UNDERRUN 0x80 #define TS_RESPONSE_CRC_FAILURE 0x82 diff --git a/firmware/controllers/generated/rusefi_generated.h b/firmware/controllers/generated/rusefi_generated.h index c72d20eb9e..19dd5e9c88 100644 --- a/firmware/controllers/generated/rusefi_generated.h +++ b/firmware/controllers/generated/rusefi_generated.h @@ -1291,6 +1291,9 @@ #define TS_PERF_TRACE_GET_BUFFER 'b' #define TS_PROTOCOL "001" #define TS_READ_COMMAND 'R' +#define TS_RESPONSE_BURN_OK 4 +#define TS_RESPONSE_COMMAND_OK 7 +#define TS_RESPONSE_OK 0 #define TS_SET_LOGGER_SWITCH 'l' #define ts_show_analog_divider true #define ts_show_auxserial_pins true diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 37252be589..8fe2a254b9 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1621,6 +1621,9 @@ end_struct // 0x77 #define TS_IO_TEST_COMMAND 'w' +#define TS_RESPONSE_OK 0 +#define TS_RESPONSE_BURN_OK 4 +#define TS_RESPONSE_COMMAND_OK 7 // Engine Sniffer time stamp unit, in microseconds #define ENGINE_SNIFFER_UNIT_US 10 diff --git a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocolCommands.java b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocolCommands.java index d3d1075be5..e73943cd53 100644 --- a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocolCommands.java +++ b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocolCommands.java @@ -12,7 +12,6 @@ public interface BinaryProtocolCommands { byte RESPONSE_OK = 0; byte RESPONSE_BURN_OK = 0x04; byte RESPONSE_COMMAND_OK = 0x07; - char COMMAND_OUTPUTS = Fields.TS_OUTPUT_COMMAND; char COMMAND_HELLO = Fields.TS_HELLO_COMMAND; char COMMAND_PROTOCOL = 'F'; // todo: make crc32CheckCommand shorted one day later - no need in 6 empty bytes 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 729fe61bf1..663bdd6a4d 100644 --- a/java_console/io/src/com/rusefi/io/tcp/BinaryProtocolServer.java +++ b/java_console/io/src/com/rusefi/io/tcp/BinaryProtocolServer.java @@ -11,7 +11,9 @@ import java.io.*; import java.net.ServerSocket; import java.net.Socket; +import static com.rusefi.binaryprotocol.IoHelper.swap16; import static com.rusefi.config.generated.Fields.TS_PROTOCOL; +import static com.rusefi.config.generated.Fields.TS_RESPONSE_BURN_OK; /** * This class makes rusEfi console a proxy for other tuning software, this way we can have two tools connected via same @@ -108,12 +110,10 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { } else if (command == Fields.TS_GET_FIRMWARE_VERSION) { stream.sendPacket((TS_OK + "rusEFI proxy").getBytes(), FileLog.LOGGER); } else if (command == COMMAND_CRC_CHECK_COMMAND) { - short page = dis.readShort(); - short offset = dis.readShort(); - short count = dis.readShort(); // no swap here? interesting! - System.out.println("CRC check " + page + "/" + offset + "/" + count); + System.out.println("CRC check"); BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState(); - int result = IoHelper.getCrc32(bp.getControllerConfiguration().getContent(), offset, count); + byte[] content = bp.getControllerConfiguration().getContent(); + int result = IoHelper.getCrc32(content, 0, content.length); ByteArrayOutputStream response = new ByteArrayOutputStream(); response.write(TS_OK.charAt(0)); new DataOutputStream(response).write(result); @@ -122,8 +122,8 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { stream.sendPacket(TS_OK.getBytes(), FileLog.LOGGER); } else if (command == COMMAND_READ) { short page = dis.readShort(); - short offset = swap16(dis.readShort()); - short count = swap16(dis.readShort()); + int offset = swap16(dis.readShort()); + int count = swap16(dis.readShort()); if (count <= 0) { FileLog.MAIN.logLine("Error: negative read request " + offset + "/" + count); } else { @@ -134,26 +134,31 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { System.arraycopy(bp.getControllerConfiguration().getContent(), offset, response, 1, count); stream.sendPacket(response, FileLog.LOGGER); } - } else if (command == COMMAND_OUTPUTS) { + } else if (command == Fields.TS_CHUNK_WRITE_COMMAND) { + dis.readShort(); // page + int offset = swap16(dis.readShort()); + int count = swap16(dis.readShort()); + FileLog.MAIN.logLine("TS_CHUNK_WRITE_COMMAND: offset=" + offset + " count=" + count); + BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState(); + System.arraycopy(packet, 7, bp.getControllerConfiguration().getContent(), offset, count); + stream.sendPacket(TS_OK.getBytes(), FileLog.LOGGER); + } else if (command == Fields.TS_BURN_COMMAND) { + stream.sendPacket(new byte[]{TS_RESPONSE_BURN_OK}, FileLog.LOGGER); + } else if (command == Fields.TS_OUTPUT_COMMAND) { + int offset = swap16(dis.readShort()); + int count = swap16(dis.readShort()); - if (System.currentTimeMillis() > 0) - throw new UnsupportedOperationException("offset and count not supported see #429"); - // todo: new version with offset and - - byte[] response = new byte[1 + Fields.TS_OUTPUT_SIZE]; + byte[] response = new byte[1 + count]; response[0] = (byte) TS_OK.charAt(0); BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState(); byte[] currentOutputs = bp.currentOutputs; if (currentOutputs != null) - System.arraycopy(currentOutputs, 1, response, 1, Fields.TS_OUTPUT_SIZE); + System.arraycopy(currentOutputs, 1 + offset , response, 1, count); stream.sendPacket(response, FileLog.LOGGER); } else { + new IllegalStateException().printStackTrace(); FileLog.MAIN.logLine("Error: unknown command " + command); } } } - - private static short swap16(short x) { - return (short) (((x) << 8) | ((x) >> 8)); - } } \ No newline at end of file diff --git a/java_console/models/src/com/rusefi/config/generated/Fields.java b/java_console/models/src/com/rusefi/config/generated/Fields.java index b9fc67749b..727be6ed76 100644 --- a/java_console/models/src/com/rusefi/config/generated/Fields.java +++ b/java_console/models/src/com/rusefi/config/generated/Fields.java @@ -1,6 +1,6 @@ package com.rusefi.config.generated; -// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Jun 20 18:31:24 EDT 2020 +// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Jun 20 22:28:34 EDT 2020 // by class com.rusefi.output.FileJavaFieldsConsumer import com.rusefi.config.*; @@ -1271,6 +1271,9 @@ public class Fields { public static final char TS_PERF_TRACE_GET_BUFFER = 'b'; public static final String TS_PROTOCOL = "001"; public static final char TS_READ_COMMAND = 'R'; + public static final int TS_RESPONSE_BURN_OK = 4; + public static final int TS_RESPONSE_COMMAND_OK = 7; + public static final int TS_RESPONSE_OK = 0; public static final char TS_SET_LOGGER_SWITCH = 'l'; public static final String TS_SIGNATURE = "rusEFI v1.2020.4"; public static final char TS_SINGLE_WRITE_COMMAND = 'W';