diff --git a/firmware/CHANGELOG.md b/firmware/CHANGELOG.md index c759e7021e..79ddeb84e9 100644 --- a/firmware/CHANGELOG.md +++ b/firmware/CHANGELOG.md @@ -34,6 +34,7 @@ All notable user-facing or behavior-altering changes will be documented in this - Toyota 4-1 VVT trigger - use extra RAM for lua if your microRusEFI unit has stm32f42x microcontroller - VVT activation delay #3443 + - ECU uptime into critical error message ## March 2022 Release - "Day 22" diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index 63490d653c..d5f4e37083 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -433,7 +433,11 @@ static void handleTestCommand(TsChannelBase* tsChannel) { tsChannel->write((const uint8_t*)testOutputBuffer, strlen(testOutputBuffer)); if (hasFirmwareError()) { - const char* error = getCriticalErrorMessage(); + char* error = getCriticalErrorMessage(); + extern int firmwareErrorUptimePosition; + if (firmwareErrorUptimePosition > 0) { + itoa10(error + firmwareErrorUptimePosition, getTimeNowSeconds()); + } chsnprintf(testOutputBuffer, sizeof(testOutputBuffer), "error=%s\r\n", error); tsChannel->write((const uint8_t*)testOutputBuffer, strlen(testOutputBuffer)); } diff --git a/firmware/controllers/core/error_handling.cpp b/firmware/controllers/core/error_handling.cpp index fbcc61a658..158de519b7 100644 --- a/firmware/controllers/core/error_handling.cpp +++ b/firmware/controllers/core/error_handling.cpp @@ -22,7 +22,12 @@ bool hasFirmwareErrorFlag = false; const char *dbg_panic_file; int dbg_panic_line; -const char* getCriticalErrorMessage(void) { +/** + * position at which we would be dynamically appending uptime + */ +int firmwareErrorUptimePosition = -1; + +char* getCriticalErrorMessage(void) { return criticalErrorMessageBuffer; } @@ -220,10 +225,17 @@ void firmwareError(obd_code_e code, const char *fmt, ...) { int errorMessageSize = strlen((char*)criticalErrorMessageBuffer); static char versionBuffer[32]; - chsnprintf(versionBuffer, sizeof(versionBuffer), " %d@%s", getRusEfiVersion(), FIRMWARE_ID); + chsnprintf(versionBuffer, sizeof(versionBuffer), "\n%d@%s\nup=", + getRusEfiVersion(), + FIRMWARE_ID); - if (errorMessageSize + strlen(versionBuffer) < sizeof(criticalErrorMessageBuffer)) { +#define MAX_UPTIME_LEN 9 + int versionBufferLength = strlen(versionBuffer); + if (errorMessageSize + versionBufferLength + MAX_UPTIME_LEN < sizeof(criticalErrorMessageBuffer)) { strcpy((char*)(criticalErrorMessageBuffer) + errorMessageSize, versionBuffer); + firmwareErrorUptimePosition = errorMessageSize + versionBufferLength; + } else { + firmwareErrorUptimePosition = -1; } #else diff --git a/firmware/controllers/core/error_handling.h b/firmware/controllers/core/error_handling.h index 9776c5e4d8..8ea76ff8ac 100644 --- a/firmware/controllers/core/error_handling.h +++ b/firmware/controllers/core/error_handling.h @@ -37,7 +37,7 @@ extern bool hasFirmwareErrorFlag; #define hasFirmwareError() hasFirmwareErrorFlag -const char* getCriticalErrorMessage(void); +char* getCriticalErrorMessage(void); const char* getWarningMessage(void); // todo: better place for this shared declaration?