gpsd.h 39 KB

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