LCOV - code coverage report
Current view: top level - logging - HealthMonitor.h (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 25 25
Test Date: 2026-03-18 19:01:10 Functions: 100.0 % 1 1
Branches: 100.0 % 18 18

             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                 :             :     bool physics_low = false; // New v0.7.117 (Issue #217)
      14                 :             : 
      15                 :             :     double loop_rate = 0.0;
      16                 :             :     double telem_rate = 0.0;
      17                 :             :     double torque_rate = 0.0;
      18                 :             :     double physics_rate = 0.0; // New v0.7.117 (Issue #217)
      19                 :             :     double expected_torque_rate = 0.0;
      20                 :             : 
      21                 :             :     // Session and Player State (#269, #274)
      22                 :             :     bool is_connected = false;
      23                 :             :     bool session_active = false;
      24                 :             :     long session_type = -1;
      25                 :             :     bool is_realtime = false;
      26                 :             :     signed char player_control = -2;
      27                 :             : };
      28                 :             : 
      29                 :             : class HealthMonitor {
      30                 :             : public:
      31                 :             :     /**
      32                 :             :      * @brief Checks if rates are within acceptable ranges.
      33                 :             :      * @param loop Current FFB loop rate (Hz).
      34                 :             :      * @param telem Current telemetry update rate (Hz).
      35                 :             :      * @param torque Current torque update rate (Hz).
      36                 :             :      * @param torqueSource Active torque source (0=Legacy, 1=Direct).
      37                 :             :      * @param physics Current physics update rate (Hz).
      38                 :             :      * @param isConnected True if connected to LMU Shared Memory.
      39                 :             :      * @param sessionActive True if a session is loaded.
      40                 :             :      * @param sessionType Current session type (0=Test Day, 1=Practice, 5=Qualifying, 10=Race).
      41                 :             :      * @param isRealtime True if in realtime (driving).
      42                 :             :      * @param playerControl Current player control state (0=Player, 1=AI, etc).
      43                 :             :      */
      44                 :        3237 :     static HealthStatus Check(double loop, double telem, double torque, int torqueSource, double physics = 0.0,
      45                 :             :                               bool isConnected = false, bool sessionActive = false, long sessionType = -1, bool isRealtime = false, signed char playerControl = -2) {
      46                 :        3237 :         HealthStatus status;
      47                 :        3237 :         status.loop_rate = loop;
      48                 :        3237 :         status.telem_rate = telem;
      49                 :        3237 :         status.torque_rate = torque;
      50                 :        3237 :         status.physics_rate = physics;
      51         [ +  + ]:        3237 :         status.expected_torque_rate = (torqueSource == 1) ? 400.0 : 100.0;
      52                 :             :         
      53                 :        3237 :         status.is_connected = isConnected;
      54                 :        3237 :         status.session_active = sessionActive;
      55                 :        3237 :         status.session_type = sessionType;
      56                 :        3237 :         status.is_realtime = isRealtime;
      57                 :        3237 :         status.player_control = playerControl;
      58                 :             : 
      59                 :             :         // Loop: Target 1000Hz (USB). Warn below 950Hz.
      60   [ +  +  +  + ]:        3237 :         if (loop > 1.0 && loop < 950.0) {
      61                 :        2313 :             status.loop_low = true;
      62                 :        2313 :             status.is_healthy = false;
      63                 :             :         }
      64                 :             : 
      65                 :             :         // Physics: Target 400Hz. Warn below 380Hz.
      66   [ +  +  +  + ]:        3237 :         if (physics > 1.0 && physics < 380.0) {
      67                 :        2252 :             status.physics_low = true;
      68                 :        2252 :             status.is_healthy = false;
      69                 :             :         }
      70                 :             : 
      71                 :             :         // Telemetry (Standard LMU): Target 100Hz. Warn below 90Hz.
      72   [ +  +  +  + ]:        3237 :         if (telem > 1.0 && telem < 90.0) {
      73                 :           1 :             status.telem_low = true;
      74                 :           1 :             status.is_healthy = false;
      75                 :             :         }
      76                 :             : 
      77                 :             :         // Torque: Target depends on source.
      78   [ +  +  +  + ]:        3237 :         if (torque > 1.0 && torque < (status.expected_torque_rate * 0.9)) {
      79                 :           1 :             status.torque_low = true;
      80                 :           1 :             status.is_healthy = false;
      81                 :             :         }
      82                 :             : 
      83                 :        3237 :         return status;
      84                 :             :     }
      85                 :             : };
      86                 :             : 
      87                 :             : #endif // HEALTHMONITOR_H
        

Generated by: LCOV version 2.0-1