int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomingPacketSize) { char command = data[0]; data++; if (command == TS_HELLO_COMMAND || command == TS_HELLO_COMMAND_DEPRECATED) { tunerStudioDebug("got Query command"); handleQueryCommand(tsChannel, TS_CRC); } else if (command == TS_GET_TEXT) { handleGetText(tsChannel); } else if (command == TS_EXECUTE) { handleExecuteCommand(tsChannel, data, incomingPacketSize - 1); } else if (command == TS_OUTPUT_COMMAND) { handleOutputChannelsCommand(tsChannel, TS_CRC); } else if (command == TS_PAGE_COMMAND) { uint16_t page = *(uint16_t *) data; handlePageSelectCommand(tsChannel, TS_CRC, page); } else if (command == TS_CHUNK_WRITE_COMMAND) { currentPageId = *(uint16_t *) data; uint16_t offset = *(uint16_t *) (data + 2); uint16_t count = *(uint16_t *) (data + 4); handleWriteChunkCommand(tsChannel, TS_CRC, offset, count, data + sizeof(TunerStudioWriteChunkRequest)); } else if (command == TS_SINGLE_WRITE_COMMAND) { uint16_t page = *(uint16_t *) data; uint16_t offset = *(uint16_t *) (data + 2); uint8_t value = data[4]; handleWriteValueCommand(tsChannel, TS_CRC, page, offset, value); } else if (command == TS_CRC_CHECK_COMMAND) { uint16_t page = *(uint16_t *) data; uint16_t offset = *(uint16_t *) (data + 2); uint16_t count = *(uint16_t *) (data + 4); handleCrc32Check(tsChannel, TS_CRC, page, offset, count); } else if (command == TS_BURN_COMMAND) { uint16_t page = *(uint16_t *) data; handleBurnCommand(tsChannel, TS_CRC, page); } else if (command == TS_READ_COMMAND) { uint16_t page = *(uint16_t *) data; uint16_t offset = *(uint16_t *) (data + 2); uint16_t count = *(uint16_t *) (data + 4); handlePageReadCommand(tsChannel, TS_CRC, page, offset, count); } else if (command == 't' || command == 'T') { handleTestCommand(tsChannel); } else if (command == TS_LEGACY_HELLO_COMMAND) { /** * 'Q' is the query command used for compatibility with older ECUs */ tunerStudioDebug("ignoring Q"); } else if (command == TS_COMMAND_F) { tunerStudioDebug("ignoring F"); /** * http://www.msextra.com/forums/viewtopic.php?f=122&t=48327 * Response from TS support: This is an optional command * * "The F command is used to find what ini. file needs to be loaded in TunerStudio to match the controller. * If you are able to just make your firmware ignore the command that would work. * Currently on some firmware versions the F command is not used and is just ignored by the firmware as a unknown command." */ } else { tunerStudioError("ERROR: ignoring unexpected command"); return false; } return true; }
int tunerStudioHandleCommand(short command) { if (command == 'H') { handleQueryCommand(); } else if (command == 'O') { handleOutputChannelsCommand(); } else if (command == 'W') { handleValueWriteCommand(); } else if (command == 'B') { handleBurnCommand(); } else if (command == 'C') { handlePageReadCommand(); } else if (command == 't' || command == 'T') { handleTestCommand(); } else if (command == 'F') { tunerStudioDebug("ignoring F"); /** * http://www.msextra.com/forums/viewtopic.php?f=122&t=48327 * Response from TS support: This is an optional command * * "The F command is used to find what ini. file needs to be loaded in TunerStudio to match the controller. * If you are able to just make your firmware ignore the command that would work. * Currently on some firmware versions the F command is not used and is just ignored by the firmware as a unknown command." */ } else { #if EFI_TUNER_STUDIO_OVER_USB /** * With TTL there is a real chance of corrupted messages. * With serial-over-USB we are not expecting communication errors */ // fatal("unexpected TunerStudio command in USB mode"); #endif /* EFI_TUNER_STUDIO_OVER_USB */ tsState.errorCounter++; return FALSE; } return TRUE; }
static bool handlePlainCommand(uint8_t command) { if (command == TS_HELLO_COMMAND) { scheduleMsg(&logger, "Got naked Query command"); handleQueryCommand(TS_PLAIN); return true; } else if (command == 't' || command == 'T') { handleTestCommand(); return true; } else if (command == TS_PAGE_COMMAND) { int recieved = chSequentialStreamRead(getTsSerialDevice(), (uint8_t *)&pageIn, sizeof(pageIn)); // todo: validate 'recieved' value handlePageSelectCommand(TS_PLAIN, pageIn); return true; } else if (command == TS_READ_COMMAND) { //scheduleMsg(&logger, "Got naked READ PAGE???"); int recieved = chSequentialStreamRead(getTsSerialDevice(), (uint8_t *)&readRequest, sizeof(readRequest)); if (recieved != sizeof(readRequest)) { // todo: handler error return true; } handlePageReadCommand(TS_PLAIN, readRequest.page, readRequest.offset, readRequest.count); return true; } else if (command == TS_OUTPUT_COMMAND) { //scheduleMsg(&logger, "Got naked Channels???"); handleOutputChannelsCommand(TS_PLAIN); return true; } else if (command == 'F') { tunerStudioDebug("not ignoring F"); tunerStudioWriteData((const uint8_t *) PROTOCOL, strlen(PROTOCOL)); return true; } else { return false; } }
/** * @return true if legacy command was processed, false otherwise */ bool handlePlainCommand(ts_channel_s *tsChannel, uint8_t command) { if (command == TS_HELLO_COMMAND || command == TS_HELLO_COMMAND_DEPRECATED) { scheduleMsg(&tsLogger, "Got naked Query command"); handleQueryCommand(tsChannel, TS_PLAIN); return true; } else if (command == 't' || command == 'T') { handleTestCommand(tsChannel); return true; } else if (command == TS_PAGE_COMMAND) { int recieved = chnReadTimeout(tsChannel->channel, (uint8_t * )&pageIn, sizeof(pageIn), TS_READ_TIMEOUT); if (recieved != sizeof(pageIn)) { tunerStudioError("ERROR: not enough for PAGE"); return true; } handlePageSelectCommand(tsChannel, TS_PLAIN, pageIn); return true; } else if (command == TS_BURN_COMMAND) { scheduleMsg(&tsLogger, "Got naked BURN"); uint16_t page; int recieved = chnReadTimeout(tsChannel->channel, (uint8_t * )&page, sizeof(page), TS_READ_TIMEOUT); if (recieved != sizeof(page)) { tunerStudioError("ERROR: Not enough for plain burn"); return true; } handleBurnCommand(tsChannel, TS_PLAIN, page); return true; } else if (command == TS_CHUNK_WRITE_COMMAND) { scheduleMsg(&tsLogger, "Got naked CHUNK_WRITE"); int recieved = chnReadTimeout(tsChannel->channel, (uint8_t * )&writeChunkRequest, sizeof(writeChunkRequest), TS_READ_TIMEOUT); if (recieved != sizeof(writeChunkRequest)) { scheduleMsg(&tsLogger, "ERROR: Not enough for plain chunk write header: %d", recieved); tsState.errorCounter++; return true; } recieved = chnReadTimeout(tsChannel->channel, (uint8_t * )&tsChannel->crcReadBuffer, writeChunkRequest.count, TS_READ_TIMEOUT); if (recieved != writeChunkRequest.count) { scheduleMsg(&tsLogger, "ERROR: Not enough for plain chunk write content: %d while expecting %d", recieved, writeChunkRequest.count); tsState.errorCounter++; return true; } currentPageId = writeChunkRequest.page; handleWriteChunkCommand(tsChannel, TS_PLAIN, writeChunkRequest.offset, writeChunkRequest.count, (uint8_t *) &tsChannel->crcReadBuffer); return true; } else if (command == TS_READ_COMMAND) { //scheduleMsg(logger, "Got naked READ PAGE???"); int recieved = chnReadTimeout(tsChannel->channel, (uint8_t * )&readRequest, sizeof(readRequest), TS_READ_TIMEOUT); if (recieved != sizeof(readRequest)) { tunerStudioError("Not enough for plain read header"); return true; } handlePageReadCommand(tsChannel, TS_PLAIN, readRequest.page, readRequest.offset, readRequest.count); return true; } else if (command == TS_OUTPUT_COMMAND) { //scheduleMsg(logger, "Got naked Channels???"); handleOutputChannelsCommand(tsChannel, TS_PLAIN); return true; } else if (command == TS_LEGACY_HELLO_COMMAND) { tunerStudioDebug("ignoring LEGACY_HELLO_COMMAND"); return true; } else if (command == TS_COMMAND_F) { tunerStudioDebug("not ignoring F"); tunerStudioWriteData(tsChannel, (const uint8_t *) PROTOCOL, strlen(PROTOCOL)); return true; } else { return false; } }