Expose Companion flood retry controls and clarify T096 fixed TX PA
This commit is contained in:
1 parent
90dee6cd1b
commit
d4b3bb5678
9 files changed
+336
-12
No files matched your search
@@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
|
||||
#include <helpers/CLICommandUtils.h>
|
||||
#include "NodePrefs.h"
|
||||
|
||||
namespace mesh { namespace companion {
|
||||
|
||||
// Companion keeps the historical core retry budget by default. These are
|
||||
// local Companion controls; repeater presets and bridge prefix filters have
|
||||
// different forwarding semantics and are intentionally not exposed here.
|
||||
template <typename SavePrefs, typename CancelFloodRetries>
|
||||
bool handleRetryCommand(CompanionNodePrefs& prefs, const char* command,
|
||||
char* reply, size_t reply_size,
|
||||
SavePrefs save_prefs,
|
||||
CancelFloodRetries cancel_flood_retries) {
|
||||
if (command == nullptr || reply == nullptr || reply_size == 0) return false;
|
||||
|
||||
const bool get = strncmp(command, "get ", 4) == 0;
|
||||
const bool set = strncmp(command, "set ", 4) == 0;
|
||||
if (!get && !set) return false;
|
||||
const char* key = command + 4;
|
||||
const char* value = set ? strchr(key, ' ') : nullptr;
|
||||
const size_t key_len = value == nullptr ? strlen(key) : static_cast<size_t>(value - key);
|
||||
const auto matches = [key, key_len](const char* name) {
|
||||
return strlen(name) == key_len && strncmp(key, name, key_len) == 0;
|
||||
};
|
||||
|
||||
enum Field { Count, Path, GroupPath, Advert };
|
||||
Field field;
|
||||
if (matches("flood.retry.count")) field = Count;
|
||||
else if (matches("flood.retry.path")) field = Path;
|
||||
else if (matches("flood.retry.group.path")) field = GroupPath;
|
||||
else if (matches("flood.retry.advert")) field = Advert;
|
||||
else return false;
|
||||
|
||||
if (get) {
|
||||
if (field == Count) {
|
||||
snprintf(reply, reply_size, "> %u", (unsigned)prefs.flood_retry_attempts);
|
||||
} else if (field == Advert) {
|
||||
snprintf(reply, reply_size, "> %s", prefs.flood_retry_advert_enabled ? "on" : "off");
|
||||
} else {
|
||||
const uint8_t gate = field == Path
|
||||
? prefs.flood_retry_max_path : prefs.flood_retry_group_max_path;
|
||||
if (gate == 0xFF) snprintf(reply, reply_size, "> off");
|
||||
else snprintf(reply, reply_size, "> %u", (unsigned)gate);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* input = value == nullptr ? "" : value + 1;
|
||||
const uint8_t old_count = prefs.flood_retry_attempts;
|
||||
const uint8_t old_path = prefs.flood_retry_max_path;
|
||||
const uint8_t old_group_path = prefs.flood_retry_group_max_path;
|
||||
const uint8_t old_advert = prefs.flood_retry_advert_enabled;
|
||||
uint32_t parsed = 0;
|
||||
bool valid = true;
|
||||
|
||||
if (field == Advert) {
|
||||
if (strcmp(input, "on") == 0) prefs.flood_retry_advert_enabled = 1;
|
||||
else if (strcmp(input, "off") == 0) prefs.flood_retry_advert_enabled = 0;
|
||||
else valid = false;
|
||||
} else if (field == Count) {
|
||||
valid = cli::parseUnsignedIntegerStrict(input, parsed) && parsed <= 15;
|
||||
if (valid) prefs.flood_retry_attempts = static_cast<uint8_t>(parsed);
|
||||
} else {
|
||||
if (strcmp(input, "off") == 0) parsed = 0xFF;
|
||||
else valid = cli::parseUnsignedIntegerStrict(input, parsed) && parsed <= 63;
|
||||
if (valid) {
|
||||
if (field == Path) prefs.flood_retry_max_path = static_cast<uint8_t>(parsed);
|
||||
else prefs.flood_retry_group_max_path = static_cast<uint8_t>(parsed);
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
const char* range = field == Count ? "0-15"
|
||||
: field == Advert ? "on|off" : "0-63|off";
|
||||
snprintf(reply, reply_size, "Error: use set %.*s <%s>",
|
||||
(int)key_len, key, range);
|
||||
return true;
|
||||
}
|
||||
if (!save_prefs()) {
|
||||
prefs.flood_retry_attempts = old_count;
|
||||
prefs.flood_retry_max_path = old_path;
|
||||
prefs.flood_retry_group_max_path = old_group_path;
|
||||
prefs.flood_retry_advert_enabled = old_advert;
|
||||
snprintf(reply, reply_size, "Error: retry setting could not be saved");
|
||||
return true;
|
||||
}
|
||||
if (old_count != 0 && prefs.flood_retry_attempts == 0) cancel_flood_retries();
|
||||
snprintf(reply, reply_size, "OK");
|
||||
return true;
|
||||
}
|
||||
|
||||
} } // namespace mesh::companion
|
||||
@@ -1032,6 +1032,13 @@ bool DataStore::loadPrefsInt(const char *filename,
|
||||
#endif
|
||||
#if defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
|
||||
323, // Pico W additionally persists its SSID/password (ESP32 uses NVS)
|
||||
#endif
|
||||
230, // Companion flood retry controls, appended after prior fields
|
||||
#ifdef TBEAM_1W
|
||||
237,
|
||||
#endif
|
||||
#if defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
|
||||
327,
|
||||
#endif
|
||||
};
|
||||
const uint32_t prefs_size = file.size();
|
||||
@@ -1164,6 +1171,14 @@ bool DataStore::loadPrefsInt(const char *filename,
|
||||
loaded_prefs.wifi_ssid[sizeof(loaded_prefs.wifi_ssid) - 1] = 0;
|
||||
loaded_prefs.wifi_pwd[sizeof(loaded_prefs.wifi_pwd) - 1] = 0;
|
||||
#endif
|
||||
readOptionalField(&loaded_prefs.flood_retry_attempts,
|
||||
sizeof(loaded_prefs.flood_retry_attempts));
|
||||
readOptionalField(&loaded_prefs.flood_retry_max_path,
|
||||
sizeof(loaded_prefs.flood_retry_max_path));
|
||||
readOptionalField(&loaded_prefs.flood_retry_group_max_path,
|
||||
sizeof(loaded_prefs.flood_retry_group_max_path));
|
||||
readOptionalField(&loaded_prefs.flood_retry_advert_enabled,
|
||||
sizeof(loaded_prefs.flood_retry_advert_enabled));
|
||||
|
||||
// Any bytes left over form only part of a historically appended field.
|
||||
// Preserve the file and defaults rather than treating that tail as EOF.
|
||||
@@ -1314,6 +1329,14 @@ bool DataStore::savePrefs(const CompanionNodePrefs& _prefs, double node_lat, dou
|
||||
success = success && file.write((uint8_t *)_prefs.wifi_pwd,
|
||||
sizeof(_prefs.wifi_pwd)) == sizeof(_prefs.wifi_pwd);
|
||||
#endif
|
||||
success = success && file.write((uint8_t *)&_prefs.flood_retry_attempts,
|
||||
sizeof(_prefs.flood_retry_attempts)) == sizeof(_prefs.flood_retry_attempts);
|
||||
success = success && file.write((uint8_t *)&_prefs.flood_retry_max_path,
|
||||
sizeof(_prefs.flood_retry_max_path)) == sizeof(_prefs.flood_retry_max_path);
|
||||
success = success && file.write((uint8_t *)&_prefs.flood_retry_group_max_path,
|
||||
sizeof(_prefs.flood_retry_group_max_path)) == sizeof(_prefs.flood_retry_group_max_path);
|
||||
success = success && file.write((uint8_t *)&_prefs.flood_retry_advert_enabled,
|
||||
sizeof(_prefs.flood_retry_advert_enabled)) == sizeof(_prefs.flood_retry_advert_enabled);
|
||||
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) || defined(ESP32_PLATFORM) || defined(RP2040_PLATFORM)
|
||||
success = file.commit(success);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <helpers/CompanionTxRoutingCLI.h>
|
||||
#include "CompanionBluetooth.h"
|
||||
#include "CompanionWireless.h"
|
||||
#include "CompanionRetry.h"
|
||||
#if defined(MESH_SOAK_DIAGNOSTICS)
|
||||
#include "../../tools/hil/S3SoakDiagnostics.h"
|
||||
#endif
|
||||
@@ -1110,12 +1111,23 @@ void MyMesh::onGroupPacketRecv(mesh::Packet* packet) {
|
||||
#endif
|
||||
|
||||
bool MyMesh::allowFloodRetry(const mesh::Packet* packet) const {
|
||||
if (packet == NULL) return false;
|
||||
if (packet == NULL || _prefs.flood_retry_attempts == 0) return false;
|
||||
// A companion may retry its own advert once, using the core's deliberately
|
||||
// slow origin-advert delay. Do not add retries while relaying a neighbour's
|
||||
// advert; the ordinary forwarding and recent-echo guard still apply.
|
||||
return packet->getPayloadType() != PAYLOAD_TYPE_ADVERT
|
||||
|| isSelfOriginAdvert(packet);
|
||||
|| (_prefs.flood_retry_advert_enabled && isSelfOriginAdvert(packet));
|
||||
}
|
||||
|
||||
uint8_t MyMesh::getFloodRetryMaxPathLength(const mesh::Packet* packet) const {
|
||||
return applyGroupDataFloodRetryPathGate(
|
||||
packet, _prefs.flood_retry_max_path,
|
||||
_prefs.flood_retry_group_max_path);
|
||||
}
|
||||
|
||||
uint8_t MyMesh::getFloodRetryMaxAttempts(const mesh::Packet* packet) const {
|
||||
(void)packet;
|
||||
return _prefs.flood_retry_attempts;
|
||||
}
|
||||
|
||||
bool MyMesh::sendFloodScoped(const TransportKey& scope, mesh::Packet* pkt, uint32_t delay_millis) {
|
||||
@@ -1977,6 +1989,16 @@ void MyMesh::begin(bool has_display, bool radio_available) {
|
||||
_prefs.sf = constrain(_prefs.sf, 5, 12);
|
||||
_prefs.cr = constrain(_prefs.cr, 5, 8);
|
||||
_prefs.tx_power_dbm = constrain(_prefs.tx_power_dbm, -9, MAX_LORA_TX_POWER);
|
||||
_prefs.flood_retry_attempts = constrain(_prefs.flood_retry_attempts, 0, 15);
|
||||
if (_prefs.flood_retry_max_path > 63
|
||||
&& _prefs.flood_retry_max_path != FLOOD_RETRY_PATH_GATE_DISABLED) {
|
||||
_prefs.flood_retry_max_path = 1;
|
||||
}
|
||||
if (_prefs.flood_retry_group_max_path > 63
|
||||
&& _prefs.flood_retry_group_max_path != FLOOD_RETRY_PATH_GATE_DISABLED) {
|
||||
_prefs.flood_retry_group_max_path = FLOOD_RETRY_PATH_GATE_DISABLED;
|
||||
}
|
||||
_prefs.flood_retry_advert_enabled = _prefs.flood_retry_advert_enabled ? 1 : 0;
|
||||
_prefs.multi_acks = constrain(_prefs.multi_acks, 0, 1);
|
||||
_prefs.manual_add_contacts = constrain(_prefs.manual_add_contacts, 0, 1);
|
||||
_prefs.vibe_quiet = constrain(_prefs.vibe_quiet, 0, 1);
|
||||
@@ -2834,7 +2856,11 @@ bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
|
||||
|
||||
if (strcmp(command, "get radio.fem.txgain") == 0) {
|
||||
if (!board.canControlLoRaFemPaGain()) {
|
||||
snprintf(reply, reply_size, "Error: unsupported");
|
||||
if (board.isLoRaFemPaGainEnabled()) {
|
||||
snprintf(reply, reply_size, "> on (fixed TX PA)");
|
||||
} else {
|
||||
snprintf(reply, reply_size, "Error: unsupported");
|
||||
}
|
||||
} else {
|
||||
snprintf(reply, reply_size, "> %s",
|
||||
board.isLoRaFemPaGainEnabled() ? "on" : "off");
|
||||
@@ -2848,7 +2874,9 @@ bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
|
||||
snprintf(reply, reply_size,
|
||||
"Error: use set radio.fem.txgain on|off");
|
||||
} else if (!board.canControlLoRaFemPaGain()) {
|
||||
snprintf(reply, reply_size, "Error: unsupported");
|
||||
snprintf(reply, reply_size, "%s", board.isLoRaFemPaGainEnabled()
|
||||
? "Error: TX PA is fixed on; use set tx to adjust power"
|
||||
: "Error: unsupported");
|
||||
} else if (!applyAndSaveFemTxGain(strcmp(value, "on") == 0)) {
|
||||
snprintf(reply, reply_size, "Error: failed to apply or save FEM TX gain");
|
||||
} else {
|
||||
@@ -8320,7 +8348,11 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
}
|
||||
} else if (strcmp(command, "get radio.fem.txgain") == 0) {
|
||||
if (!board.canControlLoRaFemPaGain()) {
|
||||
terminalOutput().print(" ERROR: FEM TX gain control is unsupported on this board\r\n");
|
||||
if (board.isLoRaFemPaGainEnabled()) {
|
||||
terminalOutput().print(" FEM TX gain: on (fixed TX PA)\r\n");
|
||||
} else {
|
||||
terminalOutput().print(" ERROR: FEM TX gain control is unsupported on this board\r\n");
|
||||
}
|
||||
} else {
|
||||
terminalOutput().printf(" FEM TX gain: %s\r\n",
|
||||
board.isLoRaFemPaGainEnabled() ? "on" : "off");
|
||||
@@ -8417,7 +8449,9 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
|
||||
terminalOutput().print(" ERROR: use set radio.fem.txgain <on|off>\r\n");
|
||||
} else if (!board.canControlLoRaFemPaGain()) {
|
||||
terminalOutput().print(" ERROR: FEM TX gain control is unsupported on this board\r\n");
|
||||
terminalOutput().print(board.isLoRaFemPaGainEnabled()
|
||||
? " ERROR: TX PA is fixed on; use set tx to adjust power\r\n"
|
||||
: " ERROR: FEM TX gain control is unsupported on this board\r\n");
|
||||
} else if (!applyAndSaveFemTxGain(strcmp(value, "on") == 0)) {
|
||||
terminalOutput().print(" ERROR: failed to apply FEM TX gain\r\n");
|
||||
} else {
|
||||
@@ -8531,6 +8565,10 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
terminalOutput().print(" set radio.fem.rxgain <on|off>\r\n");
|
||||
terminalOutput().print(" get radio.fem.txgain\r\n");
|
||||
terminalOutput().print(" set radio.fem.txgain <on|off>\r\n");
|
||||
terminalOutput().print(" get/set flood.retry.count <0-15>\r\n");
|
||||
terminalOutput().print(" get/set flood.retry.path <0-63|off>\r\n");
|
||||
terminalOutput().print(" get/set flood.retry.group.path <0-63|off>\r\n");
|
||||
terminalOutput().print(" get/set flood.retry.advert <on|off>\r\n");
|
||||
terminalOutput().print(" card\r\n");
|
||||
terminalOutput().print(" import <meshcore://card>\r\n");
|
||||
terminalOutput().print(" clock\r\n");
|
||||
@@ -8739,6 +8777,11 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp,
|
||||
}
|
||||
if (sender_timestamp == 0 && handleDirectCommand(command, reply, reply_capacity)) return true;
|
||||
|
||||
if (mesh::companion::handleRetryCommand(
|
||||
_prefs, command, reply, reply_capacity,
|
||||
[this]() { return savePrefs(); },
|
||||
[this]() { cancelAllFloodRetries(); })) return true;
|
||||
|
||||
#if COMPANION_FEATURE_USB_MOTA_SOURCE
|
||||
if (mesh::isUsbMotaOwnerTransitionCommand(command)) {
|
||||
snprintf(reply, reply_capacity,
|
||||
|
||||
@@ -285,6 +285,8 @@ protected:
|
||||
bool filterRecvFloodPacket(mesh::Packet* packet) override;
|
||||
bool allowPacketForward(const mesh::Packet* packet) override;
|
||||
bool allowFloodRetry(const mesh::Packet* packet) const override;
|
||||
uint8_t getFloodRetryMaxPathLength(const mesh::Packet* packet) const override;
|
||||
uint8_t getFloodRetryMaxAttempts(const mesh::Packet* packet) const override;
|
||||
#ifdef COMPANION_MESH_CLOCK_SYNC
|
||||
void onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
|
||||
uint32_t timestamp, const uint8_t* app_data,
|
||||
|
||||
@@ -99,6 +99,13 @@ public:
|
||||
char wifi_ssid[33] = {};
|
||||
char wifi_pwd[64] = {};
|
||||
#endif
|
||||
// Keep these after every board-specific field: all existing prefs images
|
||||
// must retain their exact offsets. Defaults reproduce the core Companion
|
||||
// retry policy for older files that have no retry tail.
|
||||
uint8_t flood_retry_attempts = 15;
|
||||
uint8_t flood_retry_max_path = 1;
|
||||
uint8_t flood_retry_group_max_path = 0xFF;
|
||||
uint8_t flood_retry_advert_enabled = 1;
|
||||
|
||||
private:
|
||||
class RadioPrefs : public CommonRadioPrefs {
|
||||
|
||||
Reference in new issue
Block a user