从小工具读取GPS数据 [英] Reading GPS data from a gadget

查看:157
本文介绍了从小工具读取GPS数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GPS小工具,我想知道如何从它接收C ++(坐标)的信息?

解决方案

这可能比评论指出的更容易回答。虽然大多数GPS装置 支持专用(通常)二进制协议,但几乎所有甚至接近当前的都支持NMEA格式的数据,并且默认提供它。无论是通过串行端口,蓝牙还是USB连接,大多数也可以看到像串行端口这样的用户程序。



IOW,你可能支持90%单元只需打开一个串口,并从中读取数据。唯一难得的是,数据格式的 NMEA标准相当昂贵(虽然它不像以前那么糟糕 - 你现在可以只买它关心的部分,这只是说附录B,IIRC)。



幸运的是,除非你打算让你的软件获得海事或飞机导航认证,否则你可能不需要 - 有大量的网站,涵盖了您可能关心的(几个)邮件类型。对于这个问题,如果你只是打开一个终端程序在正确的COM端口,看看数据,它不是很难找到自己的纬度/经度所有(至少如果你至少有一个模糊的概念,你在哪里

CSV格式 - 每行一个记录,字段之间用逗号分隔。它都是普通的ASCII / ANSI文本,所以获取坐标主要是检查第一个字段说它是正确的记录($ GPGGA),然后获取字段3,4,5和6(3和4是纬度,5和6经度-3和5给出数字,4和6具有N或S和E或W以指示北/南纬度和东/西经度)。您可能还需要检查其后的字段是否包含1或2,分别表示正常或差分GPS定位(0表示没有GPS定位,因此无效数据)。



这不是很重要,但你也应该意识到,你可能会收到几个其他字段类型,其中一些也包含修复数据。 $ GPGGA恰恰就是我使用的 - 有其他人可能是一样好,但我从来没有太多理由去看别人,因为一个人已经足够我需要/做的。 / p>

编辑:以下是从GPS接收到的数据转储示例,通过蓝牙虚拟串行端口:



$ GPGGA,090809.103,3901.4345,N,10448.2482,W,0,00,50.0,2078.2,M,-21.4,M,0.0,0000 * 43
$ GPRMC,090809.103,V,3901.4345,N,10448.2482,W,0.00,0.00,220311 ,, * 07
$ GPVTG,0.00,T ,, M,0.00,N,0.0,K * 60
$ GPGGA,090810.103,3901.4345,N,10448.2482,W,0,00,50.0,2078.2,M,-21.4,M,0.0,0000 * 4B



第二$ GPGGA记录:



<$> GPGGA,090810.103,3901.4345,N,10448.2482,W,0,00,50.0,2078.2,M,-21.4,M, 0000 * 4B



$ GPGGA是记录(Sentence)类型标识符。

090810.103是当前UTC时间。 br>
3901.4345,N是纬度。

10448.2482,W是经度。

下一个:0告诉您纬度/经度是不是有效。



纬度和经度都是格式化的(IIRC)之前的小数点是分钟,小数点后面是小数点的分数,因此3901.4345真的意味着39º1.4345的北纬。


I have a GPS gadget, and I would like to know how I can receive information with C++ (coordinates) from it?

解决方案

This is probably easier to answer than the comments indicate. While most GPS units do support proprietary (usually) binary protocols, nearly all that are even close to current also support NMEA-formatted data, and will supply it by default. Whether connected by serial port, bluetooth or USB, most also look to user programs like a serial port.

IOW, you can probably support something like 90% of reasonably current GPS units simply by opening a serial port, and reading data from it. The only ugly part is that the NMEA standard for the data format is fairly expensive (though it's not as bad as it used to be -- you can now buy just the parts of it you care about, which is to say only appendix B, IIRC).

Fortunately, unless you're planning to get your software certified for marine or aircraft navigation, you probably don't need that -- there are a fair number of web sites that cover the (few) message types you probably care about. For that matter, if you just open up a terminal program on the right COM port and look at the data, it's not too hard to find the latitude/longitude all by yourself (at least if you have at least a vague notion of where you are).

It's basically CSV format -- one record per line, with fields separated by commas. It's all in normal ASCII/ANSI text, so getting coordinates is mostly a matter of checking that the first field says it's the right kind of record ("$GPGGA"), then getting fields 3, 4 5, and 6 (3 and 4 are latitude and 5 and 6 longitude -- 3 and 5 give the number, 4 and 6 have "N", or "S" and "E" or "W" to indicate north/south latitude and East/West longitude). You'll probably also want to check that the field after that contains "1" or "2", indicating a normal or Differential GPS fix respectively (a "0" would indicate no GPS fix, so invalid data).

Not that it matters a lot, but you should probably also realize that there are several other field types you'll probably receive, and some of them contain fix data as well. $GPGGA just happens to be the one I've used -- there are others that are probably just as good, but I've never had much reason to look at others, because that one's been adequate for what I needed/did.

Edit: Here's a sample dump of data exactly as it's received from the GPS, in this case over a Bluetooth virtual serial port:

$GPGGA,090809.103,3901.4345,N,10448.2482,W,0,00,50.0,2078.2,M,-21.4,M,0.0,0000*43 $GPRMC,090809.103,V,3901.4345,N,10448.2482,W,0.00,0.00,220311,,*07 $GPVTG,0.00,T,,M,0.00,N,0.0,K*60 $GPGGA,090810.103,3901.4345,N,10448.2482,W,0,00,50.0,2078.2,M,-21.4,M,0.0,0000*4B

In the second $GPGGA record:

$GPGGA,090810.103,3901.4345,N,10448.2482,W,0,00,50.0,2078.2,M,-21.4,M,0.0,0000*4B

"$GPGGA" is the record ("Sentence") type identifier.
"090810.103" is the current UTC time.
"3901.4345,N" is the latitude.
"10448.2482,W" is the longitude.
The next: "0" is telling you that the preceding latitude/longitude are not valid.

The latitude and longitude are both formatted (IIRC) with the last two places before the decimal point being the minutes, and what's after the decimal point the fractions of a minute, so the `3901.4345" really means 39º 1.4345' north latitude.

这篇关于从小工具读取GPS数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