| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #pragma once
- #include <stdint.h>
- #include "app/sox/soc.h"
- #include "app/sox/measure.h"
- #include "app/sox/measure_task.h"
- #include "app/sox/health.h"
- #include "app/sox/state.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)
- #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 health :24;
- uint32_t state :8; // stat_cmd_resp_t
- }binfo_cmd_resp_t;
- #pragma pack(pop)
- #define CAN_KEY_GET_SN 0x05 //return string
- #define CAN_KEY_SET_SN 0x06 //string
- #define CAN_KEY_BMS_GET_CELLS 0x07
- #pragma pack (push,1)
- typedef struct {
- uint8_t cell_num;
- uint16_t voltages[CELLS_NUM];
- }cell_cmd_resp_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 :1;
- uint8_t discharger_mask :1;
- uint8_t charger_mask :1;
- uint8_t small_mask :1;
- }pwr_cmd_t;
- #pragma pack(pop)
- #define CAN_KEY_GET_VERSION 0x0c //return string
- #define CAN_KEY_BMS_TEMPS 0x11 //return int[4]
- #define CAN_KEY_AGING_TEMPS 0x12
- #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_CHARG_INFO 0xa1
- #pragma pack (push,1)
- typedef struct {
- uint32_t charge_current;
- uint32_t charge_remain_time; //s
- }cinfo_cmd_resp_t;
- #pragma pack(pop)
- #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_SOC_INFO 0xa7
- typedef struct {
- uint32_t c_min;
- uint32_t c_max;
- uint32_t c_now;
- uint32_t c_charger;
- uint32_t c_discharger;
- uint32_t cycle; //充放电循环次数
- uint32_t calibrated;
- }soc_info_t;
- #define CAN_KEY_START_CALI 0xa8
- #pragma pack (push,1)
- typedef struct {
- uint8_t flags; // bit0:1-cs1180, 0- ml5238, bit1-2 0:stop, 1:start, 2: continue
- uint8_t gain;
- uint8_t totol_samples;
- int16_t current;
- uint16_t voltage;
- }cali_cmd_t;
- #pragma pack(pop)
- #define CAN_KEY_PCBA_TEST 0xa9
- #define CAN_KEY_RESTORE_NV 0xaa /* v1/v2升级到v3使用 */
- #pragma pack (push,1)
- typedef struct {
- uint8_t flags;// 1 表示已经校准, 0 未校准
- uint8_t capacity;
- uint8_t sn_len;
- uint8_t sn[24];
- }restore_nv_cmd_t;
- #pragma pack(pop)
- #define CAN_KEY_MIN_SOC 0xab /*设置最小容量,测试使用*/
- #define CAN_KEY_GET_EVENT 0xac /*获取事件信息*/
- #define CAN_KEY_IAP_ENTER 0xF0
- #define CAN_KEY_IAP_BEGIN 0xF1
- #define CAN_KEY_IAP_CHECK 0xF2
- #define CAN_KEY_IAP_WRITE 0xF4
- #define CAN_KEY_IAP_BOOT 0xF5
- #define CAN_KEY_IAP_STAT 0xF6
- #define CAN_EEY_IAP_READ_STRING 0xF8
- #define CAN_KEY_REBOOT 0xFC
- #define CAN_KET_ERASE_NV 0xFE
- 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);
|