Harden USB logging and persist watchdog events in management reports
This commit is contained in:
1 parent
bd55369aa9
commit
3add4695cc
98 files changed
+7207
-372
No files matched your search
@@ -1002,6 +1002,9 @@ bool DataStore::loadPrefsInt(const char *filename,
|
||||
// Files written before this tail existed always started Bluetooth at boot.
|
||||
// Do not inherit a runtime off value when loading one of those images.
|
||||
loaded_prefs.bluetooth_enabled = 1;
|
||||
// Older images have no independent debug preference. Never inherit a
|
||||
// runtime-on value when loading one of those images.
|
||||
loaded_prefs.usb_debug_enabled = 0;
|
||||
double loaded_lat = node_lat;
|
||||
double loaded_lon = node_lon;
|
||||
// The original image ended after ble_pin at byte 84. Later releases only
|
||||
@@ -1056,6 +1059,13 @@ bool DataStore::loadPrefsInt(const char *filename,
|
||||
329,
|
||||
#else
|
||||
232,
|
||||
#endif
|
||||
#ifdef TBEAM_1W
|
||||
240, // Independent USB debug preference, after the existing tail
|
||||
#elif defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
|
||||
330,
|
||||
#else
|
||||
233,
|
||||
#endif
|
||||
};
|
||||
const uint32_t prefs_size = file.size();
|
||||
@@ -1200,6 +1210,8 @@ bool DataStore::loadPrefsInt(const char *filename,
|
||||
sizeof(loaded_prefs.one_key_dm_enabled));
|
||||
readOptionalField(&loaded_prefs.bluetooth_enabled,
|
||||
sizeof(loaded_prefs.bluetooth_enabled));
|
||||
readOptionalField(&loaded_prefs.usb_debug_enabled,
|
||||
sizeof(loaded_prefs.usb_debug_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.
|
||||
@@ -1207,6 +1219,7 @@ bool DataStore::loadPrefsInt(const char *filename,
|
||||
success = success && loaded_prefs.bluetooth_enabled <= 1;
|
||||
file.close();
|
||||
if (!success) return false;
|
||||
loaded_prefs.usb_debug_enabled = loaded_prefs.usb_debug_enabled == 1 ? 1 : 0;
|
||||
_prefs = loaded_prefs;
|
||||
node_lat = loaded_lat;
|
||||
node_lon = loaded_lon;
|
||||
@@ -1363,6 +1376,8 @@ bool DataStore::savePrefs(const CompanionNodePrefs& _prefs, double node_lat, dou
|
||||
sizeof(_prefs.one_key_dm_enabled)) == sizeof(_prefs.one_key_dm_enabled);
|
||||
success = success && file.write((uint8_t *)&_prefs.bluetooth_enabled,
|
||||
sizeof(_prefs.bluetooth_enabled)) == sizeof(_prefs.bluetooth_enabled);
|
||||
success = success && file.write((uint8_t *)&_prefs.usb_debug_enabled,
|
||||
sizeof(_prefs.usb_debug_enabled)) == sizeof(_prefs.usb_debug_enabled);
|
||||
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) || defined(ESP32_PLATFORM) || defined(RP2040_PLATFORM)
|
||||
success = file.commit(success);
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
#include <helpers/StatsFormatHelper.h>
|
||||
#include <helpers/UsbAsciiBinarySwitch.h>
|
||||
#include <helpers/UsbLogging.h>
|
||||
#include <helpers/UsbLoggingWatchdog.h>
|
||||
#if MESH_PACKET_LOGGING
|
||||
#include <helpers/SerialPacketLog.h>
|
||||
#endif
|
||||
#if defined(NRF52_POWER_MANAGEMENT)
|
||||
#include <helpers/NRF52VoltagePolicy.h>
|
||||
#endif
|
||||
@@ -678,7 +682,34 @@ void MyMesh::updateGpsTelemetryPolicy() {
|
||||
sensors.setTelemetryLocationAccessAvailable(hasLocationTelemetryRecipient());
|
||||
}
|
||||
|
||||
#if MESH_PACKET_LOGGING && !MESH_PACKET_LOGGING_COMPACT
|
||||
const char* MyMesh::getLogDateTime() {
|
||||
// The shared RX/TX summaries use this same virtual formatter. Keep the
|
||||
// repeater's UTC record grammar so USB packet bridges can pair RAW and RX.
|
||||
static char timestamp[32];
|
||||
const DateTime now(getRTCClock()->getCurrentTime());
|
||||
snprintf(timestamp, sizeof(timestamp), "%02u:%02u:%02u - %u/%u/%u U",
|
||||
(unsigned)now.hour(), (unsigned)now.minute(), (unsigned)now.second(),
|
||||
(unsigned)now.day(), (unsigned)now.month(), (unsigned)now.year());
|
||||
return timestamp;
|
||||
}
|
||||
#endif
|
||||
|
||||
void MyMesh::logRxRaw(float snr, float rssi, const uint8_t raw[], int len) {
|
||||
#if MESH_PACKET_LOGGING
|
||||
if (mesh::isUsbLoggingEnabled()) {
|
||||
mesh::SerialLogLine<> line;
|
||||
#if MESH_PACKET_LOGGING_COMPACT
|
||||
line.printf("R");
|
||||
line.hex(raw, len);
|
||||
line.flush(mesh::usbLoggingPort(), false);
|
||||
#else
|
||||
line.printf("%s RAW: ", getLogDateTime());
|
||||
line.hex(raw, len);
|
||||
line.flush(mesh::usbLoggingPort());
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if defined(WITH_MQTT_BRIDGE) && defined(ESP32_PLATFORM) && defined(WIFI_SSID)
|
||||
if (_mqtt_bridge && _mqtt_bridge->isRunning()) {
|
||||
_mqtt_bridge->storeRawRadioData(raw, len, snr, rssi);
|
||||
@@ -2311,6 +2342,7 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
|
||||
#endif
|
||||
memset(_prefs.bluetooth_name, 0, sizeof(_prefs.bluetooth_name));
|
||||
_prefs.bluetooth_enabled = 1;
|
||||
_prefs.usb_debug_enabled = 0;
|
||||
_prefs.display_rotation_degrees = 0;
|
||||
_prefs.cad_enabled = DEFAULT_CAD_ENABLED ? 1 : 0;
|
||||
_prefs.cad_scan_timeout_ms = 0;
|
||||
@@ -2586,6 +2618,7 @@ void MyMesh::begin(bool has_display, bool radio_available,
|
||||
_prefs.powersaving_enabled = constrain(_prefs.powersaving_enabled, 0, 1);
|
||||
_prefs.wifi_enabled = constrain(_prefs.wifi_enabled, 0, 1);
|
||||
_prefs.usb_logging_enabled = constrain(_prefs.usb_logging_enabled, 0, 1);
|
||||
_prefs.usb_debug_enabled = _prefs.usb_debug_enabled == 1 ? 1 : 0;
|
||||
_prefs.cad_enabled = constrain(_prefs.cad_enabled, 0, 1);
|
||||
if (_prefs.cad_scan_timeout_ms != 0
|
||||
&& (_prefs.cad_scan_timeout_ms < mesh::CAD_SCAN_MIN_TIMEOUT_MS
|
||||
@@ -2607,6 +2640,7 @@ void MyMesh::begin(bool has_display, bool radio_available,
|
||||
}
|
||||
#if MESH_USB_LOGGING_AVAILABLE
|
||||
const bool usb_logging_enabled = _prefs.usb_logging_enabled != 0;
|
||||
mesh::setUsbDebugEnabled(_prefs.usb_debug_enabled != 0);
|
||||
mesh::setUsbLoggingEnabled(usb_logging_enabled);
|
||||
if (!mesh::saveUsbLoggingBootPreference(usb_logging_enabled)) {
|
||||
MESH_DEBUG_PRINTLN("Unable to save next-boot USB logging interface state");
|
||||
@@ -3156,7 +3190,15 @@ bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
|
||||
if (!command || !reply || reply_size == 0) return false;
|
||||
while (*command == ' ') command++;
|
||||
|
||||
if (strcmp(command, "get public.key") == 0) {
|
||||
char public_key_hex[PUB_KEY_SIZE * 2 + 1];
|
||||
mesh::Utils::toHex(public_key_hex, self_id.pub_key, PUB_KEY_SIZE);
|
||||
snprintf(reply, reply_size, "> %s", public_key_hex);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (handleTxRoutingCommand(command, reply, reply_size)) return true;
|
||||
if (mesh::handleUsbLoggingWatchdogCommand(command, reply, reply_size)) return true;
|
||||
#if COMPANION_FEATURE_OTA_CLI
|
||||
const auto* ota_context = mesh::ota::ota_context_if_active();
|
||||
const float adaptive_ota_pace = ota_context
|
||||
@@ -3241,6 +3283,40 @@ bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
|
||||
#endif
|
||||
|
||||
#if MESH_USB_LOGGING_AVAILABLE
|
||||
if (strcmp(command, "get usb.debug") == 0) {
|
||||
snprintf(reply, reply_size, "usb.debug %s%s",
|
||||
mesh::isUsbDebugEnabled() ? "on" : "off",
|
||||
#if MESH_DEBUG
|
||||
mesh::isUsbLoggingEnabled() ? "" : " (USB logging off)"
|
||||
#else
|
||||
" (core debug not compiled)"
|
||||
#endif
|
||||
);
|
||||
return true;
|
||||
}
|
||||
if (strncmp(command, "set usb.debug", 13) == 0
|
||||
&& (command[13] == 0 || command[13] == ' ' || command[13] == '\t')) {
|
||||
const char* value = command + 13;
|
||||
while (*value == ' ' || *value == '\t') value++;
|
||||
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
|
||||
snprintf(reply, reply_size, "Error: use set usb.debug <on|off>");
|
||||
} else {
|
||||
const uint8_t enabled = strcmp(value, "on") == 0 ? 1 : 0;
|
||||
if (!savePreference(_prefs.usb_debug_enabled, enabled)) {
|
||||
snprintf(reply, reply_size, "Error: USB debug setting could not be saved");
|
||||
} else {
|
||||
snprintf(reply, reply_size, "OK - USB debug %s (saved)%s",
|
||||
enabled ? "on" : "off",
|
||||
#if MESH_DEBUG
|
||||
""
|
||||
#else
|
||||
" (core debug not compiled)"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (strcmp(command, "get usb.logging") == 0) {
|
||||
snprintf(reply, reply_size, "usb.logging %s; port: %s%s",
|
||||
mesh::isUsbLoggingEnabled() ? "on" : "off",
|
||||
@@ -9131,11 +9207,12 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
terminalOutput().printf("Companion %s (protocol %u, build %s)\r\n",
|
||||
FIRMWARE_VERSION, (unsigned)FIRMWARE_VER_CODE, FIRMWARE_BUILD_DATE);
|
||||
} else if (strcmp(command, "help") == 0) {
|
||||
terminalOutput().print("Commands:\r\n");
|
||||
terminalOutput().print(" stats-core / stats-radio / stats-radio-diag / stats-packets\r\n");
|
||||
terminalOutput().print(" get prv.key (when private key export is enabled)\r\n");
|
||||
terminalOutput().print(" get password (this role has no admin password)\r\n");
|
||||
terminalOutput().print(" erase (erase stored settings and identity)\r\n");
|
||||
terminalOutput().print(
|
||||
"Commands:\r\n"
|
||||
" stats-core / stats-radio / stats-radio-diag / stats-packets\r\n"
|
||||
" get prv.key (when private key export is enabled)\r\n"
|
||||
" get password (this role has no admin password)\r\n"
|
||||
" erase (erase stored settings and identity)\r\n");
|
||||
terminalOutput().print(" board\r\n");
|
||||
terminalOutput().print(" version\r\n");
|
||||
terminalOutput().print(" get storage.layout\r\n");
|
||||
@@ -9157,17 +9234,20 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
terminalOutput().print(" set notify.remote <contact:key|room:key> on|off (!notify, max 15s, no GPIO)\r\n");
|
||||
terminalOutput().print(" notify.test <target> / notify.stop / notify.delete <target>\r\n");
|
||||
#endif
|
||||
terminalOutput().print(" get display.inbox\r\n");
|
||||
terminalOutput().print(" set display.inbox <history|pending|unread>\r\n");
|
||||
terminalOutput().print(" set display.rotation <0|90|180|270>\r\n");
|
||||
terminalOutput().print(" get display.touch\r\n");
|
||||
terminalOutput().print(" set display.touch <on|off> (this boot only)\r\n");
|
||||
terminalOutput().print(" set {name|lat|lon|freq|tx|af} {value}\r\n");
|
||||
terminalOutput().print(" get wifi|espnow|2.4ghz\r\n");
|
||||
terminalOutput().print(" set wifi|espnow on|off [force] (force only with off)\r\n");
|
||||
terminalOutput().print(" set 2.4ghz on [all|force]|off [force] (this boot)\r\n");
|
||||
terminalOutput().print(" get bluetooth.name\r\n");
|
||||
terminalOutput().print(" set bluetooth.name <name|default>\r\n");
|
||||
terminalOutput().print(
|
||||
" get display.inbox\r\n"
|
||||
" set display.inbox <history|pending|unread>\r\n"
|
||||
" set display.rotation <0|90|180|270>\r\n"
|
||||
" get display.touch\r\n"
|
||||
" set display.touch <on|off> (this boot only)\r\n");
|
||||
terminalOutput().print(" get public.key\r\n");
|
||||
terminalOutput().print(
|
||||
" set {name|lat|lon|freq|tx|af} {value}\r\n"
|
||||
" get wifi|espnow|2.4ghz\r\n"
|
||||
" set wifi|espnow on|off [force] (force only with off)\r\n"
|
||||
" set 2.4ghz on [all|force]|off [force] (this boot)\r\n"
|
||||
" get bluetooth.name\r\n"
|
||||
" set bluetooth.name <name|default>\r\n");
|
||||
#if defined(BLE_PIN_CODE)
|
||||
terminalOutput().print(" get bluetooth (alias: get ble)\r\n");
|
||||
terminalOutput().print(" set bluetooth <on|off> [force] (saved; force only with off)\r\n");
|
||||
@@ -9180,8 +9260,17 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
terminalOutput().print(" set pin <0-999999>\r\n");
|
||||
terminalOutput().print(" powersaving [on|off]\r\n");
|
||||
#if MESH_USB_LOGGING_AVAILABLE
|
||||
terminalOutput().print(" get usb.logging\r\n");
|
||||
terminalOutput().print(" set usb.logging <on|off> [reboot]\r\n");
|
||||
terminalOutput().print(
|
||||
" get usb.logging\r\n"
|
||||
" set usb.logging <on|off> [reboot]\r\n"
|
||||
" get usb.debug\r\n"
|
||||
" set usb.debug <on|off>\r\n"
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
" get usb.watchdog\r\n"
|
||||
" get usb.watchdog.last\r\n"
|
||||
" set usb.watchdog <off|on|auto> (saved; default auto)\r\n"
|
||||
#endif
|
||||
);
|
||||
#endif
|
||||
#if defined(ESP32) && defined(WIFI_SSID)
|
||||
#if defined(COMPANION_RADIO_FULL)
|
||||
@@ -9208,40 +9297,47 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
terminalOutput().print(" get espnow.channel\r\n");
|
||||
terminalOutput().print(" set espnow.channel <1-13>\r\n");
|
||||
#endif
|
||||
terminalOutput().print(" get radio.rxps\r\n");
|
||||
terminalOutput().print(" get radio.rxps.config\r\n");
|
||||
terminalOutput().print(" set radio.rxps <off|on|level 1-10 [preamble 16|32]|rx_us sleep_us>\r\n");
|
||||
terminalOutput().print(" get radio.cad\r\n");
|
||||
terminalOutput().print(" set radio.cad <on|off>\r\n");
|
||||
terminalOutput().print(" set radio.cad timings <scan_ms|auto> <retry_ms|auto> <max_ms|auto>\r\n");
|
||||
terminalOutput().print(" get radio.rxgain\r\n");
|
||||
terminalOutput().print(" set radio.rxgain <on|off>\r\n");
|
||||
terminalOutput().print(" get radio.fem.rxgain\r\n");
|
||||
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");
|
||||
terminalOutput().print(" time <epoch-seconds>\r\n");
|
||||
terminalOutput().print(" list [n]\r\n");
|
||||
terminalOutput().print(" show [adverts|channels|emergency] [on|off]\r\n");
|
||||
terminalOutput().print(" to [recipient name or prefix]\r\n");
|
||||
terminalOutput().print(" path [direct|clear|hops separated by spaces or commas]\r\n");
|
||||
terminalOutput().print(" send <text>\r\n");
|
||||
terminalOutput().print(" login <admin-password>\r\n");
|
||||
terminalOutput().print(" cmd <remote-command>\r\n");
|
||||
terminalOutput().print(" trace [recipient name or prefix]\r\n");
|
||||
terminalOutput().print(" trace path <1|2|4> <prefixes...>\r\n");
|
||||
terminalOutput().print(" advert\r\n");
|
||||
terminalOutput().print(" reset path\r\n");
|
||||
terminalOutput().print(" public <text>\r\n");
|
||||
terminalOutput().print(" channels\r\n");
|
||||
terminalOutput().print(" channel <name-or-slot> <text>\r\n");
|
||||
// Keep identical help text in bounded chunks. Fewer virtual Print calls
|
||||
// leave room for USB controls on small-flash boards without cutting CLI.
|
||||
terminalOutput().print(
|
||||
" get radio.rxps\r\n"
|
||||
" get radio.rxps.config\r\n"
|
||||
" set radio.rxps <off|on|level 1-10 [preamble 16|32]|rx_us sleep_us>\r\n"
|
||||
" get radio.cad\r\n"
|
||||
" set radio.cad <on|off>\r\n"
|
||||
" set radio.cad timings <scan_ms|auto> <retry_ms|auto> <max_ms|auto>\r\n");
|
||||
terminalOutput().print(
|
||||
" get radio.rxgain\r\n"
|
||||
" set radio.rxgain <on|off>\r\n"
|
||||
" get radio.fem.rxgain\r\n"
|
||||
" set radio.fem.rxgain <on|off>\r\n"
|
||||
" get radio.fem.txgain\r\n"
|
||||
" set radio.fem.txgain <on|off>\r\n");
|
||||
terminalOutput().print(
|
||||
" get/set flood.retry.count <0-15>\r\n"
|
||||
" get/set flood.retry.path <0-63|off>\r\n"
|
||||
" get/set flood.retry.group.path <0-63|off>\r\n"
|
||||
" get/set flood.retry.advert <on|off>\r\n"
|
||||
" card\r\n"
|
||||
" import <meshcore://card>\r\n"
|
||||
" clock\r\n"
|
||||
" time <epoch-seconds>\r\n");
|
||||
terminalOutput().print(
|
||||
" list [n]\r\n"
|
||||
" show [adverts|channels|emergency] [on|off]\r\n"
|
||||
" to [recipient name or prefix]\r\n"
|
||||
" path [direct|clear|hops separated by spaces or commas]\r\n"
|
||||
" send <text>\r\n"
|
||||
" login <admin-password>\r\n"
|
||||
" cmd <remote-command>\r\n");
|
||||
terminalOutput().print(
|
||||
" trace [recipient name or prefix]\r\n"
|
||||
" trace path <1|2|4> <prefixes...>\r\n"
|
||||
" advert\r\n"
|
||||
" reset path\r\n"
|
||||
" public <text>\r\n"
|
||||
" channels\r\n"
|
||||
" channel <name-or-slot> <text>\r\n");
|
||||
#if defined(NRF52_PLATFORM) && defined(EXTRAFS) && !defined(QSPIFLASH)
|
||||
terminalOutput().print(" repair extrafs (erases/rebuilds internal ExtraFS)\r\n");
|
||||
terminalOutput().print(" scan extrafs erase (USB only; reboot for destructive page test)\r\n");
|
||||
@@ -9255,8 +9351,7 @@ void MyMesh::handleTerminalCommand(char* command) {
|
||||
terminalOutput().print(" ota {status|ls|announce|folder|config|...}\r\n");
|
||||
#endif
|
||||
#endif
|
||||
terminalOutput().print(" reboot\r\n");
|
||||
terminalOutput().print(" ver\r\n");
|
||||
terminalOutput().print(" reboot\r\n" " ver\r\n");
|
||||
#if defined(NRF52_PLATFORM)
|
||||
terminalOutput().println(" uf2reset");
|
||||
#endif
|
||||
@@ -10153,6 +10248,18 @@ bool MyMesh::advert() {
|
||||
}
|
||||
|
||||
// To check if there is pending work
|
||||
bool MyMesh::canRecoverUsbLogging() const {
|
||||
// Do not discard dirty pages or interrupt a protocol/flash/radio operation.
|
||||
// Normal lazy writes resolve this veto without adding writes to each poll.
|
||||
return dirty_contacts_expiry == 0 && !_store->hasPendingContactWrites()
|
||||
&& !hasOutbound() && !isAnyTempRadioActive() && !hasPendingOtaApply()
|
||||
&& !command_radio_apply_pending && !saved_radio_apply_pending
|
||||
&& _scheduled_reboot_at == 0 && pending_serial_reply_route == NULL
|
||||
&& !binary_trace_pending && sign_data == NULL
|
||||
&& !(_serial && _serial->hasPendingIO())
|
||||
&& !(_iter_started && _serial && _serial->isConnected());
|
||||
}
|
||||
|
||||
bool MyMesh::hasPendingWork() const {
|
||||
#if COMPANION_FEATURE_NOTIFICATIONS
|
||||
if (_notifications.active()) return true;
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include <helpers/StaticPoolPacketManager.h>
|
||||
#include <helpers/TerminalCommandTracker.h>
|
||||
#include <helpers/TerminalDisplayFilter.h>
|
||||
#include <helpers/UsbLogging.h>
|
||||
#include <target.h>
|
||||
#if defined(OTA_SHARED_COMPANION_QUEUE)
|
||||
#include <helpers/BorrowableFrameBuffer.h>
|
||||
@@ -350,6 +351,9 @@ protected:
|
||||
bool sendFloodScoped(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t delay_millis=0) override;
|
||||
|
||||
void logRxRaw(float snr, float rssi, const uint8_t raw[], int len) override;
|
||||
#if MESH_PACKET_LOGGING && !MESH_PACKET_LOGGING_COMPACT
|
||||
const char* getLogDateTime() override;
|
||||
#endif
|
||||
#if defined(WITH_MQTT_BRIDGE) && defined(ESP32_PLATFORM) && defined(WIFI_SSID)
|
||||
void logRx(mesh::Packet* packet, int len, float score) override;
|
||||
void logTx(mesh::Packet* packet, int len) override;
|
||||
@@ -418,9 +422,18 @@ protected:
|
||||
|
||||
public:
|
||||
bool savePrefs() {
|
||||
const uint8_t previous_usb_debug = _prefs.usb_debug_enabled;
|
||||
_prefs.usb_debug_enabled = _prefs.usb_debug_enabled == 1 ? 1 : 0;
|
||||
const bool saved =
|
||||
_store->savePrefs(_prefs, sensors.node_lat, sensors.node_lon);
|
||||
if (saved) _prefs.clearDirty();
|
||||
if (saved) {
|
||||
_prefs.clearDirty();
|
||||
#if MESH_USB_LOGGING_AVAILABLE
|
||||
mesh::setUsbDebugEnabled(_prefs.usb_debug_enabled != 0);
|
||||
#endif
|
||||
} else {
|
||||
_prefs.usb_debug_enabled = previous_usb_debug;
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
#if COMPANION_FEATURE_READER
|
||||
@@ -440,6 +453,7 @@ public:
|
||||
|
||||
// To check if there is pending work
|
||||
bool hasPendingWork() const;
|
||||
bool canRecoverUsbLogging() const;
|
||||
|
||||
private:
|
||||
// Only snapshot the changed value: CompanionNodePrefs owns self-referencing
|
||||
|
||||
@@ -110,6 +110,9 @@ public:
|
||||
uint8_t one_key_dm_enabled = 0;
|
||||
// Appended after all existing fields so older images keep Bluetooth enabled.
|
||||
uint8_t bluetooth_enabled = 1;
|
||||
// Debug verbosity is independent of the packet/output master switch. Keep
|
||||
// this after every prior persisted field so legacy images default to quiet.
|
||||
uint8_t usb_debug_enabled = 0;
|
||||
|
||||
private:
|
||||
class RadioPrefs : public CommonRadioPrefs {
|
||||
@@ -134,6 +137,7 @@ private:
|
||||
def("agc_int", _parent->agc_reset_interval);
|
||||
def("hash_mode", _parent->path_hash_mode);
|
||||
def("multi_ack", _parent->multi_acks);
|
||||
def("usb_debug", _parent->usb_debug_enabled);
|
||||
#ifdef TBEAM_1W
|
||||
def("fan", _parent->fan_mode, sizeof(_parent->fan_mode));
|
||||
def("fan_lo", _parent->fan_lo);
|
||||
@@ -144,6 +148,32 @@ private:
|
||||
public:
|
||||
explicit RadioPrefs(CompanionNodePrefs* parent) : _parent(parent) { }
|
||||
|
||||
bool getByKey(const char* key, char* value, size_t max_len) override {
|
||||
if (key != nullptr && strcmp(key, "usb_debug") == 0) {
|
||||
if (value == nullptr || max_len == 0) return false;
|
||||
if (max_len < 2) {
|
||||
value[0] = 0;
|
||||
return false;
|
||||
}
|
||||
value[0] = _parent->usb_debug_enabled == 1 ? '1' : '0';
|
||||
value[1] = 0;
|
||||
return true;
|
||||
}
|
||||
return CommonRadioPrefs::getByKey(key, value, max_len);
|
||||
}
|
||||
bool setByKey(const char* key, const char* value) override {
|
||||
if (key != nullptr && strcmp(key, "usb_debug") == 0) {
|
||||
if (value == nullptr
|
||||
|| (strcmp(value, "0") != 0 && strcmp(value, "1") != 0)) {
|
||||
return false;
|
||||
}
|
||||
_parent->usb_debug_enabled = value[0] == '1' ? 1 : 0;
|
||||
markDirty();
|
||||
return true;
|
||||
}
|
||||
return CommonRadioPrefs::setByKey(key, value);
|
||||
}
|
||||
|
||||
float getFreq() const override { return _parent->freq; }
|
||||
void setFreq(float value) override {
|
||||
_parent->freq = value;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <Arduino.h> // needed for PlatformIO
|
||||
#include <helpers/ui/StartupScreen.h>
|
||||
#include <helpers/ui/DisplayPowerSettings.h>
|
||||
#include <helpers/UsbLoggingWatchdog.h>
|
||||
#include <helpers/UsbLoggingClientActivity.h>
|
||||
#include <Mesh.h>
|
||||
#include <helpers/BluetoothMac.h>
|
||||
#include "MyMesh.h"
|
||||
@@ -1158,6 +1160,10 @@ static void serviceUsbTerminal() {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// On dual CDC hardware only CDC1 is the logging-reader endpoint.
|
||||
if (!mesh::hasDedicatedUsbLoggingPort()
|
||||
&& strlen(usb_terminal_line) == usb_terminal_line_len)
|
||||
mesh::noteUsbLoggingStatsCommand(usb_terminal_line);
|
||||
the_mesh.handleTerminalCommand(usb_terminal_line);
|
||||
clearUsbTerminalLine();
|
||||
#if MESH_USB_LOGGING_AVAILABLE
|
||||
@@ -2866,6 +2872,7 @@ void setup() {
|
||||
#error "need to define filesystem"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
// Load only the display policy before radio and secondary-storage startup.
|
||||
FILESYSTEM* display_prefs_fs = store.getPrimaryFS();
|
||||
@@ -3053,6 +3060,14 @@ void setup() {
|
||||
// platforms have no separate port, so this is a harmless no-op there.
|
||||
mesh::beginUsbLoggingPort();
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
mesh::loadUsbLoggingWatchdog(store.getPrimaryFS(), !store.isVolatilePrimaryFS(),
|
||||
[]() -> uint32_t { return rtc_clock.getCurrentTime(); });
|
||||
#else
|
||||
mesh::loadUsbLoggingWatchdog(store.getPrimaryFS(), true,
|
||||
[]() -> uint32_t { return rtc_clock.getCurrentTime(); });
|
||||
#endif
|
||||
|
||||
#if defined(BLE_PIN_CODE)
|
||||
// Keep stack registration available for a later USB `set bluetooth on`,
|
||||
// without advertising even briefly when startup enables all interfaces.
|
||||
@@ -3300,6 +3315,25 @@ void setup() {
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool usbLoggingRecoverySafe(void*) {
|
||||
if (board.isOTAUpdateRunning() || board.isRadioTestActive()
|
||||
|| radio_driver.isWatchdogObserving() || radio_driver.isCalibratingNoiseFloor()
|
||||
|| !the_mesh.canRecoverUsbLogging()) return false;
|
||||
#if defined(ENABLE_USB_INTERFACE)
|
||||
#if COMPANION_FEATURE_USB_MOTA_SOURCE
|
||||
if (usb_mota_mode) return false;
|
||||
#endif
|
||||
// The logging CDC may be separate, but USB re-enumeration/reboot affects the
|
||||
// primary Companion connection too. Never reset a live Binary client.
|
||||
if (!the_mesh.isTerminalMode()
|
||||
&& (isUsbTerminalDataConnected() || usb_serial_interface.hasPendingIO())) return false;
|
||||
const auto usb = mesh::usbLoggingStatus();
|
||||
if (usb.reader_connected && !usb.stalled
|
||||
&& (usb_terminal_line_len || usb_terminal_discard_line)) return false;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
#if defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
|
||||
if (pico_wifi_active && WiFi.status() != WL_CONNECTED
|
||||
@@ -3394,6 +3428,7 @@ void loop() {
|
||||
#endif
|
||||
rtc_clock.tick();
|
||||
board.loop();
|
||||
if (mesh::serviceUsbLoggingWatchdog(usbLoggingRecoverySafe)) board.reboot();
|
||||
#ifdef TBEAM_1W
|
||||
board.updateFanControl();
|
||||
#endif
|
||||
@@ -3409,6 +3444,7 @@ void loop() {
|
||||
// Host sessions, live logging, and button activity still need service.
|
||||
bool can_sleep = the_mesh.getNodePrefs()->powersaving_enabled
|
||||
&& !the_mesh.hasPendingWork()
|
||||
&& !mesh::isUsbLoggingWatchdogArmed()
|
||||
&& !mesh::wireless::control().pending();
|
||||
#if defined(ESP32_PLATFORM) && MESH_USB_LOGGING_AVAILABLE
|
||||
// The native-USB-only light-sleep path below bypasses ESP32Board::sleep.
|
||||
|
||||
@@ -2465,7 +2465,7 @@ void MyMesh::printRecentRepeatersSerial() {
|
||||
return;
|
||||
}
|
||||
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
if (hasPendingSerialOutput()) {
|
||||
mesh::usbConsolePort().printf("Err - USB output busy\r\n");
|
||||
return;
|
||||
@@ -5068,7 +5068,7 @@ void MyMesh::dumpLogFile() {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
if (hasPendingSerialOutput()) {
|
||||
mesh::usbConsolePort().printf("Err - USB output busy\r\n");
|
||||
return;
|
||||
@@ -5092,7 +5092,7 @@ void MyMesh::dumpLogFile() {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
bool MyMesh::hasPendingSerialOutput() const {
|
||||
return serial_log_active || serial_log_eof_pending || serial_recent_next >= 0;
|
||||
}
|
||||
@@ -11786,7 +11786,7 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *
|
||||
#if defined(WITH_WEBCONFIG) || defined(ETHERNET_ENABLED)
|
||||
if (_command_output && _local_cli_output.owns(*_command_output)) reply[0] = 0;
|
||||
#endif
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
if (sender_timestamp == 0 && serial_log_eof_pending
|
||||
&& strcmp(reply, " EOF") == 0) reply[0] = 0;
|
||||
#endif
|
||||
@@ -12264,7 +12264,7 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *
|
||||
#if defined(WITH_WEBCONFIG) || defined(ETHERNET_ENABLED)
|
||||
if (_command_output && _local_cli_output.owns(*_command_output)) reply[0] = 0;
|
||||
#endif
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
if (sender_timestamp == 0 && serial_log_eof_pending
|
||||
&& strcmp(reply, " EOF") == 0) reply[0] = 0;
|
||||
#endif
|
||||
@@ -12281,7 +12281,7 @@ void MyMesh::loop() {
|
||||
// Check radio FIRST to ensure we don't miss incoming packets
|
||||
// MQTT processing runs in a separate FreeRTOS task on Core 0, so we don't call bridge.loop() here
|
||||
mesh::Mesh::loop();
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
servicePendingSerialOutput();
|
||||
#endif
|
||||
_cli.loop();
|
||||
|
||||
@@ -314,8 +314,12 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks
|
||||
Stream* _web_terminal = nullptr;
|
||||
#endif
|
||||
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
#if defined(NRF52_PLATFORM)
|
||||
File serial_log_dump{InternalFS};
|
||||
#else
|
||||
File serial_log_dump;
|
||||
#endif
|
||||
size_t serial_log_remaining = 0;
|
||||
size_t serial_log_pending_size = 0;
|
||||
char serial_log_pending[640];
|
||||
@@ -1073,7 +1077,7 @@ public:
|
||||
}
|
||||
|
||||
void dumpLogFile() override;
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
// Large local-only replies advance between radio service passes.
|
||||
bool hasPendingSerialOutput() const;
|
||||
void servicePendingSerialOutput();
|
||||
@@ -1146,6 +1150,11 @@ public:
|
||||
bool handleHostCliSerialReply(const char* command, char* reply);
|
||||
#endif
|
||||
void loop();
|
||||
bool canRecoverUsbLogging() const {
|
||||
return dirty_contacts_expiry == 0 && !hasOutbound() && !isAnyTempRadioActive()
|
||||
&& !hasPendingOtaApply() && !saved_radio_apply_pending
|
||||
&& !temp_radio_handoff_pending && _ota_update_at == 0;
|
||||
}
|
||||
#if MESH_ENABLE_FLOOD_RULE_ENGINE
|
||||
bool allowTransportPacket(const mesh::Packet* packet, uint8_t context);
|
||||
bool allowRadioProfileCross(const mesh::Packet* packet) override {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <helpers/IdentityGeneration.h>
|
||||
#include <helpers/ui/StartupScreen.h>
|
||||
#include <helpers/ui/DisplayPowerSettings.h>
|
||||
#include <helpers/UsbLoggingWatchdog.h>
|
||||
#include <helpers/UsbLoggingClientActivity.h>
|
||||
#if MESH_PACKET_LOGGING
|
||||
#include <helpers/SerialPacketLog.h>
|
||||
#endif
|
||||
@@ -97,7 +99,7 @@ void setup() {
|
||||
mesh::wireless::control().begin(infrastructure_wireless);
|
||||
mesh::prepareUsbLoggingPort();
|
||||
Serial.begin(115200);
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
mesh::beginUsbLoggingPort();
|
||||
#endif
|
||||
#if MESH_PACKET_LOGGING
|
||||
@@ -177,7 +179,7 @@ void setup() {
|
||||
radioinit_attempts = 0;
|
||||
const uint32_t retry_started = millis();
|
||||
while (millis() - retry_started < 60000UL) {
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
mesh::serviceUsbLoggingPort();
|
||||
mesh::serviceUsbTerminalPort();
|
||||
#endif
|
||||
@@ -278,6 +280,14 @@ void setup() {
|
||||
|
||||
the_mesh.begin(fs);
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
mesh::loadUsbLoggingWatchdog(fs, !volatile_primary_fs,
|
||||
[]() -> uint32_t { return rtc_clock.getCurrentTime(); });
|
||||
#else
|
||||
mesh::loadUsbLoggingWatchdog(fs, true,
|
||||
[]() -> uint32_t { return rtc_clock.getCurrentTime(); });
|
||||
#endif
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
if (volatile_primary_fs) {
|
||||
strncpy(the_mesh.getNodePrefs()->node_name,
|
||||
@@ -314,7 +324,7 @@ void setup() {
|
||||
|
||||
static void __attribute__((noinline)) serviceCommandInterfaces() {
|
||||
bool usb_ready = true;
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
mesh::serviceUsbLoggingPort();
|
||||
mesh::serviceUsbTerminalPort();
|
||||
if (mesh::takeUsbTerminalSessionReset()) {
|
||||
@@ -374,6 +384,8 @@ static void __attribute__((noinline)) serviceCommandInterfaces() {
|
||||
console.print('\n');
|
||||
char reply[160];
|
||||
reply[0] = 0;
|
||||
if (strlen(command) == static_cast<size_t>(len))
|
||||
mesh::noteUsbLoggingStatsCommand(command);
|
||||
#if defined(MESH_SOAK_DIAGNOSTICS)
|
||||
if (mesh::hil::handleSoakCommand(command, reply, sizeof(reply))) {
|
||||
console.print(" -> ");
|
||||
@@ -428,7 +440,23 @@ static void __attribute__((noinline)) serviceCommandInterfaces() {
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool usbLoggingRecoverySafe(void*) {
|
||||
if (board.isOTAUpdateRunning() || board.isRadioTestActive()
|
||||
|| radio_driver.isWatchdogObserving() || radio_driver.isCalibratingNoiseFloor()
|
||||
|| !the_mesh.canRecoverUsbLogging()) return false;
|
||||
const auto usb = mesh::usbLoggingStatus();
|
||||
// A stale line/listing from a disconnected or stalled host cannot lock out
|
||||
// recovery forever. Protect a functional live command pump, not diagnostics.
|
||||
return !usb.reader_connected || usb.stalled
|
||||
|| (!command[0] && !command_overflow
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
&& !the_mesh.hasPendingSerialOutput()
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
mesh::serviceUsbLoggingPort();
|
||||
mesh::wireless::control().service(millis());
|
||||
#if defined(NRF52_PLATFORM)
|
||||
board.feedWatchdog(the_mesh.getNodePrefs()->system_watchdog_enabled != 0);
|
||||
@@ -456,7 +484,8 @@ void loop() {
|
||||
if (display_ready) ui_task.loop();
|
||||
#endif
|
||||
rtc_clock.tick();
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
if (mesh::serviceUsbLoggingWatchdog(usbLoggingRecoverySafe)) board.reboot();
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
mesh::serviceUsbTerminalPort();
|
||||
#endif
|
||||
|
||||
@@ -469,6 +498,7 @@ void loop() {
|
||||
#endif
|
||||
bool can_power_save = the_mesh.getNodePrefs()->powersaving_enabled
|
||||
&& !board.isUsbDataConnected()
|
||||
&& !mesh::isUsbLoggingWatchdogArmed()
|
||||
&& !mesh::wireless::control().pending();
|
||||
#if defined(MOMENTARY_BUTTON_WAKE_FROM_SLEEP) \
|
||||
&& MOMENTARY_BUTTON_WAKE_FROM_SLEEP \
|
||||
|
||||
@@ -1645,7 +1645,7 @@ void MyMesh::dumpLogFile() {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
if (hasPendingSerialOutput()) {
|
||||
mesh::usbConsolePort().printf("Err - USB output busy\r\n");
|
||||
return;
|
||||
@@ -1669,7 +1669,7 @@ void MyMesh::dumpLogFile() {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
bool MyMesh::hasPendingSerialOutput() const {
|
||||
return serial_log_active || serial_log_eof_pending;
|
||||
}
|
||||
@@ -2513,7 +2513,7 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
|
||||
#if defined(WITH_WEBCONFIG) || defined(ETHERNET_ENABLED)
|
||||
if (_command_output && _local_cli_output.owns(*_command_output)) reply[0] = 0;
|
||||
#endif
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
if (sender_timestamp == 0 && serial_log_eof_pending
|
||||
&& strcmp(reply, " EOF") == 0) reply[0] = 0;
|
||||
#endif
|
||||
@@ -2534,7 +2534,7 @@ void MyMesh::loop() {
|
||||
// Check radio FIRST to ensure we don't miss incoming packets
|
||||
// MQTT processing can take time, so we prioritize radio reception
|
||||
mesh::Mesh::loop();
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
servicePendingSerialOutput();
|
||||
#endif
|
||||
_cli.loop();
|
||||
|
||||
@@ -177,8 +177,12 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks,
|
||||
Stream* _web_terminal = nullptr;
|
||||
#endif
|
||||
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
#if defined(NRF52_PLATFORM)
|
||||
File serial_log_dump{InternalFS};
|
||||
#else
|
||||
File serial_log_dump;
|
||||
#endif
|
||||
size_t serial_log_remaining = 0;
|
||||
size_t serial_log_pending_size = 0;
|
||||
char serial_log_pending[640];
|
||||
@@ -488,7 +492,7 @@ public:
|
||||
}
|
||||
|
||||
void dumpLogFile() override;
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
// Large local-only replies advance between radio service passes.
|
||||
bool hasPendingSerialOutput() const;
|
||||
void servicePendingSerialOutput();
|
||||
@@ -550,6 +554,11 @@ public:
|
||||
return mesh::wireless::WiFi;
|
||||
}
|
||||
void loop();
|
||||
bool canRecoverUsbLogging() const {
|
||||
return dirty_contacts_expiry == 0 && !hasOutbound() && !isAnyTempRadioActive()
|
||||
&& !hasPendingOtaApply() && !saved_radio_apply_pending
|
||||
&& set_radio_at == 0 && _ota_update_at == 0;
|
||||
}
|
||||
#if MESH_ENABLE_ROOM_FLOOD_RULE_ENGINE
|
||||
bool allowTransportPacket(const mesh::Packet* packet, uint8_t context);
|
||||
bool allowRadioProfileCross(const mesh::Packet* packet) override {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <helpers/IdentityGeneration.h>
|
||||
#include <helpers/ui/StartupScreen.h>
|
||||
#include <helpers/ui/DisplayPowerSettings.h>
|
||||
#include <helpers/UsbLoggingWatchdog.h>
|
||||
#include <helpers/UsbLoggingClientActivity.h>
|
||||
#if MESH_PACKET_LOGGING
|
||||
#include <helpers/SerialPacketLog.h>
|
||||
#endif
|
||||
@@ -53,7 +55,7 @@ void setup() {
|
||||
mesh::wireless::control().begin(infrastructure_wireless);
|
||||
mesh::prepareUsbLoggingPort();
|
||||
Serial.begin(115200);
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
mesh::beginUsbLoggingPort();
|
||||
#endif
|
||||
#if MESH_PACKET_LOGGING
|
||||
@@ -184,6 +186,14 @@ void setup() {
|
||||
|
||||
the_mesh.begin(fs);
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
mesh::loadUsbLoggingWatchdog(fs, !volatile_primary_fs,
|
||||
[]() -> uint32_t { return rtc_clock.getCurrentTime(); });
|
||||
#else
|
||||
mesh::loadUsbLoggingWatchdog(fs, true,
|
||||
[]() -> uint32_t { return rtc_clock.getCurrentTime(); });
|
||||
#endif
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
if (volatile_primary_fs) {
|
||||
strncpy(the_mesh.getNodePrefs()->node_name,
|
||||
@@ -218,13 +228,27 @@ void setup() {
|
||||
board.onBootComplete();
|
||||
}
|
||||
|
||||
static bool usbLoggingRecoverySafe(void*) {
|
||||
if (board.isOTAUpdateRunning() || board.isRadioTestActive()
|
||||
|| radio_driver.isWatchdogObserving() || radio_driver.isCalibratingNoiseFloor()
|
||||
|| !the_mesh.canRecoverUsbLogging()) return false;
|
||||
const auto usb = mesh::usbLoggingStatus();
|
||||
return !usb.reader_connected || usb.stalled
|
||||
|| (!command[0]
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
&& !the_mesh.hasPendingSerialOutput()
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
mesh::serviceUsbLoggingPort();
|
||||
mesh::wireless::control().service(millis());
|
||||
#if defined(NRF52_PLATFORM)
|
||||
board.feedWatchdog(the_mesh.getNodePrefs()->system_watchdog_enabled != 0);
|
||||
#endif
|
||||
bool usb_ready = true;
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
mesh::serviceUsbLoggingPort();
|
||||
mesh::serviceUsbTerminalPort();
|
||||
if (mesh::takeUsbTerminalSessionReset()) {
|
||||
@@ -261,6 +285,9 @@ void loop() {
|
||||
command[len - 1] = 0; // replace newline with C string null terminator
|
||||
char reply[160];
|
||||
reply[0] = 0;
|
||||
if (len < static_cast<int>(sizeof(command) - 1)
|
||||
&& strlen(command) == static_cast<size_t>(len - 1))
|
||||
mesh::noteUsbLoggingStatsCommand(command);
|
||||
#ifdef ETHERNET_ENABLED
|
||||
if (!ethernet_handle_command(command, reply)) {
|
||||
the_mesh.handleUsbCommand(command, reply);
|
||||
@@ -299,7 +326,8 @@ void loop() {
|
||||
#endif
|
||||
rtc_clock.tick();
|
||||
board.loop();
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
if (mesh::serviceUsbLoggingWatchdog(usbLoggingRecoverySafe)) board.reboot();
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
mesh::serviceUsbTerminalPort();
|
||||
#endif
|
||||
#ifdef TBEAM_1W
|
||||
@@ -310,6 +338,7 @@ void loop() {
|
||||
#endif
|
||||
bool can_power_save = the_mesh.getNodePrefs()->powersaving_enabled
|
||||
&& !board.isUsbDataConnected()
|
||||
&& !mesh::isUsbLoggingWatchdogArmed()
|
||||
&& !mesh::wireless::control().pending();
|
||||
#if defined(MOMENTARY_BUTTON_WAKE_FROM_SLEEP) \
|
||||
&& MOMENTARY_BUTTON_WAKE_FROM_SLEEP \
|
||||
|
||||
@@ -963,7 +963,7 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
|
||||
bool SensorMesh::handleIncomingMsg(ClientInfo& from, uint32_t timestamp, uint8_t* data, uint8_t flags, size_t len) {
|
||||
MESH_DEBUG_PRINT("handleIncomingMsg: unhandled msg from ");
|
||||
#ifdef MESH_DEBUG
|
||||
if (mesh::isUsbLoggingEnabled()) {
|
||||
if (mesh::isUsbDebugLoggingEnabled()) {
|
||||
Stream& logging_port = mesh::usbLoggingPort();
|
||||
mesh::Utils::printHex(logging_port, from.id.pub_key, PUB_KEY_SIZE);
|
||||
logging_port.printf(": %s\n", data);
|
||||
|
||||
@@ -58,6 +58,11 @@ public:
|
||||
SensorMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables);
|
||||
void begin(FILESYSTEM* fs);
|
||||
void loop();
|
||||
bool canRecoverUsbLogging() const {
|
||||
return dirty_contacts_expiry == 0 && !hasOutbound() && !isAnyTempRadioActive()
|
||||
&& !hasPendingOtaApply() && !saved_radio_apply_pending
|
||||
&& set_radio_at == 0;
|
||||
}
|
||||
void handleCommand(uint32_t sender_timestamp, char* command, char* reply,
|
||||
int gpio_client_index = -1,
|
||||
uint8_t gpio_path_hash_size = 1);
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <helpers/nrf52/RamFallbackFileSystem.h>
|
||||
#endif
|
||||
#include <helpers/UsbLogging.h>
|
||||
#include <helpers/UsbLoggingWatchdog.h>
|
||||
#include <helpers/UsbLoggingClientActivity.h>
|
||||
|
||||
#if defined(ESP32_PLATFORM)
|
||||
#include <helpers/ESP32TrueRandom.h>
|
||||
@@ -73,7 +75,7 @@ static const unsigned long POWERSAVING_FIRST_SLEEP_SECS = 120;
|
||||
void setup() {
|
||||
mesh::prepareUsbLoggingPort();
|
||||
Serial.begin(115200);
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
mesh::beginUsbLoggingPort();
|
||||
#endif
|
||||
board.begin();
|
||||
@@ -209,6 +211,14 @@ void setup() {
|
||||
|
||||
the_mesh.begin(fs);
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
mesh::loadUsbLoggingWatchdog(fs, !volatile_primary_fs,
|
||||
[]() -> uint32_t { return rtc_clock.getCurrentTime(); });
|
||||
#else
|
||||
mesh::loadUsbLoggingWatchdog(fs, true,
|
||||
[]() -> uint32_t { return rtc_clock.getCurrentTime(); });
|
||||
#endif
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
if (volatile_primary_fs) {
|
||||
strncpy(the_mesh.getNodePrefs()->node_name,
|
||||
@@ -233,12 +243,21 @@ void setup() {
|
||||
board.onBootComplete();
|
||||
}
|
||||
|
||||
static bool usbLoggingRecoverySafe(void*) {
|
||||
if (board.isOTAUpdateRunning() || board.isRadioTestActive()
|
||||
|| radio_driver.isWatchdogObserving() || radio_driver.isCalibratingNoiseFloor()
|
||||
|| !the_mesh.canRecoverUsbLogging()) return false;
|
||||
const auto usb = mesh::usbLoggingStatus();
|
||||
return !usb.reader_connected || usb.stalled || !command[0];
|
||||
}
|
||||
|
||||
void loop() {
|
||||
mesh::serviceUsbLoggingPort();
|
||||
#if defined(NRF52_PLATFORM)
|
||||
board.feedWatchdog(the_mesh.getNodePrefs()->system_watchdog_enabled != 0);
|
||||
#endif
|
||||
bool usb_ready = true;
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
mesh::serviceUsbLoggingPort();
|
||||
mesh::serviceUsbTerminalPort();
|
||||
if (mesh::takeUsbTerminalSessionReset()) command[0] = 0;
|
||||
@@ -271,6 +290,9 @@ void loop() {
|
||||
command[len - 1] = 0; // replace newline with C string null terminator
|
||||
char reply[160];
|
||||
reply[0] = 0;
|
||||
if (len < static_cast<int>(sizeof(command) - 1)
|
||||
&& strlen(command) == static_cast<size_t>(len - 1))
|
||||
mesh::noteUsbLoggingStatsCommand(command);
|
||||
the_mesh.handleCommand(0, command, reply); // NOTE: there is no sender_timestamp via serial!
|
||||
if (reply[0]) {
|
||||
console.print(" -> ");
|
||||
@@ -288,7 +310,8 @@ void loop() {
|
||||
if (display_ready) ui_task.loop();
|
||||
#endif
|
||||
rtc_clock.tick();
|
||||
#if MESH_ESP32_USB_CONSOLE_COOPERATIVE
|
||||
if (mesh::serviceUsbLoggingWatchdog(usbLoggingRecoverySafe)) board.reboot();
|
||||
#if MESH_USB_CONSOLE_COOPERATIVE
|
||||
mesh::serviceUsbTerminalPort();
|
||||
#endif
|
||||
#ifdef HAS_EXTERNAL_WATCHDOG
|
||||
@@ -296,7 +319,8 @@ void loop() {
|
||||
#endif
|
||||
|
||||
bool can_power_save = the_mesh.getNodePrefs()->powersaving_enabled
|
||||
&& !board.isUsbDataConnected();
|
||||
&& !board.isUsbDataConnected()
|
||||
&& !mesh::isUsbLoggingWatchdogArmed();
|
||||
#if defined(MOMENTARY_BUTTON_WAKE_FROM_SLEEP) \
|
||||
&& MOMENTARY_BUTTON_WAKE_FROM_SLEEP \
|
||||
&& defined(PIN_USER_BTN) && defined(DISPLAY_CLASS)
|
||||
|
||||
Reference in new issue
Block a user