improve (#1702)
This commit is contained in:
parent
baef16ad17
commit
66b404fc59
|
@ -210,16 +210,10 @@ static void sendErrorCode(ts_channel_s *tsChannel) {
|
||||||
sr5WriteCrcPacket(tsChannel, TS_RESPONSE_CRC_FAILURE, NULL, 0);
|
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++;
|
tsState.pageCommandCounter++;
|
||||||
|
|
||||||
scheduleMsg(&tsLogger, "PAGE %d", pageId);
|
sendOkResponse(tsChannel, mode);
|
||||||
|
|
||||||
if (pageId == 0) {
|
|
||||||
sendOkResponse(tsChannel, mode);
|
|
||||||
} else {
|
|
||||||
sendErrorCode(tsChannel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -331,19 +325,17 @@ static void handleWriteChunkCommand(ts_channel_s *tsChannel, ts_response_format_
|
||||||
sendOkResponse(tsChannel, mode);
|
sendOkResponse(tsChannel, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleCrc32Check(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t pageId) {
|
static void handleCrc32Check(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count) {
|
||||||
UNUSED(pageId);
|
|
||||||
|
|
||||||
tsState.crc32CheckCommandCounter++;
|
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));
|
const char* start = getWorkingPageAddr() + offset;
|
||||||
|
|
||||||
#if 0
|
|
||||||
scheduleMsg(&tsLogger, "Sending CRC32 response: %x", crc);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
uint32_t crc = SWAP_UINT32(crc32(start, count));
|
||||||
sr5SendResponse(tsChannel, mode, (const uint8_t *) &crc, 4);
|
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
|
* 'Write' command receives a single value at a given offset
|
||||||
* @note Writing values one by one is pretty slow
|
* @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,
|
static void handleWriteValueCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t offset, uint8_t value) {
|
||||||
uint8_t value) {
|
|
||||||
UNUSED(tsChannel);
|
UNUSED(tsChannel);
|
||||||
UNUSED(mode);
|
UNUSED(mode);
|
||||||
UNUSED(page);
|
|
||||||
|
|
||||||
tsState.writeValueCommandCounter++;
|
tsState.writeValueCommandCounter++;
|
||||||
|
|
||||||
|
@ -382,20 +372,13 @@ static void handleWriteValueCommand(ts_channel_s *tsChannel, ts_response_format_
|
||||||
// scheduleMsg(logger, "va=%d", configWorkingCopy.boardConfiguration.idleValvePin);
|
// 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,
|
static void handlePageReadCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count) {
|
||||||
uint16_t count) {
|
|
||||||
tsState.readPageCommandsCounter++;
|
tsState.readPageCommandsCounter++;
|
||||||
|
|
||||||
#if EFI_TUNER_STUDIO_VERBOSE
|
#if EFI_TUNER_STUDIO_VERBOSE
|
||||||
scheduleMsg(&tsLogger, "READ mode=%d offset=%d size=%d", mode, offset, count);
|
scheduleMsg(&tsLogger, "READ mode=%d offset=%d size=%d", mode, offset, count);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (pageId != 0) {
|
|
||||||
// something is not right here
|
|
||||||
tunerStudioError("ERROR: invalid page number");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (validateOffsetCount(offset, count, tsChannel)) {
|
if (validateOffsetCount(offset, count, tsChannel)) {
|
||||||
return;
|
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
|
* 'Burn' command is a command to commit the changes
|
||||||
*/
|
*/
|
||||||
static void handleBurnCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t page) {
|
static void handleBurnCommand(ts_channel_s *tsChannel, ts_response_format_e mode) {
|
||||||
UNUSED(page);
|
|
||||||
|
|
||||||
efitimems_t nowMs = currentTimeMillis();
|
efitimems_t nowMs = currentTimeMillis();
|
||||||
tsState.burnCommandCounter++;
|
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);
|
const uint16_t* data16 = reinterpret_cast<uint16_t*>(data);
|
||||||
|
|
||||||
|
uint16_t offset = data16[0];
|
||||||
|
uint16_t count = data16[1];
|
||||||
|
|
||||||
switch(command)
|
switch(command)
|
||||||
{
|
{
|
||||||
case TS_OUTPUT_COMMAND:
|
case TS_OUTPUT_COMMAND:
|
||||||
handleOutputChannelsCommand(tsChannel, TS_CRC, data16[0], data16[1]);
|
handleOutputChannelsCommand(tsChannel, TS_CRC, offset, count);
|
||||||
break;
|
break;
|
||||||
case TS_HELLO_COMMAND:
|
case TS_HELLO_COMMAND:
|
||||||
tunerStudioDebug("got Query command");
|
tunerStudioDebug("got Query command");
|
||||||
|
@ -765,28 +749,28 @@ int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomin
|
||||||
handleExecuteCommand(tsChannel, data, incomingPacketSize - 1);
|
handleExecuteCommand(tsChannel, data, incomingPacketSize - 1);
|
||||||
break;
|
break;
|
||||||
case TS_PAGE_COMMAND:
|
case TS_PAGE_COMMAND:
|
||||||
handlePageSelectCommand(tsChannel, TS_CRC, data16[0]);
|
handlePageSelectCommand(tsChannel, TS_CRC);
|
||||||
break;
|
break;
|
||||||
case TS_GET_STRUCT:
|
case TS_GET_STRUCT:
|
||||||
handleGetStructContent(tsChannel, data16[0], data16[1]);
|
handleGetStructContent(tsChannel, offset, count);
|
||||||
break;
|
break;
|
||||||
case TS_CHUNK_WRITE_COMMAND:
|
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;
|
break;
|
||||||
case TS_SINGLE_WRITE_COMMAND:
|
case TS_SINGLE_WRITE_COMMAND:
|
||||||
{
|
{
|
||||||
uint8_t value = data[4];
|
uint8_t value = data[4];
|
||||||
handleWriteValueCommand(tsChannel, TS_CRC, data16[0], data16[1], value);
|
handleWriteValueCommand(tsChannel, TS_CRC, offset, value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TS_CRC_CHECK_COMMAND:
|
case TS_CRC_CHECK_COMMAND:
|
||||||
handleCrc32Check(tsChannel, TS_CRC, data16[0]);
|
handleCrc32Check(tsChannel, TS_CRC, offset, count);
|
||||||
break;
|
break;
|
||||||
case TS_BURN_COMMAND:
|
case TS_BURN_COMMAND:
|
||||||
handleBurnCommand(tsChannel, TS_CRC, data16[0]);
|
handleBurnCommand(tsChannel, TS_CRC);
|
||||||
break;
|
break;
|
||||||
case TS_READ_COMMAND:
|
case TS_READ_COMMAND:
|
||||||
handlePageReadCommand(tsChannel, TS_CRC, data16[0], data16[1], data16[2]);
|
handlePageReadCommand(tsChannel, TS_CRC, offset, count);
|
||||||
break;
|
break;
|
||||||
case TS_TEST_COMMAND:
|
case TS_TEST_COMMAND:
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
|
|
|
@ -75,14 +75,12 @@ typedef pre_packed struct
|
||||||
|
|
||||||
typedef pre_packed struct
|
typedef pre_packed struct
|
||||||
post_packed {
|
post_packed {
|
||||||
short int page;
|
|
||||||
short int offset;
|
short int offset;
|
||||||
short int count;
|
short int count;
|
||||||
} TunerStudioWriteChunkRequest;
|
} TunerStudioWriteChunkRequest;
|
||||||
|
|
||||||
typedef pre_packed struct
|
typedef pre_packed struct
|
||||||
post_packed {
|
post_packed {
|
||||||
short int page;
|
|
||||||
short int offset;
|
short int offset;
|
||||||
short int count;
|
short int count;
|
||||||
} TunerStudioReadRequest;
|
} TunerStudioReadRequest;
|
||||||
|
|
|
@ -46,16 +46,14 @@ enable2ndByteCanID = false
|
||||||
|
|
||||||
endianness = little
|
endianness = little
|
||||||
nPages = 1
|
nPages = 1
|
||||||
|
|
||||||
|
|
||||||
pageIdentifier = "\x00\x00"
|
pageIdentifier = "\x00\x00"
|
||||||
pageReadCommand = "@@TS_READ_COMMAND_char@@\x00\x00%2o%2c"
|
pageReadCommand = "@@TS_READ_COMMAND_char@@%2o%2c"
|
||||||
burnCommand = "@@TS_BURN_COMMAND_char@@\x00\x00"
|
burnCommand = "@@TS_BURN_COMMAND_char@@"
|
||||||
pageActivate = "@@TS_PAGE_COMMAND_char@@\x00\x00"
|
pageActivate = "@@TS_PAGE_COMMAND_char@@"
|
||||||
pageValueWrite = "@@TS_SINGLE_WRITE_COMMAND_char@@\x00\x00%2o%v"
|
pageValueWrite = "@@TS_SINGLE_WRITE_COMMAND_char@@%2o%v"
|
||||||
pageChunkWrite = "@@TS_CHUNK_WRITE_COMMAND_char@@\x00\x00%2o%2c%v"
|
pageChunkWrite = "@@TS_CHUNK_WRITE_COMMAND_char@@%2o%2c%v"
|
||||||
; todo: make this command shorter one day, no need to have all these zeros
|
crc32CheckCommand = "@@TS_CRC_CHECK_COMMAND@@%2o%2c"
|
||||||
crc32CheckCommand = "k\x00\x00\x00\x00\x00\x00"
|
|
||||||
retrieveConfigError = "e"
|
retrieveConfigError = "e"
|
||||||
|
|
||||||
;communication settings
|
;communication settings
|
||||||
|
|
|
@ -362,11 +362,10 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
int remainingSize = image.getSize() - offset;
|
int remainingSize = image.getSize() - offset;
|
||||||
int requestSize = Math.min(remainingSize, Fields.BLOCKING_FACTOR);
|
int requestSize = Math.min(remainingSize, Fields.BLOCKING_FACTOR);
|
||||||
|
|
||||||
byte packet[] = new byte[7];
|
byte packet[] = new byte[5];
|
||||||
packet[0] = Fields.TS_READ_COMMAND;
|
packet[0] = Fields.TS_READ_COMMAND;
|
||||||
putShort(packet, 1, 0); // page
|
putShort(packet, 1, swap16(offset));
|
||||||
putShort(packet, 3, swap16(offset));
|
putShort(packet, 3, swap16(requestSize));
|
||||||
putShort(packet, 5, swap16(requestSize));
|
|
||||||
|
|
||||||
byte[] response = executeCommand(packet, "load image offset=" + offset);
|
byte[] response = executeCommand(packet, "load image offset=" + offset);
|
||||||
|
|
||||||
|
@ -408,8 +407,10 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
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[7];
|
byte packet[] = new byte[5];
|
||||||
packet[0] = COMMAND_CRC_CHECK_COMMAND;
|
packet[0] = COMMAND_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, RESPONSE_OK) && response.length == 5) {
|
if (checkResponseCode(response, RESPONSE_OK) && response.length == 5) {
|
||||||
|
@ -472,11 +473,10 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
|
|
||||||
isBurnPending = true;
|
isBurnPending = true;
|
||||||
|
|
||||||
byte packet[] = new byte[7 + size];
|
byte packet[] = new byte[5 + size];
|
||||||
packet[0] = COMMAND_CHUNK_WRITE;
|
packet[0] = COMMAND_CHUNK_WRITE;
|
||||||
putShort(packet, 1, 0); // page
|
putShort(packet, 1, swap16(offset));
|
||||||
putShort(packet, 3, swap16(offset));
|
putShort(packet, 3, swap16(size));
|
||||||
putShort(packet, 5, swap16(size));
|
|
||||||
|
|
||||||
System.arraycopy(content, offset, packet, 7, size);
|
System.arraycopy(content, offset, packet, 7, size);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ public interface BinaryProtocolCommands {
|
||||||
byte RESPONSE_BURN_OK = Fields.TS_RESPONSE_BURN_OK;
|
byte RESPONSE_BURN_OK = Fields.TS_RESPONSE_BURN_OK;
|
||||||
byte RESPONSE_COMMAND_OK = Fields.TS_RESPONSE_COMMAND_OK;
|
byte RESPONSE_COMMAND_OK = Fields.TS_RESPONSE_COMMAND_OK;
|
||||||
char COMMAND_PROTOCOL = Fields.TS_COMMAND_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_CRC_CHECK_COMMAND = Fields.TS_CRC_CHECK_COMMAND;
|
||||||
char COMMAND_CHUNK_WRITE = Fields.TS_CHUNK_WRITE_COMMAND;
|
char COMMAND_CHUNK_WRITE = Fields.TS_CHUNK_WRITE_COMMAND;
|
||||||
char COMMAND_BURN = Fields.TS_BURN_COMMAND;
|
char COMMAND_BURN = Fields.TS_BURN_COMMAND;
|
||||||
|
|
Loading…
Reference in New Issue