Procházet zdrojové kódy

V0.2.0.7 合并海南变动点,优化累计安时计算,优化电压获取逻辑。

LAPTOP-KB7QFH2U\ChenJie-PC před 1 rokem
rodič
revize
ec73f9738c
4 změnil soubory, kde provedl 93 přidání a 58 odebrání
  1. 14 9
      code/app/AppGlobalVar.c
  2. 2 1
      code/app/AppGlobalVar.h
  3. 58 36
      code/app/AppTaskCan.c
  4. 19 12
      code/app/AppTaskUart1.c

+ 14 - 9
code/app/AppGlobalVar.c

@@ -18,24 +18,28 @@
 
 #define defaultSn "ZLTEST00000000001"
 
-#define EEP_START_SEC_VAR_INIT_8_NO_CACHEABLE
-#include "Eep_MemMap.h"
-AppConfigBody AppConfigInfo = {false, false, {defaultSn}, {0}};
-#define EEP_STOP_SEC_VAR_INIT_8_NO_CACHEABLE
-#include "Eep_MemMap.h"
-
 #define APP_RELEASE
 
 #ifdef APP_RELEASE
 const char WebSiteName[] = "\"iotp.fast-fun.cn\"";
 uint16 WebSitePort = 8712;
+#define EEP_START_SEC_VAR_INIT_8_NO_CACHEABLE
+#include "Eep_MemMap.h"
+AppConfigBody AppConfigInfo = {false, false, {defaultSn}, {0}};
+#define EEP_STOP_SEC_VAR_INIT_8_NO_CACHEABLE
+#include "Eep_MemMap.h"
 #else
 const char WebSiteName[] = "\"nas.fast-fun.cn\"";
 uint16 WebSitePort = 8812;
+#define EEP_START_SEC_VAR_INIT_8_NO_CACHEABLE
+#include "Eep_MemMap.h"
+AppConfigBody AppConfigInfo = {false, true, {defaultSn}, {0}};
+#define EEP_STOP_SEC_VAR_INIT_8_NO_CACHEABLE
+#include "Eep_MemMap.h"
 #endif
 
 //*全局变量*//
-const uint32 AppSwVersion = 0x00020006;
+const uint32 AppSwVersion = 0x00020007;
 const uint8 DataModuleType = 0x02; // 01=NB,02-4G
 const uint16 HwVersion = 0x0102;
 const uint32 BlSwVersion = 0x00000002;
@@ -138,7 +142,8 @@ UINT8 BcuRxFlag[28];
 /************************************************************
  *BCU->4G解码变量存放区
  ************************************************************/
-UINT8 BMS_CellRecvCounter=0;						//每个电压收取标志位
+UINT8 BMS_CellRecvFlg = 0;						//电压收取标志位
+UINT8 canRecvFramNum[BMS_CELL_MAX_NUM/3] = {0};
 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,
@@ -181,7 +186,7 @@ UINT8 BMS_CharSysNum = 0x00;					// 可充电储能子系统总数(保留),,Re-1
 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当前状态,和新版协议不匹配
+UINT8 BMS_Mode = 0x00;							// BMS当前状态,0-未上高压,2-上高压
 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,

+ 2 - 1
code/app/AppGlobalVar.h

@@ -121,7 +121,8 @@ extern BOOL BcuRxShortError[28];
 extern BOOL BcuRxLongError[28];
 extern UINT8 BcuRxErrorCounter[28];
 extern UINT8 BcuRxFlag[28];
-extern UINT8 BMS_CellRecvCounter;
+extern UINT8 BMS_CellRecvFlg;
+extern UINT8 canRecvFramNum[BMS_CELL_MAX_NUM/3];
 extern UINT8 BMS_ReqVIN;
 extern UINT8 BMS_ReqHVOff;
 extern UINT8 BMS_ProtocolEditionH;

+ 58 - 36
code/app/AppTaskCan.c

