Ver Fonte

V3.0.0.8 优化GPS更改,优化Fota升级及保护板升级问题

CHENJIE-PC\QiXiang_CHENJIE há 3 anos atrás
pai
commit
a85df57900
6 ficheiros alterados com 113 adições e 87 exclusões
  1. 1 1
      inc/AppConfig.h
  2. 1 1
      inc/AppTaskUart.h
  3. 1 1
      src/AppFunc.c
  4. 61 29
      src/AppTaskGps.c
  5. 31 35
      src/AppTaskTcp.c
  6. 18 20
      src/AppTaskUart.c

+ 1 - 1
inc/AppConfig.h

@@ -13,7 +13,7 @@
 #define DATA_MODULE_TYPE            (1)                 //1表示NB模块,2表示4G cat1
 #define EOLSTATE                    (0)                 //1表示下线检测跳过,使用默认值,0表示使用下线检测
 #define DEFAULT_SN                  "RLTEST00000000002" //默认上传的SN编码
-#define	APPSWVERSION		        0x03000007          //数据模块软件版本号
+#define	APPSWVERSION		        0x03000008          //数据模块软件版本号
 
 #define TCP_ADD                     "iotp.fast-fun.cn"  //数据上传的地址
 #define TCP_PORT					8712                //数据上传的端口

+ 1 - 1
inc/AppTaskUart.h

@@ -51,7 +51,7 @@ typedef struct _UartAnswerData
 {
 	volatile BOOL UartFlag;
     UINT8 Header[3];
-    UINT8 data[120];
+    UINT8 data[200];
     UINT16 len;
 }UartAnswerData_S;
 typedef struct _UartQueryType

+ 1 - 1
src/AppFunc.c

@@ -1879,7 +1879,7 @@ void UDS_Service(CAN_Msg_Type* CanRxMsg)
 	CAN_Msg_Type UDSAnswer ={0};	
 	UINT32 posCode,negCode;
 	UINT32  updateDifferDataByteLen = 0;
-	UINT8 updateDataBuffer[100];
+	static UINT8 updateDataBuffer[100];
 	
 	
 	

+ 61 - 29
src/AppTaskGps.c

@@ -27,19 +27,20 @@ static void GpsTask(void* arg)
 
 	if(GpsRecvHandle == NULL)
 	{
-		GpsRecvHandle = osMessageQueueNew(2,sizeof(GPSInfo*), NULL);
+		GpsRecvHandle = osMessageQueueNew(1,sizeof(GPSInfo*), NULL);
 	}
 	gpsReqMsg msg;
 	GPSInfo *GpsInfoData; 
 	char *p=NULL;
+	CHAR *p2=NULL;
 	const char *delim = "\n";
-	char *databuffer[14];
+	char *databuffer[20];
 	UINT32 speedtemp;
     UINT32 latitude;
 	UINT32 longitude;
     UINT16 direction;
