feat(Telemetry,FileManager,LoggingHandler): QA-to-shipping stats reset — telemetry.reset_boot_data + logs.clear
Console wants a "reset device stats before shipping" button for staff to clear QA-bench data (test reboots, debug log spam) without wiping actual device configuration. telemetry.reset_strikes and telemetry.reset_metrics already covered bell strikes and runtime/playback counters — this adds the two gaps: lifetime boot count + SD boot history, and SD debug logs. Deliberately does not touch FirmwareValidator's NVS namespace (rollback safety state, not history) or device identity NVS (serial/hw_family). Verified: pio run on all four board variants.
This commit is contained in:
@@ -19,7 +19,7 @@ LoggingHandler::LoggingHandler(ConfigManager& configManager, FileManager* fileMa
|
||||
|
||||
std::vector<String> LoggingHandler::commands() const {
|
||||
return { "log.set_serial", "log.set_sd", "log.set_mqtt", "log.get_config",
|
||||
"logs.list", "logs.download" };
|
||||
"logs.list", "logs.download", "logs.clear" };
|
||||
}
|
||||
|
||||
CommandResult LoggingHandler::execute(const CommandEnvelope& envelope) {
|
||||
@@ -29,6 +29,7 @@ CommandResult LoggingHandler::execute(const CommandEnvelope& envelope) {
|
||||
if (envelope.command == "log.get_config") return handleGetConfig(envelope);
|
||||
if (envelope.command == "logs.list") return handleLogsList(envelope);
|
||||
if (envelope.command == "logs.download") return handleLogsDownload(envelope);
|
||||
if (envelope.command == "logs.clear") return handleLogsClear(envelope);
|
||||
return CommandResult::err(envelope.command, "Unknown log command");
|
||||
}
|
||||
|
||||
@@ -119,3 +120,20 @@ CommandResult LoggingHandler::handleLogsDownload(const CommandEnvelope& e) {
|
||||
result["eof"] = doc["eof"];
|
||||
return CommandResult::ok("logs.download", result);
|
||||
}
|
||||
|
||||
CommandResult LoggingHandler::handleLogsClear(const CommandEnvelope& e) {
|
||||
// Deletes every day-rotated SD debug log file — a QA-to-shipping reset,
|
||||
// not part of normal log rotation. Not to be confused with the day-
|
||||
// rotation pruning that already runs automatically in appendLogLine()
|
||||
// (that only trims oldest files once over budget, never clears everything).
|
||||
if (!_fileManager) {
|
||||
return CommandResult::err("logs.clear", "SD card not available on this device");
|
||||
}
|
||||
|
||||
size_t deleted = _fileManager->deleteAllLogFiles(SD_LOG_DIR);
|
||||
LOG_WARNING(TAG, "SD debug logs cleared via logs.clear command (%u file(s))", (unsigned)deleted);
|
||||
|
||||
JsonDocument result;
|
||||
result["deleted"] = deleted;
|
||||
return CommandResult::ok("logs.clear", result);
|
||||
}
|
||||
|
||||
@@ -21,4 +21,5 @@ private:
|
||||
CommandResult handleGetConfig(const CommandEnvelope& e);
|
||||
CommandResult handleLogsList(const CommandEnvelope& e);
|
||||
CommandResult handleLogsDownload(const CommandEnvelope& e);
|
||||
CommandResult handleLogsClear(const CommandEnvelope& e);
|
||||
};
|
||||
|
||||
@@ -14,7 +14,8 @@ std::vector<String> TelemetryHandler::commands() const {
|
||||
"telemetry.get_strikes", "telemetry.reset_strikes", "telemetry.get_loads",
|
||||
"telemetry.set_max_loads", "telemetry.set_guard_enabled",
|
||||
"telemetry.get_metrics", "telemetry.reset_metrics",
|
||||
"telemetry.get_boot_history", "telemetry.get_diagnostics"
|
||||
"telemetry.get_boot_history", "telemetry.get_diagnostics",
|
||||
"telemetry.reset_boot_data"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -28,6 +29,7 @@ CommandResult TelemetryHandler::execute(const CommandEnvelope& envelope) {
|
||||
if (envelope.command == "telemetry.reset_metrics") return handleResetMetrics(envelope);
|
||||
if (envelope.command == "telemetry.get_boot_history") return handleGetBootHistory(envelope);
|
||||
if (envelope.command == "telemetry.get_diagnostics") return handleGetDiagnostics(envelope);
|
||||
if (envelope.command == "telemetry.reset_boot_data") return handleResetBootData(envelope);
|
||||
return CommandResult::err(envelope.command, "Unknown telemetry command");
|
||||
}
|
||||
|
||||
@@ -162,3 +164,17 @@ CommandResult TelemetryHandler::handleGetDiagnostics(const CommandEnvelope& e) {
|
||||
|
||||
return CommandResult::ok("telemetry.get_diagnostics", doc);
|
||||
}
|
||||
|
||||
CommandResult TelemetryHandler::handleResetBootData(const CommandEnvelope& e) {
|
||||
// Zeroes the lifetime boot counter (NVS) and deletes the SD boot history
|
||||
// log — used before shipping a device to a customer, to clear reboot
|
||||
// counts accumulated during QA/bench testing. Console-side history in
|
||||
// device_boot_events (Postgres) is a separate reset, not touched here.
|
||||
bool ok = _telemetry.resetBootData();
|
||||
if (!ok) {
|
||||
return CommandResult::err("telemetry.reset_boot_data",
|
||||
"Failed to reset lifetime boot count in NVS");
|
||||
}
|
||||
LOG_WARNING(TAG, "Boot data reset via telemetry.reset_boot_data command");
|
||||
return CommandResult::ok("telemetry.reset_boot_data", "Lifetime boot count and SD boot log reset");
|
||||
}
|
||||
|
||||
@@ -30,4 +30,5 @@ private:
|
||||
CommandResult handleResetMetrics(const CommandEnvelope& e);
|
||||
CommandResult handleGetBootHistory(const CommandEnvelope& e);
|
||||
CommandResult handleGetDiagnostics(const CommandEnvelope& e);
|
||||
CommandResult handleResetBootData(const CommandEnvelope& e);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user