hacking.html.in 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <!-- @MASTER@ -->
  4. <head lang="en">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta name="Description" content="Hacking GPSD, a guide">
  7. <meta name="Keywords" content="GPS, gpsd, translator, hackers">
  8. <meta name="Author" content="Eric S. Raymond">
  9. <meta name="robots" content="index,follow">
  10. <meta name="revised" content="@DATE@">
  11. <title>Hacker's Guide to GPSD</title>
  12. <link rel="stylesheet" href="main.css" type="text/css">
  13. </head>
  14. <body>
  15. <div id="Header">Hacker's Guide to GPSD</div>
  16. <div id="Menu">
  17. <img src="gpsd-logo-small.png" alt="Small gpsd Logo" height="126"
  18. width="105"><br>
  19. <a href="index.html">Home</a><br>
  20. <a href="index.html#news">News</a><br>
  21. <a href="index.html#downloads">Downloads</a><br>
  22. <a href="index.html#mailing-lists">Mailing lists</a><br>
  23. <a href="index.html#documentation">Documentation</a><br>
  24. <a href="faq.html">FAQ</a><br>
  25. <a href="xgps-sample.html">Screenshots</a><br>
  26. <a href="index.html#recipes">Recipes</a><br>
  27. <a href="index.html#others">Other GPSDs</a><br>
  28. <a href="hardware.html">Hardware</a><br>
  29. <a href="for-vendors.html">For GPS Vendors</a><br>
  30. <a href="wishlist.html">Wish List</a><br>
  31. <a href="hall-of-shame.html">Hall of Shame</a><br>
  32. <a href="troubleshooting.html">Troubleshooting Guide</a><br>
  33. Hacker's Guide<br>
  34. <a href="protocol-transition.html">Application Compatibility</a>
  35. <a href="references.html">References</a><br>
  36. <a href="history.html">History</a><br>
  37. <a href="future.html">Future</a><br>
  38. <div>&nbsp;</div>
  39. <a href='http://www.catb.org/hacker-emblem/'><img
  40. src='glider.png' alt='hacker emblem' height="55" width="55"></a><br>
  41. <script src="https://www.openhub.net/p/3944/widgets/project_thin_badge.js"></script>
  42. <hr>
  43. <script><!--
  44. google_ad_client = "pub-1458586455084261";
  45. google_ad_width = 160;
  46. google_ad_height = 600;
  47. google_ad_format = "160x600_as";
  48. google_ad_type = "text";
  49. google_ad_channel = "";
  50. //--></script>
  51. <script src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
  52. </script>
  53. <hr>
  54. <a href="https://validator.w3.org/check/referer"><img
  55. src="https://www.w3.org/Icons/valid-html401"
  56. alt="Valid HTML 4.01!" height="31" width="88"></a>
  57. </div>
  58. <div id="Content">
  59. <h1>Contents</h1>
  60. <p>If you're looking for things to hack on, first see the TODO
  61. file in the source distribution.</p>
  62. <ol class="ToC">
  63. <li><a href="#goals">Goals and philosophy of the project</a></li>
  64. <li><a href="#audience">Audience and supported hardware</a>
  65. <ol>
  66. <li><a href="#windows">Windows support (limited)</a></li>
  67. <li><a href="#service">The time and location service</a></li>
  68. <li><a href="#tuning">The testing and tuning tools</a></li>
  69. <li><a href="#monitoring">The GPS/GNSS monitoring tools</a></li>
  70. </ol>
  71. </li>
  72. <li><a href="#contribution">Contribution guidelines</a>
  73. <ol>
  74. <li><a href="#verify">Verify your patch or commit</a></li>
  75. <li><a href="#patches">Send patches in git-format-patch, diff -u or -c format</a></li>
  76. <li><a href="#license">The license on contributions</a></li>
  77. <li><a href="#options">Don't add invocation options!</a></li>
  78. <li><a href="#statics">Don't create static variables in the libraries!</a></li>
  79. <li><a href="#malloc">Don't use malloc!</a></li>
  80. <li><a href="#sizeof">Avoid use of sizeof(&lt;int type&gt;)!</a></li>
  81. <li><a href="#newdata">Adding new data fields or JSON objects</a></li>
  82. <li><a href="#standards">C, standards and style</a></li>
  83. <li><a href="#asserts">Use assert(3) sparingly and
  84. carefully!</a></li>
  85. </ol>
  86. </li>
  87. <li><a href="#understanding">Understanding the code</a>
  88. <ol>
  89. <li><a href="#debugging">Debugging</a></li>
  90. <li><a href="#profiling">Profiling</a></li>
  91. <li><a href="#porting">Porting to weird machines: endianness, width, and signedness issues.</a></li>
  92. <li><a href="#architecture">Architecture and how to hack it</a></li>
  93. <li><a href="#autoconfiguration">Autoconfiguration</a></li>
  94. <li><a href="#error">Error modeling</a></li>
  95. <li><a href="#ancient">Ancient history</a></li>
  96. </ol>
  97. </li>
  98. <li><a href="#newsentence">How to add a new sensor type</a>
  99. <ol>
  100. <li><a href="#newdriver">Driver-level support</a></li>
  101. <li><a href="#newjson">JSON output</a></li>
  102. <li><a href="#newtest">Updating the test suite</a></li>
  103. <li><a href="#newclient">Client-side support</a></li>
  104. <li><a href="#newdoc">Documentation</a></li>
  105. <li><a href="#newstyle">Points for style</a></li>
  106. </ol>
  107. </li>
  108. <li><a href="#trouble">Known trouble spots</a>
  109. <ol>
  110. <li><a href="#y2k1">The Y2.1K problem and other calendar issues</a></li>
  111. <li><a href="#hotplug">Hotplug interface problems</a></li>
  112. <li><a href="#security">Security Issues</a></li>
  113. </ol>
  114. </li>
  115. <li><a href="#newtypes">Adding new GPS types</a>
  116. <ol>
  117. <li><a href="#drivers">Driver architecture</a></li>
  118. <li><a href="#notdriver">When not to add a driver</a></li>
  119. <li><a href="#init">Initializing time and date</a></li>
  120. <li><a href="#invocation">How drivers are invoked</a></li>
  121. <li><a href="#reports">Where to put the data you get from the GPS</a></li>
  122. <li><a href="#confidence">Report errors with a 95% confidence interval</a></li>
  123. <li><a href="#logfiles">Log files for regression testing</a></li>
  124. </ol>
  125. </li>
  126. <li><a href="#designahead">Future Protocol Directions</a>
  127. <ol>
  128. <li><a href="#proposed">Proposed sentences</a></li>
  129. </ol>
  130. </li>
  131. <li><a href="#blindalleys">Blind alleys</a>
  132. <ol>
  133. <li><a href="#oncepercycle">Reporting fix data only once per cycle</a></li>
  134. <li><a href="#shipstrings">Allowing clients to ship arbitrary control strings to a GPS</a></li>
  135. <li><a href="#fifo">Setting FIFO threshold to 1 to reduce jitter in serial-message times</a></li>
  136. <li><a href="#subsecond">Subsecond polling</a></li>
  137. </ol>
  138. </li>
  139. <li><a href="#release">Release Checklist</a></li>
  140. </ol>
  141. <h1 id="goals">Goals and philosophy of the project</h1>
  142. <p>If the GPSD project ever needs a slogan, it will be "Hide the ugliness!"
  143. GPS technology works, but is baroque, ugly and poorly documented. Our
  144. job is to know the grotty details so nobody else has to.</p>
  145. <h1 id="audience">Audience and supported hardware</h1>
  146. <p>Our paradigm user, the one we have in mind when making design
  147. choices, is running navigational or wardriving software on a Linux-based
  148. mobile device (including both laptops and Android mobile
  149. devices). Some of our developers are actively interested in supporting
  150. GPS-with-SBC (Single-Board-Computer) hardware such as is used in
  151. balloon telemetry, marine navigation, and aviation.</p>
  152. <p>These two use cases have similar issues in areas like client
  153. interfaces and power/duty-cycle management. The one place where they
  154. differ substantially is that in the SBC and Android cases we generally
  155. know in advance what devices will be connected and when. Thus, by
  156. designing for the less predictable laptop environment, we cover both.
  157. But it is not by accident that the source code can be built with
  158. support for only one single GPS type compiled in.</p>
  159. <p>We have an important secondary interest in supporting network time
  160. service. Using GPSD to monitor a GPS with pulse-per-second capability
  161. is a perfectly serviceable and unbeatably cheap way to provide Stratum
  162. I time, and we expect this use case to increase in importance.</p>
  163. <p>While we will support survey-grade GPSes when and if we have that
  164. hardware for testing, our focus will probably remain on inexpensive
  165. and readily-available consumer-grade GPS hardware, especially GPS
  166. mice.</p>
  167. <h2 id="windows">Windows support (limited)</h2>
  168. <p>The <code>gpsd</code> daemon and most <code>gpsd</code> tools are for
  169. Unix-like systems since this is where they are developed and tested.</p>
  170. <p>Remote access over sockets via the C library and the simple command-line
  171. tools <code>gpspipe</code> and <code>gpxlogger</code> are
  172. supported on Windows platforms, although they currently have some minor
  173. limitations compared to the Unix versions:</p>
  174. <ol>
  175. <li><code>gpspipe</code> and <code>gpxlogger</code> can not be run as
  176. daemons on Windows.</li>
  177. <li><code>gpspipe</code> cannot write to the serial port on Windows.</li>
  178. </ol>
  179. <h2 id="service">The time and location service</h2>
  180. <p>The primary aim of the GPSD project is to support a simple
  181. time-and-location service for users and their geographically-aware
  182. applications.</p>
  183. <p>A GPS is a device for delivering fourteen numbers: x, y, z, t, vx,
  184. vy, vz, and error estimates for each of these seven coordinates. The
  185. <code>gpsd</code> daemon's job is to deliver these numbers to user
  186. applications with minimum fuss. This is a "TPV" &mdash;
  187. time-position-velocity report. A GPS is a TPV oracle.</p>
  188. <p>'Minimum fuss' means that the only action the user should have to
  189. take to enable location service is to plug in a GPS. The
  190. <code>gpsd</code> daemon, and its associated hotplug scripts or local
  191. equivalent, is responsible for automatically configuring itself. That
  192. includes autobauding, handshaking with the device, determining the
  193. correct mode or protocol to use, and issuing any device-specific
  194. initializations required.</p>
  195. <p>Features (such as GPS type or serial-parameter switches) that would
  196. require the user to perform administrative actions to enable location
  197. service will be rejected. GPSes that cannot be autoconfigured will
  198. not be supported. 99% of the GPS hardware on the market in 2015 is
  199. autoconfigurable, and the design direction of GPS chipsets is such
  200. that this percentage will rise rather than fall; we deliberately
  201. choose simplicity of interface and zero administration over 100%
  202. coverage.</p>
  203. <p>Here is a concrete example of how this principle applies. At least
  204. one very low-end GPS chipset (the San Jose Navigation GM-38) does not
  205. deliver correct checksums on the packets it ships to a host unless it
  206. has a fix. Typically, GPSes do not have a fix when they are plugged
  207. in, at the time <code>gpsd</code> must recognize and autoconfigure the
  208. device. Thus, supporting this chipset would require that we either
  209. (a) disable packet integrity checking in the autoconfiguration code,
  210. making detection of other more well-behaved devices unreliable, or (b)
  211. add an invocation switch to disable packet integrity checking for that
  212. chipset alone. We refuse to do either, and do not support this
  213. chipset.</p>
  214. <h2 id="tuning">The testing and tuning tools</h2>
  215. <p>Another principal goal of the GPSD software is that it be able to
  216. demonstrate its own correctness, give technical users good tools for
  217. measuring GPS accuracy and diagnosis of GPS idiosyncrasies, and
  218. provide a test framework for gpsd-using applications.</p>
  219. <p>Accordingly, we support the <code>gpsfake</code> tool that
  220. simulates a GPS using recorded or synthetic log data. We support
  221. <code>gpsprof</code>, which collects accuracy and latency statistics
  222. on GPSes and the GPS+<code>gpsd</code> combination. And we include a
  223. comprehensive regression-test suite with the package. These tools are
  224. not accidents, they are essential to ensure that the basic
  225. GPS-monitoring code is not merely correct but <em>demonstrably</em>
  226. correct.</p>
  227. <p>We support a tool, <code>gpsmon</code>, which is a low-level packet
  228. monitor and diagnostic tool. <code>gpsmon</code> is capable of tuning
  229. some device-specific control settings such as the SiRF
  230. static-navigation mode. A future direction of the project is to
  231. support diagnostic monitoring and tuning for our entire range of
  232. chipsets.</p>
  233. <h2 id="monitoring">The GPS/GNSS monitoring tools</h2>
  234. <p>Another secondary goal of the project is to provide open-source tools
  235. for diagnostic monitoring and accuracy profiling not just of
  236. individual GPSes but of the GPS/GNSS network itself. The protocols
  237. (such as IS-GPS-200 for satellite downlink and RCTM104 for
  238. differential-GPS corrections) are notoriously poorly documented, and
  239. open-source tools for interpreting them have in the past been hard
  240. to find and only sporadically maintained.</p>
  241. <p>We aim to remedy this. Our design goal is to provide lossless
  242. translators between these protocols and readable, documented
  243. text-stream formats.</p>
  244. <p>We currently provide a tool for decoding RTCM104 reports on satellite
  245. health, almanacs, and pseudorange information from differential-GPS
  246. radios and reference stations. A future direction of the project is
  247. to support an RTCM104 encoder.</p>
  248. <h1 id="contribution">Contribution guidelines</h1>
  249. <h2 id="languages">Our languages are C, Python, and sh</h2>
  250. <p>The project implementation languages are C and Python. The core
  251. libgpsd libraries (and the daemon, which is a thin wrapper around
  252. them) are written in C; the test and profiling tools are written in
  253. Python, with a limited amount of glue in POSIX-conformant sh and some
  254. bash.</p>
  255. <p>Code in other languages will, in general, be accepted only if
  256. it supplies a language binding for the libgps or libgpsd libraries
  257. that we don't already have. This restriction is an attempt to keep
  258. our long-term maintenance problem as tractable as possible.</p>
  259. <p>We require C for anything that may have to run on an embedded
  260. system. Thus, the daemon and libgpsd libraries need to stay pure C.
  261. Anything that links direct to the core libraries should also be in C,
  262. because Python's alien-type facilities are still just a little too
  263. complex and painful to be a net win for our situation.</p>
  264. <p>We prefer Python anywhere we aren't required to use C by
  265. technical constraints &mdash; in particular, for
  266. test/profiling/logging tools, hotplug agents, and miscellaneous
  267. scripts. Again, this is a long-term maintainability issue; there are
  268. whole classes of potential C bugs that simply don't exist in Python,
  269. and Python programs have a drastically lower line count for equivalent
  270. capability.</p>
  271. <p>Shell scripts are acceptable for test and build code that only has
  272. to run in our development and test environments, as opposed to target
  273. or production environments. Note that shell scripts should not assume
  274. <code>bash</code> is available but rather stick to POSIX
  275. <code>sh</code>; among other benefits, this helps portability to BSD
  276. systems. Generally code that will run in the Ubuntu/Debian
  277. <code>dash</code> can be considered safe.</p>
  278. <p>Here are two related rules:</p>
  279. <p>Any complexity that can be moved out of the <code>gpsd</code>
  280. daemon to external test or framework code doesn't belong in the
  281. daemon.</p>
  282. <p>Any complexity that can be moved out of C and into a higher-level
  283. language (Python, in particular) doesn't belong in C.</p>
  284. <p>Both rules have the same purpose: to move complexity and resource
  285. costs from the places in the codebase where we can least afford it
  286. to the places where it is most manageable and inflicts the least
  287. long-term maintenance burden.</p>
  288. <h2 id="pyversion">Python version issues and good style</h2>
  289. <p>Because Python is not used at runtime by the daemon, Python
  290. version-skew problem (such as the 2 to 3 transition) essentally
  291. never have any effect on or reveal bugs in the C code.</p>
  292. <p>A significant part of the reason is that in GPSD-world the notion
  293. of "target Python" is not actually meaningful for anything but a
  294. handful of test and profiling utilities. On the <em>very</em> rare occasions
  295. that those have had bugs (fewer than a half-dozen in the entire
  296. project history) they have generally been due to glitches in Python's
  297. OS bindings - the least rare categories related to the socket and pty
  298. libraries.</p>
  299. <p>Therefore, what version of Python code such as the regression-test
  300. framework is running under is generally unimportant if it runs at all.
  301. To minimize problems due to the ongoing Python 2 to 3 transition,
  302. follow the "polyglot" guidelines in <a
  303. href="http://www.catb.org/esr/faqs/practical-python-porting/">Practical
  304. Python porting for systems programmers</a>.
  305. <h2 id="verify">Verify your patch or commit</h2>
  306. <p>GPSD is written to a high quality standard, and has a defect rate
  307. that is remarkably low for a project of this size and complexity. Our
  308. first <a href='http://www.coverity.com/'>Coverity</a> scan, in March
  309. 2007, flagged only 4 potential problems in 22,397 LOC &mdash; and two
  310. of those were false positives. This is <a
  311. href='http://lwn.net/Articles/115530/'>three orders of magnitude
  312. cleaner</a> than typical commercial software, and about half the
  313. defect density of the Linux kernel itself.</p>
  314. <p>This did not happen by accident. We put a lot of effort into test
  315. tools and regression tests so we can avoid committing bad code. For
  316. committers, using those tests isn't just a good idea, it's the law
  317. &mdash; which is to say that if you make a habit of <em>not</em> using
  318. them when you should, your commit access <em>will</em> be yanked.</p>
  319. <p>Before shipping a patch or committing to the repository, you should
  320. go through the following checklist:</p>
  321. <ol>
  322. <li>If you are introducing a new feature or driver, include
  323. documentation.</li>
  324. <li>If your patch changes executable code in any way that is more than
  325. trivial, use the regression-test suite &mdash; "scons check"
  326. &mdash; to check that your patch doesn't break the handling of any
  327. already-supported GPS.</li>
  328. <li>In the rare case where your patch or commit breaks the
  329. regression test and it's for a good reason, part of your
  330. responsibility is to (a) rebuild the regression tests, (b)
  331. include the test changes in your patch, and (c) <b>explain
  332. in detail why the regression broke</b> in your change comment.</li>
  333. <li>After code changes that do anything to the storage handling, run
  334. valgrind-audit.py and look out for reports of memory leaks and other
  335. dynamic-allocation problems (see <a href="http://valgrind.org">the
  336. Valgrind website</a> for a description of this tool if you don't
  337. already know about it).</li>
  338. </ol>
  339. <p>Not breaking the regression tests is especially important. We rely
  340. on these to catch damaging side-effects of seemingly innocent but
  341. ill-thought-out changes, and to nail problems before they become
  342. user-visible.</p>
  343. <p>If you are contributing a driver for a new GPS, please also do the
  344. following things:</p>
  345. <ol>
  346. <li>Send us a representative sample of the GPS output for future
  347. regression-testing.</li>
  348. <li>Write a hardware entry describing the GPS for the <a
  349. href="hardware.html">hardware page</a>.</li>
  350. </ol>
  351. <p>There's a whole section on adding new drivers later in this document.</p>
  352. <h2 id="patches">Send patches in git-format-patch, diff -u or -c format</h2>
  353. <p>We like getting patches made using <code>git format-patch
  354. --signoff</code> from a repository clone, as this means we don't
  355. have to compose a change comment and attribution. The --signoff option
  356. of git format-patch adds a Signed-off-by: line to the end of your commit
  357. message. It certifies that you have the rights to submit the patch under
  358. GPSD's BSD licence (see the <a href='#license'>next section</a> and the
  359. <a href='http://developercertificate.org/'>Developer Certificate of
  360. Origin</a>).</p>
  361. <p>Failing that prefer diff -u format, but diff -c is acceptable. Do
  362. not send patches in the default (-e or ed) mode, as they are too
  363. brittle.</p>
  364. <p>When you send a patch, we expect you to do at least the first three
  365. of the same verification steps we <a href='#verify'>require</a> from
  366. our project committers. Doing all of them is better, and makes it
  367. far more likely your patch will be accepted.</p>
  368. <h2 id="license">The license on contributions</h2>
  369. <p>The GPSD libraries are under the BSD license. Please do not send
  370. contributions with GPL attached!</p>
  371. <p>The reason for this policy is to avoid making people nervous about
  372. linking the GPSD libraries to applications that may be under other
  373. licenses (such as MIT, BSD, AFL, etc.).</p>
  374. <h2 id="options">Don't add invocation options!</h2>
  375. <p>If you send a patch that adds a command-line option to the daemon, it
  376. will almost certainly be refused. Ditto for any patch that requires
  377. <code>gpsd</code> to parse a dotfile.</p>
  378. <p>One of the major objectives of this project is for
  379. <code>gpsd</code> <em>not to require administration</em> &mdash; under
  380. Linux, at least. It autobauds, it does protocol discovery, and it's
  381. activated by the hotplug system. Arranging these things involved
  382. quite a lot of work, and we're not willing to lose the
  383. zero-configuration property that work gained us.</p>
  384. <p>Instead of adding a command-line option to support whatever feature
  385. you had in mind, try to figure out a way that the feature can
  386. autoconfigure itself by doing runtime checks. If you're not clever
  387. enough to manage that, consider whether your feature control might be
  388. implemented with an extension to the gpsd protocol or the
  389. control-socket command set.</p>
  390. <p>Here are three specific reasons command-line switches are evil:</p>
  391. <p>(1) Command-line switches are often a lazy programmer's way out of
  392. writing correct adaptive logic. This is why we keep rejecting
  393. requests for a baud-rate switch and a GPS type switch &mdash; the
  394. <em>right</em> thing is to make the packet-sniffer work better, and if
  395. we relented in our opposition the pressure to get that right would
  396. disappear. Suddenly we'd be back to end-users having to fiddle with
  397. settings the software ought to figure out for itself, which is
  398. unacceptable.</p>
  399. <p>(2) Command-line switches without corresponding protocol commands
  400. pin the daemon's behavior for its entire lifespan. Why should the user
  401. have to fix a policy at startup time and never get to change his/her
  402. mind afterwards? Stupid design...</p>
  403. <p>(3) The command-line switches used for a normal <code>gpsd</code>
  404. startup can only be changed by modifying the hotplug script.
  405. Requiring end-users to modify hotplug scripts (or anything else in
  406. admin space) is a crash landing.</p>
  407. <h2 id="statics">Don't create static variables in the libraries!</h2>
  408. <p>Don't create static variables in library or driver files; it makes
  409. them non-reentrant<span class="strikeout"> and hard to light</span>.
  410. In practice, this means you shouldn't declare a static in any file
  411. that doesn't have a main() function of its own, and silly little test
  412. mains cordoned off by a preprocessor conditional don't count.</p>
  413. <p>Instead, use the 'driver' union in gps_device_t and the gps_context_t
  414. storage area that's passed in common in a lot of the calls.
  415. These are intended as places to stash stuff that needs to be shared
  416. within a session, but would be thread-local if the code were
  417. running in a thread.</p>
  418. <h2 id="malloc">Don't use malloc!</h2>
  419. <p>The best way to avoid having dynamic-memory allocation problems is
  420. not to use malloc/free at all. The <code>gpsd</code> daemon doesn't
  421. (though the client-side code does). Thus, even the longest-running
  422. instance can't have memory leaks. The only cost for this turned out
  423. to be embedding a PATH_MAX-sized buffer in the gpsd.h structure.</p>
  424. <p>Don't undo this by using malloc/free in a driver or anywhere else.</p>
  425. <p>Please note that this restriction includes indirect callers of malloc
  426. like strdup.</p>
  427. <h2 id="sizeof">Avoid use of sizeof(&lt;int type&gt;)!</h2>
  428. <p>It's tempting to extract parts of packets with by using a loop of the
  429. form "<code>for(i = 0; i &lt; len; i += sizeof(long))</code>". Don't do that;
  430. not all integer types have the same length across architectures. A long may
  431. be 4 bytes on a 32-bit machine and 8 bytes on a 64-bit. If you mean to skip
  432. 4 bytes in a packet, then say so (or use sizeof(int32_t)).</p>
  433. <h2 id="newdata">Adding new data fields or JSON objects</h2>
  434. <p>Here's what you have to do when adding a field to a JSON report, or
  435. a new JSON report to the object set.</p>
  436. <ol>
  437. <li><p>Make the daemon emit the new field(s).</p></li>
  438. <li><p>Document it in gpsd_json.xml.</p></li>
  439. <li><p>Decide whether it warrants a minor or major protocol bump.
  440. Update the appropriate macros in gpsd.h-tail. In the comment above
  441. them, add a brief description of the change.</p></li>
  442. <li><p>Update the JSON parse templates in libgps_json.c. If you don't do this,
  443. clients (possibly including gpsmon) will throw an error when they trip over the
  444. new field.</p></li>
  445. <li><p>There may be a unit test for parsing of the JSON object in
  446. test_json.c. If there is, it needs to be modified. If not, add
  447. one.</p></li>
  448. <li><p>The hard part: the data wants to go somewhere on the client side, but
  449. doing this may involve a compatibility break in the user-visible core
  450. structures. You need to make a call on whether to extend them or accept
  451. that the new data will be invisible until the next structure upgrade
  452. and if so document that as an item in TODO.</p></li>
  453. </ol>
  454. <h2 id="standards">C, standards and style</h2>
  455. <p>The C code is written with a large subset of C99. You are
  456. encouraged to use <code>bool</code>, designated initializers,
  457. <code>inline</code> and <code>restrict</code>. Do not assume
  458. that type specifiers will default to int.</p>
  459. <p>You are allowed, but not required, to use C99 // comments.</p>
  460. <p>Though C99 allows it, do not intermix declarations with executable
  461. statements within a block, that's too hard to read. Do,
  462. however, declare variables at the front of the <em>smallest</em> enclosing
  463. block.</p>
  464. <p>The code does <em>not</em> use C99 variadic macros, flexible
  465. arrays, type-generic math, or type complex. Think carefully before
  466. introducing these and don't do it without discussion on the
  467. development list first.</p>
  468. <p>The one non-C99 feature we allow is anonymous unions.</p>
  469. <p>Do not use GCC extensions, as the code should compile with any sane
  470. C99 compiler (specifically including clang). Do not use
  471. glibc-specific features, as <code>gpsd</code> is portable to multiple
  472. operating systems that do not use glibc, including BSD's libc and
  473. uClibc. Instead, rely on what POSIX guarantees.</p>
  474. <p>We are pretty laissez-faire about indent style and low-level C
  475. formatting. Be aware that if your patch seems disharmonious with what
  476. is around it, your code may be reformatted, so try to blend in.</p>
  477. <p>You may rely on a full POSIX (in particular, POSIX-2001.1) and
  478. Single Unix Standard binding to the operating system. Someday it is
  479. possible we may have a Windows port, but we refuse to cripple or
  480. overcomplicate the codebase in advance.</p>
  481. <p>Do not litter the code with undocumented magic numbers! This is
  482. especially important for buffer lengths, because unsynchronized
  483. changes to buffer lengths and the code that uses them can result in
  484. overruns and all manner of nastiness. If a magic number occurs once,
  485. a comment near the point of occurrence should explain why it has the
  486. value it does. If it occurs multiple times, make it the value of
  487. a macro that is defined in one place so that all instances can be
  488. changed sanely.</p>
  489. <h2 id="asserts">Use assert(3) sparingly and carefully!</h2>
  490. <p>gpsd - I'm speaking of the daemon itself, not the clients and test
  491. tools - runs in a lot of contexts where it provides a life-critical
  492. service. We can't allow it to faint every time it gets a case of the
  493. vapors. Instead, the right thing is to log a problem and soldier on.
  494. If the fault condition is in the logging machinery itself, the right
  495. thing is to just soldier on.</p>
  496. <p>Accordingly, there are very few asserts in the core code. Whenever
  497. possible we should avoid adding more.</p>
  498. <p>Here's the policy for the daemon and its service libraries. This
  499. doesn't apply to client code and tools, which can be more relaxed
  500. because the cost of having them go tits-up is lower and recovery
  501. is easier.<p>
  502. <ol>
  503. <li><p>Use asserts sparingly.</p></li>
  504. <li><p>One valid use is to pass hints to static analyzers. This
  505. sort of assert should be guarded with, e.g., #ifdef
  506. __COVERITY_ so we get the benefit of asserting the invariant without
  507. the risk of the assertion failing in production.</p></li>
  508. <li><p>Another use is to document should-never-happen invariants of the
  509. code. Write this sort only if you are confident it will never fire
  510. in a production release; it's there to catch when changes in a
  511. *development* revision break an invariant.</p></li>
  512. <li><p>Outside the above two cases, do not assert when you can log an internal
  513. error and recover.</p></li>
  514. <li><p>Never use assert() to check resource exhaustion conditions or
  515. other dynamic errors.</p></li>
  516. </ol>
  517. <h2 id="nohash">Avoid git hashes</h2>
  518. <p>Style point: avoid using git hashes in change comments. They'll
  519. become at best a pain in the ass and at worst meaningless
  520. if the project ever has to change version control systems again.
  521. Better to refer by committer and date.</p>
  522. <h1 id="understanding">Understanding the code</h1>
  523. <h2 id="debugging">Debugging</h2>
  524. <p><code>scons debug=yes</code> will build with the right flags to
  525. enable symbolic debugging.</p>
  526. <p>There is a script called <code>logextract</code> in the devtools
  527. directory of the source distribution that you can use to strip clean
  528. NMEA out of the log files produced by <code>gpsd</code>. This can be
  529. useful if someone ships you a log that they allege caused
  530. <code>gpsd</code> to misbehave.</p>
  531. <p><code>gpsfake</code> enables you to repeatedly feed a packet
  532. sequence to a <code>gpsd</code> instance running as non-root.
  533. Watching such a session with <code>gdb(1)</code> should smoke out any
  534. repeatable bug pretty quickly.</p>
  535. <p>Almost all the C programs have a -D option that enables logging
  536. of progress messages to standard error. In gpsd itself, this ups the
  537. syslogging level if it is running in background; see the LOG_* defines
  538. in gpsd.h to get an idea of what the log levels do. Most of the test
  539. clients accept this switch to enable progress message from the libgps
  540. code; you can use it, for example, to watch what the client-side
  541. parser for the wire protocol is actually doing.</p>
  542. <h2 id="profiling">Profiling</h2>
  543. <p>There is a timing policy flag in the WATCH command that will cause
  544. it to emit timing information at the end of every reporting cycle from
  545. the sensor.</p>
  546. <p>The profiling code relies on the GPS repeatedly spinning through
  547. a three-phase cycle:</p>
  548. <ol>
  549. <li>Phase one, computation, begins when the GPS samples satellite
  550. pseudoranges. (We'll call this time start-of-cycle or SOC). During
  551. phase one, the GPS computes a fix from those samples and buffers a
  552. burst of sentences describing the fix.</li>
  553. <li>Phase two, transmission, begins at a time we'll call
  554. start-of-reporting or SOR. In this phase the GPS transmits the burst
  555. of sentences to the listening computer. Phase two ends when the last
  556. byte of the last sentence is transmitted' we'll call this time
  557. end-of-reporting or EOR.</li>
  558. <li>In phase three, quiet time, the GPS is waiting for its next
  559. scheduled time to take a fix, and transmits nothing. Note, this phase
  560. may be nonexistent at 4800bps because the transmission time for a
  561. whole cycle's worth of data can be a second or longer (this has been
  562. observed in some NMEA GPSes). At 9600bps a GPS with a 1s cycle time
  563. emitting the normal NMEA set of {GPRMC,GGA,GPVTG,GPGLL,GSA,GPGSV) will
  564. have a quiet time minimum duration of 250ms; the pause is readily
  565. observable by eyeball in <code>gpsmon</code>. At higher speeds, or
  566. with (slightly) more compact binary protocols, quiet time increases.</li>
  567. </ol>
  568. <p>As long as we avoid profiling at 4800bps, then, we can identify the
  569. start of a reporting cycle (SOR) when data becomes available after
  570. quiet time of 250msec or greater.<p>
  571. <p>Here is a diagram of one second in the life of a typical GPS. The
  572. relative horizontal lengths of the boxes have roughly the proportions
  573. of actual timing behavior on an NMEA or SiRF-binary GPS at 19200bps,
  574. except that on this scale the typical gpsd-to-client transmission time
  575. would be nearly too small to see.</p>
  576. <div>&nbsp;</div>
  577. <div>
  578. <img style="display: block;margin-left: auto;margin-right:auto"
  579. src="cycle.svg" alt="Cycle timing diagram">
  580. </div>
  581. <div>&nbsp;</div>
  582. <p>While transmission is going on, <code>gpsd</code> is reading the
  583. sentence burst and interpreting it. At some point in the cycle
  584. ('RTIME' in the above diagram) <code>gpsd</code> will recognize that
  585. it has enough data to ship a report to clients. This might be just
  586. after the last packet in the cycle has arrived and been analyzed, but
  587. could be earlier if the device emits packets late in the cycle that
  588. <code>gpsd</code> doesn't use.</p>
  589. <p>Here are the extra timing attributes. They measure components of
  590. the latency between the GPS' time measurement and when the sentence
  591. data became available to the client. For these latency timings to be
  592. meaningful, the GPS has to ship timestamps with sub-second
  593. precision. SiRF-II and Evermore chipsets ship time with 0.01
  594. resolution; iTalk and Navcom chipsets ship times with 0.001
  595. resolution.</p>
  596. <ol>
  597. <li><code>sor:</code> SOR as a float quantity in seconds of
  598. Unix time.</li>
  599. <li><code>chars:</code> Total characters transmitted between SOC
  600. and RTIME. Note; this could be fewer than the number of characters
  601. in the entire cycle; the packet-sniffer might assemble later packets
  602. which are not analyzed by the driver.</li>
  603. <li><code>sats:</code> Number of satellites used in the cycle's fix.</li>
  604. <li><code>rtime:</code> RTIME as a float quantity in seconds of
  605. Unix time, when the daemon created the TPV for transmission.</li>
  606. </ol>
  607. <p>Note: You cannot assume that the entire SOC to RTIME interval is
  608. processing time! SOC is the GPS's report of its fix time, while RTIME
  609. is taken from your system clock. Some of the delta may be drift
  610. between your ntp-corrected system clock and the GPS's atomic-clock
  611. time.</p>
  612. <p>The distribution includes a Python script, <code>gpsprof</code>,
  613. that uses the timing support to collect profiling information from a
  614. running GPS instance. The <code>gpsprof</code> script creates latency
  615. plots using <code>gnuplot(1)</code>. It can also report the raw
  616. data.</p>
  617. <h2 id="porting">Porting to weird machines: endianness, width, and signedness issues.</h2>
  618. <p>The gpsd code is well-tested on IA32 and x86-64 (amd64) chips, also on ARM,
  619. PPCs, and MIPS. Thus, it's known to work on mainstream chips of
  620. either 32 or 64 bits and either big-endian or little-endian
  621. representation with IEE754 floating point.</p>
  622. <p>Handling of NMEA devices should not be sensitive to the machine's
  623. internal numeric representations, however, because the binary-protocol
  624. drivers have to mine bytes out of the incoming packets and mung them
  625. into fixed-width integer quantities, there could potentially be issues
  626. on weird machines. The regression test should spot these.</p>
  627. <p>If you are porting to a true 16-bit machine, or something else with
  628. an unusual set of data type widths, take a look at bits.h. We've
  629. tried to collect all the architecture dependencies here.</p>
  630. <h2 id="architecture">Architecture and how to hack it</h2>
  631. <p>There are two useful ways to think about the GPSD architecture.
  632. One is in terms of the layering of the software, the other is in terms
  633. of the normal flow of information through it.</p>
  634. <h3>The software-layering view</h3>
  635. <p> The <code>gpsd</code> breaks naturally into four pieces: the
  636. <b>drivers</b>, the <b>packet sniffer</b>, the <b>core library</b>, and
  637. the <b>multiplexer</b>. We'll describe these from the bottom up.</p>
  638. <p>The <b>drivers</b> are essentially user-space device drivers for
  639. each kind of chipset we support. The key entry points are methods to
  640. parse a data packet into time-position-velocity or status information,
  641. change its mode or baud rate, probe for device subtype, etc. See
  642. <a href="#drivers">Driver Architecture</a> for more details about
  643. them.</p>
  644. <p>The <b>packet sniffer</b> is responsible for mining data packets
  645. out of serial input streams. It's basically a state machine that's
  646. watching for anything that looks like a properly checksummed packet.
  647. Because devices can hotplug or change modes, the type of packet
  648. that will come up the wire from a serial or USB port isn't necessarily
  649. fixed forever by the first one recognized.</p>
  650. <p>The <b>core library</b> manages a session with a GPS device. The
  651. key entry points are (a) Starting a session by opening the device and
  652. reading data from it, hunting through baud rates and parity/stopbit
  653. combinations until the packet sniffer achieves synchronization
  654. lock with a known packet type, (b) polling the device for a packet,
  655. and (b) closing the device and wrapping up the session.</p>
  656. <p>A key feature of the core library is that it's responsible for
  657. switching each GPS connection to using the correct device driver
  658. depending on the packet type that the sniffer returns. This is
  659. <em>not configured in advance</em> and may change over time, notably
  660. if the device switches between different reporting protocols (most
  661. chipsets support NMEA and one or more vendor binary protocols, and
  662. devices like AIS receivers may report packets in two different
  663. protocols on the same wire).</p>
  664. <p>Finally, the <b>multiplexer</b> is the part of the daemon that
  665. handles client sessions and device assignment. It is responsible
  666. for passing TPV reports up to clients, accepting client commands,
  667. and responding to hotplug notifications. It is essentially all
  668. contained in the gpsd.c source file.</p>
  669. <p>The first three components (other than the multiplexer) are linked
  670. together in a library called libgpsd and can be used separately from
  671. the multiplexer. Our other tools that talk to GPSes directly, such as
  672. <code>gpsmon</code> and <code>gpsctl</code>, do it by calling into the
  673. core library and driver layer directly.</p>
  674. <p>Under some circumstances, the packet sniffer by itself is
  675. separately useful. <code>gpscat</code> uses it without the rest of the
  676. lower layer in order to detect and report packet boundaries in raw
  677. data. So does <code>gpsfake</code>, in order to chunk log files so they
  678. can be fed to a test instance of the daemon packet-by-packet with
  679. something approximating realistic timing.</p>
  680. <h3>The data-flow view</h3>
  681. <p>Essentially, <code>gpsd</code> spins in a loop polling for input from
  682. one of these sources:</p>
  683. <ol>
  684. <li>A set of clients making requests over a TCP/IP port.</li>
  685. <li>A set of GPSes, connected via serial or USB devices.</li>
  686. <li>A set of DGPS or NTRIP servers issuing periodic differential-GPS
  687. updates.</li>
  688. <li>The special control socket used by hotplug scripts and some
  689. configuration tools.</li>
  690. </ol>
  691. <p>The daemon only connects to a GPS when clients are connected to it.
  692. Otherwise all GPS devices are closed and the daemon is quiescent.</p>
  693. <p>All writes to client sockets go through throttled_write().
  694. This code addresses two cases. First, client has dropped the connection.
  695. Second, client is connected but not picking up data and our buffers are
  696. backing up. If we let this continue, the write buffers will fill and
  697. the effect will be denial-of-service to clients that are better behaved.</p>
  698. <p>Our strategy is brutally simple and takes advantage of the fact that
  699. GPS data has a short shelf life. If the client doesn't pick it up
  700. within a few minutes, it's probably not useful to that client. So if
  701. data is backing up to a client, drop that client. That's why we set
  702. the client socket to non-blocking.</p>
  703. <p>For similar reasons, we don't try to recover from short writes to
  704. the GPS, e.g. of DGPS corrections. They're packetized, so the device
  705. will ignore a fragment, and there will generally be another correction
  706. coming along shortly. Fixing this would require one of two
  707. strategies:</p>
  708. <ol>
  709. <li><p><b>Buffer any data not shipped by a short write for
  710. retransmission.</b> Would require us to use malloc and just be begging
  711. for memory leaks.</p></li>
  712. <li><p><b>Block till select indicates the hardware or lower layer is
  713. read for write.</b> Could introduce arbitrary delays for
  714. time-sensitive data.</p></li>
  715. </ol>
  716. <p>So far, as of early 2009, we've only seen short writes on Bluetooth
  717. devices under Linux. It is not clear whether this is a problem
  718. with the Linux Bluetooth driver (it could be failing to coalesce
  719. and buffer adjacent writes properly) or with the underlying hardware
  720. (Bluetooth devices tend to be cheaply made and dodgy in other respects
  721. as well).</p>
  722. <p>GPS input updates an internal data structure which has slots in it for
  723. all the data you can get from a GPS. Client commands mine that
  724. structure and ship reports up the socket to the client. DGPS data is
  725. passed through, raw, to the GPS.</p>
  726. <p>The trickiest part of the code is the handling of input sources in
  727. gpsd.c itself. It had to tolerate clients connecting and
  728. disconnecting at random times, and the GPS being unplugged and
  729. replugged, without leaking file descriptors; also arrange for the GPS
  730. to be open when and only when clients are active.</p>
  731. <p>The special control socket is primarily there to be used by
  732. hotplug facilities like Linux udev. It is intended to be written
  733. to by scripts activated when a relevant device (basically, a USB
  734. device with one of a particular set of vendor IDs) is connected to
  735. or disconnected from the system. On receipt of these messages,
  736. <code>gpsd</code> may add a device to its pool, or remove one and
  737. (if possible) shift clients to a different one.</p>
  738. <p>The reason these scripts have to look for vendor IDs is that USB
  739. has no GPS class. Thus, GPSes present the ID of whatever
  740. serial-to-USB converter chip they happen to be using. Fortunately
  741. there are fewer types of these in use than there are GPS chipsets;
  742. in fact, just two of them account for 80% of the USB GPS market
  743. and don't seem to be used by other consumer-grade devices.</p>
  744. <h2 id="initialization">Driver initialization and wrapup</h2>
  745. <p>Part of the job <code>gpsd</code> does is to minimize the amount
  746. of time attached GPSes are in a fully powered-up state. So there
  747. is a distinction between initializing the <code>gpsd</code> internal
  748. channel block structure for managing a GPS device (which we do when
  749. the hotplug system tells us it's available) and activating the device
  750. (when a client wants data from it) which actually involves opening it
  751. and preparing to read data from it. This is why
  752. <code>gpsd_init()</code> and <code>gpsd_activate()</code> are separate
  753. library entry points.</p>
  754. <p>There is also a distinction between deactivating a device (which we
  755. do when no users are listening to it) and finally releasing
  756. the <code>gpsd</code> channel block structure for managing the device
  757. (which typically happens either when <code>gpsd</code> terminates or
  758. the hotplug system tells <code>gpsd</code> that the device has been
  759. disconnected). This is why <code>gpsd_deactivate()</code> and
  760. <code>gpsd_wrap()</code> are separate entry points.</p>
  761. <p><code>gpsd</code> has to configure some kinds of GPS devices when
  762. it recognizes them; this is what the <code>event_identify</code> and
  763. <code>event_configure</code> hooks are for. <code>gpsd</code> tries
  764. to clean up after itself, restoring settings that were changed by the
  765. configurator method; this is done by <code>gpsd_deactivate()</code>,
  766. which fires the <code>deactivate</code> event so the driver can revert
  767. settings.</p>
  768. <h2 id="autoconfiguration">Autoconfiguration</h2>
  769. <p>One of the design goals for <code>gpsd</code> is to be as near
  770. zero-configuration as possible. Under most circumstances, it doesn't
  771. require either the GPS type or the serial-line parameters to connect
  772. to it to be specified. Presently, here's roughly how the autoconfig
  773. works. (I say "roughly" because at any given time this sequence may
  774. leave out recently-added binary packet types.)</p>
  775. <ol>
  776. <li>At each baud rate <code>gpsd</code> grabs packets until the
  777. sniffer sees either a well-formed and checksum-verified NMEA
  778. packet, a well-formed and checksum-verified packet of one of the
  779. binary protocols, or it sees one of the two special trigger strings
  780. EARTHA or ASTRAL, or it fills a long buffer with garbage (in which
  781. case it steps to the next baud-rate/parity/stop-bit).</li>
  782. <li>If it finds a SiRF packet, it queries the chip for firmware
  783. version. If the version is &lt; 231.000 it drops back to SiRF NMEA.
  784. We're done.</li>
  785. <li>If it finds a Zodiac binary packet (led with 0xff 0x81), it
  786. switches to the Zodiac driver. We're done.</li>
  787. <li>If it finds a Navcom binary packet (led with 0x10 0x02 0x99 0x66)
  788. it switches to Navcom driver. We're done.</li>
  789. <li>If it finds a TSIP binary packet (led with 0x10=DLE), it
  790. switches to the TSIP driver. We're done.</li>
  791. <li>If it finds an iTalk v3 binary packet (led with &lt;! ), it
  792. switches to the iTalk driver. We're done.</li>
  793. <li>If it finds a UBX binary packet (led with &mu;B ), it
  794. switches to the UBX driver. We're done.</li>
  795. <li>If it finds EARTHA, it selects the Earthmate driver, which then
  796. flips the connection to Zodiac binary mode. We're done.</li>
  797. <li>If it finds ASTRAL, it feeds the TripMate on the other end what
  798. it wants and goes to Tripmate NMEA mode. We're done.</li>
  799. <li>If it finds a NMEA packet, it selects the NMEA driver. This
  800. initializes by shipping all vendor-specific initialization strings
  801. to the device. The objectives are to enable GSA, disable GLL, and
  802. disable VTG. Probe strings go here too, like the one that turns
  803. on SiRF debugging output in order to detect SiRF chips.</li>
  804. <li>Now gpsd reads NMEA packets. If it sees a driver trigger string it
  805. invokes the matching driver.</li>
  806. </ol>
  807. <p>The outcome is that we know exactly what we're looking at, without any
  808. driver-type or baud rate options.</p>
  809. <p>(The above sequence of steps may be out of date. If so, it will
  810. probably be because we have added more recognized packet types and drivers.)</p>
  811. <h2 id="error">Error modeling</h2>
  812. <p>To estimate errors (which we must do if the GPS isn't nice and reports
  813. them in meters with a documented confidence interval), we need to
  814. multiply an estimate of User Equivalent Range Error (UERE) by the
  815. appropriate dilution factor,</p>
  816. <p>The UERE estimate is usually computed as the square root of the sum of
  817. the squares of individual error estimates from a physical model. The
  818. following is a representative physical error model for satellite range
  819. measurements:</p>
  820. <p>From R.B Langley's 1997 "The GPS error budget".
  821. GPS World , Vol. 8, No. 3, pp. 51-56</p>
  822. <div>&nbsp;</div>
  823. <table style="border: 1px solid gray">
  824. <tr><td>Atmospheric error &mdash; ionosphere</td><td>7.0m</td></tr>
  825. <tr><td>Atmospheric error &mdash; troposphere</td><td>0.7m</td></tr>
  826. <tr><td>Clock and ephemeris error</td><td>3.6m</td></tr>
  827. <tr><td>Receiver noise</td><td>1.5m</td></tr>
  828. <tr><td>Multipath effect</td><td>1.2m</td></tr>
  829. </table>
  830. <p>From Hoffmann-Wellenhof et al. (1997), "GPS: Theory and Practice", 4th
  831. Ed., Springer.</p>
  832. <div>&nbsp;</div>
  833. <table style="border: 1px solid gray">
  834. <tr><td>Code range noise (C/A)</td><td>0.3m</td></tr>
  835. <tr><td>Code range noise (P-code)</td><td>0.03m</td></tr>
  836. <tr><td>Phase range</td><td>0.005m</td></tr>
  837. </table>
  838. <p>We're assuming these are 2-sigma error ranges. This needs to
  839. be checked in the sources. If they're 1-sigma the resulting UEREs
  840. need to be doubled.</p>
  841. <p>Carl Carter of SiRF says: "Ionospheric error is typically corrected
  842. for at least in large part, by receivers applying the Klobuchar model
  843. using data supplied in the navigation message (subframe 4, page 18,
  844. Ionospheric and UTC data). As a result, its effect is closer to that
  845. of the troposphere, amounting to the residual between real error and
  846. corrections."</p>
  847. <p>"Multipath effect is dramatically variable, ranging from near 0 in
  848. good conditions (for example, our roof-mounted antenna with few if any
  849. multipath sources within any reasonable range) to hundreds of meters in
  850. tough conditions like urban canyons. Picking a number to use for that
  851. is, at any instant, a guess."</p>
  852. <p>"Using Hoffman-Wellenhoff is fine, but you can't use all 3 values.
  853. You need to use one at a time, depending on what you are using for
  854. range measurements. For example, our receiver only uses the C/A
  855. code, never the P code, so the 0.03 value does not apply. But once
  856. we lock onto the carrier phase, we gradually apply that as a
  857. smoothing on our C/A code, so we gradually shift from pure C/A code
  858. to nearly pure carrier phase. Rather than applying both C/A and
  859. carrier phase, you need to determine how long we have been using
  860. the carrier smoothing and use a blend of the two."</p>
  861. <p>On Carl's advice we would apply tropospheric error twice, and use
  862. the largest Wellenhof figure:</p>
  863. <p>UERE = sqrt(0.7^2 + 0.7^2 + 3.6^2 + 1.5^2 + 1.2^2 + 0.3^2) = 4.1</p>
  864. <p>DGPS corrects for atmospheric distortion, ephemeris error, and satellite/
  865. receiver clock error. Thus:</p>
  866. <p>UERE = sqrt(1.5^2 + 1.2^2 + 0.3^2) = 1.8</p>
  867. <p>which we round up to 2 (95% confidence).</p>
  868. <p>Due to multipath uncertainty, Carl says 4.1 is too low and recommends
  869. a non-DGPS UERE estimate of 8 (95% confidence). That's what we use.</p>
  870. <h2 id="ancient">Ancient history</h2>
  871. <p>The project is presently kept in a git repository. Up until
  872. mid-August 2004 (r256) it was kept in CVS, which was mechanically
  873. upconverted to Subversion. On 12 March 2010 the Subversion repository was
  874. converted to git. The external releases from the Subversion era
  875. still exist as tags.</p>
  876. <h1 id="newsentence">How to add a new sensor type</h1>
  877. <p>GPSD is designed to be relatively easily extensible to support new
  878. sensor types and sentences. Still, there's a lot of detail work
  879. involved. For your patch to be accepted, you need to do enough of the
  880. steps that the maintainers won't have to spend large amounts of time
  881. cleaning up after you. Here are the things we'll be looking for.
  882. <h2 id="newdriver">Driver-level support</h2>
  883. <p>Your first and most obvious step will be driver support. You'll
  884. need to parse the sentences coming in from your sensor and unpack them
  885. into a substructure that lives inside struct gps_data_t in gps.h.</p>
  886. <p>In the most general case this might require you to
  887. <a href="writing-a-driver.html">write a new driver</a>. We won't
  888. cover that case here; more usually what you'll be doing is
  889. adding support for a few new NMEA sentence types.</p>
  890. <p>Usually you'll be able to model your sentence parsing on a handler
  891. for one of the existing sentence types in driver_nmea0183.c. The part
  892. of this that requires the most time and care is actually designing the
  893. structures to unpack the sentence data into.</p>
  894. <p>Do not casually modify existing structures. Doing this causes an
  895. ABI break and annoys our application developers. If you must modify
  896. an existing structure, put your new members at the end of the
  897. structure rather than at the beginning or in the middle.</p>
  898. <p>Be aware that bits in the data-validity mask are a scarce resource
  899. and claim as few of them as possible, no more than one per sentence
  900. type. If you are adding support for a sensor class with a particularly
  901. complex repertoire of sentences, please claim only one bit for the
  902. sensor type, then have your own variant mask or sentence-type field in the
  903. substructure for that sentence. (See as an example the way AIVDM
  904. sentences from Marine AIS sensors are handled.)</p>
  905. <h2 id="newjson">JSON output</h2>
  906. <p>Your next step is designing and implementing the code that dumps
  907. the data from your sensor as JSON objects. In general each new
  908. sentence type will need to become a distinct JSON object - but there
  909. might be AIS-like exceptions if your sensor has particularly complex
  910. behavior.</p>
  911. <p>This part is not usually complicated. The biggest design issue is
  912. choosing good names for your object classes and field names; once
  913. you've done that, writing the dump code is pretty easy.</p>
  914. <p>Be aware that the JSON dialect available for report objects is
  915. restricted in a couple of ways. You cannot use the JSON null value,
  916. and arrays must be homogeneous - that is, every element of an array
  917. must have the same attribute set. These restrictions enable the
  918. JSON content to fit in C structures.</p>
  919. <p>Support for subobjects and subarrays is available but coding for
  920. these on the client side is subtle and tricky. Avoid using these if
  921. possible; they'll make more work for you on the client side.</p>
  922. <h2 id="newtest">Updating the test suite</h2>
  923. <p>You must supply at least one packet log from the device containing
  924. typical data, to be added to our regression-test suite.</p>
  925. <p>This is <em>absolutely required</em>. We maintain GPSD's quality
  926. by being very rigorous about regression testing. A device for which
  927. we can't test the code's correctness is a device we won't try to
  928. support.</p>
  929. <p>See the FAQ material on <a href="faq.html#logformat">annotating a
  930. test log</a> for how to do this properly.</p>
  931. <h2 id="newclient">Client-side support</h2>
  932. <p>It's not enough that the daemon emits JSON objects corresponding to
  933. your sentences. Clients need to be able to handle these, and that means
  934. our client libraries need to know how to unpack the JSON into
  935. client-side versions of the data structures updated at driver level
  936. inside the daemon.</p>
  937. <p>This is actually the trickiest part of adding a new sentence. For
  938. bindings other than the core C one the binding maintainers usually
  939. handle it, but you must write the C support yourself.</p>
  940. <p>This will require that you learn how to tell GPSD's internal JSON
  941. parser how to unpack your objects. This will come down to composing
  942. C initializers that control the parse; look in libgps_json.c for
  943. examples of how to do this.</p>
  944. <h2 id="newdoc">Documentation</h2>
  945. <p>Once you have your JSON emitted by the daemon and parsed by libgps,
  946. you must describe it on the gpsd_json(8) page. This is
  947. <em>required</em>. The job isn't finished until the documentation is
  948. done.</p>
  949. <h2 id="newstyle">Points for style</h2>
  950. <p>Audit your code with cppcheck and scan-build (there are productions in
  951. the SConstruct file). Patches that are not just clean but properly
  952. annotated for static checking will give the maintainers warm
  953. fuzzy feelings and go right to the front of the queue.</p>
  954. <p>Adding sentence support to the Python binding is usually trivial;
  955. if you've stuck to a simple enough design of your JSON object(s) you
  956. may not have to do any work at all. If you have any Python chops,
  957. looking into this yourself will make the maintainers happy.</p>
  958. <p>Enhancing the test clients so they can display data from your new
  959. sentence type is a good thing, but not required.</p>
  960. <h1 id="trouble">Known trouble spots</h1>
  961. <h2 id="y2k1">The Y2.1K problem and other calendar issues</h2>
  962. <p>Because of limitations in various GPS protocols (e.g., they were
  963. designed by fools who weren't looking past the ends of their noses)
  964. this code unavoidably includes some assumptions that will turn around
  965. and bite on various future dates. </p>
  966. <p>The three specific problems are:</p>
  967. <ol>
  968. <li>The GPS radio format has a Y2K-style bug, the week counter
  969. rollover, which happens either every 1024 weeks (roughly 19.6 years)
  970. or every 8192 weeks (roughly 157 years), depending on whether your
  971. receiver can decode a 10-bit or 13-bit GPS week field. At the time of
  972. this writing the last 0 week was in 2019, the next 10-bit wraparound
  973. will be in 2038, and the next 13-bit wraparound will be in 2137.</li>
  974. <li>NMEA delivers only two-digit years.</li>
  975. <li>SiRF chips at firmware level 231 deliver only GPS time in binary mode,
  976. not leap-second-corrected UTC.</li>
  977. </ol>
  978. <p>Because of the first problem, the receiver's notion of the year may
  979. reset to the year of the last zero week if it is cold-booted on a date
  980. after a rollover. This can have side effects:</p>
  981. <ol>
  982. <li>The year part of the reported date will be invalid.</li>
  983. <li>UTC time will be correct, but a local time calculated on this
  984. will sometimes be off +- 1 hour, due to incorrect DST calculation.</li>
  985. <li>Some receivers may fail to get a fix, especially if they don't
  986. have a recent ephemeris.</li>
  987. </ol>
  988. <p>The new 13-bit week number is only provided by the new "CNAV" data,
  989. which in turn is (or will be) available only in newly added GPS signals.
  990. Based on the carrier frequencies used, only the newest of the new
  991. signals (L1C) will be available to common civilian receivers, even with
  992. compatible hardware and firmware. This signal is unavailable from
  993. satellites earlier than Block III, which are currently (July 2016) not
  994. expected to begin to launch earlier than September 2016. Given that it
  995. takes years to launch a full constellation of satellites, it's highly
  996. unlikely that CNAV data with "operational" status will be available to
  997. common civilian receivers for some years yet.</p>
  998. <p>For these reasons, GPSD needs the host computer's system clock to
  999. be accurate to within one second.</p>
  1000. <p>When debugging time and date issues, you may find an interactive
  1001. <a href="http://navigationservices.agi.com/GNSSWeb/">GPS Date Calendar</a>
  1002. useful.</p>
  1003. <h2 id="hotplug">Hotplug interface problems</h2>
  1004. <p>The hotplug interface works pretty nicely for telling gpsd which
  1005. device to look at, at least on Fedora and Ubuntu Linux machines. But
  1006. it's Linux-specific. OpenBSD (at least) features a hotplug daemon
  1007. with similar capabilities. We ought to do the right thing there as
  1008. well.</p>
  1009. <p>Hotplug is nice, but on Linux it appears to be a moving target. For
  1010. help debugging a hotplug problem, see <a
  1011. href="troubleshooting.html#hotplugtroubleshooting">Udev Hotplug
  1012. Troubleshooting</a>.</p>
  1013. <h2 id="security">Security Issues</h2>
  1014. <p>Between versions 2.16 and 2.20, hotplugging was handled in the most
  1015. obvious way, by allowing the F command to declare new GPS devices for
  1016. gpsd to look at. Because gpsd ran as root, this had problems:</p>
  1017. <ol>
  1018. <li>A malicious client with non-root access on the host could use F to
  1019. point gpsd at a spoof GPS that was actually a pty feeding bogus
  1020. location data.</li>
  1021. <li>A malicious client could use repeated probes of a target tty or
  1022. other device to cause data loss to other users. This is a potential
  1023. remote exploit! Not too bad if the bytes he steals are your mouse, it
  1024. would just get jumpy and jerky &mdash; but suppose they're from an actual
  1025. tty and sections drop out of a serial data stream you were relying on?</li>
  1026. </ol>
  1027. <p>The conclusion was inescapable. Switching among and probing
  1028. devices that gpsd already knows about can be an unprivileged
  1029. operation, but editing gpsd's device list must be privileged. Hotplug
  1030. scripts should be able to do it, but ordinary clients should not.</p>
  1031. <p>Adding an authentication mechanism was considered and rejected (can you
  1032. say "can of big wriggly worms"?). Instead, there is a separate
  1033. control channel for the daemon, only locally accessible, only
  1034. recognizing "add device" and "remove device" commands.</p>
  1035. <p>The channel is a Unix-domain socket owned by root, so it has
  1036. file-system protection bits. An intruder would need root permissions
  1037. to get at it, in which case you'd have much bigger problems than a
  1038. spoofed GPS.</p>
  1039. <p>More generally, certainly gpsd needs to treat command input as
  1040. untrusted and for safety's sake should treat GPS data as untrusted
  1041. too (in particular this means never assuming that either source won't
  1042. try to overflow a buffer).</p>
  1043. <p>Daemon versions after 2.21 drop privileges after startup, setting UID
  1044. to "nobody" and GID to whichever group owns the GPS device specified
  1045. at startup time &mdash; or, if it doesn't exist, the system's
  1046. lowest-numbered TTY device named in PROTO_TTY. It may be necessary to
  1047. change PROTO_TTY in gpsd.c for non-Linux systems.</p>
  1048. <h1 id="newtypes">Adding new GPS types</h1>
  1049. <p>This section explains the conventions drivers for new devices
  1050. should follow.</p>
  1051. <h2 id="drivers">Driver architecture</h2>
  1052. <p>Internally, gpsd supports multiple GPS types. All are represented by
  1053. driver method tables; the main loop knows nothing about the driver
  1054. methods except when to call them. At any given time one driver is
  1055. active; by default it's the NMEA one.</p>
  1056. <p>To add a new device, populate another driver structure and add it to
  1057. the null-terminated array in drivers.c.</p>
  1058. <p>Unless your driver is a nearly trivial variant on an existing one,
  1059. it should live in its own C source file named after the driver type.
  1060. Add it to the libgpsd_sources name list in the SConstruct file.</p>
  1061. <p>The easiest way to write a driver is probably to copy the driver_proto.c
  1062. file in the source distribution, change names appropriately, and write
  1063. the guts of the analyzer and writer functions. Look in gpsutils.c
  1064. before you do; driver helper functions live there. Also read some
  1065. existing drivers for clues.</p>
  1066. <p>You can read an implementer's <a href="writing-a-driver.html">Notes
  1067. On Writing A GPSD Driver.</a></p>
  1068. <p>There's a second kind of driver architecture for
  1069. <code>gpsmon</code>, the real-time packet monitor and diagnostic tool.
  1070. It works from monitor-object definitions that include a pointer to the
  1071. device driver for the GPS type you want to monitor. See
  1072. monitor_proto.c for a prototype and technical details.</p>
  1073. <h2 id="notdriver">When not to add a driver</h2>
  1074. <p>It is not necessary to add a driver just because your NMEA GPS wants
  1075. some funky initialization string. Simply ship the string in the
  1076. initializer for the default NMEA driver. Because vendor control
  1077. strings live in vendor-specific namespaces (PSRF for SiRF, PGRM for
  1078. Garmin, etc.) your initializing control string will almost certainly
  1079. be ignored by anything not specifically watching for it.</p>
  1080. <h2 id="init">Initializing time and date</h2>
  1081. <p>Some mode-changing commands have time field that initializes the GPS
  1082. clock. If the designers were smart, they included a control bit that
  1083. allows the GPS to retain its clock value (and previous fix, if any)
  1084. and for you to leave those fields empty (sometimes this is called "hot
  1085. start").</p>
  1086. <p>If the GPS-Week/TOW fields are required, as on the Evermore chip,
  1087. don't just zero them. GPSes do eventually converge on the correct
  1088. time when they've tracked the code from enough satellites, but the
  1089. time required for convergence is related to how far off the initial
  1090. value is. Most modern receivers can cold start in 45 seconds given
  1091. good reception; under suboptimal conditions this can take upwards of
  1092. ten minutes. So make a point of getting the time of week right.</p>
  1093. <h2 id="invocation">How drivers are invoked</h2>
  1094. <p>Drivers are invoked in one of three ways: (1) when the NMEA driver
  1095. notices a trigger string associated with another driver. (2) when the
  1096. packet state machine in packet.c recognizes a special packet type, or
  1097. (3) when a probe function returns true during device open.</p>
  1098. <p>Each driver may have a trigger string that the NMEA interpreter
  1099. watches for. When that string is recognized at the start of a
  1100. line, the interpreter switches to its driver.</p>
  1101. <p>A good thing to send from the NMEA configure-event code is probe
  1102. strings. These are strings which should elicit an identifying
  1103. response from the GPS that you can use as a trigger string for a
  1104. native-mode driver, or a response which has an identifiable binary
  1105. packet type.</p>
  1106. <p>Don't worry about probe strings messing up GPSes they aren't meant for.
  1107. In general, all GPSes have rather rigidly defined packet formats with
  1108. checksums. Thus, for this probe to look legal in a different binary
  1109. command set, not only would the prefix and any suffix characters have
  1110. to match, but the checksum algorithm would have to be identical.</p>
  1111. <p>Incoming characters from the GPS device are gathered into packets
  1112. by an elaborate state machine in packet.c. The purpose of this
  1113. state machine is so gpsd can autobaud and recognize GPS types
  1114. automatically. The other way for a driver to be invoked is for
  1115. the state machine to recognize a special packet type associated
  1116. with the driver. It will look through the list of drivers compiled
  1117. in to find the (first) one that handles that packet type.</p>
  1118. <p>If you have to add a new packet type to packet.c, add tests for the
  1119. type to the test_packet.c code.</p>
  1120. <p>Probe-detect methods are intended for drivers that don't use the packet
  1121. getter because they read from a device with special kernel support.
  1122. See the Garmin binary driver for an example.</p>
  1123. <h3 id="reports">Where to put the data you get from the GPS</h3>
  1124. <p>Your driver should put new data from each incoming packet or
  1125. sentence in the 'gpsdata' member of the GPS (fixes go in the 'newdata'
  1126. member), and return a validity flag mask telling what members were
  1127. updated (all float members are initially set to not-a-number. as
  1128. well). There is driver-independent code that will be responsible for
  1129. merging that new data into the existing fix. To assist this, the
  1130. CYCLE_START_SET flag is special. Set this when the driver returns the
  1131. first timestamped message containing fix data in an update cycle.
  1132. (This excludes satellite-picture messages and messages about GPS
  1133. status that don't contain fix data.)</p>
  1134. <p>Your packet parser must return field-validity mask bits (using the
  1135. _SET macros in gps.h), suitable to be put in session->gpsdata.valid.
  1136. The watcher-mode logic relies on these as its way of knowing what to
  1137. publish. Also, you must ensure that gpsdata.fix.mode is set properly to
  1138. indicate fix validity after each message; the framework code relies on
  1139. this. Finally, you must set gpsdata.status to indicate when DGPS
  1140. fixes are available, whether through RTCM or SBAS (eg WAAS).</p>
  1141. <p>Your packet parser is also responsible for setting the tag field in
  1142. the gps_data_t structure. The packet getter will set the
  1143. sentence-length for you; it will be raw byte length, including both
  1144. payload and header/trailer bytes.</p>
  1145. <p>Note, also, that all the timestamps your driver puts in the session
  1146. structure should be UTC (with leap-second corrections) not just Unix
  1147. seconds since the epoch. The report-generator function for D
  1148. does <em>not</em> apply a timezone offset.</p>
  1149. <h3 id="confidence">Report errors with a 95% confidence interval</h3>
  1150. <p>gpsd drivers are expected to report position error estimates with
  1151. a 95% confidence interval. A few devices (Garmins and Zodiacs)
  1152. actually report error estimates. For the rest we have to compute them
  1153. using an error model.</p>
  1154. <p>Here's a table that explains how to convert from various
  1155. confidence interval units you might see in vendor documentation.</p>
  1156. <div>&nbsp;</div>
  1157. <table style="border: 1px solid gray">
  1158. <tr><td>sqr(alpha)</td><td>Probability</td><td>Notation</td></tr>
  1159. <tr><td>1.00 </td><td>39.4% </td><td>1-sigma or standard ellipse</td></tr>
  1160. <tr><td>1.18 </td><td>50.0% </td><td>Circular Error Probable (CEP)</td></tr>
  1161. <tr><td>1.414 </td><td>63.2% </td><td>Distance RMS (DRMS)</td></tr>
  1162. <tr><td>2.00 </td><td>86.5% </td><td>2 sigma ellipse</td></tr>
  1163. <tr><td>2.45 </td><td>95.0% </td><td>95% confidence level</td></tr>
  1164. <tr><td>2.818 </td><td>98.2% </td><td>2DRMS</td></tr>
  1165. <tr><td>3.00 </td><td>98.9% </td><td>3 sigma ellipse</td></tr>
  1166. </table>
  1167. <p>There are constants in gpsd.h for these factors.</p>
  1168. <h3 id="logfiles">Log files for regression testing</h3>
  1169. <p>Any time you add support for a new GPS type, you should also send us a
  1170. representative log for your GPS. This will help ensure that support
  1171. for your device is never broken in any gpsd release, because we will
  1172. run the full regression before we ship.</p>
  1173. <p>The correct format for a capture file is described in the
  1174. <a href='faq.html#logformat'>FAQ entry on reporting bugs</a>.</p>
  1175. <p>See the header comment of the gpsfake.py module for more about the
  1176. logfile format.</p>
  1177. <p>An ideal log file for regression testing would include an initial
  1178. portion during which the GPS has no fix, a portion during which it has
  1179. a fix but is stationary, and a portion during which it is moving.</p>
  1180. <h1 id="designahead">Future Protocol Directions</h1>
  1181. <p>The new protocol based on <a href="http://www.json.org/">JSON</a>
  1182. (JavaScript Object Notation) shipped in 2.90.</p>
  1183. <p>A major virtue of JSON is its extensibility. There are
  1184. <em>lots</em> of other things a sensor wedded to a GPS might report
  1185. that don't fit the position-velocity-time model of the oldstyle O report.
  1186. Depth of water. Temperature of water. Compass heading. Roll.
  1187. Pitch. Yaw. We've already had requests to handle some of these for
  1188. NMEA-emitting devices like magnetic compasses (which report heading
  1189. via a proprietary TNTHTM sentence) and fish finders (which report
  1190. water depth and temperature via NMEA DPT and MTW sentences). JSON
  1191. gives a natural way to add ad-hoc fields, and we expect to
  1192. exploit that in the future.</p>
  1193. <h2 id="proposed">Proposed sentences:</h2>
  1194. <p>Chris Kuethe has floated the following list requests for
  1195. discussion:</p>
  1196. <pre>
  1197. ?almanac -&gt; poll the almanac from the receiver
  1198. ?ephemeris -&gt; poll the ephemeris from the receiver
  1199. ?assist -&gt; load assistance data (time, position, etc) into the receiver
  1200. ?raw -&gt; get a full dump of the last measurement cycle... at least
  1201. clock, doppler, pseudorange and carrier phase.
  1202. ?readonly -&gt; get/set read-only mode. no screwing up bluetooth devices
  1203. ?listen -&gt; set the daemon's bind address. added privacy for laptop users.
  1204. ?port -&gt; set the daemon's control port used by the regression
  1205. tests, at least.
  1206. ?debug -&gt; set/modify the daemon's debug level, including after launch.
  1207. </pre>
  1208. <h1 id="blindalleys">Blind alleys</h1>
  1209. <p>Things we've considered doing and rejected.</p>
  1210. <h2 id="oncepercycle">Reporting fix data only once per cycle</h2>
  1211. <p>See the discussion of the buffering problem, above. The "Buffer all,
  1212. report then clear on start-of-cycle" policy would introduce an
  1213. unpleasant amount of latency. gpsd actually uses the "Buffer all,
  1214. report on every packet, clear at start-of-cycle" policy.</p>
  1215. <h2 id="shipstrings">Allowing clients to ship arbitrary control strings to a GPS</h2>
  1216. <p>Tempting &mdash; it would allow us to do gpsmon-like things with the
  1217. daemon running &mdash; but a bad idea. It would make denial-of-service
  1218. attacks on applications using the GPS far too easy. For example,
  1219. suppose the control string were a baud-rate change?</p>
  1220. <h2 id="fifo">Setting FIFO threshold to 1 to reduce jitter in serial-message times</h2>
  1221. <p>When using gpsd as a time reference, one of the things we'd like to do
  1222. is make the amount of lag in the message path from GPS to GPS as small
  1223. and with as little jitter as possible, so we can correct for it with
  1224. a constant offset.</p>
  1225. <p>A possibility we considered is to set the FIFO threshold on the serial
  1226. device UART to 1 using TIOCGSERIAL/TIOCSSERIAL. This would, in
  1227. effect, disable transmission buffering, increasing lag but decreasing
  1228. jitter.</p>
  1229. <p>But it's almost certainly not worth the work. Rob Janssen
  1230. reckons that at 4800bps the UART buffering can cause at most
  1231. about 15msec of jitter. This is, observably, swamped by other less
  1232. controllable sources of variation.</p>
  1233. <p>However, it turns out this is only an issue for EverMore chips. SiRF GPSes
  1234. can get the offset from the PPS or subframe data; NMEA GPSes don't
  1235. need it; and the other binary protocols supply it. Looks like
  1236. it's not worth doing.</p>
  1237. <h2 id='subsecond'>Subsecond polling</h2>
  1238. <p>gpsd relies on the GPS to periodically send TPV reports to it. A
  1239. few GPSes have the capability to change their cycle time so they can
  1240. ship reports more often (gpsd 'c' command). These all send in some
  1241. vendor-binary format; no NMEA GPS I've ever seen allows you to set a
  1242. cycle time of less than a second, if only because at 4800bps, a full
  1243. TPV report takes just under one second in NMEA.</p>
  1244. <p>But most GPSes send TPV reports once a second. At 50km/h (31mi/h)
  1245. that's 13.8 meters change in position between updates, about the same
  1246. as the uncertainty of position under typical conditions.</p>
  1247. <p>There is, however, a way to sample some GPSes at higher frequency. SiRF
  1248. chips, and some others, allow you to shut down periodic notifications
  1249. and poll them for TPV. At 57600bps we could poll a NMEA GPS 16 times
  1250. a second, and a SiRF one maybe 18 times a second.</p>
  1251. <p>Alas, Chris Kuethe reports: "At least on the SiRF 2 and 3 receivers
  1252. I have, you get one fix per second. I cooked up a test harness to
  1253. disable as many periodic messages as possible and then poll as quickly
  1254. as possible, and the receiver would not kick out more than one fix per
  1255. second. Foo!"</p>
  1256. <p>So subsecond polling would be a blind alley for all SiRF devices
  1257. and all NMEA devices. That's well over 90% of cases and renders it
  1258. not worth doing.</p>
  1259. <h1 id='release'>Release Procedure</h1>
  1260. <p>First, defining some terms. There are three tiers of code in our tarballs.
  1261. Each has a different risk profile.</p>
  1262. <h3>1) Exterior code</h3>
  1263. <p>Test clients and test tools: <code>xgps</code>, <code>cgps</code>,
  1264. <code>gpsfake</code>, <code>gpsprof</code>, <code>gpsmon</code>, etc.
  1265. These are at low risk of breakage and are easy to eyeball-check for
  1266. correctness -- when they go wrong they tend to do so in obvious ways.
  1267. Point errors in a tool don't compromise the other tools or the
  1268. daemon.</p>
  1269. <h3>2) Device drivers</h3>
  1270. <p>Drivers for the individual GPS device types. Errors in a driver can
  1271. be subtle and hard to detect, but they generally break support for one
  1272. class of device without affecting others. Driver maintainers can test
  1273. their drivers with high confidence.</p>
  1274. <h3>3) Core code</h3>
  1275. <p>Core code is shared among all device types; most notably, it includes
  1276. the packet-getter state machine, the channel-management logic, and
  1277. the error-modeling code. Historically these are the three most
  1278. bug-prone areas in the code.</p>
  1279. <p>We also need to notice that there are two different kinds of devices
  1280. with very different risk profiles:</p>
  1281. <p>A) Static-testable: These are devices like NMEA and SiRF chipsets that
  1282. can be effectively simulated with a test-load file using gpsfake. We
  1283. can verify these with high confidence using a mechanical regression test.</p>
  1284. <p>B) The problem children: Currently this includes Garmin USB and the
  1285. PPS support (both serial and USB via Macx-1). In the future it must
  1286. include any other devices that aren't static-testable. When the
  1287. correctness of drivers and core code in handling is suspect, they have
  1288. to be live-tested by someone with access to the actual device.</p>
  1289. <p>The goal of our release procedure is simple: prevent functional regressions.
  1290. No device that worked in release N should break in release N+1. Of course
  1291. we also want to prevent shipping broken core code.</p>
  1292. <p>For static-testable devices this is fairly easy to ensure. Now that
  1293. we've fixed the problems with ill-conditioned floating-point, the
  1294. regression-test suite does a pretty good job of exercising those
  1295. drivers and the related core code and producing repeatable results.
  1296. Accordingly, I'm fairly sure we will never again ship a release with
  1297. serious breakage on NMEA or SiRF devices.</p>
  1298. <p>The problem children are another matter. Right now our big exposure
  1299. here is Garmins, but we need to have good procedure in case we get
  1300. our TnT support unbroken and for other ill-behaved devices we might
  1301. encounter in the future.</p>
  1302. <p>Here are the new release-readiness states:</p>
  1303. <p>State 0 (red): There are known blocker bugs, Blocker bugs include functional
  1304. regressions in core or driver code. </p>
  1305. <p>State 1 (blue): There are no known blocker bugs. 'scons
  1306. testregress' passes, but problem-children (USB Garmin and PPS) have
  1307. not been live-tested.</p>
  1308. <p>State 2 (yellow): There are no known blocker bugs. 'scons testregress'
  1309. passes. Problem children have been live-tested. From this state, we
  1310. drop back to state 1 if anyone commits a logic change to core code or
  1311. the driver for a problem child. In state 2, devs with release
  1312. authority (presently myself, Chris, and Gary) may ship a release
  1313. candidate at any time.</p>
  1314. <p>State 3 (green): We've been in state 2 for 7 days. In state 3, a dev
  1315. with release authority can call a freeze for release.</p>
  1316. <p>State 4: (freeze): No new features that could destabilize existing code.
  1317. Release drops us to state 3.</p>
  1318. <p>When you do something that changes our release state -- in particular,
  1319. when you commit a patch that touches core or a problem-child driver
  1320. at state 2 -- you must notify the dev list.</p>
  1321. <p>Anyone notifying the list of a blocker bug drops us back to state 0.</p>
  1322. <p>When you announce a state change on the dev list, do it like this:</p>
  1323. <pre>
  1324. Red light: total breakage in Garmin USB, partial breakage in Garmin serial
  1325. Blue light: no known blockers, cosmetic problems in xgps
  1326. Yellow light: Garmins tested successfully 20 Dec 2007
  1327. Green light: I'm expecting to call freeze in about 10 days
  1328. Freeze: Scheduled release date 1 Feb 2008
  1329. </pre>
  1330. <h2>Release Checklist</h2>
  1331. <p>This is a reminder for release engineers preparing to ship a public
  1332. <code>gpsd</code> version. Release requires the following steps in
  1333. the following order:</p>
  1334. <dl>
  1335. <dt>1. Check the <a href="@BUGTRACKER@">bug tracker</a> for
  1336. release blockers.</dt>
  1337. <dd><p>Check support requests, too, and <a href="https://bugs.debian.org/cgi-bin/pkgreport.cgi?src=gpsd&amp;repeatmerged=yes">Debian's GPSD buglist</a>.</p></dd>
  1338. <dt>2. Issue the pre-release heads-up</dt>
  1339. <dd><p>About 48 hours before release, announce that it's coming so people
  1340. will have a day or so to get their urgent fixes in.</p></dd>
  1341. <dt>3. Perform a validation pass on the website content.</dt>
  1342. <dd><p>See the instructions near validation-list in the scons recipe.</p></dd>
  1343. <dt>4. Check that the version number is correct</dt>
  1344. <dd><p>It will need to be modified in SConstruct. Make sure the 'dev'
  1345. suffix is gone.</p></dd>
  1346. <dt>5. Update the NEWS file</dt>
  1347. <dd><p>The version number on the top line needs to be match what's in
  1348. SConstruct.</p></dd>
  1349. <dt>6. Fix fault-scanner warnings.</dt>
  1350. <dd><p>Look for compiler, <a
  1351. href="http://devel.recluse.de/~bzed/scan-build/gpsd/">scan-build</a>,
  1352. and Coverity warnings and fix them.</p></dd>
  1353. <dt>7. Run the regression tests and other checks</dt>
  1354. <dd><p>If it doesn't pass regressions, it isn't ready to ship. Run
  1355. <code>scons releasecheck</code> and watch for errors on a
  1356. representative selection of <a
  1357. href="https://db.debian.org/machines.cgi">porterboxes</a>.</p>
  1358. <p>Warning! Whenever the default leap second changes in gpsd.h some
  1359. gpsd regression tests will break (times one second off) and the testloads
  1360. will have to be rebuilt.</p></dd>
  1361. <dt>9. Live-test PPS</dt>
  1362. <dd><p>Point gpsmon at a GR601-W or other PPS-capable GPS and verify
  1363. that PPS events are visible.</p></dd>
  1364. <dt>10. Push and pull from the public repo</dt>
  1365. <dd><p>This is the revision the release will be built from.</p></dd>
  1366. <dt>11. Build and ship the release</dt>
  1367. <dd><p><code>scons release</code> will tag the release, make the tarball,
  1368. upload it to the hosting site, and refresh the website.</p></dd>
  1369. <dt>12. Bump the release number and push that commit</dt>
  1370. <dd><p>Bump the release number in SConstruct, adding a '~dev' suffix
  1371. so tarball instances pulled from the repo will be clearly
  1372. distinguishable from the next public release.</p></dd>
  1373. <dt>13. Close all resolved tracker bugs</dt>
  1374. <dd><p>Go to <a
  1375. href="https://savannah.nongnu.org/bugs/?group=gpsd">the tracker</a>
  1376. and close all resolved bugs.</p></dd>
  1377. <dt>14. Announce the release</dt>
  1378. <dd><p>Announce the release on the announce list, and the resumption of
  1379. regular commits on the dev list.</p></dd>
  1380. </dl>
  1381. <h2>Packaging links</h2>
  1382. <p><a
  1383. href='https://github.com/bzed/pkg-gpsd'>Debian
  1384. build controls</a></p>
  1385. <hr>
  1386. <script src="datestamp.js"></script>
  1387. </div>
  1388. </body>
  1389. </html>