|
|
@@ -1,15 +1,6 @@
|
|
|
#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
|
|
|
@@ -33,94 +24,79 @@ typedef struct
|
|
|
|
|
|
|
|
|
/* ================ 新协议 ================== */
|
|
|
-#define PROT_V00 0x00
|
|
|
-#define PROT_V01 0x01
|
|
|
+#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 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;
|
|
|
+ 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 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 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 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;
|
|
|
+ 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;//最高的那个温度
|
|
|
+}binfo_cmd_resp_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
|
|
|
-};
|
|
|
+#define CAN_KEY_BMS_CHARG_INFO 0xa1
|
|
|
+typedef struct {
|
|
|
+ uint32_t charge_current;
|
|
|
+ uint32_t charge_remain_time; //s
|
|
|
+}cinfo_cmd_resp_t;
|
|
|
|
|
|
-#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)
|
|
|
+#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_GET_VERSION 0x0c //return string
|
|
|
+#define CAN_KEY_SET_SN 0x06 //string
|
|
|
+#define CAN_KEY_GET_SN 0x05 //return string
|
|
|
|
|
|
-#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_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);
|
|
|
|
|
|
|