Files
E3/interface.h
2025-10-21 19:14:21 +08:00

1140 lines
49 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _INTERFACE_H_
#define _INTERFACE_H_
#include "stdint.h"
#include "app/app_config.h" // 假设包含基础配置和宏定义
#include "irq.h"
#include "interface_config.h"
#include <udelay/udelay.h>
#pragma pack(1)//数据结构一个字节对齐
#define REQUEST_READ_ID un_request_frame.bit_data.request_id//读取ID
#define REQUEST_HEADER_ID un_request_frame.bit_data.frame_header//帧头
#define FAULT 0
#define NORMAL 1
//-----CAN----------------------------------------------------------------
// 接收电机控制器输入
typedef struct _StrMotorInput
{
//-----接收数据0x101或者0x201----------------------------------------------
unsigned int speed : 16; // 转速 偏移量 -30000
unsigned int bus_voltage : 16; // 母线电压 系数 0.1 偏移量 -3000
unsigned int torque : 16; // 扭矩 系数 0.01 偏移量 -300 实际物理量=数据×系数+偏移量
unsigned int fault_code : 8; // 故障码
unsigned int heartbeat : 8; // 心跳
} StrMotorInput;
typedef union _UnMotorInput
{
StrMotorInput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrMotorInput)]; // 通过结构体类型确定大小
} UnMotorInput;
// 接收电机控制器输入
typedef struct _StrCanDebugOutput
{
uint8_t speed;
uint8_t desired_speed;
uint8_t curvature;
uint8_t desired_curvature;
uint16_t set_left_out;
uint16_t set_right_out;
} StrCanDebugOutput;
typedef union _UnCanDebugOutput
{
StrCanDebugOutput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrCanDebugOutput)]; // 通过结构体类型确定大小
} UnCanDebugOutput;
typedef struct _StrMotorTempInput
{
//-----接收数据0x103或者0x104----------------------------------------------
unsigned int controller_temp : 8; // 控制器温度 偏移量 -40
unsigned int motor_temp : 8; // 电机温度 偏移量 -40
unsigned int motor_max_torque: 16; // 电机最大扭矩 系数 0.01 偏移量 -300 实际物理量=数据×系数+偏移量
unsigned int reserved_1 : 8; // 保留1
unsigned int reserved_2 : 8; // 保留2
unsigned int reserved_3 : 8; // 保留3
unsigned int heartbeat2 : 8; // 心跳
} StrMotorTempInput;
typedef union _UnMotorTempInput
{
StrMotorTempInput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrMotorInput)]; // 通过结构体类型确定大小
} UnMotorTempInput;
// 接收BMS输入
typedef struct _StrBmsInput
{
//-----接收BMS数据----------------------------------------------
uint16_t bus_voltage; // 总电压 系数 0.1V/bit
uint16_t bus_current; // 电流 系数 0.1A/bit 偏移量 -30000
uint16_t soc; // SOC 系数 0.1%/bit
uint8_t Life; // 生命周期 范围 0~255
uint8_t Reserve; // 保留位
} StrBmsInput;
typedef union _UnBmsInput
{
StrBmsInput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrBmsInput)]; // 通过结构体类型确定大小
} UnBmsInput;
// 接收温度模块输入
typedef struct _StrTempModuleInput
{
//-----接收数据0x301302----------------------------------------------
// 多字节数据,高位在前,低位在后
unsigned int channel_1 : 16; // 通道1 温度传感器 系数为0.1 有符号 正数表示正温度,负数表示负温度
unsigned int channel_2 : 16; // 通道2
unsigned int channel_3 : 16; // 通道3
unsigned int channel_4 : 16; // 通道4
unsigned int channel_5 : 16; // 通道5
unsigned int channel_6 : 16; // 通道6
unsigned int channel_7 : 16; // 通道7
unsigned int channel_8 : 16; // 通道8
} StrTempModuleInput;
typedef union _UnTempModuleInput
{
StrTempModuleInput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrTempModuleInput)]; // 通过结构体类型确定大小
} UnTempModuleInput;
//-----以太网-------------------------------------------------------------
// 接收自主计算机自动输入
typedef struct _StrAutoComputerInput
{
// 多字节数据,高位在前,低位在后
unsigned int frame_header : 16; // 帧头 固定值0xFFCC
unsigned int frame_type : 16; // 帧类型 固定值0x0001
unsigned int frame_length : 8; // 帧长 固定值0x19
unsigned int heartbeat : 8; // 心跳 按帧累加
unsigned int set_speed : 16; // 设定速度 系数0.01,正为前进,负为后退 单位m/s
unsigned int set_curvature : 16; // 设定曲率 系数0.0001,正为左转,负为右转
unsigned int latitude : 32; // 纬度 系数10^-7431234567表示43.1234567度
unsigned int longitude : 32; // 经度 系数10^-7431234567表示43.1234567度
unsigned int altitude : 32; // 高度 单位mm
unsigned int heading : 16; // 航向 车辆航向35999表示359.99度
unsigned int crc : 8; // CRC 按字节累加之和溢出取低8位
} StrAutoComputerInput;
typedef union _UnAutoComputerInput
{
StrAutoComputerInput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrAutoComputerInput)]; // 通过结构体类型确定大小
} UnAutoComputerInput;
// 接收自主计算机手动输入
typedef struct _StrManualComputerInput
{
// 手动控制数据 高位在前,低位在后
unsigned int frame_header : 16; // 帧头 固定值0xFFBB
unsigned int frame_type : 16; // 帧类型 固定值0x0011
unsigned int frame_length : 8; // 帧长 固定值0x0B
unsigned int accumulated : 8; // 累加值 按帧累加
unsigned int set_speed : 16; // 期望速度 系数0.01,正为前进,负为后退 单位m/s
unsigned int set_curvature : 16; // 期望曲率 系数0.0001,正为左转,负为右转
unsigned int reserved : 8; // 保留 同时按下LB+Y时发0xFF松开发0同时按下LT+Y时发0x10松开发0
unsigned int crc : 8; // CRC 按字节累加之和溢出取低8位
} StrManualComputerInput;
typedef union _UnManualComputerInput
{
StrManualComputerInput bit_data; // 使用定义的结构体变量名
unsigned int arr[sizeof(StrManualComputerInput) / sizeof(unsigned int)]; // 通过结构体类型确定大小
} UnManualComputerInput;
// 接收请求帧
typedef struct _StrRequestFrame
{
//--------------------------------------------------
unsigned int frame_header : 16; // 帧头 固定值0x0080
unsigned int frame_type : 16; // 帧类型 固定值0x0029
unsigned int frame_length : 16; // 帧长 固定值10
unsigned int accumulated : 8; // 累加值 按帧累加
unsigned int request_id : 16; // 请求帧ID 请求ID 0-FFFFFFFF表示全部帧
unsigned int crc : 8; // CRC 按字节累加之和 取低8位
} StrRequestFrame;
typedef union _UnRequestFrame
{
StrRequestFrame bit_data; // 使用定义的结构体变量名
unsigned char arr[sizeof(StrRequestFrame)]; // 通过结构体类型确定大小
} UnRequestFrame;
// 接收遥控器输入
typedef struct _StrRemoteControlInput
{
//-----接收数据0x12000013----------------------------------------------
unsigned int speed : 16; // 速度
unsigned int curvature : 16; // 曲率
unsigned int reserve1 : 16; // 遥控轴
unsigned int switch_a : 1; // SwA
unsigned int switch_b : 2; // SwB 急停开关 1释放 0/2是急停
unsigned int switch_c : 2; // SwC 模式开关 1自动 0/2是手动
unsigned int switch_d : 1; // SwD 上电开关 先短按再长按
unsigned int reserve2 : 1; // 保留
unsigned int reserve3 : 1; // 保留
unsigned int enable : 8; // 使能
uint16_t y_axis;
uint16_t x_axis;
uint16_t reserve4;
uint16_t reserve5;
} StrRemoteControlInput;
typedef union _UnRemoteControlInput
{
StrRemoteControlInput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrRemoteControlInput)]; // 通过结构体类型确定大小
} UnRemoteControlInput;
// 磁编
typedef struct _StrMagneticEncoder
{
uint8_t ip[4]; // IPv4
uint16_t port; // 端口
uint8_t magnetic_data; // 协议类型1A
} StrMagneticEncoder;
//-----IO口---------------------------------------------------------------
// 从IO口输入
//20250116 增加温度采集字节
typedef struct _StrSwSample
{
unsigned int emergency_stop_switch : 1; // 通道1急停开关
unsigned int High_voltage_switch : 1; // 通道2高压开关
unsigned int flg_wake_ecu : 1; // 通道3
unsigned int CH04 : 1; // 通道4
unsigned int CH05 : 1; // 通道5
unsigned int CH06 : 1; // 通道6
unsigned int CH07 : 1; // 通道7
unsigned int CH08 : 1; // 通道8
unsigned int CH09 : 1; // 通道9
unsigned int CH10 : 1; // 通道10
unsigned int CH11 : 1; // 通道11
unsigned int CH12 : 1; // 通道12
unsigned int CH13 : 1; // 通道13
unsigned int CH14 : 1; // 通道14
unsigned int CH15 : 1; // 通道15
unsigned int CH16 : 1; // 通道16
unsigned int CH17 : 1; // 通道17
unsigned int CH18 : 1; // 通道18
unsigned int CH19 : 1; // 通道19
unsigned int CH20 : 1; // 通道20
unsigned int CH21 : 1; // 通道21
unsigned int CH22 : 1; // 通道22
unsigned int CH23 : 1; // 通道23
unsigned int CH24 : 1; // 通道24
unsigned int CH25 : 1; // 通道25
unsigned int CH26 : 1; // 通道26
unsigned int CH27 : 1; // 通道27
unsigned int CH28 : 1; // 通道28
unsigned int CH29 : 1; // 通道29
unsigned int CH30 : 1; // 通道30
unsigned int CH31 : 1; // 通道31
unsigned int CH32 : 1; // 通道32
// unsigned int CH33 : 1; // 通道33
// unsigned int CH34 : 1; // 通道34
// unsigned int CH35 : 1; // 通道35
// unsigned int CH36 : 1; // 通道36
// unsigned int CH37 : 1; // 通道37
// unsigned int CH38 : 1; // 通道38
// unsigned int CH39 : 1; // 通道39
// unsigned int CH40 : 1; // 通道40
// unsigned int CH41 : 1; // 通道41
// unsigned int CH42 : 1; // 通道42
// unsigned int CH43 : 1; // 通道43
// unsigned int CH44 : 1; // 通道44
// unsigned int reserve : 4;
unsigned int temperature[2]; // 温度
} StrSwSample;
typedef union _UnSwSample
{
StrSwSample bit_data; // 使用定义的结构体变量名
unsigned char arr[sizeof(StrSwSample)]; // 通过结构体类型确定大小
} UnSwSample;
//-----输出数据结构---------------------------------------------------------------
//-----CAN----------------------------------------------------------------
// 输出到电机控制器
typedef struct _StrMotorOutput
{
//-----发送数据0x201或者0x202----------------------------------------------
unsigned int mode : 8; // 模式 0x1恒速模式0x2恒扭模式其他无效
unsigned int gear : 8; // 档位 0x0空挡模式0x1前进挡0x2倒退档其他无效
unsigned int set_torque : 16; // 给定扭矩 系数 0.01 偏移量 -300 实际物理量=数据×系数+偏移量
unsigned int set_rotation_speed : 16; // 给定转速 偏移量 -30000
unsigned int fault_code : 8; // 故障码
unsigned int heartbeat : 8; // 心跳
//-----发送数据0x401或者0x402----------------------------------------------
unsigned int feed_power : 16; // 馈电功率 单位为 W 最大为10KW
unsigned int discharge_power : 16; // 放电功率 单位为 W 最大为15kW
unsigned int reserve1 : 16; // 保留
unsigned int reserve2 : 16; // 保留
} StrMotorOutput;
typedef union _UnMotorOutput
{
StrMotorOutput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrMotorOutput)]; // 通过结构体类型确定大小
} UnMotorOutput;
// 输出到采集模块
typedef struct _StrGatherOutput
{
//----- Send Data 0x15000002 ----------------------------------------------
unsigned int sleep_duration : 16; // 休眠时间
unsigned int wakeup_interval : 16; // 唤醒时间
unsigned int vehicle_mode : 8; // 整车模式
unsigned int reserved1 : 8; // 保留1
unsigned int reserved2 : 8; // 保留2
unsigned int reserved3 : 8; // 保留3
} StrGatherOutput;
typedef union _UnGatherOutput
{
StrGatherOutput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrGatherOutput)]; // 通过结构体类型确定大小
} UnGatherOutput;
// canoe协议输出
typedef struct _StrSdoOutput
{
//-----发送数据0x601----------------------------------------------
unsigned int cmd : 8; // 命令
unsigned int object_index : 16; // 索引
unsigned int sub_index : 8; // 从索引
unsigned int data : 32; // 数据
} StrSdoOutput;
typedef union _UnSdoOutput
{
StrSdoOutput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrSdoOutput)]; // 通过结构体类型确定大小
} UnSdoOutput;
// 超声波数据发送
typedef struct _StrUltrasonicOutput
{
//-----发送数据0x521----------------------------------------------
uint8_t node; // 节点
uint8_t function_code; // 功能码
uint16_t register_address; // 寄存器地址
uint16_t data; // 数据
uint16_t reserve;// 保留
} StrUltrasonicOutput;
typedef union _UnUltrasonicOutput
{
StrUltrasonicOutput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrUltrasonicOutput)]; // 通过结构体类型确定大小
} UnUltrasonicOutput;
// 超声波数据读取
typedef struct _StrUltrasonicIntput
{
//-----发送数据0x521----------------------------------------------
uint8_t node; // 节点
uint8_t function_code; // 功能码
uint8_t len; // 长度
uint16_t data; // 数据
uint8_t reserve1;// 保留
uint16_t reserve2;// 保留
} StrUltrasonicInput;
typedef union _UnUltrasonicInput
{
StrUltrasonicInput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrUltrasonicInput)]; // 通过结构体类型确定大小
} UnUltrasonicInput;
//typedef struct _StrMotorOutput
//{
////-----发送数据0x10F80807----------------------------------------------
// unsigned int gear : 2; // 0 表示空挡1 表示前进2 表示后退
// unsigned int can_gear : 1; // 0-无效 1-有效。无效时 BIT10 的挡位无效,以线路控制挡位为准
// unsigned int can_break : 1; // 0:不刹车1-刹车(刹车时才能启动电子刹车)
// unsigned int reserve1 : 1; // 0-只有高速档 1-可以通过接线切换 123 档。
// unsigned int reserve2 : 1; // 0-无效 1-有效:线控防盗使能
// unsigned int reserve3 : 1; // 0-无效 1-有效:线控巡航使能
// unsigned int reserve4 : 1; // 0-无效 1-有效:线控座桶使能
//
// unsigned int reserve5 : 1; // 0-无效 1-有效:线控边撑使能
// unsigned int reserve6 : 1; // 0-无效 1-有效:线控防盗使能
// unsigned int reserve7 : 1; // 0-无效 1-有效:线控巡航使能
// unsigned int reserve8 : 1; // 0-无效 1-有效:线控座桶使能
// unsigned int reserve9 : 1; // 0-无效 1-有效:线控巡航使能
// unsigned int reserve10 : 1; // 0-无效 1-有效:线控座桶使能
// unsigned int reserve11 : 1; // 0-无效 1-有效:线控巡航使能
// unsigned int reserve12 : 1; // 0-无效 1-有效:线控座桶使能
//
// unsigned int reserve13 : 1; // 0-无效 1-有效:线控边撑使能
// unsigned int reserve14 : 1; // 0-无效 1-有效:线控防盗使能
// unsigned int reserve15 : 1; // 0-无效 1-有效:线控巡航使能
// unsigned int reserve16 : 1; // 0-无效 1-有效:线控座桶使能
// unsigned int reserve17 : 1; // 0-无效 1-有效:线控巡航使能
// unsigned int reserve18 : 1; // 0-无效 1-有效:线控座桶使能
// unsigned int motor_direction : 1; // 0 和 1 (静止空闲状态设置有效,在油门、 转矩、转速模式下允许设置,否则使用控制器 内部保存的参数控制电机方向)
// unsigned int Contactor : 1; // 0-断开 1-闭合,(部分控制器支持)
//
// unsigned int reserve19 : 1; // 0-无效 1-有效:线控边撑使能
// unsigned int reserve20 : 1; // 0-无效 1-有效:线控防盗使能
// unsigned int reserve21 : 1; // 0-无效 1-有效:线控巡航使能
// unsigned int reserve22 : 1; // 0-无效 1-有效:线控座桶使能
// unsigned int mode : 4; //0x0:转把控制0x5:油门模式0xA:转矩模式, 0xC:转速模式,其它无效停机。在这三种模式下,电机方向设置有效。只允许在停机状态下设置控制模式。
//
// unsigned int control_data1 : 16; // 油门-256~+256(0~+256 表示最大油门,-256 表 示最大电子刹车力度。转矩 -256~10000正数 驱 动 扭 矩 0~1000.0Nm,负数表示刹车,-256 表示最大电子刹车力度)转速-256~12000,(正数表示转速 0~12000rpm 负数表示刹车,-256 最大刹车力度)
// unsigned int control_data2 : 16; // 控制数据和上一个一样
//} StrMotorOutput;
//
//typedef union _UnMotorOutput
//{
// StrMotorOutput bit_data; // 使用定义的结构体变量名
// uint8_t arr[sizeof(StrMotorOutput)]; // 通过结构体类型确定大小
//} UnMotorOutput;
//电机控制器风扇左
//kgf1
//电机控制器风扇右
//kgf3
//预充
//kgf4
//高压压继电器
//kgf78
//低压继电器
//kgf11-12
//左前红灯
//kgf6
//左前黄灯
//kgf9
//左风扇
//kgf14
//右风扇
//kgf19
//电脑
//kgf 17-18
//交换机
//kgf 21-22
//右前红灯
//kgf24
//右前黄灯
//kgf25
//左后红灯
//kgf26
//左后黄灯
//kgf27
//右后红灯
//kgf29
//右后黄灯
//kgf30
// 输出到开关阀模块
typedef struct _StrInfCanKGFOutput
{
//----------主机发送命令字0x11000002 --------------------------------------------
unsigned int KGF01 : 1; // 通道1
unsigned int KGF02 : 1; // 通道2
unsigned int KGF03 : 1; // 通道3
unsigned int KGF04 : 1; // 通道4
unsigned int KGF05 : 1; // 通道5
unsigned int KGF06 : 1; // 通道6
unsigned int KGF07 : 1; // 通道7
unsigned int KGF08 : 1; // 通道8
unsigned int KGF09 : 1; // 通道9
unsigned int KGF10 : 1; // 通道10
unsigned int KGF11 : 1; // 通道11
unsigned int KGF12 : 1; // 通道12
unsigned int KGF13 : 1; // 通道13
unsigned int KGF14 : 1; // 通道14
unsigned int KGF15 : 1; // 通道15
unsigned int KGF16 : 1; // 通道16
unsigned int can_rx2 : 8; // 保留
unsigned int can_rx3 : 8; // 保留
unsigned int can_rx4 : 8; // 保留
unsigned int can_rx5 : 8; // 保留
unsigned int can_period_h : 8; // 发送周期高位
unsigned int can_period_l : 8; // 发送周期低位
//----------发送0x11000003 ---------------------------------------------------
unsigned int pwm_01 : 4; // PWM通道1
unsigned int pwm_02 : 4; // PWM通道2
unsigned int pwm_03 : 4; // PWM通道3
unsigned int pwm_04 : 4; // PWM通道4
unsigned int pwm_05 : 4; // PWM通道5
unsigned int pwm_06 : 4; // PWM通道6
unsigned int pwm_07 : 4; // PWM通道7
unsigned int pwm_08 : 4; // PWM通道8
unsigned int pwm_09 : 4; // PWM通道9
unsigned int pwm_10 : 4; // PWM通道10
unsigned int pwm_11 : 4; // PWM通道11
unsigned int pwm_12 : 4; // PWM通道12
unsigned int pwm_13 : 4; // PWM通道13
unsigned int pwm_14 : 4; // PWM通道14
unsigned int pwm_15 : 4; // PWM通道15
unsigned int pwm_16 : 4; // PWM通道16
} StrInfCanKGFOutput;
typedef union _UnInfCanKGFOutput
{
StrInfCanKGFOutput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrInfCanKGFOutput)]; // 通过结构体类型确定大小
} UnInfCanKGFOutput;
// 输出到H桥模块
typedef struct _StrHBridgeOutput
{
//----------主机发送命令字0x7F2 --------------------------------------------
unsigned int channel_01 : 1; // 通道1
unsigned int channel_02 : 1; // 通道2
unsigned int channel_03 : 1; // 通道3
unsigned int channel_04 : 1; // 通道4
unsigned int channel_05 : 1; // 通道5
unsigned int channel_06 : 1; // 通道6
unsigned int channel_07 : 1; // 通道7
unsigned int channel_08 : 1; // 通道8
unsigned int sleep_01 : 1; // 休眠1
unsigned int sleep_02 : 1; // 休眠2
unsigned int sleep_03 : 1; // 休眠3
unsigned int sleep_04 : 1; // 休眠4
unsigned int reserve_01 : 1; // 保留1
unsigned int reserve_02 : 1; // 保留2
unsigned int reserve_03 : 1; // 保留3
unsigned int reserve_04 : 1; // 保留4
unsigned int reserve_05 : 8; // 保留5
unsigned int reserve_06 : 8; // 保留6
unsigned int reserve_07 : 8; // 保留7
unsigned int reserve_08 : 8; // 保留8
unsigned int can_period_h : 8; // 发送周期高位
unsigned int can_period_l : 8; // 发送周期低位
//----------发送0x7F3 ---------------------------------------------------
unsigned int pwm_channel_01 : 4; // PWM通道1
unsigned int pwm_channel_02 : 4; // PWM通道2
unsigned int pwm_channel_03 : 4; // PWM通道3
unsigned int pwm_channel_04 : 4; // PWM通道4
unsigned int pwm_channel_05 : 4; // PWM通道5
unsigned int pwm_channel_06 : 4; // PWM通道6
unsigned int pwm_channel_07 : 4; // PWM通道7
unsigned int pwm_channel_08 : 4; // PWM通道8
unsigned int pwm_reserve_01 : 4; // 保留pwm1
unsigned int pwm_reserve_02 : 4; // 保留pwm2
unsigned int pwm_reserve_03 : 4; // 保留pwm3
unsigned int pwm_reserve_04 : 4; // 保留pwm4
unsigned int pwm_reserve_05 : 4; // 保留pwm5
unsigned int pwm_reserve_06 : 4; // 保留pwm6
unsigned int pwm_reserve_07 : 4; // 保留pwm7
unsigned int pwm_reserve_08 : 4; // 保留pwm8
} StrHBridgeOutput;
typedef union _UnHBridgeOutput
{
StrHBridgeOutput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrHBridgeOutput)]; // 通过结构体类型确定大小
} UnHBridgeOutput;
// 输出给导航仪
typedef struct _StrWheelSpeedOutput
{
//-----发送数据0x98----------------------------------------------
unsigned int left_front : 16; // 左前轮速
unsigned int right_front : 16; // 右前轮速
unsigned int left_rear : 16; // 左后轮速
unsigned int right_rear : 16; // 右后轮速
} StrWheelSpeedOutput;
typedef union _UnWheelSpeedOutput
{
StrWheelSpeedOutput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrWheelSpeedOutput)]; // 通过结构体类型确定大小
} UnWheelSpeedOutput;
// 输出给基站升降杆
typedef struct _StrLifterOutput
{
//-----发送数据0x6F2----------------------------------------------
unsigned int cmd : 8 ; // 上升命令
unsigned int reserve1 : 8 ; // 保留
unsigned int reserve2 : 16; // 保留
unsigned int reserve3 : 16; // 保留
unsigned int reserve4 : 16; // 保留
} StrLifterOutput;
typedef union _UnrLifterOutput
{
StrLifterOutput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrLifterOutput)]; // 通过结构体类型确定大小
} UnLifterOutput;
// CAN ID 解析联合体形式支持位域和32位直接访问
typedef union _UnCanIdInfo
{
uint32_t raw; // 32位整型直接读写整个CAN ID
struct
{
uint32_t motor_id : 8; // 0-7 bit (电机ID)
uint32_t data : 16; // 8-23 bit (数据字段)
uint32_t mode : 5; // 24-28 bit (模式)
uint32_t res : 3; // 29-31 bit (保留位)
} bits;
} UnCanIdInfo;
// 输出can数据
typedef struct _StrTxCanOutput
{
uint16_t index; // 索引(类似寄存器地址)
uint16_t object_index; // 子索引通常为0x0000
uint32_t data; // 数据字段
} StrTxCanOutput;
// CAN数据区联合体 (8字节严格遵循图片协议大端序数据)
typedef union _UnTxCanData {
StrTxCanOutput bit_data; // 结构化访问
uint8_t arr[sizeof(StrTxCanOutput)]; // 字节数组形式(用于原始数据读写)
} UnTxCanData;
// 接收CAN帧结构体
typedef struct _StrTxCanFrame
{
UnCanIdInfo tx_can_id; // 接收到的29位CAN ID
UnTxCanData tx_can_data; // 接收到的8字节数据区
} StrTxCanFrame;
// CAN ID 解析联合体 (29位扩展帧严格遵循图片协议小端序适配)
typedef union _UnRxCanIdInfo {
uint32_t raw; // 完整的32位值
struct {
// 注意小端序下位域布局从低位到高位Bit0到Bit31
// 编译器通常从低位开始分配位域
// 主机CAN_ID (Bit7~Bit0) - 8位 - 最低字节
uint32_t host_id : 8; // Bit7~0: 主机CAN_ID
// 电机状态与故障信息域 (Bit23~Bit8) - 16位
uint32_t motor_can_id : 8; // Bit15~8: 当前电机CAN ID
uint32_t undervoltage : 1; // Bit16: 欠压故障 (0无1有)
uint32_t overcurrent : 1; // Bit17: 过流 (0无1有)
uint32_t overtemperature : 1; // Bit18: 过温 (0无1有)
uint32_t mag_encoder_fault : 1; // Bit19: 磁编码故障 (0无1有)
uint32_t hall_fault : 1; // Bit20: HALL编码故障 (0无1有)
uint32_t uncalibrated : 1; // Bit21: 未标定 (0无1有)
uint32_t mode_state : 2; // Bit23~22: 模式状态 (0:Reset,1:Cali,2:Motor)
// 协议标识 (Bit28~Bit24) - 5位
uint32_t protocol_id : 5; // Bit28~24: 协议标识图中为2
// 保留位 (Bit31~29) - 3位图片中未使用
uint32_t reserved : 3; // Bit31~29: 保留位应设置为0
} bits;
} UnRxCanIdInfo;
// 输出can数据
typedef struct _StrRxCanOutput
{
uint16_t current_angle; // Byte0~1: 当前角度 [0~65535]对应(-4π~4π)
uint16_t current_velocity; // Byte2~3: 当前角速度 [0~65535]对应(-15rad/s~15rad/s)
uint16_t current_torque; // Byte4~5: 当前力矩 [0~65535]对应(-120Nm~120Nm)
uint16_t temperature; // Byte6~7: 当前温度: Temp(摄氏度)*10
} StrRxCanOutput;
// CAN数据区联合体 (8字节严格遵循图片协议大端序数据)
typedef union _UnRxCanData
{
StrRxCanOutput bit_data; // 结构化访问
uint8_t arr[sizeof(StrRxCanOutput)]; // 字节数组形式(用于原始数据读写)
} UnRxCanData;
// 接收CAN帧结构体
typedef struct _StrRxCanFrame
{
UnRxCanIdInfo rx_can_id; // 接收到的29位CAN ID
UnRxCanData rx_can_data; // 接收到的8字节数据区
} StrRxCanFrame;
//-----以太网-------------------------------------------------------------
// 输出给自主计算机
typedef struct _StrComputerOutput
{
//--------------------------------------------------
unsigned int frame_header : 16; // 帧头 0xFFCC
unsigned int frame_type : 16; // 帧类型 0x0011
unsigned int frame_length : 8; // 帧长 0x000b11
unsigned int accumulated : 8; // 累加值
unsigned int speed : 16; // 左侧轮速
unsigned int curvature : 16; // 右侧轮速
unsigned int crc : 8; // CRC
} StrComputerOutput;
typedef union _UnComputerOutput
{
StrComputerOutput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrComputerOutput)]; // 通过结构体类型确定大小
} UnComputerOutput;
// 车辆信息,输出给上位机
typedef struct _StrVehicleInfoOutput
{
//--------------------------------------------------
unsigned int frame_header : 16; // 帧头 固定值0xAACC
unsigned int frame_type : 16; // 帧类型 固定值0x0020
unsigned int frame_length : 16; // 帧长 固定值41
unsigned int accumulated : 8; // 累加值 按帧累加
unsigned int desired_speed : 16; // 期望速度 系数0.01 正为前进,负为后退 单位m/s
unsigned int desired_curvature : 16; // 期望曲率 系数0.0001,正为左转,负为右转
unsigned int set_left_speed : 16; // 设定左转速度 电机1设定转速 正为正传,负为反转
unsigned int set_right_speed : 16; // 设定右转速度 电机2设定转速 正为正传,负为反转
unsigned int longitude : 32; // 纬度 系数 1e-7 值域(-180°180°
unsigned int latitude : 32; // 经度 系数 1e-7 值域(-90°90°
unsigned int altitude : 32; // 高度
unsigned int heading_angle : 16; // 航向角 系数 0.01 值域0-360°
unsigned int speed : 16; // 当前车速 系数 0.01 正为前进,负为后退 单位m/s
unsigned int curvature : 16; // 当前曲率 系数 0.0001正为左转,负为右转
unsigned int battery_voltage : 16; // 电池电压 系数 0.1 单位V
unsigned int battery_soc : 16; // 电池SOC 系数 0.1 单位:%
unsigned int battery_current : 16; // 电池电流 系数 0.1 偏移量 -30000 单位A
unsigned int vehicle_fault_state : 8; // 整车故障状态 0 故障 1正常
unsigned int crc : 8; // CRC 按字节累加之和 取低8位
} StrVehicleInfoOutput;
typedef union _UnVehicleInfoOutput
{
StrVehicleInfoOutput bit_data; // 使用定义的结构体变量名
unsigned char arr[sizeof(StrVehicleInfoOutput)]; // 通过结构体类型确定大小
} UnVehicleInfoOutput;
// 电机状态信息,输出给上位机
typedef struct _StrMotorStatusOutput
{
//--------------------------------------------------
unsigned int frame_header : 16; // 帧头 固定值0xAACC
unsigned int frame_type : 16; // 帧类型 固定值0x0021
unsigned int frame_length : 16; // 帧长 固定值30
unsigned int accumulated : 8; // 累加值 按帧累加
unsigned int left_wheel_speed : 16; // 当前左侧轮速 系数 1 偏移量 -30000 单位rad/min
unsigned int right_wheel_speed : 16; // 当前右侧轮速 系数 1 偏移量 -30000 单位rad/min
unsigned int left_torque : 16; // 左侧电机扭矩 系数 0.01 偏移量 -300 单位N/s
unsigned int right_torque : 16; // 右侧电机扭矩 系数 0.01 偏移量 -300 单位N/s
unsigned int left_fault_code : 8; // 左侧电机故障码
unsigned int right_fault_code : 8; // 右侧电机故障码
unsigned int left_torque_limit : 16; // 左侧电机扭矩限制 系数 0.01 偏移量 -300 单位N/s
unsigned int right_torque_limit : 16; // 右侧电机扭矩限制 系数 0.01 偏移量 -300 单位N/s
unsigned int left_power_in : 16; // 左侧电机馈电功率 系数 1 偏移量 0 单位W
unsigned int right_power_in : 16; // 右侧电机馈电功率 系数 1 偏移量 0 单位W
unsigned int left_power_out : 16; // 左侧电机放电功率 系数 1 偏移量 0 单位W
unsigned int right_power_out : 16; // 右侧电机放电功率 系数 1 偏移量 0 单位W
unsigned int left_voltage : 16; // 左侧电机电压 系数0.1 偏移量-3000 单位V
unsigned int right_voltage : 16; // 右侧电机电压 系数0.1 偏移量-3000 单位V
unsigned int checksum : 8; // 校验和 按字节累加之和 取低8位
} StrMotorStatusOutput;
typedef union _UnMotorStatusOutput
{
StrMotorStatusOutput bit_data; // 使用定义的结构体变量名
unsigned char arr[sizeof(StrMotorStatusOutput)]; // 通过结构体类型确定大小
} UnMotorStatusOutput;
// PID参数输出输出给上位机
typedef struct _StrPIDOutput
{
//--------------------------------------------------
unsigned int frame_header : 16; // 帧头 固定值0xAACC
unsigned int frame_type : 16; // 帧类型 固定值0x0022
unsigned int frame_length : 16; // 帧长 固定值56
unsigned int accumulated : 8; // 累加值 按帧累加
unsigned int rc_straight_p : 32; // 遥控直行P参数 系数 0.001
unsigned int rc_straight_i : 32; // 遥控直行I参数 系数 0.001
unsigned int rc_straight_d : 32; // 遥控直行D参数 系数 0.001
unsigned int auto_straight_p : 32; // 自主直行P参数 系数 0.001
unsigned int auto_straight_i : 32; // 自主直行I参数 系数 0.001
unsigned int auto_straight_d : 32; // 自主直行D参数 系数 0.001
unsigned int rc_turn_p : 32; // 遥控转弯P参数 系数 0.001
unsigned int rc_turn_i : 32; // 遥控转弯I参数 系数 0.001
unsigned int rc_turn_d : 32; // 遥控转弯D参数 系数 0.001
unsigned int auto_turn_p : 32; // 自主转弯P参数 系数 0.001
unsigned int auto_turn_i : 32; // 自主转弯I参数 系数 0.001
unsigned int auto_turn_d : 32; // 自主转弯D参数 系数 0.001
unsigned int checksum : 8; // 校验和 按字节累加之和 取低8位
} StrPIDOutput;
typedef union _UnPIDOutput
{
StrPIDOutput bit_data; // 使用定义的结构体变量名
unsigned char arr[sizeof(StrPIDOutput)]; // 通过结构体类型确定大小
} UnPIDOutput;
// 模拟信号输出,输出给上位机
typedef struct _StrAnalogSignalOutput
{
//--------------------------------------------------
unsigned int frame_header : 16; // 帧头 固定值0xAACC
unsigned int frame_type : 16; // 帧类型 固定值0x0023
unsigned int frame_length : 16; // 帧长 固定值24
unsigned int accumulated : 8; // 累加值 按帧累加
unsigned int channel_1 : 16; // 通道1 温度传感器 系数为0.1 有符号 正数表示正温度,负数标表示负温度
unsigned int channel_2 : 16; // 通道2
unsigned int channel_3 : 16; // 通道3
unsigned int channel_4 : 16; // 通道4
unsigned int channel_5 : 16; // 通道5 温度传感器 系数为0.1 有符号 正数表示正温度,负数标表示负温度
unsigned int channel_6 : 16; // 通道6
unsigned int channel_7 : 16; // 通道7
unsigned int channel_8 : 16; // 通道8
unsigned int crc : 8 ; // 校验和 按字节累加之和 取低8位
} StrAnalogSignalOutput;
typedef union _UnAnalogSignalOutput
{
StrAnalogSignalOutput bit_data; // 使用定义的结构体变量名
unsigned char arr[sizeof(StrAnalogSignalOutput)]; // 通过结构体类型确定大小
} UnAnalogSignalOutput;
// 遥控器数据输出,给上位机
typedef struct _StrRemoteControlOutput
{
//--------------------------------------------------
unsigned int frame_header : 16; // 帧头 固定值0xAACC
unsigned int frame_type : 16; // 帧类型 固定值0x0024
unsigned int frame_length : 16; // 帧长 固定值20
unsigned int accumulated : 8; // 累加值 按帧累加
// RC6GS遥控原始数据
unsigned int speed : 16; // 速度 系数0.01,正为前进,负为后退 单位m/s
unsigned int curvature : 16; // 曲率 系数0.0001,正为左转,负为右转
unsigned int reserve_1 : 16; // 备用1
unsigned int switch_a : 1; // SwA
unsigned int switch_b : 2; // SwB 0和2刹车状态 1正常状态
unsigned int switch_c : 2; // SwC 0和2自主状态 1手动状态
unsigned int switch_d : 1; // SwD
unsigned int hv_relay_state : 1; // 高压继电机状态 0 断开, 1开启
unsigned int reserve_2 : 1; // 备用
unsigned int enable : 8; // 使能 1遥控数据有效0无效
unsigned int accumulated_value : 16; // 接收累加值
unsigned int crc : 8; // 校验和 按字节累加之和 取低8位
} StrRemoteControlOutput;
typedef union _UnRemoteControlOutput
{
StrRemoteControlOutput bit_data; // 使用定义的结构体变量名
unsigned char arr[sizeof(StrRemoteControlOutput)]; // 通过结构体类型确定大小
} UnRemoteControlOutput;
// 手动控制数据,返回给请求者
typedef struct _StrManualControlOutput
{
//--------------------------------------------------
// 手动控制数据 高位在前,低位在后
unsigned int frame_header : 16; // 帧头 固定值0xFFBB
unsigned int frame_type : 16; // 帧类型 固定值0x0025
unsigned int frame_length : 8; // 帧长 固定值0x0C
unsigned int accumulated : 8; // 累加值 按帧累加
unsigned int set_speed : 16; // 设定速度 系数0.01,正为前进,负为后退 单位m/s
unsigned int set_curvature : 16; // 设定曲率 系数0.0001,正为左转,负为右转
unsigned int reserved : 8; // 保留
unsigned int crc_1 : 8 ; // CRC 按字节累加之和溢出取低8位
unsigned int accumulated_value : 16; // 接收累加值
unsigned int crc_2 : 8 ; // CRC 按字节累加之和溢出取低8位
} StrManualControlOutput;
typedef union _UnManualControlOutput
{
StrManualControlOutput bit_data; // 使用定义的结构体变量名
unsigned char arr[sizeof(StrManualControlOutput)]; // 通过结构体类型确定大小
} UnManualControlOutput;
// 自动控制数据输出,返回给请求者
typedef struct _StrAutoControlOutput
{
//--------------------------------------------------
// 自主计算机自动数据 高位在前,低位在后
unsigned int frame_header : 16; // 帧头 固定值0xFFCC
unsigned int frame_type : 16; // 帧类型 固定值0x0026
unsigned int frame_length : 8; // 帧长 固定值0x19
unsigned int accumulated : 8; // 累加值 按帧累加
unsigned int set_speed : 16; // 设定速度 系数0.01,正为前进,负为后退 单位m/s
unsigned int set_curvature : 16; // 设定曲率 系数0.0001,正为左转,负为右转
unsigned int latitude : 32; // 纬度 系数10^-7431234567表示43.1234567度
unsigned int longitude : 32; // 经度 系数10^-7431234567表示43.1234567度
unsigned int altitude : 32; // 高度 单位mm
unsigned int heading : 16; // 航向 车辆航向35999表示359.99度。
unsigned int accumulated_value : 16; // 累加值 按帧累加
unsigned int crc : 8 ; // CRC 总体累加CRC
} StrAutoControlOutput;
typedef union _UnAutoControlOutput
{
StrAutoControlOutput bit_data; // 使用定义的结构体变量名
unsigned char arr[sizeof(StrAutoControlOutput)]; // 通过结构体类型确定大小
} UnAutoControlOutput;
// 接收转台指令输入
typedef struct _StrComputerTurnableInput
{
// 多字节数据,高位在前,低位在后
unsigned int frame_header : 16; // 帧头 固定值0xFFCC
unsigned int frame_type : 16; // 帧类型 固定值0x0001
unsigned int frame_length : 8; // 帧长 固定值0x19
unsigned int heartbeat : 8; // 心跳 按帧累加
// --- 坐标数据部分 ---
int32_t position_x; // X轴坐标
int32_t position_y; // Y轴坐标
int32_t position_z; // Z轴坐标
unsigned int crc : 8; // CRC 按字节累加之和溢出取低8位
} StrComputerTurnableInput;
typedef union _UnComputerTurnableInput
{
StrComputerTurnableInput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrComputerTurnableInput)]; // 通过结构体类型确定大小
} UnComputerTurnableInput;
// 编码器数据帧结构体针对0x1A命令的响应
typedef struct _StrEncoderData {
//--------------------------------------------------
// 编码器数据帧 - 对应 0x1A 命令的响应格式10字节
unsigned int cf : 8; // 命令识别符 固定值0x1A
unsigned int sf : 8; // 编码器状态 1byte
unsigned int abs_value : 24; // 角度数据 3byte LSB重命名abs_value
unsigned int enid : 8; // 编码器ID 1byte
unsigned int abm : 24; // 圈数数据 3byte LSB
unsigned int almc : 8; // 编码器故障 1byte
unsigned int crc : 8; // CRC校验 多项式x^8+1
} StrEncoderData;
// 联合体定义,便于字节数组访问
typedef union _UnEncoderData {
StrEncoderData bit_data; // 位域方式访问
unsigned char arr[sizeof(StrEncoderData)]; // 字节数组方式访问
} UnEncoderData;
//-----IO口---------------------------------------------------------------
// 电压信号输出,到遥控器
typedef struct _StrVoltageSignalOutput
{
unsigned int pwm_value : 16; // PWM值
} StrVoltageSignalOutput;
typedef union _UnVoltageSignalOutput
{
StrVoltageSignalOutput bit_data; // 使用定义的结构体变量名
uint8_t arr[sizeof(StrVoltageSignalOutput)]; // 通过结构体类型确定大小
} UnVoltageSignalOutput;
//外部数据结构声明
extern StrRxCanFrame un_motor_input1 ;//电机控制器1 左侧
extern StrRxCanFrame un_motor_input2 ;//电机控制器2 右侧
extern StrRxCanFrame un_motor_input3 ;//电机控制器1 左后侧
extern StrRxCanFrame un_motor_input4 ;//电机控制器2 右后侧
extern UnBmsInput un_bms_input ;//BMS接收数据
extern UnTempModuleInput un_temp_module_input;//温度采集模块
extern UnAutoComputerInput un_auto_computer_input;//自主计算机自动数据
extern UnManualComputerInput un_manual_computer_input;//自主计算机手动数据
extern UnUltrasonicInput un_ultrasonic_input1;//超声波传感器输入1
extern UnUltrasonicOutput un_ultrasonic_output1;//超声波传感器输出
extern StrTxCanFrame un_motor_output1; //电机输出
extern StrTxCanFrame un_motor_output2; //电机输出
extern StrTxCanFrame un_motor_output3; //电机输出
extern StrTxCanFrame un_motor_output4; //电机输出
extern StrTxCanFrame un_motor_output5 ;//电机输出
extern StrTxCanFrame un_motor_output6 ;//电机输出
extern StrTxCanFrame un_motor_output7 ;//电机输出
extern StrTxCanFrame un_motor_output8 ;//电机输出
extern UnMotorTempInput un_motor_temp1; //电机控制器1 温度
extern UnMotorTempInput un_motor_temp2; //电机控制器2 温度
extern UnMotorTempInput un_motor_temp3; //电机控制器3 左后侧
extern UnMotorTempInput un_motor_temp4; //电机控制器4 右后侧
extern UnInfCanKGFOutput un_inf_can_kgf_output1;
extern UnInfCanKGFOutput un_inf_can_kgf_output2;
extern UnHBridgeOutput un_h_bridge_output;
extern UnHBridgeOutput un_h_bridge_output1;//H桥输出
extern UnWheelSpeedOutput un_wheel_wpeed_output;
extern UnGatherOutput un_gather_output;//采集模块输出
//串口
extern UnRemoteControlInput un_remote_control_input; //遥控器输入
//IO口
extern UnSwSample un_sw_sample;
//以太网
extern UnRequestFrame un_request_frame; //请求帧
extern UnComputerOutput un_computer_output; //输出给自主计算机
extern UnComputerTurnableInput un_computer_turnable_Input ;//转台以太网输入
extern UnEncoderData un_encoder_data_input ;
extern StrMagneticEncoder str_magnetic_encoder ;//编码器请求
//输出给上位机
extern UnVehicleInfoOutput un_vehicle_Info_output; // 车辆信息,输出给上位机
extern UnMotorStatusOutput un_motor_status_output; // 电机状态信息,输出给上位机
extern UnPIDOutput un_pid_output; // PID参数输出输出给上位机
extern UnAnalogSignalOutput un_analog_signal_output; // 模拟信号输出,输出给上位机
extern UnRemoteControlOutput un_remote_control_output;// 遥控器数据输出,给上位机
extern UnManualControlOutput un_manual_control_output;// 手动控制数据,返回给请求者
extern UnAutoControlOutput un_auto_control_output; // 自动控制数据输出,返回给请求者
extern UnSdoOutput un_sdo_output ;//转向电机输出
extern StrTxCanFrame un_sdo_output1 ;//电机1输出
extern StrTxCanFrame un_sdo_output2 ;//电机2输出
extern StrTxCanFrame un_sdo_output3 ;//电机3输出
extern StrTxCanFrame un_sdo_output4 ;//电机4输出
extern StrTxCanFrame un_sdo_output5 ;//电机5输出
extern StrTxCanFrame un_motor_output5 ;//电机1输出
extern StrTxCanFrame un_motor_output6 ;//电机2输出
extern StrTxCanFrame un_motor_output7 ;//电机3输出
extern StrTxCanFrame un_motor_output8 ;//电机4输出
extern StrRxCanFrame un_pitch_intput ;//电机输入
extern StrRxCanFrame un_right_intput ;//电机输入
//变量
extern uint8_t test_app[26];
extern UnCanDebugOutput un_can_debug_output;//调试输出
//函数
void canSendAll(void *signal_id);
void ethernetSendAll(void *signal_id);
#pragma pack()
#endif /* _INTERFACE_H_ */