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
35 changes: 24 additions & 11 deletions src/mesh/LR11x0Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,32 @@ template <typename T> bool LR11x0Interface<T>::init()

template <typename T> bool LR11x0Interface<T>::reconfigure()
{
RadioLibInterface::reconfigure();
bool success = RadioLibInterface::reconfigure();

// set mode to standby
setStandby();

// configure publicly accessible settings
int err = lora.setSpreadingFactor(sf);
if (err != RADIOLIB_ERR_NONE)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
if (err != RADIOLIB_ERR_NONE) {
if (shouldReportConfigErrors())
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
success = false;
}

err = lora.setBandwidth(bw, wideLora() && (getFreq() > 1000.0f));
if (err != RADIOLIB_ERR_NONE)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
if (err != RADIOLIB_ERR_NONE) {
if (shouldReportConfigErrors())
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
success = 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)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
if (err != RADIOLIB_ERR_NONE) {
if (shouldReportConfigErrors())
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
success = false;
}

err = lora.setSyncWord(syncWord);
assert(err == RADIOLIB_ERR_NONE);
Expand All @@ -199,8 +208,11 @@ template <typename T> bool LR11x0Interface<T>::reconfigure()
assert(err == RADIOLIB_ERR_NONE);

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

err = lora.setOutputPower(power);
assert(err == RADIOLIB_ERR_NONE);
Expand All @@ -210,9 +222,10 @@ template <typename T> bool LR11x0Interface<T>::reconfigure()
if (err != RADIOLIB_ERR_NONE)
LOG_WARN("LR11x0 setRxBoostedGainMode %s%d", radioLibErr, err);

startReceive(); // restart receiving
if (success)
startReceive(); // restart receiving

return true;
return success;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Success bool may be false. What's the cost of a descriptive result?

}

template <typename T> void LR11x0Interface<T>::disableInterrupt()
Expand Down
7 changes: 6 additions & 1 deletion src/mesh/LR11x0Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ template <class T> class LR11x0Interface : public RadioLibInterface
/// \return true if initialisation succeeded.
virtual bool reconfigure() override;

bool supportsLoRaBandwidth(float bandwidthKHz, bool wideBand) override
{
return supportsLr11x0LoRaBandwidth(bandwidthKHz, wideBand);
}

/// Prepare hardware for sleep. Call this _only_ for deep sleep, not needed for light sleep.
virtual bool sleep() override;

Expand Down Expand Up @@ -74,4 +79,4 @@ template <class T> class LR11x0Interface : public RadioLibInterface

uint32_t getPacketTime(uint32_t pl, bool received) override { return computePacketTime(lora, pl, received); }
};
#endif
#endif
35 changes: 24 additions & 11 deletions src/mesh/LR20x0Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,32 @@ template <typename T> bool LR20x0Interface<T>::init()

template <typename T> bool LR20x0Interface<T>::reconfigure()
{
RadioLibInterface::reconfigure();
bool success = RadioLibInterface::reconfigure();

// set mode to standby
setStandby();

// configure publicly accessible settings
int err = lora.setSpreadingFactor(sf);
if (err != RADIOLIB_ERR_NONE)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
if (err != RADIOLIB_ERR_NONE) {
if (shouldReportConfigErrors())
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
success = false;
}

err = lora.setBandwidth(bw); // different form than LR11xx
if (err != RADIOLIB_ERR_NONE)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
if (err != RADIOLIB_ERR_NONE) {
if (shouldReportConfigErrors())
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
success = 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)
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
if (err != RADIOLIB_ERR_NONE) {
if (shouldReportConfigErrors())
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
success = false;
}

err = lora.setSyncWord(syncWord);
assert(err == RADIOLIB_ERR_NONE);
Expand All @@ -205,8 +214,11 @@ template <typename T> bool LR20x0Interface<T>::reconfigure()
assert(err == RADIOLIB_ERR_NONE);

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

err = lora.setOutputPower(power);
assert(err == RADIOLIB_ERR_NONE);
Expand All @@ -216,9 +228,10 @@ template <typename T> bool LR20x0Interface<T>::reconfigure()
if (err != RADIOLIB_ERR_NONE)
LOG_WARN("LR20x0 setRxBoostedGainMode %s%d", radioLibErr, err);

startReceive(); // restart receiving
if (success)
startReceive(); // restart receiving

return true;
return success;
}

template <typename T> void LR20x0Interface<T>::disableInterrupt()
Expand Down
5 changes: 5 additions & 0 deletions src/mesh/LR20x0Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ template <class T> class LR20x0Interface : public RadioLibInterface
/// \return true if initialisation succeeded.
virtual bool reconfigure() override;

bool supportsLoRaBandwidth(float bandwidthKHz, bool wideBand) override
{
return supportsLr20x0LoRaBandwidth(bandwidthKHz, wideBand);
}

/// Prepare hardware for sleep. Call this _only_ for deep sleep, not needed for light sleep.
virtual bool sleep() override;

Expand Down
23 changes: 22 additions & 1 deletion src/mesh/MeshRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ static inline uint16_t clampBandwidthCode(uint16_t bwCode)
return bwCode;
}

static inline bool supportsSx128xLoRaBandwidth(float bandwidthKHz, bool wideBand)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the IS_ONE_OF macro to clean up these chained comparisons in these 3 methods

{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole section looks like an anti-pattern to the rest of the file, or at least a horrible typo trap, even for an llm

return wideBand && (bandwidthKHz == 203.125f || bandwidthKHz == 406.25f || bandwidthKHz == 812.5f || bandwidthKHz == 1625.0f);
}

static inline bool supportsLr11x0LoRaBandwidth(float bandwidthKHz, bool wideBand)
{
if (wideBand)
return bandwidthKHz == 203.125f || bandwidthKHz == 406.25f || bandwidthKHz == 812.5f;

return bandwidthKHz == 62.5f || bandwidthKHz == 125.0f || bandwidthKHz == 250.0f || bandwidthKHz == 500.0f;
}

static inline bool supportsLr20x0LoRaBandwidth(float bandwidthKHz, bool wideBand)
{
(void)wideBand;
return bandwidthKHz == 31.25f || bandwidthKHz == 41.7f || bandwidthKHz == 62.5f || bandwidthKHz == 83.0f ||
bandwidthKHz == 101.0f || bandwidthKHz == 125.0f || bandwidthKHz == 203.125f || bandwidthKHz == 250.0f ||
bandwidthKHz == 406.25f || bandwidthKHz == 500.0f || bandwidthKHz == 812.5f || bandwidthKHz == 1000.0f;
}

static inline void modemPresetToParams(meshtastic_Config_LoRaConfig_ModemPreset preset, bool wideLora, float &bwKHz, uint8_t &sf,
uint8_t &cr)
{
Expand Down Expand Up @@ -294,4 +315,4 @@ static inline float modemPresetToBwKHz(meshtastic_Config_LoRaConfig_ModemPreset
uint8_t cr = 0;
modemPresetToParams(preset, wideLora, bwKHz, sf, cr);
return bwKHz;
}
}
Loading
Loading