Skip to content
Open
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
40 changes: 29 additions & 11 deletions src/mesh/LR11x0Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,33 @@ template <typename T> bool LR11x0Interface<T>::reconfigure()
// set mode to standby
setStandby();

// configure publicly accessible settings
// The caller reboots the device when reconfigure returns false; track
// every SPI setter so we don't silently report success after a glitch.
bool ok = true;

int err = lora.setSpreadingFactor(sf);
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora.setBandwidth(bw, wideLora() && (getFreq() > 1000.0f));
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora.setCodingRate(cr, cr != 7); // use long interleaving except if CR is 4/7 which doesn't support it
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora.setSyncWord(syncWord);
assert(err == RADIOLIB_ERR_NONE);
if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("LR11x0 setSyncWord %s%d", radioLibErr, err);
ok = false;
}

if (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_LORA_24) { // clamp if wide freq range
limitPower(LR1120_MAX_POWER);
Expand All @@ -196,14 +208,22 @@ template <typename T> bool LR11x0Interface<T>::reconfigure()
}

err = lora.setPreambleLength(preambleLength);
assert(err == RADIOLIB_ERR_NONE);
if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("LR11x0 setPreambleLength %s%d", radioLibErr, err);
ok = false;
}

err = lora.setFrequency(getFreq());
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora.setOutputPower(power);
assert(err == RADIOLIB_ERR_NONE);
if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("LR11x0 setOutputPower %s%d", radioLibErr, err);
ok = false;
}

// Apply RX gain mode — valid in STDBY, matches resetAGC() pattern
err = lora.setRxBoostedGainMode(config.lora.sx126x_rx_boosted_gain);
Expand All @@ -212,7 +232,7 @@ template <typename T> bool LR11x0Interface<T>::reconfigure()

startReceive(); // restart receiving

return true;
return ok;
}

template <typename T> void LR11x0Interface<T>::disableInterrupt()
Expand All @@ -230,8 +250,6 @@ template <typename T> void LR11x0Interface<T>::setStandby()
LOG_DEBUG("LR11x0 standby failed with error %d", err);
}

assert(err == RADIOLIB_ERR_NONE);

isReceiving = false; // If we were receiving, not any more
activeReceiveStart = 0;
disableInterrupt();
Expand Down
40 changes: 29 additions & 11 deletions src/mesh/LR20x0Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,33 @@ template <typename T> bool LR20x0Interface<T>::reconfigure()
// set mode to standby
setStandby();

// configure publicly accessible settings
// The caller reboots the device when reconfigure returns false; track
// every SPI setter so we don't silently report success after a glitch.
bool ok = true;

int err = lora.setSpreadingFactor(sf);
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora.setBandwidth(bw); // different form than LR11xx
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora.setCodingRate(cr, cr != 7); // use long interleaving except if CR is 4/7 which doesn't support it
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora.setSyncWord(syncWord);
assert(err == RADIOLIB_ERR_NONE);
if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("LR20x0 setSyncWord %s%d", radioLibErr, err);
ok = false;
}

if (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_LORA_24) { // clamp if wide freq range
limitPower(LR2021_MAX_POWER_HF);
Expand All @@ -224,14 +236,22 @@ template <typename T> bool LR20x0Interface<T>::reconfigure()
}

err = lora.setPreambleLength(preambleLength);
assert(err == RADIOLIB_ERR_NONE);
if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("LR20x0 setPreambleLength %s%d", radioLibErr, err);
ok = false;
}

err = lora.setFrequency(getFreq());
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora.setOutputPower(power);
assert(err == RADIOLIB_ERR_NONE);
if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("LR20x0 setOutputPower %s%d", radioLibErr, err);
ok = false;
}

// Apply RX gain mode — valid in STDBY, matches resetAGC() pattern
err = lora.setRxBoostedGainMode(config.lora.sx126x_rx_boosted_gain);
Expand All @@ -240,7 +260,7 @@ template <typename T> bool LR20x0Interface<T>::reconfigure()

startReceive(); // restart receiving

return true;
return ok;
}

template <typename T> void LR20x0Interface<T>::disableInterrupt()
Expand All @@ -258,8 +278,6 @@ template <typename T> void LR20x0Interface<T>::setStandby()
LOG_DEBUG("LR20x0 standby failed with error %d", err);
}

assert(err == RADIOLIB_ERR_NONE);

isReceiving = false; // If we were receiving, not any more
activeReceiveStart = 0;
disableInterrupt();
Expand Down
42 changes: 29 additions & 13 deletions src/mesh/RF95Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,37 +208,51 @@ bool RF95Interface::reconfigure()
// set mode to standby
setStandby();

// configure publicly accessible settings
// The caller reboots the device when reconfigure returns false; track
// every SPI setter so we don't silently report success after a glitch.
bool ok = true;

int err = lora->setSpreadingFactor(sf);
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora->setBandwidth(bw);
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora->setCodingRate(cr);
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

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);
ok = false;
}

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);
ok = false;
}

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);
ok = false;
}

err = lora->setFrequency(getFreq());
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

limitPower(RF95_MAX_POWER);

Expand All @@ -247,12 +261,14 @@ bool RF95Interface::reconfigure()
#else
err = lora->setOutputPower(power);
#endif
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

startReceive(); // restart receiving

return true;
return ok;
}
Comment on lines 269 to 272

/**
Expand Down
45 changes: 29 additions & 16 deletions src/mesh/SX126xInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,47 +213,62 @@ template <typename T> bool SX126xInterface<T>::reconfigure()
// set mode to standby
setStandby();

// configure publicly accessible settings
// The caller reboots the device when reconfigure returns false; track
// every SPI setter so we don't silently report success after a glitch.
bool ok = true;

int err = lora.setSpreadingFactor(sf);
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora.setBandwidth(bw);
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

err = lora.setCodingRate(cr);
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

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);
ok = false;
}

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);
ok = false;
}

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);
ok = false;
}

err = lora.setFrequency(getFreq());
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
ok = false;
}

limitPower(SX126X_MAX_POWER);
// Make sure we reach the minimum power supported to turn the chip on (-9dBm)
if (power < -9)
power = -9;

err = lora.setOutputPower(power);
if (err != RADIOLIB_ERR_NONE)
if (err != RADIOLIB_ERR_NONE) {
LOG_ERROR("SX126X setOutputPower %s%d", radioLibErr, err);
assert(err == RADIOLIB_ERR_NONE);
ok = false;
}

// Apply RX gain mode — valid in STDBY (datasheet §9.6), matches resetAGC() pattern
err = lora.setRxBoostedGainMode(config.lora.sx126x_rx_boosted_gain);
Expand All @@ -262,7 +277,7 @@ template <typename T> bool SX126xInterface<T>::reconfigure()

startReceive(); // restart receiving

return true;
return ok;
}

template <typename T> void SX126xInterface<T>::disableInterrupt()
Expand All @@ -281,8 +296,6 @@ template <typename T> void SX126xInterface<T>::setStandby()
#ifdef ARCH_PORTDUINO
if (err != RADIOLIB_ERR_NONE)
portduino_status.LoRa_in_error = true;
#else
assert(err == RADIOLIB_ERR_NONE);
#endif
isReceiving = false; // If we were receiving, not any more
activeReceiveStart = 0;
Expand Down
Loading
Loading