/*
 * CanVar.c
 *
 *  Created on: 2021年12月27日
 *  编码
 *      Author: QiXiang_CHENJIE
 */
#include "CanVar.h"
UINT32 BcuInTable[28] = {
	0x1801D0F3,
	0x1801D8F3,
	0x1880D0F3,
	0x1881D0F3,
	0x1882D0F3,
	0x1883D0F3,
	0x1884D0F3,
	0x1885D0F3,
	0x1886D0F3,
	0x1887D0F3,
	0x1888D0F3,
	0x1889D0F3,
	0x188AD0F3,
	0x18C1D0F3,
	0x18C2D0F3,
	0x18E1D0F3,
	0x18E2D0F3,
	0x18E3D0F3,
	0x18E4D0F3,
	0x18E5D0F3,
	0x18E6D0F3,
	0x18F1D0F3,
	0x18F2D0F3,
	0x18F3D0F3,
	0x18F4D0F3,
	0x18F5D0F3,
	0x18FF45F4,
	0x18FFC13A,
};

BOOL BcuRxShortError[28];
BOOL BcuRxLongError[28];
UINT8 BcuRxErrorCounter[28];
UINT8 BcuRxFlag[28];
/************************************************************
 *BCU->Ebc解码变量存放区
 ************************************************************/
