Browse Source

新增GPS线程

CHENJIE-PC\QiXiang_CHENJIE 4 years ago
parent
commit
e72c296f65
1 changed files with 122 additions and 8 deletions
  1. 122 8
      src/app.c

+ 122 - 8
src/app.c

@@ -27,7 +27,7 @@
 #define Batt_Temp_Num  (7)//默认数值5、7
 #define Batt_Cell_Num_2 (Batt_Cell_Num*2)
 //主任务调度定义
-#define PROC_MAIN_TASK_STACK_SIZE           (1024)
+#define PROC_MAIN_TASK_STACK_SIZE           (512)
 static StaticTask_t             gProcess_Main_Task_t;
 static UINT8                  gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE];
 uint8_t deepslpTimerID          = DEEPSLP_TIMER_ID7;
@@ -40,6 +40,7 @@ typedef enum
 }process_Main;
 static process_Main 		    gProcess_Main_Task = PROCESS_STATE_IDLE;
 #define PROC_MAIN_STATE_SWITCH(a)  (gProcess_Main_Task = a)
+volatile bool Sleep_Flag = false;//主线程睡眠标志位
 //Uart线程定义 
 #define PROC_UART_TASK_STACK_SIZE           (1024)
 static StaticTask_t             gProcess_Uart_Task_t;
@@ -74,6 +75,13 @@ Fota_Type Fota_Struct;
 //Tcp线程定义
 
 //GPS线程定义
+#define 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;
+GPS_INFO Gps_Data;
 
 //函数声明区
 void Uart_func(void);
@@ -225,7 +233,7 @@ static void Main_Task(void* arg)
                     PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_SLEEP);
                     if(Uart_Sleep_State)
                         break;
-
+                    Sleep_Flag = true;
                 }
                 osDelay(1000/portTICK_PERIOD_MS);
                 if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
@@ -592,12 +600,6 @@ static void Fota_Task(void* arg)
                 EC_SystemReset();
 
             }
-            #ifdef USING_PRINTF1
-                printf("Uart_Rece_buffer:");
-                for(int i=0;i<110;i++)
-                    printf("%x ",Uart_Rece_buffer[i]);
-                printf("\n");
-            #endif
             Uart_Send_buffer[0] = Fota_Struct.Fota_Current_Addres>>24;
             Uart_Send_buffer[1] = Fota_Struct.Fota_Current_Addres>>16;
             Uart_Send_buffer[2] = Fota_Struct.Fota_Current_Addres>>8;
@@ -613,6 +615,91 @@ static void Fota_Task(void* arg)
         }
     }
 }
+//Gps线程
+static void GpsProcess(void* arg)
+{
+    gpsReqMsg msg;
+	GPS_INFO Gps_buffer;
+	Gps_buffer.latitude = 0xffffffff;
+	Gps_buffer.longitude = 0xffffffff;
+	char *p=NULL;
+	const char *delim = "\n";
+	char *databuffer[14];
+	/**
+	 *databuffer内容格式:
+	 *  定位标识,时间,位置有效标识,纬度,纬度指示,经度,经度指示,地面速率,地面航向,日期
+	 **/
+    posGGAServiceStart(norGpsHandle);
+    while(1)
+    {
+		//char temp[] = "$GNGGA,082626.00,2939.91801,N,10637.09500,E,1,03,2.34,-20.3,M,,M,,*40";
+		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("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(msgtemp);
+			msgtemp=NULL;
+		}
+		msg.dataPtr=NULL;
+		if (Sleep_Flag)
+		{
+            posGGAServiceStop();
+			osThreadExit();
+			break;
+		}
+    }
+}
 //Uart线程初始化
 void Uart_Task_Init()
 {
@@ -640,6 +727,32 @@ void Fota_Task_Init()
     task_attr.cb_size = sizeof(StaticTask_t);
     osThreadNew(Fota_Task, NULL, &task_attr);
 }
+//Gps线程初始化
+INT32 GpsTaskInit(void)
+{
+	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;
+}
 //主任务线程初始化
 void Main_Task_Init()
 {
@@ -665,6 +778,7 @@ void appInit(void *arg)
     Main_Task_Init();
     Uart_Task_Init();
     Fota_Task_Init();
+    GpsTaskInit();
 }
 //主函数入口
 void main_entry(void)