From 186a52172c35b15e8dc180acea4c92adca912cb9 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 27 Dec 2020 13:09:20 +0800 Subject: [PATCH] fix #577 don't make invalid radio settings reboot the board instead raise a critical fault (note though: this is still not ideal because the radio will be in an undefined state until valid settings are used) --- proto | 2 +- src/mesh/RF95Interface.cpp | 13 ++++++++----- src/mesh/SX1262Interface.cpp | 9 +++++---- src/mesh/mesh.pb.h | 7 ++++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/proto b/proto index 9a7d8a03c..323b814f4 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 9a7d8a03cb051eb42787d4a06836b109677d8ef1 +Subproject commit 323b814f4392ae0f9c42a0f14557c6b9333efce3 diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index 9410ad650..60596468b 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -1,6 +1,7 @@ #include "RF95Interface.h" #include "MeshRadio.h" // kinda yucky, but we need to know which region we are in #include "RadioLibRF95.h" +#include "error.h" #include #define MAX_POWER 20 @@ -85,6 +86,8 @@ void INTERRUPT_ATTR RF95Interface::disableInterrupt() lora->clearDio0Action(); } + + bool RF95Interface::reconfigure() { applyModemConfig(); @@ -94,13 +97,13 @@ bool RF95Interface::reconfigure() // configure publicly accessible settings int err = lora->setSpreadingFactor(sf); - assert(err == ERR_NONE); + if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora->setBandwidth(bw); - assert(err == ERR_NONE); + if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora->setCodingRate(cr); - assert(err == ERR_NONE); + if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora->setSyncWord(syncWord); assert(err == ERR_NONE); @@ -112,12 +115,12 @@ bool RF95Interface::reconfigure() assert(err == ERR_NONE); err = lora->setFrequency(freq); - assert(err == ERR_NONE); + if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); if (power > MAX_POWER) // This chip has lower power limits than some power = MAX_POWER; err = lora->setOutputPower(power); - assert(err == ERR_NONE); + if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); startReceive(); // restart receiving diff --git a/src/mesh/SX1262Interface.cpp b/src/mesh/SX1262Interface.cpp index 0a23261b5..0bff47365 100644 --- a/src/mesh/SX1262Interface.cpp +++ b/src/mesh/SX1262Interface.cpp @@ -1,4 +1,5 @@ #include "SX1262Interface.h" +#include "error.h" #include // Particular boards might define a different max power based on what their hardware can do @@ -78,13 +79,13 @@ bool SX1262Interface::reconfigure() // configure publicly accessible settings int err = lora.setSpreadingFactor(sf); - assert(err == ERR_NONE); + if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora.setBandwidth(bw); - assert(err == ERR_NONE); + if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora.setCodingRate(cr); - assert(err == ERR_NONE); + if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); // Hmm - seems to lower SNR when the signal levels are high. Leaving off for now... err = lora.setRxGain(true); @@ -100,7 +101,7 @@ bool SX1262Interface::reconfigure() assert(err == ERR_NONE); err = lora.setFrequency(freq); - assert(err == ERR_NONE); + if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); if (power > 22) // This chip has lower power limits than some power = 22; diff --git a/src/mesh/mesh.pb.h b/src/mesh/mesh.pb.h index fd382765b..1da4dd3cc 100644 --- a/src/mesh/mesh.pb.h +++ b/src/mesh/mesh.pb.h @@ -55,7 +55,8 @@ typedef enum _CriticalErrorCode { CriticalErrorCode_NoRadio = 3, CriticalErrorCode_Unspecified = 4, CriticalErrorCode_UBloxInitFailed = 5, - CriticalErrorCode_NoAXP192 = 6 + CriticalErrorCode_NoAXP192 = 6, + CriticalErrorCode_InvalidRadioSetting = 7 } CriticalErrorCode; typedef enum _ChannelSettings_ModemConfig { @@ -289,8 +290,8 @@ typedef struct _ToRadio { #define _LocationSharing_ARRAYSIZE ((LocationSharing)(LocationSharing_LocDisabled+1)) #define _CriticalErrorCode_MIN CriticalErrorCode_None -#define _CriticalErrorCode_MAX CriticalErrorCode_NoAXP192 -#define _CriticalErrorCode_ARRAYSIZE ((CriticalErrorCode)(CriticalErrorCode_NoAXP192+1)) +#define _CriticalErrorCode_MAX CriticalErrorCode_InvalidRadioSetting +#define _CriticalErrorCode_ARRAYSIZE ((CriticalErrorCode)(CriticalErrorCode_InvalidRadioSetting+1)) #define _ChannelSettings_ModemConfig_MIN ChannelSettings_ModemConfig_Bw125Cr45Sf128 #define _ChannelSettings_ModemConfig_MAX ChannelSettings_ModemConfig_Bw125Cr48Sf4096