Merge adaptive CR direct retries into keymind
This commit is contained in:
commit
ca0679e999
17 files changed
+317
-6
No files matched your search
+130
-2
@@ -114,6 +114,38 @@ static uint8_t directRetryEffectiveMarginX4(const NodePrefs* prefs) {
|
||||
return constrain(prefs->direct_retry_snr_margin_db, (uint8_t)0, (uint8_t)DIRECT_RETRY_SNR_MARGIN_X4_MAX);
|
||||
}
|
||||
|
||||
static float directRetryCrX4ToDb(int8_t snr_x4) {
|
||||
return ((float)snr_x4) / 4.0f;
|
||||
}
|
||||
|
||||
static void setDirectRetryCrDefaults(NodePrefs* prefs) {
|
||||
prefs->direct_retry_cr4_snr_x4 = DIRECT_RETRY_CR4_MIN_SNR_X4_DEFAULT;
|
||||
prefs->direct_retry_cr5_snr_x4 = DIRECT_RETRY_CR5_MIN_SNR_X4_DEFAULT;
|
||||
prefs->direct_retry_cr8_snr_x4 = DIRECT_RETRY_CR8_MAX_SNR_X4_DEFAULT;
|
||||
}
|
||||
|
||||
static bool directRetryCrThresholdsAreValid(int8_t cr4_snr_x4, int8_t cr5_snr_x4, int8_t cr8_snr_x4) {
|
||||
return (cr4_snr_x4 != 0 || cr5_snr_x4 != 0 || cr8_snr_x4 != 0)
|
||||
&& cr4_snr_x4 >= cr5_snr_x4
|
||||
&& cr5_snr_x4 >= cr8_snr_x4;
|
||||
}
|
||||
|
||||
static void sanitizeDirectRetryCrThresholds(NodePrefs* prefs) {
|
||||
if (!directRetryCrThresholdsAreValid(prefs->direct_retry_cr4_snr_x4,
|
||||
prefs->direct_retry_cr5_snr_x4,
|
||||
prefs->direct_retry_cr8_snr_x4)) {
|
||||
setDirectRetryCrDefaults(prefs);
|
||||
}
|
||||
}
|
||||
|
||||
static void formatDirectRetryCrThresholds(const NodePrefs* prefs, char* reply) {
|
||||
char cr4[12], cr5[12], cr8[12];
|
||||
strcpy(cr4, StrHelper::ftoa(directRetryCrX4ToDb(prefs->direct_retry_cr4_snr_x4)));
|
||||
strcpy(cr5, StrHelper::ftoa(directRetryCrX4ToDb(prefs->direct_retry_cr5_snr_x4)));
|
||||
strcpy(cr8, StrHelper::ftoa(directRetryCrX4ToDb(prefs->direct_retry_cr8_snr_x4)));
|
||||
sprintf(reply, "> %s,%s,%s,%s", cr4, cr5, cr8, cr8);
|
||||
}
|
||||
|
||||
static uint16_t retryPresetStepDefault(uint8_t preset) {
|
||||
switch (retryPresetOrDefault(preset)) {
|
||||
case RETRY_PRESET_INFRA:
|
||||
@@ -332,6 +364,63 @@ static bool parseRetryPreset(const char* value, uint8_t& preset) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool parseDirectRetryCrDb(const char* value, int8_t& snr_x4) {
|
||||
if (value == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char* end = NULL;
|
||||
float snr_db = strtof(value, &end);
|
||||
while (end != NULL && *end == ' ') end++;
|
||||
if (end == value || (end != NULL && *end != 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t scaled_x4 = (int32_t)((snr_db * 4.0f) + (snr_db >= 0.0f ? 0.5f : -0.5f));
|
||||
if (scaled_x4 < DIRECT_RETRY_CR_SNR_X4_MIN || scaled_x4 > DIRECT_RETRY_CR_SNR_X4_MAX) {
|
||||
return false;
|
||||
}
|
||||
snr_x4 = (int8_t)scaled_x4;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parseDirectRetryCrThresholds(char* value, NodePrefs* prefs) {
|
||||
if (value == NULL || prefs == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* parts[4];
|
||||
int num = mesh::Utils::parseTextParts(value, parts, 4);
|
||||
if (num != 3 && num != 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int8_t cr4_snr_x4;
|
||||
int8_t cr5_snr_x4;
|
||||
int8_t cr8_snr_x4;
|
||||
if (!parseDirectRetryCrDb(parts[0], cr4_snr_x4)
|
||||
|| !parseDirectRetryCrDb(parts[1], cr5_snr_x4)
|
||||
|| !parseDirectRetryCrDb(parts[num == 4 ? 3 : 2], cr8_snr_x4)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (num == 4) {
|
||||
int8_t repeated_low_snr_x4;
|
||||
if (!parseDirectRetryCrDb(parts[2], repeated_low_snr_x4) || repeated_low_snr_x4 != cr8_snr_x4) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!directRetryCrThresholdsAreValid(cr4_snr_x4, cr5_snr_x4, cr8_snr_x4)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
prefs->direct_retry_cr4_snr_x4 = cr4_snr_x4;
|
||||
prefs->direct_retry_cr5_snr_x4 = cr5_snr_x4;
|
||||
prefs->direct_retry_cr8_snr_x4 = cr8_snr_x4;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool isValidName(const char *n) {
|
||||
while (*n) {
|
||||
if (*n == '[' || *n == ']' || *n == '\\' || *n == ':' || *n == ',' || *n == '?' || *n == '*') return false;
|
||||
@@ -347,6 +436,8 @@ void CommonCLI::loadPrefs(FILESYSTEM* fs) {
|
||||
loadPrefsInt(fs, "/node_prefs");
|
||||
savePrefs(fs); // save to new filename
|
||||
fs->remove("/node_prefs"); // remove old
|
||||
} else {
|
||||
setDirectRetryCrDefaults(_prefs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,6 +522,13 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
_prefs->flood_retry_advert_enabled = FLOOD_RETRY_ADVERT_DEFAULT;
|
||||
size_t flood_retry_advert_read = file.read((uint8_t *)&_prefs->flood_retry_advert_enabled,
|
||||
sizeof(_prefs->flood_retry_advert_enabled)); // 659
|
||||
size_t retry_cr_read = 0;
|
||||
retry_cr_read += file.read((uint8_t *)&_prefs->direct_retry_cr4_snr_x4,
|
||||
sizeof(_prefs->direct_retry_cr4_snr_x4)); // 660
|
||||
retry_cr_read += file.read((uint8_t *)&_prefs->direct_retry_cr5_snr_x4,
|
||||
sizeof(_prefs->direct_retry_cr5_snr_x4)); // 661
|
||||
retry_cr_read += file.read((uint8_t *)&_prefs->direct_retry_cr8_snr_x4,
|
||||
sizeof(_prefs->direct_retry_cr8_snr_x4)); // 662
|
||||
// PowerSaving-only prefs stored radio_fem_rxgain at 291, before direct retry timing existed.
|
||||
if (radio_fem_rxgain_read != sizeof(_prefs->radio_fem_rxgain)
|
||||
&& legacy_retry_attempts_read == sizeof(legacy_retry_attempts_or_radio_fem_rxgain)
|
||||
@@ -438,7 +536,7 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
|| _prefs->direct_retry_timing_magic[1] != DIRECT_RETRY_TIMING_MAGIC_1)) {
|
||||
_prefs->radio_fem_rxgain = constrain(legacy_retry_attempts_or_radio_fem_rxgain, 0, 1);
|
||||
}
|
||||
// next: 659
|
||||
// next: 663
|
||||
|
||||
// sanitise bad pref values
|
||||
_prefs->rx_delay_base = constrain(_prefs->rx_delay_base, 0, 20.0f);
|
||||
@@ -516,6 +614,13 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
_prefs->flood_retry_advert_enabled = constrain(_prefs->flood_retry_advert_enabled, 0, 1);
|
||||
}
|
||||
}
|
||||
if (retry_cr_read != sizeof(_prefs->direct_retry_cr4_snr_x4)
|
||||
+ sizeof(_prefs->direct_retry_cr5_snr_x4)
|
||||
+ sizeof(_prefs->direct_retry_cr8_snr_x4)) {
|
||||
setDirectRetryCrDefaults(_prefs);
|
||||
} else {
|
||||
sanitizeDirectRetryCrThresholds(_prefs);
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
@@ -597,7 +702,10 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
|
||||
file.write((uint8_t *)&_prefs->flood_retry_bridge_buckets[0][0][0], sizeof(_prefs->flood_retry_bridge_buckets)); // 329
|
||||
file.write((uint8_t *)&_prefs->flood_retry_ignore_prefixes[0][0], sizeof(_prefs->flood_retry_ignore_prefixes)); // 635
|
||||
file.write((uint8_t *)&_prefs->flood_retry_advert_enabled, sizeof(_prefs->flood_retry_advert_enabled)); // 659
|
||||
// next: 660
|
||||
file.write((uint8_t *)&_prefs->direct_retry_cr4_snr_x4, sizeof(_prefs->direct_retry_cr4_snr_x4)); // 660
|
||||
file.write((uint8_t *)&_prefs->direct_retry_cr5_snr_x4, sizeof(_prefs->direct_retry_cr5_snr_x4)); // 661
|
||||
file.write((uint8_t *)&_prefs->direct_retry_cr8_snr_x4, sizeof(_prefs->direct_retry_cr8_snr_x4)); // 662
|
||||
// next: 663
|
||||
|
||||
file.close();
|
||||
}
|
||||
@@ -791,6 +899,8 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
|
||||
sprintf(reply, "> %d", (uint32_t)directRetryEffectiveBaseMs(_prefs));
|
||||
} else if (memcmp(config, "direct.retry.step", 17) == 0) {
|
||||
sprintf(reply, "> %d", (uint32_t)directRetryEffectiveStepMs(_prefs));
|
||||
} else if (memcmp(config, "direct.retry.cr", 15) == 0) {
|
||||
formatDirectRetryCrThresholds(_prefs, reply);
|
||||
} else if (memcmp(config, "owner.info", 10) == 0) {
|
||||
*reply++ = '>';
|
||||
*reply++ = ' ';
|
||||
@@ -1169,6 +1279,14 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
|
||||
} else {
|
||||
sprintf(reply, "Error, min %d and max %d", DIRECT_RETRY_STEP_MS_MIN, DIRECT_RETRY_STEP_MS_MAX);
|
||||
}
|
||||
} else if (memcmp(config, "direct.retry.cr ", 16) == 0) {
|
||||
StrHelper::strncpy(tmp, &config[16], sizeof(tmp));
|
||||
if (parseDirectRetryCrThresholds(tmp, _prefs)) {
|
||||
savePrefs();
|
||||
formatDirectRetryCrThresholds(_prefs, reply);
|
||||
} else {
|
||||
strcpy(reply, "Error, expected cr4,cr5,cr8 or cr4,cr5,low,low");
|
||||
}
|
||||
} else if (memcmp(config, "owner.info ", 11) == 0) {
|
||||
config += 11;
|
||||
char *dp = _prefs->owner_info;
|
||||
@@ -1795,6 +1913,14 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
} else {
|
||||
sprintf(reply, "Error, min %d and max %d", DIRECT_RETRY_STEP_MS_MIN, DIRECT_RETRY_STEP_MS_MAX);
|
||||
}
|
||||
} else if (memcmp(config, "direct.retry.cr ", 16) == 0) {
|
||||
StrHelper::strncpy(tmp, &config[16], sizeof(tmp));
|
||||
if (parseDirectRetryCrThresholds(tmp, _prefs)) {
|
||||
savePrefs();
|
||||
formatDirectRetryCrThresholds(_prefs, reply);
|
||||
} else {
|
||||
strcpy(reply, "Error, expected cr4,cr5,cr8 or cr4,cr5,low,low");
|
||||
}
|
||||
} else if (memcmp(config, "owner.info ", 11) == 0) {
|
||||
config += 11;
|
||||
char *dp = _prefs->owner_info;
|
||||
@@ -2006,6 +2132,8 @@ void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
sprintf(reply, "> %d", (uint32_t)directRetryEffectiveBaseMs(_prefs));
|
||||
} else if (memcmp(config, "direct.retry.step", 17) == 0) {
|
||||
sprintf(reply, "> %d", (uint32_t)directRetryEffectiveStepMs(_prefs));
|
||||
} else if (memcmp(config, "direct.retry.cr", 15) == 0) {
|
||||
formatDirectRetryCrThresholds(_prefs, reply);
|
||||
} else if (memcmp(config, "owner.info", 10) == 0) {
|
||||
*reply++ = '>';
|
||||
*reply++ = ' ';
|
||||
|
||||
Reference in new issue
Block a user