Kaynağa Gözat

Gps线程更改

CHENJIE-PC\QiXiang_CHENJIE 4 yıl önce
ebeveyn
işleme
0f2809b485
3 değiştirilmiş dosya ile 225 ekleme ve 110 silme
  1. 11 1
      inc/app.h
  2. 0 12
      inc/hal_module_adapter.h
  3. 214 97
      src/app.c

+ 11 - 1
inc/app.h

@@ -61,7 +61,17 @@ typedef struct Fota_Type
     uint8_t Fota_CRC ;
 
 }Fota_Type;
-
+typedef struct  _GPS_INFO
+{
+	uint8_t timedata[6];
+	uint8_t status;
+	uint8_t satellite_num;
+	uint16_t direction;
+	uint16_t speed;
+	uint16_t altitude;
+	uint32_t latitude;
+	uint32_t longitude;
+}GPS_INFO;
 uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece_buffer,uint8_t Data_Len);
 
 #ifdef __cplusplus

+ 0 - 12
inc/hal_module_adapter.h

@@ -123,18 +123,6 @@ typedef struct _Can_TxMsgType
     UINT8 Data[8];
 }Can_TxMsgType;
 
-typedef struct  _GPS_INFO
-{
-	uint8_t timedata[6];
-	uint8_t status;
-	uint8_t satellite_num;
-	uint16_t direction;
-	uint16_t speed;
-	uint16_t altitude;
-	uint32_t latitude;
-	uint32_t longitude;
-}GPS_INFO;
-
 typedef void (*posGGACallBack )(UINT8 res, UINT8 * params);
 void PowerPinConfig(IOType iotype);
 

+ 214 - 97
src/app.c

@@ -75,12 +75,12 @@ Fota_Type Fota_Struct;
 //Tcp线程定义
 
 //GPS线程定义
-#define GPS_TASK_STACK_SIZE   				(1024)
+#define PROC_GPS_TASK_STACK_SIZE   				(1024)
 static QueueHandle_t gpsMsgQueue = NULL;
 static QueueHandle_t norGpsHandle = NULL;
 static osThreadId_t gpsTaskHandle = NULL;
-static UINT8                   gpsTaskStack[GPS_TASK_STACK_SIZE];
-static StaticTask_t gpsTask = NULL;
+static UINT8                   gProcess_Gps_TaskStack[PROC_GPS_TASK_STACK_SIZE];
+static StaticTask_t gProcess_Gps_Task_t = NULL;
 GPS_INFO Gps_Data;
 
 //函数声明区
@@ -136,8 +136,8 @@ static void Main_Task(void* arg)
     uint32_t Uart_time = 0;
     uint32_t sleep_time_value;
     int32_t inParam = 0xAABBCCDD;
-    uint32_t Chrgend_Work_time = 180000;
-    uint32_t Wakeup_Work_time = 30000;
+    uint32_t Chrgend_Work_time = 18000;
+    uint32_t Wakeup_Work_time = 3000;
     uint32_t Sleep_Time = 20000;
     //上述参数应写入文件里
     slpManSlpState_t State;
@@ -201,10 +201,10 @@ static void Main_Task(void* arg)
             }
             case PROCESS_STATE_WORK:
             {
-                osDelay(10/portTICK_PERIOD_MS);
+                osDelay(100/portTICK_PERIOD_MS);
                 sleep_count++;
                 Uart_time++;
-                if (Uart_time >100)
+                if (Uart_time >10)
                 {
                     Uart_time = 0;
                     PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WORK);
@@ -234,8 +234,11 @@ static void Main_Task(void* arg)
                     if(Uart_Sleep_State)
                         break;
                     Sleep_Flag = true;
+                    #ifdef USING_PRINTF
+                        printf("Uart_Sleep_State:%d\r\n",Uart_Sleep_State);
+                    #endif
+                    osDelay(1000/portTICK_PERIOD_MS);
                 }
-                osDelay(1000/portTICK_PERIOD_MS);
                 if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
                 {
                     #ifdef USING_PRINTF
@@ -596,7 +599,7 @@ static void Fota_Task(void* arg)
                         printf("%X ",temp[0]);
                     }
                 #endif
-                osDelay(5000);
+                osDelay(1000);
                 EC_SystemReset();
 
             }
@@ -615,8 +618,34 @@ static void Fota_Task(void* arg)
         }
     }
 }
