From 79dad8ec8c8dfe4bb749dd9bffdd7f3506755cd1 Mon Sep 17 00:00:00 2001 From: Andrew Mark Date: Tue, 19 Jan 2021 18:21:54 -0800 Subject: [PATCH] Set critical error and reboot when radio fails to generate tx IRQ --- src/mesh/NodeDB.cpp | 7 +++++++ src/mesh/RadioLibInterface.cpp | 10 ++++++++++ src/mesh/generated/mesh.pb.h | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index dc13bc42..42ce71ea 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -7,6 +7,7 @@ #include "CryptoEngine.h" #include "FSCommon.h" #include "GPS.h" +#include "main.h" #include "MeshRadio.h" #include "NodeDB.h" #include "PacketHistory.h" @@ -583,8 +584,14 @@ NodeInfo *NodeDB::getOrCreateNode(NodeNum n) /// Record an error that should be reported via analytics void recordCriticalError(CriticalErrorCode code, uint32_t address) { + // 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=%x\n", code, address); + + // Record error to DB myNodeInfo.error_code = code; myNodeInfo.error_address = address; myNodeInfo.error_count++; + } diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 0266614a..f0eb53b2 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -3,6 +3,7 @@ #include "NodeDB.h" #include "SPILock.h" #include "mesh-pb-constants.h" +#include "error.h" #include #include #include @@ -67,9 +68,18 @@ bool RadioLibInterface::canSendImmediately() bool busyTx = sendingPacket != NULL; bool busyRx = isReceiving && isActivelyReceiving(); + if (busyTx || busyRx) { if (busyTx) DEBUG_MSG("Can not send yet, busyTx\n"); + // If we've been trying to send the same packet more than one minute and we haven't gotten a + // 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); + if (busyTx && (millis() - lastTxStart > 65000)) // After 5s more, reboot + ESP.restart(); + } if (busyRx) DEBUG_MSG("Can not send yet, busyRx\n"); return false; diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index 815fb2e2..50ae14a6 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -76,7 +76,8 @@ typedef enum _CriticalErrorCode { CriticalErrorCode_Unspecified = 4, CriticalErrorCode_UBloxInitFailed = 5, CriticalErrorCode_NoAXP192 = 6, - CriticalErrorCode_InvalidRadioSetting = 7 + CriticalErrorCode_InvalidRadioSetting = 7, + CriticalErrorCode_TransmitFailed = 8 } CriticalErrorCode; typedef enum _ChannelSettings_ModemConfig {