-	UINT8  	GpsNoDataCounter = 0;
-	UINT8	GpsResetCount = 0;
+	UINT16 GpsNoDataCounter = 0;
+	UINT8  index=0;
 	PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_INIT);
     while(1)
     {
@@ -47,9 +48,10 @@ static void GpsTask(void* arg)
 		{
 			case PROCESS_GPS_STATE_INIT:
 			{
-				posGGAReset();
+				
 				osDelay(100);
 				posGGAServiceStart(norGpsHandle);
+				posGGAReset();
 				PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_WORK);
 				break;
 			}
@@ -71,13 +73,12 @@ static void GpsTask(void* arg)
 			}
 			case PROCESS_GPS_STATE_WORK:
 			{
-				if(GpsNoDataCounter>=10 && GpsResetCount<=3)
+				if(GpsNoDataCounter>=60*10)
 				{
-					posGGAReset();
-					GpsResetCount++;
 					GpsNoDataCounter = 0;
 					osDelay(100);
 					posGGAServiceStart(norGpsHandle);
+					posGGAReset();
 				}
 				osStatus_t ret = osMessageQueueGet(norGpsHandle, &msg, 0, 1000);
 				if(ret==0)
@@ -88,6 +89,7 @@ static void GpsTask(void* arg)
 						GpsInfoData = malloc(sizeof(GPSInfo));
 						memset(GpsInfoData,0x00,sizeof(GPSInfo));
 						p = strtok(msg.dataPtr,delim);//将信息进行分割
+						p2 = strtok(NULL,delim);
 						#ifdef USING_PRINTF1
 							printf("\nP msgptr data:%s\r\n",p);
 						#endif
@@ -95,25 +97,18 @@ static void GpsTask(void* arg)
 						//p = strtok(temp,",");//模拟测试
 						if (strcmp(p,"$GNRMC")==0)
 						{
-							UINT8 i=0;			
+							index = 0;			
 							while (p)
 							{	
-								databuffer[i]=p;
+								databuffer[index]=p;
 								p = strtok(NULL,",");
-								i++;;
-							}
-							if (strcmp(databuffer[1],"V")==0|strcmp(databuffer[2],"V")==0)
-							{
-								GpsFlag = 0;
-								memset(GpsInfoData,0x00,sizeof(GPSInfo));
-								GpsNoDataCounter++;
+								index++;
 							}
-							else if (strcmp(databuffer[2],"A")==0)
+							if (index>5&&strcmp(databuffer[2],"A")==0)
 							{
-								GpsResetCount = 0;
+								GpsNoDataCounter = 0;
 								GpsInfoData->locateMark = 0x01;//有效,东经,北纬写定
-								GpsInfoData->satelliteNum = 03;//卫星数目写入1
-								GpsFlag = GpsInfoData->satelliteNum;
+								GpsFlag = 3;
 								strdel(databuffer[3],'.');
 								strdel(databuffer[5],'.');
 								strdel(databuffer[7],'.');
@@ -130,9 +125,6 @@ static void GpsTask(void* arg)
 								GpsInfoData->longitude[1] = longitude>>16;
 								GpsInfoData->longitude[2] = longitude>>8;
 								GpsInfoData->longitude[3] = longitude;
-
-								GpsInfoData->altitude[0]  = 0x03;//海拔目前无输出
-								GpsInfoData->altitude[1]  = 0xE8;
 								if(speedtemp>=50)//大于5km/h才输出方位
 								{
 									direction = atol(databuffer[8]);
@@ -152,14 +144,54 @@ static void GpsTask(void* arg)
 									{
 										AppDataInfo.AccMileage = 0;
 									}
-
 								}
-								GpsInfoData->AccMileage[0] = AppDataInfo.AccMileage>>24;
-								GpsInfoData->AccMileage[1] = AppDataInfo.AccMileage>>16;
-								GpsInfoData->AccMileage[2] = AppDataInfo.AccMileage>>8;
-								GpsInfoData->AccMileage[3] = AppDataInfo.AccMileage;
+							}
+							GpsInfoData->AccMileage[0] = AppDataInfo.AccMileage>>24;
+							GpsInfoData->AccMileage[1] = AppDataInfo.AccMileage>>16;
+							GpsInfoData->AccMileage[2] = AppDataInfo.AccMileage>>8;
+							GpsInfoData->AccMileage[3] = AppDataInfo.AccMileage;
+						}
+						p2 = strtok(p2,",");//只取第2行的信息GGA
+						memset(databuffer,0x30,20);
+						if(strcmp(p2,"$GNGGA")==0)
+						{
+							index = 0;			
+							while (p2)
+							{	
+								databuffer[index]=p2;
+								p2 = strtok(NULL,",");
+								index++;
+							}
+							if(index>9&&(strcmp(databuffer[6],"1")==0||strcmp(databuffer[6],"2")==0))
+							{
+								GpsInfoData->satelliteNum = atol(databuffer[7]);//卫星数目写入
+								GpsFlag = GpsInfoData->satelliteNum;
+								strdel(databuffer[9],'.');
+								UINT16 alt = 0;
+								alt = atol(databuffer[9])/10 + 1000;
+								GpsInfoData->altitude[0]  = alt>>8;//海拔
+								GpsInfoData->altitude[1]  = alt;
+								strdel(databuffer[2],'.');
+								strdel(databuffer[4],'.');
+								latitude =location_handle(databuffer[2]);
+								GpsInfoData->latitude[0] = latitude>> 24;
+								GpsInfoData->latitude[1] = latitude>> 16;
+								GpsInfoData->latitude[2] = latitude>> 8;
+								GpsInfoData->latitude[3] = latitude;
+								longitude = location_handle(databuffer[4]);
+								GpsInfoData->longitude[0] = longitude>>24;
+								GpsInfoData->longitude[1] = longitude>>16;
+								GpsInfoData->longitude[2] = longitude>>8;
+								GpsInfoData->longitude[3] = longitude;
+							}
+							else
+							{
+								GpsFlag = 0;
+								memset(GpsInfoData,0x00,sizeof(GPSInfo));
+								GpsNoDataCounter++;
 							}
 						}
+						osMessageQueueReset(GpsRecvHandle);
 						osMessageQueuePut(GpsRecvHandle,&GpsInfoData,0,1000);
 					}
 					if(msg.dataPtr)