UINT8 BMS_ReqVIN = 0x00;					  //是否请求VIN码,0:预留;1:请求VIN;2:不请求VIN;3:无效;,Re-1,Off-0,
UINT8 BMS_ReqHVOff = 0x00;					  //是否请求下高压,0:预留;1:请求下高压;2:不请求下高压;3:无效;,Re-1,Off-0,
UINT8 BMS_ProtocolEditionH = 0x00;			  //通讯协议版本高位(例 : 版本为3 .1, 则此处发3),	, Re - 1, Off - 0,
UINT8 BMS_ProtocolEditionL = 0x00;			  //通讯协议版本低位(例 : 版本为3 .1, 则此处发1),	, Re - 1, Off - 0,
UINT8 BMS_CharDevNum = 0x00;				  //可充电装置系统序号(BMS是整车中可充电装置系统中的第几个, 需要整车告知),1,Re-1,Off-0,
UINT8 BMS_FtPosRly = 0x00;					  //主正继电器粘连故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtNegRly = 0x00;					  //主负继电器粘连故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtPosCharRly1 = 0x00;				  //充正1继电器粘连故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtNegCharRly1 = 0x00;				  //充负1继电器粘连故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtPosCharRly2 = 0x00;				  //充正2继电器粘连故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtNegCharRly2 = 0x00;				  //充负2继电器粘连故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtHeatRly1 = 0x00;				  //加热1/正继电器粘连故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtHeatRly2 = 0x00;				  //加热2/负继电器粘连故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_StPosRly = 0x00;					  //主正继电器状态(如继电器状态由BMS检测),0:预留;1:开启;2:闭合;3:无效;,Re-1,Off-0,
UINT8 BMS_StNegRly = 0x00;					  //主负继电器状态(如继电器状态由BMS检测),0:预留;1:开启;2:闭合;3:无效;,Re-1,Off-0,
UINT8 BMS_StPreCharRly = 0x00;				  //预充继电器状态,0:预留;1:开启;2:闭合;3:无效;,Re-1,Off-0,
UINT8 BMS_StPosCharRly1 = 0x00;				  //直流充正继电器1状态,0:预留;1:开启;2:闭合;3:无效;,Re-1,Off-0,
UINT8 BMS_StNegCharRly1 = 0x00;				  //直流充负继电器1状态,0:预留;1:开启;2:闭合;3:无效;,Re-1,Off-0,
UINT8 BMS_StPosCharRly2 = 0x00;				  //直流充正继电器2状态,0:预留;1:开启;2:闭合;3:无效;,Re-1,Off-0,
UINT8 BMS_StNegCharRly2 = 0x00;				  //直流充负继电器2状态,0:预留;1:开启;2:闭合;3:无效;,Re-1,Off-0,
UINT8 BMS_FtAuxRelayWeld = 0x00;			  //附件继电器粘连故障(保留),0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_BraOpenCirc = 0x00;				  //支路断路故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtBackCharCurrOutLim = 0x00;		  //回充电流超限报警,0:正常1 : 1级 轻微故障 2 : 2级 较严重故障 3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtPosRlyOpen = 0x00;				  //主正继电器无法闭合报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtNegRlyOpen = 0x00;				  //主负继电器无法闭合报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtPosCharRly1Open = 0x00;			  //直流充电正1继电器无法闭合报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtPosCharRly2Open = 0x00;			  //直流充电正2继电器无法闭合报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtNegCharRly1Open = 0x00;			  //直流充电负1继电器无法闭合报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtNegCharRly2Open = 0x00;			  //直流充电负2继电器无法闭合报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtTMSContClose = 0x00;			  //加热膜或TMS接触器无法断开报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtTMSContOpen = 0x00;				  //加热膜或TMS接触器无法闭合报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtTMS = 0x00;						  //热管理系统故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_Ft24VSpy = 0x00;					  // BMS 24V供电异常报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtPACKSelfProt = 0x00;			  //电池包自保护报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtCharSockTempOver = 0x00;		  //充电插座过温报警,0:正常1 : 1级 轻微故障 2 : 2级 较严重故障 3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtTempOutCtrl = 0x00;				  //热失控报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_StPosHeatRly = 0x00;				  //加热正继电器状态,0:保留;1:开启;2:闭合;3:无效,Re-1,Off-0,
UINT8 BMS_StNegHeatRly = 0x00;				  //加热负继电器状态,0:保留;1:开启;2:闭合;3:无效,Re-1,Off-0,
UINT8 BMS_CharSysNum = 0x00;				  //可充电储能子系统总数(保留),,Re-1,Off-0,
UINT8 BMS_FtCode = 0x00;					  //电池系统故障码,详见附表电池系统故障码列表,Re-1,Off-0,
UINT8 BMS_ST1CheckSum = 0x00;				  // B2V_ST1的CheckSum,Byte0=Byte1 XOR Byte2 XOR Byte3 XOR Byte4 XOR Byte5 XOR Byte6 XOR Byte7,Re-1,Off-0,
UINT8 BMS_ST1Counter = 0x00;				  // B2V_ST1的生命信号,0~14循环,15:信号无效,Re-1,Off-0,
UINT8 BMS_Mode = 0x00;						  // BMS当前状态,0:预留;1:高压上电;2:高压下电;3:无效;,Re-1,Off-0,
UINT8 BMS_AuxRlySt = 0x00;					  //附件继电器状态,0:开启;1:闭合;,Re-1,Off-0,
UINT8 BMS_BattBalaSt = 0x00;				  // BMS当前均衡状态,0:未开启均衡;1:开启均衡;,Re-1,Off-0,
UINT8 BMS_CharGunSt = 0x00;					  //直流充电枪连接状态,0:未连接1 : 连接, Re - 1, Off - 0,
UINT8 BMS_CharMode = 0x00;					  // BMS当前充电模式,0:预留1 : 直流充电 2 : 交流充电 3 : 其他充电, Re - 1, Off - 0,
UINT8 BMS_CharSt = 0x00;					  //充电状态,0:可以充电1 : 正在充电 2 : 充电结束 3 : 充电故障, Re - 1, Off - 0,
UINT8 BMS_FtLvl = 0x00;						  //当前最高故障等级,0:正常1 : 1级 轻微故障 2 : 2级 较严重故障 3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtCellTempDiff = 0x00;			  //电芯温差异常报警,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtCellTempHigh = 0x00;			  //电芯温度过高报警,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtPACKOverVolt = 0x00;			  // PACK过压报警,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtPACKUndeVolt = 0x00;			  // PACK欠压报警,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtSOCLow = 0x00;					  // SOC过低报警,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtCellOverVolt = 0x00;			  //单体电压过高报警,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtCellUndeVolt = 0x00;			  //单体电压欠压报警,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtIns = 0x00;						  //绝缘报警,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtCellOverVoltDiff = 0x00;		  //单体压差过大,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtCharCurrOver = 0x00;			  //充电电流过大报警,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtDisCharCurrOver = 0x00;			  //放电电流过大报警,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtCellTempLow = 0x00;				  //电芯温度过低报警,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtBranVoltDifOver = 0x00;			  //支路压差过大报警(存在并联支路的系统),0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtBMSHardWare = 0x00;				  // BMS硬件故障,0:无故障; 1:1级 轻微故障; 2:2级 较严重故障3 : 3级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtSOCHigh = 0x00;					  // SOC过高报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtSOCJump = 0x00;					  // SOC跳变报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtInCom = 0x00;					  // BMS内部通信故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtSysMism = 0x00;					  // BMS/可充电储能系统不匹配报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtHvIntLock = 0x00;				  //高压互锁报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtSmoke = 0x00;					  //火警探测器故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtFire = 0x00;					  //电池包火灾报警,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtNum = 0x00;						  // BMS当前发生的故障总数目(包括GB32960中规定的故障数目),,Re-1,Off-0,
UINT8 BMS_PackSOC = 0x00;					  //电池包SOC,,Re-0.4,Off-0,
UINT8 BMS_PackSOH = 0x00;					  //电池包SOH,,Re-0.4,Off-0,
UINT8 BMS_MaxCellTemp = 0x00;				  //单体最高温度,,Re-1,Off--50,℃
UINT8 BMS_MinCellTemp = 0x00;				  //单体最低温度,,Re-1,Off--50,℃
UINT8 BMS_AverCellTemp = 0x00;				  //单体平均温度,,Re-1,Off--50,℃
UINT8 BMS_MaxCellTempCSC = 0x00;			  //最高温度电芯所在子系统(CSC)编号,范围(1~255),Re-1,Off-0,
UINT8 BMS_MaxCellTempNum = 0x00;			  //最高温度电芯所在子系统(CSC)内温度探针编号,范围(1~255),Re-1,Off-0,
UINT8 BMS_MinCellTempCSC = 0x00;			  //最低温度电芯所在子系统(CSC)编号,范围(1~255),Re-1,Off-0,
UINT8 BMS_MinCellTempNum = 0x00;			  //最低温度电芯所在子系统(CSC)内温度探针编号,范围(1~255),Re-1,Off-0,
UINT8 BMS_MaxCellVoltCSC = 0x00;			  //最高电压电芯所在子系统(CSC)编号,范围(1~255),Re-1,Off-0,
UINT8 BMS_MaxCellVoltNum = 0x00;			  //最高电压电芯所在子系统(CSC)内单体编号,范围(1~255),Re-1,Off-0,
UINT8 BMS_MinCellVoltCSC = 0x00;			  //最低电压电芯所在子系统(CSC)编号,范围(1~255),Re-1,Off-0,
UINT8 BMS_MinCellVoltNum = 0x00;			  //最低电压电芯所在子系统(CSC)内单体编号,范围(1~255),Re-1,Off-0,
UINT8 BMS_InsDeteSt = 0x00;					  // BMS绝缘检测状态,0:停止检测;1:激活检测;,Re-1,Off-0,
UINT8 BMS_FtCharInsLow = 0x00;				  //充电绝缘阻值低,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtCurrSenr = 0x00;				  //电流传感器故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtHeatingFilm = 0x00;				  //加热膜加热回路故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtMainLoopPreChar = 0x00;			  //主回路预充或预检故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtAuxLoopPreChar = 0x00;			  //辅件回路预充或预检故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtACANLost = 0x00;				  // ACAN/整车CAN通讯故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtDCDC = 0x00;					  // BMS-DC-DC故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtSOCDif = 0x00;					  // SOC差异过大,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtCellOverDisChar = 0x00;			  //电芯过放故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtCharOver = 0x00;				  //车载储能装置过充报警,0:正常;1:1级 轻微故障;2:2级 较严重故障3 : 10级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtContDisCharCurrOverLoad = 0x00;	  //持续回充过流故障,0:正常;1:1级 轻微故障;2:2级 较严重故障3 : 10级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_FtContCharCurrOverLoad = 0x00;	  //持续放电过流故障,0:正常;1:1级 轻微故障;2:2级 较严重故障3 : 10级 最严重故障, Re - 1, Off - 0,
UINT8 BMS_Gun1DCNegTemp = 0x00;				  //充电口1负温感值,,Re-1,Off--40,℃
UINT8 BMS_Gun1DCPosTemp = 0x00;				  //充电口1正温感值,,Re-1,Off--40,℃
UINT8 BMS_Gun2DCNegTemp = 0x00;				  //充电口2负温感值,,Re-1,Off--40,℃
UINT8 BMS_Gun2DCPosTemp = 0x00;				  //充电口2正温感值,,Re-1,Off--40,℃
UINT8 BMS_CurrHeatSt = 0x00;				  //当前加热状态,0:未加热;1:加热中;2:预留;3:无效;,Re-1,Off-0,
UINT8 BMS_CurrCoolSt = 0x00;				  //当前冷却状态,0:未冷却;1:冷却中;2:预留;3:无效;,Re-1,Off-0,
UINT8 BMS_FtCharCnct = 0x00;				  //插枪连接信号异常,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtOverDisCharCurrDuringChar = 0x00; //充电时放电电流过大,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtCharNTC = 0x00;					  //充电插座NTC故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_FtELock = 0x00;					  //电子锁故障,0:正常; 1:故障,Re-1,Off-0,
UINT8 BMS_CellVoltFramNum = 0x00;			  //单体电压帧序号,有效值1~255,Re-1,Off-0,
UINT8 BMS_CellTempFramNum = 0x00;			  //温度帧序号,有效值1~255,Re-1,Off-0,
UINT8 BMS_CSC_Code = 0x00;					  //子系统编号CSC,有效值1~255,Re-1,Off-0,
UINT8 BMS_CellTemp[64] = {0x00};			  //当前CSC下的第N个探针的温度,255 "Invalid" 0xFF 无效有效值 0 ~254, 单位 ℃, 范围(-50 ~204)℃, , Re - 1, Off-- 50,℃
UINT8 BMS_Checksum = 0x00;					  //电池编码信息1的CheckSum,Byte0=Byte1 XOR Byte2 XOR Byte3 XOR Byte4 XOR Byte5 XOR Byte6 XOR Byte7,Re-1,Off-0,
UINT8 BMS_PackComp = 0x00;					  //电池厂家,1:"CATL" 2:"Li Shen" 3:"MGL" 4:"SAMSUN" 5:"LG",Re-1,Off-0,
UINT8 BMS_BattCodeLeng = 0x00;				  //电池编码长度,0:Do not transmit this Code,Re-1,Off-0,
UINT8 BMS_SN[27] = {0x00};					  //电池编码(SN)字符1(ASCII),,Re-1,Off-0,
UINT8 BMS_BattType = 0x00;					  //电池类型,1:铅酸电池; 2:镍氢电池; 3:磷酸铁锂电池; 4:锰酸锂电池; 5:钴酸锂电池; 6:三元材料电池; 7:聚合物锂离子电池; 8:钛酸锂电池; 9:超级电容; 10~13:保留; 14:燃料电池;15:保留,Re-1,Off-0,
UINT8 BMS_CoolType = 0x00;					  //电池冷却方式,0:其他冷却方式1 : 自然冷却 2 : 风扇冷却 3 : 水冷却, Re - 1, Off - 0,
UINT8 BMS_CSC_Total = 0x00;					  //电池系统中CSC总的数目,,Re-1,Off-0,
UINT8 BMS_CellVoltLevel = 0x00;				  //单体平台电压(非实时变化的值),有效值0~5V;  255 "Signal Invalid" 0xFF 无效,Re-0.1,Off-0,V
UINT8 BMS_CellMinVolt = 0x00;				  //单体可用最低电压(非实时变化的值),有效值0~5V;  255 "Signal Invalid" 0xFF 无效,Re-0.1,Off-0,V
UINT8 BMS_CellMaxVolt = 0x00;				  //单体可用最高电压(非实时变化的值),有效值0~5V;  255 "Signal Invalid" 0xFF 无效,Re-0.1,Off-0,V
UINT8 BMS_HVBranNum = 0x00;					  //电池系统高压支路数,,Re-1,Off-0,
UINT8 BMS_SingleHVBranchCellNum = 0x00;		  //电池系统单支路电芯数,,Re-1,Off-0,
UINT8 BMS_ReqMode = 0x00;					  // BMS请求设定模式,0:关机模式1 : 制冷模式 2 : 制热模式 3 : 自循环模式, Re - 1, Off - 0,
UINT8 BMS_HVCmd = 0x00;						  //高压请求,0:请求上高压1 : 请求下高压, Re - 1, Off - 0,
UINT8 BMS_ChgSts = 0x00;					  //充电状态,0:非充电1 : 充电, Re - 1, Off - 0,
UINT8 BMS_HVRelaySts = 0x00;				  // BMS高压继电器状态,0:断开状态; 1:闭合状态; 2~3:无效,Re-1,Off-0,
UINT8 BMS_SetTemp = 0x00;					  //设定温度,,Re-1,Off--40,
UINT8 BMS_Life = 0x00;						  // BMS生命帧,,Re-1,Off-0,
UINT8 BMS_CRC = 0x00;						  // CRC校验值,,Re-1,Off-0,
UINT8 TMS_WorkStatus = 0x00;				  // TMS工作状态,0:关机模式1 : 制冷模式 2 : 制热模式 3 : 自循环模式, Re - 1, Off - 0,
UINT8 TMS_HVRelayST = 0x00;					  // TMS高压继电器状态,0:断开状态; 1:闭合状态; 2~3:无效,Re-1,Off-0,
UINT8 TMS_OutletTemp = 0x00;				  //出水温度(机组到电池),255:无效,Re-1,Off--40,
UINT8 TMS_InletTemp = 0x00;					  //回水温度(电池到机组),255:无效,Re-1,Off--40,
UINT8 TMS_ErrCode = 0x00;					  // TMS故障码,0:无故障; 出现 1 种以上循环发送,Re-1,Off-0,
UINT8 TMS_FaultLevel = 0x00;				  // TMS故障码等级,0:无效1 : 1级故障 2 : 2级故障 3 : 3级故障, Re - 1, Off - 0,
UINT16 BMS_SoftwareVersion = 0x00;			  //软件版本号:RyyyBzzz(R为软件版本、B为测试版本、正式版本不带B)  ,yyy:0~254,精度1,255:无效,不显示;zzz:0~254,精度1,255:无效,不显示;
UINT16 BMS_HardwareVersion = 0x00;			  //硬件版本号:VyyyBzzz(V为硬件版本、B为测试版本、正式版本不带B)  ,,Re-1,Off-0,
UINT16 BMS_PackCurr = 0x00;					  //电池包总电流,充电为负值,放电为正值,,Re-0.1,Off--1000,A
UINT16 BMS_MaxCharCurr = 0x00;				  //电池包最大回充电流,,Re-0.1,Off--1000,A
UINT16 BMS_MaxDisCharCurr = 0x00;			  //电池包最大放电电流,,Re-0.1,Off--1000,A
UINT16 BMS_PosIns = 0x00;					  //母线正对车体绝缘电阻,,Re-1,Off-0,KΩ
UINT16 BMS_NegIns = 0x00;					  //母线负对车体绝缘电阻,,Re-1,Off-0,KΩ
UINT16 BMS_BattVolt = 0x00;					  //电池包内侧电压,,Re-0.1,Off-0,V
UINT16 BMS_LinkVolt = 0x00;					  //电池包外侧电压,,Re-0.1,Off-0,V
UINT16 BMS_MaxCellVolt = 0x00;				  //单体最高电压值,,Re-0.001,Off-0,V
UINT16 BMS_AverCellVolt = 0x00;				  //电芯电压平均值,,Re-0.001,Off-0,V
UINT16 BMS_MinCellVolt = 0x00;				  //电芯最低电压值,,Re-0.001,Off-0,V
UINT16 BMS_ContChrgCurr = 0x00;				  // BMS允许的持续回充电流,,Re-0.1,Off-0,A
UINT16 BMS_ContDisCharCurr = 0x00;			  // BMS允许的持续放电电流,,Re-0.1,Off--1000,A
UINT16 BMS_CharReqVolt = 0x00;				  //充电所需电压(交流),,Re-0.1,Off-0,V
UINT16 BMS_CharReqCurr = 0x00;				  //充电所需电流(交流),,Re-0.1,Off--1000,A
UINT16 BMS_SysInsRes = 0x00;				  //系统绝缘电阻,,Re-1,Off-0,KΩ
UINT16 BMS_MaxDisCharPwr = 0x00;			  //最大允许放电功率,,Re-0.1,Off-0,kw
UINT16 BMS_MaxCharPwr = 0x00;				  //最大允许充电功率,,Re-0.1,Off-0,kw
UINT16 BMS_ContDisCharPwr = 0x00;			  // BMS允许的持续放电功率,,Re-0.1,Off-0,kw
UINT16 BMS_ContCharPwr = 0x00;				  // BMS允许的持续充电功率,,Re-0.1,Off-0,kw
UINT16 BMS_InstEngyCons = 0x00;				  //动力电池瞬时百公里能耗,,Re-0.1,Off-0,kwh
UINT16 BMS_TotalEngyCons = 0x00;			  //动力电池总/平均百公里能耗,,Re-0.1,Off-0,kwh
UINT16 BMS_SOE = 0x00;						  //剩余电量,,Re-0.01,Off-0,kwh
UINT16 BMS_RmanCharTime = 0x00;				  //剩余充电时间,,Re-1,Off-0,min
UINT16 BMS_CharNum = 0x00;					  //充电次数,,Re-1,Off-0,
UINT16 BMS_CellVolt[384] = {0x00};			  //电芯的电压,65535 "Invalid" 0xFFFF 无效有效值 0 ~65534, 范围(0 ~65.534) V, Re - 0.001, Off - 0, V
UINT16 BMS_BattRateCap = 0x00;				  //电池包额定容量,有效值 0~65534,65535 "Signal Invalid" 无效,Re-1,Off-0,Ah
UINT16 BMS_BattRateVolt = 0x00;				  //电池包额定电压,有效值 0~6553.4,65535 "Signal Invalid" 无效,Re-0.1,Off-0,V
UINT16 BMS_BattRateEngy = 0x00;				  //电池包额定能量,有效值 0~6553.4,65535 "Signal Invalid" 无效,Re-0.1,Off-0,kWh
UINT16 BMS_CellTotal = 0x00;				  // PACK中单体电芯的总数目,,Re-1,Off-0,
UINT16 BMS_TempTotal = 0x00;				  // PACK中电芯温度点(探针)的总数目,,Re-1,Off-0,
UINT16 BMS_SingleCharEngy = 0x00;			  //单次充电kWh 数,,Re-0.1,Off-0,KWh
UINT16 BMS_SingleCharCapy = 0x00;			  //单次充电Ah 数,,Re-0.1,Off-0,Ah
UINT16 BMS_HVVolt = 0x00;					  // BMS当前电压,,Re-1,Off-0,
UINT16 TMS_ReqPow = 0x00;					  // TMS需求功率,65535:无效,Re-0.1,Off-0,Kw
UINT32 BMS_TotalCharEngy = 0x00;			  //累计充入kWh 数,,Re-0.1,Off-0,KWh
UINT32 BMS_TotalDisCharEngy = 0x00;			  //累计放出kWh 数,,Re-0.1,Off-0,KWh
UINT32 BMS_TotalBackCharEngy = 0x00;		  //累计动能回馈充入kWh 数,,Re-0.1,Off-0,KWh
UINT32 BMS_TotalStaCharEngy = 0x00;			  //累计换电站充入kWh 数,,Re-0.1,Off-0,KWh
UINT32 BMS_TotalGunCharEngy = 0x00;			  //累计插枪充电充入kWh 数,,Re-0.1,Off-0,KWh
UINT32 BMS_TotalGunCharCapy = 0x00;			  //累计插枪充电充入Ah 数,,Re-0.1,Off-0,Ah
UINT32 BMS_TotalCharCapy = 0x00;			  //累计充入Ah 数,,Re-0.1,Off-0,Ah
UINT32 BMS_TotalDisCharCapy = 0x00;			  //累计放出Ah 数,,Re-0.1,Off-0,Ah
UINT32 BMS_TotalBackCharCapy = 0x00;		  //累计动能回馈充入Ah 数,,Re-0.1,Off-0,Ah
UINT32 BMS_TotalStaCharCapy = 0x00;			  //累计换电站充入Ah 数,,Re-0.1,Off-0,Ah
/*VCU->EBC信号*****************************************/
UINT32 VcuInTable[4] = {
	0x18F101D0,
	0x18F103D0,
	0x18E1F3D0,
	0x18FEF100};
