non-CRC mode
This commit is contained in:
parent
ff1b18a70f
commit
147a4800ea
|
@ -32,6 +32,17 @@ import static com.rusefi.binaryprotocol.IoHelper.*;
|
||||||
* 3/6/2015
|
* 3/6/2015
|
||||||
*/
|
*/
|
||||||
public class BinaryProtocol {
|
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
|
// see BLOCKING_FACTOR in firmware code
|
||||||
private static final int BLOCKING_FACTOR = 400;
|
private static final int BLOCKING_FACTOR = 400;
|
||||||
private static final byte RESPONSE_OK = 0;
|
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_PROTOCOL = 'F';
|
||||||
public static final char COMMAND_CRC_CHECK_COMMAND = 'k';
|
public static final char COMMAND_CRC_CHECK_COMMAND = 'k';
|
||||||
public static final char COMMAND_PAGE = 'P';
|
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_CHUNK_WRITE = 'C';
|
||||||
public static final char COMMAND_BURN = 'B';
|
public static final char COMMAND_BURN = 'B';
|
||||||
|
|
||||||
|
@ -341,7 +352,7 @@ public class BinaryProtocol {
|
||||||
try {
|
try {
|
||||||
dropPending();
|
dropPending();
|
||||||
|
|
||||||
sendCrcPacket(packet);
|
sendPacket(packet);
|
||||||
return receivePacket(msg, allowLongResponse);
|
return receivePacket(msg, allowLongResponse);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
|
@ -419,13 +430,18 @@ public class BinaryProtocol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendCrcPacket(byte[] command) throws IOException {
|
private void sendPacket(byte[] command) throws IOException {
|
||||||
sendCrcPacket(command, logger, stream);
|
sendPacket(command, logger, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendCrcPacket(byte[] command, Logger logger, IoStream stream) throws IOException {
|
public static void sendPacket(byte[] plainPacket, Logger logger, IoStream stream) throws IOException {
|
||||||
byte[] packet = IoHelper.makeCrc32Packet(command);
|
byte[] packet;
|
||||||
logger.info("Sending packet " + printHexBinary(command));
|
if (PLAIN_PROTOCOL) {
|
||||||
|
packet = plainPacket;
|
||||||
|
} else {
|
||||||
|
packet = IoHelper.makeCrc32Packet(plainPacket);
|
||||||
|
}
|
||||||
|
logger.info("Sending packet " + printHexBinary(plainPacket));
|
||||||
stream.write(packet);
|
stream.write(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,10 +90,10 @@ public class BinaryProtocolServer {
|
||||||
|
|
||||||
TcpIoStream stream = new TcpIoStream(clientSocket.getInputStream(), clientSocket.getOutputStream());
|
TcpIoStream stream = new TcpIoStream(clientSocket.getInputStream(), clientSocket.getOutputStream());
|
||||||
if (command == BinaryProtocol.COMMAND_HELLO) {
|
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) {
|
} else if (command == BinaryProtocol.COMMAND_PROTOCOL) {
|
||||||
// System.out.println("Ignoring crc F command");
|
// 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) {
|
} else if (command == BinaryProtocol.COMMAND_CRC_CHECK_COMMAND) {
|
||||||
short page = dis.readShort();
|
short page = dis.readShort();
|
||||||
short offset = dis.readShort();
|
short offset = dis.readShort();
|
||||||
|
@ -104,9 +104,9 @@ public class BinaryProtocolServer {
|
||||||
ByteArrayOutputStream response = new ByteArrayOutputStream();
|
ByteArrayOutputStream response = new ByteArrayOutputStream();
|
||||||
response.write(TS_OK.charAt(0));
|
response.write(TS_OK.charAt(0));
|
||||||
new DataOutputStream(response).write(result);
|
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) {
|
} 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) {
|
} else if (command == BinaryProtocol.COMMAND_READ) {
|
||||||
short page = dis.readShort();
|
short page = dis.readShort();
|
||||||
short offset = swap16(dis.readShort());
|
short offset = swap16(dis.readShort());
|
||||||
|
@ -119,7 +119,7 @@ public class BinaryProtocolServer {
|
||||||
byte[] response = new byte[1 + count];
|
byte[] response = new byte[1 + count];
|
||||||
response[0] = (byte) TS_OK.charAt(0);
|
response[0] = (byte) TS_OK.charAt(0);
|
||||||
System.arraycopy(bp.getController().getContent(), offset, response, 1, count);
|
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) {
|
} else if (command == BinaryProtocol.COMMAND_OUTPUTS) {
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public class BinaryProtocolServer {
|
||||||
byte[] currentOutputs = BinaryProtocol.currentOutputs;
|
byte[] currentOutputs = BinaryProtocol.currentOutputs;
|
||||||
if (currentOutputs != null)
|
if (currentOutputs != null)
|
||||||
System.arraycopy(currentOutputs, 1, response, 1, Fields.TS_OUTPUT_SIZE);
|
System.arraycopy(currentOutputs, 1, response, 1, Fields.TS_OUTPUT_SIZE);
|
||||||
BinaryProtocol.sendCrcPacket(response, FileLog.LOGGER, stream);
|
BinaryProtocol.sendPacket(response, FileLog.LOGGER, stream);
|
||||||
} else {
|
} else {
|
||||||
FileLog.MAIN.logLine("Error: unknown command " + command);
|
FileLog.MAIN.logLine("Error: unknown command " + command);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue