From 9bf1d5aad30e4c2ae492a5b13230a521c9a7adcd Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sun, 26 Apr 2020 11:06:09 -0700 Subject: [PATCH] TS protocol framing for auto tune/calibration features (#1370) * rearrange * fix enum * too much * format * enough generate for CI * comment Co-authored-by: Matthew Kennedy --- .../binary/tunerstudio_configuration.h | 59 +++++++++---- firmware/integration/rusefi_config.txt | 4 +- firmware/tunerstudio/rusefi.input | 87 ++++++++++--------- 3 files changed, 90 insertions(+), 60 deletions(-) diff --git a/firmware/console/binary/tunerstudio_configuration.h b/firmware/console/binary/tunerstudio_configuration.h index 365f79b988..2bde4a2b29 100644 --- a/firmware/console/binary/tunerstudio_configuration.h +++ b/firmware/console/binary/tunerstudio_configuration.h @@ -18,6 +18,16 @@ typedef struct { uint16_t values[EGT_CHANNEL_COUNT]; } egt_values_s; + +enum class TsCalMode : uint8_t { + None = 0, + Tps1Max = 1, + Tps1Min = 2, + EtbKp = 3, + EtbKi = 4, + EtbKd = 5, +}; + /** * At the moment rusEfi does NOT have any code generation around TS output channels, three locations have to be changed manually * 1) this TunerStudioOutputChannels firmware version of the structure @@ -152,15 +162,29 @@ typedef struct { uint32_t firmwareVersion; // 120 uint32_t tsConfigVersion; // 124 + // These two fields indicate to TS that we'd like to set a particular field to a particular value + // We use a maintainConstantValue in TS for each field we'd like to set, like this: + // maintainConstantValue = tpsMax, { (calibrationMode == 1 ) ? calibrationValue : tpsMax } + // maintainConstantValue = tpsMin, { (calibrationMode == 2 ) ? calibrationValue : tpsMin } + // When the mode is set to a particular value, TS will copy the calibrationValue in to the specified field. + // + // With this simple construct, the ECU can send any number of internally computed configuration fields + // back to TunerStudio, getting around the problem of setting values on the controller without TS's knowledge. + // The ECU simply has to sequentially set a mode/value, wait briefly, then repeat until all the values + // it wants to send have been sent. + float calibrationValue; // 128 + TsCalMode calibrationMode; // 132 + uint8_t padding[3]; // 133-135 + // Errors - int totalTriggerErrorCounter; // 128 - int orderingErrorCounter; // 132 - int16_t warningCounter; // 136 - int16_t lastErrorCode; // 138 - int16_t recentErrorCodes[8]; // 140 + int totalTriggerErrorCounter; // 136 + int orderingErrorCounter; // 140 + int16_t warningCounter; // 144 + int16_t lastErrorCode; // 146 + int16_t recentErrorCodes[8]; // 148-162 // Debug - float debugFloatField1; // 156 + float debugFloatField1; // 164 float debugFloatField2; float debugFloatField3; float debugFloatField4; @@ -171,23 +195,24 @@ typedef struct { int debugIntField2; int debugIntField3; int16_t debugIntField4; - int16_t debugIntField5; // 198 + int16_t debugIntField5; // 206 // accelerometer - int16_t accelerationX; // 200 - int16_t accelerationY; // 202 + int16_t accelerationX; // 208 + int16_t accelerationY; // 210 // EGT - egt_values_s egtValues; // 204 - scaled_percent throttle2Position; // 220 + egt_values_s egtValues; // 212 - scaled_voltage rawTps1Primary; // 222 - scaled_voltage rawPpsPrimary; // 224 - scaled_voltage rawClt; // 226 - scaled_voltage rawIat; // 228 - scaled_voltage rawOilPressure; // 230 + scaled_percent throttle2Position; // 228 - uint8_t unusedAtTheEnd[8]; // we have some unused bytes to allow compatible TS changes + scaled_voltage rawTps1Primary; // 230 + scaled_voltage rawPpsPrimary; // 232 + scaled_voltage rawClt; // 234 + scaled_voltage rawIat; // 236 + scaled_voltage rawOilPressure; // 238 + + uint8_t unusedAtTheEnd[4]; // we have some unused bytes to allow compatible TS changes // Temporary - will remove soon TsDebugChannels* getDebugChannels() { diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 9aafdc8a17..80a1d63ae0 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -23,13 +23,13 @@ ! type name;comment -#define TS_SIGNATURE "rusEFI v1.2020.3" +#define TS_SIGNATURE "rusEFI v1.2020.4" ! ! this is here so that rusEfi console can access it, too ! [IMPORTANT] every time TS_OUTPUT_SIZE is changed make sure to increment TS_SIGNATURE above ! -#define TS_OUTPUT_SIZE 240 +#define TS_OUTPUT_SIZE 244 ! ! this is used to confirm that firmware and TunerStudio are using the same rusefi.ini version diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 12bb2ebe7a..7aa7ba1cbb 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -304,55 +304,60 @@ fileVersion = { @@TS_FILE_VERSION@@ } firmwareVersion = scalar, U32, 120,"version_f", 1, 0 firmwareTsVersion=scalar, U32, 124,"version_p", 1, 0 +; calibation helpers + calibrationValue = scalar, F32, 128, "", 1, 0 + calibrationMode = scalar, U08, 132, "", 1, 0 + ; 3 bytes padding1 + ; Errors - totalTriggerErrorCounter=scalar,U32, 128,"counter", 1, 0 - ; orderingErrorCounter 132 - warningCounter = scalar, U16, 136, "count", 1, 0 - lastErrorCode = scalar, U16, 138, "error", 1, 0 - recentErrorCode0= scalar, U16, 140, "error", 1, 0 - recentErrorCode1= scalar, U16, 142, "error", 1, 0 - recentErrorCode2= scalar, U16, 144, "error", 1, 0 - recentErrorCode3= scalar, U16, 146, "error", 1, 0 - recentErrorCode4= scalar, U16, 148, "error", 1, 0 - recentErrorCode5= scalar, U16, 150, "error", 1, 0 - recentErrorCode6= scalar, U16, 152, "error", 1, 0 - recentErrorCode7= scalar, U16, 154, "error", 1, 0 + totalTriggerErrorCounter=scalar,U32, 136,"counter", 1, 0 + ; orderingErrorCounter 140 + warningCounter = scalar, U16, 144, "count", 1, 0 + lastErrorCode = scalar, U16, 146, "error", 1, 0 + recentErrorCode0= scalar, U16, 148, "error", 1, 0 + recentErrorCode1= scalar, U16, 150, "error", 1, 0 + recentErrorCode2= scalar, U16, 152, "error", 1, 0 + recentErrorCode3= scalar, U16, 154, "error", 1, 0 + recentErrorCode4= scalar, U16, 156, "error", 1, 0 + recentErrorCode5= scalar, U16, 158, "error", 1, 0 + recentErrorCode6= scalar, U16, 160, "error", 1, 0 + recentErrorCode7= scalar, U16, 162, "error", 1, 0 ; Debug - debugFloatField1= scalar, F32, 156, "val", 1, 0.0 - debugFloatField2= scalar, F32, 160, "val", 1, 0.0 - debugFloatField3= scalar, F32, 164, "val", 1, 0.0 - debugFloatField4= scalar, F32, 168, "val", 1, 0.0 - debugFloatField5= scalar, F32, 172, "val", 1, 0.0 - debugFloatField6= scalar, F32, 176, "val", 1, 0.0 - debugFloatField7= scalar, F32, 180, "val", 1, 0.0 - debugIntField1 = scalar, S32, 184, "val", 1, 0.0 - debugIntField2 = scalar, S32, 188, "val", 1, 0.0 - debugIntField3 = scalar, S32, 192, "val", 1, 0.0 - debugIntField4 = scalar, S16, 196, "val", 1, 0.0 - debugIntField5 = scalar, S16, 198, "val", 1, 0.0 + debugFloatField1= scalar, F32, 164, "val", 1, 0.0 + debugFloatField2= scalar, F32, 168, "val", 1, 0.0 + debugFloatField3= scalar, F32, 172, "val", 1, 0.0 + debugFloatField4= scalar, F32, 176, "val", 1, 0.0 + debugFloatField5= scalar, F32, 180, "val", 1, 0.0 + debugFloatField6= scalar, F32, 184, "val", 1, 0.0 + debugFloatField7= scalar, F32, 188, "val", 1, 0.0 + debugIntField1 = scalar, S32, 192, "val", 1, 0.0 + debugIntField2 = scalar, S32, 196, "val", 1, 0.0 + debugIntField3 = scalar, S32, 200, "val", 1, 0.0 + debugIntField4 = scalar, S16, 204, "val", 1, 0.0 + debugIntField5 = scalar, S16, 206, "val", 1, 0.0 ; Accel - accelerationX = scalar, S16, 200, "G", 0.01, 0 - accelerationY = scalar, S16, 202, "G", 0.01, 0 + accelerationX = scalar, S16, 208, "G", 0.01, 0 + accelerationY = scalar, S16, 210, "G", 0.01, 0 ; egt - egt1 = scalar, S16, 204, "deg C", 1, 0 - egt2 = scalar, S16, 206, "deg C", 1, 0 - egt3 = scalar, S16, 208, "deg C", 1, 0 - egt4 = scalar, S16, 210, "deg C", 1, 0 - egt5 = scalar, S16, 212, "deg C", 1, 0 - egt6 = scalar, S16, 214, "deg C", 1, 0 - egt7 = scalar, S16, 216, "deg C", 1, 0 - egt8 = scalar, S16, 218, "deg C", 1, 0 -; - TPS2Value = scalar, S16, 220, "%",{1/@@PACK_MULT_PERCENT@@}, 0 + egt1 = scalar, S16, 212, "deg C", 1, 0 + egt2 = scalar, S16, 214, "deg C", 1, 0 + egt3 = scalar, S16, 216, "deg C", 1, 0 + egt4 = scalar, S16, 218, "deg C", 1, 0 + egt5 = scalar, S16, 220, "deg C", 1, 0 + egt6 = scalar, S16, 222, "deg C", 1, 0 + egt7 = scalar, S16, 224, "deg C", 1, 0 + egt8 = scalar, S16, 226, "deg C", 1, 0 - rawTps1Primary = scalar, U16, 222, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0.0 - rawPpsPrimary = scalar, U16, 224, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0.0 - rawClt = scalar, U16, 226, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0.0 - rawIat = scalar, U16, 228, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0.0 - rawOilPressure = scalar, U16, 230, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0.0 + TPS2Value = scalar, S16, 228, "%",{1/@@PACK_MULT_PERCENT@@}, 0 + + rawTps1Primary = scalar, U16, 230, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0.0 + rawPpsPrimary = scalar, U16, 232, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0.0 + rawClt = scalar, U16, 234, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0.0 + rawIat = scalar, U16, 236, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0.0 + rawOilPressure = scalar, U16, 238, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0.0 ; ; see TunerStudioOutputChannels struct