Browse Source

平峰项目更改-新增了累计放电量和循环次数的计算与上传。

LAPTOP-KB7QFH2U\ChenJie-PC 2 years ago
parent
commit
8d72e364fe
6 changed files with 131 additions and 5 deletions
  1. 1 1
      src/AppGlobalVar.c
  2. 10 0
      src/AppGlobalVar.h
  3. 27 0
      src/AppTaskUart0.c
  4. 65 3
      src/AppTaskUart1.c
  5. 27 0
      src/AppTaskUart1.h
  6. 1 1
      src/main.c

+ 1 - 1
src/AppGlobalVar.c

@@ -43,7 +43,7 @@ uint8 TcpWorkState = 0;
 const char WebSiteName[] = "\"iotp.fast-fun.cn\"";
 uint16 WebSitePort = 8712;
 //const char WebSiteName[] = "\"nas.fast-fun.cn\"";
-//const uint16 WebSitePort = 8812;
+//uint16 WebSitePort = 8812;
 
 #define EEP_START_SEC_VAR_INIT_8_NO_CACHEABLE
 #include "Eep_MemMap.h"

+ 10 - 0
src/AppGlobalVar.h

@@ -61,11 +61,18 @@ extern uint16 WebSitePort;
 extern char ImeiNum[15];
 extern char IccidNum[20];
 extern uint8 TcpWorkState;
+typedef struct _AppEppType
+{
+	uint32 battDischrgAccCap;
+	uint32 battDischrgAccEnrg;
+	uint16 battCycleTimes;
+}AppEppBody;
 typedef struct _AppConfigType
 {
 	bool appSaveFlg;
 	bool eolFlg;
 	uint8 deviceSn[17];
+	AppEppBody AppDataInfo;
 	uint8 re[20];
 } AppConfigBody;
 extern AppConfigBody AppConfigInfo;
@@ -117,4 +124,7 @@ extern uint32 meterAllPwr[2];
 extern uint32 meterPosPwr[2];
 extern uint32 meterNegPwr[2];
 extern uint32 BattTempR[4];
+extern uint32 battAccEnrg ;
+extern uint32 battAccCap ;
+extern uint16 battAccUseTimes ;
 #endif /* APPGLOBALVAR_H_ */

+ 27 - 0
src/AppTaskUart0.c

@@ -10,6 +10,7 @@ static process_Uart0 gProcess_Uart0_Task = PROCESS_UART_STATE_IDLE;
 #define PROC_UART0_STATE_SWITCH(a) (gProcess_Uart0_Task = a)
 bool bmsCellInfoDecode(uint8 *dataPtr);
 bool bmsOtherInfoDecode(uint8 *dataPtr);
+void battDataCalFunc(void);
 void Uart0Task(void *pvParameters)
 {
 	(void)pvParameters;
@@ -392,6 +393,7 @@ bool bmsCellInfoDecode(uint8 *dataPtr) //
 	}
 	avrgCellVol = Battsumvoltage / BATT_CELL_VOL_NUM;
 	battPackVol = Battsumvoltage/100;
+	battDataCalFunc();
 	return true;
 }
 bool bmsOtherInfoDecode(uint8 *dataPtr)//ÆäËûÊý¾Ý½âÎö
@@ -460,4 +462,29 @@ bool bmsOtherInfoDecode(uint8 *dataPtr)//
 	}
 	return true;
 }
+void battDataCalFunc(void)
+{
+	static uint32 timercounterCal = 0;
+	uint16 timediff = 0;
+	float battCapTemp = 0;
+	float battEnrgTemp = 0;
+	timediff = TimerCounter - timercounterCal;
+	timercounterCal = TimerCounter;
+	if(timediff==0 ||timediff>10000)
+	{
+		return;
+	}
+	if(battI>10000)
+	{
+		battCapTemp = ((battI - 10000)/10.0)*(timediff/1000/3600.0);
+		battEnrgTemp = battCapTemp*battPackVol/10.0/1000;
+		AppConfigInfo.AppDataInfo.battDischrgAccCap = AppConfigInfo.AppDataInfo.battDischrgAccCap + (uint32)battCapTemp;
+		AppConfigInfo.AppDataInfo.battDischrgAccEnrg = AppConfigInfo.AppDataInfo.battDischrgAccEnrg + (uint32)battEnrgTemp;
+		if(TimerCounter%1000==0)
+		{
+			AppConfigInfo.AppDataInfo.battCycleTimes = AppConfigInfo.AppDataInfo.battDischrgAccEnrg/49;
+			AppConfigInfo.appSaveFlg = true;
+		}
+	}
+}
 #endif

