From 665d1ffed6d0083a977ed9d0b3f2a267399d9e15 Mon Sep 17 00:00:00 2001 From: kbracher Date: Thu, 23 May 2024 19:19:46 +0200 Subject: [PATCH] clean up can code --- Core/Inc/AMS_CAN.h | 7 ------- Core/Src/AMS_CAN.c | 43 ++----------------------------------------- Core/Src/main.c | 5 ----- 3 files changed, 2 insertions(+), 53 deletions(-) diff --git a/Core/Inc/AMS_CAN.h b/Core/Inc/AMS_CAN.h index 103db6c..d814d38 100644 --- a/Core/Inc/AMS_CAN.h +++ b/Core/Inc/AMS_CAN.h @@ -21,16 +21,9 @@ void ams_can_init(CAN_HandleTypeDef* hcan); void ams_can_handle_ams_msg(CAN_RxHeaderTypeDef* header, uint8_t* data); void ams_can_send_status(); -/** - * @brief Send an AMS Error via CAN. - * - * Data is taken from error_data - */ -void ams_can_send_error(); HAL_StatusTypeDef ams_can_wait_for_free_mailboxes(CAN_HandleTypeDef* handle, int num_mailboxes, uint32_t timeout); -void ams_can_send_log(); #endif /* INC_AMS_CAN_H_ */ diff --git a/Core/Src/AMS_CAN.c b/Core/Src/AMS_CAN.c index 99ca38e..4ff7b40 100644 --- a/Core/Src/AMS_CAN.c +++ b/Core/Src/AMS_CAN.c @@ -25,9 +25,7 @@ #include #include -#define CAN_ID_SLAVE_PANIC 0x009 -#define CAN_ID_SLAVE_STATUS_BASE 0x080 -#define CAN_ID_SLAVE_LOG_BASE 0x600 +#define CAN_ID_MV_BMS 0x501 void ams_can_init(CAN_HandleTypeDef* hcan) { ftcan_init(hcan); } @@ -70,43 +68,6 @@ void ams_can_send_status() { } } ftcan_marshal_unsigned(ptr, max_temp, 2); - uint16_t id = CAN_ID_SLAVE_STATUS_BASE | eeprom_config.id; + uint16_t id = CAN_ID_MV_BMS | eeprom_config.id; ftcan_transmit(id, data, sizeof(data)); } - -void ams_can_send_error() { - static uint8_t data[6]; - data[0] = eeprom_config.id; - data[1] = error_data.data_kind; - memcpy(&data[2], error_data.data, 4); - ftcan_transmit(CAN_ID_SLAVE_PANIC, data, sizeof(data)); -} - -void ams_can_send_log() { - static uint8_t call_count = 0; - static uint8_t data[8]; - - uint16_t can_addr = - CAN_ID_SLAVE_LOG_BASE | (eeprom_config.id << 4) | call_count; - uint8_t* ptr = &data[0]; - - if (call_count < N_CELLS / 4) { - for (size_t i = 0; i < 4; i++) { - size_t offset = call_count * 4; - ptr = ftcan_marshal_unsigned(ptr, module.cellVoltages[offset + i], 2); - } - ftcan_transmit(can_addr, data, sizeof(data)); - } else if (call_count == N_CELLS / 4) { - // Send last cell & failed temperature sensors - ptr = ftcan_marshal_unsigned(ptr, module.cellVoltages[N_CELLS - 1], 2); - ptr = ftcan_marshal_unsigned(ptr, tmp1075_failed_sensors, 4); - ftcan_transmit(can_addr, data, 6); - } else { - size_t offset = (call_count - N_CELLS / 4 - 1) * 8; - for (size_t i = 0; i < 8; i++) { - data[i] = tmp1075_temps[offset + i] >> 4; - } - ftcan_transmit(can_addr, data, sizeof(data)); - } - call_count = (call_count + 1) % (N_CELLS / 4 + 1 + N_TEMP_SENSORS / 8); -} diff --git a/Core/Src/main.c b/Core/Src/main.c index 523bd73..5891d50 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -134,11 +134,6 @@ int main(void) AMS_Loop(); ams_can_send_status(); - if (error_data.error_sources && - HAL_GetTick() - error_data.errors_since >= ERROR_TIME_THRESH) { - ams_can_send_error(); - } - ams_can_send_log(); } /* USER CODE END 3 */ }