diff --git a/java_console/io/src/main/java/com/rusefi/io/commands/WriteChunkCommand.java b/java_console/io/src/main/java/com/rusefi/io/commands/WriteChunkCommand.java index b35468078f..28ec9bf134 100644 --- a/java_console/io/src/main/java/com/rusefi/io/commands/WriteChunkCommand.java +++ b/java_console/io/src/main/java/com/rusefi/io/commands/WriteChunkCommand.java @@ -1,5 +1,6 @@ package com.rusefi.io.commands; public class WriteChunkCommand { - public static final int SCR_POS = 2 + 1 + 4; // 7 + public static final int SCR_POS_WITH = 1 + 4; // 5 + public static final int SCR_POS_WITH_SIZE_PREFIX = 2 + SCR_POS_WITH; // 7 } 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 6a5020fb83..03c2f2687a 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 @@ -245,12 +245,6 @@ public class BinaryProtocolServer { return length; } - private static void sendOkResponse(TcpIoStream stream) throws IOException { - byte[] response = new byte[1]; - response[0] = TS_RESPONSE_OK; - stream.sendPacket(response); - } - public static int getPacketLength(IncomingDataBuffer in, Handler protocolCommandHandler) throws IOException { return getPacketLength(in, protocolCommandHandler, Timeouts.BINARY_IO_TIMEOUT); } @@ -308,7 +302,7 @@ public class BinaryProtocolServer { int count = byteRange.getCount(); log.info("TS_CHUNK_WRITE_COMMAND: offset=" + byteRange); BinaryProtocolState bp = linkManager.getBinaryProtocolState(); - bp.setRange(packet, WriteChunkCommand.SCR_POS, offset, count); + bp.setRange(packet, WriteChunkCommand.SCR_POS_WITH_SIZE_PREFIX, offset, count); stream.sendPacket(TS_OK.getBytes()); } diff --git a/java_console/io/src/test/java/com/rusefi/binaryprotocol/test/TcpServerSandbox.java b/java_console/io/src/test/java/com/rusefi/binaryprotocol/test/TcpServerSandbox.java index 917eed3d6f..ca0f4ef01b 100644 --- a/java_console/io/src/test/java/com/rusefi/binaryprotocol/test/TcpServerSandbox.java +++ b/java_console/io/src/test/java/com/rusefi/binaryprotocol/test/TcpServerSandbox.java @@ -10,6 +10,7 @@ import com.rusefi.config.generated.TsOutputs; import com.rusefi.io.IoStream; import com.rusefi.io.commands.ByteRange; import com.rusefi.io.commands.HelloCommand; +import com.rusefi.io.commands.WriteChunkCommand; import com.rusefi.io.tcp.BinaryProtocolServer; import com.rusefi.io.tcp.TcpIoStream; import com.rusefi.ui.StatusConsumer; @@ -18,7 +19,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.Socket; -import static com.rusefi.config.generated.Fields.TS_PROTOCOL; +import static com.rusefi.config.generated.Fields.*; import static com.rusefi.io.tcp.BinaryProtocolServer.TS_OK; import static com.rusefi.io.tcp.BinaryProtocolServer.getOutputCommandResponse; @@ -59,7 +60,8 @@ public class TcpServerSandbox { } } catch (Exception e) { - System.out.println(e); + System.out.println("huh exception: " + e); + e.printStackTrace(); } } }; @@ -121,7 +123,28 @@ public class TcpServerSandbox { stream.sendPacket(response); } else if (command == Fields.TS_GET_SCATTERED_GET_COMMAND) { System.out.println("Cool TS_GET_SCATTERED_GET_COMMAND"); + int startOffset = HIGHSPEEDOFFSETS.getOffset(); + int totalResponseSize = 0; + for (int i = 0; i < HIGH_SPEED_COUNT; i++) { + int higherByte = getByte(startOffset + 1); + int type = higherByte >> 5; + int size = getSize(type); + + totalResponseSize += size; + + int twoBytes = getByte(startOffset) + (higherByte & 0x1F) * 256; + System.out.println("TS_GET_SCATTERED_GET_COMMAND index=" + i + " type=" + type + " offset=" + twoBytes); + startOffset += 2; + } + + byte[] response = new byte[1 + totalResponseSize]; + response[0] = (byte) TS_OK.charAt(0); + stream.sendPacket(response); + } else if (command == Fields.TS_CHUNK_WRITE_COMMAND) { + ByteRange byteRange = ByteRange.valueOf(payload); + System.out.println("TS_CHUNK_WRITE_COMMAND " + byteRange + " payload " + payload.length); + System.arraycopy(payload, WriteChunkCommand.SCR_POS_WITH, TOTALLY_EMPTY_CONFIGURATION, byteRange.getOffset(), byteRange.getCount()); stream.sendPacket(TS_OK.getBytes()); } else if (command == Fields.TS_BURN_COMMAND) { stream.sendPacket(new byte[]{Fields.TS_RESPONSE_BURN_OK}); @@ -137,4 +160,14 @@ public class TcpServerSandbox { } else throw new UnsupportedOperationException("Unsupported command " + BinaryProtocol.findCommand(command)); } + + private static int getSize(int type) { + if (type == 0) + return 0; + return 1 << (type - 1); + } + + private static int getByte(int startOffset) { + return TOTALLY_EMPTY_CONFIGURATION[startOffset] & 0xFF; + } }