Added Telemetry data report to the App
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "Telemetry.hpp"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
void Telemetry::begin() {
|
||||
// Initialize arrays
|
||||
@@ -10,6 +11,9 @@ void Telemetry::begin() {
|
||||
|
||||
coolingActive = false;
|
||||
|
||||
// Load strike counters from SD if available
|
||||
loadStrikeCounters();
|
||||
|
||||
// Create the telemetry task
|
||||
xTaskCreatePinnedToCore(telemetryTask, "TelemetryTask", 4096, this, 2, &telemetryTaskHandle, 1);
|
||||
|
||||
@@ -21,6 +25,11 @@ void Telemetry::setPlayerReference(bool* isPlayingPtr) {
|
||||
LOG_DEBUG("Player reference set");
|
||||
}
|
||||
|
||||
void Telemetry::setFileManager(FileManager* fm) {
|
||||
fileManager = fm;
|
||||
LOG_DEBUG("FileManager reference set");
|
||||
}
|
||||
|
||||
void Telemetry::setForceStopCallback(void (*callback)()) {
|
||||
forceStopCallback = callback;
|
||||
LOG_DEBUG("Force stop callback set");
|
||||
@@ -175,6 +184,62 @@ void Telemetry::telemetryTask(void* parameter) {
|
||||
}
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
// STRIKE COUNTER PERSISTENCE
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
void Telemetry::saveStrikeCounters() {
|
||||
if (!fileManager) {
|
||||
LOG_WARNING("Cannot save strike counters: FileManager not set");
|
||||
return;
|
||||
}
|
||||
|
||||
StaticJsonDocument<512> doc;
|
||||
JsonArray counters = doc.createNestedArray("strikeCounters");
|
||||
|
||||
// Thread-safe read of strike counters
|
||||
portENTER_CRITICAL(&telemetrySpinlock);
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
counters.add(strikeCounters[i]);
|
||||
}
|
||||
portEXIT_CRITICAL(&telemetrySpinlock);
|
||||
|
||||
if (fileManager->writeJsonFile("/telemetry_data.json", doc)) {
|
||||
LOG_INFO("Strike counters saved to SD card");
|
||||
} else {
|
||||
LOG_ERROR("Failed to save strike counters to SD card");
|
||||
}
|
||||
}
|
||||
|
||||
void Telemetry::loadStrikeCounters() {
|
||||
if (!fileManager) {
|
||||
LOG_WARNING("Cannot load strike counters: FileManager not set");
|
||||
return;
|
||||
}
|
||||
|
||||
StaticJsonDocument<512> doc;
|
||||
|
||||
if (!fileManager->readJsonFile("/telemetry_data.json", doc)) {
|
||||
LOG_INFO("No previous strike counter data found, starting fresh");
|
||||
return;
|
||||
}
|
||||
|
||||
JsonArray counters = doc["strikeCounters"];
|
||||
if (counters.isNull()) {
|
||||
LOG_WARNING("Invalid telemetry data format");
|
||||
return;
|
||||
}
|
||||
|
||||
// Thread-safe write of strike counters
|
||||
portENTER_CRITICAL(&telemetrySpinlock);
|
||||
for (uint8_t i = 0; i < 16 && i < counters.size(); i++) {
|
||||
strikeCounters[i] = counters[i].as<uint32_t>();
|
||||
}
|
||||
portEXIT_CRITICAL(&telemetrySpinlock);
|
||||
|
||||
LOG_INFO("Strike counters loaded from SD card");
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
// HEALTH CHECK IMPLEMENTATION
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user