Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1447,9 +1447,15 @@ void loop()
if (portduino_config.lora_spi_dev == "ch341" && ch341Hal != nullptr) {
ch341Hal->checkError();
}
if (portduino_status.LoRa_in_error && rebootAtMsec == 0) {
if (portduino_status.LoRa_in_error)
RadioLibInterface::loraInError = true;
#endif
if (RadioLibInterface::loraInError && rebootAtMsec == 0) {
LOG_ERROR("LoRa in error detected, attempting to recover");
if (RadioLibInterface::instance)
RadioLibInterface::instance->disableInterrupt();
router->addInterface(nullptr);
#if ARCH_PORTDUINO
if (portduino_config.lora_spi_dev == "ch341") {
if (ch341Hal != nullptr) {
delete ch341Hal;
Expand All @@ -1465,18 +1471,31 @@ void loop()
exit(EXIT_FAILURE);
}
}
#endif
auto rIf = initLoRa();
if (rIf) {
router->addInterface(std::move(rIf));
RadioLibInterface::loraInError = false;
RadioLibInterface::loraReinitAttempts = 0;
#if ARCH_PORTDUINO
portduino_status.LoRa_in_error = false;
#endif
} else {
#if ARCH_PORTDUINO
LOG_WARN("Reconfigure failed, rebooting");
if (screen) {
screen->showSimpleBanner("Rebooting...");
}
rebootAtMsec = millis() + 25;
#else
if (++RadioLibInterface::loraReinitAttempts > 1) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_NO_RADIO);
RadioLibInterface::loraInError = false;
}
#endif
}
}
#if ARCH_PORTDUINO
#if HAS_TFT
if (screen && portduino_config.displayPanel == x11 &&
config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) {
Expand Down
8 changes: 5 additions & 3 deletions src/mesh/LR11x0Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ template <typename T> bool LR11x0Interface<T>::reconfigure()
int err = lora.setSpreadingFactor(sf);
if (err != RADIOLIB_ERR_NONE)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
if (err == RADIOLIB_ERR_WRONG_MODEM)
RadioLibInterface::loraInError = true;

err = lora.setBandwidth(bw, wideLora() && (getFreq() > 1000.0f));
if (err != RADIOLIB_ERR_NONE)
Expand Down Expand Up @@ -231,7 +233,7 @@ template <typename T> void LR11x0Interface<T>::setStandby()

if (err != RADIOLIB_ERR_NONE) {
LOG_DEBUG("LR11x0 standby failed with error %d", err);
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;
}

isReceiving = false; // If we were receiving, not any more
Expand Down Expand Up @@ -278,7 +280,7 @@ template <typename T> void LR11x0Interface<T>::startReceive()
lora.startReceive(RADIOLIB_LR11X0_RX_TIMEOUT_INF, MESHTASTIC_RADIOLIB_IRQ_RX_FLAGS, RADIOLIB_IRQ_RX_DEFAULT_MASK, 0);
if (err) {
LOG_ERROR("StartReceive error: %d", err);
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;
}

RadioLibInterface::startReceive();
Expand Down Expand Up @@ -308,7 +310,7 @@ template <typename T> bool LR11x0Interface<T>::isChannelActive()
return true;

if (result == RADIOLIB_ERR_WRONG_MODEM)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;

return false;
}
Expand Down
8 changes: 5 additions & 3 deletions src/mesh/LR20x0Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ template <typename T> bool LR20x0Interface<T>::reconfigure()
int err = lora.setSpreadingFactor(sf);
if (err != RADIOLIB_ERR_NONE)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
if (err == RADIOLIB_ERR_WRONG_MODEM)
RadioLibInterface::loraInError = true;

err = lora.setBandwidth(bw); // different form than LR11xx
if (err != RADIOLIB_ERR_NONE)
Expand Down Expand Up @@ -237,7 +239,7 @@ template <typename T> void LR20x0Interface<T>::setStandby()

if (err != RADIOLIB_ERR_NONE) {
LOG_DEBUG("LR20x0 standby failed with error %d", err);
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;
}

isReceiving = false; // If we were receiving, not any more
Expand Down Expand Up @@ -285,7 +287,7 @@ template <typename T> void LR20x0Interface<T>::startReceive()
lora.startReceive(RADIOLIB_LR2021_RX_TIMEOUT_INF, MESHTASTIC_RADIOLIB_IRQ_RX_FLAGS, RADIOLIB_IRQ_RX_DEFAULT_MASK, 0);
if (err) {
LOG_ERROR("StartReceive error: %d", err);
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;
}

RadioLibInterface::startReceive();
Expand Down Expand Up @@ -315,7 +317,7 @@ template <typename T> bool LR20x0Interface<T>::isChannelActive()
return true;

if (result == RADIOLIB_ERR_WRONG_MODEM)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;

return false;
}
Expand Down
8 changes: 5 additions & 3 deletions src/mesh/RF95Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ bool RF95Interface::reconfigure()
int err = lora->setSpreadingFactor(sf);
if (err != RADIOLIB_ERR_NONE)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
if (err == RADIOLIB_ERR_WRONG_MODEM)
RadioLibInterface::loraInError = true;