BOOL VcuRxShortError[4];
BOOL VcuRxLongError[4];
UINT8 VcuRxFlag[4];
UINT8 VcuRxErrorCounter[4];
UINT8 VCU_Num_VIN[17];			// VCU-VIN
UINT8 VCU_St_VinRecv;			// VIN接收状态
UINT8 VCU_St_BattRly = 0x00;	//电池接触器状态,0:闭合，指示灯灭 1:断开，指示灯亮 2:预留 3:无效,R-1,Off-0,
UINT8 VCU_St_Check = 0x00;		// VCU自检状态,0:正在自检 1:自检成功 2:自检失败 3:无效,R-1,Off-0,
UINT8 VCU_St_SysIntLock = 0x00; //系统互锁状态,0:没有互锁 1:充电互锁 2:预留 3:无效,R-1,Off-0,
UINT8 VCU_St_Veh = 0x00;		//整车状态,0:Wait 1:Ready 2:预留 3:无效,R-1,Off-0,
UINT8 VCU_St_Gear = 0x00;		//档位状态, -1:倒档  0:空档  1:1档  2:2档  3:3档  4:4档  5:5档  6:6档  7:7档  8:8档  9:9档  10:10档  11:11档  12:12档  13:13档  14:14无效 ,R-1,Off--125,
UINT8 VCU_Ft_Sys = 0x00;		// VCU故障（与MCU故障点亮同一个符号）,0:无故障 1:系统故障,R-1,Off-0,
UINT8 VCU_Ft_Tran = 0x00;		//变速箱故障,0:正常 1:报警,R-1,Off-0,
UINT8 VCU_Ft_BattSys = 0x00;	//动力电池系统故障,0:正常 1:报警,R-1,Off-0,
UINT8 VCU_State_Veh = 0x00;		//车辆状态,1:车辆启动状态 2:熄火 3:其他状态 14:异常 15:无效,R-1,Off-0,
UINT8 VCU_Counter = 0x00;		//循环计数器,,R-0.1,Off-0,
UINT8 VCU_SoftVersion = 0x00;	// VCU软件版本号,,R-0.1,Off-0,
UINT8 VCU_St_AccPedal = 0x00;	//加速踏板状态,,R-0.4,Off-0,
UINT8 VCU_St_BrakePedal = 0x00; //刹车踏板状态,,R-0.4,Off-0,
UINT8 VCU_St_ParkBrakeSw = 0;	//手刹状态
// declear the UINT16 vars
UINT16 VCU_VehSpd = 0x00;	//车速,,R-0.0039,Off-0,Km/h
UINT16 VCU_RemaMile = 0x00; //剩余里程,,R-0.125,Off-0,Km
/*EBC->CAN信号*****************************/
UINT32 EbcOutTable[2][2] =
	{{0x18FFF8A7, 100},
	 {0x18FEF8A7, 100}};
