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
@@ -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