Browse Source

版本号为:2.1.0.9,修复2.1.0.8 线程竞争问题导致没有gps消息

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
2b84bcc190
5 changed files with 101 additions and 81 deletions
  1. 1 1
      inc/app.h
  2. 21 6
      src/CANTask.c
  3. 70 67
      src/GpsTask.c
  4. 1 1
      src/MainTask.c
  5. 8 6
      src/TcpTask.c

+ 1 - 1
inc/app.h

@@ -52,7 +52,7 @@ extern "C" {
 #define	DRVSWVERSION		0x01050000     //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
 #define	DRVSWVERSION		0x01050000     //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
 //#define	APPSWVERSION		0x01020209     
 //#define	APPSWVERSION		0x01020209     
 //#define	APPSWVERSION		0x02000103
 //#define	APPSWVERSION		0x02000103
-#define	APPSWVERSION		0x02010008
+#define	APPSWVERSION		0x02010009
 //--------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------
 
 
 #define APP_CONFIG_FILE_LATEST_VERSION 0
 #define APP_CONFIG_FILE_LATEST_VERSION 0

+ 21 - 6
src/CANTask.c

@@ -68,18 +68,18 @@ void CANTaskInit(void* arg)
 static void Can_Receive()
 static void Can_Receive()
 {    
 {    
 	slpManSlpState_t State;
 	slpManSlpState_t State;
-    uint8_t cnt,temp,udsFlag,msgFlag=0;
-	UINT8 i,j = 0;
+    uint8_t udsFlag,msgFlag=0;
+	UINT8 i = 0;
+	UINT16 delayconuter = 0;
+	CAN_Sleep_State = false;
     while(true)
     while(true)
     {
     {
 		memset(CanRxMsg, 0, sizeof(CanRxMsg));    		
 		memset(CanRxMsg, 0, sizeof(CanRxMsg));    		
 		switch(gProcess_CAN_Task)
 		switch(gProcess_CAN_Task)
 		{
 		{
 			case PROCESS_CAN_STATE_IDLE:
 			case PROCESS_CAN_STATE_IDLE:
-				CAN_Sleep_State = false;
-				
+				osDelay(2000);
 				PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_WORK);
 				PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_WORK);
-				
 				break;				
 				break;				
 			
 			
 			case PROCESS_CAN_STATE_WORK:
 			case PROCESS_CAN_STATE_WORK:
@@ -89,7 +89,8 @@ static void Can_Receive()
 					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
 					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
 				}
 				}
 				if(HAL_Can_Receive(CanRxMsg)>0)					
 				if(HAL_Can_Receive(CanRxMsg)>0)					
-				{						
+				{
+					delayconuter=0;						
 					for(i=0; i<2; i++)
 					for(i=0; i<2; i++)
 					{								
 					{								
 						if(CanRxMsg[i].Id == 0x7A0)
 						if(CanRxMsg[i].Id == 0x7A0)
@@ -128,6 +129,20 @@ static void Can_Receive()
 						CanMsgTx1000ms();							
 						CanMsgTx1000ms();							
 					}				
 					}				
 				}
 				}
+				else
+				{
+					delayconuter++;
+					osDelay(10);
+					if(delayconuter>=0xfffe)
+					{
+						delayconuter=0;
+					}
+				}
+				if(delayconuter>100)
+				{
+					delayconuter=0;
+					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
+				}
 				break;
 				break;
 				
 				
 	        case PROCESS_CAN_STATE_SLEEP:
 	        case PROCESS_CAN_STATE_SLEEP:

+ 70 - 67
src/GpsTask.c

@@ -65,85 +65,88 @@ static void GpsTask(void* arg)
     }
     }
     while(1)
     while(1)
     {
     {
-        char temp[] = "$GNRMC,082626.000,A,2939.91801,N,10637.09500,E,0.543,30.254,261120,,,A,V*17";
-        osMessageQueueGet(norGpsHandle, &msg, 0, osWaitForever);
-        if (msg.dataPtr)
-        {	
-            osStatus_t result = osMutexAcquire(GpsMutex, osWaitForever);//Gps数据锁	
-            p = strtok(msg.dataPtr,delim);//将信息进行分割
-            // #ifdef USING_PRINTF	
-            //     printf("\nP msgptr data:%s\r\n",p);
-            // #endif
-            int i=0;
-            p = strtok(p,",");//只取第1行的信息RMC
-            //p = strtok(temp,",");//模拟测试
-            if (strcmp(p,"$GNRMC")==0)
-            {			
-                while (p)
-                {	
-                    databuffer[i]=p;
-                    p = strtok(NULL,",");
-                    i++;;
-                }
-                if (strcmp(databuffer[1],"V")==0|strcmp(databuffer[2],"V")==0)
-                {
-                    memset(GpsData,0x00,sizeof(GpsData));
-                }
-                else if (strcmp(databuffer[2],"A")==0)
+        //char temp[] = "$GNRMC,082626.000,A,2939.91801,N,10637.09500,E,0.543,30.254,261120,,,A,V*17";
+        osStatus_t ret = osMessageQueueGet(norGpsHandle, &msg, 0, osWaitForever);
+        if(ret==0)
+        {
+            if (msg.dataPtr)
+            {	
+                osStatus_t result = osMutexAcquire(GpsMutex, osWaitForever);//Gps数据锁	
+                p = strtok(msg.dataPtr,delim);//将信息进行分割
+                #ifdef USING_PRINTF1
+                    printf("\nP msgptr data:%s\r\n",p);
+                #endif
+                p = strtok(p,",");//只取第1行的信息RMC
+                //p = strtok(temp,",");//模拟测试
+                if (strcmp(p,"$GNRMC")==0)
                 {
                 {
-                    GpsData[0] = 0x01;//有效,东经,北纬写定
-                    GpsData[1] = 03;//卫星数目写入1
-                    strdel(databuffer[3],'.');
-                    strdel(databuffer[5],'.');
-                    strdel(databuffer[7],'.');
-                    speedtemp = atol(databuffer[7])*1852/1e5;//节换算单位,1节=1.852km每小时
-                    GpsData[4] = (speedtemp>>8)&0xFF;
-                    GpsData[5] = speedtemp&0xFF; 
-                    latitude =location_handle(databuffer[3]);
-                    GpsData[8] = latitude>> 24;
-                    GpsData[9] = latitude>> 16;
-                    GpsData[10] = latitude>> 8;
-                    GpsData[11] = latitude;
-                    longitude = location_handle(databuffer[5]);
-                    GpsData[12] = longitude>>24;
-                    GpsData[13] = longitude>>16;
-                    GpsData[14] = longitude>>8;
-                    GpsData[15] = longitude;
-
-                    GpsData[6] = 0x03;
-                    GpsData[7] = 0xE8;
-                    if(speedtemp>=50)//大于5km/h才输出方位
-                    {
-                        direction = atol(databuffer[8]);
-                        GpsData[2] = direction>>8;
-                        GpsData[3] = direction;
+                    UINT8 i=0;			
+                    while (p)
+                    {	
+                        databuffer[i]=p;
+                        p = strtok(NULL,",");
+                        i++;;
                     }
                     }
-                    else
+                    if (strcmp(databuffer[1],"V")==0|strcmp(databuffer[2],"V")==0)
                     {
                     {
-                        GpsData[2] = 0xff;
-                        GpsData[3] = 0xfe;
+                        memset(GpsData,0x00,sizeof(GpsData));
                     }
                     }
-                    if(speedtemp>=30 && speedtemp<=1500 && WorkFlag==0x01)
+                    else if (strcmp(databuffer[2],"A")==0)
                     {
                     {
-                        AppDataInfo.appDataModify = true;
-                        AppDataInfo.AccMileage = speedtemp/36 + AppDataInfo.AccMileage;
-                        if(AppDataInfo.AccMileage>=0xfffffffe)
+                        GpsData[0] = 0x01;//有效,东经,北纬写定
+                        GpsData[1] = 03;//卫星数目写入1
+                        strdel(databuffer[3],'.');
+                        strdel(databuffer[5],'.');
+                        strdel(databuffer[7],'.');
+                        speedtemp = atol(databuffer[7])*1852/1e5;//节换算单位,1节=1.852km每小时
+                        GpsData[4] = (speedtemp>>8)&0xFF;
+                        GpsData[5] = speedtemp&0xFF; 
+                        latitude =location_handle(databuffer[3]);
+                        GpsData[8] = latitude>> 24;
+                        GpsData[9] = latitude>> 16;
+                        GpsData[10] = latitude>> 8;
+                        GpsData[11] = latitude;
+                        longitude = location_handle(databuffer[5]);
+                        GpsData[12] = longitude>>24;
+                        GpsData[13] = longitude>>16;
+                        GpsData[14] = longitude>>8;
+                        GpsData[15] = longitude;
+
+                        GpsData[6] = 0x03;
+                        GpsData[7] = 0xE8;
+                        if(speedtemp>=50)//大于5km/h才输出方位
+                        {
+                            direction = atol(databuffer[8]);
+                            GpsData[2] = direction>>8;
+                            GpsData[3] = direction;
+                        }
+                        else
                         {
                         {
-                            AppDataInfo.AccMileage = 0;
+                            GpsData[2] = 0xff;
+                            GpsData[3] = 0xfe;
                         }
                         }
+                        if(speedtemp>=30 && speedtemp<=1500 && WorkFlag==0x01)
+                        {
+                            AppDataInfo.appDataModify = true;
+                            AppDataInfo.AccMileage = speedtemp/36 + AppDataInfo.AccMileage;
+                            if(AppDataInfo.AccMileage>=0xfffffffe)
+                            {
+                                AppDataInfo.AccMileage = 0;
+                            }
 
 
+                        }
+                        GpsData[16] = AppDataInfo.AccMileage>>24;
+                        GpsData[17] = AppDataInfo.AccMileage>>16;
+                        GpsData[18] = AppDataInfo.AccMileage>>8;
+                        GpsData[19] = AppDataInfo.AccMileage;
                     }
                     }
-                    GpsData[16] = AppDataInfo.AccMileage>>24;
-                    GpsData[17] = AppDataInfo.AccMileage>>16;
-                    GpsData[18] = AppDataInfo.AccMileage>>8;
-                    GpsData[19] = AppDataInfo.AccMileage;
                 }
                 }
+                osMutexRelease(GpsMutex);
             }
             }
-        osMutexRelease(GpsMutex);
+            if(msg.dataPtr)
+                free(msg.dataPtr);
+            msg.dataPtr=NULL;
         }
         }
-        if(msg.dataPtr)
-            free(msg.dataPtr);
-        msg.dataPtr=NULL;
         if (Sleep_flag)
         if (Sleep_flag)
 		{
 		{
             posGGAServiceStop();
             posGGAServiceStop();

+ 1 - 1
src/MainTask.c

@@ -55,7 +55,7 @@ static UINT8                  gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE]
 static osThreadId_t           MainTaskId = NULL;
 static osThreadId_t           MainTaskId = NULL;
 uint8_t MainSlpHandler          = 0xff;//主线程睡眠句柄
 uint8_t MainSlpHandler          = 0xff;//主线程睡眠句柄
 uint8_t deepslpTimerID          = DEEPSLP_TIMER_ID7;//睡眠定时器ID
 uint8_t deepslpTimerID          = DEEPSLP_TIMER_ID7;//睡眠定时器ID
-volatile bool Work_timer_end = false;
+static volatile bool Work_timer_end = false;
 static process_Main 		    gProcess_Main_Task;
 static process_Main 		    gProcess_Main_Task;
 #define PROC_MAIN_STATE_SWITCH(a)  (gProcess_Main_Task = a)
 #define PROC_MAIN_STATE_SWITCH(a)  (gProcess_Main_Task = a)
 
 

+ 8 - 6
src/TcpTask.c

@@ -339,7 +339,7 @@ static void TcpDataInfoAssembleSend()
 	    BattToTcpInfo.dataLength[0] = (DataLen>>8) & 0xFF;
 	    BattToTcpInfo.dataLength[0] = (DataLen>>8) & 0xFF;
 	    BattToTcpInfo.dataLength[1] = DataLen & 0xFF;
 	    BattToTcpInfo.dataLength[1] = DataLen & 0xFF;
        
        
-        #ifdef USING_PRINTF
+        #ifdef USING_PRINTF1
             printf("year:%x,month:%d,day:%d,hour:%d,minute:%d,second:%d\n",UTC8TimeTcp.year,UTC8TimeTcp.month,UTC8TimeTcp.day,UTC8TimeTcp.hour,UTC8TimeTcp.minute,UTC8TimeTcp.second);
             printf("year:%x,month:%d,day:%d,hour:%d,minute:%d,second:%d\n",UTC8TimeTcp.year,UTC8TimeTcp.month,UTC8TimeTcp.day,UTC8TimeTcp.hour,UTC8TimeTcp.minute,UTC8TimeTcp.second);
         #endif
         #endif
         BattToTcpInfo.battInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; 	//year
         BattToTcpInfo.battInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; 	//year
@@ -441,7 +441,6 @@ static void TcpDataInfoAssembleSend()
         minute=(TimeStracture.UTCtimer2&0xff0000)>>16;
         minute=(TimeStracture.UTCtimer2&0xff0000)>>16;
         sec=(TimeStracture.UTCtimer2&0xff00)>>8;
         sec=(TimeStracture.UTCtimer2&0xff00)>>8;
         UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp,year,month,day,hour,minute,sec);
         UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp,year,month,day,hour,minute,sec);
-
         DataLen= (UINT16)sizeof(GpsToTcpInfo.gpsInfo);
         DataLen= (UINT16)sizeof(GpsToTcpInfo.gpsInfo);
         GpsToTcpInfo.startSymbol[0] = TCP_START_SYM1;
         GpsToTcpInfo.startSymbol[0] = TCP_START_SYM1;
 	    GpsToTcpInfo.startSymbol[1] = TCP_START_SYM2;
 	    GpsToTcpInfo.startSymbol[1] = TCP_START_SYM2;
@@ -480,10 +479,13 @@ static void TcpDataInfoAssembleSend()
                 TcpSendLen = 0xFB & TcpSendLen;
                 TcpSendLen = 0xFB & TcpSendLen;
             }
             }
         }
         }