+ 31 - 35
src/AppTaskTcp.c

@@ -419,46 +419,42 @@ static void TcpDataInfoAssembleSend()
         GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; 						    //hour
         GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;						    //mins
         GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
-        osStatus_t ret = osMessageQueueGet(GpsRecvHandle,&GpsRecvData,0,0);
+        osStatus_t ret = osMessageQueueGet(GpsRecvHandle,&GpsRecvData,0,100);
         if(ret == 0)
         {
             memcpy((UINT8 *)&GpsToTcpInfo.gpsInfo.locateMark, GpsRecvData,sizeof(GPSInfo));
-        }
-        else
-        {
-            memcpy((UINT8 *)&GpsToTcpInfo.gpsInfo.locateMark, 0x00,sizeof(GPSInfo));
-        }
-        GpsToTcpInfo.gpsInfo.Tac[0] = tac>>8;
-        GpsToTcpInfo.gpsInfo.Tac[1] = tac&0xFF;
-        GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>24;
-        GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>16;
-        GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>8;
-        GpsToTcpInfo.gpsInfo.CellID[0] = cellId;
-        GpsToTcpInfo.CRC = bcc_chk((UINT8 *)&GpsToTcpInfo, sizeof(GPSMsgtoTcpType)-1 );
-        if(GpsRecvData!=NULL)
-            free(GpsRecvData);
-        GpsRecvData=NULL;
-        //if(GpsToTcpInfo.gpsInfo.locateMark==0x01)
-        if(1)
-        {
-            len = tcpipConnectionSend(socContext.id, (UINT8 *)&GpsToTcpInfo, sizeof(GpsToTcpInfo), 0, 0, 0);
-            #ifdef USING_PRINTF1
-                for (int i = 0; i < sizeof(GpsToTcpInfo); i++)
+            GpsToTcpInfo.gpsInfo.Tac[0] = tac>>8;
+            GpsToTcpInfo.gpsInfo.Tac[1] = tac&0xFF;
+            GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>24;
+            GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>16;
+            GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>8;
+            GpsToTcpInfo.gpsInfo.CellID[0] = cellId;
+            GpsToTcpInfo.CRC = bcc_chk((UINT8 *)&GpsToTcpInfo, sizeof(GPSMsgtoTcpType)-1 );
+            //if(GpsToTcpInfo.gpsInfo.locateMark==0x01)
+            if(1)
+            {
+                len = tcpipConnectionSend(socContext.id, (UINT8 *)&GpsToTcpInfo, sizeof(GpsToTcpInfo), 0, 0, 0);
+                #ifdef USING_PRINTF1
+                    for (int i = 0; i < sizeof(GpsToTcpInfo); i++)
+                    {
+                        printf("%02x ",*((UINT8 *)&GpsToTcpInfo+i));
+                    }
+                    printf("-[%d]-Gpslen:%d\n",__LINE__,len);
+                #endif
+                if(len>0)
                 {
-                    printf("%02x ",*((UINT8 *)&GpsToTcpInfo+i));
+                    TcpSendLen = 0x04 | TcpSendLen;
+                }
+                else
+                {
+                    TcpSendLen = 0xFB & TcpSendLen;
+                    sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
                 }
-                printf("-[%d]-Gpslen:%d\n",__LINE__,len);
-            #endif
-            if(len>0)
-            {
-                TcpSendLen = 0x04 | TcpSendLen;
-            }
-            else
-            {
-                TcpSendLen = 0xFB & TcpSendLen;
-                sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
             }
         }
+        if(GpsRecvData!=NULL)
+            free(GpsRecvData);
+        GpsRecvData=NULL;
     }
     if(send_counter==1)//版本信息上报 上报频率为每次重启后上报或者每次更新后上报或者每天上报一次均可
     {
@@ -542,12 +538,12 @@ static void TcpDataInfoAssembleSend()
             }
         }
     }
