2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2020-12-08 23:23:02 -08:00
|
|
|
|
|
|
|
#include "tunerstudio_impl.h"
|
|
|
|
#include "tunerstudio.h"
|
|
|
|
#include "tunerstudio_io.h"
|
|
|
|
|
|
|
|
#include "status_loop.h"
|
|
|
|
|
2022-04-13 22:44:35 -07:00
|
|
|
#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;
|
2020-12-08 23:23:02 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 'Output' command sends out a snapshot of current values
|
|
|
|
* Gauges refresh
|
|
|
|
*/
|
2021-02-19 23:11:39 -08:00
|
|
|
void TunerStudio::cmdOutputChannels(TsChannelBase* tsChannel, uint16_t offset, uint16_t count) {
|
2020-12-08 23:23:02 -08:00
|
|
|
if (offset + count > sizeof(TunerStudioOutputChannels)) {
|
2021-04-18 16:13:48 -07:00
|
|
|
efiPrintf("TS: Version Mismatch? Too much outputs requested %d/%d/%d", offset, count,
|
2020-12-08 23:23:02 -08:00
|
|
|
sizeof(TunerStudioOutputChannels));
|
|
|
|
sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tsState.outputChannelsCommandCounter++;
|
2022-03-14 20:02:00 -07:00
|
|
|
updateTunerStudioState();
|
2020-12-08 23:23:02 -08:00
|
|
|
// this method is invoked too often to print any debug information
|
2022-01-05 17:12:38 -08:00
|
|
|
tsChannel->writeCrcPacket(TS_RESPONSE_OK, reinterpret_cast<const uint8_t*>(&engine->outputChannels) + offset, count);
|
2020-12-08 23:23:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // EFI_TUNER_STUDIO
|