MTK MT33xx型GPS的NMEA协议解析实例
1)解析实现
gps_main.c
- #include <nmea/nmea.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #include "nrf_gpio.h"
- #include "gps_main.h"
- #include "main.h"
- #define GPS_PIN 27
- static struct gps_t
- {
- char buf[];
- uint8_t index;
- enum gps_state_t
- {
- GPS_NULL,
- START,
- PAYLOAD,
- END,
- } gps_state;
- } gps;
- void gps_on(void)
- {
- nrf_gpio_cfg_output(GPS_PIN);
- nrf_gpio_pin_set(GPS_PIN);
- memset(gps.buf,,sizeof(char)*);
- gps.gps_state = START;
- gps.index = ;
- }
- void gps_off(void)
- {
- nrf_gpio_pin_clear(GPS_PIN);
- }
- void gps_buf_fill_data(uint8_t cr)
- {
- switch (gps.gps_state)
- {
- case START:
- if(cr == '$')
- {
- gps.buf[gps.index++] = cr;
- gps.gps_state = PAYLOAD;
- }
- else gps.gps_state = START;
- break;
- case PAYLOAD:
- if(cr == '\r')
- {
- gps.gps_state = END;
- }
- gps.buf[gps.index++] = cr;
- break;
- case END:
- if(cr == '\n')
- {
- if( xSemaphoreGive( gpsSemaphore ) != pdTRUE )
- {
- }
- gps.buf[gps.index] = cr;
- }
- break;
- default:
- break;
- }
- }
- void gps_thread(void * arg)
- {
- nmeaINFO info;
- nmeaPARSER parser;
- int size_nmeaINFO = sizeof(nmeaINFO);
- int size_nmeaPARSER = sizeof(nmeaPARSER);
- nmea_zero_INFO(&info);
- nmea_parser_init(&parser);
- static uint8_t gps_nmea_scanning = ;
- static int inuse_value = ;
- static int inview_value = ;
- gps_on();
- for (;;)
- {
- if( xSemaphoreTake( gpsSemaphore, ( TickType_t ) ) )
- {
- switch (gps_nmea_scanning)
- {
- case :
- if(strstr(gps.buf,"$GPRMC")!=NULL)
- {
- if ((nmea_parse(&parser, (char*)gps.buf, (int)strlen((char*)gps.buf), &info)) > )
- {
- printf("inuse %d\r\n",inuse_value);
- printf("inview %d\r\n",inview_value);
- printf("sig %d\r\n",info.sig);
- printf("fix %d\r\n",info.fix);
- printf("year %d\r\n",info.utc.year);
- printf("mon %d\r\n",info.utc.mon);
- printf("day %d\r\n",info.utc.day);
- printf("hour %d\r\n",info.utc.hour);
- printf("min %d\r\n",info.utc.min);
- printf("sec %d\r\n",info.utc.sec);
- printf("lon %.5f\r\n",info.lon);
- printf("lat %.5f\r\n",info.lat);
- printf("speed %.2f\r\n",info.speed);
- }
- gps_nmea_scanning = ;
- }
- break;
- case :
- if(strstr(gps.buf,"$GPGGA")!=NULL)
- {
- /*
- MTK的GPS模组GPGGA协议内容是14项,nmealib库是解析的12项,这里手动解算inuse
- if ((nmea_parse(&parser, (char*)gps.buf, (int)strlen((char*)gps.buf), &info)) > 0 )
- */
- char inuse_buf[];
- int count = , index = ;
- for (index = ; index < strlen(gps.buf); ++index)
- {
- if (gps.buf[index] == ',')
- ++count;
- if (count == )
- break;
- }
- strncpy(inuse_buf, &gps.buf[index+], );
- int n = atoi(inuse_buf);
- inuse_value = n;
- gps_nmea_scanning = ;
- }
- break;
- case :
- if(strstr(gps.buf,"$GPGSV")!=NULL)
- {
- if ((nmea_parse(&parser, (char*)gps.buf, (int)strlen((char*)gps.buf), &info)) > )
- {
- inview_value = info.satinfo.inview;
- }
- gps_nmea_scanning = ;
- }
- break;
- default:
- break;
- }
- memset(gps.buf,,sizeof(char)*);
- gps.index = ;
- gps.gps_state = START;
- }
- }
- }
gps_main.h
- #ifndef GPS_MAIN_H__
- #define GPS_MAIN_H__
- #include <stdint.h>
- void gps_on(void);
- void gps_off(void);
- void gps_buf_fill_data(uint8_t cr);
- void gps_thread(void * arg);
- #endif
2)在串口接收函数中填充GPS缓存即可
- gps_buf_fill_data(cr);
3)附件demo打包下载http://files.cnblogs.com/files/dong1/gps.rar
end
MTK MT33xx型GPS的NMEA协议解析实例的更多相关文章
- GPS之NMEA协议20160526
NMEA 0183是美国国家海洋电子协会(National Marine Electronics Association)为海用电子设备制定的标准格式.现在已经成为GPS导航设备统一的RTCM(Rad ...
- nmea协议
NMEA协议 信息类型为: GPGSV:可见卫星信息 GPGLL:地理定位信息 GPRMC:推荐最小定位信息 GPVTG:地面速度信息 GPGGA:GPS定位信息 GPGSA:当前卫星信息 1. Gl ...
- SYN2306C型 GPS北斗授时导航接收机
SYN2306C型 GPS北斗授时导航接收机 北斗对时系统北斗标准同步时钟北斗卫星校时器使用说明视频链接: http://www.syn029.com/h-pd-222-0_310_36_-1.htm ...
- SYN2306B型 GPS北斗双模授时板
SYN2306B型 GPS北斗双模授时板 产品概述 SYN2306B型GPS北斗双模授时板是由西安同步电子科技有限公司精心设计.自行研发生产的一款双模授时板卡,接收北斗或者GPS北斗混合授时卫星信号, ...
- SYN2306A型 GPS北斗双模授时板
SYN2306A型 GPS北斗双模授时板 北斗gps时钟北斗授时设备北斗时钟同步系统使用说明视频链接: http://www.syn029.com/h-pd-211-0_310_36_-1.html ...
- ts 协议解析
pes : http://wenku.baidu.com/link?url=KjcA0qXqZ1bWVQTa8i1YOmygofldSQL7Pjj-zGRw1e_6_LFmVLo5DIWF0SNwVn ...
- [转]netty对http协议解析原理
本文主要介绍netty对http协议解析原理,着重讲解keep-alive,gzip,truncked等机制,详细描述了netty如何实现对http解析的高性能. 1 http协议 1.1 描述 标示 ...
- NMEA协议 上位机 C# (转)
源:NMEA协议 上位机 c# 前些时间写做了两款用NMEA协议的上位机,在这里做一个总结和记录.和大家分享,也为了以后不会忘记. NMEA协议总体来说,相对简单,是气象上比较成熟的协议. 主要有以下 ...
- twemproxyRedis协议解析探索——剖析twemproxy代码正编
这篇文章会对twemproxyRedis协议解析代码部分进行一番简单的分析,同时给出twemproxy目前支持的所有Redis命令.在这篇文章开始前,我想大家去简单地理解一下有限状态机,当然不理解也是 ...
随机推荐
- cstore_fdw的安装使用以及源码分析
一.cstore_fdw的简介 https://github.com/citusdata/cstore_fdw,此外部表扩展是由citusdata公司开发,使用RC_file格式对数据进行列式存储. ...
- Mac MySQL启动不了解决办法(MySQL卸载重新安装教程)
一段时间没用MySQL,今天使用时突然发现启动不了了,怎么点start都没用,或者输入密码了 还是没用... 好急...找了一圈资料,没发现特别好的解决办法,只能使用大招了----->< ...
- pitch yaw roll是什么
虚拟现实 三维空间的右手笛卡尔坐标如图1所示. 图1 在航空中,pitch, yaw, roll如图2所示. pitch是围绕X轴旋转,也叫做俯仰角,如图3所示. yaw是围绕Y轴旋转,也叫偏航角,如 ...
- 升级Ubuntu 16.04 LTS后 DSL拨号上网(ppp)连接自动断开解决办法
原本在Ubuntu 15.10用拨号上网没有问题,但升级了16.04 LTS后发现原来的DSL连接不上了.主要表现为: 1.在NetworkManager里面选择DSL Connection能够尝试拨 ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- [LeetCode] Palindrome Partitioning 拆分回文串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- [LeetCode] String to Integer (atoi) 字符串转为整数
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...
- c#与JavaScript实现对用户名、密码进行RSA非对称加密
博主最近手上这个项目呢(就是有上百个万恶的复杂excel需要解析的那个项目,参见博客:http://www.cnblogs.com/csqb-511612371/p/4885930.html),由于是 ...
- 高介分类:核方法与支持向量机(SVM)
数据模型:并不是简单地二维数据,多个维度或者对象的数据聚合起来 { persion1's attr1:value1,...,persion1's attrN:va ...
- dateRangePicker时间范围控件
Github:https://github.com/dangrossman/bootstrap-daterangepicker/ 使用daterangepicker()为元素创建一个时间范围控件 &l ...