mirror of https://github.com/rusefi/rusefi-1.git
steps towards better commands encapsulation
This commit is contained in:
parent
d7da81b5c2
commit
141804f490
|
@ -144,15 +144,11 @@ uint8_t* getWorkingPageAddr() {
|
||||||
return (uint8_t*)engineConfiguration;
|
return (uint8_t*)engineConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr size_t getTunerStudioPageSize() {
|
|
||||||
return TOTAL_CONFIG_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendOkResponse(TsChannelBase *tsChannel, ts_response_format_e mode) {
|
void sendOkResponse(TsChannelBase *tsChannel, ts_response_format_e mode) {
|
||||||
tsChannel->sendResponse(mode, NULL, 0);
|
tsChannel->sendResponse(mode, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sendErrorCode(TsChannelBase *tsChannel, uint8_t code) {
|
void sendErrorCode(TsChannelBase *tsChannel, uint8_t code) {
|
||||||
tsChannel->writeCrcPacket(code, nullptr, 0);
|
tsChannel->writeCrcPacket(code, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,23 +252,9 @@ static void handleGetStructContent(TsChannelBase* tsChannel, int structId, int s
|
||||||
|
|
||||||
#endif // EFI_TUNER_STUDIO
|
#endif // EFI_TUNER_STUDIO
|
||||||
|
|
||||||
// Validate whether the specified offset and count would cause an overrun in the tune.
|
bool validateOffsetCount(size_t offset, size_t count, TsChannelBase* tsChannel);
|
||||||
// Returns true if an overrun would occur.
|
|
||||||
static bool validateOffsetCount(size_t offset, size_t count, TsChannelBase* tsChannel) {
|
|
||||||
if (offset + count > getTunerStudioPageSize()) {
|
|
||||||
efiPrintf("TS: Project mismatch? Too much configuration requested %d/%d", offset, count);
|
|
||||||
tunerStudioError(tsChannel, "ERROR: out of range");
|
|
||||||
sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
extern bool rebootForPresetPending;
|
||||||
}
|
|
||||||
|
|
||||||
// This is used to prevent TS from reading/writing when we have just applied a preset, to prevent TS getting confused.
|
|
||||||
// At the same time an ECU reboot is forced by triggering a fatal error, informing the user to please restart
|
|
||||||
// the ECU. Forcing a reboot will force TS to re-read the tune CRC,
|
|
||||||
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
|
||||||
|
@ -299,7 +281,7 @@ void TunerStudio::handleWriteChunkCommand(TsChannelBase* tsChannel, ts_response_
|
||||||
|
|
||||||
#if EFI_TUNER_STUDIO
|
#if EFI_TUNER_STUDIO
|
||||||
|
|
||||||
static void handleCrc32Check(TsChannelBase *tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count) {
|
void TunerStudio::handleCrc32Check(TsChannelBase *tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count) {
|
||||||
tsState.crc32CheckCommandCounter++;
|
tsState.crc32CheckCommandCounter++;
|
||||||
|
|
||||||
// Ensure we are reading from in bounds
|
// Ensure we are reading from in bounds
|
||||||
|
@ -317,7 +299,7 @@ static void handleCrc32Check(TsChannelBase *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(TsChannelBase* tsChannel, ts_response_format_e mode, uint16_t offset, uint8_t value) {
|
void TunerStudio::handleWriteValueCommand(TsChannelBase* tsChannel, ts_response_format_e mode, uint16_t offset, uint8_t value) {
|
||||||
UNUSED(tsChannel);
|
UNUSED(tsChannel);
|
||||||
UNUSED(mode);
|
UNUSED(mode);
|
||||||
|
|
||||||
|
@ -341,7 +323,7 @@ static void handleWriteValueCommand(TsChannelBase* tsChannel, ts_response_format
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handlePageReadCommand(TsChannelBase* tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count) {
|
void TunerStudio::handlePageReadCommand(TsChannelBase* tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count) {
|
||||||
tsState.readPageCommandsCounter++;
|
tsState.readPageCommandsCounter++;
|
||||||
|
|
||||||
if (rebootForPresetPending) {
|
if (rebootForPresetPending) {
|
||||||
|
|
|
@ -6,7 +6,32 @@
|
||||||
|
|
||||||
#include "status_loop.h"
|
#include "status_loop.h"
|
||||||
|
|
||||||
#if EFI_TUNER_STUDIO && (EFI_PROD_CODE || EFI_SIMULATOR)
|
#if EFI_TUNER_STUDIO
|
||||||
|
|
||||||
|
void sendErrorCode(TsChannelBase *tsChannel, uint8_t code);
|
||||||
|
|
||||||
|
static constexpr size_t getTunerStudioPageSize() {
|
||||||
|
return TOTAL_CONFIG_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate whether the specified offset and count would cause an overrun in the tune.
|
||||||
|
// Returns true if an overrun would occur.
|
||||||
|
bool validateOffsetCount(size_t offset, size_t count, TsChannelBase* tsChannel) {
|
||||||
|
if (offset + count > getTunerStudioPageSize()) {
|
||||||
|
efiPrintf("TS: Project mismatch? Too much configuration requested %d/%d", offset, count);
|
||||||
|
tunerStudioError(tsChannel, "ERROR: out of range");
|
||||||
|
sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This is used to prevent TS from reading/writing when we have just applied a preset, to prevent TS getting confused.
|
||||||
|
// At the same time an ECU reboot is forced by triggering a fatal error, informing the user to please restart
|
||||||
|
// the ECU. Forcing a reboot will force TS to re-read the tune CRC,
|
||||||
|
bool rebootForPresetPending = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 'Output' command sends out a snapshot of current values
|
* @brief 'Output' command sends out a snapshot of current values
|
||||||
|
|
|
@ -31,6 +31,9 @@ public:
|
||||||
void handlePageSelectCommand(TsChannelBase *tsChannel, ts_response_format_e mode);
|
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 handleWriteChunkCommand(TsChannelBase* tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count,
|
||||||
void *content);
|
void *content);
|
||||||
|
void handleCrc32Check(TsChannelBase *tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count);
|
||||||
|
void handleWriteValueCommand(TsChannelBase* tsChannel, ts_response_format_e mode, uint16_t offset, uint8_t value);
|
||||||
|
void handlePageReadCommand(TsChannelBase* tsChannel, ts_response_format_e mode, uint16_t offset, uint16_t count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void sendErrorCode(TsChannelBase* tsChannel, uint8_t code);
|
void sendErrorCode(TsChannelBase* tsChannel, uint8_t code);
|
||||||
|
|
|
@ -79,7 +79,8 @@ TEST(TunerstudioCommands, writeChunkEngineConfig) {
|
||||||
|
|
||||||
// two step - writes to the engineConfiguration section require a burn
|
// two step - writes to the engineConfiguration section require a burn
|
||||||
uint8_t val = 50;
|
uint8_t val = 50;
|
||||||
handleWriteChunkCommand(&channel, TS_CRC, 100, 1, &val);
|
TunerStudio instance;
|
||||||
|
instance.handleWriteChunkCommand(&channel, TS_CRC, 100, 1, &val);
|
||||||
|
|
||||||
EXPECT_EQ(configBytes[100], 50);
|
EXPECT_EQ(configBytes[100], 50);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue