|
| 1 | +#include "sp140/esc_monitors.h" |
| 2 | +#include "sp140/monitor_config.h" |
| 3 | +#include "sp140/esc.h" // For ESC error checking functions |
| 4 | +#include <Arduino.h> |
| 5 | + |
| 6 | +// External references to core monitoring infrastructure |
| 7 | +extern std::vector<IMonitor*> monitors; |
| 8 | +extern MultiLogger multiLogger; |
| 9 | + |
| 10 | +// External references to thread-safe data copies |
| 11 | +extern STR_ESC_TELEMETRY_140 monitoringEscData; |
| 12 | + |
| 13 | +void addESCMonitors() { |
| 14 | + // ESC MOS Temperature Monitor |
| 15 | + static SensorMonitor* escMosTemp = new SensorMonitor( |
| 16 | + SensorID::ESC_MOS_Temp, |
| 17 | + escMosTempThresholds, |
| 18 | + []() { return monitoringEscData.mos_temp; }, |
| 19 | + &multiLogger); |
| 20 | + monitors.push_back(escMosTemp); |
| 21 | + |
| 22 | + // ESC MCU Temperature Monitor |
| 23 | + static SensorMonitor* escMcuTemp = new SensorMonitor( |
| 24 | + SensorID::ESC_MCU_Temp, |
| 25 | + escMcuTempThresholds, |
| 26 | + []() { return monitoringEscData.mcu_temp; }, |
| 27 | + &multiLogger); |
| 28 | + monitors.push_back(escMcuTemp); |
| 29 | + |
| 30 | + // ESC Capacitor Temperature Monitor |
| 31 | + static SensorMonitor* escCapTemp = new SensorMonitor( |
| 32 | + SensorID::ESC_CAP_Temp, |
| 33 | + escCapTempThresholds, |
| 34 | + []() { return monitoringEscData.cap_temp; }, |
| 35 | + &multiLogger); |
| 36 | + monitors.push_back(escCapTemp); |
| 37 | + |
| 38 | + // Motor Temperature Monitor |
| 39 | + static SensorMonitor* motorTemp = new SensorMonitor( |
| 40 | + SensorID::Motor_Temp, |
| 41 | + motorTempThresholds, |
| 42 | + []() { return monitoringEscData.motor_temp; }, |
| 43 | + &multiLogger); |
| 44 | + monitors.push_back(motorTemp); |
| 45 | + |
| 46 | + // Individual ESC Running Error Monitors (Critical) |
| 47 | + static BooleanMonitor* escOverCurrentError = new BooleanMonitor( |
| 48 | + SensorID::ESC_OverCurrent_Error, |
| 49 | + []() { return hasOverCurrentError(monitoringEscData.running_error); }, |
| 50 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 51 | + monitors.push_back(escOverCurrentError); |
| 52 | + |
| 53 | + static BooleanMonitor* escLockedRotorError = new BooleanMonitor( |
| 54 | + SensorID::ESC_LockedRotor_Error, |
| 55 | + []() { return hasLockedRotorError(monitoringEscData.running_error); }, |
| 56 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 57 | + monitors.push_back(escLockedRotorError); |
| 58 | + |
| 59 | + static BooleanMonitor* escOverTempError = new BooleanMonitor( |
| 60 | + SensorID::ESC_OverTemp_Error, |
| 61 | + []() { return hasOverTempError(monitoringEscData.running_error); }, |
| 62 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 63 | + monitors.push_back(escOverTempError); |
| 64 | + |
| 65 | + static BooleanMonitor* escOverVoltError = new BooleanMonitor( |
| 66 | + SensorID::ESC_OverVolt_Error, |
| 67 | + []() { return hasOverVoltError(monitoringEscData.running_error); }, |
| 68 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 69 | + monitors.push_back(escOverVoltError); |
| 70 | + |
| 71 | + static BooleanMonitor* escVoltageDropError = new BooleanMonitor( |
| 72 | + SensorID::ESC_VoltageDrop_Error, |
| 73 | + []() { return hasVoltagDropError(monitoringEscData.running_error); }, |
| 74 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 75 | + monitors.push_back(escVoltageDropError); |
| 76 | + |
| 77 | + // Individual ESC Running Warning Monitors |
| 78 | + static BooleanMonitor* escThrottleSatWarning = new BooleanMonitor( |
| 79 | + SensorID::ESC_ThrottleSat_Warning, |
| 80 | + []() { return hasThrottleSatWarning(monitoringEscData.running_error); }, |
| 81 | + true, AlertLevel::WARN_HIGH, &multiLogger); |
| 82 | + monitors.push_back(escThrottleSatWarning); |
| 83 | + |
| 84 | + // Individual ESC Self-Check Error Monitors (All Critical) |
| 85 | + static BooleanMonitor* escMotorCurrentOutError = new BooleanMonitor( |
| 86 | + SensorID::ESC_MotorCurrentOut_Error, |
| 87 | + []() { return hasMotorCurrentOutError(monitoringEscData.selfcheck_error); }, |
| 88 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 89 | + monitors.push_back(escMotorCurrentOutError); |
| 90 | + |
| 91 | + static BooleanMonitor* escTotalCurrentOutError = new BooleanMonitor( |
| 92 | + SensorID::ESC_TotalCurrentOut_Error, |
| 93 | + []() { return hasTotalCurrentOutError(monitoringEscData.selfcheck_error); }, |
| 94 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 95 | + monitors.push_back(escTotalCurrentOutError); |
| 96 | + |
| 97 | + static BooleanMonitor* escMotorVoltageOutError = new BooleanMonitor( |
| 98 | + SensorID::ESC_MotorVoltageOut_Error, |
| 99 | + []() { return hasMotorVoltageOutError(monitoringEscData.selfcheck_error); }, |
| 100 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 101 | + monitors.push_back(escMotorVoltageOutError); |
| 102 | + |
| 103 | + static BooleanMonitor* escCapNTCError = new BooleanMonitor( |
| 104 | + SensorID::ESC_CapNTC_Error, |
| 105 | + []() { return hasCapNTCError(monitoringEscData.selfcheck_error); }, |
| 106 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 107 | + monitors.push_back(escCapNTCError); |
| 108 | + |
| 109 | + static BooleanMonitor* escMosNTCError = new BooleanMonitor( |
| 110 | + SensorID::ESC_MosNTC_Error, |
| 111 | + []() { return hasMosNTCError(monitoringEscData.selfcheck_error); }, |
| 112 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 113 | + monitors.push_back(escMosNTCError); |
| 114 | + |
| 115 | + static BooleanMonitor* escBusVoltRangeError = new BooleanMonitor( |
| 116 | + SensorID::ESC_BusVoltRange_Error, |
| 117 | + []() { return hasBusVoltRangeError(monitoringEscData.selfcheck_error); }, |
| 118 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 119 | + monitors.push_back(escBusVoltRangeError); |
| 120 | + |
| 121 | + static BooleanMonitor* escBusVoltSampleError = new BooleanMonitor( |
| 122 | + SensorID::ESC_BusVoltSample_Error, |
| 123 | + []() { return hasBusVoltSampleError(monitoringEscData.selfcheck_error); }, |
| 124 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 125 | + monitors.push_back(escBusVoltSampleError); |
| 126 | + |
| 127 | + static BooleanMonitor* escMotorZLowError = new BooleanMonitor( |
| 128 | + SensorID::ESC_MotorZLow_Error, |
| 129 | + []() { return hasMotorZLowError(monitoringEscData.selfcheck_error); }, |
| 130 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 131 | + monitors.push_back(escMotorZLowError); |
| 132 | + |
| 133 | + static BooleanMonitor* escMotorZHighError = new BooleanMonitor( |
| 134 | + SensorID::ESC_MotorZHigh_Error, |
| 135 | + []() { return hasMotorZHighError(monitoringEscData.selfcheck_error); }, |
| 136 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 137 | + monitors.push_back(escMotorZHighError); |
| 138 | + |
| 139 | + static BooleanMonitor* escMotorVDet1Error = new BooleanMonitor( |
| 140 | + SensorID::ESC_MotorVDet1_Error, |
| 141 | + []() { return hasMotorVDet1Error(monitoringEscData.selfcheck_error); }, |
| 142 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 143 | + monitors.push_back(escMotorVDet1Error); |
| 144 | + |
| 145 | + static BooleanMonitor* escMotorVDet2Error = new BooleanMonitor( |
| 146 | + SensorID::ESC_MotorVDet2_Error, |
| 147 | + []() { return hasMotorVDet2Error(monitoringEscData.selfcheck_error); }, |
| 148 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 149 | + monitors.push_back(escMotorVDet2Error); |
| 150 | + |
| 151 | + static BooleanMonitor* escMotorIDet2Error = new BooleanMonitor( |
| 152 | + SensorID::ESC_MotorIDet2_Error, |
| 153 | + []() { return hasMotorIDet2Error(monitoringEscData.selfcheck_error); }, |
| 154 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 155 | + monitors.push_back(escMotorIDet2Error); |
| 156 | + |
| 157 | + static BooleanMonitor* escSwHwIncompatError = new BooleanMonitor( |
| 158 | + SensorID::ESC_SwHwIncompat_Error, |
| 159 | + []() { return hasSwHwIncompatError(monitoringEscData.selfcheck_error); }, |
| 160 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 161 | + monitors.push_back(escSwHwIncompatError); |
| 162 | + |
| 163 | + static BooleanMonitor* escBootloaderBadError = new BooleanMonitor( |
| 164 | + SensorID::ESC_BootloaderBad_Error, |
| 165 | + []() { return hasBootloaderBadError(monitoringEscData.selfcheck_error); }, |
| 166 | + true, AlertLevel::CRIT_HIGH, &multiLogger); |
| 167 | + monitors.push_back(escBootloaderBadError); |
| 168 | +} |
0 commit comments