1)解析实现

gps_main.c

  1. #include <nmea/nmea.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <stdint.h>
  5. #include <stdlib.h>
  6.  
  7. #include "nrf_gpio.h"
  8. #include "gps_main.h"
  9. #include "main.h"
  10.  
  11. #define GPS_PIN 27
  12.  
  13. static struct gps_t
  14. {
  15. char buf[];
  16. uint8_t index;
  17. enum gps_state_t
  18. {
  19. GPS_NULL,
  20. START,
  21. PAYLOAD,
  22. END,
  23. } gps_state;
  24. } gps;
  25.  
  26. void gps_on(void)
  27. {
  28. nrf_gpio_cfg_output(GPS_PIN);
  29. nrf_gpio_pin_set(GPS_PIN);
  30. memset(gps.buf,,sizeof(char)*);
  31. gps.gps_state = START;
  32. gps.index = ;
  33. }
  34.  
  35. void gps_off(void)
  36. {
  37. nrf_gpio_pin_clear(GPS_PIN);
  38. }
  39.  
  40. void gps_buf_fill_data(uint8_t cr)
  41. {
  42. switch (gps.gps_state)
  43. {
  44. case START:
  45. if(cr == '$')
  46. {
  47. gps.buf[gps.index++] = cr;
  48. gps.gps_state = PAYLOAD;
  49. }
  50. else gps.gps_state = START;
  51. break;
  52.  
  53. case PAYLOAD:
  54. if(cr == '\r')
  55. {
  56. gps.gps_state = END;
  57. }
  58. gps.buf[gps.index++] = cr;
  59. break;
  60.  
  61. case END:
  62. if(cr == '\n')
  63. {
  64. if( xSemaphoreGive( gpsSemaphore ) != pdTRUE )
  65. {
  66. }
  67. gps.buf[gps.index] = cr;
  68. }
  69. break;
  70.  
  71. default:
  72. break;
  73. }
  74. }
  75.  
  76. void gps_thread(void * arg)
  77. {
  78. nmeaINFO info;
  79. nmeaPARSER parser;
  80.  
  81. int size_nmeaINFO = sizeof(nmeaINFO);
  82. int size_nmeaPARSER = sizeof(nmeaPARSER);
  83.  
  84. nmea_zero_INFO(&info);
  85. nmea_parser_init(&parser);
  86.  
  87. static uint8_t gps_nmea_scanning = ;
  88. static int inuse_value = ;
  89. static int inview_value = ;
  90.  
  91. gps_on();
  92.  
  93. for (;;)
  94. {
  95. if( xSemaphoreTake( gpsSemaphore, ( TickType_t ) ) )
  96. {
  97. switch (gps_nmea_scanning)
  98. {
  99. case :
  100. if(strstr(gps.buf,"$GPRMC")!=NULL)
  101. {
  102. if ((nmea_parse(&parser, (char*)gps.buf, (int)strlen((char*)gps.buf), &info)) > )
  103. {
  104. printf("inuse %d\r\n",inuse_value);
  105. printf("inview %d\r\n",inview_value);
  106. printf("sig %d\r\n",info.sig);
  107. printf("fix %d\r\n",info.fix);
  108. printf("year %d\r\n",info.utc.year);
  109. printf("mon %d\r\n",info.utc.mon);
  110. printf("day %d\r\n",info.utc.day);
  111. printf("hour %d\r\n",info.utc.hour);
  112. printf("min %d\r\n",info.utc.min);
  113. printf("sec %d\r\n",info.utc.sec);
  114. printf("lon %.5f\r\n",info.lon);
  115. printf("lat %.5f\r\n",info.lat);
  116. printf("speed %.2f\r\n",info.speed);
  117. }
  118. gps_nmea_scanning = ;
  119. }
  120. break;
  121.  
  122. case :
  123. if(strstr(gps.buf,"$GPGGA")!=NULL)
  124. {
  125. /*
  126. MTK的GPS模组GPGGA协议内容是14项,nmealib库是解析的12项,这里手动解算inuse
  127. if ((nmea_parse(&parser, (char*)gps.buf, (int)strlen((char*)gps.buf), &info)) > 0 )
  128. */
  129. char inuse_buf[];
  130. int count = , index = ;
  131. for (index = ; index < strlen(gps.buf); ++index)
  132. {
  133. if (gps.buf[index] == ',')
  134. ++count;
  135. if (count == )
  136. break;
  137. }
  138. strncpy(inuse_buf, &gps.buf[index+], );
  139. int n = atoi(inuse_buf);
  140. inuse_value = n;
  141. gps_nmea_scanning = ;
  142. }
  143. break;
  144.  
  145. case :
  146. if(strstr(gps.buf,"$GPGSV")!=NULL)
  147. {
  148. if ((nmea_parse(&parser, (char*)gps.buf, (int)strlen((char*)gps.buf), &info)) > )
  149. {
  150. inview_value = info.satinfo.inview;
  151. }
  152. gps_nmea_scanning = ;
  153. }
  154. break;
  155.  
  156. default:
  157. break;
  158. }
  159.  
  160. memset(gps.buf,,sizeof(char)*);
  161. gps.index = ;
  162. gps.gps_state = START;
  163. }
  164. }
  165. }

