Shunt timeout
This commit is contained in:
parent
bf11004c64
commit
25d6ab2667
|
@ -5,8 +5,9 @@
|
||||||
|
|
||||||
#include "stm32f3xx_hal.h"
|
#include "stm32f3xx_hal.h"
|
||||||
|
|
||||||
#define THRESH_OVERCURRENT 300000 // mA
|
#define SHUNT_TIMEOUT 300 // ms
|
||||||
#define THRESH_OVERTEMP 1000 // 1/10 °C
|
#define SHUNT_THRESH_OVERCURRENT 300000 // mA
|
||||||
|
#define SHUNT_THRESH_OVERTEMP 1000 // 1/10 °C
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t current;
|
int32_t current;
|
||||||
|
|
|
@ -24,10 +24,13 @@ void shunt_init() {
|
||||||
|
|
||||||
void shunt_check() {
|
void shunt_check() {
|
||||||
int is_error = 0;
|
int is_error = 0;
|
||||||
if (shunt_data.current >= THRESH_OVERCURRENT) {
|
if (HAL_GetTick() - shunt_data.last_message > SHUNT_TIMEOUT) {
|
||||||
|
is_error = 1;
|
||||||
|
can_send_error(TS_ERRORKIND_SHUNT_TIMEOUT, 0);
|
||||||
|
} else if (shunt_data.current >= SHUNT_THRESH_OVERCURRENT) {
|
||||||
is_error = 1;
|
is_error = 1;
|
||||||
can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);
|
can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);
|
||||||
} else if (shunt_data.busbartemp >= THRESH_OVERTEMP) {
|
} else if (shunt_data.busbartemp >= SHUNT_THRESH_OVERTEMP) {
|
||||||
is_error = 1;
|
is_error = 1;
|
||||||
can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);
|
can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +38,8 @@ void shunt_check() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void shunt_handle_can_msg(uint16_t id, const uint8_t *data) {
|
void shunt_handle_can_msg(uint16_t id, const uint8_t *data) {
|
||||||
|
shunt_data.last_message = HAL_GetTick();
|
||||||
|
|
||||||
// All result messages contain a big-endian 6-byte integer
|
// All result messages contain a big-endian 6-byte integer
|
||||||
uint64_t result = ftcan_unmarshal_unsigned(&data, 6);
|
uint64_t result = ftcan_unmarshal_unsigned(&data, 6);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue