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:
2026-07-17 14:14:55 +03:00
parent 959cb77d81
commit f41332a771
11 changed files with 172 additions and 2 deletions
+37
View File
@@ -380,6 +380,43 @@ void Telemetry::resetMetrics() {
LOG_WARNING(TAG, "Telemetry metrics reset by user");
}
// ════════════════════════════════════════════════════════════════════════════
// BOOT DATA RESET — clears the lifetime boot counter (NVS) and the SD-side
// boot history log. Deliberately separate from FirmwareValidator's own NVS
// namespace ("fw_validator") — that one is live rollback-safety state, not
// "history," and must never be touched by this. See docs/features/
// feature-catalog.md's boot-tracking table for why the two are kept distinct.
// ════════════════════════════════════════════════════════════════════════════
bool Telemetry::resetBootData() {
bool nvsOk = true;
if (_bootNvsHandle != 0) {
esp_err_t err = nvs_set_u32(_bootNvsHandle, "lifetime_boots", 0);
if (err == ESP_OK) err = nvs_commit(_bootNvsHandle);
if (err != ESP_OK) {
LOG_ERROR(TAG, "Failed to reset lifetime boot count in NVS: %s", esp_err_to_name(err));
nvsOk = false;
}
} else {
nvsOk = false;
}
portENTER_CRITICAL(&telemetrySpinlock);
lifetimeBootCount = 0;
portEXIT_CRITICAL(&telemetrySpinlock);
// SD boot log — best-effort. Absent SD/FileManager isn't a failure of the
// NVS reset (which is the authoritative counter); deleteFile() returning
// false because the file never existed yet is also not an error worth
// surfacing.
if (fileManager) {
fileManager->deleteFile("/telemetry_boot_log.json");
}
LOG_WARNING(TAG, "Boot data reset by user (lifetime count + SD boot log)");
return nvsOk;
}
// ════════════════════════════════════════════════════════════════════════════
// RUNTIME PERSISTENCE
// ════════════════════════════════════════════════════════════════════════════