@@ -75,14 +75,13 @@ static void CalAccAhFunc(void)//100ms运行一次
 {
 	static float tmp_DischrgAh = 0;//mah
 	static float tmp_ChrgAh = 0;//mah
-//	if(BcuRxLongError[3]==0 && (BcuRxLongError[24]==1||BcuRxShortError[24]==1))//在CAN消息正常,CAN[24]存在时间长的问题,不建议用丢帧处理
-	if(BcuRxLongError[3]==0 && BMS_Mode==0)
+	if(BcuRxLongError[3]==0)
 	{
-		if(BMS_CharSt==1)//1是正在充电
+		if(BMS_CharSt==1)//充电计算
 		{
 			tmp_ChrgAh = tmp_ChrgAh + (float)(abs(BMS_PackCurr - 10000)/360);
 		}
-		else//放电计算
+		else if(BMS_Mode==2)//放电计算
 		{
 			tmp_DischrgAh = tmp_DischrgAh + (float)(abs(BMS_PackCurr - 10000)/360);
 		}
@@ -280,28 +279,49 @@ void BcuDecodeFunction(uint32 ID, uint8 *rawData)
 		BcuRxFlag[12] = 0x01;
 		break;
 	case 0x18C1D0F3:
-		BMS_CellVoltFramNum = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
-		BMS_CSC_Code = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
-		if (BMS_CellVoltFramNum == 0 || BMS_CellVoltFramNum > 128)
-		{
-			break;
-		}
-		BMS_CellRecvCounter = (BMS_CellRecvCounter + 1) >= 128 ? 128 : (BMS_CellRecvCounter + 1);
-		for (UINT8 i = 0; i < 3; i++)
 		{
-			BMS_CellVolt[(BMS_CellVoltFramNum - 1) * 3 + i] = (UINT16)(((*(UINT8 *)(rawData + i * 2 + 2)) | (*(UINT8 *)(rawData + i * 2 + 3) << 8)) & 0xFFFF);
+			uint8 battCellTotalTemp = 0;
+			battCellTotalTemp = min(BMS_CellTotal, BMS_CELL_MAX_NUM)/3;
+			BMS_CellVoltFramNum = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
+			BMS_CSC_Code = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
+			if (BMS_CellVoltFramNum == 0 || BMS_CellVoltFramNum >battCellTotalTemp )
+			{
+				break;
+			}
+			for (UINT8 i = 0; i < 3; i++)
+			{
+				BMS_CellVolt[(BMS_CellVoltFramNum - 1) * 3 + i] = (UINT16)(((*(UINT8 *)(rawData + i * 2 + 2)) | (*(UINT8 *)(rawData + i * 2 + 3) << 8)) & 0xFFFF);
+			}
+			canRecvFramNum[BMS_CellVoltFramNum - 1] = 1;
+			if(BMS_CellRecvFlg==false)
+			{
+				uint8 FrameSum = 0;
+				for(uint8 i=0;i<battCellTotalTemp;i++)
+				{
+					FrameSum = FrameSum + canRecvFramNum[i];
+				}
+				if(FrameSum==battCellTotalTemp)
+				{
+					BMS_CellRecvFlg = true;
+				}
+			}
+
+
+			BcuRxFlag[13] = 0x01;
 		}
-		BcuRxFlag[13] = 0x01;
 		break;
 	case 0x18C2D0F3:
+		{
+		uint8 tempType = 8;
+		uint8 csc_maxCode = 8;
+		uint8 tempCount = 0,offvalue = 0;
 		BMS_CellTempFramNum = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
 		BMS_CSC_Code = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
-		if (BMS_CSC_Code == 0 || BMS_CSC_Code > 8)
+		if (BMS_CSC_Code == 0 || BMS_CSC_Code > csc_maxCode)
 		{
 			break;
 		}
-		uint8 tempCount = 0,offvalue = 0;
-		if(BMS_CellTempFramNum%2==0)
+		if(BMS_CellTempFramNum%2==0 && tempType==8)
 		{
 			tempCount = 2;
 			offvalue = 6;
@@ -313,12 +333,13 @@ void BcuDecodeFunction(uint32 ID, uint8 *rawData)
 		}
 		for(uint8 i=0; i<tempCount; i++)
 		{
-			if (((BMS_CSC_Code - 1) * 8 + i + offvalue) < sizeof(BMS_CellTemp) && ((UINT8)(((*(UINT8 *)(rawData + 2 + i))) & 0xFF) >= 10))
+			if (((BMS_CSC_Code - 1) * tempType + i + offvalue) < sizeof(BMS_CellTemp) && ((UINT8)(((*(UINT8 *)(rawData + 2 + i))) & 0xFF) >= 10))
 			{
-				BMS_CellTemp[(BMS_CSC_Code - 1) * 8 + i + offvalue] = (UINT8)(((*(UINT8 *)(rawData + 2 + i))) & 0xFF)- 10;
+				BMS_CellTemp[(BMS_CSC_Code - 1) * tempType + i + offvalue] = (UINT8)(((*(UINT8 *)(rawData + 2 + i))) & 0xFF)- 10;
 			}
 		}
 		BcuRxFlag[14] = 0x01;
+		}
 		break;
 	case 0x18E1D0F3:
 		BMS_Checksum = 0;
@@ -1152,7 +1173,8 @@ void BcuRxMsgSetInvalidValue(uint32 ID)
 		break;
 	case 0x18C1D0F3:
 		BMS_CellVoltFramNum = 0xFF;
-		BMS_CellRecvCounter = 0;
+		memset(canRecvFramNum,0x00,sizeof(canRecvFramNum));
+		BMS_CellRecvFlg = 0;
 		for (UINT16 i = 0; i < sizeof(BMS_CellVolt) / 2; i++)
 		{
 			BMS_CellVolt[i] = 0xFFFF;
@@ -1199,13 +1221,13 @@ void BcuRxMsgSetInvalidValue(uint32 ID)
 		break;
 	case 0x18E4D0F3:
 		BMS_Checksum = 0xFF;
-		BMS_SN[20] = 0xFF;
-		BMS_SN[21] = 0xFF;
-		BMS_SN[22] = 0xFF;
-		BMS_SN[23] = 0xFF;
-		BMS_SN[24] = 0xFF;
-		BMS_SN[25] = 0xFF;
-		BMS_SN[26] = 0xFF;
+//		BMS_SN[20] = 0xFF;
+//		BMS_SN[21] = 0xFF;
+//		BMS_SN[22] = 0xFF;
+//		BMS_SN[23] = 0xFF;
+//		BMS_SN[24] = 0xFF;
+//		BMS_SN[25] = 0xFF;
+//		BMS_SN[26] = 0xFF;
 		break;
 	case 0x18E5D0F3:
 		BMS_BattRateCap = 0xFFFF;
@@ -1216,24 +1238,24 @@ void BcuRxMsgSetInvalidValue(uint32 ID)
 		break;
 	case 0x18E6D0F3:
 		BMS_CSC_Total = 0xFF;
-		//		BMS_CellTotal = BMS_CELL_MAX_NUM;
-		//		BMS_TempTotal = BMS_TEMP_MAX_NUM;
+//		BMS_CellTotal = BMS_CELL_MAX_NUM;
+//		BMS_TempTotal = BMS_TEMP_MAX_NUM;
 		BMS_CellVoltLevel = 0xFF;
 		BMS_CellMinVolt = 0xFF;
 		BMS_CellMaxVolt = 0xFF;
 		break;
 	case 0x18F1D0F3:
-		BMS_TotalCharEngy = 0xFFFFFFFF;
-		BMS_TotalDisCharEngy = 0xFFFFFFFF;
-		BMS_SingleCharEngy = 0xFFFF;
+//		BMS_TotalCharEngy = 0xFFFFFFFF;
+//		BMS_TotalDisCharEngy = 0xFFFFFFFF;
+//		BMS_SingleCharEngy = 0xFFFF;
 		break;
 	case 0x18F2D0F3:
-		BMS_TotalBackCharEngy = 0xFFFFFFFF;
-		BMS_TotalStaCharEngy = 0xFFFFFFFF;
+//		BMS_TotalBackCharEngy = 0xFFFFFFFF;
+//		BMS_TotalStaCharEngy = 0xFFFFFFFF;
 		break;
 	case 0x18F3D0F3:
-		BMS_TotalGunCharEngy = 0xFFFFFFFF;
-		BMS_TotalGunCharCapy = 0xFFFFFFFF;
+//		BMS_TotalGunCharEngy = 0xFFFFFFFF;
+//		BMS_TotalGunCharCapy = 0xFFFFFFFF;
 		break;
 	case 0x18F4D0F3:
 //		BMS_TotalCharCapy = 0xFFFFFFFF;

+ 19 - 12
code/app/AppTaskUart1.c

@@ -255,7 +255,7 @@ static void TcpDataSendFeqHandFunc(uint8* DataIdx)
 		TcpDataFeq.GpsFeqCnt[1] = 60*3;
 		TcpDataFeq.TrkBattFeqCnt[1]  = 10;
 	}
-	else if(BMS_Mode==0)//放电中
+	else if(BMS_Mode==2)//放电中
 	{
 		TcpDataFeq.GpsFeqCnt[1] = 10;
 		TcpDataFeq.TrkBattFeqCnt[1]  = 30;
@@ -265,7 +265,17 @@ static void TcpDataSendFeqHandFunc(uint8* DataIdx)
 		TcpDataFeq.GpsFeqCnt[1] = 60;
 		TcpDataFeq.TrkBattFeqCnt[1]  = 60;
 	}
-
+	TcpDataFeq.DebugMsgFeqCnt[1] = TcpDataFeq.TrkBattFeqCnt[1];
+	//读取硬线唤醒源状态,若没有硬线唤醒,则降低调试信息发送频率
+	Dio_LevelType wakeup1,wakeup2 = STD_HIGH;
+	wakeup1 = Dio_ReadChannel(DioConf_DioChannel_PTB0_GPIO_IN_MCU_WAKEUP1);
+	wakeup2 = Dio_ReadChannel(DioConf_DioChannel_PTE2_GPIO_IN_MCU_WAKEUP2);
+	if(wakeup1==STD_LOW && wakeup2==STD_LOW)
+	{
+		TcpDataFeq.DebugMsgFeqCnt[1] = 10*60;
+		TcpDataFeq.TrkVehichleFeqCnt[1] = 10*60;
+		TcpDataFeq.GpsFeqCnt[1] = 3*60;
+	}
 	return;
 }
 sint8 TcpDataSendFunc(sint8 ConnectId,uint8 DataSendIdxIn)
@@ -967,7 +977,7 @@ void TcpDataEncode(uint8 DataIdx,uint32 *PtrSendAddr, uint16 *SendLen)
 								{%.2f,%.2f,%.2f,%.2f,%.2f;\
 								%.2f,%.2f,%.2f,%.2f,%.2f,}\
 								{%.2f,%.2f,%.2f,%.2f,%.2f;\
-								%.2f,%.2f,%.2f,%.2f,%.2f,},%s,%d",
+								%.2f,%.2f,%.2f,%.2f,%.2f,},%s,%d-M-%d,P-%d,N-%d,C-%d,A-%d",
 				returnFreq[0][0], returnFreq[0][1], returnFreq[0][2], returnFreq[0][3], returnFreq[0][4],
 				returnP[0][0], returnP[0][1], returnP[0][2], returnP[0][3], returnP[0][4],
 
