完成CANFD通信调试
This commit is contained in:
+49
-44
@@ -18,28 +18,31 @@ typedef union {
|
||||
} float_union_t;
|
||||
|
||||
// 添加辅助函数用于将short类型数据打包到u8数组中
|
||||
static inline void pack_short_to_bytes(u8* buffer, u16 offset, short value) {
|
||||
buffer[offset] = (u8)(value & 0xFF);
|
||||
buffer[offset + 1] = (u8)((value >> 8) & 0xFF);
|
||||
static inline void pack_short_to_bytes(u8 *buffer, u16 offset, short value) {
|
||||
buffer[offset] = (u8)(value & 0xFF);
|
||||
buffer[offset + 1] = (u8)((value >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
// 添加辅助函数用于将u16类型数据打包到u8数组中
|
||||
static inline void pack_u16_to_bytes(u8* buffer, u16 offset, u16 value) {
|
||||
buffer[offset] = (u8)(value & 0xFF);
|
||||
buffer[offset + 1] = (u8)((value >> 8) & 0xFF);
|
||||
static inline void pack_u16_to_bytes(u8 *buffer, u16 offset, u16 value) {
|
||||
buffer[offset] = (u8)(value & 0xFF);
|
||||
buffer[offset + 1] = (u8)((value >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
// 添加辅助函数用于将float类型数据打包到u8数组中
|
||||
static inline void pack_float_to_bytes(u8* buffer, u16 offset, float_union_t& float_union) {
|
||||
buffer[offset] = float_union.b[0];
|
||||
buffer[offset + 1] = float_union.b[1];
|
||||
buffer[offset + 2] = float_union.b[2];
|
||||
buffer[offset + 3] = float_union.b[3];
|
||||
static inline void pack_float_to_bytes(u8 *buffer, u16 offset,
|
||||
float_union_t &float_union) {
|
||||
buffer[offset] = float_union.b[0];
|
||||
buffer[offset + 1] = float_union.b[1];
|
||||
buffer[offset + 2] = float_union.b[2];
|
||||
buffer[offset + 3] = float_union.b[3];
|
||||
}
|
||||
|
||||
u8 can_gpio_init(void);
|
||||
void can_config(void);
|
||||
void canfd_config(void);
|
||||
u8 can_gpio_init(void); // CAN引脚初始化
|
||||
void can_config(void); // CAN初始化
|
||||
void canfd_config(void);// CANFD初始化
|
||||
void CAN0_RX0_IRQHandler(void);// CAN接收中断处理函数
|
||||
|
||||
void can_loopback_init(void);
|
||||
void can_loopback_test(void);
|
||||
|
||||
@@ -50,42 +53,44 @@ void can_loopback_test(void);
|
||||
class CAN_transmiter {
|
||||
|
||||
private:
|
||||
u8 controller_Mode;
|
||||
float_union_t limit_velocity_union;
|
||||
u16 limit_voltage;
|
||||
short mcu_temp;
|
||||
short motor_temp;
|
||||
u16 Power_Voltage;
|
||||
float_union_t rt_angle_union;
|
||||
float_union_t rt_velocity_union;
|
||||
u8 Status_code;
|
||||
float_union_t target_angle_union;
|
||||
u8 Target_Control_Mode;
|
||||
float_union_t target_velocity_union;
|
||||
float_union_t u_current_union;
|
||||
float_union_t w_current_union;
|
||||
float_union_t v_current_union;
|
||||
u8 controller_Mode = 0; // 电机模式
|
||||
float_union_t limit_velocity_union = {0}; // 限制速度
|
||||
u16 limit_voltage = 0; // 限制电压
|
||||
short mcu_temp = 0; // MCU温度
|
||||
short motor_temp = 0; // 电机温度
|
||||
u16 Power_Voltage = 0; // 电源电压
|
||||
float_union_t rt_angle_union = {0}; // 实时角度
|
||||
float_union_t rt_velocity_union = {0}; // 实时速度
|
||||
u8 Status_code = 0; // 状态码
|
||||
float_union_t target_angle_union = {0}; // 目标角度
|
||||
u8 Target_Control_Mode = 0; // 目标控制模式
|
||||
float_union_t target_velocity_union = {0}; // 目标速度
|
||||
float_union_t u_current_union = {0}; // U相电流
|
||||
float_union_t w_current_union = {0}; // W相电流
|
||||
float_union_t v_current_union = {0}; // V相电流
|
||||
|
||||
u8 transmit_mailbox; // 初始化为无mailbox状态
|
||||
u32 timeout; // 默认超时为0xFFFF
|
||||
u8 transmit_data[64]; // CANFD最大64字节
|
||||
can_trasnmit_message_struct transmit_message; // 发送消息结构体
|
||||
u8 transmit_mailbox = CAN_NOMAILBOX; // 初始化为无mailbox状态
|
||||
u32 timeout = 0XFFFF; // 默认超时为0xFFFF
|
||||
u8 transmit_data[64]; // CANFD最大64字节
|
||||
|
||||
can_trasnmit_message_struct transmit_message;
|
||||
can_receive_message_struct receive_message;
|
||||
|
||||
can_fdframe_struct can_fd_parameter;
|
||||
can_fd_tdc_struct can_fd_tdc_parameter;
|
||||
void update(); // 更新数据
|
||||
u8 CAN_Receive(); // CAN接收
|
||||
u8 CANFD_Receive(); // CANFD接收
|
||||
u8 CAN_Send(u32 ID, u8 length, u8 *data); // CAN发送
|
||||
u8 CANFD_Send(u32 ID, u8 length, u8 *data); // CANFD发送
|
||||
u8 CAN_all_Send(); // CAN发送
|
||||
u8 CANFD_all_Send(); // CANFD发送
|
||||
|
||||
public:
|
||||
// 添加构造函数声明
|
||||
CAN_transmiter();
|
||||
u8 CAN_Send(u32 ID, u8 length, u8 *data);
|
||||
u8 CANFD_Send(u32 ID, u8 length, u8 *data);
|
||||
void update();
|
||||
u8 CAN_all_Send();
|
||||
u8 CANFD_all_Send();
|
||||
u8 CAN_Receive();
|
||||
u8 CANFD_Receive();
|
||||
|
||||
can_receive_message_struct receive_message; // 接收消息结构体
|
||||
FlagStatus can0_receive_flag; // CAN0接收标志
|
||||
FlagStatus can0_send_flag; // CAN0发送标志
|
||||
|
||||
void communication_check(); // 通信检查
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user