gpsd.h 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. /* gpsd.h -- fundamental types and structures for the gpsd library
  2. *
  3. * This file is Copyright 2017 by the GPSD project
  4. * SPDX-License-Identifier: BSD-2-clause
  5. */
  6. #ifndef _GPSD_H_
  7. #define _GPSD_H_
  8. #include "compiler.h" /* Must be outside extern "C" for "atomic"
  9. * pulls in gpsd_config.h */
  10. # ifdef __cplusplus
  11. extern "C" {
  12. # endif
  13. #include <stdarg.h>
  14. #include <stdbool.h>
  15. #include <stdint.h>
  16. #include <stdio.h>
  17. #include <termios.h>
  18. #ifdef HAVE_WINSOCK2_H
  19. #include <winsock2.h> /* for fd_set */
  20. #else /* !HAVE_WINSOCK2_H */
  21. #include <sys/select.h> /* for fd_set */
  22. #endif /* !HAVE_WINSOCK2_H */
  23. #include <time.h> /* for time_t */
  24. #include "gps.h"
  25. #include "os_compat.h"
  26. #include "ppsthread.h"
  27. #include "timespec.h"
  28. /*
  29. * Constants for the VERSION response
  30. * 3.1: Base JSON version
  31. * 3.2: Added POLL command and response
  32. * 3.3: AIS app_id split into DAC and FID
  33. * 3.4: Timestamps change from seconds since Unix epoch to ISO8601.
  34. * 3.5: POLL subobject name changes: fixes -> tpv, skyview -> sky.
  35. * DEVICE::activated becomes ISO8601 rather than real.
  36. * 3.6 VERSION, WATCH, and DEVICES from slave gpsds get "remote" attribute.
  37. * 3.7 PPS message added to repertoire. SDDBT water depth reported as
  38. * negative altitude with Mode 3 set.
  39. * 3.8 AIS course member becomes float in scaled mode (bug fix).
  40. * 3.9 split24 flag added. Controlled-vocabulary fields are now always
  41. * dumped in both numeric and string form, with the string being the
  42. * value of a synthesized additional attribute with "_text" appended.
  43. * (Thus, the 'scaled' flag no longer affects display of these fields.)
  44. * PPS drift message ships nsec rather than msec.
  45. * 3.10 The obsolete tag field has been dropped from JSON.
  46. * 3.11 A precision field, log2 of the time source jitter, has been added
  47. * to the PPS report. See ntpshm.h for more details.
  48. * 3.12 OSC message added to repertoire.
  49. * 3.13 gnssid:svid added to SAT
  50. * time added to ATT
  51. * 3.19 Added RAW message class.
  52. * Add cfg_stage and cfg_step, for initialization
  53. * Add oldfix2 for better oldfix
  54. * Make subtype longer
  55. * Add ubx.protver, ubx.last_msgid and more to gps_device_t.ubx
  56. * MAX_PACKET_LENGTH 516 -> 9216
  57. * Add stuff to gps_device_t.nmea for NMEA 4.1
  58. * 3.20
  59. * Remove TIMEHINT_ENABLE. It only worked when enabled.
  60. * Remove NTP_ENABLE and NTPSHM_ENABLE. It only worked when enabled.
  61. * Change gps_type_t.min_cycle from double to timespec_t
  62. * Change gps_device_t.last_time from double to timespec_t
  63. * Change gps_lexer_t.start_time from timestamp_t to timespec_t
  64. * Change gps_context_t.gps_tow from double to timespec_t
  65. * Change gps_device_t.sor from timestamp_t to timespec_t
  66. * Change gps_device_t.this_frac_time, last_frac_time to timespec_t
  67. * Change nmea.subseconds from double to timespec_t
  68. * Remove gpsd_gpstime_resolve()
  69. * Changed order of gpsd_log() arguments. Add GPSD_LOG().
  70. * Remove gps_device_t.back_to_nmea.
  71. * Add fixed_port_speed, fixed_port_framing to gps_context_t.
  72. * change tsip.superpkt from bool to int.
  73. * Add tsip .machine_id, .hardware_code, .last_tow, last_chan_seen
  74. * Split gps_device_t.subtype into subtype and subtype1
  75. * 3.20.1
  76. * GPSD_PROTO_*_VERSION moved to gpsd_config.h
  77. * Add gps_context_t.passive
  78. * Add gps_context_t.batteryRTC
  79. *
  80. */
  81. #define JSON_DATE_MAX 24 /* ISO8601 timestamp with 2 decimal places */
  82. // be sure to change BUILD_LEAPSECONDS as needed.
  83. #define BUILD_CENTURY 2000
  84. #define BUILD_LEAPSECONDS 18
  85. #ifndef DEFAULT_GPSD_SOCKET
  86. #define DEFAULT_GPSD_SOCKET RUNDIR "/gpsd.sock"
  87. #endif
  88. /* Some internal capabilities depend on which drivers we're compiling. */
  89. #if !defined(AIVDM_ENABLE) && defined(NMEA2000_ENABLE)
  90. #define AIVDM_ENABLE
  91. #endif
  92. #if !defined(NMEA0183_ENABLE) && (defined(ASHTECH_ENABLE) || \
  93. defined(FV18_ENABLE) || \
  94. defined(MTK3301_ENABLE) || \
  95. defined(OCEANSERVER_ENABLE) || \
  96. defined(GPSCLOCK_ENABLE) || \
  97. defined(FURY_ENABLE) || \
  98. defined(SKYTRAQ_ENABLE) || \
  99. defined(TRIPMATE_ENABLE) || \
  100. defined(TNT_ENABLE))
  101. #define NMEA0183_ENABLE
  102. #endif
  103. #ifdef EARTHMATE_ENABLE
  104. #define ZODIAC_ENABLE
  105. #endif
  106. #if defined(EVERMORE_ENABLE) || \
  107. defined(GARMIN_ENABLE) || \
  108. defined(GEOSTAR_ENABLE) || \
  109. defined(GREIS_ENABLE) || \
  110. defined(ITRAX_ENABLE) || \
  111. defined(NAVCOM_ENABLE) || \
  112. defined(NMEA2000_ENABLE) || \
  113. defined(ONCORE_ENABLE) || \
  114. defined(SIRF_ENABLE) || \
  115. defined(SUPERSTAR2_ENABLE) || \
  116. defined(TSIP_ENABLE) || \
  117. defined(UBLOX_ENABLE) || \
  118. defined(ZODIAC_ENABLE)
  119. #define BINARY_ENABLE
  120. #endif
  121. #if defined(TRIPMATE_ENABLE) || defined(BINARY_ENABLE)
  122. #define NON_NMEA0183_ENABLE
  123. #endif
  124. #if defined(TNT_ENABLE) || defined(OCEANSERVER_ENABLE)
  125. #define COMPASS_ENABLE
  126. #endif
  127. #ifdef ISYNC_ENABLE
  128. #define STASH_ENABLE
  129. #endif
  130. /* First, declarations for the packet layer... */
  131. /*
  132. * NMEA 3.01, Section 5.3 says the max sentence length shall be
  133. * 82 chars, including the leading $ and terminating \r\n.
  134. *
  135. * Some receivers (TN-200, GSW 2.3.2) emit oversized sentences.
  136. * The Trimble BX-960 receiver emits a 91-character GGA message.
  137. * The current hog champion is the Skytraq S2525F8 which emits
  138. * a 100-character PSTI message.
  139. */
  140. #define NMEA_MAX 102 /* max length of NMEA sentence */
  141. #define NMEA_MAX_FLD 100 // max fields in an NMEA sentence
  142. #define NMEA_BIG_BUF (2*NMEA_MAX+1) /* longer than longest NMEA sentence */
  143. /* a few bits of ISGPS magic */
  144. enum isgpsstat_t {
  145. ISGPS_NO_SYNC, ISGPS_SYNC, ISGPS_SKIP, ISGPS_MESSAGE,
  146. };
  147. #define RTCM_MAX (RTCM2_WORDS_MAX * sizeof(isgps30bits_t))
  148. /* RTCM is more variable length than RTCM 2 */
  149. #define RTCM3_MAX 512
  150. /*
  151. * The packet buffers need to be as long than the longest packet we
  152. * expect to see in any protocol, because we have to be able to hold
  153. * an entire packet for checksumming...
  154. * First we thought it had to be big enough for a SiRF Measured Tracker
  155. * Data packet (188 bytes). Then it had to be big enough for a UBX SVINFO
  156. * packet (206 bytes). Now it turns out that a couple of ITALK messages are
  157. * over 512 bytes. I know we like verbose output, but this is ridiculous.
  158. * Whoopie! The u-blox 8 UBX-RXM-RAWX packet is 8214 byte long!
  159. */
  160. #define MAX_PACKET_LENGTH 9216 /* 4 + 16 + (256 * 32) + 2 + fudge */
  161. /*
  162. * UTC of second 0 of week 0 of the first rollover period of GPS time.
  163. * Used to compute UTC from GPS time. Also, the threshold value
  164. * under which system clock times are considered unreliable. Often,
  165. * embedded systems come up thinking it's early 1970 and the system
  166. * clock will report small positive values until the clock is set. By
  167. * choosing this as the cutoff, we'll never reject historical GPS logs
  168. * that are actually valid.
  169. */
  170. #define GPS_EPOCH ((time_t)315964800) /* 6 Jan 1980 00:00:00 UTC */
  171. /* time constant */
  172. #define SECS_PER_DAY ((time_t)(60*60*24)) /* seconds per day */
  173. #define SECS_PER_WEEK (7*SECS_PER_DAY) /* seconds per week */
  174. #define GPS_ROLLOVER (1024*SECS_PER_WEEK) /* rollover period */
  175. struct gpsd_errout_t {
  176. int debug; /* lexer debug level */
  177. void (*report)(const char *); /* reporting hook for lexer errors */
  178. char *label;
  179. };
  180. struct gps_lexer_t {
  181. /* packet-getter internals */
  182. int type;
  183. #define BAD_PACKET -1
  184. #define COMMENT_PACKET 0
  185. #define NMEA_PACKET 1
  186. #define AIVDM_PACKET 2
  187. #define GARMINTXT_PACKET 3
  188. #define MAX_TEXTUAL_TYPE 3 /* increment this as necessary */
  189. #define SIRF_PACKET 4
  190. #define ZODIAC_PACKET 5
  191. #define TSIP_PACKET 6
  192. #define EVERMORE_PACKET 7
  193. #define ITALK_PACKET 8
  194. #define GARMIN_PACKET 9
  195. #define NAVCOM_PACKET 10
  196. #define UBX_PACKET 11
  197. #define SUPERSTAR2_PACKET 12
  198. #define ONCORE_PACKET 13
  199. #define GEOSTAR_PACKET 14
  200. #define NMEA2000_PACKET 15
  201. #define GREIS_PACKET 16
  202. #define MAX_GPSPACKET_TYPE 16 /* increment this as necessary */
  203. #define RTCM2_PACKET 17
  204. #define RTCM3_PACKET 18
  205. #define JSON_PACKET 19
  206. #define PACKET_TYPES 20 /* increment this as necessary */
  207. #define SKY_PACKET 21
  208. #define TEXTUAL_PACKET_TYPE(n) ((((n)>=NMEA_PACKET) && ((n)<=MAX_TEXTUAL_TYPE)) || (n)==JSON_PACKET)
  209. #define GPS_PACKET_TYPE(n) (((n)>=NMEA_PACKET) && ((n)<=MAX_GPSPACKET_TYPE))
  210. #define LOSSLESS_PACKET_TYPE(n) (((n)>=RTCM2_PACKET) && ((n)<=RTCM3_PACKET))
  211. #define PACKET_TYPEMASK(n) (1 << (n))
  212. #define GPS_TYPEMASK (((2<<(MAX_GPSPACKET_TYPE+1))-1) &~ PACKET_TYPEMASK(COMMENT_PACKET))
  213. unsigned int state;
  214. size_t length;
  215. unsigned char inbuffer[MAX_PACKET_LENGTH*2+1];
  216. size_t inbuflen;
  217. unsigned char *inbufptr;
  218. /* outbuffer needs to be able to hold 4 GPGSV records at once */
  219. unsigned char outbuffer[MAX_PACKET_LENGTH*2+1];
  220. size_t outbuflen;
  221. unsigned long char_counter; /* count characters processed */
  222. unsigned long retry_counter; /* count sniff retries */
  223. unsigned counter; /* packets since last driver switch */
  224. struct gpsd_errout_t errout; /* how to report errors */
  225. timespec_t start_time; /* time of first input */
  226. unsigned long start_char; /* char counter at first input */
  227. /*
  228. * ISGPS200 decoding context.
  229. *
  230. * This is not conditionalized on RTCM104_ENABLE because we need to
  231. * be able to build gpsdecode even when RTCM support is not
  232. * configured in the daemon.
  233. */
  234. struct {
  235. bool locked;
  236. int curr_offset;
  237. isgps30bits_t curr_word;
  238. unsigned int bufindex;
  239. /*
  240. * Only these should be referenced from elsewhere, and only when
  241. * RTCM_MESSAGE has just been returned.
  242. */
  243. isgps30bits_t buf[RTCM2_WORDS_MAX]; /* packet data */
  244. size_t buflen; /* packet length in bytes */
  245. } isgps;
  246. #ifdef PASSTHROUGH_ENABLE
  247. unsigned int json_depth;
  248. unsigned int json_after;
  249. #endif /* PASSTHROUGH_ENABLE */
  250. #ifdef STASH_ENABLE
  251. unsigned char stashbuffer[MAX_PACKET_LENGTH];
  252. size_t stashbuflen;
  253. #endif /* STASH_ENABLE */
  254. };
  255. extern void lexer_init(struct gps_lexer_t *);
  256. extern void packet_reset(struct gps_lexer_t *);
  257. extern void packet_pushback(struct gps_lexer_t *);
  258. extern void packet_parse(struct gps_lexer_t *);
  259. extern ssize_t packet_get(int, struct gps_lexer_t *);
  260. extern int packet_sniff(struct gps_lexer_t *);
  261. #define packet_buffered_input(lexer) ((lexer)->inbuffer + (lexer)->inbuflen - (lexer)->inbufptr)
  262. /* Next, declarations for the core library... */
  263. /* factors for converting among confidence interval units */
  264. #define CEP50_SIGMA 1.18
  265. #define DRMS_SIGMA 1.414
  266. #define CEP95_SIGMA 2.45
  267. /* this is where we choose the confidence level to use in reports */
  268. #define GPSD_CONFIDENCE CEP95_SIGMA
  269. #define NTPSHMSEGS (MAX_DEVICES * 2) /* number of NTP SHM segments */
  270. #define NTP_MIN_FIXES 3 /* # fixes to wait for before shipping NTP time */
  271. #define AIVDM_CHANNELS 2 /* A, B */
  272. struct gps_device_t;
  273. struct gps_context_t {
  274. int valid; /* member validity flags */
  275. #define LEAP_SECOND_VALID 0x01 /* we have or don't need correction */
  276. #define GPS_TIME_VALID 0x02 /* GPS week/tow is valid */
  277. #define CENTURY_VALID 0x04 /* have received ZDA or 4-digit year */
  278. struct gpsd_errout_t errout; /* debug verbosity level and hook */
  279. bool readonly; /* if true, never write to device */
  280. bool passive; // if true, never autoconfigure device
  281. // if true, remove fix gate to time, for some RTC backed receivers.
  282. // DANGEROUS
  283. bool batteryRTC;
  284. speed_t fixed_port_speed; // Fixed port speed, if non-zero
  285. char fixed_port_framing[4]; // Fixed port framing, if non-blank
  286. /* DGPS status */
  287. int fixcnt; /* count of good fixes seen */
  288. /* timekeeping */
  289. time_t start_time; /* local time of daemon startup */
  290. int leap_seconds; /* Unix secs to UTC (GPS-UTC offset) */
  291. unsigned short gps_week; /* GPS week, usually 10 bits */
  292. timespec_t gps_tow; /* GPS time of week */
  293. int century; /* for NMEA-only devices without ZDA */
  294. int rollovers; /* rollovers since start of run */
  295. int leap_notify; /* notification state from subframe */
  296. #define LEAP_NOWARNING 0x0 /* normal, no leap second warning */
  297. #define LEAP_ADDSECOND 0x1 /* last minute of day has 60 seconds */
  298. #define LEAP_DELSECOND 0x2 /* last minute of day has 59 seconds */
  299. #define LEAP_NOTINSYNC 0x3 /* overload, clock is free running */
  300. /* we need the volatile here to tell the C compiler not to
  301. * 'optimize' as 'dead code' the writes to SHM */
  302. volatile struct shmTime *shmTime[NTPSHMSEGS];
  303. bool shmTimeInuse[NTPSHMSEGS];
  304. void (*pps_hook)(struct gps_device_t *, struct timedelta_t *);
  305. #ifdef SHM_EXPORT_ENABLE
  306. /* we don't want the compiler to treat writes to shmexport as dead code,
  307. * and we don't want them reordered either */
  308. volatile void *shmexport;
  309. int shmid; /* ID of SHM (for later IPC_RMID) */
  310. #endif
  311. ssize_t (*serial_write)(struct gps_device_t *,
  312. const char *buf, const size_t len);
  313. };
  314. /* state for resolving interleaved Type 24 packets */
  315. struct ais_type24a_t {
  316. unsigned int mmsi;
  317. char shipname[AIS_SHIPNAME_MAXLEN+1];
  318. };
  319. #define MAX_TYPE24_INTERLEAVE 8 /* max number of queued type 24s */
  320. struct ais_type24_queue_t {
  321. struct ais_type24a_t ships[MAX_TYPE24_INTERLEAVE];
  322. int index;
  323. };
  324. /* state for resolving AIVDM decodes */
  325. struct aivdm_context_t {
  326. /* hold context for decoding AIDVM packet sequences */
  327. int decoded_frags; // for tracking AIDVM parts in a multipart sequence
  328. unsigned char bits[2048];
  329. size_t bitlen; /* how many valid bits */
  330. struct ais_type24_queue_t type24_queue;
  331. };
  332. #define MODE_NMEA 0
  333. #define MODE_BINARY 1
  334. typedef enum {ANY, GPS, RTCM2, RTCM3, AIS} gnss_type;
  335. typedef enum {
  336. event_wakeup,
  337. event_triggermatch,
  338. event_identified,
  339. event_configure,
  340. event_driver_switch,
  341. event_deactivate,
  342. event_reactivate,
  343. } event_t;
  344. #define INTERNAL_SET(n) ((gps_mask_t)(1llu<<(SET_HIGH_BIT+(n))))
  345. #define RAW_IS INTERNAL_SET(1) /* raw pseudoranges available */
  346. #define USED_IS INTERNAL_SET(2) /* sat-used count available */
  347. #define DRIVER_IS INTERNAL_SET(3) /* driver type identified */
  348. #define CLEAR_IS INTERNAL_SET(4) /* starts a reporting cycle */
  349. #define REPORT_IS INTERNAL_SET(5) /* ends a reporting cycle */
  350. #define NODATA_IS INTERNAL_SET(6) /* no data read from fd */
  351. #define NTPTIME_IS INTERNAL_SET(7) // precision time is available
  352. #define PERR_IS INTERNAL_SET(8) /* PDOP set */
  353. #define PASSTHROUGH_IS INTERNAL_SET(9) /* passthrough mode */
  354. #define EOF_IS INTERNAL_SET(10) /* synthetic EOF */
  355. #define GOODTIME_IS INTERNAL_SET(11) /* time good even if no pos fix */
  356. #define DATA_IS ~(ONLINE_SET|PACKET_SET|CLEAR_IS|REPORT_IS)
  357. typedef unsigned int driver_mask_t;
  358. #define DRIVER_NOFLAGS 0x00000000u
  359. #define DRIVER_STICKY 0x00000001u
  360. /*
  361. * True if a device type is non-null and has control methods.
  362. */
  363. #define CONTROLLABLE(dp) (((dp) != NULL) && \
  364. ((dp)->speed_switcher != NULL \
  365. || (dp)->mode_switcher != NULL \
  366. || (dp)->rate_switcher != NULL))
  367. /*
  368. * True if a driver selection of it should be sticky.
  369. */
  370. #define STICKY(dp) ((dp) != NULL && ((dp)->flags & DRIVER_STICKY) != 0)
  371. struct gps_type_t {
  372. /* GPS method table, describes how to talk to a particular GPS type */
  373. char *type_name;
  374. int packet_type;
  375. driver_mask_t flags; /* reserved for expansion */
  376. char *trigger;
  377. int channels;
  378. bool (*probe_detect)(struct gps_device_t *session);
  379. ssize_t (*get_packet)(struct gps_device_t *session);
  380. gps_mask_t (*parse_packet)(struct gps_device_t *session);
  381. ssize_t (*rtcm_writer)(struct gps_device_t *session,
  382. const char *rtcmbuf, size_t rtcmbytes);
  383. void (*init_query)(struct gps_device_t *session);
  384. void (*event_hook)(struct gps_device_t *session, event_t event);
  385. bool (*speed_switcher)(struct gps_device_t *session,
  386. speed_t speed, char parity, int stopbits);
  387. void (*mode_switcher)(struct gps_device_t *session, int mode);
  388. bool (*rate_switcher)(struct gps_device_t *session, double rate);
  389. timespec_t min_cycle;
  390. ssize_t (*control_send)(struct gps_device_t *session,
  391. char *buf, size_t buflen);
  392. double (*time_offset)(struct gps_device_t *session);
  393. };
  394. /*
  395. * Each input source has an associated type. This is currently used in two
  396. * ways:
  397. *
  398. * (1) To determine if we require that gpsd be the only process opening a
  399. * device. We make an exception for PTYs because the master side has to be
  400. * opened by test code.
  401. *
  402. * (2) To determine whether it's safe to send wakeup strings. These are
  403. * required on some unusual RS-232 devices (such as the TNT compass and
  404. * Thales/Ashtech GPSes) but should not be shipped to unidentified USB
  405. * or Bluetooth devices as we don't even know in advance those are GPSes;
  406. * they might not cope well.
  407. *
  408. * Where it says "case detected but not used" it means that we can identify
  409. * a source type but no behavior is yet contingent on it. A "discoverable"
  410. * device is one for which there is discoverable metadata such as a
  411. * vendor/product ID.
  412. *
  413. * We should never see a block device; that would indicate a serious error
  414. * in command-line usage or the hotplug system.
  415. */
  416. typedef enum {source_unknown,
  417. source_blockdev, /* block devices can't be GPS sources */
  418. source_rs232, /* potential GPS source, not discoverable */
  419. source_usb, /* potential GPS source, discoverable */
  420. source_bluetooth, /* potential GPS source, discoverable */
  421. source_can, /* potential GPS source, fixed CAN format */
  422. source_pty, /* PTY: we don't require exclusive access */
  423. source_tcp, /* TCP/IP stream: case detected but not used */
  424. source_udp, /* UDP stream: case detected but not used */
  425. source_gpsd, /* Remote gpsd instance over TCP/IP */
  426. source_pps, /* PPS-only device, such as /dev/ppsN */
  427. source_pipe, /* Unix FIFO; don't use blocking I/O */
  428. } sourcetype_t;
  429. /*
  430. * Each input source also has an associated service type.
  431. */
  432. typedef enum {service_unknown,
  433. service_sensor,
  434. service_dgpsip,
  435. service_ntrip,
  436. } servicetype_t;
  437. /*
  438. * Private state information about an NTRIP stream.
  439. */
  440. struct ntrip_stream_t
  441. {
  442. char mountpoint[101];
  443. char credentials[128];
  444. char authStr[128];
  445. char url[256];
  446. char port[32]; /* in my /etc/services 16 was the longest */
  447. bool set; /* found and set */
  448. enum
  449. {
  450. fmt_rtcm2,
  451. fmt_rtcm2_0,
  452. fmt_rtcm2_1,
  453. fmt_rtcm2_2,
  454. fmt_rtcm2_3,
  455. fmt_rtcm3_0,
  456. fmt_rtcm3_1,
  457. fmt_rtcm3_2,
  458. fmt_rtcm3_3,
  459. fmt_unknown
  460. } format;
  461. int carrier;
  462. double latitude;
  463. double longitude;
  464. int nmea;
  465. enum
  466. { cmp_enc_none, cmp_enc_unknown } compr_encryp;
  467. enum
  468. { auth_none, auth_basic, auth_digest, auth_unknown } authentication;
  469. int fee;
  470. int bitrate;
  471. };
  472. struct gps_device_t {
  473. /* session object, encapsulates all global state */
  474. struct gps_data_t gpsdata;
  475. const struct gps_type_t *device_type;
  476. unsigned int driver_index; /* numeric index of current driver */
  477. unsigned int drivers_identified; /* bitmask; what drivers have we seen? */
  478. unsigned int cfg_stage; /* configuration stage counter */
  479. unsigned int cfg_step; /* configuration step counter */
  480. const struct gps_type_t *last_controller;
  481. struct gps_context_t *context;
  482. sourcetype_t sourcetype;
  483. servicetype_t servicetype;
  484. int mode;
  485. struct termios ttyset, ttyset_old;
  486. unsigned int baudindex;
  487. int saved_baud;
  488. struct gps_lexer_t lexer;
  489. int badcount;
  490. int subframe_count;
  491. /* firmware version or subtype ID, 96 too small for ZED-F9 */
  492. char subtype[128];
  493. char subtype1[128];
  494. time_t opentime;
  495. time_t releasetime;
  496. bool zerokill;
  497. time_t reawake;
  498. timespec_t sor; /* time start of this reporting cycle */
  499. unsigned long chars; /* characters in the cycle */
  500. bool ship_to_ntpd;
  501. volatile struct shmTime *shm_clock;
  502. volatile struct shmTime *shm_pps;
  503. int chronyfd; /* for talking to chrony */
  504. volatile struct pps_thread_t pps_thread;
  505. /*
  506. * msgbuf needs to hold the hex decode of inbuffer
  507. * so msgbuf must be 2x the size of inbuffer
  508. */
  509. char msgbuf[MAX_PACKET_LENGTH*4+1]; /* command message buffer for sends */
  510. size_t msgbuflen;
  511. int observed; /* which packet type`s have we seen? */
  512. bool cycle_end_reliable; /* does driver signal REPORT_MASK */
  513. int fixcnt; /* count of fixes from this device */
  514. struct gps_fix_t newdata; /* where drivers put their data */
  515. struct gps_fix_t lastfix; /* not quite yet ready for oldfix */
  516. struct gps_fix_t oldfix; /* previous fix for error modeling */
  517. #ifdef NMEA0183_ENABLE
  518. struct {
  519. unsigned short sats_used[MAXCHANNELS];
  520. int part, await; /* for tracking GSV parts */
  521. struct tm date; /* date part of last sentence time */
  522. timespec_t subseconds; /* subsec part of last sentence time */
  523. // pointers to each field in fieldcopy. Each is NUL terminated.
  524. char *field[NMEA_MAX_FLD];
  525. unsigned char fieldcopy[NMEA_MAX+1]; // a copy of the current sentence
  526. /* detect receivers that ship GGA with non-advancing timestamp */
  527. bool latch_mode;
  528. char last_gga_timestamp[16];
  529. char last_gga_talker;
  530. /* GSV stuff */
  531. bool seen_bdgsv;
  532. bool seen_gagsv;
  533. bool seen_glgsv;
  534. bool seen_gpgsv;
  535. bool seen_qzss;
  536. char last_gsv_talker;
  537. unsigned char last_gsv_sigid; /* NMEA 4.1 */
  538. /* GSA stuff */
  539. bool seen_glgsa;
  540. bool seen_gngsa;
  541. bool seen_bdgsa;
  542. bool seen_gagsa;
  543. char last_gsa_talker;
  544. /*
  545. * State for the cycle-tracking machinery.
  546. * The reason these timestamps are separate from the
  547. * general sentence timestamps is that we can
  548. * use the minutes and seconds part of a sentence
  549. * with an incomplete timestamp (like GGA) for
  550. * end-cycle recognition, even if we don't have a previous
  551. * RMC or ZDA that lets us get full time from it.
  552. */
  553. timespec_t this_frac_time, last_frac_time;
  554. bool latch_frac_time;
  555. int lasttag; /* index into nmea_phrase[] */
  556. // 80 > number of used entries in nmea_phrase[]
  557. #define NMEA_NUM 80
  558. // bit map into nmea_phrase[], +1 to shut up coverity
  559. bool cycle_enders[NMEA_NUM + 1];
  560. bool cycle_continue;
  561. } nmea;
  562. #endif /* NMEA0183_ENABLE */
  563. /*
  564. * The rest of this structure is driver-specific private storage.
  565. * Only put a driver's scratch storage in here if it is never
  566. * implemented on the same device that supports any mode already
  567. * in this union; otherwise bad things might happen after a device
  568. * mode switch.
  569. */
  570. union {
  571. #ifdef BINARY_ENABLE
  572. #ifdef GEOSTAR_ENABLE
  573. struct {
  574. unsigned int physical_port;
  575. } geostar;
  576. #endif /* GEOSTAR_ENABLE */
  577. #ifdef GREIS_ENABLE
  578. struct {
  579. uint32_t rt_tod; // RT message time of day (modulo 1 day)
  580. bool seen_rt; /* true if seen RT message */
  581. bool seen_uo; /* true if seen UO message */
  582. bool seen_si; /* true if seen SI message */
  583. bool seen_az; /* true if seen AZ message */
  584. bool seen_ec; /* true if seen EC message */
  585. bool seen_el; /* true if seen EL message */
  586. /* true if seen a raw measurement message */
  587. bool seen_raw;
  588. } greis;
  589. #endif /* GREIS_ENABLE */
  590. #ifdef SIRF_ENABLE
  591. struct {
  592. unsigned int need_ack; /* if NZ we're awaiting ACK */
  593. unsigned int driverstate; /* for private use */
  594. #define SIRF_LT_231 0x01 /* SiRF at firmware rev < 231 */
  595. #define SIRF_EQ_231 0x02 /* SiRF at firmware rev == 231 */
  596. #define SIRF_GE_232 0x04 /* SiRF at firmware rev >= 232 */
  597. #define UBLOX 0x08 /* u-blox firmware with packet 0x62 */
  598. unsigned long satcounter;
  599. unsigned int time_seen;
  600. unsigned char lastid; /* ID with last timestamp seen */
  601. #define TIME_SEEN_UTC_2 0x08 /* Seen UTC time variant 2? */
  602. /* fields from Navigation Parameters message */
  603. bool nav_parameters_seen; /* have we seen one? */
  604. unsigned char altitude_hold_mode;
  605. unsigned char altitude_hold_source;
  606. int16_t altitude_source_input;
  607. unsigned char degraded_mode;
  608. unsigned char degraded_timeout;
  609. unsigned char dr_timeout;
  610. unsigned char track_smooth_mode;
  611. /* fields from DGPS Status */
  612. unsigned int dgps_source;
  613. #define SIRF_DGPS_SOURCE_NONE 0 /* No DGPS correction type selected */
  614. #define SIRF_DGPS_SOURCE_SBAS 1 /* SBAS */
  615. #define SIRF_DGPS_SOURCE_SERIAL 2 /* RTCM corrections */
  616. #define SIRF_DGPS_SOURCE_BEACON 3 /* Beacon corrections */
  617. #define SIRF_DGPS_SOURCE_SOFTWARE 4 /* Software API corrections */
  618. } sirf;
  619. #endif /* SIRF_ENABLE */
  620. #ifdef SUPERSTAR2_ENABLE
  621. struct {
  622. time_t last_iono;
  623. } superstar2;
  624. #endif /* SUPERSTAR2_ENABLE */
  625. #ifdef TSIP_ENABLE
  626. struct {
  627. unsigned short sats_used[MAXCHANNELS];
  628. /* Super Packet mode requested.
  629. * 0 = None, 1 = old superpacket, 2 = new superpacket (SMT 360) */
  630. uint8_t superpkt;
  631. uint8_t machine_id; // from 0x4b
  632. uint16_t hardware_code; // from 0x1c-83
  633. time_t last_41; /* Timestamps for packet requests */
  634. time_t last_48;
  635. time_t last_5c;
  636. time_t last_6d;
  637. time_t last_46;
  638. time_t req_compact;
  639. unsigned int stopbits; /* saved RS232 link parameter */
  640. char parity;
  641. int subtype; // hardware ID, sort of
  642. #define TSIP_UNKNOWN 0
  643. #define TSIP_ACUTIME_GOLD 3001
  644. #define TSIP_RESSMT360 3023
  645. #define TSIP_ICMSMT360 3026
  646. #define TSIP_RES36017x22 3031
  647. uint8_t alt_is_msl; // 0 if alt is HAE, 1 if MSL
  648. timespec_t last_tow; // used to find cycle start
  649. int last_chan_seen; // from 0x5c or 0x5d
  650. } tsip;
  651. #endif /* TSIP_ENABLE */
  652. #ifdef GARMIN_ENABLE /* private housekeeping stuff for the Garmin driver */
  653. struct {
  654. unsigned char Buffer[4096+12]; /* Garmin packet buffer */
  655. size_t BufferLen; /* current GarminBuffer Length */
  656. } garmin;
  657. #endif /* GARMIN_ENABLE */
  658. #ifdef ZODIAC_ENABLE /* private housekeeping stuff for the Zodiac driver */
  659. struct {
  660. unsigned short sn; /* packet sequence number */
  661. /*
  662. * Zodiac chipset channel status from PRWIZCH. Keep it so
  663. * raw-mode translation of Zodiac binary protocol can send
  664. * it up to the client.
  665. */
  666. #define ZODIAC_CHANNELS 12
  667. unsigned int Zs[ZODIAC_CHANNELS]; /* satellite PRNs */
  668. unsigned int Zv[ZODIAC_CHANNELS]; /* signal values (0-7) */
  669. } zodiac;
  670. #endif /* ZODIAC_ENABLE */
  671. #ifdef UBLOX_ENABLE
  672. struct {
  673. unsigned char port_id;
  674. unsigned char sbas_in_use;
  675. unsigned char protver; /* u-blox protocol version */
  676. unsigned int last_msgid; /* last class/ID */
  677. /* FIXME: last_time set but never used? */
  678. timespec_t last_time; /* time of last_msgid */
  679. unsigned int end_msgid; /* cycle ender class/ID */
  680. /* iTOW, and last_iTOW, in ms, used for cycle end detect. */
  681. int64_t iTOW;
  682. int64_t last_iTOW;
  683. } ubx;
  684. #endif /* UBLOX_ENABLE */
  685. #ifdef NAVCOM_ENABLE
  686. struct {
  687. uint8_t physical_port;
  688. bool warned;
  689. } navcom;
  690. #endif /* NAVCOM_ENABLE */
  691. #ifdef ONCORE_ENABLE
  692. struct {
  693. #define ONCORE_VISIBLE_CH 12
  694. int visible;
  695. int PRN[ONCORE_VISIBLE_CH]; /* PRNs of satellite */
  696. int elevation[ONCORE_VISIBLE_CH]; /* elevation of satellite */
  697. int azimuth[ONCORE_VISIBLE_CH]; /* azimuth */
  698. #define ONCORE_POS_HOLD_MODE_UNKNOWN 0
  699. #define ONCORE_POS_HOLD_MODE_OFF 1
  700. #define ONCORE_POS_HOLD_MODE_ON 2
  701. #define ONCORE_POS_HOLD_MODE_SURVEYING 3
  702. int pos_hold_mode;
  703. int pps_offset_ns;
  704. } oncore;
  705. #endif /* ONCORE_ENABLE */
  706. #ifdef NMEA2000_ENABLE
  707. struct {
  708. unsigned int can_msgcnt;
  709. unsigned int can_net;
  710. unsigned int unit;
  711. bool unit_valid;
  712. int mode;
  713. unsigned int mode_valid;
  714. unsigned int idx;
  715. // size_t ptr;
  716. size_t fast_packet_len;
  717. int type;
  718. void *workpgn;
  719. void *pgnlist;
  720. unsigned char sid[8];
  721. } nmea2000;
  722. #endif /* NMEA2000_ENABLE */
  723. /*
  724. * This is not conditionalized on RTCM104_ENABLE because we need to
  725. * be able to build gpsdecode even when RTCM support is not
  726. * configured in the daemon. It doesn't take up extra space.
  727. */
  728. struct {
  729. /* ISGPS200 decoding */
  730. bool locked;
  731. int curr_offset;
  732. isgps30bits_t curr_word;
  733. isgps30bits_t buf[RTCM2_WORDS_MAX];
  734. unsigned int bufindex;
  735. } isgps;
  736. #endif /* BINARY_ENABLE */
  737. #ifdef AIVDM_ENABLE
  738. struct {
  739. struct aivdm_context_t context[AIVDM_CHANNELS];
  740. char ais_channel;
  741. } aivdm;
  742. #endif /* AIVDM_ENABLE */
  743. } driver;
  744. /*
  745. * State of an NTRIP connection. We don't want to zero this on every
  746. * activation, otherwise the connection state will get lost. Information
  747. * in this substructure is only valid if servicetype is service_ntrip.
  748. */
  749. struct {
  750. /* state information about the stream */
  751. struct ntrip_stream_t stream;
  752. /* state information about our response parsing */
  753. enum {
  754. ntrip_conn_init,
  755. ntrip_conn_sent_probe,
  756. ntrip_conn_sent_get,
  757. ntrip_conn_established,
  758. ntrip_conn_err
  759. } conn_state; /* connection state for multi stage connect */
  760. bool works; // marks a working connection, so we try to reconnect once
  761. bool sourcetable_parse; /* have we read the sourcetable header? */
  762. } ntrip;
  763. /* State of a DGPSIP connection */
  764. struct {
  765. bool reported;
  766. } dgpsip;
  767. };
  768. /*
  769. * These are used where a file descriptor of 0 or greater indicates open device.
  770. */
  771. #define UNALLOCATED_FD -1 /* this slot is available for reallocation */
  772. #define PLACEHOLDING_FD -2 /* this slot *not* available for reallocation */
  773. /* logging levels */
  774. #define LOG_ERROR -1 /* errors, display always */
  775. #define LOG_SHOUT 0 /* not an error but we should always see it */
  776. #define LOG_WARN 1 /* not errors but may indicate a problem */
  777. #define LOG_CLIENT 2 /* log JSON reports to clients */
  778. #define LOG_INF 3 /* key informative messages */
  779. #define LOG_PROG 4 /* progress messages */
  780. #define LOG_IO 5 /* IO to and from devices */
  781. #define LOG_DATA 6 /* log data management messages */
  782. #define LOG_SPIN 7 /* logging for catching spin bugs */
  783. #define LOG_RAW 8 /* raw low-level I/O */
  784. #define ISGPS_ERRLEVEL_BASE LOG_RAW
  785. #define IS_HIGHEST_BIT(v,m) (v & ~((m<<1)-1))==0
  786. /* driver helper functions */
  787. extern void isgps_init(struct gps_lexer_t *);
  788. enum isgpsstat_t isgps_decode(struct gps_lexer_t *,
  789. bool (*preamble_match)(isgps30bits_t *),
  790. bool (*length_check)(struct gps_lexer_t *),
  791. size_t,
  792. unsigned int);
  793. extern unsigned int isgps_parity(isgps30bits_t);
  794. extern void isgps_output_magnavox(const isgps30bits_t *, unsigned int, FILE *);
  795. extern enum isgpsstat_t rtcm2_decode(struct gps_lexer_t *, unsigned int);
  796. extern void json_rtcm2_dump(const struct rtcm2_t *,
  797. const char *, char[], size_t);
  798. extern void rtcm2_unpack(struct gps_device_t *, struct rtcm2_t *, char *);
  799. extern void json_rtcm3_dump(const struct rtcm3_t *,
  800. const char *, char[], size_t);
  801. extern void rtcm3_unpack(const struct gps_context_t *,
  802. struct rtcm3_t *, char *);
  803. /* here are the available GPS drivers */
  804. extern const struct gps_type_t **gpsd_drivers;
  805. /* gpsd library internal prototypes */
  806. extern gps_mask_t generic_parse_input(struct gps_device_t *);
  807. extern ssize_t generic_get(struct gps_device_t *);
  808. extern gps_mask_t nmea_parse(char *, struct gps_device_t *);
  809. extern ssize_t nmea_write(struct gps_device_t *, char *, size_t);
  810. extern ssize_t nmea_send(struct gps_device_t *, const char *, ... );
  811. extern void nmea_add_checksum(char *);
  812. extern gps_mask_t sirf_parse(struct gps_device_t *, unsigned char *, size_t);
  813. extern gps_mask_t evermore_parse(struct gps_device_t *, unsigned char *,
  814. size_t);
  815. extern gps_mask_t navcom_parse(struct gps_device_t *, unsigned char *, size_t);
  816. extern gps_mask_t garmin_ser_parse(struct gps_device_t *);
  817. extern gps_mask_t garmintxt_parse(struct gps_device_t *);
  818. extern gps_mask_t aivdm_parse(struct gps_device_t *);
  819. extern bool netgnss_uri_check(char *);
  820. extern int netgnss_uri_open(struct gps_device_t *, char *);
  821. extern void netgnss_report(struct gps_context_t *,
  822. struct gps_device_t *,
  823. struct gps_device_t *);
  824. extern void netgnss_autoconnect(struct gps_context_t *, double, double);
  825. extern int dgpsip_open(struct gps_device_t *, const char *);
  826. extern void dgpsip_report(struct gps_context_t *,
  827. struct gps_device_t *,
  828. struct gps_device_t *);
  829. extern void dgpsip_autoconnect(struct gps_context_t *,
  830. double, double, const char *);
  831. extern int ntrip_open(struct gps_device_t *, char *);
  832. extern void ntrip_report(struct gps_context_t *,
  833. struct gps_device_t *,
  834. struct gps_device_t *);
  835. extern void gpsd_tty_init(struct gps_device_t *);
  836. extern int gpsd_serial_open(struct gps_device_t *);
  837. extern bool gpsd_set_raw(struct gps_device_t *);
  838. extern ssize_t gpsd_serial_write(struct gps_device_t *,
  839. const char *, const size_t);
  840. extern bool gpsd_next_hunt_setting(struct gps_device_t *);
  841. extern int gpsd_switch_driver(struct gps_device_t *, char *);
  842. extern void gpsd_set_speed(struct gps_device_t *, speed_t, char, unsigned int);
  843. extern speed_t gpsd_get_speed(const struct gps_device_t *);
  844. extern speed_t gpsd_get_speed_old(const struct gps_device_t *);
  845. extern int gpsd_get_stopbits(const struct gps_device_t *);
  846. extern char gpsd_get_parity(const struct gps_device_t *);
  847. extern void gpsd_assert_sync(struct gps_device_t *);
  848. extern void gpsd_close(struct gps_device_t *);
  849. extern ssize_t gpsd_write(struct gps_device_t *, const char *, const size_t);
  850. extern void gpsd_time_init(struct gps_context_t *, time_t);
  851. extern void gpsd_set_century(struct gps_device_t *);
  852. extern timespec_t gpsd_gpstime_resolv(struct gps_device_t *, unsigned,
  853. timespec_t);
  854. extern timespec_t gpsd_utc_resolve(struct gps_device_t *);
  855. extern void gpsd_century_update(struct gps_device_t *, int);
  856. extern void gpsd_zero_satellites(struct gps_data_t *sp);
  857. extern gps_mask_t gpsd_interpret_subframe(struct gps_device_t *, unsigned int,
  858. uint32_t[]);
  859. extern gps_mask_t gpsd_interpret_subframe_raw(struct gps_device_t *,
  860. unsigned int, uint32_t[]);
  861. extern const char *gpsd_hexdump(char *, size_t, char *, size_t);
  862. extern const char *gpsd_packetdump(char *, size_t, char *, size_t);
  863. extern const char *gpsd_prettydump(struct gps_device_t *);
  864. # ifdef __cplusplus
  865. extern "C" {
  866. # endif
  867. extern int gpsd_hexpack(const char *, char *, size_t);
  868. # ifdef __cplusplus
  869. }
  870. # endif
  871. extern ssize_t hex_escapes(char *, const char *);
  872. extern void gpsd_position_fix_dump(struct gps_device_t *,
  873. char[], size_t);
  874. extern void gpsd_clear_data(struct gps_device_t *);
  875. extern socket_t netlib_connectsock(int, const char *, const char *,
  876. const char *);
  877. extern socket_t netlib_localsocket(const char *, int);
  878. extern const char *netlib_errstr(const int);
  879. extern char *netlib_sock2ip(socket_t);
  880. extern void nmea_tpv_dump(struct gps_device_t *, char[], size_t);
  881. extern void nmea_sky_dump(struct gps_device_t *, char[], size_t);
  882. extern void nmea_subframe_dump(struct gps_device_t *, char[], size_t);
  883. extern void nmea_ais_dump(struct gps_device_t *, char[], size_t);
  884. extern unsigned int ais_binary_encode(struct ais_t *ais, unsigned char *bits,
  885. int flag);
  886. extern void ntp_latch(struct gps_device_t *device, struct timedelta_t *td);
  887. extern void ntpshm_context_init(struct gps_context_t *);
  888. extern void ntpshm_session_init(struct gps_device_t *);
  889. extern int ntpshm_put(struct gps_device_t *, volatile struct shmTime *,
  890. struct timedelta_t *);
  891. extern void ntpshm_link_deactivate(struct gps_device_t *);
  892. extern void ntpshm_link_activate(struct gps_device_t *);
  893. extern void errout_reset(struct gpsd_errout_t *errout);
  894. extern void gpsd_acquire_reporting_lock(void);
  895. extern void gpsd_release_reporting_lock(void);
  896. extern gps_mask_t ecef_to_wgs84fix(struct gps_fix_t *,
  897. double, double, double,
  898. double, double, double);
  899. extern void clear_dop(struct dop_t *);
  900. /* shmexport.c */
  901. #define GPSD_SHM_KEY 0x47505344 /* "GPSD" */
  902. struct shmexport_t
  903. {
  904. int bookend1;
  905. struct gps_data_t gpsdata;
  906. int bookend2;
  907. };
  908. extern bool shm_acquire(struct gps_context_t *);
  909. extern void shm_release(struct gps_context_t *);
  910. extern void shm_update(struct gps_context_t *, struct gps_data_t *);
  911. /* dbusexport.c */
  912. #if defined(DBUS_EXPORT_ENABLE)
  913. int initialize_dbus_connection (void);
  914. void send_dbus_fix (struct gps_device_t* channel);
  915. #endif /* defined(DBUS_EXPORT_ENABLE) */
  916. /* srecord.c */
  917. extern void hexdump(size_t, unsigned char *, unsigned char *);
  918. extern unsigned char sr_sum(unsigned int, unsigned int, unsigned char *);
  919. extern int bin2srec(unsigned int, unsigned int, unsigned int,
  920. unsigned char *, unsigned char *);
  921. extern int srec_hdr(unsigned int, unsigned char *, unsigned char *);
  922. extern int srec_fin(unsigned int, unsigned char *);
  923. extern unsigned char hc(unsigned char);
  924. /* a BSD transplant */
  925. int b64_ntop(unsigned char const *src, size_t srclength, char *target,
  926. size_t targsize);
  927. /* application interface */
  928. extern void gps_context_init(struct gps_context_t *context,
  929. const char *label);
  930. extern void gpsd_init(struct gps_device_t *,
  931. struct gps_context_t *,
  932. const char *);
  933. extern void gpsd_clear(struct gps_device_t *);
  934. extern int parse_uri_dest(char *s, char **host, char **service, char **device);
  935. extern int gpsd_open(struct gps_device_t *);
  936. #define O_CONTINUE 0
  937. #define O_PROBEONLY 1
  938. #define O_OPTIMIZE 2
  939. extern int gpsd_activate(struct gps_device_t *, const int);
  940. extern void gpsd_deactivate(struct gps_device_t *);
  941. #define AWAIT_GOT_INPUT 1
  942. #define AWAIT_NOT_READY 0
  943. #define AWAIT_FAILED -1
  944. extern int gpsd_await_data(fd_set *,
  945. fd_set *,
  946. const int,
  947. fd_set *,
  948. struct gpsd_errout_t *errout);
  949. extern gps_mask_t gpsd_poll(struct gps_device_t *);
  950. #define DEVICE_EOF -3
  951. #define DEVICE_ERROR -2
  952. #define DEVICE_UNREADY -1
  953. #define DEVICE_READY 1
  954. #define DEVICE_UNCHANGED 0
  955. extern int gpsd_multipoll(const bool,
  956. struct gps_device_t *,
  957. void (*)(struct gps_device_t *, gps_mask_t),
  958. float reawake_time);
  959. extern void gpsd_wrap(struct gps_device_t *);
  960. extern bool gpsd_add_device(const char *device_name, bool flag_nowait);
  961. extern const char *gpsd_maskdump(gps_mask_t);
  962. /* exceptional driver methods */
  963. extern bool ubx_write(struct gps_device_t *, unsigned int, unsigned int,
  964. unsigned char *, size_t);
  965. extern bool ais_binary_decode(const struct gpsd_errout_t *errout,
  966. struct ais_t *ais,
  967. const unsigned char *, size_t,
  968. struct ais_type24_queue_t *);
  969. void gpsd_labeled_report(const int, const int,
  970. const char *, const char *, va_list);
  971. // do not call gpsd_log() directly, use GPSD_LOG() to save a lot of cpu time
  972. PRINTF_FUNC(3, 4) void gpsd_log(const int, const struct gpsd_errout_t *,
  973. const char *, ...);
  974. /*
  975. * GPSD_LOG() is the new one debug logger to rule them all.
  976. *
  977. * The calling convention is not attractive:
  978. * GPSD_LOG(debuglevel, (fmt, ...));
  979. * GPSD_LOG(2, ("this will appear on stdout if debug >= %d\n", 2));
  980. *
  981. * This saves significant pushing, popping, hexification, etc. when
  982. * the debug level does not require it.
  983. */
  984. #define GPSD_LOG(lvl, eo, ...) \
  985. do { \
  986. if ((eo)->debug >= (lvl)) \
  987. gpsd_log(lvl, eo, __VA_ARGS__); \
  988. } while (0)
  989. #define NITEMS(x) ((int) (sizeof(x) / sizeof(x[0]) + COMPILE_CHECK_IS_ARRAY(x)))
  990. /*
  991. * C99 requires NAN to be defined if the implementation supports quiet
  992. * NANs. At one point, it seems Solaris did not define NAN; it is not
  993. * clear if this is still true.
  994. */
  995. #ifndef NAN
  996. #define NAN (0.0f/0.0f)
  997. #endif
  998. #if !defined(HAVE_CFMAKERAW)
  999. /*
  1000. * POSIX does not specify cfmakeraw, but it is pretty common. We
  1001. * provide an implementation in serial.c for systems that lack it.
  1002. */
  1003. void cfmakeraw(struct termios *);
  1004. #endif /* !defined(HAVE_CFMAKERAW) */
  1005. #define DEVICEHOOKPATH "/" SYSCONFDIR "/gpsd/device-hook"
  1006. # ifdef __cplusplus
  1007. }
  1008. # endif
  1009. #endif /* _GPSD_H_ */
  1010. // Local variables:
  1011. // mode: c
  1012. // end:
  1013. // vim: set expandtab shiftwidth=4