drivers.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865
  1. /*
  2. * This file is Copyright (c) 2010-2018 by the GPSD project
  3. * SPDX-License-Identifier: BSD-2-clause
  4. */
  5. #include "gpsd_config.h" /* must be before all includes */
  6. #include <assert.h>
  7. #include <ctype.h>
  8. #include <stdarg.h>
  9. #include <stdbool.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <unistd.h>
  14. #include "gpsd.h"
  15. #include "bits.h" /* for getbeu16(), to extract big-endian words */
  16. #include "strfuncs.h"
  17. ssize_t generic_get(struct gps_device_t *session)
  18. {
  19. return packet_get(session->gpsdata.gps_fd, &session->lexer);
  20. }
  21. gps_mask_t generic_parse_input(struct gps_device_t *session)
  22. {
  23. if (session->lexer.type == BAD_PACKET)
  24. return 0;
  25. else if (session->lexer.type == COMMENT_PACKET) {
  26. gpsd_set_century(session);
  27. return 0;
  28. #ifdef NMEA0183_ENABLE
  29. } else if (session->lexer.type == NMEA_PACKET) {
  30. const struct gps_type_t **dp;
  31. gps_mask_t st = 0;
  32. char *sentence = (char *)session->lexer.outbuffer;
  33. if (sentence[strlen(sentence)-1] != '\n')
  34. GPSD_LOG(LOG_IO, &session->context->errout,
  35. "<= GPS: %s\n", sentence);
  36. else
  37. GPSD_LOG(LOG_IO, &session->context->errout,
  38. "<= GPS: %s", sentence);
  39. if ((st=nmea_parse(sentence, session)) == 0) {
  40. GPSD_LOG(LOG_WARN, &session->context->errout,
  41. "unknown sentence: \"%s\"\n", sentence);
  42. }
  43. for (dp = gpsd_drivers; *dp; dp++) {
  44. char *trigger = (*dp)->trigger;
  45. if (trigger!=NULL && str_starts_with(sentence, trigger)) {
  46. GPSD_LOG(LOG_PROG, &session->context->errout,
  47. "found trigger string %s.\n", trigger);
  48. if (*dp != session->device_type) {
  49. (void)gpsd_switch_driver(session, (*dp)->type_name);
  50. if (session->device_type != NULL
  51. && session->device_type->event_hook != NULL)
  52. session->device_type->event_hook(session,
  53. event_triggermatch);
  54. st |= DEVICEID_SET;
  55. }
  56. }
  57. }
  58. return st;
  59. #endif /* NMEA0183_ENABLE */
  60. } else {
  61. GPSD_LOG(LOG_SHOUT, &session->context->errout,
  62. "packet type %d fell through (should never happen): %s.\n",
  63. session->lexer.type, gpsd_prettydump(session));
  64. return 0;
  65. }
  66. }
  67. /**************************************************************************
  68. *
  69. * Generic driver -- make no assumptions about the device type
  70. *
  71. **************************************************************************/
  72. /* *INDENT-OFF* */
  73. const struct gps_type_t driver_unknown = {
  74. .type_name = "Unknown", /* full name of type */
  75. .packet_type = COMMENT_PACKET, /* associated lexer packet type */
  76. .flags = DRIVER_NOFLAGS, /* no flags set */
  77. .trigger = NULL, /* it's the default */
  78. .channels = 12, /* consumer-grade GPS */
  79. .probe_detect = NULL, /* no probe */
  80. .get_packet = generic_get, /* use generic packet getter */
  81. .parse_packet = generic_parse_input, /* how to interpret a packet */
  82. .rtcm_writer = NULL, /* write RTCM data straight */
  83. .init_query = NULL, /* non-perturbing initial query */
  84. .event_hook = NULL, /* lifetime event handler */
  85. #ifdef RECONFIGURE_ENABLE
  86. .speed_switcher = NULL, /* no speed switcher */
  87. .mode_switcher = NULL, /* no mode switcher */
  88. .rate_switcher = NULL, /* no sample-rate switcher */
  89. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  90. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  91. #endif /* RECONFIGURE_ENABLE */
  92. #ifdef CONTROLSEND_ENABLE
  93. .control_send = NULL, /* how to send control strings */
  94. #endif /* CONTROLSEND_ENABLE */
  95. .time_offset = NULL, /* no method for NTP fudge factor */
  96. };
  97. /* *INDENT-ON* */
  98. #ifdef NMEA0183_ENABLE
  99. /**************************************************************************
  100. *
  101. * NMEA 0183
  102. *
  103. * This is separate from the 'unknown' driver because we don't want to
  104. * ship NMEA subtype probe strings to a device until we've seen at
  105. * least one NMEA packet. This avoids spamming devices that might
  106. * actually be USB modems or other things in USB device class FF that
  107. * just happen to have one of 'our' adaptor chips in front of them.
  108. *
  109. **************************************************************************/
  110. static void nmea_event_hook(struct gps_device_t *session, event_t event)
  111. {
  112. if (session->context->readonly)
  113. return;
  114. /*
  115. * This is where we try to tickle NMEA devices into revealing their
  116. * inner natures.
  117. */
  118. if (event == event_configure) {
  119. /*
  120. * The reason for splitting these probes up by packet sequence
  121. * number, interleaving them with the first few packet receives,
  122. * is because many generic-NMEA devices get confused if you send
  123. * too much at them in one go.
  124. *
  125. * A fast response to an early probe will change drivers so the
  126. * later ones won't be sent at all. Thus, for best overall
  127. * performance, order these to probe for the most popular types
  128. * soonest.
  129. *
  130. * Note: don't make the trigger strings identical to the probe,
  131. * because some NMEA devices (notably SiRFs) will just echo
  132. * unknown strings right back at you. A useful dodge is to append
  133. * a comma to the trigger, because that won't be in the response
  134. * unless there is actual following data.
  135. */
  136. switch (session->lexer.counter) {
  137. #ifdef NMEA0183_ENABLE
  138. case 0:
  139. /* probe for Garmin serial GPS -- expect $PGRMC followed by data */
  140. GPSD_LOG(LOG_PROG, &session->context->errout,
  141. "=> Probing for Garmin NMEA\n");
  142. (void)nmea_send(session, "$PGRMCE");
  143. break;
  144. #endif /* NMEA0183_ENABLE */
  145. #ifdef SIRF_ENABLE
  146. case 1:
  147. /*
  148. * We used to try to probe for SiRF by issuing
  149. * "$PSRF105,1" and expecting "$Ack Input105.". But it
  150. * turns out this only works for SiRF-IIs; SiRF-I and
  151. * SiRF-III don't respond. Sadly, the MID132 binary
  152. * request for firmware version is ignored in NMEA mode.
  153. * Thus the only reliable probe is to try to flip the SiRF
  154. * into binary mode, cluing in the library to revert it on
  155. * close.
  156. *
  157. * SiRFs dominate the consumer-grade GPS-mouse market, so
  158. * we used to put this test first. Unfortunately this
  159. * causes problems for gpsctl, as it cannot select the
  160. * NMEA driver without switching the device back to binary
  161. * mode! Fix this if we ever find a nondisruptive probe
  162. * string.
  163. */
  164. GPSD_LOG(LOG_PROG, &session->context->errout,
  165. "=> Probing for SiRF\n");
  166. (void)nmea_send(session,
  167. "$PSRF100,0,%d,%d,%d,0",
  168. session->gpsdata.dev.baudrate,
  169. 9 - session->gpsdata.dev.stopbits,
  170. session->gpsdata.dev.stopbits);
  171. break;
  172. #endif /* SIRF_ENABLE */
  173. #ifdef NMEA0183_ENABLE
  174. case 2:
  175. /* probe for the FV-18 -- expect $PFEC,GPint followed by data */
  176. GPSD_LOG(LOG_PROG, &session->context->errout,
  177. "=> Probing for FV-18\n");
  178. (void)nmea_send(session, "$PFEC,GPint");
  179. break;
  180. case 3:
  181. /* probe for the Trimble Copernicus */
  182. GPSD_LOG(LOG_PROG, &session->context->errout,
  183. "=> Probing for Trimble Copernicus\n");
  184. (void)nmea_send(session, "$PTNLSNM,0139,01");
  185. break;
  186. #endif /* NMEA0183_ENABLE */
  187. #ifdef EVERMORE_ENABLE
  188. case 4:
  189. GPSD_LOG(LOG_PROG, &session->context->errout,
  190. "=> Probing for Evermore\n");
  191. /* Enable checksum and GGA(1s), GLL(0s), GSA(1s), GSV(1s), RMC(1s), VTG(0s), PEMT101(0s) */
  192. /* EverMore will reply with: \x10\x02\x04\x38\x8E\xC6\x10\x03 */
  193. (void)gpsd_write(session,
  194. "\x10\x02\x12\x8E\x7F\x01\x01\x00\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x13\x10\x03",
  195. 22);
  196. break;
  197. #endif /* EVERMORE_ENABLE */
  198. #ifdef GPSCLOCK_ENABLE
  199. case 5:
  200. /* probe for Furuno Electric GH-79L4-N (GPSClock); expect $PFEC,GPssd */
  201. GPSD_LOG(LOG_PROG, &session->context->errout,
  202. "=> Probing for GPSClock\n");
  203. (void)nmea_send(session, "$PFEC,GPsrq");
  204. break;
  205. #endif /* GPSCLOCK_ENABLE */
  206. #ifdef ASHTECH_ENABLE
  207. case 6:
  208. /* probe for Ashtech -- expect $PASHR,RID */
  209. GPSD_LOG(LOG_PROG, &session->context->errout,
  210. "=> Probing for Ashtech\n");
  211. (void)nmea_send(session, "$PASHQ,RID");
  212. break;
  213. #endif /* ASHTECH_ENABLE */
  214. #ifdef UBLOX_ENABLE
  215. case 7:
  216. /* probe for UBX -- query port configuration */
  217. GPSD_LOG(LOG_PROG, &session->context->errout,
  218. "=> Probing for UBX\n");
  219. (void)ubx_write(session, 0x06, 0x00, NULL, 0);
  220. break;
  221. #endif /* UBLOX_ENABLE */
  222. #ifdef MTK3301_ENABLE
  223. case 8:
  224. /* probe for MTK-3301 -- expect $PMTK705 */
  225. GPSD_LOG(LOG_PROG, &session->context->errout,
  226. "=> Probing for MediaTek\n");
  227. (void)nmea_send(session, "$PMTK605");
  228. break;
  229. #endif /* MTK3301_ENABLE */
  230. #ifdef GREIS_ENABLE
  231. case 9:
  232. /* probe for Javad GREIS -- expect reply with JAVAD */
  233. GPSD_LOG(LOG_PROG, &session->context->errout,
  234. "=> Probing for Javad GREIS\n");
  235. /* TODO: confirm this actually gets JAVAD response */
  236. (void)nmea_send(session, "print,/par/rcv/vendor");
  237. break;
  238. #endif /* GREIS_ENABLE */
  239. default:
  240. break;
  241. }
  242. }
  243. }
  244. /* *INDENT-OFF* */
  245. const struct gps_type_t driver_nmea0183 = {
  246. .type_name = "NMEA0183", /* full name of type */
  247. .packet_type = NMEA_PACKET, /* associated lexer packet type */
  248. .flags = DRIVER_NOFLAGS, /* remember this */
  249. .trigger = NULL, /* it's the default */
  250. .channels = 12, /* consumer-grade GPS */
  251. .probe_detect = NULL, /* no probe */
  252. .get_packet = generic_get, /* use generic packet getter */
  253. .parse_packet = generic_parse_input, /* how to interpret a packet */
  254. .rtcm_writer = gpsd_write, /* write RTCM data straight */
  255. .init_query = NULL, /* non-perturbing initial query */
  256. .event_hook = nmea_event_hook, /* lifetime event handler */
  257. #ifdef RECONFIGURE_ENABLE
  258. .speed_switcher = NULL, /* no speed switcher */
  259. #ifdef BINARY_ENABLE
  260. .mode_switcher = NULL, /* maybe switchable if it was a SiRF */
  261. #else
  262. .mode_switcher = NULL, /* no binary mode to revert to */
  263. #endif /* BINARY_ENABLE */
  264. .rate_switcher = NULL, /* no sample-rate switcher */
  265. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  266. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  267. #endif /* RECONFIGURE_ENABLE */
  268. #ifdef CONTROLSEND_ENABLE
  269. .control_send = nmea_write, /* how to send control strings */
  270. #endif /* CONTROLSEND_ENABLE */
  271. .time_offset = NULL, /* no method for NTP fudge factor */
  272. };
  273. /* *INDENT-ON* */
  274. #if defined(GARMIN_ENABLE) && defined(NMEA0183_ENABLE)
  275. /**************************************************************************
  276. *
  277. * Garmin NMEA
  278. *
  279. **************************************************************************/
  280. #ifdef RECONFIGURE_ENABLE
  281. static void garmin_mode_switch(struct gps_device_t *session, int mode)
  282. /* only does anything in one direction, going to Garmin binary driver */
  283. {
  284. struct timespec delay;
  285. if (mode == MODE_BINARY) {
  286. (void)nmea_send(session, "$PGRMC1,1,2,1,,,,2,W,N");
  287. (void)nmea_send(session, "$PGRMI,,,,,,,R");
  288. /* wait 333 uSec, standard Garmin settling time */
  289. delay.tv_sec = 0;
  290. delay.tv_nsec = 333000L;
  291. nanosleep(&delay, NULL);
  292. }
  293. }
  294. #endif /* RECONFIGURE_ENABLE */
  295. static void garmin_nmea_event_hook(struct gps_device_t *session,
  296. event_t event)
  297. {
  298. if (session->context->readonly)
  299. return;
  300. if (event == event_driver_switch) {
  301. /* forces a reconfigure as the following packets come in */
  302. session->lexer.counter = 0;
  303. }
  304. if (event == event_configure) {
  305. /*
  306. * And here's that reconfigure. It's split up like this because
  307. * receivers like the Garmin GPS-10 don't handle having having a lot of
  308. * probes shoved at them very well.
  309. */
  310. switch (session->lexer.counter) {
  311. case 0:
  312. /* reset some config, AutoFix, WGS84, PPS
  313. * Set the PPS pulse length to 40ms which leaves the Garmin 18-5hz
  314. * with a 160ms low state.
  315. * NOTE: new PPS only takes effect after next power cycle
  316. */
  317. (void)nmea_send(session, "$PGRMC,A,,100,,,,,,A,,1,2,1,30");
  318. break;
  319. case 1:
  320. /* once a sec, no averaging, NMEA 2.3, WAAS */
  321. (void)nmea_send(session, "$PGRMC1,1,1,1,,,,2,W,N");
  322. break;
  323. case 2:
  324. /* get some more config info */
  325. (void)nmea_send(session, "$PGRMC1E");
  326. break;
  327. case 3:
  328. /* turn off all output except GGA */
  329. (void)nmea_send(session, "$PGRMO,,2");
  330. (void)nmea_send(session, "$PGRMO,GPGGA,1");
  331. break;
  332. case 4:
  333. /* enable GPGGA, GPGSA, GPGSV, GPRMC on Garmin serial GPS */
  334. (void)nmea_send(session, "$PGRMO,GPGSA,1");
  335. break;
  336. case 5:
  337. (void)nmea_send(session, "$PGRMO,GPGSV,1");
  338. break;
  339. case 6:
  340. (void)nmea_send(session, "$PGRMO,GPRMC,1");
  341. break;
  342. case 7:
  343. (void)nmea_send(session, "$PGRMO,PGRME,1");
  344. break;
  345. }
  346. }
  347. }
  348. /* *INDENT-OFF* */
  349. const struct gps_type_t driver_garmin = {
  350. .type_name = "Garmin NMEA", /* full name of type */
  351. .packet_type = NMEA_PACKET, /* associated lexer packet type */
  352. .flags = DRIVER_STICKY, /* remember this */
  353. .trigger = "$PGRMC,", /* Garmin private */
  354. .channels = 12, /* not used by this driver */
  355. .probe_detect = NULL, /* no probe */
  356. .get_packet = generic_get, /* use generic packet getter */
  357. .parse_packet = generic_parse_input, /* how to interpret a packet */
  358. .rtcm_writer = NULL, /* some do, some don't, skip for now */
  359. .init_query = NULL, /* non-perturbing initial query */
  360. .event_hook = garmin_nmea_event_hook, /* lifetime event handler */
  361. #ifdef RECONFIGURE_ENABLE
  362. .speed_switcher = NULL, /* no speed switcher */
  363. .mode_switcher = garmin_mode_switch, /* mode switcher */
  364. .rate_switcher = NULL, /* no sample-rate switcher */
  365. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  366. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  367. #endif /*RECONFIGURE_ENABLE */
  368. #ifdef CONTROLSEND_ENABLE
  369. .control_send = nmea_write, /* how to send control strings */
  370. #endif /* CONTROLSEND_ENABLE */
  371. .time_offset = NULL, /* no method for NTP fudge factor */
  372. };
  373. /* *INDENT-ON* */
  374. #endif /* GARMIN_ENABLE && NMEA0183_ENABLE */
  375. #ifdef ASHTECH_ENABLE
  376. /**************************************************************************
  377. *
  378. * Ashtech (then Thales, now Magellan Professional) Receivers
  379. *
  380. **************************************************************************/
  381. static void ashtech_event_hook(struct gps_device_t *session, event_t event)
  382. {
  383. if (session->context->readonly)
  384. return;
  385. if (event == event_wakeup)
  386. (void)nmea_send(session, "$PASHQ,RID");
  387. if (event == event_identified) {
  388. /* turn WAAS on. can't hurt... */
  389. (void)nmea_send(session, "$PASHS,WAS,ON");
  390. /* reset to known output state */
  391. (void)nmea_send(session, "$PASHS,NME,ALL,A,OFF");
  392. /* then turn on some useful sentences */
  393. #ifdef __future__
  394. /* we could parse these, but they're oversize so they get dropped */
  395. (void)nmea_send(session, "$PASHS,NME,POS,A,ON");
  396. (void)nmea_send(session, "$PASHS,NME,SAT,A,ON");
  397. #else
  398. (void)nmea_send(session, "$PASHS,NME,GGA,A,ON");
  399. (void)nmea_send(session, "$PASHS,NME,GSA,A,ON");
  400. (void)nmea_send(session, "$PASHS,NME,GSV,A,ON");
  401. (void)nmea_send(session, "$PASHS,NME,RMC,A,ON");
  402. #endif
  403. (void)nmea_send(session, "$PASHS,NME,ZDA,A,ON");
  404. }
  405. }
  406. /* *INDENT-OFF* */
  407. const struct gps_type_t driver_ashtech = {
  408. .type_name = "Ashtech", /* full name of type */
  409. .packet_type = NMEA_PACKET, /* associated lexer packet type */
  410. .flags = DRIVER_STICKY, /* remember this */
  411. .trigger = "$PASHR,RID,", /* Ashtech receivers respond thus */
  412. .channels = 24, /* not used, GG24 has 24 channels */
  413. .probe_detect = NULL, /* no probe */
  414. .get_packet = generic_get, /* how to get a packet */
  415. .parse_packet = generic_parse_input, /* how to interpret a packet */
  416. .rtcm_writer = gpsd_write, /* write RTCM data straight */
  417. .init_query = NULL, /* non-perturbing initial query */
  418. .event_hook = ashtech_event_hook, /* lifetime event handler */
  419. #ifdef RECONFIGURE_ENABLE
  420. .speed_switcher = NULL, /* no speed switcher */
  421. .mode_switcher = NULL, /* no mode switcher */
  422. .rate_switcher = NULL, /* no sample-rate switcher */
  423. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  424. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  425. #endif /* RECONFIGURE_ENABLE */
  426. #ifdef CONTROLSEND_ENABLE
  427. .control_send = nmea_write, /* how to send control strings */
  428. #endif /* CONTROLSEND_ENABLE */
  429. .time_offset = NULL, /* no method for NTP fudge factor */
  430. };
  431. /* *INDENT-ON* */
  432. #endif /* ASHTECH_ENABLE */
  433. #ifdef FV18_ENABLE
  434. /**************************************************************************
  435. *
  436. * FV18 -- uses 2 stop bits, needs to be told to send GSAs
  437. *
  438. **************************************************************************/
  439. static void fv18_event_hook(struct gps_device_t *session, event_t event)
  440. {
  441. if (session->context->readonly)
  442. return;
  443. /*
  444. * Tell an FV18 to send GSAs so we'll know if 3D is accurate.
  445. * Suppress GLL and VTG. Enable ZDA so dates will be accurate for replay.
  446. * It's possible we might not need to redo this on event_reactivate,
  447. * but doing so is safe and cheap.
  448. */
  449. if (event == event_identified || event == event_reactivate)
  450. (void)nmea_send(session,
  451. "$PFEC,GPint,GSA01,DTM00,ZDA01,RMC01,GLL00,VTG00,GSV05");
  452. }
  453. /* *INDENT-OFF* */
  454. const struct gps_type_t driver_fv18 = {
  455. .type_name = "San Jose Navigation FV18", /* full name of type */
  456. .packet_type = NMEA_PACKET, /* associated lexer packet type */
  457. .flags = DRIVER_STICKY, /* remember this */
  458. .trigger = "$PFEC,GPint,", /* FV18s should echo the probe */
  459. .channels = 12, /* not used by this driver */
  460. .probe_detect = NULL, /* no probe */
  461. .get_packet = generic_get, /* how to get a packet */
  462. .parse_packet = generic_parse_input, /* how to interpret a packet */
  463. .rtcm_writer = gpsd_write, /* write RTCM data straight */
  464. .init_query = NULL, /* non-perturbing initial query */
  465. .event_hook = fv18_event_hook, /* lifetime event handler */
  466. #ifdef RECONFIGURE_ENABLE
  467. .speed_switcher = NULL, /* no speed switcher */
  468. .mode_switcher = NULL, /* no mode switcher */
  469. .rate_switcher = NULL, /* no sample-rate switcher */
  470. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  471. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  472. #endif /* RECONFIGURE_ENABLE */
  473. #ifdef CONTROLSEND_ENABLE
  474. .control_send = nmea_write, /* how to send control strings */
  475. #endif /* CONTROLSEND_ENABLE */
  476. .time_offset = NULL, /* no method for NTP fudge factor */
  477. };
  478. /* *INDENT-ON* */
  479. #endif /* FV18_ENABLE */
  480. #ifdef GPSCLOCK_ENABLE
  481. /**************************************************************************
  482. *
  483. * Furuno Electric GPSClock (GH-79L4)
  484. *
  485. **************************************************************************/
  486. /*
  487. * Based on http://www.tecsys.de/fileadmin/user_upload/pdf/gh79_1an_intant.pdf
  488. */
  489. /* *INDENT-OFF* */
  490. const struct gps_type_t driver_gpsclock = {
  491. .type_name = "Furuno Electric GH-79L4", /* full name of type */
  492. .packet_type = NMEA_PACKET, /* associated lexer packet type */
  493. .flags = DRIVER_STICKY, /* remember this */
  494. .trigger = "$PFEC,GPssd", /* GPSClock should return this */
  495. .channels = 12, /* not used by this driver */
  496. .probe_detect = NULL, /* no probe */
  497. .get_packet = generic_get, /* how to get a packet */
  498. .parse_packet = generic_parse_input, /* how to interpret a packet */
  499. .rtcm_writer = gpsd_write, /* write RTCM data straight */
  500. .init_query = NULL, /* non-perturbing initial query */
  501. .event_hook = NULL, /* no lifetime event handler */
  502. #ifdef RECONFIGURE_ENABLE
  503. .speed_switcher = NULL, /* no speed switcher */
  504. .mode_switcher = NULL, /* no mode switcher */
  505. .rate_switcher = NULL, /* sample rate is fixed */
  506. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  507. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  508. #endif /* RECONFIGURE_ENABLE */
  509. #ifdef CONTROLSEND_ENABLE
  510. .control_send = nmea_write, /* how to send control strings */
  511. #endif /* CONTROLSEND_ENABLE */
  512. .time_offset = NULL, /* no method for NTP fudge factor */
  513. };
  514. /* *INDENT-ON* */
  515. #endif /* GPSCLOCK_ENABLE */
  516. #ifdef TRIPMATE_ENABLE
  517. /**************************************************************************
  518. *
  519. * TripMate -- extended NMEA, gets faster fix when primed with lat/long/time
  520. *
  521. **************************************************************************/
  522. /*
  523. * Some technical FAQs on the TripMate:
  524. * http://vancouver-webpages.com/pub/peter/tripmate.faq
  525. * http://www.asahi-net.or.jp/~KN6Y-GTU/tripmate/trmfaqe.html
  526. * The TripMate was discontinued sometime before November 1998
  527. * and was replaced by the Zodiac EarthMate.
  528. */
  529. static void tripmate_event_hook(struct gps_device_t *session, event_t event)
  530. {
  531. if (session->context->readonly)
  532. return;
  533. /* TripMate requires this response to the ASTRAL it sends at boot time */
  534. if (event == event_identified)
  535. (void)nmea_send(session, "$IIGPQ,ASTRAL");
  536. /* stop it sending PRWIZCH */
  537. if (event == event_identified || event == event_reactivate)
  538. (void)nmea_send(session, "$PRWIILOG,ZCH,V,,");
  539. }
  540. /* *INDENT-OFF* */
  541. static const struct gps_type_t driver_tripmate = {
  542. .type_name = "Delorme TripMate", /* full name of type */
  543. .packet_type = NMEA_PACKET, /* lexer packet type */
  544. .flags = DRIVER_STICKY, /* no rollover or other flags */
  545. .trigger ="ASTRAL", /* tells us to switch */
  546. .channels = 12, /* consumer-grade GPS */
  547. .probe_detect = NULL, /* no probe */
  548. .get_packet = generic_get, /* how to get a packet */
  549. .parse_packet = generic_parse_input, /* how to interpret a packet */
  550. .rtcm_writer = gpsd_write, /* send RTCM data straight */
  551. .init_query = NULL, /* non-perturbing query */
  552. .event_hook = tripmate_event_hook, /* lifetime event handler */
  553. #ifdef RECONFIGURE_ENABLE
  554. .speed_switcher= NULL, /* no speed switcher */
  555. .mode_switcher = NULL, /* no mode switcher */
  556. .rate_switcher = NULL, /* no sample-rate switcher */
  557. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  558. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  559. #endif /* RECONFIGURE_ENABLE */
  560. #ifdef CONTROLSEND_ENABLE
  561. .control_send = nmea_write, /* how to send control strings */
  562. #endif /* CONTROLSEND_ENABLE */
  563. .time_offset = NULL, /* no method for NTP fudge factor */
  564. };
  565. /* *INDENT-ON* */
  566. #endif /* TRIPMATE_ENABLE */
  567. #ifdef EARTHMATE_ENABLE
  568. /**************************************************************************
  569. *
  570. * Zodiac EarthMate textual mode
  571. *
  572. * Note: This is the pre-2003 version using Zodiac binary protocol.
  573. * There is a good HOWTO at <http://www.hamhud.net/ka9mva/earthmate.htm>.
  574. * It has been replaced with a design that uses a SiRF chipset.
  575. *
  576. **************************************************************************/
  577. static void earthmate_event_hook(struct gps_device_t *session, event_t event)
  578. {
  579. struct timespec delay;
  580. if (session->context->readonly)
  581. return;
  582. if (event == event_triggermatch) {
  583. (void)gpsd_write(session, "EARTHA\r\n", 8);
  584. /* wait 10,000 uSec */
  585. delay.tv_sec = 0;
  586. delay.tv_nsec = 10000000L;
  587. nanosleep(&delay, NULL);
  588. (void)gpsd_switch_driver(session, "Zodiac");
  589. }
  590. }
  591. /* *INDENT-OFF* */
  592. static const struct gps_type_t driver_earthmate = {
  593. .type_name = "Pre-2003 Delorme EarthMate",
  594. .packet_type = NMEA_PACKET, /* associated lexer packet type */
  595. .flags = DRIVER_STICKY, /* no rollover or other flags */
  596. .trigger = "EARTHA", /* Earthmate trigger string */
  597. .channels = 12, /* not used by NMEA parser */
  598. .probe_detect = NULL, /* no probe */
  599. .get_packet = generic_get, /* how to get a packet */
  600. .parse_packet = generic_parse_input, /* how to interpret a packet */
  601. .rtcm_writer = NULL, /* don't send RTCM data */
  602. .init_query = NULL, /* non-perturbing query */
  603. .event_hook = earthmate_event_hook, /* lifetime event handler */
  604. #ifdef RECONFIGURE_ENABLE
  605. .speed_switcher= NULL, /* no speed switcher */
  606. .mode_switcher = NULL, /* no mode switcher */
  607. .rate_switcher = NULL, /* no sample-rate switcher */
  608. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  609. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  610. #endif /* RECONFIGURE_ENABLE */
  611. #ifdef CONTROLSEND_ENABLE
  612. .control_send = nmea_write, /* never actually used. */
  613. #endif /* CONTROLSEND_ENABLE */
  614. .time_offset = NULL, /* no method for NTP fudge factor */
  615. };
  616. /* *INDENT-ON* */
  617. #endif /* EARTHMATE_ENABLE */
  618. #endif /* NMEA0183_ENABLE */
  619. #ifdef TNT_ENABLE
  620. /**************************************************************************
  621. * True North Technologies - Revolution 2X Digital compass
  622. *
  623. * More info: http://www.tntc.com/
  624. *
  625. * This is a digital compass which uses magnetometers to measure the
  626. * strength of the earth's magnetic field. Based on these measurements
  627. * it provides a compass heading using NMEA formatted output strings.
  628. * This is useful to supplement the heading provided by another GPS
  629. * unit. A GPS heading is unreliable at slow speed or no speed.
  630. *
  631. **************************************************************************/
  632. static ssize_t tnt_control_send(struct gps_device_t *session,
  633. char *msg, size_t len UNUSED)
  634. /* send a control string in TNT native formal */
  635. {
  636. ssize_t status;
  637. unsigned char sum = '\0';
  638. char c, *p = msg;
  639. if (*p == '@') {
  640. p++;
  641. }
  642. #ifdef __UNUSED__
  643. else {
  644. GPSD_LOG(LOG_ERROR, &session->context->errout,
  645. "Bad TNT sentence: '%s'\n", msg);
  646. }
  647. #endif /* __UNUSED__ */
  648. while (((c = *p) != '\0')) {
  649. sum ^= c;
  650. p++;
  651. }
  652. (void)snprintf(p, 6, "*%02X\r\n", (unsigned int)sum);
  653. status = gpsd_write(session, msg, strlen(msg));
  654. return status;
  655. }
  656. static bool tnt_send(struct gps_device_t *session, const char *fmt, ...)
  657. /* printf(3)-like TNT command generator */
  658. {
  659. char buf[BUFSIZ];
  660. va_list ap;
  661. ssize_t sent;
  662. va_start(ap, fmt);
  663. (void)vsnprintf(buf, sizeof(buf) - 5, fmt, ap);
  664. va_end(ap);
  665. sent = tnt_control_send(session, buf, strlen(buf));
  666. if (sent == (ssize_t) strlen(buf)) {
  667. GPSD_LOG(LOG_IO, &session->context->errout,
  668. "=> GPS: %s\n", buf);
  669. return true;
  670. } else {
  671. GPSD_LOG(LOG_WARN, &session->context->errout,
  672. "=> GPS: %s FAILED\n", buf);
  673. return false;
  674. }
  675. }
  676. #ifdef RECONFIGURE_ENABLE
  677. static bool tnt_speed(struct gps_device_t *session,
  678. speed_t speed, char parity UNUSED, int stopbits UNUSED)
  679. {
  680. /*
  681. * Baud rate change followed by device reset.
  682. * See page 40 of Technical Guide 1555-B. We need:
  683. * 2400 -> 1, 4800 -> 2, 9600 -> 3, 19200 -> 4, 38400 -> 5
  684. */
  685. unsigned int val = speed / 2400u; /* 2400->1, 4800->2, 9600->4, 19200->8... */
  686. unsigned int i = 0;
  687. /* fast way to compute log2(val) */
  688. while ((val >> i) > 1)
  689. ++i;
  690. return tnt_send(session, "@B6=%d", i + 1)
  691. && tnt_send(session, "@F28.6=1");
  692. }
  693. #endif /* RECONFIGURE_ENABLE */
  694. static void tnt_event_hook(struct gps_device_t *session, event_t event)
  695. /* TNT lifetime event hook */
  696. {
  697. if (session->context->readonly)
  698. return;
  699. if (event == event_wakeup) {
  700. (void)tnt_send(session, "@F0.3=1"); /* set run mode */
  701. (void)tnt_send(session, "@F2.2=1"); /* report in degrees */
  702. }
  703. }
  704. /* *INDENT-OFF* */
  705. const struct gps_type_t driver_trueNorth = {
  706. .type_name = "True North", /* full name of type */
  707. .packet_type = NMEA_PACKET, /* associated lexer packet type */
  708. .flags = DRIVER_STICKY, /* remember this */
  709. .trigger = "$PTNTHTM", /* their proprietary sentence */
  710. .channels = 0, /* not an actual GPS at all */
  711. .probe_detect = NULL, /* no probe in run mode */
  712. .get_packet = generic_get, /* how to get a packet */
  713. .parse_packet = generic_parse_input, /* how to interpret a packet */
  714. .rtcm_writer = NULL, /* Don't send */
  715. .init_query = NULL, /* non-perturbing initial query */
  716. .event_hook = tnt_event_hook, /* lifetime event handler */
  717. #ifdef RECONFIGURE_ENABLE
  718. .speed_switcher = tnt_speed, /* no speed switcher */
  719. .mode_switcher = NULL, /* no mode switcher */
  720. .rate_switcher = NULL, /* no wrapup */
  721. .min_cycle.tv_sec = 0, /* not relevant, no rate switch */
  722. .min_cycle.tv_nsec = 500000000, /* not relevant, no rate switch */
  723. #endif /* RECONFIGURE_ENABLE */
  724. #ifdef CONTROLSEND_ENABLE
  725. .control_send = tnt_control_send, /* how to send control strings */
  726. #endif /* CONTROLSEND_ENABLE */
  727. .time_offset = NULL,
  728. };
  729. /* *INDENT-ON* */
  730. #endif
  731. #ifdef OCEANSERVER_ENABLE
  732. /**************************************************************************
  733. * OceanServer - Digital Compass, OS5000 Series
  734. *
  735. * More info: http://www.ocean-server.com/download/OS5000_Compass_Manual.pdf
  736. *
  737. * This is a digital compass which uses magnetometers to measure the
  738. * strength of the earth's magnetic field. Based on these measurements
  739. * it provides a compass heading using NMEA formatted output strings.
  740. * This is useful to supplement the heading provided by another GPS
  741. * unit. A GPS heading is unreliable at slow speed or no speed.
  742. *
  743. **************************************************************************/
  744. static int oceanserver_send(struct gpsd_errout_t *errout,
  745. const int fd, const char *fmt, ...)
  746. {
  747. int status;
  748. char buf[BUFSIZ];
  749. va_list ap;
  750. va_start(ap, fmt);
  751. (void)vsnprintf(buf, sizeof(buf) - 5, fmt, ap);
  752. va_end(ap);
  753. (void)strlcat(buf, "", sizeof(buf));
  754. status = (int)write(fd, buf, strlen(buf));
  755. (void)tcdrain(fd);
  756. if (status == (int)strlen(buf)) {
  757. GPSD_LOG(LOG_IO, errout, "=> GPS: %s\n", buf);
  758. return status;
  759. } else {
  760. GPSD_LOG(LOG_WARN, errout, "=> GPS: %s FAILED\n", buf);
  761. return -1;
  762. }
  763. }
  764. static void oceanserver_event_hook(struct gps_device_t *session,
  765. event_t event)
  766. {
  767. if (session->context->readonly)
  768. return;
  769. if (event == event_configure && session->lexer.counter == 0) {
  770. /* report in NMEA format */
  771. (void)oceanserver_send(&session->context->errout,
  772. session->gpsdata.gps_fd, "2\n");
  773. /* ship all fields */
  774. (void)oceanserver_send(&session->context->errout,
  775. session->gpsdata.gps_fd, "X2047");
  776. }
  777. }
  778. /* *INDENT-OFF* */
  779. static const struct gps_type_t driver_oceanServer = {
  780. .type_name = "OceanServer OS5000", /* full name of type */
  781. .packet_type = NMEA_PACKET, /* associated lexer packet type */
  782. .flags = DRIVER_STICKY, /* no rollover or other flags */
  783. .trigger = "$OHPR,", /* detect their main sentence */
  784. .channels = 0, /* not an actual GPS at all */
  785. .probe_detect = NULL,
  786. .get_packet = generic_get, /* how to get a packet */
  787. .parse_packet = generic_parse_input, /* how to interpret a packet */
  788. .rtcm_writer = NULL, /* Don't send */
  789. .init_query = NULL, /* non-perturbing initial query */
  790. .event_hook = oceanserver_event_hook,
  791. #ifdef RECONFIGURE_ENABLE
  792. .speed_switcher = NULL, /* no speed switcher */
  793. .mode_switcher = NULL, /* no mode switcher */
  794. .rate_switcher = NULL, /* no wrapup */
  795. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  796. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  797. #endif /* RECONFIGURE_ENABLE */
  798. #ifdef CONTROLSEND_ENABLE
  799. .control_send = nmea_write, /* how to send control strings */
  800. #endif /* CONTROLSEND_ENABLE */
  801. .time_offset = NULL,
  802. };
  803. /* *INDENT-ON* */
  804. #endif
  805. #ifdef FURY_ENABLE
  806. /**************************************************************************
  807. *
  808. * Jackson Labs Fury, a high-precision laboratory clock
  809. *
  810. * Will also support other Jackon Labs boards, including the Firefly.
  811. *
  812. * Note: you must either build with fixed_port_speed=115200 or tweak the
  813. * speed on the port to 115200 before running. The device's default mode
  814. * does not stream output, so our hunt loop will simply time out otherwise.
  815. *
  816. **************************************************************************/
  817. static bool fury_rate_switcher(struct gps_device_t *session, double rate)
  818. {
  819. char buf[78];
  820. double inverted;
  821. /* rate is a frequency, but the command takes interval in # of seconds */
  822. if (rate == 0.0)
  823. inverted = 0.0;
  824. else
  825. inverted = 1.0/rate;
  826. if (inverted > 256)
  827. return false;
  828. (void)snprintf(buf, sizeof(buf), "GPS:GPGGA %d\r\n", (int)inverted);
  829. (void)gpsd_write(session, buf, strlen(buf));
  830. return true;
  831. }
  832. static void fury_event_hook(struct gps_device_t *session, event_t event)
  833. {
  834. if (event == event_wakeup && gpsd_get_speed(session) == 115200)
  835. (void)fury_rate_switcher(session, 1.0);
  836. else if (event == event_deactivate)
  837. (void)fury_rate_switcher(session, 0.0);
  838. }
  839. /* *INDENT-OFF* */
  840. static const struct gps_type_t driver_fury = {
  841. .type_name = "Jackson Labs Fury", /* full name of type */
  842. .packet_type = NMEA_PACKET, /* associated lexer packet type */
  843. .flags = DRIVER_STICKY, /* no rollover or other flags */
  844. .trigger = NULL, /* detect their main sentence */
  845. .channels = 0, /* not an actual GPS at all */
  846. .probe_detect = NULL,
  847. .get_packet = generic_get, /* how to get a packet */
  848. .parse_packet = generic_parse_input, /* how to interpret a packet */
  849. .rtcm_writer = NULL, /* Don't send */
  850. .init_query = NULL, /* non-perturbing initial query */
  851. .event_hook = fury_event_hook,
  852. #ifdef RECONFIGURE_ENABLE
  853. .speed_switcher = NULL, /* no speed switcher */
  854. .mode_switcher = NULL, /* no mode switcher */
  855. .rate_switcher = fury_rate_switcher,
  856. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  857. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  858. #endif /* RECONFIGURE_ENABLE */
  859. #ifdef CONTROLSEND_ENABLE
  860. .control_send = nmea_write, /* how to send control strings */
  861. #endif /* CONTROLSEND_ENABLE */
  862. .time_offset = NULL,
  863. };
  864. /* *INDENT-ON* */
  865. #endif /* FURY_ENABLE */
  866. #ifdef RTCM104V2_ENABLE
  867. /**************************************************************************
  868. *
  869. * RTCM-104 (v2), used for broadcasting DGPS corrections and by DGPS radios
  870. *
  871. **************************************************************************/
  872. static gps_mask_t rtcm104v2_analyze(struct gps_device_t *session)
  873. {
  874. rtcm2_unpack(&session->gpsdata.rtcm2, (char *)session->lexer.isgps.buf);
  875. /* extra guard prevents expensive hexdump calls */
  876. if (session->context->errout.debug >= LOG_RAW)
  877. GPSD_LOG(LOG_RAW, &session->context->errout,
  878. "RTCM 2.x packet type 0x%02x length %d words "
  879. "from %zd bytes: %s\n",
  880. session->gpsdata.rtcm2.type,
  881. session->gpsdata.rtcm2.length + 2,
  882. session->lexer.isgps.buflen,
  883. gpsd_hexdump(session->msgbuf, sizeof(session->msgbuf),
  884. (char *)session->lexer.isgps.buf,
  885. (session->gpsdata.rtcm2.length +
  886. 2) * sizeof(isgps30bits_t)));
  887. session->cycle_end_reliable = true;
  888. return RTCM2_SET;
  889. }
  890. /* *INDENT-OFF* */
  891. static const struct gps_type_t driver_rtcm104v2 = {
  892. .type_name = "RTCM104V2", /* full name of type */
  893. .packet_type = RTCM2_PACKET, /* associated lexer packet type */
  894. .flags = DRIVER_NOFLAGS, /* no rollover or other flags */
  895. .trigger = NULL, /* no recognition string */
  896. .channels = 0, /* not used */
  897. .probe_detect = NULL, /* no probe */
  898. .get_packet = generic_get, /* how to get a packet */
  899. .parse_packet = rtcm104v2_analyze, /* */
  900. .rtcm_writer = NULL, /* don't send RTCM data, */
  901. .init_query = NULL, /* non-perturbing initial query */
  902. .event_hook = NULL, /* no event_hook */
  903. #ifdef RECONFIGURE_ENABLE
  904. .speed_switcher= NULL, /* no speed switcher */
  905. .mode_switcher = NULL, /* no mode switcher */
  906. .rate_switcher = NULL, /* no sample-rate switcher */
  907. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  908. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  909. #endif /* RECONFIGURE_ENABLE */
  910. #ifdef CONTROLSEND_ENABLE
  911. .control_send = NULL, /* how to send control strings */
  912. #endif /* CONTROLSEND_ENABLE */
  913. .time_offset = NULL,
  914. };
  915. /* *INDENT-ON* */
  916. #endif /* RTCM104V2_ENABLE */
  917. #ifdef RTCM104V3_ENABLE
  918. /**************************************************************************
  919. *
  920. * RTCM-104 (v3), used for broadcasting DGPS corrections and by DGPS radios
  921. *
  922. **************************************************************************/
  923. static gps_mask_t rtcm104v3_analyze(struct gps_device_t *session)
  924. {
  925. uint16_t type = getbeu16(session->lexer.inbuffer, 3) >> 4;
  926. GPSD_LOG(LOG_RAW, &session->context->errout, "RTCM 3.x packet %d\n", type);
  927. rtcm3_unpack(session->context,
  928. &session->gpsdata.rtcm3,
  929. (char *)session->lexer.outbuffer);
  930. session->cycle_end_reliable = true;
  931. return RTCM3_SET;
  932. }
  933. /* *INDENT-OFF* */
  934. static const struct gps_type_t driver_rtcm104v3 = {
  935. .type_name = "RTCM104V3", /* full name of type */
  936. .packet_type = RTCM3_PACKET, /* associated lexer packet type */
  937. .flags = DRIVER_NOFLAGS, /* no rollover or other flags */
  938. .trigger = NULL, /* no recognition string */
  939. .channels = 0, /* not used */
  940. .probe_detect = NULL, /* no probe */
  941. .get_packet = generic_get, /* how to get a packet */
  942. .parse_packet = rtcm104v3_analyze, /* */
  943. .rtcm_writer = NULL, /* don't send RTCM data, */
  944. .init_query = NULL, /* non-perturbing initial query */
  945. .event_hook = NULL, /* no event hook */
  946. #ifdef RECONFIGURE_ENABLE
  947. .speed_switcher= NULL, /* no speed switcher */
  948. .mode_switcher = NULL, /* no mode switcher */
  949. .rate_switcher = NULL, /* no sample-rate switcher */
  950. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  951. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  952. #endif /* RECONFIGURE_ENABLE */
  953. #ifdef CONTROLSEND_ENABLE
  954. .control_send = NULL, /* how to send control strings */
  955. #endif /* CONTROLSEND_ENABLE */
  956. .time_offset = NULL,
  957. };
  958. /* *INDENT-ON* */
  959. #endif /* RTCM104V3_ENABLE */
  960. #ifdef GARMINTXT_ENABLE
  961. /**************************************************************************
  962. *
  963. * Garmin Simple Text protocol
  964. *
  965. **************************************************************************/
  966. /* *INDENT-OFF* */
  967. static const struct gps_type_t driver_garmintxt = {
  968. .type_name = "Garmin Simple Text", /* full name of type */
  969. .packet_type = GARMINTXT_PACKET, /* associated lexer packet type */
  970. .flags = DRIVER_NOFLAGS, /* no rollover or other flags */
  971. .trigger = NULL, /* no recognition string */
  972. .channels = 0, /* not used */
  973. .probe_detect = NULL, /* no probe */
  974. .get_packet = generic_get, /* how to get a packet */
  975. .parse_packet = garmintxt_parse, /* how to parse one */
  976. .rtcm_writer = NULL, /* don't send RTCM data, */
  977. .init_query = NULL, /* non-perturbing initial query */
  978. .event_hook = NULL, /* no event hook */
  979. #ifdef RECONFIGURE_ENABLE
  980. .speed_switcher= NULL, /* no speed switcher */
  981. .mode_switcher = NULL, /* no mode switcher */
  982. .rate_switcher = NULL, /* no sample-rate switcher */
  983. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  984. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  985. #endif /* RECONFIGURE_ENABLE */
  986. #ifdef CONTROLSEND_ENABLE
  987. .control_send = NULL, /* how to send control strings */
  988. #endif /* CONTROLSEND_ENABLE */
  989. .time_offset = NULL,
  990. };
  991. /* *INDENT-ON* */
  992. #endif /* GARMINTXT_ENABLE */
  993. #ifdef MTK3301_ENABLE
  994. /**************************************************************************
  995. *
  996. * MediaTek MTK-3301, 3329, 3333, 3339
  997. *
  998. * OEMs for several GPS vendors, notably including Garmin, FasTrax, Trimble,
  999. * and AdaFruit. Website at <http://www.mediatek.com/>.
  1000. *
  1001. * The Trimble Condor appears to be an MTK3329. It behaves as an MTK3301
  1002. * and positively acknowledges all 3301 sentences as valid. It ignores $PMTK
  1003. * sentence fields that are not implemented in the Trimble Condor. It does
  1004. * not have power-save mode and ignores $PMTK320. For $PMTK314 it silently
  1005. * ignores periodic enabling of messages that aren't supported.
  1006. *
  1007. * From its datasheet the MTK3339 seems to add QZSS support not present in
  1008. * earlier versions. The data sheet says it has 66 channels, which mkes
  1009. * sense given the multi-constellation capability. The channel count
  1010. * in the driver is never used by the NMEA driver so leaving the lower MTK3301
  1011. * value in there is OK.
  1012. *
  1013. * MTK3333 support 10Hz.
  1014. *
  1015. * The Adafruit GPS HAT for the Raspberry Pi is an MTK3339. It works with this
  1016. * driver; in fact AdaFruit's overview page for the product features GPSD.
  1017. *
  1018. **************************************************************************/
  1019. static void mtk3301_event_hook(struct gps_device_t *session, event_t event)
  1020. {
  1021. /*
  1022. 0 NMEA_SEN_GLL, GPGLL interval - Geographic Position - Latitude longitude
  1023. 1 NMEA_SEN_RMC, GPRMC interval - Recommended Minimum Specific GNSS Sentence
  1024. 2 NMEA_SEN_VTG, GPVTG interval - Course Over Ground and Ground Speed
  1025. 3 NMEA_SEN_GGA, GPGGA interval - GPS Fix Data
  1026. 4 NMEA_SEN_GSA, GPGSA interval - GNSS DOPS and Active Satellites
  1027. 5 NMEA_SEN_GSV, GPGSV interval - GNSS Satellites in View
  1028. 6 NMEA_SEN_GRS, GPGRS interval - GNSS Range Residuals
  1029. 7 NMEA_SEN_GST, GPGST interval - GNSS Pseudorange Errors Statistics
  1030. 13 NMEA_SEN_MALM, PMTKALM interval - GPS almanac information
  1031. 14 NMEA_SEN_MEPH, PMTKEPH interval - GPS ephemeris information
  1032. 15 NMEA_SEN_MDGP, PMTKDGP interval - GPS differential correction information
  1033. 16 NMEA_SEN_MDBG, PMTKDBG interval – MTK debug information
  1034. 17 NMEA_SEN_ZDA, GPZDA interval - Time & Date
  1035. 18 NMEA_SEN_MCHN, PMTKCHN interval – GPS channel status
  1036. "$PMTK314,1,1,1,1,1,5,1,1,0,0,0,0,0,0,0,0,0,1,0"
  1037. */
  1038. if (session->context->readonly)
  1039. return;
  1040. if (event == event_triggermatch) {
  1041. (void)nmea_send(session, "$PMTK320,0"); /* power save off */
  1042. (void)nmea_send(session, "$PMTK300,1000,0,0,0.0,0.0");/* Fix interval */
  1043. (void)nmea_send(session,
  1044. "$PMTK314,0,1,0,1,1,5,1,1,0,0,0,0,0,0,0,0,0,1,0");
  1045. (void)nmea_send(session, "$PMTK301,2"); /* DGPS is WAAS */
  1046. (void)nmea_send(session, "$PMTK313,1"); /* SBAS enable */
  1047. /* PMTK_API_Q_OUTPUT_CTL - Query PPS pulse width - Trimble only?
  1048. * http://trl.trimble.com/docushare/dsweb/Get/Document-482603/CONDOR_UG_2C_75263-00.pdf *
  1049. * badly documented */
  1050. (void)nmea_send(session, "$PMTK424");
  1051. }
  1052. }
  1053. #ifdef RECONFIGURE_ENABLE
  1054. static bool mtk3301_rate_switcher(struct gps_device_t *session, double rate)
  1055. {
  1056. char buf[78];
  1057. unsigned int milliseconds = (unsigned int)(1000 * rate);
  1058. if (rate > 1) {
  1059. // force no slower than 1Hz
  1060. milliseconds = 1000;
  1061. } else if (rate < 0.1) {
  1062. // force no faster than 10Hz, MTK3333 can do 10Hz
  1063. milliseconds = 100;
  1064. }
  1065. (void)snprintf(buf, sizeof(buf), "$PMTK300,%u,0,0,0,0", milliseconds);
  1066. (void)nmea_send(session, buf); /* Fix interval */
  1067. return true;
  1068. }
  1069. #endif /* RECONFIGURE_ENABLE */
  1070. /* *INDENT-OFF* */
  1071. const struct gps_type_t driver_mtk3301 = {
  1072. .type_name = "MTK-3301", /* full name of type */
  1073. .packet_type = NMEA_PACKET, /* associated lexer packet type */
  1074. .flags = DRIVER_STICKY, /* remember this */
  1075. .trigger = "$PMTK705,", /* firmware release name and version */
  1076. .channels = 12, /* not used by this driver */
  1077. .probe_detect = NULL, /* no probe */
  1078. .get_packet = generic_get, /* how to get a packet */
  1079. .parse_packet = generic_parse_input, /* how to interpret a packet */
  1080. .rtcm_writer = gpsd_write, /* write RTCM data straight */
  1081. .init_query = NULL, /* non-perturbing initial query */
  1082. .event_hook = mtk3301_event_hook, /* lifetime event handler */
  1083. #ifdef RECONFIGURE_ENABLE
  1084. .speed_switcher = NULL, /* no speed switcher */
  1085. .mode_switcher = NULL, /* no mode switcher */
  1086. .rate_switcher = mtk3301_rate_switcher, /* sample rate switcher */
  1087. .min_cycle.tv_sec = 0,
  1088. .min_cycle.tv_nsec = 100000000, /* max 10Hz */
  1089. #endif /* RECONFIGURE_ENABLE */
  1090. #ifdef CONTROLSEND_ENABLE
  1091. .control_send = nmea_write, /* how to send control strings */
  1092. #endif /* CONTROLSEND_ENABLE */
  1093. .time_offset = NULL,
  1094. };
  1095. /* *INDENT-ON* */
  1096. #endif /* MTK3301_ENABLE */
  1097. #ifdef ISYNC_ENABLE
  1098. /**************************************************************************
  1099. *
  1100. * Spectratime LNRCLOK / GRCLOK iSync GPS-disciplined rubidium oscillators
  1101. *
  1102. * These devices comprise a u-blox 6 attached to a separate iSync
  1103. * microcontroller which drives the rubidium oscillator. The iSync
  1104. * microcontroller can be configured to pass through the underlying
  1105. * GPS communication channel, while still using the GPS PPSREF signal
  1106. * to discipline the rubidium oscillator.
  1107. *
  1108. * The iSync can also generate its own periodic status packets in NMEA
  1109. * format. These describe the state of the oscillator (including
  1110. * whether or not the oscillator PPSOUT is synced to the GPS PPSREF).
  1111. * These packets are transmitted in the middle of the underlying GPS
  1112. * packets, forcing us to handle interrupted NMEA packets.
  1113. *
  1114. * The default state of the device is to generate no periodic output.
  1115. * We send a probe string to initiate beating of the iSync-proprietary
  1116. * $PTNTS,B message, which is then detected as a NMEA trigger.
  1117. *
  1118. **************************************************************************/
  1119. static ssize_t isync_write(struct gps_device_t *session, const char *data)
  1120. {
  1121. return gpsd_write(session, data, strlen(data));
  1122. }
  1123. static bool isync_detect(struct gps_device_t *session)
  1124. {
  1125. speed_t old_baudrate;
  1126. char old_parity;
  1127. unsigned int old_stopbits;
  1128. /* Set 9600 8N1 */
  1129. old_baudrate = session->gpsdata.dev.baudrate;
  1130. old_parity = session->gpsdata.dev.parity;
  1131. old_stopbits = session->gpsdata.dev.stopbits;
  1132. gpsd_set_speed(session, 9600, 'N', 1);
  1133. /* Cancel pass-through mode and initiate beating of $PTNTS,B
  1134. * message, which can subsequently be detected as a trigger.
  1135. */
  1136. (void)isync_write(session, "@@@@\r\nMAW0C0B\r\n");
  1137. /* return serial port to original settings */
  1138. gpsd_set_speed(session, old_baudrate, old_parity, old_stopbits);
  1139. return false;
  1140. }
  1141. static void isync_event_hook(struct gps_device_t *session, event_t event)
  1142. {
  1143. if (session->context->readonly)
  1144. return;
  1145. if (event == event_driver_switch) {
  1146. session->lexer.counter = 0;
  1147. }
  1148. if (event == event_configure) {
  1149. switch (session->lexer.counter) {
  1150. case 1:
  1151. /* Configure timing and frequency flags:
  1152. * - Thermal compensation active
  1153. * - PPSREF active
  1154. * - PPSOUT active
  1155. */
  1156. (void)isync_write(session, "MAW040B\r\n");
  1157. /* Configure tracking flags:
  1158. * - Save frequency every 24 hours
  1159. * - Align PPSOUT to PPSINT
  1160. * - Track PPSREF
  1161. */
  1162. (void)isync_write(session, "MAW0513\r\n");
  1163. /* Configure tracking start flags:
  1164. * - Tracking restart allowed
  1165. * - Align to PPSREF
  1166. */
  1167. (void)isync_write(session, "MAW0606\r\n");
  1168. /* Configure tracking window:
  1169. * - 4us
  1170. */
  1171. (void)isync_write(session, "MAW1304\r\n");
  1172. /* Configure alarm window:
  1173. * - 4us
  1174. */
  1175. (void)isync_write(session, "MAW1404\r\n");
  1176. break;
  1177. case 2:
  1178. /* Configure pulse every d second:
  1179. * - pulse every second
  1180. */
  1181. (void)isync_write(session, "MAW1701\r\n");
  1182. /* Configure pulse origin:
  1183. * - zero offset
  1184. */
  1185. (void)isync_write(session, "MAW1800\r\n");
  1186. /* Configure pulse width:
  1187. * - 600ms
  1188. */
  1189. (void)isync_write(session, "MAW1223C34600\r\n");
  1190. break;
  1191. case 3:
  1192. /* Configure GPS resource utilization:
  1193. * - do not consider GPS messages
  1194. */
  1195. (void)isync_write(session, "MAW2200\r\n");
  1196. /* Restart sync */
  1197. (void)isync_write(session, "SY1\r\n");
  1198. /* Restart tracking */
  1199. (void)isync_write(session, "TR1\r\n");
  1200. break;
  1201. case 4:
  1202. /* Cancel BTx messages (if any) */
  1203. (void)isync_write(session, "BT0\r\n");
  1204. /* Configure messages coming out every second:
  1205. * - Oscillator status ($PTNTA) at 750ms
  1206. */
  1207. (void)isync_write(session, "MAW0B00\r\n");
  1208. (void)isync_write(session, "MAW0C0A\r\n");
  1209. break;
  1210. case 5:
  1211. /* Enable GPS passthrough and force u-blox driver to
  1212. * select NMEA mode.
  1213. */
  1214. session->mode = 0;
  1215. session->drivers_identified = 0;
  1216. (void)isync_write(session, "@@@@GPS\r\n");
  1217. break;
  1218. case 6:
  1219. /* Trigger detection of underlying u-blox (if necessary) */
  1220. (void)ubx_write(session, 0x06, 0x00, NULL, 0);
  1221. break;
  1222. }
  1223. }
  1224. }
  1225. /* *INDENT-OFF* */
  1226. const struct gps_type_t driver_isync = {
  1227. .type_name = "iSync", /* full name of type */
  1228. .packet_type = NMEA_PACKET, /* associated lexer packet type */
  1229. .flags = DRIVER_STICKY, /* remember this */
  1230. .trigger = "$PTNTS,B,", /* iSync status message */
  1231. .channels = 50, /* copied from driver_ubx */
  1232. .probe_detect = isync_detect, /* how to detect at startup time */
  1233. .get_packet = generic_get, /* how to get a packet */
  1234. .parse_packet = generic_parse_input, /* how to interpret a packet */
  1235. .init_query = NULL, /* non-perturbing initial query */
  1236. .event_hook = isync_event_hook, /* lifetime event handler */
  1237. #ifdef RECONFIGURE_ENABLE
  1238. .speed_switcher = NULL, /* no speed switcher */
  1239. .mode_switcher = NULL, /* no mode switcher */
  1240. .rate_switcher = NULL, /* no sample-rate switcher */
  1241. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  1242. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  1243. #endif /* RECONFIGURE_ENABLE */
  1244. #ifdef CONTROLSEND_ENABLE
  1245. .control_send = nmea_write, /* how to send control strings */
  1246. #endif /* CONTROLSEND_ENABLE */
  1247. .time_offset = NULL, /* no method for NTP fudge factor */
  1248. };
  1249. /* *INDENT-ON* */
  1250. #endif /* ISYNC_ENABLE */
  1251. #ifdef AIVDM_ENABLE
  1252. /**************************************************************************
  1253. *
  1254. * AIVDM - ASCII armoring of binary AIS packets
  1255. *
  1256. **************************************************************************/
  1257. static bool aivdm_decode(const char *buf, size_t buflen,
  1258. struct gps_device_t *session,
  1259. struct ais_t *ais,
  1260. int debug)
  1261. {
  1262. #ifdef __UNUSED_DEBUG__
  1263. char *sixbits[64] = {
  1264. "000000", "000001", "000010", "000011", "000100",
  1265. "000101", "000110", "000111", "001000", "001001",
  1266. "001010", "001011", "001100", "001101", "001110",
  1267. "001111", "010000", "010001", "010010", "010011",
  1268. "010100", "010101", "010110", "010111", "011000",
  1269. "011001", "011010", "011011", "011100", "011101",
  1270. "011110", "011111", "100000", "100001", "100010",
  1271. "100011", "100100", "100101", "100110", "100111",
  1272. "101000", "101001", "101010", "101011", "101100",
  1273. "101101", "101110", "101111", "110000", "110001",
  1274. "110010", "110011", "110100", "110101", "110110",
  1275. "110111", "111000", "111001", "111010", "111011",
  1276. "111100", "111101", "111110", "111111",
  1277. };
  1278. #endif /* __UNUSED_DEBUG__ */
  1279. int nfrags, ifrag, nfields = 0;
  1280. unsigned char *field[NMEA_MAX*2];
  1281. unsigned char fieldcopy[NMEA_MAX*2+1];
  1282. unsigned char *data, *cp;
  1283. char const *cp1;
  1284. int pad;
  1285. struct aivdm_context_t *ais_context;
  1286. int i;
  1287. if (buflen == 0)
  1288. return false;
  1289. /* we may need to dump the raw packet */
  1290. GPSD_LOG(LOG_PROG, &session->context->errout,
  1291. "AIVDM packet length %zd: %s\n", buflen, buf);
  1292. /* first clear the result, making sure we don't return garbage */
  1293. memset(ais, 0, sizeof(*ais));
  1294. /* discard overlong sentences */
  1295. if (strlen(buf) > sizeof(fieldcopy)-1) {
  1296. GPSD_LOG(LOG_ERROR, &session->context->errout,
  1297. "overlong AIVDM packet.\n");
  1298. return false;
  1299. }
  1300. /* discard sentences with high-half characters in them, they're corrupted */
  1301. for (cp1 = buf; *cp1; cp1++) {
  1302. if (!isascii(*cp1)) {
  1303. GPSD_LOG(LOG_ERROR, &session->context->errout,
  1304. "corrupted AIVDM packet.\n");
  1305. return false;
  1306. }
  1307. }
  1308. /* extract packet fields */
  1309. (void)strlcpy((char *)fieldcopy, buf, sizeof(fieldcopy));
  1310. field[nfields++] = (unsigned char *)buf;
  1311. for (cp = fieldcopy;
  1312. cp < fieldcopy + buflen; cp++)
  1313. {
  1314. if (
  1315. (*cp == (unsigned char)',') ||
  1316. (*cp == (unsigned char)'*')
  1317. ) {
  1318. *cp = '\0';
  1319. field[nfields++] = cp + 1;
  1320. }
  1321. }
  1322. #ifdef __UNDEF_DEBUG_
  1323. for(int i=0;i<nfields;i++)
  1324. GPSD_LOG(LOG_DATA, &session->context->errout,
  1325. "field [%d] [%s]\n", i, field[i]);
  1326. #endif
  1327. /* discard sentences with exiguous commas; catches run-ons */
  1328. if (nfields < 7) {
  1329. GPSD_LOG(LOG_ERROR, &session->context->errout,
  1330. "malformed AIVDM packet.\n");
  1331. return false;
  1332. }
  1333. switch (field[4][0]) {
  1334. case '\0':
  1335. /*
  1336. * Apparently an empty channel is normal for AIVDO sentences,
  1337. * which makes sense as they don't come in over radio. This
  1338. * is going to break if there's ever an AIVDO type 24, though.
  1339. */
  1340. if (!str_starts_with((const char *)field[0], "!AIVDO"))
  1341. GPSD_LOG(LOG_INF, &session->context->errout,
  1342. "invalid empty AIS channel. Assuming 'A'\n");
  1343. ais_context = &session->driver.aivdm.context[0];
  1344. session->driver.aivdm.ais_channel ='A';
  1345. break;
  1346. case '1':
  1347. if (strcmp((char *)field[4], (char *)"12") == 0) {
  1348. GPSD_LOG(LOG_INF, &session->context->errout,
  1349. "ignoring bogus AIS channel '12'.\n");
  1350. return false;
  1351. }
  1352. /* fall through */
  1353. case 'A':
  1354. ais_context = &session->driver.aivdm.context[0];
  1355. session->driver.aivdm.ais_channel ='A';
  1356. break;
  1357. case '2':
  1358. case 'B':
  1359. ais_context = &session->driver.aivdm.context[1];
  1360. session->driver.aivdm.ais_channel ='B';
  1361. break;
  1362. case 'C':
  1363. GPSD_LOG(LOG_INF, &session->context->errout,
  1364. "ignoring AIS channel C (secure AIS).\n");
  1365. return false;
  1366. default:
  1367. GPSD_LOG(LOG_ERROR, &session->context->errout,
  1368. "invalid AIS channel 0x%0X .\n", field[4][0]);
  1369. return false;
  1370. }
  1371. nfrags = atoi((char *)field[1]); /* number of fragments to expect */
  1372. ifrag = atoi((char *)field[2]); /* fragment id */
  1373. data = field[5];
  1374. pad = 0;
  1375. if(isdigit(field[6][0]))
  1376. pad = field[6][0] - '0'; /* number of padding bits ASCII encoded*/
  1377. GPSD_LOG(LOG_PROG, &session->context->errout,
  1378. "nfrags=%d, ifrag=%d, decoded_frags=%d, data=%s, pad=%d\n",
  1379. nfrags, ifrag, ais_context->decoded_frags, data, pad);
  1380. /* assemble the binary data */
  1381. /* check fragment ordering */
  1382. if (ifrag != ais_context->decoded_frags + 1) {
  1383. GPSD_LOG(LOG_ERROR, &session->context->errout,
  1384. "invalid fragment #%d received, expected #%d.\n",
  1385. ifrag, ais_context->decoded_frags + 1);
  1386. if (ifrag != 1)
  1387. return false;
  1388. /* else, ifrag==1: Just discard all that was previously decoded and
  1389. * simply handle that packet */
  1390. ais_context->decoded_frags = 0;
  1391. }
  1392. if (ifrag == 1) {
  1393. (void)memset(ais_context->bits, '\0', sizeof(ais_context->bits));
  1394. ais_context->bitlen = 0;
  1395. }
  1396. /* wacky 6-bit encoding, shades of FIELDATA */
  1397. for (cp = data; cp < data + strlen((char *)data); cp++) {
  1398. unsigned char ch;
  1399. ch = *cp;
  1400. ch -= 48;
  1401. if (ch >= 40)
  1402. ch -= 8;
  1403. #ifdef __UNUSED_DEBUG__
  1404. GPSD_LOG(LOG_RAW, &session->context->errout,
  1405. "%c: %s\n", *cp, sixbits[ch]);
  1406. #endif /* __UNUSED_DEBUG__ */
  1407. for (i = 5; i >= 0; i--) {
  1408. if ((ch >> i) & 0x01) {
  1409. ais_context->bits[ais_context->bitlen / 8] |=
  1410. (1 << (7 - ais_context->bitlen % 8));
  1411. }
  1412. ais_context->bitlen++;
  1413. if (ais_context->bitlen > sizeof(ais_context->bits)) {
  1414. GPSD_LOG(LOG_INF, &session->context->errout,
  1415. "overlong AIVDM payload truncated.\n");
  1416. return false;
  1417. }
  1418. }
  1419. }
  1420. ais_context->bitlen -= pad;
  1421. /* time to pass buffered-up data to where it's actually processed? */
  1422. if (ifrag == nfrags) {
  1423. if (debug >= LOG_INF) {
  1424. size_t clen = BITS_TO_BYTES(ais_context->bitlen);
  1425. GPSD_LOG(LOG_INF, &session->context->errout,
  1426. "AIVDM payload is %zd bits, %zd chars: %s\n",
  1427. ais_context->bitlen, clen,
  1428. gpsd_hexdump(session->msgbuf, sizeof(session->msgbuf),
  1429. (char *)ais_context->bits, clen));
  1430. }
  1431. /* clear waiting fragments count */
  1432. ais_context->decoded_frags = 0;
  1433. /* decode the assembled binary packet */
  1434. return ais_binary_decode(&session->context->errout,
  1435. ais,
  1436. ais_context->bits,
  1437. ais_context->bitlen,
  1438. &ais_context->type24_queue);
  1439. }
  1440. /* we're still waiting on another sentence */
  1441. ais_context->decoded_frags++;
  1442. return false;
  1443. }
  1444. static gps_mask_t aivdm_analyze(struct gps_device_t *session)
  1445. {
  1446. if (session->lexer.type == AIVDM_PACKET) {
  1447. if (aivdm_decode
  1448. ((char *)session->lexer.outbuffer, session->lexer.outbuflen,
  1449. session, &session->gpsdata.ais,
  1450. session->context->errout.debug)) {
  1451. return ONLINE_SET | AIS_SET;
  1452. } else
  1453. return ONLINE_SET;
  1454. #ifdef NMEA0183_ENABLE
  1455. } else if (session->lexer.type == NMEA_PACKET) {
  1456. return nmea_parse((char *)session->lexer.outbuffer, session);
  1457. #endif /* NMEA0183_ENABLE */
  1458. } else
  1459. return 0;
  1460. }
  1461. /* *INDENT-OFF* */
  1462. const struct gps_type_t driver_aivdm = {
  1463. /* Full name of type */
  1464. .type_name = "AIVDM", /* associated lexer packet type */
  1465. .packet_type = AIVDM_PACKET, /* numeric packet type */
  1466. .flags = DRIVER_NOFLAGS, /* no rollover or other flags */
  1467. .trigger = NULL, /* identifying response */
  1468. .channels = 0, /* not used by this driver */
  1469. .probe_detect = NULL, /* no probe */
  1470. .get_packet = generic_get, /* how to get a packet */
  1471. .parse_packet = aivdm_analyze, /* how to analyze a packet */
  1472. .rtcm_writer = NULL, /* don't send RTCM data, */
  1473. .init_query = NULL, /* non-perturbing initial query */
  1474. .event_hook = NULL, /* lifetime event handler */
  1475. #ifdef RECONFIGURE_ENABLE
  1476. .speed_switcher = NULL, /* no speed switcher */
  1477. .mode_switcher = NULL, /* no mode switcher */
  1478. .rate_switcher = NULL, /* no rate switcher */
  1479. .min_cycle.tv_sec = 1, /* max 1Hz */
  1480. .min_cycle.tv_nsec = 0,
  1481. #endif /* RECONFIGURE_ENABLE */
  1482. #ifdef CONTROLSEND_ENABLE
  1483. .control_send = NULL, /* no control sender */
  1484. #endif /* CONTROLSEND_ENABLE */
  1485. .time_offset = NULL, /* no NTP communication */
  1486. };
  1487. /* *INDENT-ON* */
  1488. #endif /* AIVDM_ENABLE */
  1489. #ifdef PASSTHROUGH_ENABLE
  1490. /**************************************************************************
  1491. *
  1492. * JSON passthrough driver
  1493. *
  1494. **************************************************************************/
  1495. static void path_rewrite(struct gps_device_t *session, char *prefix)
  1496. /* prepend the session path to the value of a specified attribute */
  1497. {
  1498. /*
  1499. * Hack the packet to reflect its origin. This code is supposed
  1500. * to insert the path naming the remote gpsd instance into the
  1501. * beginning of the path attribute, followed by a # to separate it
  1502. * from the device.
  1503. */
  1504. char *prefloc;
  1505. assert(prefix != NULL && session->lexer.outbuffer != NULL);
  1506. /* possibly the rewrite has been done already, this comw up in gpsmon */
  1507. if (strstr((char *)session->lexer.outbuffer, session->gpsdata.dev.path) != NULL)
  1508. return;
  1509. for (prefloc = (char *)session->lexer.outbuffer;
  1510. prefloc < (char *)session->lexer.outbuffer+session->lexer.outbuflen;
  1511. prefloc++)
  1512. if (str_starts_with(prefloc, prefix)) {
  1513. char *sfxloc;
  1514. char copy[sizeof(session->lexer.outbuffer)+1];
  1515. (void)strlcpy(copy,
  1516. (char *)session->lexer.outbuffer,
  1517. sizeof(copy));
  1518. prefloc += strlen(prefix);
  1519. (void)strlcpy(prefloc,
  1520. session->gpsdata.dev.path,
  1521. sizeof(session->gpsdata.dev.path));
  1522. if ((sfxloc = strchr(prefloc, '#')))
  1523. *sfxloc = '\0'; /* Avoid accumulating multiple device names */
  1524. (void)strlcat((char *)session->lexer.outbuffer, "#",
  1525. sizeof(session->lexer.outbuffer));
  1526. (void)strlcat((char *)session->lexer.outbuffer,
  1527. copy + (prefloc-(char *)session->lexer.outbuffer),
  1528. sizeof(session->lexer.outbuffer));
  1529. }
  1530. session->lexer.outbuflen = strlen((char *)session->lexer.outbuffer);
  1531. }
  1532. static gps_mask_t json_pass_packet(struct gps_device_t *session)
  1533. {
  1534. GPSD_LOG(LOG_IO, &session->context->errout,
  1535. "<= GPS: %s\n", (char *)session->lexer.outbuffer);
  1536. if (strstr(session->gpsdata.dev.path, ":/") != NULL && strstr(session->gpsdata.dev.path, "localhost") == NULL)
  1537. {
  1538. /* devices and paths need to be edited */
  1539. if (strstr((char *)session->lexer.outbuffer, "DEVICE") != NULL)
  1540. path_rewrite(session, "\"path\":\"");
  1541. path_rewrite(session, "\"device\":\"");
  1542. /* mark certain responses without a path or device attribute */
  1543. if (session->gpsdata.dev.path[0] != '\0') {
  1544. if (strstr((char *)session->lexer.outbuffer, "VERSION") != NULL
  1545. || strstr((char *)session->lexer.outbuffer, "WATCH") != NULL
  1546. || strstr((char *)session->lexer.outbuffer, "DEVICES") != NULL) {
  1547. session->lexer.outbuffer[session->lexer.outbuflen-1] = '\0';
  1548. (void)strlcat((char *)session->lexer.outbuffer, ",\"remote\":\"",
  1549. sizeof(session->lexer.outbuffer));
  1550. (void)strlcat((char *)session->lexer.outbuffer,
  1551. session->gpsdata.dev.path,
  1552. sizeof(session->lexer.outbuffer));
  1553. (void)strlcat((char *)session->lexer.outbuffer, "\"}",
  1554. sizeof(session->lexer.outbuffer));
  1555. }
  1556. session->lexer.outbuflen = strlen((char *)session->lexer.outbuffer);
  1557. }
  1558. }
  1559. GPSD_LOG(LOG_PROG, &session->context->errout,
  1560. "JSON, passing through %s\n",
  1561. (char *)session->lexer.outbuffer);
  1562. return PASSTHROUGH_IS;
  1563. }
  1564. /* *INDENT-OFF* */
  1565. const struct gps_type_t driver_json_passthrough = {
  1566. .type_name = "JSON slave driver", /* full name of type */
  1567. .packet_type = JSON_PACKET, /* associated lexer packet type */
  1568. .flags = DRIVER_NOFLAGS, /* don't remember this */
  1569. .trigger = NULL, /* it's the default */
  1570. .channels = 0, /* not used */
  1571. .probe_detect = NULL, /* no probe */
  1572. .get_packet = generic_get, /* use generic packet getter */
  1573. .parse_packet = json_pass_packet, /* how to interpret a packet */
  1574. .rtcm_writer = NULL, /* write RTCM data straight */
  1575. .init_query = NULL, /* non-perturbing initial query */
  1576. .event_hook = NULL, /* lifetime event handler */
  1577. #ifdef RECONFIGURE_ENABLE
  1578. .speed_switcher = NULL, /* no speed switcher */
  1579. .mode_switcher = NULL, /* no mode switcher */
  1580. .rate_switcher = NULL, /* no sample-rate switcher */
  1581. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  1582. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  1583. #endif /* RECONFIGURE_ENABLE */
  1584. #ifdef CONTROLSEND_ENABLE
  1585. .control_send = NULL, /* how to send control strings */
  1586. #endif /* CONTROLSEND_ENABLE */
  1587. .time_offset = NULL, /* no method for NTP fudge factor */
  1588. };
  1589. /* *INDENT-ON* */
  1590. #endif /* PASSTHROUGH_ENABLE */
  1591. /* *INDENT-OFF* */
  1592. const struct gps_type_t driver_pps = {
  1593. .type_name = "PPS", /* full name of type */
  1594. .packet_type = BAD_PACKET, /* associated lexer packet type */
  1595. .flags = DRIVER_NOFLAGS, /* don't remember this */
  1596. .trigger = NULL, /* it's the default */
  1597. .channels = 0, /* not used */
  1598. .probe_detect = NULL, /* no probe */
  1599. .get_packet = NULL, /* use generic packet getter */
  1600. .parse_packet = NULL, /* how to interpret a packet */
  1601. .rtcm_writer = NULL, /* write RTCM data straight */
  1602. .init_query = NULL, /* non-perturbing initial query */
  1603. .event_hook = NULL, /* lifetime event handler */
  1604. #ifdef RECONFIGURE_ENABLE
  1605. .speed_switcher = NULL, /* no speed switcher */
  1606. .mode_switcher = NULL, /* no mode switcher */
  1607. .rate_switcher = NULL, /* no sample-rate switcher */
  1608. .min_cycle.tv_sec = 1, /* not relevant, no rate switch */
  1609. .min_cycle.tv_nsec = 0, /* not relevant, no rate switch */
  1610. #endif /* RECONFIGURE_ENABLE */
  1611. #ifdef CONTROLSEND_ENABLE
  1612. .control_send = NULL, /* how to send control strings */
  1613. #endif /* CONTROLSEND_ENABLE */
  1614. .time_offset = NULL, /* no method for NTP fudge factor */
  1615. };
  1616. /* *INDENT-ON* */
  1617. extern const struct gps_type_t driver_evermore;
  1618. extern const struct gps_type_t driver_garmin_ser_binary;
  1619. extern const struct gps_type_t driver_garmin_usb_binary;
  1620. extern const struct gps_type_t driver_geostar;
  1621. extern const struct gps_type_t driver_greis;
  1622. extern const struct gps_type_t driver_italk;
  1623. extern const struct gps_type_t driver_navcom;
  1624. extern const struct gps_type_t driver_nmea2000;
  1625. extern const struct gps_type_t driver_oncore;
  1626. extern const struct gps_type_t driver_sirf;
  1627. extern const struct gps_type_t driver_skytraq;
  1628. extern const struct gps_type_t driver_superstar2;
  1629. extern const struct gps_type_t driver_tsip;
  1630. extern const struct gps_type_t driver_ubx;
  1631. extern const struct gps_type_t driver_zodiac;
  1632. /* the point of this rigamarole is to not have to export a table size */
  1633. static const struct gps_type_t *gpsd_driver_array[] = {
  1634. &driver_unknown,
  1635. #ifdef NMEA0183_ENABLE
  1636. &driver_nmea0183,
  1637. #ifdef ASHTECH_ENABLE
  1638. &driver_ashtech,
  1639. #endif /* ASHTECH_ENABLE */
  1640. #ifdef TRIPMATE_ENABLE
  1641. &driver_tripmate,
  1642. #endif /* TRIPMATE_ENABLE */
  1643. #ifdef EARTHMATE_ENABLE
  1644. &driver_earthmate,
  1645. #endif /* EARTHMATE_ENABLE */
  1646. #ifdef GPSCLOCK_ENABLE
  1647. &driver_gpsclock,
  1648. #endif /* GPSCLOCK_ENABLE */
  1649. #ifdef GARMIN_ENABLE
  1650. &driver_garmin,
  1651. #endif /* GARMIN_ENABLE */
  1652. #ifdef MTK3301_ENABLE
  1653. &driver_mtk3301,
  1654. #endif /* MTK3301_ENABLE */
  1655. #ifdef OCEANSERVER_ENABLE
  1656. &driver_oceanServer,
  1657. #endif /* OCEANSERVER_ENABLE */
  1658. #ifdef FV18_ENABLE
  1659. &driver_fv18,
  1660. #endif /* FV18_ENABLE */
  1661. #ifdef TNT_ENABLE
  1662. &driver_trueNorth,
  1663. #endif /* TNT_ENABLE */
  1664. #ifdef FURY_ENABLE
  1665. &driver_fury,
  1666. #endif /* FURY_ENABLE */
  1667. #ifdef AIVDM_ENABLE
  1668. &driver_aivdm,
  1669. #endif /* AIVDM_ENABLE */
  1670. #endif /* NMEA0183_ENABLE */
  1671. #ifdef EVERMORE_ENABLE
  1672. &driver_evermore,
  1673. #endif /* EVERMORE_ENABLE */
  1674. #ifdef GARMIN_ENABLE
  1675. /* be sure to try Garmin Serial Binary before Garmin USB Binary */
  1676. &driver_garmin_ser_binary,
  1677. &driver_garmin_usb_binary,
  1678. #endif /* GARMIN_ENABLE */
  1679. #ifdef GEOSTAR_ENABLE
  1680. &driver_geostar,
  1681. #endif /* GEOSTAR_ENABLE */
  1682. #ifdef GREIS_ENABLE
  1683. &driver_greis,
  1684. #endif /* GREIS_ENABLE */
  1685. #ifdef ITRAX_ENABLE
  1686. &driver_italk,
  1687. #endif /* ITRAX_ENABLE */
  1688. #ifdef ONCORE_ENABLE
  1689. &driver_oncore,
  1690. #endif /* ONCORE_ENABLE */
  1691. #ifdef NAVCOM_ENABLE
  1692. &driver_navcom,
  1693. #endif /* NAVCOM_ENABLE */
  1694. #ifdef SIRF_ENABLE
  1695. &driver_sirf,
  1696. #endif /* SIRF_ENABLE */
  1697. #ifdef SKYTRAQ_ENABLE
  1698. &driver_skytraq,
  1699. #endif /* SKYTRAQ_ENABLE */
  1700. #ifdef SUPERSTAR2_ENABLE
  1701. &driver_superstar2,
  1702. #endif /* SUPERSTAR2_ENABLE */
  1703. #ifdef TSIP_ENABLE
  1704. &driver_tsip,
  1705. #endif /* TSIP_ENABLE */
  1706. #ifdef ISYNC_ENABLE
  1707. &driver_isync,
  1708. #endif /* ISYNC_ENABLE */
  1709. #ifdef UBLOX_ENABLE
  1710. &driver_ubx,
  1711. #endif /* UBLOX_ENABLE */
  1712. #ifdef ZODIAC_ENABLE
  1713. &driver_zodiac,
  1714. #endif /* ZODIAC_ENABLE */
  1715. #ifdef NMEA2000_ENABLE
  1716. &driver_nmea2000,
  1717. #endif /* NMEA2000_ENABLE */
  1718. #ifdef RTCM104V2_ENABLE
  1719. &driver_rtcm104v2,
  1720. #endif /* RTCM104V2_ENABLE */
  1721. #ifdef RTCM104V3_ENABLE
  1722. &driver_rtcm104v3,
  1723. #endif /* RTCM104V3_ENABLE */
  1724. #ifdef GARMINTXT_ENABLE
  1725. &driver_garmintxt,
  1726. #endif /* GARMINTXT_ENABLE */
  1727. #ifdef PASSTHROUGH_ENABLE
  1728. &driver_json_passthrough,
  1729. #endif /* PASSTHROUGH_ENABLE */
  1730. &driver_pps,
  1731. NULL,
  1732. };
  1733. const struct gps_type_t **gpsd_drivers = &gpsd_driver_array[0];