Quiet USB packet logs for five minutes after console commands

This commit is contained in:
mikecarper committed 2026-10-27 18:19:19 -07:00
1 parent 3ec3a07236
commit b3df8bfd3f
23 files changed
+347 -31

No files matched your search

+2 -2
View File
@@ -234,7 +234,7 @@ bool Dispatcher::startOutboundTransmit() {
outbound_expiry = futureMillis(max_airtime);
#if MESH_PACKET_LOGGING
if (isUsbLoggingEnabled()) {
if (isUsbPacketLoggingAllowed()) {
#if MESH_PACKET_LOGGING_COMPACT
serialLogCompactPacket(usbLoggingPort(), 'T', raw, len);
#else
@@ -1164,7 +1164,7 @@ void Dispatcher::checkRecv() {
}
if (pkt) {
#if MESH_PACKET_LOGGING && !MESH_PACKET_LOGGING_COMPACT
if (isUsbLoggingEnabled()) {
if (isUsbPacketLoggingAllowed()) {
logPacketLine("RX", pkt, pkt->getRawLength(), true, score, air_time);
}
#endif
+2
View File
@@ -4453,6 +4453,7 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
}
// Commit before changing the stream's live protocol ownership.
mesh::setUsbLoggingEnabled(enabled);
if (enabled) mesh::resumeUsbPacketLogging();
snprintf(reply, 160, "OK - USB logging %s (saved)", enabled ? "on" : "off");
} else {
mesh::cli::formatError(reply, 160, "usage set usb.logging on|off");
@@ -4503,6 +4504,7 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
return;
}
mesh::setUsbLoggingEnabled(usb_enabled);
if (usb_enabled) mesh::resumeUsbPacketLogging();
const bool applied = wifi_enabled ? _callbacks->setMqttBridgeState(true)
: _callbacks->requestMqttBridgeStop();
if (!applied) {
+33
View File
@@ -94,6 +94,9 @@ static std::atomic<bool> usb_logging_enabled{true};
#endif
static std::atomic<bool> usb_logging_preference_known{false};
static std::atomic<bool> usb_debug_enabled{false};
#if MESH_USB_LOGGING_AVAILABLE
static std::atomic<uint32_t> usb_packet_logging_quiet_until{0};
#endif
#if MESH_ENABLE_HOST_KISS
static std::atomic<bool> usb_binary_stream_owned{false};
static std::atomic<uint32_t> usb_text_writers{0};
@@ -1294,6 +1297,36 @@ bool isUsbLoggingEnabled() {
return usb_logging_enabled.load(std::memory_order_relaxed);
}
#if MESH_USB_LOGGING_AVAILABLE
void noteUsbConsoleCommand(const char* command) {
if (command == nullptr || hasDedicatedUsbLoggingPort() || isUsbLoggingPacketStream()) return;
while (*command == ' ' || *command == '\t' || *command == '\r' || *command == '\n') ++command;
if (*command == 0 || isUsbLoggingStatsCommand(command)) return;
for (const unsigned char* p = reinterpret_cast<const unsigned char*>(command); *p; ++p) {
if ((*p < 32 && *p != '\t') || *p >= 127) return;
}
uint32_t deadline = uint32_t(millis()) + 300000UL;
if (deadline == 0) deadline = 1;
usb_packet_logging_quiet_until.store(deadline, std::memory_order_relaxed);
}
void resumeUsbPacketLogging() {
usb_packet_logging_quiet_until.store(0, std::memory_order_relaxed);
}
bool isUsbPacketLoggingAllowed() {
uint32_t deadline = usb_packet_logging_quiet_until.load(std::memory_order_relaxed);
bool quiet = deadline != 0;
if (quiet && int32_t(uint32_t(millis()) - deadline) >= 0) {
// Do not clear a newer command's pause if it raced this expiry sample.
quiet = !usb_packet_logging_quiet_until.compare_exchange_strong(
deadline, 0, std::memory_order_relaxed) && deadline != 0;
}
return isUsbLoggingEnabled()
&& (hasDedicatedUsbLoggingPort() || isUsbLoggingPacketStream() || !quiet);
}
#endif
bool isUsbDebugEnabled() {
return usb_debug_enabled.load(std::memory_order_relaxed);
}
+13
View File
@@ -92,6 +92,19 @@ inline size_t nextUsbLoggingIdentityOffset(size_t current_offset,
// protect framed traffic and restores its saved choice after preferences load.
bool isUsbLoggingEnabled();
void setUsbLoggingEnabled(bool enabled);
#if MESH_USB_LOGGING_AVAILABLE
// Human console commands pause packet records for five minutes without
// changing the saved logging setting, functional replies, or debug output.
// Dedicated logging endpoints, explicit packet streams, and stats polls keep
// their continuous capture contract. Explicit logging-on commands may resume.
void noteUsbConsoleCommand(const char* command);
void resumeUsbPacketLogging();
bool isUsbPacketLoggingAllowed();
#else
inline void noteUsbConsoleCommand(const char*) {}
inline void resumeUsbPacketLogging() {}
inline bool isUsbPacketLoggingAllowed() { return false; }
#endif
// Verbose diagnostics are opt-in and persisted by the role preferences.
// The requested setting survives switching the master USB output gate off.
bool isUsbDebugEnabled();