non-CRC mode

This commit is contained in:
rusefi 2017-03-03 21:23:40 -05:00
parent ff1b18a70f
commit 147a4800ea
2 changed files with 29 additions and 13 deletions

View File

@ -32,6 +32,17 @@ import static com.rusefi.binaryprotocol.IoHelper.*;
* 3/6/2015
*/
public class BinaryProtocol {
private static final String PROTOCOL_PLAIN = "protocol.plain";
/**
* This properly allows to switch to non-CRC32 mode
* todo: finish this feature, assuming we even need it.
*/
private static boolean PLAIN_PROTOCOL = Boolean.getBoolean(PROTOCOL_PLAIN);
static {
FileLog.MAIN.logLine(PROTOCOL_PLAIN + ": " + PLAIN_PROTOCOL);
}
// see BLOCKING_FACTOR in firmware code
private static final int BLOCKING_FACTOR = 400;
private static final byte RESPONSE_OK = 0;
@ -50,7 +61,7 @@ public class BinaryProtocol {
public static final char COMMAND_PROTOCOL = 'F';
public static final char COMMAND_CRC_CHECK_COMMAND = 'k';
public static final char COMMAND_PAGE = 'P';
public static final char COMMAND_READ = 'R';
public static final char COMMAND_READ = 'R'; // 082 decimal
public static final char COMMAND_CHUNK_WRITE = 'C';
public static final char COMMAND_BURN = 'B';
@ -341,7 +352,7 @@ public class BinaryProtocol {
try {
dropPending();
sendCrcPacket(packet);
sendPacket(packet);
return receivePacket(msg, allowLongResponse);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
@ -419,13 +430,18 @@ public class BinaryProtocol {
}
}
private void sendCrcPacket(byte[] command) throws IOException {
sendCrcPacket(command, logger, stream);
private void sendPacket(byte[] command) throws IOException {
sendPacket(command, logger, stream);
}
public static void sendCrcPacket(byte[] command, Logger logger, IoStream stream) throws IOException {
byte[] packet = IoHelper.makeCrc32Packet(command);
logger.info("Sending packet " + printHexBinary(command));
public static void sendPacket(byte[] plainPacket, Logger logger, IoStream stream) throws IOException {
byte[] packet;
if (PLAIN_PROTOCOL) {
packet = plainPacket;
} else {
packet = IoHelper.makeCrc32Packet(plainPacket);
}
logger.info("Sending packet " + printHexBinary(plainPacket));
stream.write(packet);
}

View File

@ -90,10 +90,10 @@ public class BinaryProtocolServer {
TcpIoStream stream = new TcpIoStream(clientSocket.getInputStream(), clientSocket.getOutputStream());
if (command == BinaryProtocol.COMMAND_HELLO) {
BinaryProtocol.sendCrcPacket((TS_OK + TS_SIGNATURE).getBytes(), FileLog.LOGGER, stream);
BinaryProtocol.sendPacket((TS_OK + TS_SIGNATURE).getBytes(), FileLog.LOGGER, stream);
} else if (command == BinaryProtocol.COMMAND_PROTOCOL) {
// System.out.println("Ignoring crc F command");
BinaryProtocol.sendCrcPacket((TS_OK + TS_PROTOCOL).getBytes(), FileLog.LOGGER, stream);
BinaryProtocol.sendPacket((TS_OK + TS_PROTOCOL).getBytes(), FileLog.LOGGER, stream);
} else if (command == BinaryProtocol.COMMAND_CRC_CHECK_COMMAND) {
short page = dis.readShort();
short offset = dis.readShort();
@ -104,9 +104,9 @@ public class BinaryProtocolServer {
ByteArrayOutputStream response = new ByteArrayOutputStream();
response.write(TS_OK.charAt(0));
new DataOutputStream(response).write(result);
BinaryProtocol.sendCrcPacket(response.toByteArray(), FileLog.LOGGER, stream);
BinaryProtocol.sendPacket(response.toByteArray(), FileLog.LOGGER, stream);
} else if (command == BinaryProtocol.COMMAND_PAGE) {
BinaryProtocol.sendCrcPacket(TS_OK.getBytes(), FileLog.LOGGER, stream);
BinaryProtocol.sendPacket(TS_OK.getBytes(), FileLog.LOGGER, stream);
} else if (command == BinaryProtocol.COMMAND_READ) {
short page = dis.readShort();
short offset = swap16(dis.readShort());
@ -119,7 +119,7 @@ public class BinaryProtocolServer {
byte[] response = new byte[1 + count];
response[0] = (byte) TS_OK.charAt(0);
System.arraycopy(bp.getController().getContent(), offset, response, 1, count);
BinaryProtocol.sendCrcPacket(response, FileLog.LOGGER, stream);
BinaryProtocol.sendPacket(response, FileLog.LOGGER, stream);
}
} else if (command == BinaryProtocol.COMMAND_OUTPUTS) {
@ -128,7 +128,7 @@ public class BinaryProtocolServer {
byte[] currentOutputs = BinaryProtocol.currentOutputs;
if (currentOutputs != null)
System.arraycopy(currentOutputs, 1, response, 1, Fields.TS_OUTPUT_SIZE);
BinaryProtocol.sendCrcPacket(response, FileLog.LOGGER, stream);
BinaryProtocol.sendPacket(response, FileLog.LOGGER, stream);
} else {
FileLog.MAIN.logLine("Error: unknown command " + command);
}