replacing-nmea.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE article PUBLIC
  3. "-//OASIS//DTD DocBook XML V4.1.2//EN"
  4. "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
  5. <!ENTITY howto "http://en.tldp.org/HOWTO/">
  6. <!ENTITY mini-howto "http://en.tldp.org/HOWTO/mini/">
  7. <!ENTITY homepage "http://catb.org/~esr/">
  8. ]>
  9. <article>
  10. <title>Towards a Better GPS Protocol</title>
  11. <articleinfo>
  12. <author>
  13. <firstname>Eric</firstname>
  14. <othername>Steven</othername>
  15. <surname>Raymond</surname>
  16. <affiliation>
  17. <orgname><ulink url="&homepage;">
  18. Thyrsus Enterprises</ulink></orgname>
  19. <address>
  20. <email>esr@thyrsus.com</email>
  21. </address>
  22. </affiliation>
  23. </author>
  24. <copyright>
  25. <year>2004</year>
  26. <holder role="mailto:esr@thyrsus.com">Eric S. Raymond</holder>
  27. </copyright>
  28. <!-- legalnotice>
  29. <title>Copyright</title>
  30. <para>Permission is granted to copy, distribute and/or modify
  31. this document under the terms of the Open Publication License,
  32. version 2.0.</para>
  33. </legalnotice -->
  34. <revhistory>
  35. <revision>
  36. <revnumber>1.0</revnumber>
  37. <date>04 January 2005</date>
  38. <authorinitials>esr</authorinitials>
  39. <revremark>
  40. Initial draft.
  41. </revremark>
  42. </revision>
  43. <revision>
  44. <revnumber>1.1</revnumber>
  45. <date>11 February 2005</date>
  46. <authorinitials>esr</authorinitials>
  47. <revremark>
  48. Corrected SGPS example, thanks to Kevin Niehage for the bug report.
  49. </revremark>
  50. </revision>
  51. <revision>
  52. <revnumber>1.2</revnumber>
  53. <date>25 April 2005</date>
  54. <authorinitials>esr</authorinitials>
  55. <revremark>
  56. Specify UTC. Fix time-uncertainty units. Vertical course
  57. angle changed to climb/sink rate.
  58. </revremark>
  59. </revision>
  60. <revision>
  61. <revnumber>1.3</revnumber>
  62. <date>16 November 2006</date>
  63. <authorinitials>esr</authorinitials>
  64. <revremark>
  65. Added GPSVID and GPSGP, changed to mandate ISO8601 dates.
  66. </revremark>
  67. </revision>
  68. <revision>
  69. <revnumber>1.4</revnumber>
  70. <date>21 November 2006</date>
  71. <authorinitials>esr</authorinitials>
  72. <revremark>
  73. Fixed timestamp to Zulu time. Specified signed latitude.
  74. </revremark>
  75. </revision>
  76. <revision>
  77. <revnumber>1.5</revnumber>
  78. <date>25 February 2009</date>
  79. <authorinitials>esr</authorinitials>
  80. <revremark>
  81. Fixed GPSGP so the response isn't identical to the send,
  82. avoiding problems on multidrop lines. Added SGPS revision
  83. field to $GPVID. Went back to requiring checksums, because
  84. you just know it was going to bite someday otherwise.
  85. Changed sentence length limit to 255.
  86. </revremark>
  87. </revision>
  88. <revision>
  89. <revnumber>1.6</revnumber>
  90. <date>5 January 2016</date>
  91. <authorinitials>esr</authorinitials>
  92. <revremark>
  93. Corrected timezone in example
  94. W3 datetime document has disapperard, point to Internet Archive
  95. </revremark>
  96. </revision>
  97. </revhistory>
  98. <abstract>
  99. <para>The NMEA 0183 protocol used by GPS units might best be described as
  100. "layer upon layer of cruft". In this paper, we examine the problems
  101. and consider a cleaner design.</para>
  102. </abstract>
  103. </articleinfo>
  104. <sect1><title>What's Wrong with NMEA 0183, and Why Fix It?</title>
  105. <para>The protocol used by GPS devices to report to computers is a
  106. small subset of NMEA 0183. NMEA stands for "National Marine
  107. Electronics Association", and the features GPSes use for reporting
  108. time/position/velocity information are a small part of a protocol
  109. originally designed for communication between parts of complex marine
  110. navigation systems. Thus the full protocol includes support for depth
  111. sounders, LORAN, and many other things irrelevant to a modern GPS.</para>
  112. <para>The lowest level of NMEA 0183 is quite sensibly designed. The
  113. protocol consists of sentences, each led by a dollar sign and an
  114. identifying text tag, followed by multiple comma-separated textual
  115. fields, ended by an asterisk, a checksum, and LF/CR. This is a
  116. simple, clean format with good extensibility, easy to parse and
  117. generate. It is well adapted to its job, which is to pass
  118. small amounts of numeric and status information. The textual
  119. format makes it easy to log NMEA sessions, edit them, and play them
  120. back &mdash; a substantial advantage in developing talker and
  121. parser software.</para>
  122. <para>Unfortunately, the good news ends there. The design of the
  123. upper layers of NMEA 0183 is patchy, kludgy, and replete with the kind
  124. of errors that arise from growth by accretion rather than forethought.
  125. Here are some of the more obvious problems:</para>
  126. <itemizedlist>
  127. <listitem><para> NMEA timestamps usually (e.g in GPBWC, GPBWR, GPGBS,
  128. GPGGA, GPGLL, GPGXA, GPTRF, GPZTG) report time-of-day only. The
  129. exceptions (GPRMC, GPTRF, GPZDA) report only two digits of year and no
  130. century. Time precision is unspecified, usually to the second though
  131. some devices report a fractional decimal part to millisecond
  132. precision. </para></listitem>
  133. <listitem><para>
  134. It is not possible to get a time/position/velocity report in a single
  135. sentence. Some sentences (GPRMC) report time and 2D position and velocity,
  136. some (GPGGA) report time and 3D position, some (GPVTG) report velocity
  137. only. As a result, the API for a protocol client is complicated by
  138. the necessity of maintaining separate age indications for 2D position,
  139. 3D position, and velocity,
  140. </para></listitem>
  141. <listitem><para>
  142. NMEA sentences have at least three kinds of validity indicators &mdash; mode
  143. (GPGSA only), status (GPGLL, GPGGA), and the Active/Void field (GPRMC,
  144. GPGLL). And that's before we get into the FAA extensions in late
  145. revisions of the protocol. Interpreting these status bits is a black
  146. art involving knowledge of undocumented and often vendor-specific quirks.
  147. </para></listitem>
  148. <listitem><para>
  149. There is no standard way of indicating that part of a
  150. time/position/velocity report is invalid (e.g. because the device does
  151. not have a fix of the required quality). Many devices simply report 0
  152. for invalid fields, which doesn't sound bad unless you're near the
  153. zero-zero point in the Bay of Benin &mdash; or at sea level. It is
  154. also not generally possible to distinguish between information a GPS
  155. is not yet reporting but will return on a good fix (such as altitude)
  156. from information it will never report (such as, on many units, local
  157. magnetic variation).</para></listitem>
  158. <listitem><para>
  159. As least one messy bit in NMEA 0183 was an adaptation to machines with
  160. only small amounts of expensive RAM: the fact that satellite status
  161. may show up in a sequence of as many as three sentences to be
  162. processed serially. On modern machines, RAM buffers are cheap. It
  163. makes more sense to ship a single long sentence and decrease code
  164. complexity in the receiver by not requiring a stateful parser.
  165. </para></listitem>
  166. <listitem><para>
  167. Position accuracy estimates are not easy to compute from
  168. NMEA reports. Reporting a measurement without giving its 95%
  169. confidence interval is bad practice.
  170. </para></listitem>
  171. <listitem><para>
  172. For modern GPS devices, even the small piece of NMEA directly
  173. concerned with GPS capabilities is seriously over-complex. Whereas
  174. older GPS devices included elaborate facilities for waypoint tracking
  175. and navigational computation, newer ones are designed under the
  176. assumption that they are connected to a general-purpose computer that
  177. is more powerful and flexible at these things; thus, the GPS only
  178. needs to be a time/position/velocity oracle.
  179. </para></listitem>
  180. <listitem><para>
  181. NMEA 0183 is in general very loosely specified and
  182. poorly documented. Its problems are compounded by the fact that it is
  183. a proprietary specification, jealously guarded by IP lawyers.
  184. </para></listitem>
  185. </itemizedlist>
  186. <para>As a result of these problems, implementing NMEA 0183 talker
  187. software is far more complex than need be, and the protocol tends to
  188. introduce latencies that vary in an unpredictable way. The latter is
  189. a serious problem for aviation and other high-precision GPS
  190. applications, and probably provided a technical reason that one major
  191. GPS vendor (Garmin) dropped NMEA 0183 support entirely in 2004 in
  192. favor of a tighter binary protocol (we refrain from speculating on
  193. other less creditable motives for this move).</para>
  194. </sect1>
  195. <sect1><title>How To Do Better</title>
  196. <para>The critique above immediately suggests several ways to improve
  197. a protocol for GPS reports;</para>
  198. <itemizedlist>
  199. <listitem><para>
  200. Keep the low-level syntax, because it's not broken. It has all the
  201. advantages of textual protocols. Going to a more tightly-packed
  202. binary format might look attractive at first glance, but the gain in
  203. information would be marginal at best. Textual formats already use
  204. 7 out of 8 bits per byte and encode variable-length numeric fields more
  205. efficiently than binary; also they avoid endianness issues.
  206. </para></listitem>
  207. <listitem><para>
  208. Add to the syntax standard ways of indicating that either (a) the
  209. GPS cannot now ship valid data for the field, or (b) the GPS will
  210. <emphasis>never</emphasis> ship data for this field.
  211. </para></listitem>
  212. <listitem>
  213. <para>Include a full timestamp, to millisecond precision or better, with
  214. every sentence. Every timestamp should be in the same standard form
  215. and should include a full date with century.</para>
  216. </listitem>
  217. <listitem><para>
  218. Report the uncertainty corresponding to a 95% confidence interval on a
  219. standard normal distribution for each measurement field.
  220. </para></listitem>
  221. <listitem><para>
  222. Design the protocol around a single core sentence that reports
  223. time/position/velocity and the uncertainties in same.
  224. </para></listitem>
  225. <listitem><para>
  226. Make it an objective of the design for an informal specification to fit
  227. on a single page.
  228. </para></listitem>
  229. </itemizedlist>
  230. </sect1>
  231. <sect1><title>Informal specification: SGPS</title>
  232. <para>Here, then, is a proposed informal specification for SGPS, Simple GPS
  233. Protocol.</para>
  234. <para>The protocol consists of sentences, each led by a dollar sign
  235. and an identifying sentence tag, followed by multiple comma-separated
  236. textual fields, ended by an asterisk, a CRC32 checksum, and LF/CR.
  237. Sentences are at most 255 characters long, counting the
  238. trailing CR/LF.</para>
  239. <para>A field that is empty indicates that the talker does not have
  240. valid information for this field but promises to report it in the future. A
  241. field consisting of a question mark (?) indicates that the talker does
  242. not expect to ever ship valid information for this field.</para>
  243. <para>The first field of every SGPS report sentence is a full
  244. timestamp in the format of the <ulink
  245. url='https://web.archive.org/web/20150919174330/https://www.w3.org/TR/1998/NOTE-datetime-19980827'>W3C
  246. profile of ISO 8601</ulink>, with the timezone required to be
  247. Zulu (UTC) time.</para>
  248. <sect2><title>GPTPV</title>
  249. <para>The core sentence of SGPS has the following layout:</para>
  250. <orderedlist>
  251. <listitem><para>
  252. The sentence tag is GPTPV, standing for Time/Position/Velocity.
  253. </para></listitem>
  254. <listitem><para>
  255. The first field is the required timestamp.
  256. </para></listitem>
  257. <listitem><para>
  258. The second field is the uncertainty of the timestamp in (fractional) seconds.
  259. </para></listitem>
  260. <listitem><para>
  261. The third field is signed latitude in degrees. Encoding must be decimal
  262. degrees, not degree/minute/second.
  263. </para></listitem>
  264. <listitem><para>
  265. The fourth field is signed longitude in degrees. Encoding must be decimal
  266. degrees, not degree/minute/second.
  267. </para></listitem>
  268. <listitem><para>
  269. The fifth field is horizontal uncertainty in meters (95% confidence).
  270. </para></listitem>
  271. <listitem><para>
  272. The sixth field is altitude in meters.
  273. </para></listitem>
  274. <listitem><para>
  275. The seventh field is vertical uncertainty in meters (95% confidence).
  276. </para></listitem>
  277. <listitem><para>
  278. The eighth field is speed over ground in meters per second.
  279. </para></listitem>
  280. <listitem><para>
  281. The ninth field is speed-over-ground uncertainty in meters per second (95% confidence).
  282. </para></listitem>
  283. <listitem><para>
  284. The tenth field is course over ground in degrees from true north.
  285. </para></listitem>
  286. <listitem><para>
  287. The eleventh field is uncertainty of course over ground in degrees (95%
  288. confidence).
  289. </para></listitem>
  290. <listitem><para>
  291. The twelfth field is climb/sink in meters per second.
  292. </para></listitem>
  293. <listitem><para>
  294. The thirteenth field is uncertainty of climb/sink in meters per second
  295. (95% confidence).
  296. </para></listitem>
  297. <listitem><para>
  298. The fourteenth field is an FAA mode indicator.
  299. </para></listitem>
  300. </orderedlist>
  301. <para>These fourteen fields completely describe the position and
  302. velocity of an object and the associated uncertainties. The FAA
  303. mode field is added to satisfy a U.S. regulator's requirement.</para>
  304. <para>Here is an example:</para>
  305. <programlisting>
  306. $GPTPV,2005-02-11T04:40:51.231Z,?,49.45,-123.12,2.3,70.1,52.0,01.0,02.1,23.1,0.6,,,8,A*31
  307. 2005-02-11T04:40:51.231Z, Time (Feb 11 04:40:51 UTC 2005)
  308. ?, Timestamp uncertainty will never be reported
  309. 49.45, Latitude (- sign indicates latitude south)
  310. -123.12, Longitude (- sign indicates longitude west)
  311. 2.3, Meters of horizontal uncertainty of position
  312. 70.1, Altitude, meters above sea level
  313. 52, Uncertainty of altitude
  314. 0.01, Speed, meters/sec
  315. 0.02, Speed uncertainty
  316. 23.1, Course over ground relative to true North
  317. 0.6, Course uncertainty in degrees.
  318. , Climb/sink not reported
  319. , Climb/sink uncertainty not reported
  320. A FAA mode indicator A (Auto).
  321. 31 Checksum.
  322. </programlisting>
  323. </sect2>
  324. <sect2><title>GPSVU</title>
  325. <para>A second sentence describes GPS satellite status.</para>
  326. <orderedlist>
  327. <listitem><para>
  328. The sentence tag is GPSVU, standing for Satellite View Update.
  329. </para></listitem>
  330. <listitem><para>
  331. The first field is the required timestamp.
  332. </para></listitem>
  333. <listitem><para>
  334. The second field is a count of satellites.
  335. </para></listitem>
  336. <listitem>
  337. <para>The remainder of the sentence fields are groups of four, one
  338. for each predicted position of a visible satellite. Each group has
  339. the following four elements:</para>
  340. <orderedlist>
  341. <listitem><para>
  342. The PRN or satellite ID.
  343. </para></listitem>
  344. <listitem><para>
  345. Elevation in degrees
  346. </para></listitem>
  347. <listitem><para>
  348. Azimuth, degrees
  349. </para></listitem>
  350. <listitem><para>
  351. Signal-to-noise ratio in decibels. If this satellite was used in the
  352. last fix, suffix this field with a '!'.
  353. </para></listitem>
  354. </orderedlist>
  355. </listitem>
  356. </orderedlist>
  357. <para>Here is an example:</para>
  358. <programlisting>
  359. $GPSVU,2005-02-11T04:40:51.231Z,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00,14,25,170,00,16,57,208,39!,18,67,296,40!,19,40,246,00,22,42,067,42,24,14,311,43!,27,05,244,00*40
  360. </programlisting>
  361. </sect2>
  362. <sect2><title>GPVID</title>
  363. <para>A third sentence identifies the device. It is GPVID for Version
  364. ID, and the fields are as follows:</para>
  365. <orderedlist>
  366. <listitem><para>
  367. The sentence tag is GPVID, standing for Vendor ID.
  368. </para></listitem>
  369. <listitem><para>
  370. The first field is the required timestamp.
  371. </para></listitem>
  372. <listitem><para>
  373. The second field is the SGPS revision level.
  374. </para></listitem>
  375. <listitem><para>
  376. The third field is the vendor name.
  377. </para></listitem>
  378. <listitem><para>
  379. The fourth field is the device name or model number.
  380. </para></listitem>
  381. <listitem><para>
  382. The fifth field is a chipset designation.
  383. </para></listitem>
  384. <listitem><para>
  385. The sixth field may be empty or a subtype ID, typically a firmware
  386. revision level.
  387. </para></listitem>
  388. </orderedlist>
  389. <para>All fields must consist of US-ASCII text not containing commas.
  390. The total length of the sentence must not exceed the old NMEA maximum
  391. of 82.</para>
  392. <para>Here is an example:</para>
  393. <programlisting>
  394. $GPVID,2006-11-17T12:29:37Z,1.0,Haicom,H204S,SiRF-II,231.00.00*5C
  395. </programlisting>
  396. </sect2>
  397. <sect2><title>GPGSP</title>
  398. <para>With the addition of a fourth sentence, $GPSGP, transition to the
  399. new protocol would be easy. It would have two forms:</para>
  400. <para>$GPSGP,1: directs the receiver to emit GPPVT and GPSVU
  401. only, if it is not already doing so.</para>
  402. <para>$GPSGP,0: directs the receiver to return to NMEA-classic mode, if
  403. it is capable of doing so.</para>
  404. <para>Example:</para>
  405. <programlisting>
  406. $GPGSP,1*4E
  407. </programlisting>
  408. <para>An SGPS-conformant receiver is required to respond with
  409. $GPSGP,timestamp,x,y where x is 1 or 0 reflecting the command, and y is 1 or 0
  410. reporting its new mode.</para>
  411. <para>Other listeners can distinguish GPGSP responses from requests
  412. by checking whether field 1 contains an IS8601 timestamp; an easy way
  413. to check this is to look for the trailing Z.</para>
  414. </sect2>
  415. <sect2><title>Other considerations</title>
  416. <para>Finally, SGPS-compliant receivers are required to respond to the
  417. requests $GPPVT, $GPVSU, $GPVID, and $GPGSP (without arguments) with the
  418. corresponding report based on most recent available data.</para>
  419. </sect2>
  420. </sect1>
  421. <sect1><title>Could This Be Adopted?</title>
  422. <para>Astute readers will already have noted that the SGPS sentences
  423. might be sold as a minor extension to NMEA 0183. first supplementing
  424. and eventually obsolescing the half-dozen or so sentences emitted by
  425. most modern GPSes.</para>
  426. <para>The only fields reported in the SGPS set that cannot be
  427. trivially derived from data already computed for NMEA reports are
  428. (a) Climb/sink, and (b) GPSTPV uncertainty fields. None
  429. of these should be difficult to derive.</para>
  430. </sect1>
  431. </article>