LCOV - code coverage report
Current view: top level - src - HealthMonitor.h (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 16 16
Test Date: 2026-03-01 21:30:38 Functions: 100.0 % 1 1
Branches: 100.0 % 14 14

             Branch data     Line data    Source code
       1                 :             : #ifndef HEALTHMONITOR_H
       2                 :             : #define HEALTHMONITOR_H
       3                 :             : 
       4                 :             : /**
       5                 :             :  * @brief Logic for determining if system sample rates are healthy.
       6                 :             :  * Issue #133: Adjusted thresholds to be source-aware.
       7                 :             :  */
       8                 :             : struct HealthStatus {
       9                 :             :     bool is_healthy = true;
      10                 :             :     bool loop_low = false;
      11                 :             :     bool telem_low = false;
      12                 :             :     bool torque_low = false;
      13                 :             : 
      14                 :             :     double loop_rate = 0.0;
      15                 :             :     double telem_rate = 0.0;
      16                 :             :     double torque_rate = 0.0;
      17                 :             :     double expected_torque_rate = 0.0;
      18                 :             : };
      19                 :             : 
      20                 :             : class HealthMonitor {
      21                 :             : public:
      22                 :             :     /**
      23                 :             :      * @brief Checks if rates are within acceptable ranges.
      24                 :             :      * @param loop Current FFB loop rate (Hz).
      25                 :             :      * @param telem Current telemetry update rate (Hz).
      26                 :             :      * @param torque Current torque update rate (Hz).
      27                 :             :      * @param torqueSource Active torque source (0=Legacy, 1=Direct).
      28                 :             :      */
      29                 :        4768 :     static HealthStatus Check(double loop, double telem, double torque, int torqueSource) {
      30                 :        4768 :         HealthStatus status;
      31                 :        4768 :         status.loop_rate = loop;
      32                 :        4768 :         status.telem_rate = telem;
      33                 :        4768 :         status.torque_rate = torque;
      34         [ +  + ]:        4768 :         status.expected_torque_rate = (torqueSource == 1) ? 400.0 : 100.0;
      35                 :             : 
      36                 :             :         // Loop: Target 400Hz. Warn below 360Hz.
      37   [ +  +  +  + ]:        4768 :         if (loop > 1.0 && loop < 360.0) {
      38                 :           1 :             status.loop_low = true;
      39                 :           1 :             status.is_healthy = false;
      40                 :             :         }
      41                 :             : 
      42                 :             :         // Telemetry (Standard LMU): Target 100Hz. Warn below 90Hz.
      43   [ +  +  +  + ]:        4768 :         if (telem > 1.0 && telem < 90.0) {
      44                 :           1 :             status.telem_low = true;
      45                 :           1 :             status.is_healthy = false;
      46                 :             :         }
      47                 :             : 
      48                 :             :         // Torque: Target depends on source.
      49   [ +  +  +  + ]:        4768 :         if (torque > 1.0 && torque < (status.expected_torque_rate * 0.9)) {
      50                 :           1 :             status.torque_low = true;
      51                 :           1 :             status.is_healthy = false;
      52                 :             :         }
      53                 :             : 
      54                 :        4768 :         return status;
      55                 :             :     }
      56                 :             : };
      57                 :             : 
      58                 :             : #endif // HEALTHMONITOR_H
        

Generated by: LCOV version 2.0-1