@@ -975,7 +985,8 @@ void TcpDataEncode(uint8 DataIdx,uint32 *PtrSendAddr, uint16 *SendLen)
 				returnP[1][0], returnP[1][1], returnP[1][2], returnP[1][3], returnP[1][4],
 
 				returnFreq[2][0], returnFreq[2][1], returnFreq[2][2], returnFreq[2][3], returnFreq[2][4],
-				returnP[2][0], returnP[2][1], returnP[2][2], returnP[2][3], returnP[2][4],tmp,DeviceErrNum);
+				returnP[2][0], returnP[2][1], returnP[2][2], returnP[2][3], returnP[2][4],tmp,DeviceErrNum,
+				BMS_Mode,BMS_StPosRly,BMS_StNegRly,BMS_CharSt,BMS_PackCurr-10000);
 
 		BufferLen = strlen((const char *)rbuf);
 		*SendLen = BufferLen + sizeof(DebugMsgInfo);
@@ -1033,17 +1044,13 @@ void TcpDataEncode(uint8 DataIdx,uint32 *PtrSendAddr, uint16 *SendLen)
 		*(SendBuffer + 0x24) = (UTC8TimeTcp.second & 0xFF); // uint8	second
 		memcpy(SendBuffer + 0x25, VIN, 17);
 		*(SendBuffer + 0x36) = (vehicleStatus & 0xFF); // uint8	整车状态
