Check individual heartbeat frames for timeouts
This commit is contained in:
parent
d9e8cc5f52
commit
4316e604da
@ -12,5 +12,6 @@
|
|||||||
|
|
||||||
#define SlavesTimeoutError 1
|
#define SlavesTimeoutError 1
|
||||||
#define SlavesErrorFrameError 2
|
#define SlavesErrorFrameError 2
|
||||||
|
#define SLAVES_FRAME_TIMEOUT_ERROR 3
|
||||||
|
|
||||||
#endif /* INC_AMS_ERRORCODES_H_ */
|
#endif /* INC_AMS_ERRORCODES_H_ */
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#define NUMBEROFTEMPS 32
|
#define NUMBEROFTEMPS 32
|
||||||
|
|
||||||
#define SLAVETIMEOUT 500
|
#define SLAVETIMEOUT 500
|
||||||
|
#define SLAVE_HEARTBEAT_FRAMES 11
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ typedef struct {
|
|||||||
uint32_t timestamp;
|
uint32_t timestamp;
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
uint8_t timeout;
|
uint8_t timeout;
|
||||||
|
uint32_t frame_timestamps[SLAVE_HEARTBEAT_FRAMES];
|
||||||
|
|
||||||
} SlaveHandler;
|
} SlaveHandler;
|
||||||
|
|
||||||
|
@ -210,5 +210,6 @@ void updateSlaveInfo(uint8_t slaveID, uint8_t MessageID, canFrame rxFrame) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
slaves[slaveID].timestamp = rxFrame.timestamp;
|
slaves[slaveID].timestamp = rxFrame.timestamp;
|
||||||
|
slaves[slaveID].frame_timestamps[MessageID] = rxFrame.timestamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,11 @@
|
|||||||
|
|
||||||
#include "Slave_Monitoring.h"
|
#include "Slave_Monitoring.h"
|
||||||
|
|
||||||
|
#include "AMS_Errorcodes.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#include "stm32g4xx_hal.h"
|
||||||
|
|
||||||
SlaveHandler slaves[NUMBEROFSLAVES];
|
SlaveHandler slaves[NUMBEROFSLAVES];
|
||||||
|
|
||||||
void initSlaves() {
|
void initSlaves() {
|
||||||
@ -25,15 +30,18 @@ void initSlaves() {
|
|||||||
|
|
||||||
for (int n = 0; n < NUMBEROFSLAVES; n++) {
|
for (int n = 0; n < NUMBEROFSLAVES; n++) {
|
||||||
for (int i = 0; i < NUMBEROFTEMPS; i++)
|
for (int i = 0; i < NUMBEROFTEMPS; i++)
|
||||||
slaves[n].cellTemps[i] = 30000;
|
slaves[n].cellTemps[i] = 0;
|
||||||
|
|
||||||
for (int j = 0; j < NUMBEROFCELLS; j++)
|
for (int j = 0; j < NUMBEROFCELLS; j++)
|
||||||
slaves[n].cellVoltages[j] = 25000;
|
slaves[n].cellVoltages[j] = 32768;
|
||||||
|
|
||||||
slaves[n].error = 0;
|
slaves[n].error = 0;
|
||||||
slaves[n].timeout = 0;
|
slaves[n].timeout = 0;
|
||||||
slaves[n].timestamp = HAL_GetTick();
|
slaves[n].timestamp = HAL_GetTick();
|
||||||
slaves[n].slaveID = n;
|
slaves[n].slaveID = n;
|
||||||
|
for (int i = 0; i < SLAVE_HEARTBEAT_FRAMES; i++) {
|
||||||
|
slaves[n].frame_timestamps[i] = HAL_GetTick();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +61,23 @@ uint8_t checkSlaveTimeout() {
|
|||||||
AMS_Error_Handler(&timeouterror);
|
AMS_Error_Handler(&timeouterror);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (HAL_GetTick() < 20000) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < SLAVE_HEARTBEAT_FRAMES; i++) {
|
||||||
|
if ((int)(HAL_GetTick() - slaves[n].frame_timestamps[i]) >
|
||||||
|
SLAVETIMEOUT * 2) {
|
||||||
|
slaves[n].timeout = 1;
|
||||||
|
AMSErrorHandle timeouterror;
|
||||||
|
timeouterror.errorcode = SLAVES_FRAME_TIMEOUT_ERROR;
|
||||||
|
timeouterror.errorarg[0] = n;
|
||||||
|
timeouterror.errorarg[1] = i;
|
||||||
|
AMS_Error_Handler(&timeouterror);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user