nicer API

This commit is contained in:
rusefillc 2021-12-05 00:31:50 -05:00
parent 54e7062483
commit 0243003c96
1 changed files with 9 additions and 4 deletions

View File

@ -430,10 +430,7 @@ public class BinaryProtocol {
int crcOfLocallyCachedConfiguration = IoHelper.getCrc32(localCached.getContent()); int crcOfLocallyCachedConfiguration = IoHelper.getCrc32(localCached.getContent());
log.info(String.format(CONFIGURATION_RUSEFI_BINARY + " Local cache CRC %x\n", crcOfLocallyCachedConfiguration)); log.info(String.format(CONFIGURATION_RUSEFI_BINARY + " Local cache CRC %x\n", crcOfLocallyCachedConfiguration));
byte packet[] = new byte[5]; byte[] packet = createCrcCommand(localCached.getSize());
packet[0] = Fields.TS_CRC_CHECK_COMMAND;
putShort(packet, 1, swap16(/*offset = */ 0));
putShort(packet, 3, swap16(localCached.getSize()));
byte[] response = executeCommand(packet, "get CRC32"); byte[] response = executeCommand(packet, "get CRC32");
if (checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK) && response.length == 5) { if (checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK) && response.length == 5) {
@ -452,6 +449,14 @@ public class BinaryProtocol {
return null; return null;
} }
public static byte[] createCrcCommand(int size) {
byte[] packet = new byte[5];
packet[0] = Fields.TS_CRC_CHECK_COMMAND;
putShort(packet, 1, swap16(/*offset = */ 0));
putShort(packet, 3, swap16(size));
return packet;
}
public byte[] executeCommand(byte[] packet, String msg) { public byte[] executeCommand(byte[] packet, String msg) {
return executeCommand(packet, msg, false); return executeCommand(packet, msg, false);
} }