From babc1b3613c4c274c54887af222588c88fdf1866 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 29 Apr 2021 09:52:15 +0800 Subject: [PATCH] include file/lineno in critical error logs --- src/error.h | 5 ++++- src/gps/UBloxGPS.cpp | 2 +- src/main.cpp | 4 ++-- src/mesh/NodeDB.cpp | 7 +++++-- src/mesh/RF95Interface.cpp | 10 +++++----- src/mesh/RadioLibInterface.cpp | 2 +- src/mesh/generated/mesh.pb.h | 7 ++++--- src/nrf52/main-nrf52.cpp | 4 ++-- src/sleep.cpp | 2 +- 9 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/error.h b/src/error.h index 12cb5a002..2ccf18911 100644 --- a/src/error.h +++ b/src/error.h @@ -4,5 +4,8 @@ #include "mesh/generated/mesh.pb.h" // For CriticalErrorCode +/// A macro that include filename and line +#define RECORD_CRITICALERROR(code) (code, __LINE__, __FILE__) + /// Record an error that should be reported via analytics -void recordCriticalError(CriticalErrorCode code = CriticalErrorCode_Unspecified, uint32_t address = 0); +void recordCriticalError(CriticalErrorCode code = CriticalErrorCode_Unspecified, uint32_t address = 0, const char *filename = NULL); diff --git a/src/gps/UBloxGPS.cpp b/src/gps/UBloxGPS.cpp index 8fda6bc43..632f5d5c9 100644 --- a/src/gps/UBloxGPS.cpp +++ b/src/gps/UBloxGPS.cpp @@ -43,7 +43,7 @@ bool UBloxGPS::setupGPS() DEBUG_MSG("Connected to UBLOX GPS successfully\n"); if (!setUBXMode()) - recordCriticalError(CriticalErrorCode_UBloxInitFailed); // Don't halt the boot if saving the config fails, but do report the bug + RECORD_CRITICALERROR(CriticalErrorCode_UBloxInitFailed); // Don't halt the boot if saving the config fails, but do report the bug return true; } else { diff --git a/src/main.cpp b/src/main.cpp index 68d92fc3a..1bf8bbcb1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -466,7 +466,7 @@ void setup() // Do this after service.init (because that clears error_code) #ifdef AXP192_SLAVE_ADDRESS if (!axp192_found) - recordCriticalError(CriticalErrorCode_NoAXP192); // Record a hardware fault for missing hardware + RECORD_CRITICALERROR(CriticalErrorCode_NoAXP192); // Record a hardware fault for missing hardware #endif // Don't call screen setup until after nodedb is setup (because we need @@ -557,7 +557,7 @@ void setup() airTime = new AirTime(); if (!rIf) - recordCriticalError(CriticalErrorCode_NoRadio); + RECORD_CRITICALERROR(CriticalErrorCode_NoRadio); else router->addInterface(rIf); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index a6ce8e4c8..07706cb46 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -541,12 +541,15 @@ NodeInfo *NodeDB::getOrCreateNode(NodeNum n) } /// Record an error that should be reported via analytics -void recordCriticalError(CriticalErrorCode code, uint32_t address) +void recordCriticalError(CriticalErrorCode code, uint32_t address, const char *filename) { // Print error to screen and serial port String lcd = String("Critical error ") + code + "!\n"; screen->print(lcd.c_str()); - DEBUG_MSG("NOTE! Recording critical error %d, address=%lx\n", code, address); + if(filename) + DEBUG_MSG("NOTE! Recording critical error %d at %s:%lx\n", code, filename, address); + else + DEBUG_MSG("NOTE! Recording critical error %d, address=%lx\n", code, address); // Record error to DB myNodeInfo.error_code = code; diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index e99ec2e36..ea3fd0f70 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -94,15 +94,15 @@ bool RF95Interface::reconfigure() // configure publicly accessible settings int err = lora->setSpreadingFactor(sf); if (err != ERR_NONE) - recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); err = lora->setBandwidth(bw); if (err != ERR_NONE) - recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); err = lora->setCodingRate(cr); if (err != ERR_NONE) - recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); err = lora->setSyncWord(syncWord); assert(err == ERR_NONE); @@ -115,13 +115,13 @@ bool RF95Interface::reconfigure() err = lora->setFrequency(freq); if (err != ERR_NONE) - recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); if (power > MAX_POWER) // This chip has lower power limits than some power = MAX_POWER; err = lora->setOutputPower(power); if (err != ERR_NONE) - recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); startReceive(); // restart receiving diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index f7a2bc415..43e347f14 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -75,7 +75,7 @@ bool RadioLibInterface::canSendImmediately() // TX IRQ from the radio, the radio is probably broken. if (busyTx && (millis() - lastTxStart > 60000)) { DEBUG_MSG("Hardware Failure! busyTx for more than 60s\n"); - recordCriticalError(CriticalErrorCode_TransmitFailed); + RECORD_CRITICALERROR(CriticalErrorCode_TransmitFailed); #ifndef NO_ESP32 if (busyTx && (millis() - lastTxStart > 65000)) // After 5s more, reboot ESP.restart(); diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index faa915dbd..1df6b4633 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -46,7 +46,8 @@ typedef enum _CriticalErrorCode { CriticalErrorCode_NoAXP192 = 6, CriticalErrorCode_InvalidRadioSetting = 7, CriticalErrorCode_TransmitFailed = 8, - CriticalErrorCode_Brownout = 9 + CriticalErrorCode_Brownout = 9, + CriticalErrorCode_SX1262Failure = 10 } CriticalErrorCode; typedef enum _Routing_Error { @@ -216,8 +217,8 @@ typedef struct _ToRadio { #define _Constants_ARRAYSIZE ((Constants)(Constants_DATA_PAYLOAD_LEN+1)) #define _CriticalErrorCode_MIN CriticalErrorCode_None -#define _CriticalErrorCode_MAX CriticalErrorCode_Brownout -#define _CriticalErrorCode_ARRAYSIZE ((CriticalErrorCode)(CriticalErrorCode_Brownout+1)) +#define _CriticalErrorCode_MAX CriticalErrorCode_SX1262Failure +#define _CriticalErrorCode_ARRAYSIZE ((CriticalErrorCode)(CriticalErrorCode_SX1262Failure+1)) #define _Routing_Error_MIN Routing_Error_NONE #define _Routing_Error_MAX Routing_Error_NOT_AUTHORIZED diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index ef99c9f49..802c8f9d7 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -108,7 +108,7 @@ void checkSDEvents() while (NRF_SUCCESS == sd_evt_get(&evt)) { switch (evt) { case NRF_EVT_POWER_FAILURE_WARNING: - recordCriticalError(CriticalErrorCode_Brownout); + RECORD_CRITICALERROR(CriticalErrorCode_Brownout); break; default: @@ -118,7 +118,7 @@ void checkSDEvents() } } else { if (NRF_POWER->EVENTS_POFWARN) - recordCriticalError(CriticalErrorCode_Brownout); + RECORD_CRITICALERROR(CriticalErrorCode_Brownout); } } diff --git a/src/sleep.cpp b/src/sleep.cpp index ae175eed2..1021041a2 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -127,7 +127,7 @@ static void waitEnterSleep() delay(100); // Kinda yucky - wait until radio says say we can shutdown (finished in process sends/receives) if (millis() - now > 30 * 1000) { // If we wait too long just report an error and go to sleep - recordCriticalError(CriticalErrorCode_SleepEnterWait); + RECORD_CRITICALERROR(CriticalErrorCode_SleepEnterWait); assert(0); // FIXME - for now we just restart, need to fix bug #167 break; }