Fall back to default modem preset if requested bandwidth is too large (#4497)

This commit is contained in:
GUVWAF 2024-08-18 16:14:23 +02:00 committed by GitHub
parent e3e36e23f9
commit 7a65c8838d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 85 additions and 63 deletions

View File

@ -412,6 +412,8 @@ void RadioInterface::applyModemConfig()
// Set up default configuration // Set up default configuration
// No Sync Words in LORA mode // No Sync Words in LORA mode
meshtastic_Config_LoRaConfig &loraConfig = config.lora; meshtastic_Config_LoRaConfig &loraConfig = config.lora;
bool validConfig = false; // We need to check for a valid configuration
while (!validConfig) {
if (loraConfig.use_preset) { if (loraConfig.use_preset) {
switch (loraConfig.modem_preset) { switch (loraConfig.modem_preset) {
@ -480,6 +482,25 @@ void RadioInterface::applyModemConfig()
bw = 1625.0; bw = 1625.0;
} }
if ((myRegion->freqEnd - myRegion->freqStart) < bw / 1000) {
static const char *err_string =
"Regional frequency range is smaller than bandwidth. Falling back to default preset.\n";
LOG_ERROR(err_string);
RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING);
meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed();
cn->level = meshtastic_LogRecord_Level_ERROR;
sprintf(cn->message, err_string);
service->sendClientNotification(cn);
// Set to default modem preset
loraConfig.use_preset = true;
loraConfig.modem_preset = meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST;
} else {
validConfig = true;
}
}
power = loraConfig.tx_power; power = loraConfig.tx_power;
if ((power == 0) || ((power + REGULATORY_GAIN_LORA > myRegion->powerLimit) && !devicestate.owner.is_licensed)) if ((power == 0) || ((power + REGULATORY_GAIN_LORA > myRegion->powerLimit) && !devicestate.owner.is_licensed))

View File

@ -5,6 +5,7 @@
#include "Observer.h" #include "Observer.h"
#include "PointerQueue.h" #include "PointerQueue.h"
#include "airtime.h" #include "airtime.h"
#include "error.h"
#define MAX_TX_QUEUE 16 // max number of packets which can be waiting for transmission #define MAX_TX_QUEUE 16 // max number of packets which can be waiting for transmission