refactoring
This commit is contained in:
parent
88f131adbb
commit
6a704897bb
|
@ -85,6 +85,8 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
|
||||
public static String findCommand(byte command) {
|
||||
switch (command) {
|
||||
case Fields.TS_COMMAND_F:
|
||||
return "PROTOCOL";
|
||||
case Fields.TS_CRC_CHECK_COMMAND:
|
||||
return "CRC_CHECK";
|
||||
case Fields.TS_BURN_COMMAND:
|
||||
|
@ -352,10 +354,10 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
return null;
|
||||
|
||||
int remainingSize = image.getSize() - offset;
|
||||
int requestSize = Math.min(remainingSize, BLOCKING_FACTOR);
|
||||
int requestSize = Math.min(remainingSize, Fields.BLOCKING_FACTOR);
|
||||
|
||||
byte packet[] = new byte[7];
|
||||
packet[0] = COMMAND_READ;
|
||||
packet[0] = Fields.TS_READ_COMMAND;
|
||||
putShort(packet, 1, 0); // page
|
||||
putShort(packet, 3, swap16(offset));
|
||||
putShort(packet, 5, swap16(requestSize));
|
||||
|
@ -454,9 +456,9 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
}
|
||||
|
||||
public void writeData(byte[] content, Integer offset, int size) {
|
||||
if (size > BLOCKING_FACTOR) {
|
||||
writeData(content, offset, BLOCKING_FACTOR);
|
||||
writeData(content, offset + BLOCKING_FACTOR, size - BLOCKING_FACTOR);
|
||||
if (size > Fields.BLOCKING_FACTOR) {
|
||||
writeData(content, offset, Fields.BLOCKING_FACTOR);
|
||||
writeData(content, offset + Fields.BLOCKING_FACTOR, size - Fields.BLOCKING_FACTOR);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,17 +7,13 @@ import com.rusefi.config.generated.Fields;
|
|||
* 6/21/2017.
|
||||
*/
|
||||
public interface BinaryProtocolCommands {
|
||||
// see BLOCKING_FACTOR in firmware code
|
||||
int BLOCKING_FACTOR = Fields.BLOCKING_FACTOR;
|
||||
byte RESPONSE_OK = Fields.TS_RESPONSE_OK;
|
||||
byte RESPONSE_BURN_OK = Fields.TS_RESPONSE_BURN_OK;
|
||||
byte RESPONSE_COMMAND_OK = Fields.TS_RESPONSE_COMMAND_OK;
|
||||
char COMMAND_PROTOCOL = 'F';
|
||||
char COMMAND_PROTOCOL = Fields.TS_COMMAND_F;
|
||||
// todo: make crc32CheckCommand shorted one day later - no need in 6 empty bytes
|
||||
char COMMAND_CRC_CHECK_COMMAND = Fields.TS_CRC_CHECK_COMMAND;
|
||||
char COMMAND_PAGE = 'P';
|
||||
char COMMAND_READ = Fields.TS_READ_COMMAND;
|
||||
char COMMAND_CHUNK_WRITE = 'C'; // pageChunkWrite
|
||||
char COMMAND_BURN = 'B'; // burnCommand
|
||||
char COMMAND_CHUNK_WRITE = Fields.TS_CHUNK_WRITE_COMMAND;
|
||||
char COMMAND_BURN = Fields.TS_BURN_COMMAND;
|
||||
char COMMAND_GET_STRUCT = '9'; // TS_GET_STRUCT
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class IncomingDataBuffer {
|
|||
log.debug(loggingPrefix + "Got packet size " + packetSize);
|
||||
if (packetSize < 0)
|
||||
return null;
|
||||
if (!allowLongResponse && packetSize > Math.max(BinaryProtocolCommands.BLOCKING_FACTOR, Fields.TS_OUTPUT_SIZE) + 10)
|
||||
if (!allowLongResponse && packetSize > Math.max(Fields.BLOCKING_FACTOR, Fields.TS_OUTPUT_SIZE) + 10)
|
||||
return null;
|
||||
|
||||
isTimeout = waitForBytes(loggingPrefix + msg + " body", start, packetSize + 4);
|
||||
|
|
|
@ -159,9 +159,9 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
stream.sendPacket((TS_OK + "rusEFI proxy").getBytes());
|
||||
} else if (command == COMMAND_CRC_CHECK_COMMAND) {
|
||||
handleCrc(linkManager, stream);
|
||||
} else if (command == COMMAND_PAGE) {
|
||||
} else if (command == Fields.TS_PAGE_COMMAND) {
|
||||
stream.sendPacket(TS_OK.getBytes());
|
||||
} else if (command == COMMAND_READ) {
|
||||
} else if (command == Fields.TS_READ_COMMAND) {
|
||||
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(payload, 1, payload.length - 1));
|
||||
handleRead(linkManager, dis, stream);
|
||||
} else if (command == Fields.TS_CHUNK_WRITE_COMMAND) {
|
||||
|
|
Loading…
Reference in New Issue