From 99b9391ae80e7a9ba6b112b1cb398f2cd871bfe7 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 9 Dec 2020 01:23:02 -0600 Subject: [PATCH] start peeling out ts commands (#2045) * start peeling out commands * guard Co-authored-by: Matthew Kennedy --- firmware/console/binary/tunerstudio.cpp | 32 ++++++------------- firmware/console/binary/tunerstudio.mk | 1 + .../console/binary/tunerstudio_commands.cpp | 29 +++++++++++++++++ firmware/console/binary/tunerstudio_impl.h | 20 ++++++++++++ 4 files changed, 59 insertions(+), 23 deletions(-) create mode 100644 firmware/console/binary/tunerstudio_commands.cpp diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index c7d7434c73..0766a48625 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -211,6 +211,10 @@ static void sendErrorCode(ts_channel_s *tsChannel, uint8_t code) { sr5WriteCrcPacket(tsChannel, code, nullptr, 0); } +void TunerStudio::sendErrorCode(ts_channel_s* tsChannel, uint8_t code) { + ::sendErrorCode(tsChannel, code); +} + static void handlePageSelectCommand(ts_channel_s *tsChannel, ts_response_format_e mode) { tsState.pageCommandCounter++; @@ -460,7 +464,7 @@ static bool isKnownCommand(char command) { || command == TS_GET_CONFIG_ERROR; } -TunerStudioBase tsInstance; +TunerStudio tsInstance(&tsLogger); static void tsProcessOne(ts_channel_s* tsChannel) { validateStack("communication", STACK_USAGE_COMMUNICATION, 128); @@ -616,24 +620,6 @@ void handleQueryCommand(ts_channel_s *tsChannel, ts_response_format_e mode) { sr5SendResponse(tsChannel, mode, (const uint8_t *)signature, strlen(signature) + 1); } -/** - * @brief 'Output' command sends out a snapshot of current values - * Gauges refresh - */ -static void handleOutputChannelsCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count) { - if (offset + count > sizeof(TunerStudioOutputChannels)) { - scheduleMsg(&tsLogger, "TS: Version Mismatch? Too much outputs requested %d/%d/%d", offset, count, - sizeof(TunerStudioOutputChannels)); - sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE); - return; - } - - tsState.outputChannelsCommandCounter++; - prepareTunerStudioOutputs(); - // this method is invoked too often to print any debug information - sr5SendResponse(tsChannel, mode, ((const uint8_t *) &tsOutputChannels) + offset, count); -} - /** * rusEfi own test command */ @@ -659,10 +645,10 @@ static void handleTestCommand(ts_channel_s *tsChannel) { extern CommandHandler console_line_callback; -static void handleGetVersion(ts_channel_s *tsChannel, ts_response_format_e mode) { +static void handleGetVersion(ts_channel_s *tsChannel) { static char versionBuffer[32]; chsnprintf(versionBuffer, sizeof(versionBuffer), "rusEFI v%d@%s", getRusEfiVersion(), VCS_VERSION); - sr5SendResponse(tsChannel, mode, (const uint8_t *) versionBuffer, strlen(versionBuffer) + 1); + sr5SendResponse(tsChannel, TS_CRC, (const uint8_t *) versionBuffer, strlen(versionBuffer) + 1); } static void handleGetText(ts_channel_s *tsChannel) { @@ -743,14 +729,14 @@ int TunerStudioBase::handleCrcCommand(ts_channel_s *tsChannel, char *data, int i switch(command) { case TS_OUTPUT_COMMAND: - handleOutputChannelsCommand(tsChannel, TS_CRC, offset, count); + cmdOutputChannels(tsChannel, offset, count); break; case TS_HELLO_COMMAND: tunerStudioDebug("got Query command"); handleQueryCommand(tsChannel, TS_CRC); break; case TS_GET_FIRMWARE_VERSION: - handleGetVersion(tsChannel, TS_CRC); + handleGetVersion(tsChannel); break; #if EFI_FILE_LOGGING || EFI_SIMULATOR case TS_SD_R_COMMAND: diff --git a/firmware/console/binary/tunerstudio.mk b/firmware/console/binary/tunerstudio.mk index eae9121f0b..ab0961b22d 100644 --- a/firmware/console/binary/tunerstudio.mk +++ b/firmware/console/binary/tunerstudio.mk @@ -1,5 +1,6 @@ TUNERSTUDIO_SRC_CPP = $(PROJECT_DIR)/console/binary/tunerstudio_io.cpp \ $(PROJECT_DIR)/console/binary/tunerstudio.cpp \ + $(PROJECT_DIR)/console/binary/tunerstudio_commands.cpp \ $(PROJECT_DIR)/console/binary/bluetooth.cpp \ $(PROJECT_DIR)/console/binary/signature.cpp diff --git a/firmware/console/binary/tunerstudio_commands.cpp b/firmware/console/binary/tunerstudio_commands.cpp new file mode 100644 index 0000000000..913703e535 --- /dev/null +++ b/firmware/console/binary/tunerstudio_commands.cpp @@ -0,0 +1,29 @@ +#include "global.h" + +#include "tunerstudio_impl.h" +#include "tunerstudio.h" +#include "tunerstudio_io.h" + +#include "status_loop.h" + +#if EFI_TUNER_STUDIO + +/** + * @brief 'Output' command sends out a snapshot of current values + * Gauges refresh + */ +void TunerStudio::cmdOutputChannels(ts_channel_s *tsChannel, uint16_t offset, uint16_t count) { + if (offset + count > sizeof(TunerStudioOutputChannels)) { + scheduleMsg(tsLogger, "TS: Version Mismatch? Too much outputs requested %d/%d/%d", offset, count, + sizeof(TunerStudioOutputChannels)); + sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE); + return; + } + + tsState.outputChannelsCommandCounter++; + prepareTunerStudioOutputs(); + // this method is invoked too often to print any debug information + sr5SendResponse(tsChannel, TS_CRC, ((const uint8_t *) &tsOutputChannels) + offset, count); +} + +#endif // EFI_TUNER_STUDIO diff --git a/firmware/console/binary/tunerstudio_impl.h b/firmware/console/binary/tunerstudio_impl.h index 14459d4d11..d5e2a121f0 100644 --- a/firmware/console/binary/tunerstudio_impl.h +++ b/firmware/console/binary/tunerstudio_impl.h @@ -1,8 +1,28 @@ #pragma once +#include + class ts_channel_s; class TunerStudioBase { public: int handleCrcCommand(ts_channel_s *tsChannel, char *data, int incomingPacketSize); + +protected: + virtual void cmdOutputChannels(ts_channel_s *tsChannel, uint16_t offset, uint16_t count) = 0; +}; + +class TunerStudio : public TunerStudioBase { +public: + TunerStudio(Logging* logger) + : tsLogger(logger) + { + } + + void cmdOutputChannels(ts_channel_s *tsChannel, uint16_t offset, uint16_t count) override; + +private: + void sendErrorCode(ts_channel_s* tsChannel, uint8_t code); + + Logging* tsLogger; };