gps_main.h

  1. #ifndef GPS_MAIN_H__
  2. #define GPS_MAIN_H__
  3.  
  4. #include <stdint.h>
  5.  
  6. void gps_on(void);
  7. void gps_off(void);
  8. void gps_buf_fill_data(uint8_t cr);
  9.  
  10. void gps_thread(void * arg);
  11.  
  12. #endif

2)在串口接收函数中填充GPS缓存即可

  1. gps_buf_fill_data(cr);

3)附件demo打包下载http://files.cnblogs.com/files/dong1/gps.rar

end

MTK MT33xx型GPS的NMEA协议解析实例的更多相关文章

  1. GPS之NMEA协议20160526

    NMEA 0183是美国国家海洋电子协会(National Marine Electronics Association)为海用电子设备制定的标准格式.现在已经成为GPS导航设备统一的RTCM(Rad ...

  2. nmea协议

    NMEA协议 信息类型为: GPGSV:可见卫星信息 GPGLL:地理定位信息 GPRMC:推荐最小定位信息 GPVTG:地面速度信息 GPGGA:GPS定位信息 GPGSA:当前卫星信息 1. Gl ...

  3. SYN2306C型 GPS北斗授时导航接收机

    SYN2306C型 GPS北斗授时导航接收机 北斗对时系统北斗标准同步时钟北斗卫星校时器使用说明视频链接: http://www.syn029.com/h-pd-222-0_310_36_-1.htm ...

  4. SYN2306B型 GPS北斗双模授时板

    SYN2306B型 GPS北斗双模授时板 产品概述 SYN2306B型GPS北斗双模授时板是由西安同步电子科技有限公司精心设计.自行研发生产的一款双模授时板卡,接收北斗或者GPS北斗混合授时卫星信号, ...

  5. SYN2306A型 GPS北斗双模授时板

    SYN2306A型 GPS北斗双模授时板 北斗gps时钟北斗授时设备北斗时钟同步系统使用说明视频链接: http://www.syn029.com/h-pd-211-0_310_36_-1.html ...

  6. ts 协议解析

    pes : http://wenku.baidu.com/link?url=KjcA0qXqZ1bWVQTa8i1YOmygofldSQL7Pjj-zGRw1e_6_LFmVLo5DIWF0SNwVn ...

  7. [转]netty对http协议解析原理

    本文主要介绍netty对http协议解析原理,着重讲解keep-alive,gzip,truncked等机制,详细描述了netty如何实现对http解析的高性能. 1 http协议 1.1 描述 标示 ...

  8. NMEA协议 上位机 C# (转)

    源:NMEA协议 上位机 c# 前些时间写做了两款用NMEA协议的上位机,在这里做一个总结和记录.和大家分享,也为了以后不会忘记. NMEA协议总体来说,相对简单,是气象上比较成熟的协议. 主要有以下 ...

  9. twemproxyRedis协议解析探索——剖析twemproxy代码正编

    这篇文章会对twemproxyRedis协议解析代码部分进行一番简单的分析,同时给出twemproxy目前支持的所有Redis命令.在这篇文章开始前,我想大家去简单地理解一下有限状态机,当然不理解也是 ...

随机推荐

  1. cstore_fdw的安装使用以及源码分析

    一.cstore_fdw的简介 https://github.com/citusdata/cstore_fdw,此外部表扩展是由citusdata公司开发,使用RC_file格式对数据进行列式存储. ...

  2. Mac MySQL启动不了解决办法(MySQL卸载重新安装教程)

    一段时间没用MySQL,今天使用时突然发现启动不了了,怎么点start都没用,或者输入密码了  还是没用... 好急...找了一圈资料,没发现特别好的解决办法,只能使用大招了----->< ...

  3. pitch yaw roll是什么

    虚拟现实 三维空间的右手笛卡尔坐标如图1所示. 图1 在航空中,pitch, yaw, roll如图2所示. pitch是围绕X轴旋转,也叫做俯仰角,如图3所示. yaw是围绕Y轴旋转,也叫偏航角,如 ...

  4. 升级Ubuntu 16.04 LTS后 DSL拨号上网(ppp)连接自动断开解决办法

    原本在Ubuntu 15.10用拨号上网没有问题,但升级了16.04 LTS后发现原来的DSL连接不上了.主要表现为: 1.在NetworkManager里面选择DSL Connection能够尝试拨 ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. [LeetCode] Palindrome Partitioning 拆分回文串

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  7. [LeetCode] String to Integer (atoi) 字符串转为整数

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  8. c#与JavaScript实现对用户名、密码进行RSA非对称加密

    博主最近手上这个项目呢(就是有上百个万恶的复杂excel需要解析的那个项目,参见博客:http://www.cnblogs.com/csqb-511612371/p/4885930.html),由于是 ...

  9. 高介分类:核方法与支持向量机(SVM)

        数据模型:并不是简单地二维数据,多个维度或者对象的数据聚合起来      {           persion1's attr1:value1,...,persion1's attrN:va ...

  10. dateRangePicker时间范围控件

    Github:https://github.com/dangrossman/bootstrap-daterangepicker/ 使用daterangepicker()为元素创建一个时间范围控件 &l ...