Add saved repeater trace exception while repeating is disabled
This commit is contained in:
1 parent
4bec31b4e1
commit
1ddca12a41
14 files changed
+761
-22
No files matched your search
@@ -764,6 +764,7 @@ void CommonCLI::loadPrefs(FILESYSTEM* fs) {
|
||||
memset(_prefs->extra_sf, 0, sizeof(_prefs->extra_sf));
|
||||
_prefs->usb_logging_enabled = 1;
|
||||
_prefs->usb_debug_enabled = 0;
|
||||
_prefs->trace_when_repeat_off = 0;
|
||||
#ifdef WITH_RS232_BRIDGE
|
||||
_prefs->bridge_uart = WITH_RS232_BRIDGE_UART;
|
||||
#else
|
||||
@@ -935,9 +936,10 @@ void CommonCLI::syncOtaConfigFromPrefs() {
|
||||
#endif
|
||||
|
||||
void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
// Older or truncated preference images must never inherit debug opt-in
|
||||
// Older or truncated preference images must never inherit these opt-ins
|
||||
// from a previous load of a newer image.
|
||||
_prefs->usb_debug_enabled = 0;
|
||||
_prefs->trace_when_repeat_off = 0;
|
||||
#if defined(RP2040_PLATFORM)
|
||||
File file = fs->open(filename, "r");
|
||||
#else
|
||||
@@ -1330,6 +1332,10 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
if (file.available() >= (int)sizeof(_prefs->usb_debug_enabled)) {
|
||||
file.read((uint8_t *)&_prefs->usb_debug_enabled,
|
||||
sizeof(_prefs->usb_debug_enabled));
|
||||
if (file.available() >= (int)sizeof(_prefs->trace_when_repeat_off)) {
|
||||
file.read((uint8_t *)&_prefs->trace_when_repeat_off,
|
||||
sizeof(_prefs->trace_when_repeat_off));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1445,6 +1451,8 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
_prefs->usb_logging_enabled = constrain(_prefs->usb_logging_enabled, 0, 1); // boolean
|
||||
// Only a deliberately saved 1 enables diagnostics; corrupted bytes are OFF.
|
||||
_prefs->usb_debug_enabled = _prefs->usb_debug_enabled == 1 ? 1 : 0;
|
||||
// Corrupt or unknown values must not enable a repeat-off exception.
|
||||
_prefs->trace_when_repeat_off = _prefs->trace_when_repeat_off == 1 ? 1 : 0;
|
||||
_prefs->cad_enabled = constrain(_prefs->cad_enabled, 0, 1); // boolean
|
||||
if (!directRetryPrefsValid(_prefs)) {
|
||||
setDefaultDirectRetryPrefs(_prefs);
|
||||
@@ -1658,6 +1666,7 @@ static bool writeCommonPrefsImage(Writer& writer, NodePrefs* prefs) {
|
||||
WRITE_COMMON_PREFS(&prefs->primary_radio_preamble); // appended primary tuple field
|
||||
WRITE_COMMON_PREFS(&prefs->espnow_bridge_enabled); // appended Full ESP-NOW intent
|
||||
WRITE_COMMON_PREFS(&prefs->usb_debug_enabled); // appended USB debug intent
|
||||
WRITE_COMMON_PREFS(&prefs->trace_when_repeat_off); // appended repeater trace exception
|
||||
|
||||
#undef WRITE_COMMON_PREFS_BYTES
|
||||
#undef WRITE_COMMON_PREFS
|
||||
@@ -1671,6 +1680,7 @@ void CommonCLI::savePrefs(FILESYSTEM* fs, PrefsSaveRouting::Scope scope) {
|
||||
_common_save_result_known = true;
|
||||
_common_save_succeeded = false;
|
||||
_prefs->usb_debug_enabled = _prefs->usb_debug_enabled == 1 ? 1 : 0;
|
||||
_prefs->trace_when_repeat_off = _prefs->trace_when_repeat_off == 1 ? 1 : 0;
|
||||
}
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
// Observer builds use a verified temp/backup transaction for common prefs.
|
||||
@@ -1817,6 +1827,7 @@ void CommonCLI::savePrefs(FILESYSTEM* fs, PrefsSaveRouting::Scope scope) {
|
||||
file.write((uint8_t *)&_prefs->primary_radio_preamble, sizeof(_prefs->primary_radio_preamble)); // appended
|
||||
file.write((uint8_t *)&_prefs->espnow_bridge_enabled, sizeof(_prefs->espnow_bridge_enabled)); // appended
|
||||
file.write((uint8_t *)&_prefs->usb_debug_enabled, sizeof(_prefs->usb_debug_enabled)); // appended
|
||||
file.write((uint8_t *)&_prefs->trace_when_repeat_off, sizeof(_prefs->trace_when_repeat_off)); // appended
|
||||
|
||||
_common_save_succeeded = file.commit();
|
||||
if (!_common_save_succeeded) {
|
||||
@@ -3349,6 +3360,29 @@ bool CommonCLI::handleSdCardGetCmd(const char* config, char* reply) {
|
||||
|
||||
void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* reply) {
|
||||
const char* config = &command[4];
|
||||
if (strncmp(config, "repeat.trace", 12) == 0
|
||||
&& (config[12] == 0 || config[12] == ' ' || config[12] == '\t')) {
|
||||
if (strcmp(_callbacks->getRole(), "repeater") != 0) {
|
||||
strcpy(reply, "Error: repeat.trace is only supported by repeaters");
|
||||
return;
|
||||
}
|
||||
const char* value = config + 12;
|
||||
while (*value == ' ' || *value == '\t') ++value;
|
||||
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
|
||||
strcpy(reply, "Error: usage set repeat.trace on|off");
|
||||
return;
|
||||
}
|
||||
const uint8_t previous = _prefs->trace_when_repeat_off;
|
||||
_prefs->trace_when_repeat_off = strcmp(value, "on") == 0 ? 1 : 0;
|
||||
if (!trySavePrefs()) {
|
||||
_prefs->trace_when_repeat_off = previous;
|
||||
strcpy(reply, "Error: Repeat trace not saved; unchanged");
|
||||
return;
|
||||
}
|
||||
_callbacks->onRetryConfigChanged();
|
||||
snprintf(reply, 160, "OK - repeat.trace %s (saved)", value);
|
||||
return;
|
||||
}
|
||||
#if defined(NRF52_POWER_MANAGEMENT)
|
||||
if (mesh::power::handleVoltagePolicyCommand(command, reply, 160)) return;
|
||||
#endif
|
||||
@@ -4695,6 +4729,17 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
|
||||
void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* reply) {
|
||||
const char* config = &command[4];
|
||||
if (strncmp(config, "repeat.trace", 12) == 0
|
||||
&& (config[12] == 0 || config[12] == ' ' || config[12] == '\t')) {
|
||||
if (strcmp(_callbacks->getRole(), "repeater") != 0) {
|
||||
strcpy(reply, "Error: repeat.trace is only supported by repeaters");
|
||||
} else if (strcmp(config, "repeat.trace") != 0) {
|
||||
strcpy(reply, "Error: usage get repeat.trace");
|
||||
} else {
|
||||
snprintf(reply, 160, "> %s", _prefs->trace_when_repeat_off == 1 ? "on" : "off");
|
||||
}
|
||||
return;
|
||||
}
|
||||
#if defined(NRF52_POWER_MANAGEMENT)
|
||||
if (mesh::power::handleVoltagePolicyCommand(command, reply, 160)) return;
|
||||
#endif
|
||||
|
||||
@@ -183,8 +183,11 @@ public:
|
||||
// logging artifact's enabled-at-first-boot behavior.
|
||||
uint8_t usb_logging_enabled = 1;
|
||||
// USB diagnostics are opt-in independently of the packet output gate.
|
||||
// Persisted at the very end of /com_prefs, not beside usb_log.
|
||||
// Appended after ESP-NOW intent in /com_prefs, not beside usb_log.
|
||||
uint8_t usb_debug_enabled = 0;
|
||||
// Repeater-only opt-in for routed trace diagnostics while repeat is off.
|
||||
// Appended after usb_debug in /com_prefs; existing images stay disabled.
|
||||
uint8_t trace_when_repeat_off = 0;
|
||||
// Runtime UART choice for merged RS-232 repeater artifacts. Appended at
|
||||
// /com_prefs offset 862; single-UART builds keep their compiled port here.
|
||||
uint8_t bridge_uart = 0;
|
||||
@@ -377,6 +380,7 @@ private:
|
||||
protected:
|
||||
void structure() override {
|
||||
def("disable", _parent->disable_fwd);
|
||||
def("trace_off", _parent->trace_when_repeat_off);
|
||||
def("f_max", _parent->flood_max);
|
||||
def("f_max_uns", _parent->flood_max_unscoped);
|
||||
def("f_max_adv", _parent->flood_max_advert);
|
||||
|
||||
@@ -573,15 +573,19 @@ bool isUsbLoggingWatchdogUpdateActive() { return false; }
|
||||
bool handleUsbLoggingWatchdogCommand(const char* command, char* reply,
|
||||
size_t capacity) {
|
||||
if (!command || !reply || !capacity) return false;
|
||||
static const char* const keys[] = {"get usb.watchdog.last", "get usb.watchdog", "set usb.watchdog"};
|
||||
for (const char* key : keys) {
|
||||
const size_t length = strlen(key);
|
||||
if (strncmp(command, key, length)
|
||||
|| (command[length] && command[length] != ' ' && command[length] != '\t')) continue;
|
||||
snprintf(reply, capacity, "Error: unsupported");
|
||||
return true;
|
||||
const char* suffix;
|
||||
constexpr size_t prefix_size = sizeof("get usb.watchdog") - 1;
|
||||
if (strncmp(command, "get usb.watchdog", prefix_size) == 0) {
|
||||
suffix = command + prefix_size;
|
||||
if (strncmp(suffix, ".last", 5) == 0) suffix += 5;
|
||||
} else if (strncmp(command, "set usb.watchdog", prefix_size) == 0) {
|
||||
suffix = command + prefix_size;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
if (*suffix && *suffix != ' ' && *suffix != '\t') return false;
|
||||
snprintf(reply, capacity, "Error: unsupported");
|
||||
return true;
|
||||
}
|
||||
} // namespace mesh
|
||||
#endif // MESH_USB_CONSOLE_COOPERATIVE
|
||||
|
||||
Reference in new issue
Block a user