CELIS/HARDWARE/CAN/can.c
2024-08-09 14:24:48 +08:00

1404 lines
42 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "can.h"
#include "REV_CarMessage.h"
#include <stdbool.h>
#include <string.h>
#include "CDZ_DATA.h"
#include "Err_Info_Process.h"
#include "Err_code.h"
#define DEBUG_BMS 1
#if DEBUG_BMS > 0
#define BMS_PRINT DEPRINT
#define BMS_PRINT_ARRAY DEPRINT_ARRAY
#else
#define BMS_PRINT
#define BMS_PRINT_ARRAY
#endif
extern uint8_t stopChargeReason;
extern int8_t can_write( CanTxMsg *TxMessage);
extern int8_t can_write2( CanTxMsg *TxMessage);
// SOC
uint8_t Bms_BatChargeRealObdBatCurSOC = 0 ;
//bms 发送报文 握手
void bms_SendBHM(uint16_t MaxVoltage);
//bms 发送报文 辨识
void bms_SendBRM(uint16_t step);
//bms 发送报文 动力蓄电池参数
void bms_SendBCP(uint16_t step);
// 电池准备就绪状态 BRO
//0x0--BMS不能辨识 0xaa--BMS能辨识
void bms_SendBRO(uint8_t Ready);
//电池充电需求 BCL
void bms_SendBCL(void);
//bms 发送报文 电池总状态 BCS
void bms_SendBCS(uint16_t step);
//bms 发送报文 动力蓄电池 状态 BSM
void bms_SendBSM(uint16_t step);
//bms 发送报文 中止充电报文 BST
void bms_SendBST(uint16_t step);
//bms 发送报文 BMS统计报文 BSD
void bms_SendBSD(uint16_t step);
//bms 发送报文 BMS错误报文 BEM
void bms_SendBEM(uint16_t step);
record_t ChargeRecordInfo ={0}; //
ChargeParam_t CDZ_ChargeInfo;
/*参数初始化定义*/
Bms_BatInfo_t Bms_BatInfo;
/* 充电配置参数 */
static CDZ_BAT_CONFIG_PARAM_t Bms_BatConfigParam ;
/*充电阶段参数信息*/
Bms_BatRealInfo_t Bms_BatChargeRealInfo ;
CanRxMsg BMSCAN1Msg;
CanTxMsg BMS_CanTxData;
CanTxMsg BMS_Can2TxData;
void BmsParaDataInit(void)
{
}
/************************************************************************
* Function: HEX2BCD
* Description: ?16??????BCD?
* Input: hex: ?????16??
* Return: ?????BCD?
**************************************************************************/
u8 HEX2BCD(u8 hex)
{
return (((hex / 10) << 4) & 0xf0) | ((hex % 10) & 0xf);
}
/************************************************************************
* Function: BCD2HEX
* Description: ?BCD????16??
* Input: bcd: ?????BCD?
* Return: ?????16????
**************************************************************************/
u8 BCD2HEX(u8 bcd)
{
return (((bcd >> 4) & 0xf) * 10 + (bcd & 0xf));
}
//===========================充电桩各个报文解析 ====================================
//充电桩握手
static int8_t CDZ_ParseCHM(const uint8_t *pData, int32_t iLen, int8_t Ch)
{
if(iLen >3)iLen =3;
memcpy(CDZ_ChargeInfo.VersionNo,pData,iLen);
return TRUE;
}
//充电桩辨识
static int8_t CDZ_ParseCRM(const uint8_t *pData, int32_t iLen, int8_t Ch)
{
if(iLen >8)iLen =8;
CDZ_ChargeInfo.identify = pData[0];
CDZ_ChargeInfo.SerialNo[0] = pData[1];
CDZ_ChargeInfo.SerialNo[1] = pData[2];
CDZ_ChargeInfo.SerialNo[2] = pData[3];
CDZ_ChargeInfo.SerialNo[3] = pData[4];
CDZ_ChargeInfo.RegionalCode[0] = pData[5];
CDZ_ChargeInfo.RegionalCode[1] = pData[6];
CDZ_ChargeInfo.RegionalCode[2] = pData[7];
return TRUE;
}
//充电桩时间同步
static int8_t CDZ_ParseCTS(const uint8_t *pData, int32_t iLen, int8_t Ch)
{
if(iLen >8)iLen =8;
CDZ_ChargeInfo.date[0] =BCD2HEX(pData[0]); // s 29
CDZ_ChargeInfo.date[1] = BCD2HEX(pData[1]);//min 59
CDZ_ChargeInfo.date[2] = BCD2HEX(pData[2]);//hour 23
CDZ_ChargeInfo.date[3] = BCD2HEX(pData[3]);//day 12
CDZ_ChargeInfo.date[4] = BCD2HEX(pData[4]); //mon 6
CDZ_ChargeInfo.date[5] = BCD2HEX(pData[5]); //year 19
CDZ_ChargeInfo.date[6] = BCD2HEX(pData[6]); //year 20
memcpy((uint8_t *)&ChargeRecordInfo.date[0],(uint8_t *)&CDZ_ChargeInfo.date[0],7) ;
return TRUE;
}
//充电桩最大输出能力
static int8_t CDZ_ParseCML(const uint8_t *pData, int32_t iLen, int8_t Ch)
{
int16_t data = 0;
CDZ_ChargeInfo.ChargeOutMaxVoltage =(pData[1] <<8) | pData[0]; // 0.1V
CDZ_ChargeInfo.ChargeOutMinVoltage =(pData[3] <<8 )| pData[2]; // 0.1V
data = (pData[5] <<8 | pData[4]);
data = data > 4000 ? (data - 4000): (4000-data);
CDZ_ChargeInfo.ChargeOutMaxCurrent =data; // 0.1A
data = (pData[7] <<8 | pData[6]);
data = data > 4000 ? (data - 4000): (4000-data);
CDZ_ChargeInfo.ChargeOutMinCurrent =data; // 0.1 A
return TRUE;
}
//充电桩准备就绪 CRO
static int8_t CDZ_ParseCRO(const uint8_t *pData, int32_t iLen, int8_t Ch)
{
CDZ_ChargeInfo.ready = pData[0]; // 0.1V
return TRUE;
}
//充电桩充电状态报文 CCS
static int8_t CDZ_ParseCCS(const uint8_t *pData, int32_t iLen, int8_t Ch)
{
int16_t data = 0;
CDZ_ChargeInfo.ChargeOutVoltage = (pData[1] <<8) + pData[0]; // 0.1V
data = (pData[3] <<8) + pData[2];
data = data > 4000 ? (data - 4000): (4000-data);
CDZ_ChargeInfo.ChargeOutCurrent = data; // 0.1A
//Bms_BatChargeRealInfo.BatRealVol =CDZ_ChargeInfo.ChargeOutVoltage ;
if(data >= 10)// 超过1A时
{
Bms_BatChargeRealInfo.BatRealCur =CDZ_ChargeInfo.ChargeOutCurrent ;
//Bms_BatChargeRealInfo.BatRealVol =CDZ_ChargeInfo.ChargeOutVoltage ;
}
else
{
Bms_BatChargeRealInfo.BatRealCur = 0 ;
}
CDZ_ChargeInfo.ChargeTime = (pData[5] <<8) + pData[4]; // 0.1V
CDZ_ChargeInfo.ChargeTime = CDZ_ChargeInfo.ChargeTime ;
CDZ_ChargeInfo.ChargeAllow = pData[6]; // 是否允许充电
return TRUE;
}
//充电桩充电中止报文 CST
static int8_t CDZ_ParseCST(const uint8_t *pData, int32_t iLen, int8_t Ch)
{
CDZ_ChargeInfo.end.stats[1] = pData[0];
CDZ_ChargeInfo.end.stats[2] = pData[1];
CDZ_ChargeInfo.end.stats[3] = pData[2];
CDZ_ChargeInfo.end.stats[4] = pData[3];
// CDZ_ChargeInfo.StopReason = pData[0]; // 0.1V
// CDZ_ChargeInfo.ChargeEndFaultCode = (pData[2] <<8) + pData[1]; // 0.1V
// CDZ_ChargeInfo.ChargeEndErrCode = pData[3]; //
return TRUE;
}
//充电桩结束阶段报文 CSD
static int8_t CDZ_ParseCSD(const uint8_t *pData, int32_t iLen, int8_t Ch)
{
// CSD 充电机统计数据报文
// CDZ_ChargeInfo.ChargeTimeTotal = (pData[1]<<8)+ pData[0]; // 0.1V
//CDZ_ChargeInfo.ChargeEnergyTotal = (pData[3] <<8) + pData[2]; // 0.1V
CDZ_ChargeInfo.SerialNumber[0] = pData[4];
CDZ_ChargeInfo.SerialNumber[1] = pData[5];
CDZ_ChargeInfo.SerialNumber[2] = pData[6];
CDZ_ChargeInfo.SerialNumber[3] = pData[7];
return TRUE;
}
//充电桩错误报文 CEM
static int8_t CDZ_ParseCEM(const uint8_t *pData, int32_t iLen, int8_t Ch)
{
// CDZ_ChargeInfo.BmsRcvCode = (pData[3] <<24) + (pData[2]<<16)+ (pData[1]<<8)+ pData[0]; // 0.1V
CDZ_ChargeInfo.end.stats[5] = pData[0];
CDZ_ChargeInfo.end.stats[6] = pData[1];
CDZ_ChargeInfo.end.stats[7] = pData[2];
CDZ_ChargeInfo.end.stats[8] = pData[3];
return TRUE;
}
/*********************************************************************************
函数名称bms_check_status
功能描述: 充电过程检测是否收到错误报文
输 入:命令
输 出:无
返 回 值false 故障 true 无故障
*********************************************************************************/
int8_t bms_check_status(void)
{
return TRUE;
}
/*********************************************************************************
函数名称wulingbms_check_status
功能描述充电过程检查车辆bms是否有故障
输 入:命令
输 出:无
返 回 值false 故障 true 无故障
*********************************************************************************/
int8_t wulingbms_check_status(void)
{
return TRUE;
}
CanRxMsg testBMSCAN1Msg;
/*********************************************************************************
函数名称wulingbms_check_status
功能描述充电过程检查车辆bms是否有故障
输 入:命令
输 出:无
返 回 值false 故障 true 无故障
*********************************************************************************/
static void bms_parseData(int32_t objId, uint8_t *cCanData, int32_t can_DataLen, int8_t Ch)
{
int8_t bParseResult = 0;
// BMS_PRINT("\n\r收到充电桩can 数据[%d]:",Ch);
// BMS_PRINT("%x \n",objId);
// BMS_PRINT_ARRAY(cCanData,can_DataLen);
//CDZ_ChargeInfo.BmsRcvTimeCount = 0;
CDZ_Time_Out_Handl();//超时处理
switch(objId)
{
case CanCHMID: //电池握手报文
bParseResult = CDZ_ParseCHM(cCanData, can_DataLen, Ch);
if (bParseResult)
{
CDZ_ChargeInfo.BmsRcvCode |= D_CDZ_HANDING_CHM;
// test_bmsrevdata =1;
//BMS_PRINT("\n\r握手报文 st_BmsStatusInfo[%d].BmsRcvCode = %x\n\r",Ch,st_BmsStatusInfo[Ch].BmsRcvCode);
}
break;
case CanCRMID:
{
bParseResult = CDZ_ParseCRM(cCanData, can_DataLen, Ch);
if (bParseResult)
{
CDZ_ChargeInfo.BmsRcvCode |= D_CDZ_HANDING_CRM;
}
break;
}
case CanCTSID:
{
bParseResult = CDZ_ParseCTS(cCanData, can_DataLen, Ch);
if (bParseResult)
{
CDZ_ChargeInfo.BmsRcvCode |= D_CDZ_CONFIG_CTS;
}
break;
}
case CanCMLID:
{
bParseResult = CDZ_ParseCML(cCanData, can_DataLen, Ch);
if (bParseResult)
{
CDZ_ChargeInfo.BmsRcvCode |= D_CDZ_CONFIG_CML;
}
break;
}
case CanCROID:
{
bParseResult = CDZ_ParseCRO(cCanData, can_DataLen, Ch);
if (bParseResult)
{
CDZ_ChargeInfo.BmsRcvCode |= D_CDZ_CONFIG_CRO;
}
break;
}
case CanCCSID:
{
bParseResult = CDZ_ParseCCS(cCanData, can_DataLen, Ch);
if (bParseResult)
{
CDZ_ChargeInfo.BmsRcvCode |= D_CDZ_CHARGE_CCS;
}
break;
}
case CanCSTID:
case CanCSTID1:
{
bParseResult = CDZ_ParseCST(cCanData, can_DataLen, Ch);
if (bParseResult)
{
CDZ_ChargeInfo.BmsRcvCode |= D_CDZ_END_CST;
}
break;
}
case CanCSDID:
{
bParseResult = CDZ_ParseCSD(cCanData, can_DataLen, Ch);
if (bParseResult)
{
CDZ_ChargeInfo.BmsRcvCode |= D_CDZ_END_CSD;
}
break;
}
case CanCEMID:
{
bParseResult = CDZ_ParseCEM(cCanData, can_DataLen, Ch);
if (bParseResult)
{
CDZ_ChargeInfo.BmsRcvCode |= D_CDZ_END_CEM;
}
break;
}
default:
break;
}
}
/*********************************************************************************
函数名称:接收充电桩数据
功能描述接收can1数据
输 入:命令
输 出:无
返 回 值:-1异常 1正常
*********************************************************************************/
int bms_RcvCanSingleDataProc(CanRxMsg pSingleCanRxData)
{
static CanRxMsg SingleCanRxData = {0};
static uint32_t SingleId;
SingleCanRxData = pSingleCanRxData;
SingleId = SingleCanRxData.ExtId;
if((SingleCanRxData.ExtId & 0x0000FFFF) != 0x0000F456) //不是充电桩报文
return -1;
if((SingleCanRxData.ExtId & 0xFFFF0000) == CAN_CM_CTRL_ID)//收到bms多包数据连接请求
{
BMSCAN1Msg = SingleCanRxData;
return -1;
}
if((SingleCanRxData.ExtId & 0xFFFF0000) == CAN_CM_DATA_ID)//收到bms发送多包数据
{
BMSCAN1Msg = SingleCanRxData;
return -1;
}
if(
(SingleId == CanCHMID) || (SingleId== CanCRMID) ||
(SingleId == CanCTSID) || (SingleId == CanCMLID) ||
(SingleId == CanCROID) || (SingleId == CanCCSID) ||
(SingleId == CanCSDID) || (SingleId == CanCEMID) ||
(SingleId == CanCSTID) || (SingleId == CanCSTID1)
)
{
testBMSCAN1Msg = SingleCanRxData;
bms_parseData(SingleCanRxData.ExtId, SingleCanRxData.Data, SingleCanRxData.DLC, 0);
}
return 0;
}
static CAN_REV_Mutli_t CanMessage;// add dxm ??bms???????
uint32_t MutliRecvTimer = 0;//add dxm
uint32_t MutliRecvCount = 0;//add dxm
/*********************************************************************************
函数名称bms_RcvCanMutliData
功能描述:解析多包数据
输 入can
输 出:无
返 回 值:无
*********************************************************************************/
void bms_RcvCanMutliData(CanRxMsg candata,uint8_t channel,uint8_t *flag)
{
static uint8_t uPackNum = 0;
if(CanMessage.tail < CAN_MAX_PACKET)
{
CanMessage.Msgbody[CanMessage.tail] = candata;
CanMessage.tail++;
}
if((candata.ExtId & 0xFFFF0000) == CAN_CM_CTRL_ID) //收到充电桩多包数据请求
{
if(candata.Data[0] == CM_RTS_CTRL_CODE || candata.Data[0] == CM_EMA_CTRL_CODE)
{
uPackNum = candata.Data[3];
}
else if(candata.Data[0] == CM_CTS_CTRL_CODE)
{
uPackNum = candata.Data[1];
}
MutliRecvCount = 10;//15ms????
}
else if((candata.ExtId & 0xFFFF0000) == CAN_CM_DATA_ID) //收到多包数据
{
if(uPackNum == candata.Data[0])
{
MutliRecvCount = 20;
uPackNum = 0;
}
else
{
MutliRecvCount = 50;
}
}
TickOut(&MutliRecvTimer,0);
*flag =0;
}
uint8_t bms_rev_busy_flag = 0;
volatile uint8_t MutliRecvFlag = {0};
CanRxMsg MutliBMSCAN1Msg;
/*********************************************************************************
函数名称bms_RcvCanMutliData
功能描述can接收中断
输 入:命令
输 出:无
返 回 值:无
*********************************************************************************/
//void USB_LP_CAN1_RX0_IRQHandler(void)
//{
// CanRxMsg RxMessage;
// CAN_Receive(CAN1,CAN_FIFO0,&RxMessage);
// bms_rev_busy_flag = 1;
// if(bms_RcvCanSingleDataProc(RxMessage) == 1)
// {
// MutliBMSCAN1Msg = RxMessage;
// bms_RcvCanMutliData(MutliBMSCAN1Msg,0,&bms_rev_busy_flag);
// }
//}
/*********************************************************************************
函数名称Is_bms_RcvMutliMsgOverFlag
功能描述:判断多包数据是否接收完毕
输 入Ch 通道
输 出:无
返 回 值:无
*********************************************************************************/
static void Is_bms_RcvMutliMsgOverFlag()
{
if(MutliRecvCount)
{
if(TickOut(&MutliRecvTimer,MutliRecvCount)== TRUE)
{
// BMS_PRINT("\n\r多帧接收完毕,延时[%d]毫秒\r\n",MutliRecvCount);
MutliRecvFlag = 1;//接收多包数据完成标志位
MutliRecvCount= 0;//延时清0
}
else
{
//未超时暂不处理
}
}
else //test
{
}
}
/*********************************************************************************
函数名称bms_RcvCanMutliDataProc
功能描述:多包内容接收和解析
输 入Ch CAN 通道 (0/1)
输 出:无
返 回 值:无
*********************************************************************************/
static CanRxMsg st_CanRxData= {0};
void bms_RcvCanMutliDataProc()
{
static uint32_t objId= 0;
static uint8_t MutliPacketFlag = FALSE;//多包解析数据标记
static uint16_t cCanMutliDataLen= 0; //多包数据字节数
//static CanRxMsg st_CanRxData= 0;
Is_bms_RcvMutliMsgOverFlag(); //判断多包数据是否接收完毕多包标志是否置位
if(MutliRecvFlag == 1)//多包数据已接收完
{
if(CanMessage.head >= CanMessage.tail)
{
MutliRecvFlag = 0;
CanMessage.tail =0;
CanMessage.head =0;
// BMS_PRINT("\n\r多帧处理完毕\r\n");
return;
}
memcpy(&st_CanRxData,&CanMessage.Msgbody[CanMessage.head++],sizeof(CanRxMsg));
if((st_CanRxData.ExtId & 0x0000FFFF) != 0x000056F4 ) //ID过滤
return;
else
{
if((st_CanRxData.ExtId & 0xFFFF0000) == CAN_CM_CTRL_ID ) //传输连接控制
{
if(st_CanRxData.Data[0] == CM_RTS_CTRL_CODE) //传输控制请求
{
}
else if(st_CanRxData.Data[0] == CM_CTS_CTRL_CODE) //传输控制请求
{
}
return;
}
else if( (st_CanRxData.ExtId & 0xFFFF0000) == CAN_CM_DATA_ID ) //传输连接数据传输
{
}
}
}
if(MutliPacketFlag == TRUE) //多包接收完成
{
MutliPacketFlag = FALSE;
bms_parseData(objId, 0, cCanMutliDataLen, 0);
cCanMutliDataLen= 0;
}
}
/*****************************************************can2发送*****************************/
#define WAIT_TIME_MS 3
//bms 发送报文数据握手
void bms_SendBHM(uint16_t MaxVoltage)
{
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBHMID;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 2;
memset(BMS_CanTxData.Data, 0xff, 8);
BMS_CanTxData.Data[0] = MaxVoltage &0xff;
BMS_CanTxData.Data[1] =(MaxVoltage >> 8)&0xff;//最高充电允许电压
can_write(&BMS_CanTxData);
}
//bms 发送报文 辨识
void bms_SendBRM(uint16_t step)
{
uint8_t ucVehichleBmsInfo[17] ={0}; //车辆辨识信息 VIN码
if(step == 1)
{
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBRMID1;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 8;
memset(BMS_CanTxData.Data,0xff,8);
BMS_CanTxData.Data[0] = 0x10;
BMS_CanTxData.Data[1] = 0x31;//数据长度
BMS_CanTxData.Data[2] = 0x00;//数据长度
BMS_CanTxData.Data[3] = 0x07;//49帧数据需要7包数据发送
BMS_CanTxData.Data[4] = 0xff;
BMS_CanTxData.Data[5] = 0x00;
BMS_CanTxData.Data[6] = 0x02;
BMS_CanTxData.Data[7] = 0x00;
can_write(&BMS_CanTxData);
}
else if(step == 2)
{
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBRMID2;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 8;
memset(BMS_CanTxData.Data, 0xff, 8);
//01 01 01 01 03 e8 03 58
//010101当前版本信息
//03磷酸铁锂电池类型
// 0x03e8 蓄电池额定容量
// 蓄电池额定总电压 :0x1b58 = 7000 =700V
//厂商名称:0x00000000
BMS_CanTxData.Data[0] = 0x01;
BMS_CanTxData.Data[1] = GetBRM_VersionArr_0();
BMS_CanTxData.Data[2] = GetBRM_VersionArr_1();
BMS_CanTxData.Data[3] = GetBRM_VersionArr_2(); //bms通讯协议版本号默认 00 01 01
BMS_CanTxData.Data[4] = GetBRM_Battery_TYPE(); //电池类型
BMS_CanTxData.Data[5] = GetBRM_RatedCapacity()&0xff;
BMS_CanTxData.Data[6] = (GetBRM_RatedCapacity()>>8)&0xff;//额定容量
BMS_CanTxData.Data[7] = GetBRM_RatedTotalVoltage()&0xff;
can_write(&BMS_CanTxData);
//延时 10ms
Delay_MS(WAIT_TIME_MS);
BMS_CanTxData.Data[0] = 0x02;
BMS_CanTxData.Data[1] =(GetBRM_RatedTotalVoltage()>>8)&0xff; //电池总电压
BMS_CanTxData.Data[2] = BMSDefaultParameters.BRM.Battery_manufacturer[0];
BMS_CanTxData.Data[3] = BMSDefaultParameters.BRM.Battery_manufacturer[1];
BMS_CanTxData.Data[4] = BMSDefaultParameters.BRM.Battery_manufacturer[2];
BMS_CanTxData.Data[5] = BMSDefaultParameters.BRM.Battery_manufacturer[3]; //电池厂商名字--4字节
BMS_CanTxData.Data[6] = 0x00;//电池组序号
BMS_CanTxData.Data[7] = 0x00;//电池组序号
can_write(&BMS_CanTxData);
//延时 10ms
Delay_MS(WAIT_TIME_MS);
BMS_CanTxData.Data[0] = 0x03;//包序
BMS_CanTxData.Data[1] = 0x01;//电池组序号
BMS_CanTxData.Data[2] = 0x02;//电池组序号 //电池组号--4字节
BMS_CanTxData.Data[3] = BMSDefaultParameters.BRM.Batteryack_production_dateYesr; //-电池生产日期--3字节 年
BMS_CanTxData.Data[4] = BMSDefaultParameters.BRM.Batteryack_production_dateMouth; // 月
BMS_CanTxData.Data[5] = BMSDefaultParameters.BRM.Batteryack_production_dateData; // 日
BMS_CanTxData.Data[6] = BMSDefaultParameters.BRM.Battery_pack_charge_count.fields.ChargeCount[0];
BMS_CanTxData.Data[7] = BMSDefaultParameters.BRM.Battery_pack_charge_count.fields.ChargeCount[1];
can_write(&BMS_CanTxData);
//延时 10ms
Delay_MS(WAIT_TIME_MS);
SysParaPileD.VIN_Enable = 0;//不上报VIN
if(SysParaPileD.VIN_Enable == 1) //上报VIN
{
memcpy(ucVehichleBmsInfo, BMSDefaultParameters.BRM.ucCarVin,sizeof(Bms_BatInfo.ucVehichleInfo));
}
else //不上报 VIN
{
memset(ucVehichleBmsInfo,0xFF,sizeof(ucVehichleBmsInfo));
}
BMS_CanTxData.Data[0] = 0x04;
BMS_CanTxData.Data[1] = BMSDefaultParameters.BRM.Battery_pack_charge_count.fields.ChargeCount[2];//电池组充电次数--3字节
BMS_CanTxData.Data[2] = BMSDefaultParameters.BRM.Battery_pack_property_right_identification; //电池产权租赁
BMS_CanTxData.Data[3] = 0x00; // 预留
BMS_CanTxData.Data[4] = ucVehichleBmsInfo[0]; // 车辆 VIN
BMS_CanTxData.Data[5] = ucVehichleBmsInfo[1];
BMS_CanTxData.Data[6] = ucVehichleBmsInfo[2];
BMS_CanTxData.Data[7] = ucVehichleBmsInfo[3];
can_write(&BMS_CanTxData);
//延时 10ms
Delay_MS(WAIT_TIME_MS);
BMS_CanTxData.Data[0] = 0x05;
BMS_CanTxData.Data[1] = ucVehichleBmsInfo[4];
BMS_CanTxData.Data[2] = ucVehichleBmsInfo[5];
BMS_CanTxData.Data[3] = ucVehichleBmsInfo[6];
BMS_CanTxData.Data[4] = ucVehichleBmsInfo[7];
BMS_CanTxData.Data[5] = ucVehichleBmsInfo[8];
BMS_CanTxData.Data[6] = ucVehichleBmsInfo[9];
BMS_CanTxData.Data[7] = ucVehichleBmsInfo[10];
can_write(&BMS_CanTxData);
//延时 10ms
Delay_MS(WAIT_TIME_MS);
BMS_CanTxData.Data[0] = 0x06;
BMS_CanTxData.Data[1] = ucVehichleBmsInfo[11];
BMS_CanTxData.Data[2] = ucVehichleBmsInfo[12];
BMS_CanTxData.Data[3] = ucVehichleBmsInfo[13];
BMS_CanTxData.Data[4] = ucVehichleBmsInfo[14];
BMS_CanTxData.Data[5] = ucVehichleBmsInfo[15];
BMS_CanTxData.Data[6] = ucVehichleBmsInfo[16];
BMS_CanTxData.Data[7] = 0x10; //bms软件版本号
can_write(&BMS_CanTxData);
//延时 10ms
Delay_MS(WAIT_TIME_MS);
BMS_CanTxData.Data[0] = 0x07;
BMS_CanTxData.Data[1] = 0x0A; //日10
BMS_CanTxData.Data[2] = 0x0B; //月11
BMS_CanTxData.Data[3] = 0x07; //年20
BMS_CanTxData.Data[4] = 0xE0; // 16
BMS_CanTxData.Data[5] = 0xff; //预留默认0xff
BMS_CanTxData.Data[6] = 0xff; //预留默认0xff
BMS_CanTxData.Data[7] = 0xff; //预留默认0xff
can_write(&BMS_CanTxData);
}
}
#include "adc.h"
//bms 发送报文 动力蓄电池参数
void bms_SendBCP(uint16_t step)
{
if(step == 1)
{
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBRMID1;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 8;
memset(BMS_CanTxData.Data, 0xff, 8);
BMS_CanTxData.Data[0] = 0x10;
BMS_CanTxData.Data[1] = 0x0d;
BMS_CanTxData.Data[2] = 0x00;
BMS_CanTxData.Data[3] = 0x02;
BMS_CanTxData.Data[4] = 0xff;
BMS_CanTxData.Data[5] = 0x00;
BMS_CanTxData.Data[6] = 0x06;
BMS_CanTxData.Data[7] = 0x00;
can_write(&BMS_CanTxData);
}
else if(step == 2)
{
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBRMID2;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 8;
memset(BMS_CanTxData.Data, 0xff, 8);
/*单体最高电压:375 (0.1v), 电流:1720 (0.1A)
最高允许充电电压:5994 (0.1V),最高允许温度:60 (C)
整车总电荷状态:458 (0.1%), 当前总电压:5335 (0.1V)*/
BMS_CanTxData.Data[0] = 0x01;
BMS_CanTxData.Data[1] = BMSDefaultParameters.BCP.MaxChargingVoltageSingle&0xff;
BMS_CanTxData.Data[2] = (BMSDefaultParameters.BCP.MaxChargingVoltageSingle>>8)&0xff; //单体蓄电池最高允许充电电压420*0.01 = 4.2v 精度0.01
BMS_CanTxData.Data[3] = (4000-BMSDefaultParameters.BCP.MaxChargingCurrent)&0xff;
BMS_CanTxData.Data[4] = ((4000-BMSDefaultParameters.BCP.MaxChargingCurrent)>>8)&0xff;//最高允许充电电流 精度0.1 偏移量-400
BMS_CanTxData.Data[5] = BMSDefaultParameters.BCP.NominalTotalEnergy&0xff;
BMS_CanTxData.Data[6] = (BMSDefaultParameters.BCP.NominalTotalEnergy>>8)&0xff; //动力蓄电池标称总能量 精度0.1
BMS_CanTxData.Data[7] = BMSDefaultParameters.BCP.MaxTotalChargingVoltage&0xff;
can_write(&BMS_CanTxData);
//延时 10ms 50 00 f4 01 64 19 00
Delay_MS(WAIT_TIME_MS);
BMS_CanTxData.Data[0] = 0x02;
BMS_CanTxData.Data[1] =(BMSDefaultParameters.BCP.MaxTotalChargingVoltage>>8)&0xff; //最高允许充电总电压
BMS_CanTxData.Data[2] = BMSDefaultParameters.BCP.MaxTemperature+10; //动力蓄电池最高温度110 -50 = 60°C 偏移量-50
BMS_CanTxData.Data[3] = GetBCP_ChargeState()&0xff;
BMS_CanTxData.Data[4] = (GetBCP_ChargeState()>>8)&0xff; //整车Soc状态 精度0.1
BMS_CanTxData.Data[5] = BMSDefaultParameters.BCP.CurrentVoltage&0xff ;
BMS_CanTxData.Data[6] = (BMSDefaultParameters.BCP.CurrentVoltage >>8)&0xff;//整车动力蓄电池当前电压300v
BMS_CanTxData.Data[7] = 0x00;
can_write(&BMS_CanTxData);
}
}
// 电池准备就绪状态 BRO
//0x0--BMS不能辨识 0xaa--BMS能辨识
void bms_SendBRO(uint8_t Ready)
{
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBROID;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 1;
memset(BMS_CanTxData.Data, 0xff, 8);
BMS_CanTxData.Data[0] = Ready;
can_write(&BMS_CanTxData);
}
//电池充电需求 BCL
void bms_SendBCL(void)
{
uint16_t fTotalBatVol ,fTotalBatCur;
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBCLID;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 5;
memset(BMS_CanTxData.Data, 0xff, 8);
/* 电池充电需求 BCL 需求电压:0xfa0 =4000=400V
需求电流:0xf46 充电模式:02 恒流充电*/
if(Err_Read(51) || Err_Read(52))
{
fTotalBatVol = BMSDefaultParameters.BCL.VoltageDemand;
fTotalBatCur = 4000-(BMSDefaultParameters.BCL.CurrentDemand*0.8);
}
else
{
fTotalBatVol = BMSDefaultParameters.BCL.VoltageDemand;
fTotalBatCur = (4000-BMSDefaultParameters.BCL.CurrentDemand);
}
// Bms_BatChargeRealInfo.uChargeMode = 2 ; //2恒流 1--恒压
BMS_CanTxData.Data[0] = (fTotalBatVol)&0xff;
BMS_CanTxData.Data[1] = (fTotalBatVol>>8)&0xff; //电压需求 精度0.1
BMS_CanTxData.Data[2] = (fTotalBatCur)&0xff;
BMS_CanTxData.Data[3] = (fTotalBatCur>>8)&0xff; //电流需求 精度0.1 偏移量-400
BMS_CanTxData.Data[4] = BMSDefaultParameters.BCL.Mode?2:1;//充电模式 0x1:恒压 0x2:恒流
can_write(&BMS_CanTxData);
}
//bms 发送报文 电池总状态 BCS
void bms_SendBCS(uint16_t step)
{
if(step == 1)
{
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBRMID1;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 8;
memset(BMS_CanTxData.Data, 0xff, 8);
BMS_CanTxData.Data[0] = 0x10;
BMS_CanTxData.Data[1] = 0x09;
BMS_CanTxData.Data[2] = 0x00;
BMS_CanTxData.Data[3] = 0x02;
BMS_CanTxData.Data[4] = 0xff;
BMS_CanTxData.Data[5] = 0x00;
BMS_CanTxData.Data[6] = 0x11;
BMS_CanTxData.Data[7] = 0x00;
can_write(&BMS_CanTxData);
}
else if(step == 2)
{
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBRMID2;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 8;
memset(BMS_CanTxData.Data, 0xff, 8);
/*充电电压测量值:0x139e =5022 电流测量值:0x
fa0 = 4000 =400A(偏移-400A) 荷电状态: 32%
估算剩余时间 0x0050 分钟*/
BMS_CanTxData.Data[0] = 0x01;
//1-12位:最高单体电压 精度0.01
//13~16位:最高单体电压所在序号0~15
//Bms_BatChargeRealInfo.nBayMaxVolInfo =((1<<12) |( Bms_BatConfigParam.BatMaxChargeVol-100));
//BMSDefaultParameters.BCS.MaxSingleCellVoltage.value =((1<<12) |( BMSDefaultParameters.BCS.MaxSingleCellVoltage.value-100));
BMS_CanTxData.Data[1] = BMSDefaultParameters.BCS.ChargingVoltage&0xff;
BMS_CanTxData.Data[2] = (BMSDefaultParameters.BCS.ChargingVoltage>>8)&0xff; //充电电压测量值
BMS_CanTxData.Data[3] = BMSDefaultParameters.BCS.ChargingCurrent&0xff;
BMS_CanTxData.Data[4] = (BMSDefaultParameters.BCS.ChargingCurrent>>8)&0xff;//充电电流测量值
BMS_CanTxData.Data[5] = BMSDefaultParameters.BCS.MaxSingleCellVoltage.value&0xff;
BMS_CanTxData.Data[6] = (BMSDefaultParameters.BCS.MaxSingleCellVoltage.value>>8)&0xff;
BMS_CanTxData.Data[7] = BMSDefaultParameters.uBatCurSOC; //当前SOC状态
can_write(&BMS_CanTxData);
Delay_MS(WAIT_TIME_MS);
//延时 10ms 50 00 f4 01 64 19 00
// BMSDefaultParameters.BCS.RemainingChargeTime = 100 - BMSDefaultParameters.uBatCurSOC;
BMS_CanTxData.Data[0] = 0x02;
BMS_CanTxData.Data[1] = BMSDefaultParameters.BCS.RemainingChargeTime&0xff;
BMS_CanTxData.Data[2] = (BMSDefaultParameters.BCS.RemainingChargeTime>>8)&0xff; //估算剩余充电时间
BMS_CanTxData.Data[3] = 0;
BMS_CanTxData.Data[4] = 0;
BMS_CanTxData.Data[5] = 0;
BMS_CanTxData.Data[6] = 0;
BMS_CanTxData.Data[7] = 0;
can_write(&BMS_CanTxData);
}
}
//bms 发送报文 动力蓄电池 状态 BSM
void bms_SendBSM(uint16_t step)
{
uint8_t BatMaxVoltNum = 0; //电池最高电压编号
uint8_t BatMaxtemp = 0; //电池最高温度
uint8_t BatMaxTempNum = 0; //电池最高温度编号
int8_t BatMintemp = 0; //电池最低温度
int8_t BatMintempNum = 0; //电池最低温度编号
int8_t BMS_Insulation_Fault; //动力蓄电池绝缘状态
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBSMID;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 7;
memset(BMS_CanTxData.Data, 0xff, 8);
if(SysParaPileD.SocSimulaType == 1)
{
BatMaxVoltNum = 0x05; //电池最高电压编号
BatMaxtemp = 0x4B; //电池最高温度 (偏移量-50°C所以加50
BatMaxTempNum = 0x04; //电池最高温度编号
BatMintemp = 0x4A; //电池最低温度 (偏移量-50°C所以加50
BatMintempNum = 0x03; //电池最低温度编号
}
else
{
BatMaxVoltNum = 0x05; //电池最高电压编号 5号
BatMaxtemp = 0x4B; //电池最高温度 75-50 = 25°C (偏移量-50°C所以加50
BatMaxTempNum = 0x04; //电池最高温度编号 4号
BatMintemp = 0x4A; //电池最低温度 74-50 = 24°C (偏移量-50°C所以加50
BatMintempNum = 0x03; //电池最低温度编号 3号
}
//6.0~6.1位:单体蓄电池电压过高/过低 00:正常 01:过高 10:过低
//6.2~6.3位:电池SOC状态过高/过低 00:正常 01:过高 10:过低
//6.4~6.5位:单体蓄电池充电过流 00:正常 01:过流 10:不可信
//6.6~6.7位:单体蓄电池温度过高 00:正常 01:过高 10:不可信
//7.0~7.1位:动力蓄电池绝缘状态 00:正常 01:过高 10:过低
//7.2~7.3位:动力蓄电池输出连接器连接状态 00:正常 01:过高 10:过低
//7.4~7.5位:充电允许 00:禁止 01:允许
if(Err_Read(43) || Err_Read(44))//单体蓄电池电压过高/过低
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.high_low_voltage_status = 0x1;
else
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.high_low_voltage_status = 0x0;
if(Err_Read(45) || Err_Read(12))//电池SOC状态过高/过低
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.high_low_SOC_status = 0x1;
else
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.high_low_SOC_status = 0x0;
if(Err_Read(46))//单体蓄电池充电过流
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.charging_overcurrent_status = 0x1;
else
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.charging_overcurrent_status = 0x0;
if(Err_Read(11))//单体蓄电池温度过高
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.high_temperature_status = 0x1;
else
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.high_temperature_status = 0x0;
if(Err_Read(14) || Err_Read(26))//动力蓄电池绝缘状态
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.insulation_status = 0x1;
else
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.insulation_status = 0x0;
if(GetBSM_output_connector_status() == true)//动力蓄电池输出连接器连接状态
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.output_connector_status = 0x1;
else
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.output_connector_status = 0x0;
if(GetBSM_charging_permission() == true)//充电允许
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.charging_permission = 0x1;
else
BMSDefaultParameters.BSM.BSM_DATA_FAULT.bits.charging_permission = 0x0;
BMS_CanTxData.Data[0] = GetBSM_highest_cell_voltage_number(); //最高单体蓄电池电压所在编号
BMS_CanTxData.Data[1] = GetBSM_highest_battery_temperature()+10; //最高动力蓄电池温度
BMS_CanTxData.Data[2] = GetBSM_highest_temperature_detection_point(); //最高温度编号
BMS_CanTxData.Data[3] = GetBSM_lowest_battery_temperature()+10; //最低动力蓄电池温度
BMS_CanTxData.Data[4] = GetBSM_lowest_temperature_detection_point(); //最低温度编号
BMS_CanTxData.Data[5] = BMSDefaultParameters.BSM.BSM_DATA_FAULT.stats[0]; //未使用
BMS_CanTxData.Data[6] = BMSDefaultParameters.BSM.BSM_DATA_FAULT.stats[1]; //充电允许
can_write(&BMS_CanTxData);
}
//bms 发送报文 中止充电报文 BST
void bms_SendBST(uint16_t step)
{
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBSTID;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 4;
//memset(BMS_CanTxData.Data, 0xff, 8);
//bms中止原因
//1.1~1.2位:达到所需求的SOC 00:未达到 01:达到 10:不可信
//3.3~3.4位:达到总电压设定值 00:未达到 01:达到 10:不可信
//3.5~3.6位:达到单体电压设定值 00:未达到 01:达到 10:不可信
//3.7~3.8位:充电桩主动终止 00:正常 01:充电桩终止(收到CST帧) 10:不可信
//达到SOC设定值
if(BMSDefaultParameters.uBatCurSOC == 100)
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.SOC_Target = 0x1;
else
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.SOC_Target = 0x0;
// //达到单体电压设定值
// if(stopChargeReason == 30)
// Bms_AbortReason |= 0x10;
// else
// Bms_AbortReason |= 0x00;
//充电桩主动终止
if(Err_Read(47) == true)
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.Charging_pile_stops_actively = 0x1;
else
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.Charging_pile_stops_actively = 0x0;
/*********************************bms中止故障原因
//2.1~2.2位:绝缘故障 00:正常 01:故障 10:不可信 0x01
//2.3~2.4位:输出连接器过温 00:正常 01:故障 10:不可信 0x04
//2.5~2.6位:bms元件、输出连接过温 00:正常 01:故障 10:不可信 0x10
//2.7~2.8位:充电连接器故障 00:正常 01:故障 10:不可信 0x40
//3.1~3.2位:电池组温度过高故障 00:正常 01:故障 10:不可信 0x100
//3.3~3.4位:高压续电器故障 00:正常 01:故障 10:不可信 0x400
//3.5~3.6位:检测点2电压检测故障 00:正常 01:故障 10:不可信 0x1000
//3.7~3.8位:其他故障 00:正常 01:故障 10:不可信 0x4000
********************************************************************/
if(Err_Read(26) == true || Err_Read(14) == true)//绝缘故障
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.Fault_insulation = 0x1;
else
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.Fault_insulation = 0x0;
if(Err_Read(11) == true)//电池组温度过高故障
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.High_temperature_fault_battery_pack = 0x1;
else
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.High_temperature_fault_battery_pack = 0x0;
if(Err_Read(3) == true || Err_Read(4) == true)//高压继电器故障
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.Fault_high_voltage_relay = 0x1;
else
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.Fault_high_voltage_relay = 0x0;
//bms中止充电错误原因
//4.1~4.2:电流过大 00:正常 01:超过需求值 10:不可信 0x01
//4.3~4.4:电压异常 00:正常 01:电压异常 10:不可信 0x04
if(Err_Read(46) == true)
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.Excessive_current = 0x1;
else
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.Excessive_current = 0x0;
if(Err_Read(1) == true /*|| Err_Read(2) == true*/)
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.Abnormal_voltage = 0x1;
else
BMSDefaultParameters.BST.BST_DATA_FAULT.bits.Abnormal_voltage = 0x0;
BMS_CanTxData.Data[0] = BMSDefaultParameters.BST.BST_DATA_FAULT.stats[0];
BMS_CanTxData.Data[1] = BMSDefaultParameters.BST.BST_DATA_FAULT.stats[1];
BMS_CanTxData.Data[2] = BMSDefaultParameters.BST.BST_DATA_FAULT.stats[2];
BMS_CanTxData.Data[3] = BMSDefaultParameters.BST.BST_DATA_FAULT.stats[3];
can_write(&BMS_CanTxData);
}
//bms 发送报文 BMS统计报文 BSD
void bms_SendBSD(uint16_t step)
{
static uint16_t BattCellMaxVolt,BattCellMinVolt; //蓄电池单体最高电压 蓄电池单体最低电压
static uint16_t BattCellMaxTemp, BattCellMinTemp; //蓄电池单体最高温度 蓄电池单体最低温度
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBSDID;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 7;
memset(BMS_CanTxData.Data, 0xff, 8);
BMS_CanTxData.Data[0] = BMSDefaultParameters.uBatCurSOC; //中止soc
BMS_CanTxData.Data[1] = GetBSDmin_cell_voltage()&0xff;
BMS_CanTxData.Data[2] = (GetBSDmin_cell_voltage()>>8)&0xff; //动力蓄电池单体最低电压 精度0.01 0x044c = 1100*0.01 = 11v
BMS_CanTxData.Data[3] = GetBSDmax_cell_voltage()&0xff;
BMS_CanTxData.Data[4] = (GetBSDmax_cell_voltage()>>8)&0xff; //动力蓄电池单体最高电压 精度0.01 0x04b0 = 1200*0.01 = 12v
BMS_CanTxData.Data[5] = GetBSDmin_battery_temperature(); //动力蓄电池最低温度 偏移量-50 0x64 = 100-50 = 50°C
BMS_CanTxData.Data[6] = GetBSDmax_battery_temperature(); //动力蓄电池最高温度 偏移量-50 0x65 = 101-50 = 51°C
can_write(&BMS_CanTxData);
}
//bms 发送报文 BMS错误报文 BEM
void bms_SendBEM(uint16_t step)
{
BMS_CanTxData.StdId = 0;
BMS_CanTxData.ExtId = CanBEMID;
BMS_CanTxData.IDE = CAN_ID_EXT;
BMS_CanTxData.RTR = CAN_RTR_DATA;
BMS_CanTxData.DLC = 4;
memset(BMS_CanTxData.Data, 0xff, 8);
//1.1~1.2位:充电桩辨识报文超时(0x00) 0x00:正常 0x01:超时 0x10:不可信
//1.3~1.4位:充电桩辨识报文超时(0xaa) 0x00:正常 0x01:超时 0x10:不可信
//2.1~2.2位:接受充电桩时间同步和最多输出能力超时(CTS/CMN) 0x00:正常 0x01:超时 0x10:不可信
//2.3~2.4位:接收充电桩完成准备超时(CRO) 0x00:正常 0x01:超时 0x10:不可信
//3.1~3.2位:接收充电桩充电状态报文超时(CCS) 0x00:正常 0x01:超时 0x10:不可信
//3.3~3.4位:接收充电桩中止充电报文超时(CST) 0x00:正常 0x01:超时 0x10:不可信
//4.1~4.2位:接收充电桩统计报文超时(CSD) 0x00:正常 0x01:超时 0x10:不可信
BMS_CanTxData.Data[0] = 0x00;
BMS_CanTxData.Data[1] = 0x00;
BMS_CanTxData.Data[2] = 0x00;
BMS_CanTxData.Data[3] = 0x00;
can_write(&BMS_CanTxData);
}
//===========================OBD BMS 各个报文解析 ====================================
wulingbat_info_t WuLingBatteryInfo;
static int8_t ParseBMS100(CanRxMsg *pData)//解析老化ID0x100数据
{
if(pData->Data[0]==1)
{
WuLingBatteryInfo.Long_TEST = 1;//老化标志位
}
return TRUE;
}
CanRxMsg testBMSCAN2Msg;
CanTxMsg testBMSCAN2MsgTx;
extern uint8_t NetworkManageFrameFlag;
static uint32_t NetworkManageFrameFlagTimer = 0; /* 记录最后接收到网络管理帧 的tick */
static uint32_t NetworkLocalWakingTimer = 0; /* 记录本地唤醒条件维持的tick */
void CheckNetworkManageFrameFlagTimeout(void)
{
// if (ChkPwrManageAccoff()!=0)
// {
// TickOut(&NetworkLocalWakingTimer, 0); /* 当前本地唤醒有效更新tick记录 */
// }
// if (NetworkManageFrameFlagTimer == 0) /* 如果NetworkManageFrameFlagTimer=0 表示刚初始化,或者唤醒后未接收到管理帧,但唤醒后本身会发送一包管理帧,所以从这里开始计时 */
// { /* 注意这里与实际发送的管理帧的tick可能有出入好在10%的误差比较大,应该能满足,不能满足考虑这里 */
// TickOut(&NetworkManageFrameFlagTimer, 0);
// }
// else if (TickOut(&NetworkManageFrameFlagTimer, 1200))
// {
// NetworkManageFrameFlag = 0; /* 这里清NetworkManageFrameFlag 主要是为了,与之前的逻辑相一致 */
// }
// #if 0
// if(TickOut(&NetworkManageFrameFlagTimer, 1200) == TRUE) // 5s ?
// {
// NetworkManageFrameFlag = 0;
// TickOut(&NetworkManageFrameFlagTimer, 0);
// }
// #endif
}
/**
* @brief: 用来返回 当前是否可以发送网络数据帧
*
* @return TRUE: 可以发送FALSE不可以发送
*/
static __inline bool NetWorkAppDateSending(void)
{
//判断是否有A+ ACC 与can网络唤醒没有3s停止
if (TickOut(&NetworkManageFrameFlagTimer, 3000) == TRUE && TickOut(&NetworkLocalWakingTimer, 3000) == TRUE)
{
return FALSE;
}
return TRUE;
}
/*********************************************************************************
函数名称bms2_parseData
功能描述:判断是否需要的报文去解析
输 入Ch CAN 通道 (0/1)
输 出:无
返 回 值:无
*********************************************************************************/
int bms_RcvCan2DataProc(CanRxMsg pCanRxData)
{
static CanRxMsg SingleCanRxData = {0};
uint32_t SingleId;
SingleCanRxData = pCanRxData;
SingleId = SingleCanRxData.StdId;
//网络管理帧的接收判断
// if(
// ( )||(SingleId == CANBMS600INFOID_WULING)||
// (SingleId == CANBMS605INFOID_WULING)||(SingleId == CANBMS614INFOID_WULING)||
// (SingleId == CANBMS62AINFOID_WULING)||(SingleId == CANBMS651INFOID_WULING)||
// (SingleId == CANBMS653INFOID_WULING)||(SingleId == CANBMS652INFOID_WULING)||
// (SingleId == CANBMS654INFOID_WULING)||(SingleId == CANBMS686INFOID_WULING))
// {
// NetworkManageFrameFlag = 1;
// TickOut(&NetworkManageFrameFlagTimer, 0);
// }
testBMSCAN2Msg = SingleCanRxData;
GPIO_SetBits(GPIOC,GPIO_Pin_7); //1043 ENable
REV_CanData.CarMessage(&SingleCanRxData); //解析can数据
memset( &SingleCanRxData,0,sizeof(CanRxMsg));
SingleCanRxData.StdId =0;
return 0;
}
/*******************************************************模拟VIN码********************************/
int VinCalc(char *Vin,char *reslt)
{
unsigned int i = 0;
unsigned int sum =0;
unsigned int check = 0;
char temp=0;
unsigned int j = 0;
const char jianquan[26][2] = {
{'A',1},{'B',2},{'C',3},{'D',4},{'E',5},{'F',6},
{'G',7},{'H',8},{'I',0},{'J',1},{'K',2},{'L',3},
{'M',4},{'N',5},{'O',0},{'P',7},{'Q',8},{'R',9},
{'S',2},{'T',3},{'U',4},{'V',5},{'W',6},{'X',7},
{'Y',8},{'Z',9}};
char pos[17]={8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2};
for(i=0;i<17;i++)
{
if(Vin[i]>='a'&&Vin[i]<='z')
{
temp = Vin[i]-0x20;
}
else if((Vin[i]>='A')&&(Vin[i]<='Z'))
{
temp = Vin[i];
}
else if((Vin[i]>='0')&&(Vin[i]<='9'))temp = Vin[i]-'0';
else return GD_ERR;
if((temp>='A')&&(temp<='Z'))
{
for(j=0;j<26;j++)
{
if(temp == jianquan[j][0])
temp = jianquan[j][1];
}
}
check += temp*pos[i];
}
*reslt = check%11;
return GD_OK;
}
extern u32 ChipUniqueID[3];
char VinTest(void)
{
char check = 0;
vin_byte_t vin_code;
char* Vin=SysParaPileD.VehichleInfo;//"LK6ADCE15LB408569";
vin_code.data = ChipUniqueID[2] >>16&0xff;
SysParaPileD.VehichleInfo[11] = vin_code.bits.vode_h >0x0A? vin_code.bits.vode_h-0x0A+0x30:vin_code.bits.vode_h +0x30;
SysParaPileD.VehichleInfo[12] = vin_code.bits.vode_l >0x0A? vin_code.bits.vode_l -0x0A+0x30:vin_code.bits.vode_l +0x30;;
vin_code.data = ChipUniqueID[2] >>8&0xff;
SysParaPileD.VehichleInfo[13] = vin_code.bits.vode_h >0x0A? vin_code.bits.vode_h-0x0A+0x30:vin_code.bits.vode_h +0x30;
SysParaPileD.VehichleInfo[14] = vin_code.bits.vode_l >0x0A? vin_code.bits.vode_l -0x0A+0x30:vin_code.bits.vode_l +0x30;;
vin_code.data = ChipUniqueID[2]&0xff;
SysParaPileD.VehichleInfo[15] = vin_code.bits.vode_h >0x0A? vin_code.bits.vode_h-0x0A+0x30:vin_code.bits.vode_h +0x30;
SysParaPileD.VehichleInfo[16] = vin_code.bits.vode_l >0x0A? vin_code.bits.vode_l -0x0A+0x30:vin_code.bits.vode_l +0x30;;
// VinCalc((char*)&SysParaPileD.VehichleInfo[0],&check);
// data = VinTest();
VinCalc(Vin,&check);
SysParaPileD.VehichleInfo[8] = check +0x30;
SysParaPileD.device_type = 0;
// char* Vin="LFV2A21K657355844";
return check;
}
char VinTest2(void)
{
char check = 0;
char VehichleInfo[17] = {"LK6ADCE19LB355844"};
vin_byte_t vin_code;
char* Vin= VehichleInfo;//"LK6ADCE15LB408569";
// data = VinTest();
VinCalc(Vin,&check);
VehichleInfo[8] = check +0x30;
SysParaPileD.device_type = 0;
return check;
}
/******************************************can2数据发送***************************************/
int8_t FDC_General_Status_5(void)
{
static u8 statsdata[8] = {0};
static u8 stats[8] = {0};
BMS_Can2TxData.StdId = 0x38A;
BMS_Can2TxData.ExtId = 0;
BMS_Can2TxData.IDE = CAN_ID_STD;
BMS_Can2TxData.RTR = CAN_RTR_DATA;
BMS_Can2TxData.DLC = 8; //长度
stats[0] = 1;
stats[1] = 1;
stats[2] = 1;
memcpy(statsdata, &stats[0], 8);
memcpy(BMS_Can2TxData.Data, statsdata, 8);
can_write2(&BMS_Can2TxData);
return TRUE;
}
extern bool can_sent_cycle_timeout(unsigned int frame_id);
static uint8_t DCDCSendBms2State = 1;
void WULING_DCDCSendBms2_force(void)
{
DCDCSendBms2State = 1;
}
int8_t WULING_DCDCSendBms2(void)
{
uint32_t tmp;
static uint16_t index = 0,index2,index3,index4 = 0;
static uint32_t timerout = 0;
static uint32_t timer = 0;
static uint32_t timer2 = 0;
static uint32_t timer3 = 0;
CheckNetworkManageFrameFlagTimeout();
if(DCDCSendBms2State ==1)
{
if(TickOutCycle(&timer, 10) == TRUE) // 100ms
{
index=0;
DCDCSendBms2State = 2;
}
}
else if(DCDCSendBms2State ==2)
{
// if(ChkPwrManageAccoff()!=0 || ChkNetworkManageoff() !=0)//满足物理唤醒条件
// {
// timerout =0;
// }
// else
// {
// if(timerout < 10000) //1s
// {
// if(TickOutCycle(&timer3, 10) == TRUE) // 100ms
// {
// timerout++;
// }
// }
// }
if(TickOutCycle(&timer,5)== TRUE) // 100ms/20= 5
{
//100ms 周期
if(index3++%4==0)
{
index++;
if(NetWorkAppDateSending() == TRUE)
{
FDC_General_Status_5();
}
}
}
}
return TRUE;
}