UINT8 EBC_Counter = 0;		   // EBC_Counter	LIFE 信号
UINT8 EBC_LockSt = 0;		   // EBC_LockSt	锁止销反馈状态
UINT8 EBC_CnctSt = 0;		   //换电连接器状态（充电回路&放电回路同时闭合代表闭合，有一路断开则为断开）
UINT8 EBC_DisCharCnctSt = 0;   //	放电回路换电连接器状态(保留)
UINT8 EBC_CharCnctSt = 0;	   //	充电回路换电连接器状态（保留）
UINT8 EBC_FtLvl = 0;		   //换电系统故障等级
UINT8 EBC_FtCode = 0;		   //换电系统故障码
UINT8 EBC_AirPressure = 0;	   //气压值
UINT8 EBC_CharSt = 0;		   //充电标志位
UINT8 EBC_ActHeatReq = 0;	   //主动预热请求
UINT8 EBC_InhiHVOn = 0;		   //禁止高压上电
UINT8 EBC_ReqHVOff = 0;		   //请求高压下电
UINT8 EBC_StopChgCmd = 0;	   //停止充电指令
UINT8 EBC_State = 0;		   //换电控制器状态
UINT8 EBC_DisCharPos1Temp = 0; //放电正1温度
UINT8 EBC_DischarNeg1Temp = 0; //放电负1温度
UINT8 EBC_DisCharPos2Temp = 0; //放电正2温度
UINT8 EBC_DisCharNeg2Temp = 0; //放电负2温度
UINT8 EBC_ChgPos1Temp = 0;	   //充电正1温度(保留)
UINT8 EBC_ChgNeg1Temp = 0;	   //充电负1温度(保留)
UINT8 EBC_ChgPos2Temp = 0;	   //充电正2温度(保留)
UINT8 EBC_ChgNeg2Temp = 0;	   //充电负2温度(保留)

