AppTaskGps.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * @Author: chenjie
  3. * @Date: 2022-06-06
  4. * @LastEditTime: 2022-10-27
  5. * @LastEditors: chenjie
  6. * @Description:
  7. * @FilePath: \undefinedd:\1_WorkFiles\1_Device\2_4G_G1\2_SW\workspace\S32K146_4G\code\app\AppTaskGps.c
  8. * Copyright (c) 2022 by chenjie, All Rights Reserved.
  9. */
  10. #include "AppTaskGps.h"
  11. void strdel(char *str, char c);
  12. uint32 location_handle(char *in1);
  13. void GpsDataDecode(uint8 *msg);
  14. uint8 GpsRecvPtr[1024];
  15. uint32 timerCounterGetdata = 0;
  16. static void vtimerCallback(TimerHandle_t pxTimer)
  17. {
  18. uint32 ulTimerID;
  19. ulTimerID = (uint32)pvTimerGetTimerID(pxTimer);
  20. if (ulTimerID == 0)
  21. {
  22. timerCounterGetdata++;
  23. }
  24. }
  25. void GpsTask(void *pvParameters)
  26. {
  27. (void)pvParameters;
  28. GpsDataQueueHandle = xQueueCreate(1, sizeof(GPSInfo));//长度为1才可以允许覆写
  29. Dio_WriteChannel(DioConf_DioChannel_PTD1_GPIO_OUT_MCU_GPS_POW_EN, STD_ON);//GPS开机
  30. uint16 pReadLen = 0;
  31. TimerHandle_t monitorTimer1ms;
  32. monitorTimer1ms = xTimerCreate("monitor1ms", 1, pdTRUE, (void *)0, vtimerCallback);
  33. xTimerStart(monitorTimer1ms, 0);
  34. real_T S0[SIZE_FFT];
  35. real_T S1[SIZE_FFT];
  36. real_T S2[SIZE_FFT];
  37. uint8 fftIdx = 0;
  38. while(1)
  39. {
  40. memset(GpsRecvPtr,0,sizeof(GpsRecvPtr));
  41. UART_Receive_Data(UART_LPUART2,GpsRecvPtr,&pReadLen,1);
  42. if(pReadLen>0)
  43. {
  44. GpsDataDecode(GpsRecvPtr);
  45. }
  46. if (timerCounterGetdata % 10 == 0)
  47. {
  48. SL_SC7A20_Read_XYZ_Data(xyzData);
  49. S0[fftIdx] = (real_T)xyzData[0];
  50. S1[fftIdx] = (real_T)xyzData[1];
  51. S2[fftIdx] = (real_T)xyzData[2];
  52. fftIdx++;
  53. }
  54. if (fftIdx >= SIZE_FFT)
  55. {
  56. fftIdx = 0;
  57. fft(S0, sizeof(S0) / sizeof(real_T), 100, returnFreq[0], returnP[0]); // 50 max
  58. fft(S1, sizeof(S1) / sizeof(real_T), 100, returnFreq[1], returnP[1]);
  59. fft(S2, sizeof(S2) / sizeof(real_T), 100, returnFreq[2], returnP[2]);
  60. }
  61. }
  62. }
  63. void GpsDataDecode(uint8 *msg)
  64. {
  65. //char temp[] = "$GNRMC,082626.000,A,2939.91801,N,10637.09500,E,0.543,30.254,261120,,,A,V*17";
  66. char *p = NULL;
  67. char *p2 = NULL;
  68. const char *delim = "\n";
  69. GPSInfo GpsInfoData;
  70. uint8 index = 0;
  71. char *databuffer[20];
  72. uint32 speedtemp;
  73. uint32 latitude;
  74. uint32 longitude;
  75. uint16 direction;
  76. memset((uint8 *)&GpsInfoData, 0x00, sizeof(GPSInfo));
  77. p = strtok(msg, delim); //将信息进行分割
  78. p2 = strtok(NULL, delim);
  79. p = strtok(p, ","); //只取第1行的信息RMC
  80. //p = strtok(temp,",");//模拟测试
  81. if (strcmp(p, "$GNRMC") == 0)
  82. {
  83. index = 0;
  84. while (p)
  85. {
  86. databuffer[index] = p;
  87. p = strtok(NULL, ",");
  88. index++;
  89. }
  90. if (index > 5 && strcmp(databuffer[2], "A") == 0)
  91. {
  92. GpsInfoData.locateMark = 0x01; //有效,东经,北纬写定
  93. strdel(databuffer[3], '.');
  94. strdel(databuffer[5], '.');
  95. strdel(databuffer[7], '.');
  96. speedtemp = atol(databuffer[7]) * 1852 / 1e5; //节换算单位,1节=1.852km每小时
  97. GpsInfoData.speed[0] = (speedtemp >> 8) & 0xFF;
  98. GpsInfoData.speed[1] = speedtemp & 0xFF;
  99. latitude = location_handle(databuffer[3]);
  100. GpsInfoData.latitude[0] = latitude >> 24;
  101. GpsInfoData.latitude[1] = latitude >> 16;
  102. GpsInfoData.latitude[2] = latitude >> 8;
  103. GpsInfoData.latitude[3] = latitude;
  104. longitude = location_handle(databuffer[5]);
  105. GpsInfoData.longitude[0] = longitude >> 24;
  106. GpsInfoData.longitude[1] = longitude >> 16;
  107. GpsInfoData.longitude[2] = longitude >> 8;
  108. GpsInfoData.longitude[3] = longitude;
  109. if (speedtemp >= 50) //大于5km/h才输出方位
  110. {
  111. direction = atol(databuffer[8]);
  112. GpsInfoData.direction[0] = direction >> 8;
  113. GpsInfoData.direction[1] = direction;
  114. }
  115. else
  116. {
  117. GpsInfoData.direction[0] = 0xff;
  118. GpsInfoData.direction[1] = 0xff;
  119. }
  120. // if (speedtemp >= 30 && speedtemp <= 1500 && BattWorkStateDelay == 0x01)
  121. // {
  122. // AppDataInfo.appDataModify = true;
  123. // AppDataInfo.AccMileage = speedtemp / 36 + AppDataInfo.AccMileage;
  124. // if (AppDataInfo.AccMileage >= 0xfffffffe)
  125. // {
  126. // AppDataInfo.AccMileage = 0;
  127. // }
  128. // }累计里程的累加
  129. }
  130. // GpsInfoData.AccMileage[0] = AppDataInfo.AccMileage >> 24;
  131. // GpsInfoData.AccMileage[1] = AppDataInfo.AccMileage >> 16;
  132. // GpsInfoData.AccMileage[2] = AppDataInfo.AccMileage >> 8;
  133. // GpsInfoData.AccMileage[3] = AppDataInfo.AccMileage;
  134. }
  135. p2 = strtok(p2, ","); //只取第2行的信息GGA
  136. memset(databuffer, 0x30, 20);
  137. if (strcmp(p2, "$GNGGA") == 0)
  138. {
  139. index = 0;
  140. while (p2)
  141. {
  142. databuffer[index] = p2;
  143. p2 = strtok(NULL, ",");
  144. index++;
  145. }
  146. if (index > 9 && (strcmp(databuffer[6], "1") == 0 || strcmp(databuffer[6], "2") == 0))
  147. {
  148. GpsInfoData.satelliteNum = atol(databuffer[7]); //卫星数目写入
  149. strdel(databuffer[9], '.');
  150. uint16 alt = 0;
  151. alt = atol(databuffer[9]) / 10 + 1000;
  152. GpsInfoData.altitude[0] = alt >> 8; //海拔
  153. GpsInfoData.altitude[1] = alt;
  154. strdel(databuffer[2], '.');
  155. strdel(databuffer[4], '.');
  156. latitude = location_handle(databuffer[2]);
  157. GpsInfoData.latitude[0] = latitude >> 24;
  158. GpsInfoData.latitude[1] = latitude >> 16;
  159. GpsInfoData.latitude[2] = latitude >> 8;
  160. GpsInfoData.latitude[3] = latitude;
  161. longitude = location_handle(databuffer[4]);
  162. GpsInfoData.longitude[0] = longitude >> 24;
  163. GpsInfoData.longitude[1] = longitude >> 16;
  164. GpsInfoData.longitude[2] = longitude >> 8;
  165. GpsInfoData.longitude[3] = longitude;
  166. }
  167. }
  168. xQueueOverwrite(GpsDataQueueHandle,(uint8 *)&GpsInfoData);
  169. }
  170. void strdel(char *str, char c)
  171. {
  172. char *p = str;
  173. while (*str)
  174. {
  175. if (*str != c)
  176. *p++ = *str;
  177. str++;
  178. }
  179. *p = '\0';
  180. }
  181. uint32 location_handle(char *in1)
  182. {
  183. uint32 location_temp;
  184. uint32 location_degree;
  185. uint32 location_min;
  186. location_temp = atol(in1);
  187. location_degree = location_temp / (1e7);
  188. location_degree = location_degree * (1e6);
  189. location_min = location_temp - location_degree * 10;
  190. location_min = location_min / 6;
  191. location_temp = location_degree + location_min;
  192. return location_temp;
  193. }