+        #ifdef USING_PRINTF1
+            printf("GpsMsg:\n");
+            UINT8* p = (UINT8 *)&GpsToTcpInfo;  
+            for(int i =0 ;i<sizeof(GpsToTcpInfo);i++)
+                printf("%x ",*(p+i));
+        #endif
     }
     }
-    #ifdef USING_PRINTF
-        printf("Version report! send_counter:%d\n",send_counter);
-    #endif
     if(send_counter==1)//版本信息上报
     if(send_counter==1)//版本信息上报
     {
     {
         VersionMsgtoTcpType VerMsgToTcpInfo;
         VersionMsgtoTcpType VerMsgToTcpInfo;
@@ -616,7 +618,7 @@ static void TcpDataInfoAssembleSend()
         DebugMsgInfo.CRC = bcc_chk(SendBuffer, BufferLen+sizeof(DebugMsgInfo)-1);
         DebugMsgInfo.CRC = bcc_chk(SendBuffer, BufferLen+sizeof(DebugMsgInfo)-1);
         memcpy(SendBuffer+BufferLen+sizeof(DebugMsgInfo)-1,&DebugMsgInfo.CRC,1);
         memcpy(SendBuffer+BufferLen+sizeof(DebugMsgInfo)-1,&DebugMsgInfo.CRC,1);
         len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen+sizeof(DebugMsgInfo), 0, 0, 0);
         len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen+sizeof(DebugMsgInfo), 0, 0, 0);
-        #ifdef USING_PRINTF
+        #ifdef USING_PRINTF1
             printf("DebugMsgInfo!\n");
             printf("DebugMsgInfo!\n");
             UINT8* p = SendBuffer;
             UINT8* p = SendBuffer;
             for(i =0 ;i<BufferLen+sizeof(DebugMsgInfo);i++)
             for(i =0 ;i<BufferLen+sizeof(DebugMsgInfo);i++)