clean up can code
This commit is contained in:
parent
d701266509
commit
665d1ffed6
@ -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_ */
|
||||
|
@ -25,9 +25,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
@ -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 */
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user