+// 字符串删除函数
+void strdel(char * str,char c)
+{
+	char *p = str;
+	while(*str)
+	{
+		if(*str!=c)
+			*p++ = *str;
+		str++;
+	}
+	*p = '\0';
+}
+//位置信息处理
+uint32_t location_handle(char *in1)
+{
+	uint32_t location_temp;
+	uint32_t location_degree;
+	uint32_t location_min;
+	location_temp = atol(in1);
+	location_degree = location_temp/(1e7);
+	location_degree = location_degree*(1e6);
+	location_min = location_temp-location_degree*10;
+	location_min = location_min/6;
+	location_temp = location_degree+location_min;
+	return location_temp;
+} 
 //Gps线程
-static void GpsProcess(void* arg)
+static void Gps_Task(void* arg)
 {
     gpsReqMsg msg;
 	GPS_INFO Gps_buffer;
@@ -625,79 +654,175 @@ static void GpsProcess(void* arg)
 	char *p=NULL;
 	const char *delim = "\n";
 	char *databuffer[14];
+    int data_index;
+    osStatus_t Queue_flag;
 	/**
 	 *databuffer内容格式:
 	 *  定位标识,时间,位置有效标识,纬度,纬度指示,经度,经度指示,地面速率,地面航向,日期
 	 **/
-    posGGAServiceStart(norGpsHandle);
+    //posGGAServiceStart(norGpsHandle);
     while(1)
     {
-		//char temp[] = "$GNGGA,082626.00,2939.91801,N,10637.09500,E,1,03,2.34,-20.3,M,,M,,*40";
+        osDelay(1000);
+	    //Queue_flag = osMessageQueueGet(norGpsHandle, &msg, 0, 2000);
+        #ifdef USING_PRINTF	
+            printf("Queue_flag [%d]\r\n",Queue_flag);
+        #endif 
+        if(Queue_flag==0)
+        {
+            /*
+                    handle event
+            */
+            #ifdef USING_PRINTF	
+                printf("GpsProcess [%d] %s\r\n",msg.len,msg.dataPtr);
+            #endif 
+            if(msg.dataPtr)
+                free(msg.dataPtr);
+            msg.dataPtr=NULL;
+        }
+
+
+        /**模拟测试结果解析正确
 		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)
-		{		
-			void  *msgtemp = msg.dataPtr;//取指针
-			p = strtok(msg.dataPtr,delim);//将信息进行分割
-			int i=0;
-			p = strtok(p,",");//只取第1行的信息RMC
-			p = strtok(temp,",");//模拟测试
-			if (strcmp(p,"$GNRMC")==0)
-			{			
-				while (p)
-				{	
-					#ifdef USING_PRINTF	
-						printf("p:%s\r\n",p);
-					#endif
-					databuffer[i]=p;
-					p = strtok(NULL,",");
-					i++;;
-				}
-				if (strcmp(databuffer[1],"V")==0|strcmp(databuffer[2],"V")==0)
-				{
+        #ifdef USING_PRINTF
+            printf("temp:%s\n ",temp);
+        #endif
+        p = strtok(temp,",");//模拟测试
+        #ifdef USING_PRINTF	
+			printf("p:%s\r\n",p);
+		#endif
+        if (strcmp(p,"$GNRMC")==0)
+        {
+            data_index = 0;
+            while (p)
+            {	
+                #ifdef USING_PRINTF	
+                    printf("%s",p);
+                #endif
+                databuffer[data_index]=p;
+                p = strtok(NULL,",");
+                data_index++;;
+            }
+            #ifdef USING_PRINTF	
+                printf("databuffer:\t");
+                for (int i = 0; i < data_index; i++)
+                {
+                    printf("%s-",databuffer[i]);
+                }
+                printf("\n");
+            #endif
+            if (strcmp(databuffer[1],"V")==0|strcmp(databuffer[2],"V")==0)
+            {
+                #ifdef USING_PRINTF	
+                    printf("Gpsdata invalide\n");
+                #endif 
+                Gps_buffer.status = 0x00;
+                Gps_buffer.speed = 0xffff;
+                Gps_buffer.direction= 0xffff;
+            }
+            else if (strcmp(databuffer[2],"A")==0)
+            {
+                uint32_t speedtemp;
+                #ifdef USING_PRINTF	
+                    printf("Gpsdata valide\n");
+                #endif 
+                Gps_buffer.status = 0x01;//有效,东经,北纬写定
+                Gps_buffer.satellite_num = 03;//卫星数目写入1
+                strdel(databuffer[3],'.');
+                strdel(databuffer[5],'.');
+                strdel(databuffer[7],'.');
+                speedtemp = atol(databuffer[7])*1852;//节换算单位,1节=1.852km每小时
+                Gps_buffer.speed = speedtemp/1e5;
+                Gps_buffer.latitude = location_handle(databuffer[3]);
+                Gps_buffer.longitude = location_handle(databuffer[5]);
+                Gps_buffer.altitude = 00;
+                if(Gps_buffer.speed>=100)//大于10km/h才输出方位
+                {
+                    Gps_buffer.direction = atol(databuffer[8]);
+                }
+                Gps_buffer.direction = 0xfffe;
+            }
+            #ifdef USING_PRINTF	
+                printf("Gps_buffer:%x,%x,%x,%x",Gps_buffer.direction,Gps_buffer.speed,Gps_buffer.latitude,Gps_buffer.longitude);
+            #endif
+        }
+        **/
+
+
 
-					#ifdef USING_PRINTF	
-						printf("Gpsdata invalide\n");
-					#endif 
-					Gps_buffer.status = 0x00;
-					Gps_buffer.speed = 0xffff;
-					Gps_buffer.direction= 0xffff;
+		// //char temp[] = "$GNGGA,082626.00,2939.91801,N,10637.09500,E,1,03,2.34,-20.3,M,,M,,*40";
+		// Queue_flag = osMessageQueueGet(norGpsHandle, &msg, 0, 1000);
+        // #ifdef USING_PRINTF
+        //     printf("Queue_flag:%d\n ",Queue_flag);
+        // #endif
+		// if (msg.dataPtr)
+		// {		
+			// void  *msgtemp = msg.dataPtr;//取指针
+			// p = strtok(msg.dataPtr,delim);//将信息进行分割
+            // #ifdef USING_PRINTF
+            //     printf("%s ",msg.dataPtr);
+            // #endif
+			// p = strtok(p,",");//只取第1行的信息RMC
+			// p = strtok(temp,",");//模拟测试
+            // #ifdef USING_PRINTF	
+			// 	printf("p:%s\r\n",p);
+			// #endif
+			// if (strcmp(p,"$GNRMC")==0)
+			// {			
+			// 	while (p)
+			// 	{	
+			// 		#ifdef USING_PRINTF	
+			// 			printf("p:%s\r\n",p);
+			// 		#endif
+			// 		databuffer[i]=p;
+			// 		p = strtok(NULL,",");
+			// 		i++;;
+			// 	}
+			// 	if (strcmp(databuffer[1],"V")==0|strcmp(databuffer[2],"V")==0)
+			// 	{
 
-				}
-				else if (strcmp(databuffer[2],"A")==0)
-				{
-					uint32_t speedtemp;
-					#ifdef USING_PRINTF	
-						printf("Gpsdata valide\n");
-					#endif 
-					Gps_buffer.status = 0x01;//有效,东经,北纬写定
-					Gps_buffer.satellite_num = 03;//卫星数目写入1
-					strdel(databuffer[3],'.');
-					strdel(databuffer[5],'.');
-					strdel(databuffer[7],'.');
-					speedtemp = atol(databuffer[7])*1852;//节换算单位,1节=1.852km每小时
-					Gps_buffer.speed = speedtemp/1e5;
-					Gps_buffer.latitude = location_handle(databuffer[3]);
-					Gps_buffer.longitude = location_handle(databuffer[5]);
-					Gps_buffer.altitude = 00;
-					if(Gps_buffer.speed>=100)//大于10km/h才输出方位
-					{
-						Gps_buffer.direction = atol(databuffer[8]);
-					}
-					Gps_buffer.direction = 0xfffe;
-				}
-				osMessageQueuePut(gpsMsgQueue, &Gps_buffer, 0, 1000);
-			}
-			free(msgtemp);
-			msgtemp=NULL;
-		}
-		msg.dataPtr=NULL;
-		if (Sleep_Flag)
-		{
-            posGGAServiceStop();
-			osThreadExit();
-			break;
-		}
+			// 		#ifdef USING_PRINTF	
+			// 			printf("Gpsdata invalide\n");
+			// 		#endif 
+			// 		Gps_buffer.status = 0x00;
+			// 		Gps_buffer.speed = 0xffff;
+			// 		Gps_buffer.direction= 0xffff;
+
+			// 	}
+			// 	else if (strcmp(databuffer[2],"A")==0)
+			// 	{
+			// 		uint32_t speedtemp;
+			// 		#ifdef USING_PRINTF	
+			// 			printf("Gpsdata valide\n");
+			// 		#endif 
+			// 		Gps_buffer.status = 0x01;//有效,东经,北纬写定
+			// 		Gps_buffer.satellite_num = 03;//卫星数目写入1
+			// 		strdel(databuffer[3],'.');
+			// 		strdel(databuffer[5],'.');
+			// 		strdel(databuffer[7],'.');
+			// 		speedtemp = atol(databuffer[7])*1852;//节换算单位,1节=1.852km每小时
+			// 		Gps_buffer.speed = speedtemp/1e5;
+			// 		Gps_buffer.latitude = location_handle(databuffer[3]);
+			// 		Gps_buffer.longitude = location_handle(databuffer[5]);
+			// 		Gps_buffer.altitude = 00;
+			// 		if(Gps_buffer.speed>=100)//大于10km/h才输出方位
+			// 		{
+			// 			Gps_buffer.direction = atol(databuffer[8]);
+			// 		}
+			// 		Gps_buffer.direction = 0xfffe;
+			// 	}
+				// osMessageQueuePut(gpsMsgQueue, &Gps_buffer, 0, 1000);
+			// }
+		// 	free(msg.dataPtr);
+		// 	msg.dataPtr=NULL;
+		// }
+		// msg.dataPtr=NULL;
+		// if (Sleep_Flag)
+		// {
+        //     posGGAServiceStop();
+		// 	osThreadExit();
+		// 	break;
+		// }
     }
 }
 //Uart线程初始化
