| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #pragma once
- #include <stdint.h>
- /* ================ 老协议 ================== */
- #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 MY_CAN_ADDR 0x30
- #pragma pack (push,1)
- typedef struct
- {
- uint8_t can_addr:7;
- uint8_t can_dir:1; //0->out, 1 ->in,如果发现收到的是0,可能是红外那边自环过来的,需要丢弃
- }can_head_t;
- #define CAN_OUT(head, addr) {(head)->can_addr = addr; (head)->can_dir = 0;}
- #define CAN_IN(head) ((head)->can_dir == 1)
- typedef struct {
- can_head_t head;
- uint8_t key;
- uint8_t data[0];
- }can_frame_t;
- #pragma pack(pop)
- /* can key define */
- #define CAN_KEY_BMS_SET_POWER 0x0B //开关各种mos和小电流
- #pragma pack (push,1)
- typedef struct {
- uint8_t discharger_fet :1;//dis/charger mos是否打开
- uint8_t charger_fet :1;
- uint8_t small_power :1;//小电是否打开
- uint8_t res :5;
- }pwr_cmd_t;
- #pragma pack(pop)
- #define CAN_KEY_BMS_GET_STAT 0xa0 //bms_stat_t
- #pragma pack (push,1)
- typedef struct {
- uint8_t insert :1;//是否新插入,检测到霍尔马上置为1,等CAN_KEY_BMS_CLEAR
- 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 is_charger_in :1;
- uint8_t is_balancing :1; //是否在均衡
- }stat_cmd_resp_t;
- #pragma pack(pop)
- #define CAN_KEY_BMS_BASE_INFO 0x00 //电压,电流,能量, SOC,max temp
- #pragma pack (push,1)
- typedef struct {
- uint32_t pack_voltage;
- int32_t pack_current;
- uint8_t capacity;
- uint32_t energy; //能量,给PS100/200/310/360计算续航里程用
- int8_t max_temp;//最高的那个温度
- uint32_t cycle; //充放电循环次数
- }binfo_cmd_resp_t;
- #pragma pack(pop)
- #define CAN_KEY_BMS_CHARG_INFO 0xa1
- typedef struct {
- uint32_t charge_current;
- uint32_t charge_remain_time; //s
- }cinfo_cmd_resp_t;
- #define CAN_KEY_BMS_TEMPS 0x11 //return int[4]
- #define CAN_KEY_BMS_GET_CELLS 0x07 //return uint16_t[15]
- #define CAN_KEY_SET_LOGGER 0xa2 //byte 0:modle, byte1 level
- #define CAN_KEY_BMS_CLEAR 0xa3 //clear some flags used by PSxxx, exp: stat_cmd_resp_t.insert
- #define CAN_KEY_BMS_GET_HEALTH_STAT 0xa4 //return bms_health_t
- #define CAN_KEY_BMS_GET_TIME 0xa5 //return bms running times(second) uint32_t
- #define CAN_KEY_BMS_SET_WORK_MODE 0xa6 //byte0=mode, byte1=start/stop
- #define CAN_KEY_GET_VERSION 0x0c //return string
- #define CAN_KEY_SET_SN 0x06 //string
- #define CAN_KEY_GET_SN 0x05 //return string
- void protocol_send_bms_info(uint8_t dest, uint8_t key, uint8_t *data, int len);
- void protocol_send_debug_info(uint8_t dest, uint8_t *data, int size);
- void protocol_send_ack(uint8_t dest, uint8_t key, int result);
|