/*************************************************************
 *Ebc->Ble组码变量以及Ebc应用层变量存放区
 ************************************************************/
uint8 g_c_BlePwr = 0;
uint8 g_c_AirPwr = 0;
uint8 g_c_LedPwr = 0;
uint16 bcud_E_snglChrg; //单次充电能量，精度0.1kwh

uint16 bcud_pct_soc;		 //电池SOC，精度0.1
uint16 bcud_Q_snglChrg;		 //单次充电容量，精度0.1Ah
uint16 bcud_V_battU;		 //电池电压 精度0.1V
uint32 bcud_E_accChrg;		 //累计充电能量，精度0.1kwh
uint32 bcud_E_accDischrg;	 //累计放电能量，精度0.1kwh
uint32 bcud_E_accPlugInChrg; //累计插枪充电能量，精度0.1kwh
uint32 bcud_E_accRecovry;	 //累计回收能量，精度0.1kwh
uint32 bcud_E_accSwapBatt;	 //累计换电站能量，精度0.1kwh
uint32 bcud_Q_accChrg;		 //累计充电容量，精度0.1ah
uint32 bcud_Q_accDischrg;	 //累计放电容量，精度0.1ah
uint32 bcud_Q_accPlugInChrg; //累计插枪充电容量，精度0.1ah
uint32 bcud_Q_accRecovry;	 //累计回收容量，精度0.1ah
uint32 bcud_Q_accSwapBatt;	 //累计换电站容量，精度0.1ah
uint32 vcud_M_accDrv;		 //累计行驶里程,精度0.1km
uint8 bcud_pct_bcuSoh;		 //电池Soh，精度0.4%
uint8 bcud_st_bcuComun;		 //电池通讯状态,0-通信中断,1-通信正常
uint8 bcud_st_bcuMainRelay;	 //主继电器信号,0-保留 1-断开,2-关闭 3-异常
uint8 bcud_st_bcuTmsLiquid;	 //热管理液位状态,1-液位正常,0-液位过低
uint8 bcud_st_hvWork;		 //电池高压状态，0-高压开启 1-预充，2-高压关断，3-高压上电故障
uint8 bcuv_Num_battSn[32];	 //电池SN号码

