128 lines
5.1 KiB
C++
128 lines
5.1 KiB
C++
/*
|
|
* ═══════════════════════════════════════════════════════════════════════════════════
|
|
* TELEMETRY.HPP - System Monitoring and Analytics Engine
|
|
* ═══════════════════════════════════════════════════════════════════════════════════
|
|
*
|
|
* 📊 THE SYSTEM WATCHDOG OF VESPER 📊
|
|
*
|
|
* This class provides comprehensive system monitoring, performance tracking,
|
|
* and safety management. It continuously monitors bell usage, load conditions,
|
|
* and system health to ensure safe and optimal operation.
|
|
*
|
|
* 🏗️ MONITORING ARCHITECTURE:
|
|
* • Real-time bell load tracking and thermal management
|
|
* • Strike counting for warranty and maintenance tracking
|
|
* • Performance metrics collection and analysis
|
|
* • System health monitoring and alerting
|
|
* • Thread-safe operation with spinlock protection
|
|
*
|
|
* 🔔 BELL MONITORING:
|
|
* • Individual bell strike counting (warranty tracking)
|
|
* • Load accumulation and thermal modeling
|
|
* • Overload detection and protection
|
|
* • Configurable thresholds per bell
|
|
* • Automatic cooling period management
|
|
*
|
|
* 🔥 THERMAL PROTECTION:
|
|
* • Real-time load calculation based on activation duration
|
|
* • Thermal decay modeling for cooling
|
|
* • Overload prevention with automatic cooling
|
|
* • Emergency stop capability for safety
|
|
* • System-wide thermal state tracking
|
|
*
|
|
* 📊 ANALYTICS & REPORTING:
|
|
* • Performance metrics collection
|
|
* • Usage pattern analysis
|
|
* • Health status reporting
|
|
* • Predictive maintenance indicators
|
|
* • Historical data tracking
|
|
*
|
|
* ⚙️ SAFETY FEATURES:
|
|
* • Automatic system protection from overload
|
|
* • Force stop callback for emergency situations
|
|
* • Comprehensive bounds checking
|
|
* • Fail-safe operation modes
|
|
* • Graceful degradation under stress
|
|
*
|
|
* 📋 VERSION: 2.0 (Enhanced monitoring and safety)
|
|
* 📅 DATE: 2025
|
|
* 👨💻 AUTHOR: Advanced Bell Systems
|
|
* ═══════════════════════════════════════════════════════════════════════════════════
|
|
*/
|
|
|
|
#ifndef TELEMETRY_HPP
|
|
#define TELEMETRY_HPP
|
|
|
|
#include <Arduino.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "../Logging/Logging.hpp"
|
|
#include "../FileManager/FileManager.hpp"
|
|
|
|
class Telemetry {
|
|
private:
|
|
// Bell tracking
|
|
uint32_t strikeCounters[16] = {0}; // Total strikes per bell (warranty tracking)
|
|
uint16_t bellLoad[16] = {0}; // Current heat load per bell
|
|
uint16_t bellMaxLoad[16] = {60}; // Max load threshold per bell
|
|
bool coolingActive = false; // System-wide cooling flag
|
|
|
|
// Task handle
|
|
TaskHandle_t telemetryTaskHandle = NULL;
|
|
|
|
// External references (to be set via setters)
|
|
bool* playerIsPlayingPtr = nullptr;
|
|
FileManager* fileManager = nullptr;
|
|
|
|
// Spinlock for critical sections
|
|
portMUX_TYPE telemetrySpinlock = portMUX_INITIALIZER_UNLOCKED;
|
|
|
|
public:
|
|
// Initialization
|
|
void begin();
|
|
|
|
// Set external references
|
|
void setPlayerReference(bool* isPlayingPtr);
|
|
void setFileManager(FileManager* fm);
|
|
|
|
// Bell strike handling (call this on every hammer strike)
|
|
void recordBellStrike(uint8_t bellIndex);
|
|
|
|
// Strike counter management (warranty tracking)
|
|
uint32_t getStrikeCount(uint8_t bellIndex);
|
|
void resetStrikeCounters(); // User-requested reset
|
|
|
|
// Persistence methods
|
|
void saveStrikeCounters();
|
|
void loadStrikeCounters();
|
|
|
|
// Bell load management
|
|
uint16_t getBellLoad(uint8_t bellIndex);
|
|
void setBellMaxLoad(uint8_t bellIndex, uint16_t maxLoad);
|
|
bool isOverloaded(uint8_t bellIndex);
|
|
bool isCoolingActive(); // Check if system needs cooling
|
|
|
|
// Data collection (future expansion)
|
|
void logTemperature(float temperature);
|
|
void logVibration(float vibration);
|
|
|
|
// Force stop callback (to be set by main application)
|
|
void setForceStopCallback(void (*callback)());
|
|
|
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
// HEALTH CHECK METHOD
|
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
|
|
/** @brief Check if Telemetry is in healthy state */
|
|
bool isHealthy() const;
|
|
|
|
// Static task function
|
|
static void telemetryTask(void* parameter);
|
|
|
|
private:
|
|
void (*forceStopCallback)() = nullptr;
|
|
void checkBellLoads();
|
|
};
|
|
|
|
#endif
|