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

+21 -16
View File
@@ -820,7 +820,7 @@ const char* MyMesh::getLogDateTime() {
void MyMesh::logRxRaw(float snr, float rssi, const uint8_t raw[], int len) {
#if MESH_PACKET_LOGGING
if (mesh::isUsbLoggingEnabled()) {
if (mesh::isUsbPacketLoggingAllowed()) {
mesh::SerialLogLine<> line;
#if MESH_PACKET_LOGGING_COMPACT
line.printf("R");
@@ -4380,22 +4380,25 @@ bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
mesh::cli::formatError(reply, reply_size, "USB logging changed for this boot but save failed");
} else if (!mesh::saveUsbLoggingBootPreference(enabled)) {
mesh::cli::formatError(reply, reply_size, "setting saved, but next-boot USB interface state could not be saved");
} else if (mesh::usbLoggingInterfaceRestartRequired()
|| (enabled && packet_stream != mesh::isUsbLoggingPacketStream())) {
if (reboot_if_needed) {
snprintf(reply, reply_size,
"OK - USB logging %s (saved); rebooting to change USB interfaces",
enabled ? (packet_stream ? "stream" : "on") : "off");
_scheduled_reboot_at = futureMillis(1000);
if (_scheduled_reboot_at == 0) _scheduled_reboot_at = 1;
} else {
snprintf(reply, reply_size,
"OK - USB logging %s (saved); reboot required to change USB interfaces",
enabled ? (packet_stream ? "stream" : "on") : "off");
}
} else {
snprintf(reply, reply_size, "OK - USB logging %s (saved)",
enabled ? (packet_stream ? "stream" : "on") : "off");
if (enabled) mesh::resumeUsbPacketLogging();
if (mesh::usbLoggingInterfaceRestartRequired()
|| (enabled && packet_stream != mesh::isUsbLoggingPacketStream())) {
if (reboot_if_needed) {
snprintf(reply, reply_size,
"OK - USB logging %s (saved); rebooting to change USB interfaces",
enabled ? (packet_stream ? "stream" : "on") : "off");
_scheduled_reboot_at = futureMillis(1000);
if (_scheduled_reboot_at == 0) _scheduled_reboot_at = 1;
} else {
snprintf(reply, reply_size,
"OK - USB logging %s (saved); reboot required to change USB interfaces",
enabled ? (packet_stream ? "stream" : "on") : "off");
}
} else {
snprintf(reply, reply_size, "OK - USB logging %s (saved)",
enabled ? (packet_stream ? "stream" : "on") : "off");
}
}
}
return true;
@@ -4931,6 +4934,7 @@ bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
if (!savePrefs() || !mesh::saveUsbLoggingBootPreference(usb)) {
mesh::cli::formatError(reply, reply_size, "logging output changed but USB setting could not be saved");
} else {
if (usb) mesh::resumeUsbPacketLogging();
// USB ownership changes can clear the terminal's input buffer while
// this command is executing. Use parsed values, not that borrowed text.
snprintf(reply, reply_size, "OK - logging.output %s (saved)",
@@ -11403,6 +11407,7 @@ void MyMesh::checkCLIRescueCmd() {
complete_line:
{
if (strlen(cli_command) == len) mesh::noteUsbConsoleCommand(cli_command);
reply_buf[0] = 0;
#if COMPANION_FEATURE_READER
if (mesh::morseTimingActive(_radio) && isCompanionReaderRequest(cli_command)) {
+1
View File
@@ -1408,6 +1408,7 @@ static void serviceUsbTerminal() {
#endif
// NUL-containing lines were discarded before reaching this point. On
// dual CDC hardware only CDC1 is the logging-reader endpoint.
mesh::noteUsbConsoleCommand(usb_terminal_line);
if (!mesh::hasDedicatedUsbLoggingPort())
mesh::noteUsbLoggingStatsCommand(usb_terminal_line);
the_mesh.handleTerminalCommand(usb_terminal_line);
+1 -1
View File
@@ -1261,7 +1261,7 @@ bool MyMesh::allowTransportPacket(const mesh::Packet* packet, uint8_t context) {
void MyMesh::logRxRaw(float snr, float rssi, const uint8_t raw[], int len) {
#if MESH_PACKET_LOGGING
if (mesh::isUsbLoggingEnabled()) {
if (mesh::isUsbPacketLoggingAllowed()) {
#if MESH_PACKET_LOGGING_COMPACT
mesh::serialLogCompactPacket(mesh::usbLoggingPort(), 'R', raw, len);
#else
+3 -1
View File
@@ -626,8 +626,10 @@ static void __attribute__((noinline)) serviceCommandInterfaces() {
console.print('\n');
char reply[160];
reply[0] = 0;
if (strlen(command) == static_cast<size_t>(len))
if (strlen(command) == static_cast<size_t>(len)) {
mesh::noteUsbConsoleCommand(command);
mesh::noteUsbLoggingStatsCommand(command);
}
#if defined(MESH_SOAK_DIAGNOSTICS)
if (mesh::hil::handleSoakCommand(command, reply, sizeof(reply))) {
console.print(" -> ");
+1 -1
View File
@@ -1458,7 +1458,7 @@ bool MyMesh::allowTransportPacket(const mesh::Packet* packet, uint8_t context) {
void MyMesh::logRxRaw(float snr, float rssi, const uint8_t raw[], int len) {
#if MESH_PACKET_LOGGING
if (mesh::isUsbLoggingEnabled()) {
if (mesh::isUsbPacketLoggingAllowed()) {
mesh::SerialLogLine<> line;
line.printf("%s RAW: ", getLogDateTime());
line.hex(raw, len);
+3 -1
View File
@@ -413,8 +413,10 @@ void loop() {
char reply[160];
reply[0] = 0;
if (len < static_cast<int>(sizeof(command) - 1)
&& strlen(command) == static_cast<size_t>(len - 1))
&& strlen(command) == static_cast<size_t>(len - 1)) {
mesh::noteUsbConsoleCommand(command);
mesh::noteUsbLoggingStatsCommand(command);
}
#ifdef ETHERNET_ENABLED
if (!ethernet_handle_command(command, reply)) {
the_mesh.handleUsbCommand(command, reply);
+3 -1
View File
@@ -396,8 +396,10 @@ void loop() {
char reply[160];
reply[0] = 0;
if (len < static_cast<int>(sizeof(command) - 1)
&& strlen(command) == static_cast<size_t>(len - 1))
&& strlen(command) == static_cast<size_t>(len - 1)) {
mesh::noteUsbConsoleCommand(command);
mesh::noteUsbLoggingStatsCommand(command);
}
the_mesh.handleCommand(0, command, reply); // NOTE: there is no sender_timestamp via serial!
if (reply[0]) {
console.print(" -> ");