+ 65 - 3
src/AppTaskUart1.c

@@ -741,6 +741,10 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 	{
 		DataIdx = 0x93; //储能电量信息发送
 	}
+	else if ((TcpSendTimeCounter+4) % 60 == 0)
+	{
+		DataIdx = 0x8A; //累计信息发送
+	}
 	else
 	{
 		*SendLen = 0;
@@ -1050,6 +1054,65 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		*PtrSendAddr = (uint32)SendBuffer;
 		break;
 	}
+	case 0x8A:
+	{
+		AccInfoToTcp AccInfoToTcpMsg;
+		*SendLen = sizeof(AccInfoToTcpMsg);
+		SendBuffer = malloc(*SendLen);
+		uint16 DataLen = 0;
+		DataLen = (uint16)sizeof(AccInfoToTcpMsg.AccMsg);
+		AccInfoToTcpMsg.startSymbol[0] = TCP_START_SYM1;
+		AccInfoToTcpMsg.startSymbol[1] = TCP_START_SYM2;
+		AccInfoToTcpMsg.cmdSymbol = TCP_CMD_SYM;
+		AccInfoToTcpMsg.ansSymbol = TCP_ANS_SYM;
+		memcpy(AccInfoToTcpMsg.SN, TcpbattSN, BATT_SN_LEN);
+		AccInfoToTcpMsg.encryptMethod = TCP_ENCPT_DISABLE; // not encrypt
+		AccInfoToTcpMsg.dataLength[0] = (DataLen >> 8) & 0xFF;
+		AccInfoToTcpMsg.dataLength[1] = DataLen & 0xFF;
+		AccInfoToTcpMsg.AccMsg.sendTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
+		AccInfoToTcpMsg.AccMsg.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;	// month
+		AccInfoToTcpMsg.AccMsg.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;	// day
+		AccInfoToTcpMsg.AccMsg.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;	// hour
+		AccInfoToTcpMsg.AccMsg.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
+		AccInfoToTcpMsg.AccMsg.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; // sec
+		AccInfoToTcpMsg.AccMsg.msgMark = DataIdx;
+		AccInfoToTcpMsg.AccMsg.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
+		AccInfoToTcpMsg.AccMsg.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;	 // month
+		AccInfoToTcpMsg.AccMsg.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;	 // day
+		AccInfoToTcpMsg.AccMsg.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;	 // hour
+		AccInfoToTcpMsg.AccMsg.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
+		AccInfoToTcpMsg.AccMsg.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
+		AccInfoToTcpMsg.AccMsg.accOnlineDays[0] = 0;
+		AccInfoToTcpMsg.AccMsg.accOnlineDays[1] = 0;
+		AccInfoToTcpMsg.AccMsg.accDrvMiles[0] = 0;
+		AccInfoToTcpMsg.AccMsg.accDrvMiles[1] = 0;
+		AccInfoToTcpMsg.AccMsg.sohNoCalibrTime[0] = 0;
+		AccInfoToTcpMsg.AccMsg.sohNoCalibrTime[1] = 0;
+		AccInfoToTcpMsg.AccMsg.accChrgEng[0] = 0;
+		AccInfoToTcpMsg.AccMsg.accChrgEng[1] = 0;
+		AccInfoToTcpMsg.AccMsg.accChrgEng[2] = 0;
+		AccInfoToTcpMsg.AccMsg.accChrgEng[3] = 0;
+		AccInfoToTcpMsg.AccMsg.accDischrgEng[0] = 0x00;
+		AccInfoToTcpMsg.AccMsg.accDischrgEng[1] = 0x00;
+		AccInfoToTcpMsg.AccMsg.accDischrgEng[2] = 0x00;
+		AccInfoToTcpMsg.AccMsg.accDischrgEng[3] = 0x08;
+		AccInfoToTcpMsg.AccMsg.accChrgCap[0] = 0;
+		AccInfoToTcpMsg.AccMsg.accChrgCap[1] = 0;
+		AccInfoToTcpMsg.AccMsg.accChrgCap[2] = 0;
+		AccInfoToTcpMsg.AccMsg.accChrgCap[3] = 0;
+		AccInfoToTcpMsg.AccMsg.accDischrgCap[0] = AppConfigInfo.AppDataInfo.battDischrgAccCap>>24;
+		AccInfoToTcpMsg.AccMsg.accDischrgCap[1] = AppConfigInfo.AppDataInfo.battDischrgAccCap>>16;
+		AccInfoToTcpMsg.AccMsg.accDischrgCap[2] = AppConfigInfo.AppDataInfo.battDischrgAccCap>>8;
+		AccInfoToTcpMsg.AccMsg.accDischrgCap[3] = AppConfigInfo.AppDataInfo.battDischrgAccCap;
+		AccInfoToTcpMsg.AccMsg.accOverChrgTimes= 0;
+		AccInfoToTcpMsg.AccMsg.accOverDischrgTimes = 0;
+		AccInfoToTcpMsg.AccMsg.accCycleTimes[0] = AppConfigInfo.AppDataInfo.battCycleTimes>>8;
+		AccInfoToTcpMsg.AccMsg.accCycleTimes[1] = AppConfigInfo.AppDataInfo.battCycleTimes;
+		AccInfoToTcpMsg.CRC = bcc_chk((uint8 *)&AccInfoToTcpMsg, sizeof(AccInfoToTcpMsg) - 1);
+		memcpy(SendBuffer, &AccInfoToTcpMsg, sizeof(AccInfoToTcpMsg));
+		*PtrSendAddr = (uint32)SendBuffer;
+		break;
+	}
 	default:
 		break;
 	}
