Skip to content

Commit a02373f

Browse files
committed
Add monitor for ESC TWAI initialization failure
Introduces a new SensorID for ESC TWAI/CAN bus initialization failure and adds a BooleanMonitor to alert when initialization fails. Updates string and abbreviation mappings for the new sensor ID to improve error reporting and diagnostics.
1 parent 7d2ea3c commit a02373f

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

inc/sp140/simple_monitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum class SensorID {
4444
ESC_MotorIDet2_Error, // Bit 11: motor_i_det2_bad
4545
ESC_SwHwIncompat_Error, // Bit 13: sw_hw_incompatible
4646
ESC_BootloaderBad_Error, // Bit 14: bootloader_unsupported
47+
ESC_TWAI_Init_Failure, // TWAI/CAN bus initialization failure
4748

4849
// BMS
4950
BMS_MOS_Temp,

src/sp140/esc_monitors.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@ extern MultiLogger multiLogger;
1010
// External references to thread-safe data copies
1111
extern STR_ESC_TELEMETRY_140 monitoringEscData;
1212

13+
// External reference to ESC TWAI initialization status
14+
extern bool escTwaiInitialized;
15+
1316
void addESCMonitors() {
17+
// ESC TWAI Initialization (Alert when failed)
18+
static BooleanMonitor* escTwaiInitFailure = new BooleanMonitor(
19+
SensorID::ESC_TWAI_Init_Failure,
20+
SensorCategory::ESC,
21+
[]() { return escTwaiInitialized; },
22+
false, // Alert when false (i.e., when initialization failed)
23+
AlertLevel::CRIT_HIGH, // Critical since ESC won't work without TWAI
24+
&multiLogger);
25+
monitors.push_back(escTwaiInitFailure);
1426
// ESC MOS Temperature Monitor - with hysteresis
1527
static HysteresisSensorMonitor* escMosTemp = new HysteresisSensorMonitor(
1628
SensorID::ESC_MOS_Temp,

src/sp140/simple_monitor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const char* sensorIDToString(SensorID id) {
108108
case SensorID::ESC_MotorIDet2_Error: return "ESC_MotorIDet2_Error";
109109
case SensorID::ESC_SwHwIncompat_Error: return "ESC_SwHwIncompat_Error";
110110
case SensorID::ESC_BootloaderBad_Error: return "ESC_BootloaderBad_Error";
111+
case SensorID::ESC_TWAI_Init_Failure: return "ESC_TWAI_Init_Failure";
111112

112113
// BMS
113114
case SensorID::BMS_MOS_Temp: return "BMS_MOS_Temp";
@@ -167,6 +168,7 @@ const char* sensorIDToAbbreviation(SensorID id) {
167168
case SensorID::ESC_MotorIDet2_Error: return "MC-SE-11"; // Bit 11
168169
case SensorID::ESC_SwHwIncompat_Error: return "MC-SE-13"; // Bit 13
169170
case SensorID::ESC_BootloaderBad_Error: return "MC-SE-14"; // Bit 14
171+
case SensorID::ESC_TWAI_Init_Failure: return "MC-CAN"; // CAN/TWAI init failure
170172

171173
// BMS (Battery Management System)
172174
case SensorID::BMS_MOS_Temp: return "BC-F";

0 commit comments

Comments
 (0)