Full Optimized – High Speed #4818

refactoring - nicer API
This commit is contained in:
rusefillc 2022-11-23 21:19:15 -05:00
parent 1c7a7b0874
commit cee496a9df
2 changed files with 10 additions and 6 deletions

View File

@ -13,6 +13,7 @@ import com.rusefi.config.generated.Fields;
import com.rusefi.core.Pair;
import com.rusefi.core.SensorCentral;
import com.rusefi.io.*;
import com.rusefi.io.commands.ByteRange;
import com.rusefi.io.commands.GetOutputsCommand;
import com.rusefi.io.commands.HelloCommand;
import com.rusefi.core.FileUtil;
@ -328,8 +329,7 @@ public class BinaryProtocol {
int requestSize = Math.min(remainingSize, Fields.BLOCKING_FACTOR);
byte[] packet = new byte[4];
putShort(packet, 0, swap16(offset));
putShort(packet, 2, swap16(requestSize));
ByteRange.packOffsetAndSize(offset, requestSize, packet);
byte[] response = executeCommand(Fields.TS_READ_COMMAND, packet, "load image offset=" + offset);
@ -422,8 +422,7 @@ public class BinaryProtocol {
public static byte[] createCrcCommand(int size) {
byte[] packet = new byte[4];
putShort(packet, 0, swap16(/*offset = */ 0));
putShort(packet, 2, swap16(size));
ByteRange.packOffsetAndSize(0, size, packet);
return packet;
}
@ -477,8 +476,7 @@ public class BinaryProtocol {
isBurnPending = true;
byte[] packet = new byte[4 + size];
putShort(packet, 0, swap16(ecuOffset));
putShort(packet, 2, swap16(size));
ByteRange.packOffsetAndSize(ecuOffset, size, packet);
System.arraycopy(content, contentOffset, packet, 4, size);

View File

@ -6,6 +6,7 @@ import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import static com.rusefi.binaryprotocol.IoHelper.putShort;
import static com.rusefi.binaryprotocol.IoHelper.swap16;
public class ByteRange {
@ -22,6 +23,11 @@ public class ByteRange {
return new DataInputStream(new ByteArrayInputStream(payload, 1, payload.length - 1));
}
public static void packOffsetAndSize(int offset, int requestSize, byte[] packet) {
putShort(packet, 0, swap16(offset));
putShort(packet, 2, swap16(requestSize));
}
public int getOffset() {
return offset;
}