#ifndef __CAN_H #define __CAN_H #include "sys.h" #include "stm32f10x.h" #include "stm32f10x_can.h" #define CAN_MAX_PACKET 20 typedef struct { uint8_t head; uint8_t tail; CanRxMsg Msgbody[CAN_MAX_PACKET]; }CAN_REV_Mutli_t; //握手阶段 #define CanCHMID 0x1826f456 //充电机握手 #define CanBHMID 0x182756f4 //BMS握手 //辨识阶段 #define CanCRMID 0x1801f456 //充电机识别 #define CanBRMID 0x1C0256f4 //BMS 和车辆辨识报文 //优先级 06 0x180256f4 07 0x1C0256f4 #define CanBRMID1 0x1CEC56f4 //BMS 和车辆辨识报文 // EC提示充电桩需要发送多包数据 #define CanBRMID2 0x1CEB56f4 //BMS 和车辆辨识报文 // EB提示充电桩开始发送多包数据 //配置阶段 #define CanBCPID 0x180656f4 //电池充电参数 // 优先级 06 0x180656f4 07 0x1C0656f4 #define CanBCPID1 0x1C0656f4 //电池充电参数 #define CanCTSID 0x1807f456 //充电机发送时间同步信息 #define CanCMLID 0x1808f456 //充电机最大输出级别 #define CanBROID 0x100956f4 //电池充电就绪 #define CanCROID 0x100af456 //充电机准备输出就绪 //充电阶段 #define CanBCLID 0x181056f4 //电池充电级别 #define CanBCSID 0x181156f4 //电池充电总状态 // 06 0x181156f4 07 0x1C1156f4 #define CanCCSID 0x1812f456 //充电机状态 #define CanBSMID 0x181356f4 // #define CanBMVID 0x1C1556f4 //电池各模块电压 // 06 CanBMVID 0x181556f4 //电池各模块电压 #define CanBMTID 0x1C1656f4 //电池组温度 //06 0x181656f4 //电池组温度 #define CanBSOCID 0x181756f4 //电池SOC容量 #define CanBAVID 0x181856f4 //电池组平均电压 #define CanBSTID 0x101956f4 //BMS终止充电 #define CanBSTID1 0x181956f4 //BMS终止充电 #define CanCSTID 0x101af456 //充电机终止充电 #define CanCSTID1 0x181af456 //充电机终止充电 //充电结束 #define CanBSDID 0x181c56f4 //BMS充电统计 #define CanCSDID 0x181df456 //充电机充电统计 //错误报文 #define CanBEMID 0x081e56f4 //BMS错误报文 #define CanCEMID 0x081ff456 //充电机错误报文 //传输连接协议的ID #define CAN_CM_CTRL_ID 0x1CEC0000 //传输连接管理控制ID 多包数据连接请求 #define CAN_CM_DATA_ID 0x1CEB0000 //传输连接数据传输ID 发送多包数据 #define CAN_CM_CTRL_ID1 0x1cecf456 //传输连接管理控制ID #define CAN_CM_DATA_ID1 0x1cebf456 //传输连接数据传输ID //控制直接定义 #define CM_RTS_CTRL_CODE 0x10 #define CM_CTS_CTRL_CODE 0x11 #define CM_EMA_CTRL_CODE 0x13 #define CM_ABORT_CTRL_CODE 0xFF //需要采用传输连接协议的PGN编号 #define CM_BRM_PGN 0x000200 //电池组身份编码信息 #define CM_BMV_PGN 0x001500 //蓄电池各模块电压 #define CM_BMT_PGN 0x001600 //蓄电池组温度 #define CM_BSOC_PGN 0x001700 //蓄电池组荷电容量SOC #define CM_BAV_PGN 0x001800 //蓄电池组平均模块电压 #define CM_BCP_PGN 0x000600 //动力蓄电池充电参数 #define CM_BCS_PGN 0x001100 //电池充电总状态 #pragma pack (1) /*指定按1字节对齐*/ typedef union { uint8_t stats[14]; struct { uint8_t ChrgPlAtvStpChrg :2; //充电桩主动中止 uint8_t Pnt2VltDtnErr :2; //检测电2电压异常 uint8_t ChrgConcetErr :2; //充电连接器故障 uint8_t ChrgReserve1 :2; //预留 uint8_t ChrgPlStpChrgRsn1 :2; //充电桩设定条件中止 uint8_t ChrgPlStpChrgRsn2 :2; //人工中止 uint8_t ChrgPlStpChrgRsn3 :2; //故障中止 uint8_t ChrgPlStpChrgRsn4 :2; //bms主动中止 uint8_t ChrgPlStpChrgFltRsn1 :2; //充电机过温 uint8_t ChrgPlStpChrgFltRsn2 :2; //充电机连接器故障 uint8_t ChrgPlStpChrgFltRsn3 :2; //充电机内部过温 uint8_t ChrgPlStpChrgFltRsn4 :2; //电量不能传送 uint8_t ChrgPlStpChrgFltRsn5 :2; //充电桩急停 uint8_t ChrgPlStpChrgFltRsn6 :2; //其他故障 uint8_t ChrgPlStpChrgFltRsn7 :2; //预留1 uint8_t ChrgPlStpChrgFltRsn8 :2; //预留2 uint8_t ChrgPlStpChrgErrRsn1 :2; //电流不匹配 uint8_t ChrgPlStpChrgErrRsn2 :2; //电压异常 uint8_t ChrgPlStpChrgErrRsn3 :2; //预留1 uint8_t ChrgPlStpChrgErrRsn4 :2; //预留2 //bem bms 停止报文 4 uint8_t RcvChrgPlMsgTmt1 :2; //接收bms辨识报文00超时 uint8_t RcvChrgPlMsgTmt2 :2; //接收bms辨识报文aa超时 uint8_t RcvChrgPlMsgTmt_1 :2; //预留1 uint8_t RcvChrgPlMsgTmt_2 :2; //预留1 uint8_t RcvChrgPlMsgTmt3 :2;// 接收充电桩时间同步报文和最大输出能力报文超时 uint8_t RcvChrgPlMsgTmt4 :2; // 接收充电桩准备完成报文超时 uint8_t RcvChrgPlMsgTmt_3 :2; //预留1 uint8_t RcvChrgPlMsgTmt_4 :2; //预留1 //6 uint8_t RcvChrgPlMsgTmt5 :2; // 接收充电桩充电状态报文超时 uint8_t RcvChrgPlMsgTmt6 :2; // 接收充电桩中止报文超时 uint8_t RcvChrgPlMsgTmt_5 :2; //预留1 uint8_t RcvChrgPlMsgTmt_6 :2; //预留1 //7 uint8_t RcvChrgPlMsgTmt7 :2; //接收充电桩统计报文超时 uint8_t RcvChrgPlMsgTmt_7 :6; //预留 //bms相关数据超时 uint8_t RcvBMSMsgTmt1 :2; //接收bms辨识报文超时 uint8_t RcvBMSMsgTmt_1 :6; // uint8_t RcvBMSMsgTmt2 :2; //接收电池充电参数报文超时 uint8_t RcvBMSMsgTmt3 :2; //接收bms准备报文超时 uint8_t RcvBMSMsgTmt_2 :2; //预留 uint8_t RcvBMSMsgTmt_3 :2; //预留 uint8_t RcvBMSMsgTmt4 :2; //接收bms充电状态报文超时 uint8_t RcvBMSMsgTmt5 :2; //接收电池充电要求报文超时 uint8_t RcvBMSMsgTmt6 :2; // 接收bms中止报文超时 uint8_t RcvBMSMsgTmt_6:2; //预留 uint8_t RcvBMSMsgTmt7 :2; //接收bms统计报文超时 uint8_t RcvBMSMsgTmt_7 :6; //预留 uint8_t reserve7:8; }bits; }stop_t; /*充电机参数*/ typedef struct { uint8_t VersionNo[3]; //充电机通信协议版本号 uint8_t identify; //辨识结果 CRM uint8_t SerialNo[4]; //充电编号 uint8_t RegionalCode[3]; //充电机/站所在区域编码,ASCII码 uint8_t date[7]; //CTS // CML uint16_t ChargeOutMaxVoltage; //充电机最高输出电压 1位小数,下同 uint16_t ChargeOutMinVoltage; //充电机最低输出电压 uint16_t ChargeOutMaxCurrent; //充电机最大输出电流 uint16_t ChargeOutMinCurrent; // CRO uint8_t ready; //准备好 // CCS 充电状态报文 uint16_t ChargeOutVoltage; //充电机输出电压 1位小数,下同 uint16_t ChargeOutCurrent; //充电机输出电流 uint16_t ChargeTime; //充电时间 uint8_t ChargeAllow; // 00暂停 01允许 // CST 充电终止报文 stop_t end; // uint8_t StopReason; // 00暂停 01允许 // uint16_t ChargeEndFaultCode; //充电故障原因 // uint8_t ChargeEndErrCode; //充电错误原因 // CSD 充电机统计数据报文 uint16_t ChargeTimeTotal; // 总的充电时间 0-600min uint16_t ChargeEnergyTotal; //充电电量 0.1kwh 0-1000kwh uint8_t SerialNumber[4]; //充电机编号 // CEM 充电机错误报文 int32_t BmsRcvCode; //接收的报文 uint8_t REV_CML_FLAG; }ChargeParam_t; #pragma pack() /*取消指定对齐,恢复缺省对齐*/ /*充电机参数*/ extern ChargeParam_t CDZ_ChargeInfo; /* 充电机与BMS的通讯过程定义 */ enum { CDZ_CHARGE_HAND_PROCESS = 0, //充电握手阶段 CDZ_CHARGE_CONFIG_PROCESS, //充电配置阶段 CDZ_CHARGE_CHARGING_PROCESS, //充电阶段 CDZ_CHARGE_END_PROCESS, //充电结束阶段 CDZ_CHARGE_ERROR_PROCESS //充电错误 }; /* 握手阶段 BHM */ typedef struct { uint8_t ChargeAllowMaxVoltage; //充电允许最高电压 0.1V } Battery_PackInfo_t; /* 辨识阶段 BRM */ /* 电池组身份编码信息 */ #pragma pack (1) typedef struct { uint8_t ucBmsVersion[3]; //电池协议版本号 uint8_t ucBatType; //电池类型 uint16_t TotalCapacity; //总容量 0.1 AH uint16_t TotalVoltage; //总电压 0.1V uint8_t ucProductName[4]; //电池组电池厂家名称 uint32_t uBatIndex; //电池组的序号 uint8_t uProductYear; //电池组生产日期:年 BCD uint8_t uProductMonth; //电池组生产日期:月 BCD uint8_t uProductDay; //电池组生产日期:日 bcd uint8_t uChargeCountTotal[3]; //电池组充电次数 uint8_t ucBatOwnerFlag; //电池组的产权信息:0-租赁;1-车自有 uint8_t ucReserved; //预留 uint8_t ucVehichleInfo[17]; //车辆辨识信息 VIN码 uint8_t ucSoftwareVersion[8]; //bms软件版本号 } Bms_BatInfo_t; //Bms_BatInfo_t Bms_BatInfo; /* 充电配置参数 */ typedef struct { uint16_t BatMaxChargeVol; //单体蓄电池最高允许充电电压(0.00~24.00V) 0.01V uint16_t BatMaxChargeCur; //最高允许充电电流(-400.0A~0A) 0.1A uint16_t uBatMaxEnergy; //动力蓄电池运行最高容量 0~1000ah 1% 0.1kw uint16_t BatMaxTotalChargeVol; //最高允许充电总电压(0.0~800.0V) 0.1V uint8_t uBatMaxTempPlus50; //蓄电池模块最高允许的温度(-50~200℃) uint16_t uTotalBatSOC; //整车动力蓄电池荷电状态(0.0~100.0%) 单位0.1% uint16_t fTotalBatVol; //整车动力蓄电池当前电压(0.0~750.0V) 0.1V }CDZ_BAT_CONFIG_PARAM_t; //CDZ_BAT_CONFIG_PARAM_t Bms_BatCfgParam; /* 充电准备就绪*/ /* 握手阶段 BHM */ typedef struct { uint8_t BMS_ChargeReady; //充电准备 00 未准备好 AA准备好 FF 无效 } Battery_Pack_Ready_t; /*充电阶段参数信息*/ typedef struct { uint16_t BatRequireVoltage; //电池电压需求 uint16_t BatRequireCurrent; //电池电流需求 uint8_t uChargeMode; //当前充电模式:CHARGE_FIX_VOLTAGE--恒压充电 // CHARGE_FIX_CURRENT--恒流充电 uint16_t BatRealVol; //电池电压测量值 uint16_t BatRealCur; //电池电流测量值 uint16_t nBayMaxVolInfo; //最高单体电压 uint8_t uBatCurSOC; //当前荷电状态 uint16_t uEvalChargeFinTime; //估算充满时间 uint16_t uChargeEnergy; //充电量 uint8_t uChargeEnable; //充电量 uint8_t contactorState; //充电量 uint8_t DC_300V_ContactorState; //充电量 // uint8_t uBatMinTempPlus50; //电池最低温度 // uint8_t uBatMaxTempPlus50; //电池最高温度 }Bms_BatRealInfo_t; #pragma pack() /*取消指定对齐,恢复缺省对齐*/ //Bms_BatRealInfo_t Bms_BatRealInfo; //extern uint16_t Plc_RequireVoltage; //extern uint16_t Plc_RequireCurrent; typedef union { uint16_t flag; struct { uint16_t cellVolF : 2; uint16_t socFlag : 2; uint16_t curFlag : 2; uint16_t tempFlag : 2; uint16_t resFlag : 2; uint16_t contFlag : 2; uint16_t chgFlag : 2; }bits; }Bms_BATSTATUS; /* 充电阶段电池的实时状态 BSM */ typedef struct { uint8_t uBatMaxVolSerialNo; //最高单体动力蓄电池电压所在编号 uint8_t uBatMaxTemp; //最高动力蓄电池温度 uint8_t uBatMaxTempPosition; //最高温度检测点编号 /*add*/ uint8_t uBatMinTemp; //最低动力蓄电池的温度 uint8_t uBatMinTemPosition; //最低动力蓄电池的温度检测点编号 Bms_BATSTATUS BAT_STATUS; //蓄电池状态 } Bms_BatRealStatus_t; //Bms_BatRealStatus_t Bms_BatRealStatus; /* 充电阶段电池温度 BMT*/ typedef struct __Bms_BatChargeInfo___ { uint16_t fBatCellVol[256]; //#1~256 蓄电池最小测量单元电压 int8_t uBatCellTemp[128]; //1~128温度 } Bms_BatChargeInfo; /* BMS终止充电原因 BST*/ typedef struct __CDZ_BMS_END_CHARGE_INFO__ { int8_t uBmsEndChargeReason; //BMS终止充电原因 int8_t uBmsEndFaultCode[2]; //BMS终止故障原因 int8_t uBmsEndErrCode; //BMS终止充电故障原因 }Bms_EndChargeInfo; /* 充电完成后BMS统计数据 BSD*/ typedef struct __CDZ_BMS_STAT_DATA__ { uint8_t EndSOC; //终止荷电状态 uint16_t BatCellMinVol; //单体动力蓄电池最低电压 uint16_t BatCellMaxVol; //单体动力蓄电池最高电压 int8_t cBatMinTempPlus50; //电池组最低温度 -50 偏移量 int8_t cBatMaxTempPlus50; //电池组最高温度 -50 偏移量 }Bms_StatInfo; /* 错误报文 BEM*/ typedef struct __Bms_StatusInfo_ { int32_t BmsErrCode; //bms错误报文 int8_t bBmsFaultCode[4]; //Bms故障代码 }Bms_StatusInfo; typedef struct _Bms_TaskManager_ { int8_t bBmsTaskStep; int8_t bBmsProcRes; // 01 握手失败 02 配置失败 04 充电失败 int8_t bBmsConmand; // 启动配置命令 } Bms_TaskManger; void bms_SendCRM(uint8_t uIdentyFlag); #define CC_CHARGE_INIT 0x00 //空闲 #define CC_CHARGE_IDLE 0x01 //空闲 #define CC_CHARGE_READY 0x02 //准备 #define CC_CHARGE_START 0x03 //开始 #define CC_CHARGE_ING 0x04 //充电中 #define CC_CHARGE_END 0x05 //停止 #define CC_CHARGE1_ING 0x01 //充电中 #define CC_CHARGE2_ING 0x02 //充电中 #define CC_CHARGE3_ING 0x03 //充电中 #define CC_CHARGE4_ING 0x04 //充电中 #define CC_CHARGE5_ING 0x05 //充电中 extern uint8_t g_ChargeStep; /*握手启动阶段*/ #define D_CDZ_HANDING_CHM 0x00004000 /* 充电握手阶段 */ #define D_CDZ_HANDING_CRM 0x00000001 /*配置阶段收到的报文*/ #define D_CDZ_CONFIG_CTS 0x00000002 #define D_CDZ_CONFIG_CML 0x00000004 #define D_CDZ_CONFIG_CRO 0x00000008 /*充电阶段收到的报文*/ #define D_CDZ_CHARGE_CCS 0x00000010 /*充电中止收到的报文*/ #define D_CDZ_END_CST 0x00000020 #define D_CDZ_END_CSD 0x00000040 /*错误编码*/ #define D_CDZ_END_CEM 0x00000080 extern void AppCtrOnoffHandle(void); void BmsParaDataInit(void); extern ChargeParam_t CDZ_ChargeInfo; extern Bms_BatRealInfo_t Bms_BatChargeRealInfo ; /***************CAN2 数据 奇瑞的bms数据************************/ #define MAX_TEMP_BAT 46 //故障 #define MAX_TEMP2_BAT 48 //降载 #define MAX_TEMP3_BAT 50 //降载 #define MAX_TEMP4_BAT 52 //降载 #define MAX_TEMP5_BAT 55 //降载 #define MAX_CURENT_TEMP 400 #define LOW_CURENT_TEMP 400 //降载 #define LOW_TEMP1_BAT 2 //降载 #define LOW_TEMP2_BAT 3 //降载 #define LOW_TEMP3_BAT 5 //降载 extern int8_t CheckQiruiBMSWarningState(void); extern uint8_t Bms_BatChargeRealObdBatCurSOC ; /* 电池组 bms0 信息 */ #pragma pack (1) /*指定按1字节对齐*/ typedef union { uint8_t stats[8]; struct { uint16_t bmsChrgCurRqst:13;//充电电流请求 uint16_t bmsChrgCurRqstV:1;//充电电流请求有? uint16_t reserv:2; //byte2 3 交换高低字节 uint16_t bmsChrgVolRqst:13;//充电电压请求 uint16_t bmsChrgVolRqstV:1;//充电电压请求有? uint16_t reserve:2; uint16_t reserve4:8; uint16_t reserve5:8; uint16_t reserve6:8; uint16_t reserve7:8; }bits; }bms284_sts_t; //---------------------------------------------------------- typedef struct{ uint16_t communicationflag; uint16_t maxchargcur; //计算得出 //---------bms284-充电请求电压----------------- bms284_sts_t bms284; //======================================= uint8_t Long_TEST; //老化测试标志 }wulingbat_info_t; #pragma pack() /*取消指定对齐,恢复缺省对齐*/ extern wulingbat_info_t WuLingBatteryInfo; #define CANILONG_TESTINFOID 0x100 //老化测试模式标志 #define CANBMS284INFOID_WULING 0x284 //----------------模拟VIN------------- #define GD_OK 1 #define GD_ERR -1 int VinCalc(char *Vin,char *reslt); char VinTest(void); char VinTest2(void); int VinCalc(char *Vin,char *reslt); //----------------END----------------- int8_t WULING_DCDCSendBms2(void); //发送can数据 int8_t wulingbms_check_status(void); //bms状态 int8_t CheckWuLingBMSFaultState(void); //电池包故障 int8_t CheckWuLingBMSWarningState(void);//bms警告降载 /******充电流程暴露的函数****/ void bms_SendBHM(uint16_t MaxVoltage); void bms_SendBRM(uint16_t step); void bms_SendBCP(uint16_t step); void bms_SendBRO(uint8_t Ready); void bms_SendBCL(void); void bms_SendBCS(uint16_t step); void bms_SendBSM(uint16_t step); void bms_SendBSD(uint16_t step); void bms_SendBST(uint16_t step); #endif