This commit is contained in:
Matthew Kennedy 2020-08-18 19:37:08 -07:00 committed by GitHub
parent baef16ad17
commit 66b404fc59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 59 deletions

View File

@ -210,16 +210,10 @@ static void sendErrorCode(ts_channel_s *tsChannel) {
sr5WriteCrcPacket(tsChannel, TS_RESPONSE_CRC_FAILURE, NULL, 0);
}
static void handlePageSelectCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t pageId) {
static void handlePageSelectCommand(ts_channel_s *tsChannel, ts_response_format_e mode) {
tsState.pageCommandCounter++;
scheduleMsg(&tsLogger, "PAGE %d", pageId);
if (pageId == 0) {
sendOkResponse(tsChannel, mode);
} else {
sendErrorCode(tsChannel);
}
sendOkResponse(tsChannel, mode);
}
/**
@ -331,19 +325,17 @@ static void handleWriteChunkCommand(ts_channel_s *tsChannel, ts_response_format_
sendOkResponse(tsChannel, mode);
}
static void handleCrc32Check(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t pageId) {
UNUSED(pageId);
static void handleCrc32Check(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count) {
tsState.crc32CheckCommandCounter++;
uint16_t count = getTunerStudioPageSize();
// Ensure we are reading from in bounds
if (validateOffsetCount(offset, count, tsChannel)) {
return;
}
uint32_t crc = SWAP_UINT32(crc32((void * ) getWorkingPageAddr(), count));
#if 0
scheduleMsg(&tsLogger, "Sending CRC32 response: %x", crc);
#endif
const char* start = getWorkingPageAddr() + offset;
uint32_t crc = SWAP_UINT32(crc32(start, count));
sr5SendResponse(tsChannel, mode, (const uint8_t *) &crc, 4);
}
@ -351,11 +343,9 @@ static void handleCrc32Check(ts_channel_s *tsChannel, ts_response_format_e mode,
* 'Write' command receives a single value at a given offset
* @note Writing values one by one is pretty slow
*/
static void handleWriteValueCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t page, uint16_t offset,
uint8_t value) {
static void handleWriteValueCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t offset, uint8_t value) {
UNUSED(tsChannel);
UNUSED(mode);
UNUSED(page);
tsState.writeValueCommandCounter++;
@ -382,20 +372,13 @@ static void handleWriteValueCommand(ts_channel_s *tsChannel, ts_response_format_
// scheduleMsg(logger, "va=%d", configWorkingCopy.boardConfiguration.idleValvePin);
}
static void handlePageReadCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t pageId, uint16_t offset,
uint16_t count) {
static void handlePageReadCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count) {
tsState.readPageCommandsCounter++;
#if EFI_TUNER_STUDIO_VERBOSE
scheduleMsg(&tsLogger, "READ mode=%d offset=%d size=%d", mode, offset, count);
#endif
if (pageId != 0) {
// something is not right here
tunerStudioError("ERROR: invalid page number");
return;
}
if (validateOffsetCount(offset, count, tsChannel)) {
return;
}
@ -424,9 +407,7 @@ static void sendResponseCode(ts_response_format_e mode, ts_channel_s *tsChannel,
/**
* 'Burn' command is a command to commit the changes
*/
static void handleBurnCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t page) {
UNUSED(page);
static void handleBurnCommand(ts_channel_s *tsChannel, ts_response_format_e mode) {
efitimems_t nowMs = currentTimeMillis();
tsState.burnCommandCounter++;
@ -738,10 +719,13 @@ int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomin
const uint16_t* data16 = reinterpret_cast<uint16_t*>(data);
uint16_t offset = data16[0];
uint16_t count = data16[1];
switch(command)
{
case TS_OUTPUT_COMMAND:
handleOutputChannelsCommand(tsChannel, TS_CRC, data16[0], data16[1]);
handleOutputChannelsCommand(tsChannel, TS_CRC, offset, count);
break;
case TS_HELLO_COMMAND:
tunerStudioDebug("got Query command");
@ -765,28 +749,28 @@ int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomin
handleExecuteCommand(tsChannel, data, incomingPacketSize - 1);
break;
case TS_PAGE_COMMAND:
handlePageSelectCommand(tsChannel, TS_CRC, data16[0]);
handlePageSelectCommand(tsChannel, TS_CRC);
break;
case TS_GET_STRUCT:
handleGetStructContent(tsChannel, data16[0], data16[1]);
handleGetStructContent(tsChannel, offset, count);
break;
case TS_CHUNK_WRITE_COMMAND:
handleWriteChunkCommand(tsChannel, TS_CRC, data16[1], data16[2], data + sizeof(TunerStudioWriteChunkRequest));
handleWriteChunkCommand(tsChannel, TS_CRC, offset, count, data + sizeof(TunerStudioWriteChunkRequest));
break;
case TS_SINGLE_WRITE_COMMAND:
{
uint8_t value = data[4];
handleWriteValueCommand(tsChannel, TS_CRC, data16[0], data16[1], value);
handleWriteValueCommand(tsChannel, TS_CRC, offset, value);
}
break;
case TS_CRC_CHECK_COMMAND:
handleCrc32Check(tsChannel, TS_CRC, data16[0]);
handleCrc32Check(tsChannel, TS_CRC, offset, count);
break;
case TS_BURN_COMMAND:
handleBurnCommand(tsChannel, TS_CRC, data16[0]);
handleBurnCommand(tsChannel, TS_CRC);
break;
case TS_READ_COMMAND:
handlePageReadCommand(tsChannel, TS_CRC, data16[0], data16[1], data16[2]);
handlePageReadCommand(tsChannel, TS_CRC, offset, count);
break;
case TS_TEST_COMMAND:
[[fallthrough]];

View File

@ -75,14 +75,12 @@ typedef pre_packed struct
typedef pre_packed struct
post_packed {
short int page;
short int offset;
short int count;
} TunerStudioWriteChunkRequest;
typedef pre_packed struct
post_packed {
short int page;
short int offset;
short int count;
} TunerStudioReadRequest;

View File

@ -46,16 +46,14 @@ enable2ndByteCanID = false
endianness = little
nPages = 1
pageIdentifier = "\x00\x00"
pageReadCommand = "@@TS_READ_COMMAND_char@@\x00\x00%2o%2c"
burnCommand = "@@TS_BURN_COMMAND_char@@\x00\x00"
pageActivate = "@@TS_PAGE_COMMAND_char@@\x00\x00"
pageValueWrite = "@@TS_SINGLE_WRITE_COMMAND_char@@\x00\x00%2o%v"
pageChunkWrite = "@@TS_CHUNK_WRITE_COMMAND_char@@\x00\x00%2o%2c%v"
; todo: make this command shorter one day, no need to have all these zeros
crc32CheckCommand = "k\x00\x00\x00\x00\x00\x00"
pageReadCommand = "@@TS_READ_COMMAND_char@@%2o%2c"
burnCommand = "@@TS_BURN_COMMAND_char@@"
pageActivate = "@@TS_PAGE_COMMAND_char@@"
pageValueWrite = "@@TS_SINGLE_WRITE_COMMAND_char@@%2o%v"
pageChunkWrite = "@@TS_CHUNK_WRITE_COMMAND_char@@%2o%2c%v"
crc32CheckCommand = "@@TS_CRC_CHECK_COMMAND@@%2o%2c"
retrieveConfigError = "e"
;communication settings

View File

@ -362,11 +362,10 @@ public class BinaryProtocol implements BinaryProtocolCommands {
int remainingSize = image.getSize() - offset;
int requestSize = Math.min(remainingSize, Fields.BLOCKING_FACTOR);
byte packet[] = new byte[7];
byte packet[] = new byte[5];
packet[0] = Fields.TS_READ_COMMAND;
putShort(packet, 1, 0); // page
putShort(packet, 3, swap16(offset));
putShort(packet, 5, swap16(requestSize));
putShort(packet, 1, swap16(offset));
putShort(packet, 3, swap16(requestSize));
byte[] response = executeCommand(packet, "load image offset=" + offset);
@ -408,8 +407,10 @@ public class BinaryProtocol implements BinaryProtocolCommands {
int crcOfLocallyCachedConfiguration = IoHelper.getCrc32(localCached.getContent());
log.info(String.format(CONFIGURATION_RUSEFI_BINARY + " Local cache CRC %x\n", crcOfLocallyCachedConfiguration));
byte packet[] = new byte[7];
byte packet[] = new byte[5];
packet[0] = COMMAND_CRC_CHECK_COMMAND;
putShort(packet, 1, swap16(/*offset = */ 0));
putShort(packet, 3, swap16(localCached.getSize()));
byte[] response = executeCommand(packet, "get CRC32");
if (checkResponseCode(response, RESPONSE_OK) && response.length == 5) {
@ -472,11 +473,10 @@ public class BinaryProtocol implements BinaryProtocolCommands {
isBurnPending = true;
byte packet[] = new byte[7 + size];
byte packet[] = new byte[5 + size];
packet[0] = COMMAND_CHUNK_WRITE;
putShort(packet, 1, 0); // page
putShort(packet, 3, swap16(offset));
putShort(packet, 5, swap16(size));
putShort(packet, 1, swap16(offset));
putShort(packet, 3, swap16(size));
System.arraycopy(content, offset, packet, 7, size);

View File

@ -11,7 +11,6 @@ public interface BinaryProtocolCommands {
byte RESPONSE_BURN_OK = Fields.TS_RESPONSE_BURN_OK;
byte RESPONSE_COMMAND_OK = Fields.TS_RESPONSE_COMMAND_OK;
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_CHUNK_WRITE = Fields.TS_CHUNK_WRITE_COMMAND;
char COMMAND_BURN = Fields.TS_BURN_COMMAND;