Send AMS error messages
This commit is contained in:
@ -28,6 +28,13 @@ HAL_StatusTypeDef can_send_status() {
|
||||
return ftcan_transmit(CAN_ID_AMS_STATUS, data, sizeof(data));
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef can_send_error(TSErrorKind kind, uint8_t arg) {
|
||||
uint8_t data[2];
|
||||
data[0] = kind;
|
||||
data[1] = arg;
|
||||
return ftcan_transmit(CAN_ID_AMS_ERROR, data, sizeof(data));
|
||||
}
|
||||
|
||||
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
||||
if ((id & 0xFF0) == CAN_ID_SHUNT_BASE) {
|
||||
shunt_handle_can_msg(id, data);
|
||||
|
||||
@ -23,7 +23,14 @@ void shunt_init() {
|
||||
}
|
||||
|
||||
void shunt_check() {
|
||||
int is_error = shunt_data.current >= THRESH_OVERCURRENT;
|
||||
int is_error = 0;
|
||||
if (shunt_data.current >= THRESH_OVERCURRENT) {
|
||||
is_error = 1;
|
||||
can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);
|
||||
} else if (shunt_data.busbartemp >= THRESH_OVERTEMP) {
|
||||
is_error = 1;
|
||||
can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);
|
||||
}
|
||||
ts_sm_set_error_source(TS_ERROR_SOURCE_SHUNT, is_error);
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "slave_monitoring.h"
|
||||
|
||||
#include "can.h"
|
||||
#include "main.h"
|
||||
#include "ts_state_machine.h"
|
||||
|
||||
@ -60,14 +61,18 @@ void slaves_check() {
|
||||
uint16_t min_voltage_new = 0xFFFF;
|
||||
int16_t max_temp_new = 0xFFFF;
|
||||
for (int i = 0; i < N_SLAVES; i++) {
|
||||
// Update timeout errors
|
||||
if (now - slaves[i].last_message >= SLAVE_TIMEOUT) {
|
||||
// Don't overwrite a different error kind
|
||||
if (slaves[i].error.kind == SLAVE_ERR_NONE) {
|
||||
slaves[i].error.kind = SLAVE_ERR_TIMEOUT;
|
||||
can_send_error(TS_ERRORKIND_SLAVE_TIMEOUT, slaves[i].id);
|
||||
}
|
||||
} else if (slaves[i].error.kind == SLAVE_ERR_TIMEOUT) {
|
||||
slaves[i].error.kind = SLAVE_ERR_NONE;
|
||||
}
|
||||
|
||||
// Determine min/max
|
||||
if (slaves[i].min_voltage < min_voltage_new) {
|
||||
min_voltage_new = slaves[i].min_voltage;
|
||||
}
|
||||
@ -107,6 +112,7 @@ void slaves_handle_panic(const uint8_t *data) {
|
||||
}
|
||||
slaves[idx].error.data = ftcan_unmarshal_unsigned(&data, 4);
|
||||
slaves[idx].last_message = HAL_GetTick();
|
||||
can_send_error(TS_ERRORKIND_SLAVE_PANIC, slave_id);
|
||||
}
|
||||
|
||||
void slaves_handle_status(const uint8_t *data) {
|
||||
|
||||
Reference in New Issue
Block a user