Full Optimized – High Speed #4818

This commit is contained in:
rusefillc 2022-11-23 22:38:49 -05:00
parent adc6acac20
commit d0478250ff
3 changed files with 38 additions and 10 deletions

View File

@ -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
}

View File

@ -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());
}

View File

@ -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;
}
}