@@ -709,7 +834,7 @@ void Uart_Task_Init()
     task_attr.name = "Uart_Task";
     task_attr.stack_mem = gProcess_Uart_TaskStack;
     task_attr.stack_size = PROC_UART_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;
+    task_attr.priority = osPriorityBelowNormal7;
     task_attr.cb_mem = &gProcess_Uart_Task_t;
     task_attr.cb_size = sizeof(StaticTask_t);
     osThreadNew(Uart_Task, NULL, &task_attr);
@@ -722,36 +847,28 @@ void Fota_Task_Init()
     task_attr.name = "Fota_Task";
     task_attr.stack_mem = gProcess_Fota_TaskStack;
     task_attr.stack_size = PROC_FOTA_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;
+    task_attr.priority = osPriorityBelowNormal7;
     task_attr.cb_mem = &gProcess_Fota_Task_t;
     task_attr.cb_size = sizeof(StaticTask_t);
     osThreadNew(Fota_Task, NULL, &task_attr);
 }
 //Gps线程初始化
-INT32 GpsTaskInit(void)
+void Gps_Task_Init()
 {
-	if(norGpsHandle == NULL)
+    if(norGpsHandle == NULL)
 	{
 		norGpsHandle = osMessageQueueNew(1,sizeof(gpsReqMsg), NULL);
-		if(norGpsHandle == NULL)
-			return 1;
-	}
-	if(gpsTaskHandle == NULL)
-	{
-		osThreadAttr_t task_attr;
-		memset(&task_attr , 0 , sizeof(task_attr));
-		task_attr.name = "GPS";
-		task_attr.priority = osPriorityNormal1;
-		task_attr.cb_mem = &gpsTask;
-		task_attr.cb_size = sizeof(StaticTask_t);
-		task_attr.stack_mem = gpsTaskStack;
-		task_attr.stack_size =GPS_TASK_STACK_SIZE;
-		memset(& gpsTaskStack, 0xa5, GPS_TASK_STACK_SIZE);
-		gpsTaskHandle = osThreadNew(GpsProcess , NULL,&task_attr);
-		if(gpsTaskHandle == NULL)
-			return 1;
 	}
-	return 0;
+    osThreadAttr_t task_attr;
+    memset(&task_attr,0,sizeof(task_attr));
+    memset(gProcess_Gps_TaskStack, 0xA5, PROC_GPS_TASK_STACK_SIZE);
+    task_attr.name = "Gps_Task";
+    task_attr.stack_mem = gProcess_Gps_TaskStack;
+    task_attr.stack_size = PROC_GPS_TASK_STACK_SIZE;
+    task_attr.priority = osPriorityBelowNormal7;
+    task_attr.cb_mem = &gProcess_Gps_Task_t;
+    task_attr.cb_size = sizeof(StaticTask_t);
+    osThreadNew(Gps_Task, NULL, &task_attr);
 }
 //主任务线程初始化
 void Main_Task_Init()
@@ -778,7 +895,7 @@ void appInit(void *arg)
     Main_Task_Init();
     Uart_Task_Init();
     Fota_Task_Init();
-    GpsTaskInit();
+    //Gps_Task_Init();
 }
 //主函数入口
 void main_entry(void)