Merge adaptive CR direct retries into keymind

This commit is contained in:
mikecarper committed 2026-05-08 12:43:24 -07:00
commit ca0679e999
17 files changed
+317 -6

No files matched your search

+18
View File
@@ -556,6 +556,24 @@ This document provides an overview of CLI commands that can be sent to MeshCore
---
#### View or change adaptive coding rate for direct retry packets
**Usage:**
- `get direct.retry.cr`
- `set direct.retry.cr <cr4_min>,<cr5_min>,<cr8_max>`
- `set direct.retry.cr <cr4_min>,<cr5_min>,<low>,<low>`
**Parameters:**
- `cr4_min`: SNR in dB where retry packets use `CR4`
- `cr5_min`: SNR in dB where retry packets use `CR5`
- `cr8_max`: SNR in dB where retry packets use `CR8`
- `low`: optional repeated low boundary; both low values must match
**Default:** `10.0,7.5,2.5,2.5`
**Note:** DM retry packets with a recent repeater table entry use that entry's SNR to pick a local transmit coding rate. With the default, SNR `10.0 dB` and up uses `CR4`, SNR `7.5 dB` and up uses `CR5`, SNR `2.5 dB` and down uses `CR8`, and the middle band uses `CR7`. `CR6` is never selected. The shorter form `set direct.retry.cr 10.0,7.5,2.5` is equivalent to `set direct.retry.cr 10.0,7.5,2.5,2.5`.
---
#### View or change the SNR margin used for direct retry eligibility
**Usage:**
- `get direct.retry.margin`
+52
View File
@@ -846,6 +846,55 @@ bool MyMesh::allowDirectRetry(const mesh::Packet* packet, const uint8_t* next_ho
return true;
}
uint8_t MyMesh::getDirectRetryCodingRateForSNR(int8_t snr_x4) const {
if (snr_x4 >= _prefs.direct_retry_cr4_snr_x4) {
return 4;
}
if (snr_x4 >= _prefs.direct_retry_cr5_snr_x4) {
return 5;
}
if (snr_x4 <= _prefs.direct_retry_cr8_snr_x4) {
return 8;
}
return 7;
}
void MyMesh::configureDirectRetryPacket(mesh::Packet* retry, const mesh::Packet* original, uint8_t retry_attempt) {
(void) original;
(void) retry_attempt;
if (retry == NULL || !retry->isRouteDirect()) {
return;
}
switch (retry->getPayloadType()) {
case PAYLOAD_TYPE_ACK:
case PAYLOAD_TYPE_PATH:
case PAYLOAD_TYPE_REQ:
case PAYLOAD_TYPE_RESPONSE:
case PAYLOAD_TYPE_TXT_MSG:
case PAYLOAD_TYPE_ANON_REQ:
case PAYLOAD_TYPE_MULTIPART:
break;
default:
return;
}
uint8_t prefix[MAX_ROUTE_HASH_BYTES];
uint8_t prefix_len = 0;
if (!extractDirectRetryPrefix(retry, prefix, prefix_len)) {
return;
}
const auto* recent = ((const SimpleMeshTables *)getTables())->findRecentRepeaterByHash(prefix, prefix_len);
if (recent == NULL) {
return;
}
uint8_t retry_cr = getDirectRetryCodingRateForSNR(recent->snr_x4);
if (retry_cr >= 4 && retry_cr <= 8 && retry_cr != active_cr) {
retry->tx_cr = retry_cr;
}
}
uint8_t MyMesh::getDirectRetryPreset() const {
if (_prefs.retry_preset <= RETRY_PRESET_MOBILE) {
return _prefs.retry_preset;
@@ -1758,6 +1807,9 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
_prefs.flood_retry_path_gate = 2;
_prefs.flood_retry_bridge_enabled = 0;
_prefs.flood_retry_advert_enabled = 0;
_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;
StrHelper::strncpy(_prefs.node_name, ADVERT_NAME, sizeof(_prefs.node_name));
_prefs.node_lat = ADVERT_LAT;
_prefs.node_lon = ADVERT_LON;
+3
View File
@@ -133,6 +133,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
bool extractDirectRetryPrefix(const mesh::Packet* packet, uint8_t* prefix, uint8_t& prefix_len) const;
int8_t getDirectRetryMinSNRX4() const;
uint8_t getDirectRetryCodingRateForSNR(int8_t snr_x4) const;
uint8_t getDirectRetryPreset() const;
uint8_t getDirectRetryConfiguredMaxAttempts() const;
uint32_t getDirectRetryAttemptStepMillis() const;
@@ -181,7 +182,9 @@ protected:
uint32_t getRetransmitDelay(const mesh::Packet* packet) override;
uint32_t getDirectRetransmitDelay(const mesh::Packet* packet) override;
uint8_t getDefaultTxCodingRate() const override { return active_cr; }
bool allowDirectRetry(const mesh::Packet* packet, const uint8_t* next_hop_hash, uint8_t next_hop_hash_len) const override;
void configureDirectRetryPacket(mesh::Packet* retry, const mesh::Packet* original, uint8_t retry_attempt) override;
uint32_t getDirectRetryEchoDelay(const mesh::Packet* packet) const override;
uint8_t getDirectRetryMaxAttempts(const mesh::Packet* packet) const override;
uint32_t getDirectRetryAttemptDelay(const mesh::Packet* packet, uint8_t attempt_idx) override;
+23
View File
@@ -52,6 +52,13 @@ void Dispatcher::updateTxBudget() {
}
}
void Dispatcher::restoreOutboundCodingRate() {
if (outbound_restore_cr != 0) {
_radio->setCodingRate(outbound_restore_cr);
outbound_restore_cr = 0;
}
}
int Dispatcher::calcRxDelay(float score, uint32_t air_time) const {
return (int) ((pow(10, 0.85f - score) - 1.0) * air_time);
}
@@ -105,6 +112,7 @@ void Dispatcher::loop() {
}
_radio->onSendFinished();
restoreOutboundCodingRate();
logTx(outbound, 2 + outbound->getPathByteLen() + outbound->payload_len);
onSendComplete(outbound);
if (outbound->isRouteFlood()) {
@@ -118,6 +126,7 @@ void Dispatcher::loop() {
MESH_DEBUG_PRINTLN("%s Dispatcher::loop(): WARNING: outbound packed send timed out!", getLogDateTime());
_radio->onSendFinished();
restoreOutboundCodingRate();
logTxFail(outbound, 2 + outbound->getPathByteLen() + outbound->payload_len);
onSendFail(outbound);
@@ -150,6 +159,7 @@ void Dispatcher::loop() {
bool Dispatcher::tryParsePacket(Packet* pkt, const uint8_t* raw, int len) {
int i = 0;
pkt->tx_cr = 0;
pkt->header = raw[i++];
if (pkt->getPayloadVer() > PAYLOAD_VER_1) {
MESH_DEBUG_PRINTLN("%s Dispatcher::checkRecv(): unsupported packet version", getLogDateTime());
@@ -330,11 +340,23 @@ void Dispatcher::checkSend() {
memcpy(&raw[len], outbound->payload, outbound->payload_len); len += outbound->payload_len;
uint32_t max_airtime = _radio->getEstAirtimeFor(len)*3/2;
outbound_restore_cr = 0;
uint8_t default_cr = getDefaultTxCodingRate();
if (outbound->tx_cr >= 4 && outbound->tx_cr <= 8 && default_cr >= 4 && default_cr <= 8
&& outbound->tx_cr != default_cr) {
if (_radio->setCodingRate(outbound->tx_cr)) {
outbound_restore_cr = default_cr;
max_airtime = _radio->getEstAirtimeFor(len)*3/2;
} else {
MESH_DEBUG_PRINTLN("%s Dispatcher::checkSend(): WARN: failed to set packet CR%d", getLogDateTime(), (uint32_t)outbound->tx_cr);
}
}
outbound_start = _ms->getMillis();
bool success = _radio->startSendRaw(raw, len);
if (!success) {
MESH_DEBUG_PRINTLN("%s Dispatcher::loop(): ERROR: send start failed!", getLogDateTime());
restoreOutboundCodingRate();
logTxFail(outbound, outbound->getRawLength());
onSendFail(outbound);
@@ -366,6 +388,7 @@ Packet* Dispatcher::obtainNewPacket() {
} else {
pkt->payload_len = pkt->path_len = 0;
pkt->_snr = 0;
pkt->tx_cr = 0;
}
return pkt;
}
+10
View File
@@ -46,6 +46,12 @@ public:
*/
virtual bool startSendRaw(const uint8_t* bytes, int len) = 0;
/**
* \brief Sets LoRa coding rate for subsequent transmits/receives.
* \returns true if the radio accepted the coding rate.
*/
virtual bool setCodingRate(uint8_t cr) { return false; }
/**
* \returns true if the previous 'startSendRaw()' completed successfully.
*/
@@ -116,6 +122,7 @@ typedef uint32_t DispatcherAction;
class Dispatcher {
Packet* outbound; // current outbound packet
unsigned long outbound_expiry, outbound_start, total_air_time, rx_air_time;
uint8_t outbound_restore_cr;
unsigned long next_tx_time;
unsigned long cad_busy_start;
unsigned long radio_nonrx_start;
@@ -128,6 +135,7 @@ class Dispatcher {
unsigned long duty_cycle_window_ms;
void processRecvPacket(Packet* pkt);
void restoreOutboundCodingRate();
void updateTxBudget();
protected:
@@ -140,6 +148,7 @@ protected:
: _radio(&radio), _ms(&ms), _mgr(&mgr)
{
outbound = NULL;
outbound_restore_cr = 0;
total_air_time = rx_air_time = 0;
next_tx_time = ms.getMillis();
cad_busy_start = 0;
@@ -167,6 +176,7 @@ protected:
virtual int calcRxDelay(float score, uint32_t air_time) const;
virtual uint32_t getCADFailRetryDelay() const;
virtual uint32_t getCADFailMaxDuration() const;
virtual uint8_t getDefaultTxCodingRate() const { return 0; }
virtual int getInterferenceThreshold() const { return 0; } // disabled by default
virtual int getAGCResetInterval() const { return 0; } // disabled by default
virtual unsigned long getDutyCycleWindowMs() const { return 3600000; }
+8 -3
View File
@@ -698,16 +698,19 @@ void Mesh::armDirectRetryOnSendComplete(const Packet* packet) {
}
*retry = *packet;
retry->tx_cr = 0;
uint8_t retry_attempt = _direct_retries[i].retry_attempts_sent + 1;
configureDirectRetryPacket(retry, packet, retry_attempt);
uint32_t retry_delay = getDirectRetryAttemptDelay(packet, _direct_retries[i].retry_attempts_sent);
if (queueOutboundPacket(retry, _direct_retries[i].priority, retry_delay)) {
_direct_retries[i].packet = retry;
_direct_retries[i].retry_delay = retry_delay;
_direct_retries[i].retry_at = futureMillis(retry_delay);
_direct_retries[i].waiting_final_echo = false;
onDirectRetryEvent("queued", retry, retry_delay, _direct_retries[i].retry_attempts_sent + 1);
onDirectRetryEvent("queued", retry, retry_delay, retry_attempt);
} else {
onDirectRetryEvent("dropped_queue_full", retry, retry_delay, _direct_retries[i].retry_attempts_sent + 1);
onDirectRetryEvent("failure", retry, elapsed_millis, _direct_retries[i].retry_attempts_sent + 1);
onDirectRetryEvent("dropped_queue_full", retry, retry_delay, retry_attempt);
onDirectRetryEvent("failure", retry, elapsed_millis, retry_attempt);
releasePacket(retry);
clearDirectRetrySlot(i);
}
@@ -729,6 +732,8 @@ void Mesh::armDirectRetryOnSendComplete(const Packet* packet) {
}
*retry = *packet;
retry->tx_cr = 0;
configureDirectRetryPacket(retry, packet, 1);
// Start the echo wait only after the initial direct transmission actually completed.
if (queueOutboundPacket(retry, _direct_retries[i].priority, _direct_retries[i].retry_delay)) {
+5
View File
@@ -195,6 +195,11 @@ protected:
*/
virtual void onDirectRetryEvent(const char* event, const Packet* packet, uint32_t delay_millis, uint8_t retry_attempt) { }
/**
* \brief Optional hook to set local-only transmit options on a retry packet before it is queued.
*/
virtual void configureDirectRetryPacket(Packet* retry, const Packet* original, uint8_t retry_attempt) { }
/**
* \brief Perform search of local DB of peers/contacts.
* \returns Number of peers with matching hash
+3 -1
View File
@@ -8,6 +8,7 @@ Packet::Packet() {
header = 0;
path_len = 0;
payload_len = 0;
tx_cr = 0;
}
bool Packet::isValidPathLen(uint8_t path_len) {
@@ -64,6 +65,7 @@ uint8_t Packet::writeTo(uint8_t dest[]) const {
bool Packet::readFrom(const uint8_t src[], uint8_t len) {
uint8_t i = 0;
tx_cr = 0;
header = src[i++];
if (hasTransportCodes()) {
memcpy(&transport_codes[0], &src[i], 2); i += 2;
@@ -84,4 +86,4 @@ bool Packet::readFrom(const uint8_t src[], uint8_t len) {
return true; // success
}
}
}
+1
View File
@@ -49,6 +49,7 @@ public:
uint8_t path[MAX_PATH_SIZE];
uint8_t payload[MAX_PACKET_PAYLOAD];
int8_t _snr;
uint8_t tx_cr; // volatile local-only TX coding-rate override; not serialized
/**
* \brief calculate the hash of payload + type
+130 -2
View File
@@ -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++ = ' ';
+9
View File
@@ -63,6 +63,12 @@
#define COMMON_CLI_TMP_LEN ((FLOOD_RETRY_LIST_TEXT_MAX > (PRV_KEY_SIZE * 2 + 4)) ? FLOOD_RETRY_LIST_TEXT_MAX : (PRV_KEY_SIZE * 2 + 4))
#endif
#define DIRECT_RETRY_CR4_MIN_SNR_X4_DEFAULT 40 // 10.0 dB and up => CR4
#define DIRECT_RETRY_CR5_MIN_SNR_X4_DEFAULT 30 // 7.5 dB and up => CR5
#define DIRECT_RETRY_CR8_MAX_SNR_X4_DEFAULT 10 // 2.5 dB and down => CR8
#define DIRECT_RETRY_CR_SNR_X4_MIN -128
#define DIRECT_RETRY_CR_SNR_X4_MAX 127
struct NodePrefs { // persisted to file
float airtime_factor;
char node_name[32];
@@ -121,6 +127,9 @@ struct NodePrefs { // persisted to file
uint8_t flood_retry_bridge_buckets[FLOOD_RETRY_BRIDGE_BUCKETS][FLOOD_RETRY_BUCKET_PREFIXES][FLOOD_RETRY_PREFIX_LEN];
uint8_t flood_retry_ignore_prefixes[FLOOD_RETRY_IGNORE_PREFIXES][FLOOD_RETRY_PREFIX_LEN];
uint8_t flood_retry_advert_enabled;
int8_t direct_retry_cr4_snr_x4;
int8_t direct_retry_cr5_snr_x4;
int8_t direct_retry_cr8_snr_x4;
};
class CommonCLICallbacks {
@@ -20,6 +20,15 @@ public:
int sf = ((CustomLLCC68 *)_radio)->spreadingFactor;
return packetScoreInt(snr, sf, packet_len);
}
bool setCodingRate(uint8_t cr) override {
idle();
int err = ((CustomLLCC68 *)_radio)->setCodingRate(cr);
if (err != RADIOLIB_ERR_NONE) {
MESH_DEBUG_PRINTLN("CustomLLCC68Wrapper: error: setCodingRate(%d)=%d", (uint32_t)cr, err);
return false;
}
return true;
}
void doResetAGC() override { sx126xResetAGC((SX126x *)_radio); }
@@ -25,6 +25,16 @@ public:
float getLastRSSI() const override { return ((CustomLR1110 *)_radio)->getRSSI(); }
float getLastSNR() const override { return ((CustomLR1110 *)_radio)->getSNR(); }
bool setCodingRate(uint8_t cr) override {
idle();
int err = ((CustomLR1110 *)_radio)->setCodingRate(cr);
if (err != RADIOLIB_ERR_NONE) {
MESH_DEBUG_PRINTLN("CustomLR1110Wrapper: error: setCodingRate(%d)=%d", (uint32_t)cr, err);
return false;
}
return true;
}
void setRxBoostedGainMode(bool en) override {
((CustomLR1110 *)_radio)->setRxBoostedGainMode(en);
}
@@ -21,6 +21,15 @@ public:
int sf = ((CustomSTM32WLx *)_radio)->spreadingFactor;
return packetScoreInt(snr, sf, packet_len);
}
bool setCodingRate(uint8_t cr) override {
idle();
int err = ((CustomSTM32WLx *)_radio)->setCodingRate(cr);
if (err != RADIOLIB_ERR_NONE) {
MESH_DEBUG_PRINTLN("CustomSTM32WLxWrapper: error: setCodingRate(%d)=%d", (uint32_t)cr, err);
return false;
}
return true;
}
void doResetAGC() override { sx126xResetAGC((SX126x *)_radio); }
};
@@ -24,6 +24,15 @@ public:
int sf = ((CustomSX1262 *)_radio)->spreadingFactor;
return packetScoreInt(snr, sf, packet_len);
}
bool setCodingRate(uint8_t cr) override {
idle();
int err = ((CustomSX1262 *)_radio)->setCodingRate(cr);
if (err != RADIOLIB_ERR_NONE) {
MESH_DEBUG_PRINTLN("CustomSX1262Wrapper: error: setCodingRate(%d)=%d", (uint32_t)cr, err);
return false;
}
return true;
}
virtual void powerOff() override {
((CustomSX1262 *)_radio)->sleep(false);
}
@@ -24,6 +24,15 @@ public:
int sf = ((CustomSX1268 *)_radio)->spreadingFactor;
return packetScoreInt(snr, sf, packet_len);
}
bool setCodingRate(uint8_t cr) override {
idle();
int err = ((CustomSX1268 *)_radio)->setCodingRate(cr);
if (err != RADIOLIB_ERR_NONE) {
MESH_DEBUG_PRINTLN("CustomSX1268Wrapper: error: setCodingRate(%d)=%d", (uint32_t)cr, err);
return false;
}
return true;
}
void doResetAGC() override { sx126xResetAGC((SX126x *)_radio); }
@@ -23,4 +23,13 @@ public:
int sf = ((CustomSX1276 *)_radio)->spreadingFactor;
return packetScoreInt(snr, sf, packet_len);
}
bool setCodingRate(uint8_t cr) override {
idle();
int err = ((CustomSX1276 *)_radio)->setCodingRate(cr);
if (err != RADIOLIB_ERR_NONE) {
MESH_DEBUG_PRINTLN("CustomSX1276Wrapper: error: setCodingRate(%d)=%d", (uint32_t)cr, err);
return false;
}
return true;
}
};