diff --git a/Core/Inc/AMS_Errorcodes.h b/Core/Inc/AMS_Errorcodes.h index c96572f..63b3bb5 100644 --- a/Core/Inc/AMS_Errorcodes.h +++ b/Core/Inc/AMS_Errorcodes.h @@ -13,5 +13,6 @@ #define SlavesTimeoutError 1 #define SlavesErrorFrameError 2 #define SLAVES_FRAME_TIMEOUT_ERROR 3 +#define SLAVES_TOO_FEW_TEMPS 4 #endif /* INC_AMS_ERRORCODES_H_ */ diff --git a/Core/Inc/Slave_Monitoring.h b/Core/Inc/Slave_Monitoring.h index a64437f..bc0524c 100644 --- a/Core/Inc/Slave_Monitoring.h +++ b/Core/Inc/Slave_Monitoring.h @@ -20,6 +20,8 @@ #define SLAVETIMEOUT 500 #define SLAVE_HEARTBEAT_FRAMES 11 +// 30% * 90 = 27, each sensor measures 2 cells +#define SLAVE_MIN_TEMP_SENSORS 14 typedef struct { diff --git a/Core/Src/Slave_Monitoring.c b/Core/Src/Slave_Monitoring.c index 6b8b7be..d261874 100644 --- a/Core/Src/Slave_Monitoring.c +++ b/Core/Src/Slave_Monitoring.c @@ -78,6 +78,20 @@ uint8_t checkSlaveTimeout() { return 1; } } + + int working_cell_temps = 0; + for (int i = 0; i < NUMBEROFTEMPS; i++) { + if (slaves[n].cellTemps[i] != 0) { + working_cell_temps++; + } + } + if (working_cell_temps < SLAVE_MIN_TEMP_SENSORS) { + AMSErrorHandle temperror; + temperror.errorcode = SLAVES_TOO_FEW_TEMPS; + temperror.errorarg[0] = n; + AMS_Error_Handler(&temperror); + return 1; + } } return 0; }