#include #include "main.h" #include "can.h" #include "scs_sdc.h" #include "can-halal.h" extern int can_ams_last_tick; HAL_StatusTypeDef can_init(FDCAN_HandleTypeDef* handle) { TRY(ftcan_init(handle)); TRY(ftcan_add_filter(CAN_ID_AMS_STATUS, 0xFFF)); TRY(ftcan_add_filter(CAN_ID_AMS_ERROR, 0xFFF)); return HAL_OK; } HAL_StatusTypeDef can_change_ts_state(TSState state) { uint8_t data[2]; if (state == TS_ACTIVE) { data[0] = state; return ftcan_transmit(CAN_ID_AMS_IN, data, sizeof(data)); } else if (state == TS_INACTIVE){ data[0] = state; return ftcan_transmit(CAN_ID_AMS_IN, data, sizeof(data)); } else { return HAL_ERROR; } } void ftcan_msg_received_cb(uint16_t id, size_t len, const uint8_t* data) { switch (id) { case CAN_ID_AMS_STATUS: can_ams_last_tick = HAL_GetTick(); ts_handle_ams_status(data); break; case CAN_ID_AMS_SIGNALS: break; case CAN_ID_AMS_ERROR: break; default: break; } }