Clamp bw for malformed use_preset false with empty bandwidth

This commit is contained in:
Ben Meadors
2026-07-09 10:30:11 -05:00
parent 168f669e61
commit 515fe8b94f
3 changed files with 124 additions and 0 deletions
+10
View File
@@ -190,6 +190,16 @@ static inline uint16_t bwKHzToCode(float bwKHz)
return (uint16_t)(bwKHz + 0.5f);
}
/// Clamp a bandwidth *code* (the on-wire config.lora.bandwidth value) to a usable value.
/// A code of 0 (proto default / unset) returns the default bandwidth's code; any other value
/// is returned unchanged (RadioLib validates the exact discrete bandwidth downstream).
static inline uint16_t clampBandwidthCode(uint16_t bwCode)
{
if (bwCode == 0)
return bwKHzToCode(LORA_BW_DEFAULT_KHZ);
return bwCode;
}
static inline void modemPresetToParams(meshtastic_Config_LoRaConfig_ModemPreset preset, bool wideLora, float &bwKHz, uint8_t &sf,
uint8_t &cr)
{