err = lora->setBandwidth(bw);
if (err != RADIOLIB_ERR_NONE)
Expand Down Expand Up @@ -279,7 +281,7 @@ void RF95Interface::setStandby()
int err = lora->standby();
if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("RF95 standby %s%d", radioLibErr, err);
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;
}

isReceiving = false; // If we were receiving, not any more
Expand All @@ -304,7 +306,7 @@ void RF95Interface::startReceive()
int err = lora->startReceive();
if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("RF95 startReceive %s%d", radioLibErr, err);
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;
}

isReceiving = true;
Expand All @@ -329,7 +331,7 @@ bool RF95Interface::isChannelActive()
if (result != RADIOLIB_CHANNEL_FREE)
LOG_ERROR("RF95 isChannelActive %s%d", radioLibErr, result);
if (result == RADIOLIB_ERR_WRONG_MODEM)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;

// LOG_DEBUG("Channel is free!");
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/mesh/RadioLibInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void INTERRUPT_ATTR RadioLibInterface::isrTxLevel0()
/** Our ISR code currently needs this to find our active instance
*/
RadioLibInterface *RadioLibInterface::instance;
volatile bool RadioLibInterface::loraInError = false;
uint8_t RadioLibInterface::loraReinitAttempts = 0;

/** Could we send right now (i.e. either not actively receiving or transmitting)? */
bool RadioLibInterface::canSendImmediately()
Expand Down
3 changes: 3 additions & 0 deletions src/mesh/RadioLibInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified
*/
static RadioLibInterface *instance;

static volatile bool loraInError;
static uint8_t loraReinitAttempts;

/** Clear instance on destruction so stale pointer checks in loop() are safe */
virtual ~RadioLibInterface()
{
Expand Down
11 changes: 5 additions & 6 deletions src/mesh/SX126xInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ template <typename T> bool SX126xInterface<T>::reconfigure()
int err = lora.setSpreadingFactor(sf);
if (err != RADIOLIB_ERR_NONE)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
if (err == RADIOLIB_ERR_WRONG_MODEM)
RadioLibInterface::loraInError = true;

err = lora.setBandwidth(bw);
if (err != RADIOLIB_ERR_NONE)
Expand Down Expand Up @@ -317,10 +319,9 @@ template <typename T> void SX126xInterface<T>::setStandby()

if (err != RADIOLIB_ERR_NONE) {
LOG_DEBUG("SX126x standby %s%d", radioLibErr, err);
RadioLibInterface::loraInError = true;
#ifdef ARCH_PORTDUINO
portduino_status.LoRa_in_error = true;
#else
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
#endif
}
isReceiving = false; // If we were receiving, not any more
Expand Down Expand Up @@ -374,10 +375,9 @@ template <typename T> void SX126xInterface<T>::startReceive()
#endif
if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("SX126X %s %s%d", rxMethod, radioLibErr, err);
RadioLibInterface::loraInError = true;
#ifdef ARCH_PORTDUINO
portduino_status.LoRa_in_error = true;
#else
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
#endif
}

Expand Down Expand Up @@ -409,10 +409,9 @@ template <typename T> bool SX126xInterface<T>::isChannelActive()
if (result != RADIOLIB_CHANNEL_FREE)
LOG_ERROR("SX126X scanChannel %s%d", radioLibErr, result);
if (result == RADIOLIB_ERR_WRONG_MODEM) {
RadioLibInterface::loraInError = true;
#ifdef ARCH_PORTDUINO
portduino_status.LoRa_in_error = true;
#else
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
#endif
}

Expand Down
8 changes: 5 additions & 3 deletions src/mesh/SX128xInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ template <typename T> bool SX128xInterface<T>::reconfigure()
int err = lora.setSpreadingFactor(sf);
if (err != RADIOLIB_ERR_NONE)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
if (err == RADIOLIB_ERR_WRONG_MODEM)
RadioLibInterface::loraInError = true;

err = lora.setBandwidth(bw);
if (err != RADIOLIB_ERR_NONE)
Expand Down Expand Up @@ -177,7 +179,7 @@ template <typename T> void SX128xInterface<T>::setStandby()

if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("SX128x standby %s%d", radioLibErr, err);
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;
}
#if ARCH_PORTDUINO
if (portduino_config.lora_rxen_pin.pin != RADIOLIB_NC) {
Expand Down Expand Up @@ -269,7 +271,7 @@ template <typename T> void SX128xInterface<T>::startReceive()

if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("SX128X startReceive %s%d", radioLibErr, err);
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;
}

RadioLibInterface::startReceive();
Expand Down Expand Up @@ -300,7 +302,7 @@ template <typename T> bool SX128xInterface<T>::isChannelActive()
if (result != RADIOLIB_CHANNEL_FREE)
LOG_ERROR("SX128X scanChannel %s%d", radioLibErr, result);
if (result == RADIOLIB_ERR_WRONG_MODEM)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_RADIO_SPI_BUG);
RadioLibInterface::loraInError = true;

return false;
}
Expand Down