@@ -1161,10 +1224,9 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
 				TcpCmdAnswer[0] = TCP_START_SYM1;
 				TcpCmdAnswer[1] = TCP_START_SYM1;
 				TcpCmdAnswer[2] = TCP_CONCMD_SYM;
-				if (*(Ptr + 30) == 0x01) //远程升级指令
+				if (*(Ptr + 30) == 0x83) //远程升级指令
 				{
-					//Fota_Func(Ptr, SocketId);
-					//Fota_Ftp();
+					Fota_Ftp();
 				}
                 else if (*(Ptr + 30) == 0x80) //远程锁定命令
                 {

+ 27 - 0
src/AppTaskUart1.h

@@ -134,6 +134,33 @@ typedef struct StorageInfoToTcpType2
 	StorageInfo2 StorageMsg2;
 	uint8 CRC;
 } StorageInfoToTcp2;
+typedef struct AccInfoType
+{
+	uint8 sendTimeUTC[6];
+	uint8 msgMark;
+	uint8 msgCollectionTimeUTC[6];
+	uint8 accOnlineDays[2];
+	uint8 accDrvMiles[2];
+	uint8 sohNoCalibrTime[2];
+	uint8 accChrgEng[4];
+	uint8 accDischrgEng[4];
+	uint8 accChrgCap[4];
+	uint8 accDischrgCap[4];
+	uint8 accOverChrgTimes;
+	uint8 accOverDischrgTimes;
+	uint8 accCycleTimes[2];
+}AccInfo;
+typedef struct AccInfoToTcpType
+{
+	uint8 startSymbol[2];
+	uint8 cmdSymbol;
+	uint8 ansSymbol;
+	uint8 SN[BATT_SN_LEN];
+	uint8 encryptMethod;
+	uint8 dataLength[2];
+	AccInfo AccMsg;
+	uint8 CRC;
+}AccInfoToTcp;
 typedef struct UTC8Time_Type
 {
 	uint8 year;

+ 1 - 1
src/main.c

@@ -120,7 +120,7 @@ int main(void)
 #endif /* ADC_PRECOMPILE_SUPPORT == STD_ON */
 
     /* Partition only if it was not partitioned before for EERAM with code 0x4 */
-    Eep_DepartParitition(T_EEEPROM_SIZE);
+//    Eep_DepartParitition(T_EEEPROM_SIZE);
     /* Initialize Eep driver */
 #if defined (EEP_PRECOMPILE_SUPPORT)
     Eep_Init(NULL_PTR);