-		if (BMS_Mode == 1)
+		if (BMS_Mode == 2)
 		{
 			bmsHVOn = 1;
 		}
-		else if (BMS_Mode == 2)
-		{
-			bmsHVOn = 0;
-		}
 		else
 		{
-			bmsHVOn = 0xFF;
+			bmsHVOn = 2;
 		}
 		*(SendBuffer + 0x37) = (bmsHVOn & 0xFF);			 // uint8	bms上高压指令
 		*(SendBuffer + 0x38) = (currentGearPosition & 0xFF); // uint8	当前档位
@@ -1077,7 +1084,7 @@ void TcpDataEncode(uint8 DataIdx,uint32 *PtrSendAddr, uint16 *SendLen)
 	}
 	case 0x91:
 	{
-		if(BMS_CellRecvCounter<128)
+		if(BMS_CellRecvFlg==false)//CAN上电压数据未接收完成
 		{
 			*SendLen = 0; // 不发送,长度为0
 			return;
@@ -1108,7 +1115,7 @@ void TcpDataEncode(uint8 DataIdx,uint32 *PtrSendAddr, uint16 *SendLen)
 		*(SendBuffer + 0x23) = (UTC8TimeTcp.minute & 0xFF);	   // uint8	minute
 		*(SendBuffer + 0x24) = (UTC8TimeTcp.second & 0xFF);	   // uint8	second
 		*(SendBuffer + 0x25) = (CSQValue & 0xFF);			   // uint8	csq
-		*(SendBuffer + 0x26) = (BMS_Mode & 0xFF);			   // uint8	BMS当前状态,0:预留;1:高压上电;2:高压下电;3:无效;,Re-1,Off-0,
+		*(SendBuffer + 0x26) = (bmsHVOn & 0xFF);			   // uint8	BMS当前状态,0:预留;1:高压上电;2:高压下电;3:无效;,Re-1,Off-0,
 		*(SendBuffer + 0x27) = (BMS_CharGunSt & 0xFF);		   // uint8	直流充电枪连接状态,0:未连接1 : 连接, Re - 1, Off - 0,
 		*(SendBuffer + 0x28) = (BMS_FtLvl & 0xFF);			   // uint8	当前最高故障等级,0-正常 1-1级 轻微故障 2-2级 较严重故障 3-3级 最严重故障,精度_1,偏移量_0,单位_
 		*(SendBuffer + 0x29) = (BMS_FtCode & 0xFF);			   // uint8	故障码,见BMS_ErrCode,精度_1,偏移量_0,单位_