REO progress

This commit is contained in:
rusefi 2020-06-21 00:31:01 -04:00
parent 42d6aa53e8
commit 1a7154647e
3 changed files with 48 additions and 29 deletions

View File

@ -600,4 +600,10 @@ public class BinaryProtocol implements BinaryProtocolCommands {
throw new UnsupportedOperationException("type " + sensor.getType());
}
}
public void setRange(byte[] src, int scrPos, int offset, int count) {
synchronized (imageLock) {
System.arraycopy(src, scrPos, controller.getContent(), offset, count);
}
}
}

View File

@ -13,7 +13,7 @@ public class IoHelper {
return getCrc32(packet, 0, packet.length);
}
public static int getCrc32(byte[] packet, int offset, int length) {
private static int getCrc32(byte[] packet, int offset, int length) {
CRC32 c = new CRC32();
c.update(packet, offset, length);
return (int) c.getValue();

View File

@ -110,43 +110,19 @@ 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) {
System.out.println("CRC check");
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
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);
stream.sendPacket(response.toByteArray(), FileLog.LOGGER);
handleCrc(stream);
} else if (command == COMMAND_PAGE) {
stream.sendPacket(TS_OK.getBytes(), FileLog.LOGGER);
} else if (command == COMMAND_READ) {
short page = 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 {
System.out.println("read " + page + "/" + offset + "/" + count);
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
byte[] response = new byte[1 + count];
response[0] = (byte) TS_OK.charAt(0);
System.arraycopy(bp.getControllerConfiguration().getContent(), offset, response, 1, count);
stream.sendPacket(response, FileLog.LOGGER);
}
handleRead(dis, stream);
} 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);
handleWrite(packet, dis, stream);
} 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());
System.out.println("TS_OUTPUT_COMMAND offset=" + offset + "/count=" + count);
byte[] response = new byte[1 + count];
response[0] = (byte) TS_OK.charAt(0);
@ -161,4 +137,41 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
}
}
}
private static void handleWrite(byte[] packet, DataInputStream dis, TcpIoStream stream) throws IOException {
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();
bp.setRange(packet, 7, offset, count);
stream.sendPacket(TS_OK.getBytes(), FileLog.LOGGER);
}
private static void handleRead(DataInputStream dis, TcpIoStream stream) throws IOException {
short page = 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 {
System.out.println("read " + page + "/" + offset + "/" + count);
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
byte[] response = new byte[1 + count];
response[0] = (byte) TS_OK.charAt(0);
System.arraycopy(bp.getControllerConfiguration().getContent(), offset, response, 1, count);
stream.sendPacket(response, FileLog.LOGGER);
}
}
private static void handleCrc(TcpIoStream stream) throws IOException {
System.out.println("CRC check");
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
byte[] content = bp.getControllerConfiguration().getContent();
int result = IoHelper.getCrc32(content);
ByteArrayOutputStream response = new ByteArrayOutputStream();
response.write(TS_OK.charAt(0));
new DataOutputStream(response).writeInt(result);
stream.sendPacket(response.toByteArray(), FileLog.LOGGER);
}
}