diff --git a/Core/Inc/can_handler.h b/Core/Inc/can_handler.h index 02c0b802..f16ee3de 100644 --- a/Core/Inc/can_handler.h +++ b/Core/Inc/can_handler.h @@ -25,6 +25,7 @@ #define FAULT_CANID 0x703 #define NOISE_CANID 0x88 #define DEBUG_CANID 0x702 +#define FAULT_TIMER_CANID 0x6FF typedef struct { uint32_t prev_tick; @@ -45,6 +46,7 @@ typedef enum { FAULT, NOISE, DEBUG, + FAULT_TIMER, RL_MSG_COUNT } rate_lim_t; diff --git a/Core/Inc/compute.h b/Core/Inc/compute.h index 176da204..2f5f32e0 100644 --- a/Core/Inc/compute.h +++ b/Core/Inc/compute.h @@ -185,6 +185,9 @@ void compute_send_segment_temp_message(acc_data_t *bmsdata); void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl); +void compute_send_fault_timer_message(uint8_t start_stop, uint32_t fault_code, + uint16_t data_1); + /** * @brief Send CAN message for debugging the car on the fly. * diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 0725ac01..fde3ea8a 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -96,6 +96,10 @@ void init_can_msg_config() debug_msg.id = DEBUG_CANID; debug_msg.len = 8; // yaml decodes this to 8 bytes + can_msg_t fault_timer_msg; + fault_timer_msg.id = FAULT_TIMER_CANID; + fault_timer_msg.len = 4; + // rl_data_t rl_discharge_data = { .msg_rate = 5000 }; // rl_data_t rl_charge_data = { .msg_rate = 0 }; @@ -112,6 +116,7 @@ void init_can_msg_config() bms_can_msgs[FAULT] = fault_msg; bms_can_msgs[NOISE] = noise_msg; bms_can_msgs[DEBUG] = debug_msg; + bms_can_msgs[FAULT_TIMER] = fault_timer_msg; // rl_data[DISCHARGE] = rl_discharge_data; // rl_data[CHARGE] = rl_charge_data; @@ -159,6 +164,9 @@ rl_data_t *get_rl_msg(uint32_t can_id) case DEBUG_CANID: return &rl_data[DEBUG]; break; + case FAULT_TIMER_CANID: + return &rl_data[FAULT_TIMER]; + break; default: break; } diff --git a/Core/Src/compute.c b/Core/Src/compute.c index 022c1ac0..89f863c5 100644 --- a/Core/Src/compute.c +++ b/Core/Src/compute.c @@ -535,6 +535,30 @@ void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl) queue_can_msg(bms_can_msgs[FAULT]); } +void compute_send_fault_timer_message(uint8_t start_stop, uint32_t fault_code, + uint16_t data_1) +{ + struct __attribute__((__packed__)) { + uint8_t start_stop; + uint8_t fault_code; + int16_t data_1; + } fault_timer_msg_data; + + fault_timer_msg_data.start_stop = start_stop; + fault_timer_msg_data.fault_code = log2(fault_code); + fault_timer_msg_data.data_1 = data_1; + + endian_swap(&fault_timer_msg_data.fault_code, + sizeof(fault_timer_msg_data.fault_code)); + endian_swap(&fault_timer_msg_data.data_1, + sizeof(fault_timer_msg_data.data_1)); + + memcpy(bms_can_msgs[FAULT_TIMER].data, &fault_timer_msg_data, + sizeof(fault_timer_msg_data)); + + queue_can_msg(bms_can_msgs[FAULT_TIMER]); +} + void compute_send_voltage_noise_message(acc_data_t *bmsdata) { struct __attribute__((__packed__)) { diff --git a/Core/Src/stateMachine.c b/Core/Src/stateMachine.c index e59f0a20..647bae80 100644 --- a/Core/Src/stateMachine.c +++ b/Core/Src/stateMachine.c @@ -303,6 +303,8 @@ uint32_t sm_fault_eval(fault_eval_t *index) if (!fault_present) { printf("\t\t\t*******Fault cleared: %s\r\n", index->id); cancel_timer(&index->timer); + compute_send_fault_timer_message(0, index->code, + index->data_1); return 0; } @@ -321,6 +323,7 @@ uint32_t sm_fault_eval(fault_eval_t *index) else if (!is_timer_active(&index->timer) && fault_present) { printf("\t\t\t*******Starting fault timer: %s\r\n", index->id); start_timer(&index->timer, index->timeout); + compute_send_fault_timer_message(1, index->code, index->data_1); if (index->code == DISCHARGE_LIMIT_ENFORCEMENT_FAULT) { compute_send_fault_message(1, index->data_1, index->lim_1); diff --git a/Drivers/Embedded-Base b/Drivers/Embedded-Base index 83258635..970cceb6 160000 --- a/Drivers/Embedded-Base +++ b/Drivers/Embedded-Base @@ -1 +1 @@ -Subproject commit 83258635fc749ac72adb4b52e61f4f1a42e1842f +Subproject commit 970cceb6d6589c23d21ff6e3d2c29696973902ff