TunerStudio Cleanup (#649)

* TS cleanup

* remove fl_protocol

* fix build
This commit is contained in:
Matthew Kennedy 2019-01-05 04:55:21 -08:00 committed by rusefi
parent 0c6f361181
commit a12a62b57a
5 changed files with 35 additions and 151 deletions

View File

@ -72,8 +72,8 @@
#include "malfunction_central.h"
#include "console_io.h"
#include "crc.h"
#include "fl_protocol.h"
#include "bluetooth.h"
#include "tunerstudio_io.h"
#include <string.h>
#include "engine_configuration.h"
@ -437,15 +437,10 @@ void handleBurnCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint1
scheduleMsg(&tsLogger, "BURN in %dms", currentTimeMillis() - nowMs);
}
static TunerStudioReadRequest readRequest;
static TunerStudioWriteChunkRequest writeChunkRequest;
static TunerStudioOchRequest ochRequest;
static short int pageIn;
static bool isKnownCommand(char command) {
return command == TS_HELLO_COMMAND || command == TS_READ_COMMAND || command == TS_OUTPUT_COMMAND
|| command == TS_PAGE_COMMAND || command == TS_BURN_COMMAND || command == TS_SINGLE_WRITE_COMMAND
|| command == TS_LEGACY_HELLO_COMMAND || command == TS_CHUNK_WRITE_COMMAND || command == TS_EXECUTE
|| command == TS_CHUNK_WRITE_COMMAND || command == TS_EXECUTE
|| command == TS_IO_TEST_COMMAND
|| command == TS_GET_FILE_RANGE
|| command == TS_TOOTH_COMMAND
@ -457,8 +452,6 @@ static bool isKnownCommand(char command) {
void runBinaryProtocolLoop(ts_channel_s *tsChannel, bool isConsoleRedirect) {
int wasReady = false;
bool isFirstByte = true;
while (true) {
int isReady = sr5IsReady(isConsoleRedirect);
if (!isReady) {
@ -491,14 +484,6 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel, bool isConsoleRedirect) {
}
onDataArrived();
if (isFirstByte) {
if (isStartOfFLProtocol(firstByte)) {
}
}
isFirstByte = false;
// scheduleMsg(logger, "Got first=%x=[%c]", firstByte, firstByte);
if (handlePlainCommand(tsChannel, firstByte))
continue;
@ -511,7 +496,7 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel, bool isConsoleRedirect) {
}
// scheduleMsg(logger, "Got secondByte=%x=[%c]", secondByte, secondByte);
uint32_t incomingPacketSize = firstByte * 256 + secondByte;
uint16_t incomingPacketSize = firstByte << 8 | secondByte;
if (incomingPacketSize == BINARY_SWITCH_TAG) {
// we are here if we get a binary switch request while already in binary mode. We will just ignore it.
@ -624,15 +609,12 @@ void handleQueryCommand(ts_channel_s *tsChannel, ts_response_format_e mode) {
* @brief 'Output' command sends out a snapshot of current values
*/
void handleOutputChannelsCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count) {
if (sizeof(TunerStudioOutputChannels) < offset + count) {
scheduleMsg(&tsLogger, "invalid offset/count %d/%d", offset, count);
sendErrorCode(tsChannel);
return;
}
tsState.outputChannelsCommandCounter++;
prepareTunerStudioOutputs();
// this method is invoked too often to print any debug information
@ -698,78 +680,32 @@ static void handleExecuteCommand(ts_channel_s *tsChannel, char *data, int incomi
* @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) {
// Bail fast if guaranteed not to be a plain command
if(command == 0)
{
return false;
}
else if (command == TS_HELLO_COMMAND) {
scheduleMsg(&tsLogger, "Got naked Query command");
handleQueryCommand(tsChannel, TS_PLAIN);
return true;
} else if (command == TS_TEST_COMMAND || command == 'T') {
handleTestCommand(tsChannel);
return true;
} else if (command == TS_PAGE_COMMAND) {
int received = sr5ReadData(tsChannel, (uint8_t * )&pageIn, sizeof(pageIn));
if (received != 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 = sr5ReadData(tsChannel, (uint8_t * )&page, sizeof(page));
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 received = sr5ReadData(tsChannel, (uint8_t * )&writeChunkRequest, sizeof(writeChunkRequest));
if (received != sizeof(writeChunkRequest)) {
scheduleMsg(&tsLogger, "ERROR: Not enough for plain chunk write header: %d", received);
tsState.errorCounter++;
return true;
}
received = sr5ReadData(tsChannel, (uint8_t * )&tsChannel->crcReadBuffer, writeChunkRequest.count);
if (received != writeChunkRequest.count) {
scheduleMsg(&tsLogger, "ERROR: Not enough for plain chunk write content: %d while expecting %d", received,
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 received = sr5ReadData(tsChannel, (uint8_t * )&readRequest, sizeof(readRequest));
if (received != 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) {
int received = sr5ReadData(tsChannel, (uint8_t * )&ochRequest, sizeof(ochRequest));
if (received != sizeof(ochRequest)) {
tunerStudioError("Not enough for OutputChannelsCommand");
return true;
}
//scheduleMsg(logger, "Got naked Channels???");
handleOutputChannelsCommand(tsChannel, TS_PLAIN, ochRequest.offset, ochRequest.count);
return true;
} else if (command == TS_LEGACY_HELLO_COMMAND) {
tunerStudioDebug("ignoring LEGACY_HELLO_COMMAND");
return true;
} else if (command == TS_COMMAND_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."
*/
tunerStudioDebug("not ignoring F");
sr5WriteData(tsChannel, (const uint8_t *) PROTOCOL, strlen(PROTOCOL));
return true;
} else {
// This wasn't a valid command
return false;
}
}
@ -778,7 +714,13 @@ bool handlePlainCommand(ts_channel_s *tsChannel, uint8_t command) {
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) {
// Output command first since it's popular
if (command == TS_OUTPUT_COMMAND) {
uint16_t offset = *(uint16_t *) (data);
uint16_t count = *(uint16_t *) (data + 2);
handleOutputChannelsCommand(tsChannel, TS_CRC, offset, count);
} else if (command == TS_HELLO_COMMAND) {
tunerStudioDebug("got Query command");
handleQueryCommand(tsChannel, TS_CRC);
} else if (command == TS_GET_FIRMWARE_VERSION) {
@ -787,10 +729,6 @@ int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomin
handleGetText(tsChannel);
} else if (command == TS_EXECUTE) {
handleExecuteCommand(tsChannel, data, incomingPacketSize - 1);
} else if (command == TS_OUTPUT_COMMAND) {
uint16_t offset = *(uint16_t *) (data);
uint16_t count = *(uint16_t *) (data + 2);
handleOutputChannelsCommand(tsChannel, TS_CRC, offset, count);
} else if (command == TS_PAGE_COMMAND) {
uint16_t page = *(uint16_t *) data;
handlePageSelectCommand(tsChannel, TS_CRC, page);
@ -824,20 +762,6 @@ int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomin
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 if (command == TS_IO_TEST_COMMAND) {
uint16_t subsystem = SWAP_UINT16(*(short*)&data[0]);
uint16_t index = SWAP_UINT16(*(short*)&data[2]);

View File

@ -59,19 +59,20 @@ typedef struct {
input_queue_t fifoRxQueue;
} uart_dma_s;
#define TS_HELLO_COMMAND_DEPRECATED 'H' // 0x48
#define TS_HELLO_COMMAND 'S' // 0x53 queryCommand
// These commands are used exclusively by the rusEfi console
#define TS_TEST_COMMAND 't' // 0x74
#define TS_TOOTH_COMMAND 'L' // 0x4C
#define TS_LEGACY_HELLO_COMMAND 'Q' // 0x51
#define TS_GET_TEXT 'G' // 0x47
#define TS_GET_FILE_RANGE '2'
#define TS_EXECUTE 'E' // 0x45
// These commands are used by TunerStudio and the rusEfi console
#define TS_HELLO_COMMAND 'S' // 0x53 queryCommand
#define TS_OUTPUT_COMMAND 'O' // 0x4F ochGetCommand
#define TS_READ_COMMAND 'R' // 0x52
#define TS_PAGE_COMMAND 'P' // 0x50
#define TS_COMMAND_F 'F' // 0x46
#define TS_EXECUTE 'E' // 0x45
#define TS_GET_TEXT 'G' // 0x47
#define TS_GET_FILE_RANGE '2'
#define TS_GET_FIRMWARE_VERSION 'V' // versionInfo
#define TS_TOOTH_COMMAND 'L' // 0x4C
#define TS_SINGLE_WRITE_COMMAND 'W' // 0x57 pageValueWrite
#define TS_CHUNK_WRITE_COMMAND 'C' // 0x43 pageChunkWrite

View File

@ -3,6 +3,5 @@ CONSOLESRC =
CONSOLE_SRC_CPP = $(PROJECT_DIR)/console/status_loop.cpp \
$(PROJECT_DIR)/console/console_io.cpp \
$(PROJECT_DIR)/console/fl_binary/fl_protocol.cpp \
$(PROJECT_DIR)/console/eficonsole.cpp
$(PROJECT_DIR)/console/eficonsole.cpp

View File

@ -1,13 +0,0 @@
/*
* @file fl_protocol.cpp
*
* @date Mar 15, 2017
* @author Andrey Belomutskiy, (c) 2012-2018
*/
#include "fl_protocol.h"
bool isStartOfFLProtocol(uint8_t firstByte) {
return firstByte == START_TAG;
}

View File

@ -1,27 +0,0 @@
/*
* @file fl_protocol.h
*
* @date Mar 14, 2017
* @author Andrey Belomutskiy, (c) 2012-2017
*/
#ifndef CONSOLE_FL_BINARY_FT_PROTOCOL_H_
#define CONSOLE_FL_BINARY_FT_PROTOCOL_H_
#include "rusefi_types.h"
#define START_TAG 0xAA
#define MAGIC_TAG 0xBB
#define END_TAG 0xCC
#define FL_Firmware_version 0x0002
#define FL_Interface_Version 0x0000
#define FL_Compiler_Version 0xEEF2
#define FL_Decoder_Name 0xEEEE
#define FL_Firmware_Build_Date 0xEEF0B
#define FL_Max_Packet_Size 0x0004
#define FL_Operating_System 0xEEF4
bool isStartOfFLProtocol(uint8_t firstByte);
#endif /* CONSOLE_FL_BINARY_FT_PROTOCOL_H_ */