Devuan fork of gpsd
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1072 lines
39 KiB

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