diff --git a/src/mesh/LR11x0Interface.cpp b/src/mesh/LR11x0Interface.cpp index 8be0b64139f..b724af5e010 100644 --- a/src/mesh/LR11x0Interface.cpp +++ b/src/mesh/LR11x0Interface.cpp @@ -290,7 +290,8 @@ template bool LR11x0Interface::reconfigure() RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); err = lora.setSyncWord(syncWord); - assert(err == RADIOLIB_ERR_NONE); + if (err != RADIOLIB_ERR_NONE) + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); if (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_LORA_24) { // clamp if wide freq range limitPower(LR1120_MAX_POWER); @@ -299,14 +300,16 @@ template bool LR11x0Interface::reconfigure() } err = lora.setPreambleLength(preambleLength); - assert(err == RADIOLIB_ERR_NONE); + if (err != RADIOLIB_ERR_NONE) + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); err = lora.setFrequency(getFreq()); if (err != RADIOLIB_ERR_NONE) RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); err = lora.setOutputPower(power); - assert(err == RADIOLIB_ERR_NONE); + if (err != RADIOLIB_ERR_NONE) + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); // Apply RX gain mode - valid in STDBY, matches resetAGC() pattern err = lora.setRxBoostedGainMode(config.lora.sx126x_rx_boosted_gain); @@ -331,10 +334,9 @@ template void LR11x0Interface::setStandby() if (err != RADIOLIB_ERR_NONE) { LOG_DEBUG("LR11x0 standby failed, err %d", err); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); } - assert(err == RADIOLIB_ERR_NONE); - isReceiving = false; // If we were receiving, not any more activeReceiveStart = 0; disableInterrupt(); @@ -377,9 +379,10 @@ template void LR11x0Interface::startReceive() // We use a 16 bit preamble so this should save some power by letting radio sit in standby mostly. int err = lora.startReceive(RADIOLIB_LR11X0_RX_TIMEOUT_INF, MESHTASTIC_RADIOLIB_IRQ_RX_FLAGS, RADIOLIB_IRQ_RX_DEFAULT_MASK, 0); - if (err) + if (err) { LOG_ERROR("StartReceive error: %d", err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); + } RadioLibInterface::startReceive(); @@ -407,7 +410,8 @@ template bool LR11x0Interface::isChannelActive() if (result == RADIOLIB_LORA_DETECTED) return true; - assert(result != RADIOLIB_ERR_WRONG_MODEM); + if (result == RADIOLIB_ERR_WRONG_MODEM) + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); return false; } diff --git a/src/mesh/LR20x0Interface.cpp b/src/mesh/LR20x0Interface.cpp index dcc514041e4..fca905d4d4a 100644 --- a/src/mesh/LR20x0Interface.cpp +++ b/src/mesh/LR20x0Interface.cpp @@ -336,10 +336,9 @@ template void LR20x0Interface::setStandby() if (err != RADIOLIB_ERR_NONE) { LOG_DEBUG("LR20x0 standby failed, err %d", err); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); } - assert(err == RADIOLIB_ERR_NONE); - isReceiving = false; // If we were receiving, not any more activeReceiveStart = 0; disableInterrupt(); @@ -383,9 +382,10 @@ template void LR20x0Interface::startReceive() // We use a 16 bit preamble so this should save some power by letting radio sit in standby mostly. int err = lora.startReceive(RADIOLIB_LR2021_RX_TIMEOUT_INF, MESHTASTIC_RADIOLIB_IRQ_RX_FLAGS, RADIOLIB_IRQ_RX_DEFAULT_MASK, 0); - if (err) + if (err) { LOG_ERROR("StartReceive error: %d", err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); + } RadioLibInterface::startReceive(); @@ -413,7 +413,8 @@ template bool LR20x0Interface::isChannelActive() if (result == RADIOLIB_LORA_DETECTED) return true; - assert(result != RADIOLIB_ERR_WRONG_MODEM); + if (result == RADIOLIB_ERR_WRONG_MODEM) + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); return false; } diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index 909d47e23e7..07a55b31d30 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -228,19 +228,22 @@ bool RF95Interface::reconfigure() RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); err = lora->setSyncWord(syncWord); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("RF95 setSyncWord %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); + } err = lora->setCurrentLimit(currentLimit); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("RF95 setCurrentLimit %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); + } err = lora->setPreambleLength(preambleLength); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("RF95 setPreambleLength %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); + } err = lora->setFrequency(getFreq()); if (err != RADIOLIB_ERR_NONE) @@ -275,9 +278,10 @@ void RF95Interface::addReceiveMetadata(meshtastic_MeshPacket *mp) void RF95Interface::setStandby() { int err = lora->standby(); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("RF95 standby %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); + } isReceiving = false; // If we were receiving, not any more disableInterrupt(); @@ -299,9 +303,10 @@ void RF95Interface::startReceive() setTransmitEnable(false); setStandby(); int err = lora->startReceive(); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("RF95 startReceive %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); + } isReceiving = true; @@ -324,7 +329,8 @@ bool RF95Interface::isChannelActive() } if (result != RADIOLIB_CHANNEL_FREE) LOG_ERROR("RF95 isChannelActive %s%d", radioLibErr, result); - assert(result != RADIOLIB_ERR_WRONG_MODEM); + if (result == RADIOLIB_ERR_WRONG_MODEM) + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); // LOG_DEBUG("Channel is free"); return false; diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 2400a8e03f6..6f16e92b185 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -209,19 +209,22 @@ template bool SX126xInterface::reconfigure() RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); err = lora.setSyncWord(syncWord); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("SX126X setSyncWord %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); + } err = lora.setCurrentLimit(currentLimit); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("SX126X setCurrentLimit %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); + } err = lora.setPreambleLength(preambleLength); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("SX126X setPreambleLength %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); + } err = lora.setFrequency(getFreq()); if (err != RADIOLIB_ERR_NONE) @@ -322,14 +325,14 @@ template void SX126xInterface::setStandby() int err = lora.standby(); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_DEBUG("SX126x standby %s%d", radioLibErr, err); #ifdef ARCH_PORTDUINO - if (err != RADIOLIB_ERR_NONE) portduino_status.LoRa_in_error = true; #else - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); #endif + } isReceiving = false; // If we were receiving, not any more activeReceiveStart = 0; disableInterrupt(); @@ -379,14 +382,14 @@ template void SX126xInterface::startReceive() int err = lora.startReceiveDutyCycleAuto(preambleLength, 8, MESHTASTIC_RADIOLIB_IRQ_RX_FLAGS); const char *rxMethod = "startReceiveDutyCycleAuto"; #endif - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("SX126X %s %s%d", rxMethod, radioLibErr, err); #ifdef ARCH_PORTDUINO - if (err != RADIOLIB_ERR_NONE) portduino_status.LoRa_in_error = true; #else - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); #endif + } RadioLibInterface::startReceive(); @@ -415,12 +418,13 @@ template bool SX126xInterface::isChannelActive() return true; if (result != RADIOLIB_CHANNEL_FREE) LOG_ERROR("SX126X scanChannel %s%d", radioLibErr, result); + if (result == RADIOLIB_ERR_WRONG_MODEM) { #ifdef ARCH_PORTDUINO - if (result == RADIOLIB_ERR_WRONG_MODEM) portduino_status.LoRa_in_error = true; #else - assert(result != RADIOLIB_ERR_WRONG_MODEM); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); #endif + } return false; } diff --git a/src/mesh/SX128xInterface.cpp b/src/mesh/SX128xInterface.cpp index bb1d8902477..1fcd2087401 100644 --- a/src/mesh/SX128xInterface.cpp +++ b/src/mesh/SX128xInterface.cpp @@ -131,14 +131,16 @@ template bool SX128xInterface::reconfigure() RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); err = lora.setSyncWord(syncWord); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("SX128X setSyncWord %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); + } err = lora.setPreambleLength(preambleLength); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("SX128X setPreambleLength %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); + } err = lora.setFrequency(getFreq()); if (err != RADIOLIB_ERR_NONE) @@ -147,9 +149,10 @@ template bool SX128xInterface::reconfigure() limitPower(SX128X_MAX_POWER); err = lora.setOutputPower(power); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("SX128X setOutputPower %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); + } startReceive(); // restart receiving @@ -172,9 +175,10 @@ template void SX128xInterface::setStandby() int err = lora.standby(); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("SX128x standby %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); + } #if ARCH_PORTDUINO if (portduino_config.lora_rxen_pin.pin != RADIOLIB_NC) { digitalWrite(portduino_config.lora_rxen_pin.pin, LOW); @@ -263,9 +267,10 @@ template void SX128xInterface::startReceive() int err = lora.startReceive(RADIOLIB_SX128X_RX_TIMEOUT_INF, MESHTASTIC_RADIOLIB_IRQ_RX_FLAGS); - if (err != RADIOLIB_ERR_NONE) + if (err != RADIOLIB_ERR_NONE) { LOG_ERROR("SX128X startReceive %s%d", radioLibErr, err); - assert(err == RADIOLIB_ERR_NONE); + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); + } RadioLibInterface::startReceive(); @@ -294,7 +299,8 @@ template bool SX128xInterface::isChannelActive() return true; if (result != RADIOLIB_CHANNEL_FREE) LOG_ERROR("SX128X scanChannel %s%d", radioLibErr, result); - assert(result != RADIOLIB_ERR_WRONG_MODEM); + if (result == RADIOLIB_ERR_WRONG_MODEM) + RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG); return false; }