uint8 vcud_P_airSensorBack;			   //后桥气压值，单位Mpa，精度0.01Mpa
uint8 vcud_P_airSensorForward;		   //前桥气压值，单位Mpa，精度0.01Mpa
uint8 vcud_st_carStart;				   //整车启动状态，0001-车辆启动状态，0010-熄火，0011-其他状态，1111-无效
uint8 vcud_st_footbrake;			   //脚刹信号，0-无效，1-有效
uint8 vcud_st_gear;					   //档位信号，FF-倒挡（R），0-空挡（N），X-前进档（DX）X取1-12
uint8 vcud_st_handbrake;			   //手刹信号，0-无效，1-有效
uint8 vcud_st_keyOn;				   //钥匙信号，1-上电，0-下电
uint8 vcud_st_Steer;				   //方向盘信号，bit0-左侧转向灯，bit1-右侧转向灯，每bit 0-OFF，1-ON
uint8 vcud_st_vcuComun;				   // vcu通讯状态，0-通信中断,1-通信正常
uint8 vcuv_Num_vin[17];				   // VIN码
uint8 bled_flg_lockCmd = 0;			   //锁钩电磁阀锁紧命令，1-有效，0-无效
uint8 bled_flg_unlockCmd = 0;		   //锁钩电磁阀解锁命令，1-有效，0-无效
uint8 bled_flg_lockCmdForce = 0;	   //锁钩电磁阀锁紧强制命令，1-有效，0-无效
uint8 bled_flg_unlockCmdForce = 0;	   //锁钩电磁阀解锁强制命令，1-有效，0-无效
uint8 bled_flg_topAscendCmd = 0;	   //顶板上升命令，1-有效，0-无效
uint8 bled_flg_topDescendCmd = 0;	   //顶板下降命令，1-有效，0-无效
uint8 bled_flg_topAscendCmdForce = 0;  //顶板强制上升命令，1-有效，0-无效
uint8 bled_flg_topDescendCmdForce = 0; //顶板强制下降命令，1-有效，0-无效
uint8 bled_flg_openDustReCmd = 0;	   //除尘打开指令，1-有效，0-无效
uint8 bled_flg_closeDustReCmd = 0;	   //除尘关闭指令，1-有效，0-无效
uint8 bled_flg_Heart = 0;			   //心跳维持指令
uint8 bled_flg_getEbcData = 0;		   //获取ebc数据指令
uint8 bled_flg_getVcuData = 0;		   //获取vcu数据指令
uint8 bled_flg_getBmsData = 0;		   //获取bms数据指令
uint8 bled_flg_handShake = 0;		   //握手指令
uint8 bled_flg_swapBattDone = 0;	   //换电完成指令
uint8 bled_flg_backToDrv = 0;		   //回到行驶状态指令
uint8 bled_flg_autoLock = 0;		   //自动锁定指令
uint8 bled_flg_autoUnlock = 0;		   //自动解锁指令
uint8 bled_flg_toSwapMod = 0;		   //换到换电状态
uint8 bled_flg_safeStopCmd = 0;		   //急停指令
uint32 bled_Nr_softVer = 0;			   // BLE软件版本
uint8 bled_flg_role = 0;			   // ble的主从模式 01-主，02-从
uint8 bled_flg_bleConn = 0;			   // ble蓝牙连接状态
uint8 bled_flg_bleDisconn = 0;		   // ble蓝牙断开状态
uint8 bled_st_dataTrans = 0;		   //蓝牙数据传输状态
/*
ebc应用层变量
*/
uint8 ebcd_flg_Can2SendEnbale = 0;	 //应答BLE的使能
uint8 ebcd_st_toBleAns = 0;			 //应答BLE的指令序号
uint8 ebcd_P_airSensor = 0;			 //压力传感器气压值：单位Mpa，精度0.01Mpa
uint8 ebcd_T_plugin[4] = {0};		 //四个接插件温度，加了偏移量40
uint8 ebcd_flg_forbidHVOn = 0;		 //禁止高压上电 BMS
uint8 ebcb_flg_reqHvOff = 0;		 //请求高压下电 BMS
uint8 ebcd_flg_LockErr = 0;			 //锁紧机构故障状态,0-异常，1-正常
uint8 ebcd_flg_dChrgLockErr = 0;	 //放电互锁故障状态
uint8 ebcd_flg_chrgLockErr = 0;		 //充电互锁故障状态
uint8 ebcd_flg_dChgCnctOverTemp = 0; //放电连接器过温标志
uint8 ebcd_st_ebcWork = DriveMode;	 // Ebc当前状态 0-行车，1-通讯（握手才进入通讯状态），2-换电
uint8 ebcd_Nr_errMax;				 //故障等级：当前故障最大等级
uint8 ebcd_Num_faultCode;			 // ebc故障码，未定义
uint8 ebcd_st_chargingMod;			 //充电模式，1-车载充电，2-换电站充电
uint8 ebdc_st_lockUpState = 0;		 //锁止机构状态，0-故障，1-解锁成功，2-上锁成功
uint8 ebdc_st_ConnecState = 0;		 //换电连接器状态（充电回路&放电回路同时闭合代表闭合，有一路断开则为断开），0_未连接 1_连接
uint8 ebcd_flg_pluginLockSig;		 //互锁接插件信号状态,1-触发,0-无触发
uint8 ebcd_flg_swapAdmit;			 //允许换电判断：0-不允许,1-允许
uint8 ebcd_Num_err1;				 //故障码1
uint8 ebcd_Num_err2;				 //故障码2
uint8 ebcd_st_ebcConnect;			 // Ebc通讯模式，0-无线蓝牙，1-有线连接 ，默认0
uint8 ebcd_st_ebcLockWork;			 // Ebc解锁模式，0-单步模式，1-自动模式
uint8 ebcd_st_errTable1;			 //故障表1，bit0-气压异常，bit1-液位异常，bit2-Flash读取异常
uint8 ebcd_st_errTable2;			 //故障表2，bit0-互锁异常，bit1-整车CAN异常，bit2-电池CAN异常，bit3-锁钩异常，bit4-升降机异常，bit5-电池位置异常
uint8 ebcd_st_errTable3;			 //故障表3，bit0-放电互锁异常，bit1-充电互锁异常，bit2-整车高压互锁异常
uint8 ebcd_st_lockSensor;			 //锁紧传感器信号：bit0-bit3：传感器0-3的状态每，bit：1-触发，0-不触发
uint8 ebcd_st_lockSucJug;			 //锁紧完成判断：0-完全未锁紧,1-完全锁紧,2-未完全锁紧"
uint8 ebcd_st_pedstSensor;			 //底座落座传感器：bit0-bit1：传感器0-1的状态,每bit：1-触发，0-无触发
uint8 ebcd_st_pedstSucJug;			 //电池底座到位判断：0-完全未到位,1-完全到位,2-未完全到位
uint8 ebcd_st_pluginLockSig;		 //互锁接插件信号具体状态,1-触发,0-无触发
uint8 ebcd_st_unlockSensor;		 //解锁传感器信号：bit0-bit3：传感器0-3的状态每，bit：1-触发，0-不触发
uint8 ebcd_st_unlockSucJug;			 //解锁完成判断：0-完全未解锁，1-完全解锁，2-未完全解锁
uint8 m_flg_HVlock1 = 0;			 //互锁状态1，电池换电接插件
uint8 m_flg_HVlock2 = 0;			 //互锁状态2，整车放电接插件
uint16 Test_LockPressure = 0;		 //锁紧力测试
uint8 ebcd_flg_ebcManCtrlEn = 0;	 // EBC手动控制使能
uint8 ebcd_flg_ebcManCtrlMode = 0;	 // EBC手动控制模式