-    if(send_counter%1==0)
+    if(send_counter%60==0)
     {
         DebugMsgtoTcpType DebugMsgInfo;
         UINT16 BufferLen = 0;
         UINT8 rbuf[1000];
-		sprintf((char *)rbuf,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",socd_pct_ekfSoc,socd_pct_ahSoc,socd_pct_battSoc,socd_pct_bcuSoc,ihd_tm_parkTime,sohd_Q_chrgEo,sohd_flg_chrgEndEo,cand_Nr_cellNr,cand_V_chrgStartStat,cand_Q_cellCap,sohd_pct_bcuSoh,sfmd_idx_fltCode,sfmd_num_fltNum);
+		sprintf((char *)rbuf,"%x",battProtectState);
 		BufferLen = strlen(rbuf);
         SendBuffer = malloc(BufferLen+sizeof(DebugMsgInfo));
         memcpy(SendBuffer+sizeof(DebugMsgInfo)-1, rbuf,BufferLen);

+ 18 - 20
src/AppTaskUart.c

@@ -29,7 +29,6 @@ static UINT8 Uart_DataRecv_func(UartQueryType Uart_Read_Msg_Fun,UINT8* Uart_Recv
 static void UartTask(void* arg)
 {
 
-    UINT16  Uart_Uds_LEN;
     UINT16  Reg_Num = 0;
     UINT16  Uart_Recv_LEN;
     UINT8   UartRecvFlagCounter = 0;
@@ -118,8 +117,7 @@ static void UartTask(void* arg)
                 Uart_Read_Msg.Reg_Begin_L = 0x00;
                 Uart_Read_Msg.Reg_Num_H   = Reg_Num>>8;
                 Uart_Read_Msg.Reg_Num_L   = Reg_Num;
-                Uart_Uds_LEN = Reg_Num*2;
-                memset(UartAnswerData.Header,0x00,Uart_Uds_LEN);
+                memset(&(UartAnswerData),0x00,sizeof(UartAnswerData_S));
 				CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Read_Msg,6);
 				Uart_Read_Msg.CRC_L = CRC_chk_buffer;
 				Uart_Read_Msg.CRC_H = CRC_chk_buffer>>8;
@@ -1460,17 +1458,17 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 	updateDataTotalByteLen = ((ReadNVMTemp[0]<<24)&0xFF000000) | ((ReadNVMTemp[1]<<16)&0xFF0000) | ((ReadNVMTemp[2]<<8)&0xFF00) | (ReadNVMTemp[3]&0xFF) ;
 	updateDataPackageCount = (updateDataTotalByteLen+(64-1))/64;  //进一法 e = (a+(b-1))/b	
 
-	for(i=0; i<((updateDataTotalByteLen+4)+(64-1))/64;i++)
+	for(i=0; i<((updateDataTotalByteLen+headerLen-1)+(64-1))/64;i++)//
 	{
 		memset(ReadNVMTemp, 0, 64);
-		if((i+1)*64 < (updateDataTotalByteLen+4))
+		if((i+1)*64 <= (updateDataTotalByteLen+headerLen-1))
 		{	
 			tempLen = 64;
 			BSP_QSPI_Read_Safe(ReadNVMTemp,FLASH_BMS_FOTA_START_ADDR+1+i*64,64);
 		}
 		else
 		{
-			tempLen = (updateDataTotalByteLen+4) - i*64;
+			tempLen = (updateDataTotalByteLen+headerLen-1) - i*64;
 			BSP_QSPI_Read_Safe(ReadNVMTemp,FLASH_BMS_FOTA_START_ADDR+1+i*64,tempLen);
 		}
 		
@@ -1478,7 +1476,7 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 		{
 			checkSumCal = (checkSumCal + ReadNVMTemp[j]) & 0xFF;
 		}
-		//osDelay(10);
+		osDelay(10);
 	}
 	if(checkSum != checkSumCal)
 	{
@@ -1521,7 +1519,7 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 				pUpdateMsgSend[5] = CRCtemp&0xFF;		//CRC Low
 				
 				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
+				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
 				#ifdef USING_PRINTF
 				printf("update step 1 answer,updateMsgReadLen = %x:\n",updateMsgReadLen);
 				
@@ -1621,8 +1619,8 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 				pUpdateMsgSend[5+dataLen] = CRCtemp&0xFF;		//CRC Low
 				
 				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
-				#ifdef USING_PRINTF1
+				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
+				#ifdef USING_PRINTF
 				printf("update step 3 answer:\n");
 				 for(ii=0;ii<updateMsgReadLen;ii++)
 					printf("%x ",bmsAnswerMsg[ii]);
@@ -1704,8 +1702,8 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 				pUpdateMsgSend[5+dataLen] = CRCtemp&0xFF;		//CRC Low
 				
 				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
-				#ifdef USING_PRINTF1
+				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
+				#ifdef USING_PRINTF
 				printf("update step 5 answer:\n");
 				 for(ii=0;ii<updateMsgReadLen;ii++)
 					printf("%x ",bmsAnswerMsg[ii]);
@@ -1769,14 +1767,14 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 
 					memset(ReadNVMTemp, 0, 64);
 					
-					if((i+1)*64 < (updateDataTotalByteLen))
+					if((i+1)*64 <= (updateDataTotalByteLen))
 					{	
 						tempLen = 64;
 						BSP_QSPI_Read_Safe(ReadNVMTemp,FLASH_BMS_FOTA_START_ADDR+headerLen+i*64,64);
 					}
 					else
 					{
-						tempLen = (updateDataTotalByteLen) - i*64;
+						tempLen = (updateDataTotalByteLen) - i*64;//
 						BSP_QSPI_Read_Safe(ReadNVMTemp,FLASH_BMS_FOTA_START_ADDR+headerLen+i*64,tempLen);
 					}
 
@@ -1804,8 +1802,8 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 					pUpdateMsgSend[5+dataLen] = CRCtemp&0xFF;		//CRC Low
 					
 					memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-					ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
-					#ifdef USING_PRINTF1
+					ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
+					#ifdef USING_PRINTF
 						printf("update step 7 answer:\n");
 					 for(ii=0;ii<updateMsgReadLen;ii++)
 						printf("%x ",bmsAnswerMsg[ii]);
@@ -1888,8 +1886,8 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 				pUpdateMsgSend[5] = CRCtemp&0xFF;		//CRC Low
 				
 				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
-				#ifdef USING_PRINTF1
+				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
+				#ifdef USING_PRINTF
 				printf("update step 9 answer:\n");
 				 for(ii=0;ii<updateMsgReadLen;ii++)
 					printf("%x ",bmsAnswerMsg[ii]);
@@ -1951,8 +1949,8 @@ updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
 				pUpdateMsgSend[5] = CRCtemp&0xFF;		//CRC Low
 				
 				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
-				#ifdef USING_PRINTF1
+				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 1000);
+				#ifdef USING_PRINTF
 				printf("update step A answer:\n");
 				 for(ii=0;ii<updateMsgReadLen;ii++)
 					printf("%x ",bmsAnswerMsg[ii]);