123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- /****************************************************************************
- *
- * Copy right: Qx.Chen jie
- * File name: GpsTask.c
- * Description: Gps处理任务
- * History: 2021-03-07
- *
- ****************************************************************************/
- #include "bsp.h"
- #include "bsp_custom.h"
- #include "osasys.h"
- #include "ostask.h"
- #include "queue.h"
- #include "ps_event_callback.h"
- #include "app.h"
- #include "cmisim.h"
- #include "cmimm.h"
- #include "cmips.h"
- #include "sockets.h"
- #include "psifevent.h"
- #include "ps_lib_api.h"
- #include "lwip/netdb.h"
- //#include <cis_def.h>
- #include "debug_log.h"
- #include "slpman_ec616.h"
- #include "plat_config.h"
- #include "ec_tcpip_api.h"
- #include "app.h"
- #include "MainTask.h"
- #include "GpsTask.h"
- #include "TcpTask.h"
- //全局变量区输入
- extern volatile BOOL Sleep_flag;
- extern AppDataBody AppDataInfo;
- extern UINT8 WorkFlag;
- //全局变量区输出
- UINT8 GpsData[20];
- osMutexId_t GpsMutex = NULL;
- //线程定义区
- #define GPS_TASK_STACK_SIZE (512)
- static QueueHandle_t norGpsHandle = NULL;
- static osThreadId_t gpsTaskHandle = NULL;
- static StaticTask_t gpsTask = NULL;
- static UINT8 gpsTaskStack[GPS_TASK_STACK_SIZE];
- //函数声明区
- void strdel(char * str,char c);
- UINT32 location_handle(char *in1);
- static void GpsTask(void* arg)
- {
- gpsReqMsg msg;
- char *p=NULL;
- const char *delim = "\n";
- char *databuffer[14];
- UINT32 speedtemp;
- UINT32 latitude;
- UINT32 longitude;
- UINT16 direction;
- posGGAServiceStart(norGpsHandle);
- posGGAReset();
- if(GpsMutex == NULL)
- {
- GpsMutex = osMutexNew(NULL);
- }
- while(1)
- {
- //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)
- {
- UINT8 i=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)
- {
- 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
- {
- 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;
- }
- }
- osMutexRelease(GpsMutex);
- }
- if(msg.dataPtr)
- free(msg.dataPtr);
- msg.dataPtr=NULL;
- }
- if (Sleep_flag)
- {
- posGGAServiceStop();
- osThreadExit();
- break;
- }
- }
- }
- 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 = osPriorityBelowNormal6;
- 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(GpsTask , NULL,&task_attr);
- if(gpsTaskHandle == NULL)
- return 1;
- }
-
- return 0;
- }
- /*----------------------------------------*/
- // 字符串删除函数
- void strdel(char * str,char c)
- {
- char *p = str;
- while(*str)
- {
- if(*str!=c)
- *p++ = *str;
- str++;
- }
- *p = '\0';
- }
- UINT32 location_handle(char *in1)
- {
- UINT32 location_temp;
- UINT32 location_degree;
- UINT32 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;
- }
|