steps towards better commands encapsulation

This commit is contained in:
rusefi 2022-04-14 01:06:44 -04:00
parent fcf9a42bea
commit d7da81b5c2
3 changed files with 25 additions and 13 deletions

View File

@ -160,7 +160,7 @@ void TunerStudio::sendErrorCode(TsChannelBase* tsChannel, uint8_t code) {
::sendErrorCode(tsChannel, code); ::sendErrorCode(tsChannel, code);
} }
static void handlePageSelectCommand(TsChannelBase *tsChannel, ts_response_format_e mode) { void TunerStudio::handlePageSelectCommand(TsChannelBase *tsChannel, ts_response_format_e mode) {
tsState.pageCommandCounter++; tsState.pageCommandCounter++;
sendOkResponse(tsChannel, mode); sendOkResponse(tsChannel, mode);
@ -278,7 +278,7 @@ bool rebootForPresetPending = false;
* This command is needed to make the whole transfer a bit faster * This command is needed to make the whole transfer a bit faster
* @note See also handleWriteValueCommand * @note See also handleWriteValueCommand
*/ */
static void handleWriteChunkCommand(TsChannelBase* tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count, void TunerStudio::handleWriteChunkCommand(TsChannelBase* tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count,
void *content) { void *content) {
tsState.writeChunkCommandCounter++; tsState.writeChunkCommandCounter++;
@ -455,7 +455,7 @@ static void handleTestCommand(TsChannelBase* tsChannel) {
* Query with CRC takes place while re-establishing connection * Query with CRC takes place while re-establishing connection
* Query without CRC takes place on TunerStudio startup * Query without CRC takes place on TunerStudio startup
*/ */
static void handleQueryCommand(TsChannelBase* tsChannel, ts_response_format_e mode) { void TunerStudio::handleQueryCommand(TsChannelBase* tsChannel, ts_response_format_e mode) {
tsState.queryCommandCounter++; tsState.queryCommandCounter++;
#if EFI_TUNER_STUDIO_VERBOSE #if EFI_TUNER_STUDIO_VERBOSE
efiPrintf("got S/H (queryCommand) mode=%d", mode); efiPrintf("got S/H (queryCommand) mode=%d", mode);
@ -470,7 +470,7 @@ static void handleQueryCommand(TsChannelBase* tsChannel, ts_response_format_e mo
* *
* @return true if legacy command was processed, false otherwise * @return true if legacy command was processed, false otherwise
*/ */
static bool handlePlainCommand(TsChannelBase* tsChannel, uint8_t command) { bool TunerStudio::handlePlainCommand(TsChannelBase* tsChannel, uint8_t command) {
// Bail fast if guaranteed not to be a plain command // Bail fast if guaranteed not to be a plain command
if (command == 0) { if (command == 0) {
return false; return false;
@ -529,7 +529,7 @@ static int tsProcessOne(TsChannelBase* tsChannel) {
return -1; return -1;
} }
if (handlePlainCommand(tsChannel, firstByte)) { if (tsInstance.handlePlainCommand(tsChannel, firstByte)) {
return -1; return -1;
} }
@ -663,7 +663,7 @@ static void handleGetText(TsChannelBase* tsChannel) {
} }
#endif // EFI_TEXT_LOGGING #endif // EFI_TEXT_LOGGING
static void handleExecuteCommand(TsChannelBase* tsChannel, char *data, int incomingPacketSize) { void TunerStudio::handleExecuteCommand(TsChannelBase* tsChannel, char *data, int incomingPacketSize) {
data[incomingPacketSize] = 0; data[incomingPacketSize] = 0;
char *trimmed = efiTrim(data); char *trimmed = efiTrim(data);
#if EFI_SIMULATOR #if EFI_SIMULATOR
@ -676,7 +676,7 @@ static void handleExecuteCommand(TsChannelBase* tsChannel, char *data, int incom
static int transmitted = 0; static int transmitted = 0;
int TunerStudioBase::handleCrcCommand(TsChannelBase* tsChannel, char *data, int incomingPacketSize) { int TunerStudio::handleCrcCommand(TsChannelBase* tsChannel, char *data, int incomingPacketSize) {
ScopePerf perf(PE::TunerStudioHandleCrcCommand); ScopePerf perf(PE::TunerStudioHandleCrcCommand);
char command = data[0]; char command = data[0];

View File

@ -1,12 +1,20 @@
/**
* @file tunerstudio_impl.h
*/
#pragma once #pragma once
#include <cstdint> #include <cstdint>
struct TsChannelBase; struct TsChannelBase;
typedef enum {
TS_PLAIN = 0,
TS_CRC = 1
} ts_response_format_e;
class TunerStudioBase { class TunerStudioBase {
public: public:
int handleCrcCommand(TsChannelBase* tsChannel, char *data, int incomingPacketSize);
protected: protected:
virtual void cmdOutputChannels(TsChannelBase* tsChannel, uint16_t offset, uint16_t count) = 0; virtual void cmdOutputChannels(TsChannelBase* tsChannel, uint16_t offset, uint16_t count) = 0;
@ -14,7 +22,15 @@ protected:
class TunerStudio : public TunerStudioBase { class TunerStudio : public TunerStudioBase {
public: public:
int handleCrcCommand(TsChannelBase* tsChannel, char *data, int incomingPacketSize);
bool handlePlainCommand(TsChannelBase* tsChannel, uint8_t command);
void cmdOutputChannels(TsChannelBase* tsChannel, uint16_t offset, uint16_t count) override; void cmdOutputChannels(TsChannelBase* tsChannel, uint16_t offset, uint16_t count) override;
void handleQueryCommand(TsChannelBase* tsChannel, ts_response_format_e mode);
void handleExecuteCommand(TsChannelBase* tsChannel, char *data, int incomingPacketSize);
void handlePageSelectCommand(TsChannelBase *tsChannel, ts_response_format_e mode);
void handleWriteChunkCommand(TsChannelBase* tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count,
void *content);
private: private:
void sendErrorCode(TsChannelBase* tsChannel, uint8_t code); void sendErrorCode(TsChannelBase* tsChannel, uint8_t code);

View File

@ -8,6 +8,7 @@
#pragma once #pragma once
#include "global.h" #include "global.h"
#include "tunerstudio_impl.h"
#if (!TS_NO_PRIMARY && defined(TS_PRIMARY_PORT)) #if (!TS_NO_PRIMARY && defined(TS_PRIMARY_PORT))
#define HAS_PRIMARY true #define HAS_PRIMARY true
@ -29,11 +30,6 @@
#include "pin_repository.h" #include "pin_repository.h"
#endif #endif
typedef enum {
TS_PLAIN = 0,
TS_CRC = 1
} ts_response_format_e;
class TsChannelBase { class TsChannelBase {
public: public:
TsChannelBase(const char *name); TsChannelBase(const char *name);