rusEFI
The most advanced open source ECU
tunerstudio_commands.cpp
Go to the documentation of this file.
1 #include "pch.h"
2 
3 #include "tunerstudio_impl.h"
4 #include "tunerstudio.h"
5 #include "tunerstudio_io.h"
6 
7 #include "live_data.h"
8 
9 #include "status_loop.h"
10 
11 #if EFI_TUNER_STUDIO
12 
13 static constexpr size_t getTunerStudioPageSize() {
14  return TOTAL_CONFIG_SIZE;
15 }
16 
17 // Validate whether the specified offset and count would cause an overrun in the tune.
18 // Returns true if an overrun would occur.
19 bool validateOffsetCount(size_t offset, size_t count, TsChannelBase* tsChannel) {
20  if (offset + count > getTunerStudioPageSize()) {
21  efiPrintf("TS: Project mismatch? Too much configuration requested %d/%d", offset, count);
22  tunerStudioError(tsChannel, "ERROR: out of range");
23  sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE);
24  return true;
25  }
26 
27  return false;
28 }
29 
30 
31 // This is used to prevent TS from reading/writing when we have just applied a preset, to prevent TS getting confused.
32 // At the same time an ECU reboot is forced by triggering a fatal error, informing the user to please restart
33 // the ECU. Forcing a reboot will force TS to re-read the tune CRC,
35 
36 static Timer channelsRequestTimer;
37 
39  return channelsRequestTimer.getElapsedSeconds();
40 }
41 
42 /**
43  * @brief 'Output' command sends out a snapshot of current values
44  * Gauges refresh
45  */
46 void TunerStudio::cmdOutputChannels(TsChannelBase* tsChannel, uint16_t offset, uint16_t count) {
47  if (offset + count > TS_TOTAL_OUTPUT_SIZE) {
48  efiPrintf("TS: Version Mismatch? Too much outputs requested offset=%d + count=%d/total=%d", offset, count,
50  sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE);
51  return;
52  }
53 
54  if (offset < BLOCKING_FACTOR) {
56  channelsRequestTimer.reset();
57  }
58 
61  tsChannel->assertPacketSize(count, false);
62  // this method is invoked too often to print any debug information
63  uint8_t * scratchBuffer = (uint8_t *)tsChannel->scratchBuffer;
64  /**
65  * collect data from all models
66  */
67  copyRange(scratchBuffer + 3, getLiveDataFragments(), offset, count);
68 
69  tsChannel->crcAndWriteBuffer(TS_RESPONSE_OK, count);
70 }
71 
72 #endif // EFI_TUNER_STUDIO
TunerStudioOutputChannels outputChannels
Definition: engine.h:96
void crcAndWriteBuffer(const uint8_t responseCode, const size_t size)
char scratchBuffer[BLOCKING_FACTOR+30]
void assertPacketSize(size_t size, bool allowLongPackets)
void cmdOutputChannels(TsChannelBase *tsChannel, uint16_t offset, uint16_t count) override
'Output' command sends out a snapshot of current values Gauges refresh
void sendErrorCode(TsChannelBase *tsChannel, uint8_t code)
Engine * engine
FragmentList getLiveDataFragments()
Definition: live_data.cpp:222
void sendErrorCode(TsChannelBase *tsChannel, uint8_t code)
tunerstudio_counters_s tsState
void tunerStudioError(TsChannelBase *tsChannel, const char *msg)
void updateTunerStudioState()
static Timer channelsRequestTimer
static constexpr size_t getTunerStudioPageSize()
bool validateOffsetCount(size_t offset, size_t count, TsChannelBase *tsChannel)
bool rebootForPresetPending
int getSecondsSinceChannelsRequest()