#define EEPDATA_START_SEC_VAR
#include "MemMap.h"
uint16 ebcd_Nr_swapBatt;	//换电次数
uint16 ebcd_Nr_swapSucBatt; //换电成功次数
uint16 ManuControlTimes = 0;
uint16 LockDelayTime = 0;	//锁定延时时间（传感器到位以后延时多少时间确定为锁定成功
uint16 UnlockDelayTime = 0; //解锁延时时间（传感器到位以后延时多少时间确定为解锁成功

uint8 sfmv_Num_FltEEsave = 0;
#define EEPDATA_STOP_SEC_VAR
#include "MemMap.h"
#define APPLAYERVER_START_SEC_VAR
#include "MemMap.h"
const uint8 T_table[240] = {239, 238, 237, 236, 235, 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224,
							223, 222, 221, 220, 219, 218, 217, 216, 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203,
							202, 201, 200, 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182,
							181, 180, 179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161,
							160, 159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140,
							139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119,
							118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97,
							96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69,
							68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41,
							40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,
							12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
const uint32 R_table[240] = {125, 127, 129, 131, 133, 136, 138, 141, 143, 145, 148, 151, 153, 156, 159, 162, 165,
							 168, 171, 174, 177, 180, 183, 187, 190, 194, 198, 201, 205, 209, 213, 217, 221, 226, 230, 234, 239, 244, 249,
							 254, 259, 264, 269, 274, 280, 286, 292, 298, 304, 310, 316, 323, 330, 337, 344, 351, 359, 366, 374, 382, 391,
							 399, 408, 417, 426, 436, 445, 455, 466, 476, 487, 498, 509, 521, 533, 546, 558, 571, 585, 599, 613, 627, 642,
							 658, 674, 690, 707, 724, 742, 760, 779, 799, 819, 839, 861, 883, 905, 928, 952, 977, 1002, 1029, 1056, 1083,
							 1112, 1142, 1172, 1204, 1236, 1270, 1305, 1340, 1377, 1415, 1455, 1495, 1537, 1581, 1626, 1672, 1720, 1769,
							 1821, 1874, 1928, 1985, 2044, 2104, 2167, 2232, 2299, 2369, 2441, 2515, 2592, 2672, 2755, 2841, 2931, 3023,
							 3119, 3218, 3321, 3428, 3539, 3654, 3773, 3898, 4026, 4160, 4299, 4443, 4593, 4749, 4911, 5080, 5255, 5438,
							 5627, 5825, 6030, 6244, 6466, 6698, 6940, 7191, 7454, 7727, 8012, 8309, 8619, 8942, 9280, 9632, 10000, 10383,
							 10784, 11203, 11641, 12098, 12577, 13077, 13600, 14147, 14720, 15319, 15947, 16604, 17293, 18015, 18771,
							 19564, 20395, 21268, 22183, 23144, 24152, 25211, 26324, 27493, 28722, 30014, 31373, 32802, 34307, 35891,
							 37558, 39315, 41166, 43117, 45174, 47343, 49633, 52049, 54599, 57293, 60140, 63148, 66329, 69693, 73252,
							 77019, 81008, 85233, 89710, 94455, 99488, 104827, 110493, 116508, 122898, 129687, 136905, 144580,
							 152746, 161438, 170694, 180554, 191063, 202269};

const uint8 DataPackCounter[21] = {1, 1, 7, 5, 16, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
const uint8 DataPackBegin[21] = {0, 0x11, 0x21, 0x31, 0x40, 0x51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
#define APPLAYERVER_STOP_SEC_VAR
#include "MemMap.h"
