NMEA 值可以包含“*”吗? (星号)?
我正在尝试创建与 NMEA 兼容的专有句子,其中可能包含任意字符串。
带校验和的 NMEA 语句的常用格式为:
$GPxxx,val1,val2,...,valn*ck<cr><lf>
其中 *
标记 2 位校验和的开始。
我的问题是:任何值字段本身都可以包含 *
字符吗?
解析器似乎有可能等待最终的*
)。但我不知道标准是否允许。
还有其他字符可能会导致问题吗?
I am trying to create NMEA-compatible proprietary sentences, which may contain arbitrary strings.
The usual format for an NMEA sentence with checksum is:
$GPxxx,val1,val2,...,valn*ck<cr><lf>
where *
marks the start of a 2-digit checksum.
My question is: Can any of the value fields contain a *
character themselves?
It would seem possible for a parser to wait for the final <cr><lf>
, then to look back at the previous 3 characters to find the checksum if present (rather than just waiting for the first *
in the sentence). However I don't know if the standard allows it.
Are there other characters which may cause problems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
需要注意的两个 ASCII 字符是 $(必须位于开头)和 *(位于校验和之前)。其他任何解析您的自定义 NMEA 的人都不会期望在其他地方找到这些字符中的任何一个。一些解析器在遇到 $ 时认为新行已经开始。在串行端口通信中,有时字符会在传输过程中丢失,这就是为什么句子标记以 $ 开头。
如果您要创建自己的 NMEA 命令,通常以 P 开头,后跟 3 个字符的代码,指示创建专有消息的制造商或公司,因此您可以使用 $PSQU。请注意,尽管建议 NMEA 命令的长度为 5 个字符,但各种硬件和软件制造商也提供了长度从 4 个字符到 7 个字符不等的专有消息。
显然,如果您正在编写自己的解析器,您可以做您喜欢的事情。
这个网站相当有用:
http://www.gpsinformation.org/dale/nmea.htm
The two ASCII characters to be careful with are $, which has to be at the start, and * which precedes the checksum. Anyone else parsing your custom NMEA wouldn't expect to find either of those characters anywhere else. Some parsers, when they hit a $ assume that a new line has started. With serial port communication sometimes characters get lost in transit, and that's why there's a $ start of sentence marker.
If you're going to make your own NMEA commands it is customary to start them with P followed by a 3 character code indicating the manufacturer or company creating the proprietary message, so you could use $PSQU. Note that although it is recommended that NMEA commands are 5 characters long, there are proprietary messages out there by various hardware and software manufacturers that are anywhere from 4 characters to 7 characters long.
Obviously if you're writing your own parser you can do what you like.
This website is rather useful:
http://www.gpsinformation.org/dale/nmea.htm
如果您自己扩展协议(基于“专有”)-那么当然,您可以添加任何您喜欢的内容。我会坚持使用 ASCII,但在这些范围内会变得疯狂。 (显然,您需要提出自己的 $GPxxx,以免与现有消息冲突。也许是一个新标头 $SQUEL,...)
根据定义,专有消息将不与 NMEA 兼容。
监听 NMEA 流的标准解析器应该忽略任何与它认为的“好”数据不匹配的内容。这意味着校验和错误,或者任何大规模损坏的消息,例如它会认为您的新消息中添加了一些随机 * 。
如果您只是编写现有消息,那么 * 没有意义,应该被忽略,但是,如果校验和正确并且解析器无法理解有效负载,则您将面临出现重大问题的风险。
If you're extending the protocol yourself (based on "proprietary") - then sure, you can put in anything you like. I would stick to ASCII, but go wild within those bounds. (Obviously, you need to come up with your own $GPxxx so as not to clash with existing messages. Perhaps a new header $SQUEL, ...)
By definition, a proprietary message will not be NMEA-compatible.
A standard parser listening to an NMEA stream should ignore anything that doesn't match what it thinks is 'good' data. That means a checksum error, or any massively corrupted message like it would think your new message is with some random *s thrown in.
If you are merely writing an existing message, then a * doesn't make sense, and should be ignored, but you run the risk of major issues if the checksum is correct, and the parser doesn't understand the payload.