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)
This commit is contained in:
Kevin Hester 2020-12-27 13:09:20 +08:00
parent 21570fc24f
commit 186a52172c
4 changed files with 18 additions and 13 deletions

2
proto

@ -1 +1 @@
Subproject commit 9a7d8a03cb051eb42787d4a06836b109677d8ef1
Subproject commit 323b814f4392ae0f9c42a0f14557c6b9333efce3

View File

@ -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 <configuration.h>
#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

View File

@ -1,4 +1,5 @@
#include "SX1262Interface.h"
#include "error.h"
#include <configuration.h>
// 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;

View File

@ -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