| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #pragma once
- #include <stdint.h>
- #pragma pack (push,1)
- typedef struct
- {
- uint8_t can_addr;
- }can_head_t;
- #pragma pack(pop)
- /* ================ 老协议 ================== */
- #pragma pack (push,1)
- typedef struct
- {
- //整个包大小,包含protocol_head_t
- uint8_t size;
- //命令设备
- uint8_t type;
- //协议类型
- uint8_t protocol;
- //命令类型
- uint8_t cmd;
- //命令校验
- uint16_t checksum;
- //命令处理调用
- uint8_t dir;
- //命令返回状态
- uint8_t bStatus;
- }protocol_old_head_t;
- #pragma pack(pop)
- /* ================ 新协议 ================== */
- #define PROT_V00 0x00
- #define PROT_V01 0x01
- #pragma pack (push,1)
- typedef struct {
- uint8_t dir :1;//1:bms out, 0: bms in
- uint8_t insert :1;//是否新插入
- uint8_t health :1;//电池是否有异常
- uint8_t discharger_fet :1;//dis/charger mos是否打开
- uint8_t charger_fet :1;
- uint8_t small_power :1;//小电是否打开
- uint8_t is_charging :1;//是否在充电
- uint8_t cmd_result :1;//PSxxx 下发的cmd,是否成功
- }bms_stat_t;
- typedef struct {
- uint8_t dir :1;//1:bms out, 0: bms in
- uint8_t power_cmd :1;//power命令是否有效,开关充放电mos,小电
- uint8_t discharger_fet :1;//打开dis/charger mos
- uint8_t charger_fet :1;
- uint8_t small_power :1;//打开小电
- uint8_t bms_info :1; //读取bms基本信息,电压,电流
- uint8_t bms_temps :1; //读取pack的温度
- uint8_t ext_cmd :1; //扩展命令
- }bms_cmd_t;
- typedef struct
- {
- //协议类型
- uint8_t protocol;
- union {
- bms_stat_t status;
- bms_cmd_t command;
- }u_sc;
- }protocol_head_t;
- #pragma pack(pop)
- enum
- {
- OP_NONE, //返回bms基本信息
- OP_BIN_LIAN, // not used
- OP_WRITE_SN,
- OP_PAIR,
- OP_UPDATE_PAIR,
- OP_READ_INFO,
- OP_ALARM_TIMES,
- OP_CELL_VOL,//0x07
- OP_TEMP_OTHER,//0x08
-
- OP_OPEN_FET = 0x0B,
- OP_CLEAR_PAIR = OP_TEMP_OTHER + 1,
- OP_UPDATE_SOFTWARE_REQ = 0x0E,
- OP_UPDATE_SOFTWARE = 0x0F,
-
- OP_MAX
- };
- #pragma pack (push,1)
- typedef struct
- {
- uint8_t bike_speed;
- uint32_t current_miles;//本次电门打开行驶的里程
- uint8_t egate_open; //电门开关信号
- uint8_t operate;
- uint8_t res[8];//保留
- }command_t;
- #pragma pack(pop)
- #pragma pack (push,1)
- typedef struct {
- uint8_t remain_mils; //预估可行驶里程
- uint8_t soc_percent; //剩余电量
- uint8_t charger_remain_time; //预计充电完成时间
- uint8_t is_charging; //是否在充电
- uint32_t current; //放电或者充电电流
- uint32_t pack_voltage; //电池包总电压
- uint8_t max_temp; //4个温感中的最高温度
- uint16_t bms_status; //bms的状态,比如过高温放电等
- uint32_t in_balance_cells; //正在均衡的电芯
- uint8_t misc_flags; //0:bound, 1-2: mosfet, 3: aux short, 4: full 5-6:reserve
- uint8_t result; //0-3:result, 4-7: operate
- }common_response_t;
- #pragma pack(pop)
- void protocol_send_bms_info(protocol_head_t *head);
- void protocol_send_debug_info(uint8_t dest, uint8_t *data, int size);
|