Merge pull request #651 from android606/log-tx-failure

Set critical error and reboot when radio fails to generate Tx IRQ - fixes #138
This commit is contained in:
Kevin Hester 2021-01-27 18:05:56 +08:00 committed by GitHub
commit 2b4ddc07f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -7,6 +7,7 @@
#include "CryptoEngine.h" #include "CryptoEngine.h"
#include "FSCommon.h" #include "FSCommon.h"
#include "GPS.h" #include "GPS.h"
#include "main.h"
#include "MeshRadio.h" #include "MeshRadio.h"
#include "NodeDB.h" #include "NodeDB.h"
#include "PacketHistory.h" #include "PacketHistory.h"
@ -583,8 +584,14 @@ NodeInfo *NodeDB::getOrCreateNode(NodeNum n)
/// Record an error that should be reported via analytics /// Record an error that should be reported via analytics
void recordCriticalError(CriticalErrorCode code, uint32_t address) 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); DEBUG_MSG("NOTE! Recording critical error %d, address=%x\n", code, address);
// Record error to DB
myNodeInfo.error_code = code; myNodeInfo.error_code = code;
myNodeInfo.error_address = address; myNodeInfo.error_address = address;
myNodeInfo.error_count++; myNodeInfo.error_count++;
} }

View File

@ -3,6 +3,7 @@
#include "NodeDB.h" #include "NodeDB.h"
#include "SPILock.h" #include "SPILock.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "error.h"
#include <configuration.h> #include <configuration.h>
#include <pb_decode.h> #include <pb_decode.h>
#include <pb_encode.h> #include <pb_encode.h>
@ -67,9 +68,20 @@ bool RadioLibInterface::canSendImmediately()
bool busyTx = sendingPacket != NULL; bool busyTx = sendingPacket != NULL;
bool busyRx = isReceiving && isActivelyReceiving(); bool busyRx = isReceiving && isActivelyReceiving();
if (busyTx || busyRx) { if (busyTx || busyRx) {
if (busyTx) if (busyTx)
DEBUG_MSG("Can not send yet, busyTx\n"); 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);
#ifndef NO_ESP32
if (busyTx && (millis() - lastTxStart > 65000)) // After 5s more, reboot
ESP.restart();
#endif
}
if (busyRx) if (busyRx)
DEBUG_MSG("Can not send yet, busyRx\n"); DEBUG_MSG("Can not send yet, busyRx\n");
return false; return false;

View File

@ -76,7 +76,8 @@ typedef enum _CriticalErrorCode {
CriticalErrorCode_Unspecified = 4, CriticalErrorCode_Unspecified = 4,
CriticalErrorCode_UBloxInitFailed = 5, CriticalErrorCode_UBloxInitFailed = 5,
CriticalErrorCode_NoAXP192 = 6, CriticalErrorCode_NoAXP192 = 6,
CriticalErrorCode_InvalidRadioSetting = 7 CriticalErrorCode_InvalidRadioSetting = 7,
CriticalErrorCode_TransmitFailed = 8
} CriticalErrorCode; } CriticalErrorCode;
typedef enum _ChannelSettings_ModemConfig { typedef enum _ChannelSettings_ModemConfig {