cleanup specfile for packaging
[profile/ivi/gpsd.git] / gpsd.h-tail
1 /* Feature configuration switches end here
2  *
3  * This file is Copyright (c) 2010 by the GPSD project
4  * BSD terms apply: see the file COPYING in the distribution root for details.
5  */
6 #endif /* GPSD_CONFIG_H */
7
8 #ifdef HAVE_TERMIOS_H
9 #include <termios.h>
10 #endif
11 #ifdef HAVE_SYS_TERMIOS_H
12 #include <sys/termios.h>
13 #endif
14 #include "gps.h"
15
16 #ifdef _WIN32
17 typedef unsigned int speed_t;
18 #endif
19
20 /*
21  * Constants for the VERSION response
22  * 3.1: Base JSON version
23  * 3.2: Added POLL command and response
24  * 3.3: AIS app_id split into DAC and FID
25  */
26 #define GPSD_PROTO_MAJOR_VERSION        3       /* bump on incompatible changes */
27 #define GPSD_PROTO_MINOR_VERSION        3       /* bump on compatible changes */
28
29 /* Some internal capabilities depend on which drivers we're compiling. */
30 #ifdef EARTHMATE_ENABLE
31 #define ZODIAC_ENABLE   
32 #endif
33 #if defined(ZODIAC_ENABLE) || defined(SIRF_ENABLE) || defined(GARMIN_ENABLE) || defined(TSIP_ENABLE) || defined(EVERMORE_ENABLE) || defined(ITRAX_ENABLE) || defined(UBX_ENABLE) || defined(SUPERSTAR2_ENABLE) || defined(ONCORE_ENABLE)
34 #define BINARY_ENABLE   
35 #endif
36 #if defined(TRIPMATE_ENABLE) || defined(BINARY_ENABLE)
37 #define NON_NMEA_ENABLE 
38 #endif
39 #if defined(TNT_ENABLE) || defined(OCEANSERVER_ENABLE)
40 #define COMPASS_ENABLE  
41 #endif
42
43 /* First, declarations for the packet layer... */
44
45 /*
46  * For NMEA-conforming receivers this is supposed to be 82, but
47  * some receivers (TN-200, GSW 2.3.2) emit oversized sentences.
48  * The current hog champion is the Trimble BX-960 receiver, which
49  * emits a 91-character GGA message.
50  */
51 #define NMEA_MAX        91              /* max length of NMEA sentence */
52 #define NMEA_BIG_BUF    (2*NMEA_MAX+1)  /* longer than longest NMEA sentence */
53
54 /* a few bits of ISGPS magic */
55 enum isgpsstat_t {
56     ISGPS_NO_SYNC, ISGPS_SYNC, ISGPS_SKIP, ISGPS_MESSAGE,
57 };
58 #define ISGPS_ERRLEVEL_BASE     5
59
60 #define RTCM_MAX        (RTCM2_WORDS_MAX * sizeof(isgps30bits_t))
61
62 /*
63  * The packet buffers need to be as long than the longest packet we
64  * expect to see in any protocol, because we have to be able to hold
65  * an entire packet for checksumming...
66  * First we thought it had to be big enough for a SiRF Measured Tracker
67  * Data packet (188 bytes). Then it had to be big enough for a UBX SVINFO
68  * packet (206 bytes). Now it turns out that a couple of ITALK messages are
69  * over 512 bytes. I know we like verbose output, but this is ridiculous.
70  */
71 #define MAX_PACKET_LENGTH       516     /* 7 + 506 + 3 */
72
73 struct gps_packet_t {
74     /* packet-getter internals */
75     int type;
76 #define BAD_PACKET              -1
77 #define COMMENT_PACKET          0
78 #define NMEA_PACKET             1
79 #define AIVDM_PACKET            2
80 #define GARMINTXT_PACKET        3
81 #define MAX_TEXTUAL_TYPE        3       /* increment this as necessary */
82 #define SIRF_PACKET             4
83 #define ZODIAC_PACKET           5
84 #define TSIP_PACKET             6
85 #define EVERMORE_PACKET         7
86 #define ITALK_PACKET            8
87 #define GARMIN_PACKET           9
88 #define NAVCOM_PACKET           10
89 #define UBX_PACKET              11
90 #define SUPERSTAR2_PACKET       12
91 #define ONCORE_PACKET           13
92 #define MAX_PACKET_TYPE         13      /* increment this as necessary */
93 #define RTCM2_PACKET            14
94 #define RTCM3_PACKET            15
95 #define TEXTUAL_PACKET_TYPE(n)  (((n)>=NMEA_PACKET) && ((n)<=MAX_TEXTUAL_TYPE))
96 #define GPS_PACKET_TYPE(n)      (((n)>=NMEA_PACKET) && ((n)<=MAX_PACKET_TYPE))
97 #define LOSSLESS_PACKET_TYPE(n) (((n)>=RTCM2_PACKET) && ((n)<=RTCM3_PACKET))
98 #define PACKET_TYPEMASK(n)      (1 << (n))
99 #define GPS_TYPEMASK    (((2<<(MAX_PACKET_TYPE+1))-1) &~ PACKET_TYPEMASK(COMMENT_PACKET))
100     unsigned int state;
101     size_t length;
102     unsigned char inbuffer[MAX_PACKET_LENGTH*2+1];
103     size_t inbuflen;
104     unsigned /*@observer@*/char *inbufptr;
105     /* outbuffer needs to be able to hold 4 GPGSV records at once */
106     unsigned char outbuffer[MAX_PACKET_LENGTH*2+1];
107     size_t outbuflen;
108     unsigned long char_counter;         /* count characters processed */
109     unsigned long retry_counter;        /* count sniff retries */
110     unsigned counter;                   /* packets since last driver switch */
111     /*
112      * This is not conditionalized on RTCM104_ENABLE because we need to
113      * be able to build gpsdecode even when RTCM support is not
114      * configured in the daemon.
115      */
116     struct {
117         /* ISGPS200 decoding */
118         bool            locked;
119         int             curr_offset;
120         isgps30bits_t   curr_word;
121         isgps30bits_t   buf[RTCM2_WORDS_MAX];
122         unsigned int    bufindex;
123     } isgps;
124 };
125
126 extern void packet_init(/*@out@*/struct gps_packet_t *);
127 extern void packet_reset(/*@out@*/struct gps_packet_t *);
128 extern void packet_pushback(struct gps_packet_t *);
129 extern void packet_parse(struct gps_packet_t *);
130 extern ssize_t packet_get(int, struct gps_packet_t *);
131 extern int packet_sniff(struct gps_packet_t *);
132 #define packet_buffered_input(lexer) ((lexer)->inbuffer + (lexer)->inbuflen - (lexer)->inbufptr)
133
134 extern void isgps_init(/*@out@*/struct gps_packet_t *);
135 enum isgpsstat_t isgps_decode(struct gps_packet_t *, 
136                               bool (*preamble_match)(isgps30bits_t *),
137                               bool (*length_check)(struct gps_packet_t *),
138                               size_t,
139                               unsigned int);
140 extern unsigned int isgps_parity(isgps30bits_t);
141 extern void isgps_output_magnavox(const isgps30bits_t *, unsigned int, FILE *);
142
143 extern enum isgpsstat_t rtcm2_decode(struct gps_packet_t *, unsigned int);
144 extern void rtcm2_sager_dump(const struct rtcm2_t *, /*@out@*/char[], size_t);
145 extern void rtcm2_json_dump(const struct rtcm2_t *, /*@out@*/char[], size_t);
146 extern int rtcm2_undump(/*@out@*/struct rtcm2_t *, char *);
147 extern void rtcm2_unpack(/*@out@*/struct rtcm2_t *, char *);
148 extern void rtcm3_unpack(/*@out@*/struct rtcm3_t *, char *);
149 extern void rtcm3_dump(struct rtcm3_t *rtcm, FILE *);
150
151 extern size_t oncore_payload_cksum_length(unsigned char id1,unsigned char id2);
152
153 /* Next, declarations for the core library... */
154
155 /* factors for converting among confidence interval units */
156 #define CEP50_SIGMA     1.18
157 #define DRMS_SIGMA      1.414
158 #define CEP95_SIGMA     2.45
159
160 /* this is where we choose the confidence level to use in reports */
161 #define GPSD_CONFIDENCE CEP95_SIGMA
162
163 #define NTPSHMSEGS      4               /* number of NTP SHM segments */
164
165 #define AIVDM_CHANNELS  2               /* A, B */
166
167 struct gps_context_t {
168     int valid;                          /* member validity flags */
169     bool readonly;                      /* if true, never write to device */
170 #define LEAP_SECOND_VALID       0x01    /* we have or don't need correction */
171     /* DGPSIP status */
172     bool sentdgps;                      /* have we sent a DGPS report? */
173     enum { netgnss_none, netgnss_dgpsip, netgnss_ntrip} netgnss_service;        /* type of GNSS service */
174     int fixcnt;                         /* count of good fixes seen */
175     socket_t dsock;                     /* socket to DGPSIP server/Ntrip caster */
176     void *netgnss_privdata;             /* DGNSS service specific data */
177     size_t rtcmbytes;                   /* byte count of last RTCM104 report */
178     char rtcmbuf[RTCM_MAX];             /* last RTCM104 report */
179     double rtcmtime;                    /* timestamp of last RTCM104 report */ 
180     /* timekeeping */
181     int leap_seconds;                   /* Unix seconds to UTC */
182     unsigned short gps_week;            /* GPS week, actually 10 bits */
183     double gps_tow;                     /* GPS time of week, actually 19 bits */
184     int century;                        /* for NMEA-only devices without ZDA */
185 #ifdef NTPSHM_ENABLE
186     bool enable_ntpshm;
187     /*@reldef@*/struct shmTime *shmTime[NTPSHMSEGS];
188     bool shmTimeInuse[NTPSHMSEGS];
189 # ifdef PPS_ENABLE
190     bool shmTimePPS;
191 # endif /* PPS_ENABLE */
192 #endif /* NTPSHM_ENABLE */
193 };
194
195 struct aivdm_context_t {
196     /* hold context for decoding AIDVM packet sequences */
197     int decoded_frags;          /* for tracking AIDVM parts in a multipart sequence */
198     unsigned char bits[2048];
199     size_t bitlen; /* how many valid bits */
200     unsigned int mmsi24; /* type 24 specific */
201     char shipname24[AIS_SHIPNAME_MAXLEN+1]; /* type 24 specific */
202 };
203
204 struct gps_device_t;
205
206 #if defined (HAVE_SYS_TERMIOS_H)
207 #include <sys/termios.h>
208 #else
209 #if defined (HAVE_TERMIOS_H)
210 #include <termios.h>
211 #endif
212 #endif
213
214 #define MODE_NMEA       0
215 #define MODE_BINARY     1
216
217 typedef enum {ANY, GPS, RTCM2, RTCM3, AIS} gnss_type;
218 typedef enum {
219     event_wakeup,
220     event_triggermatch,
221     event_identified,
222     event_configure, 
223     event_driver_switch,
224     event_deactivate,
225     event_reactivate,
226 } event_t;
227
228 #define ONLINE_IS       0x00000001u
229 #define TIME_IS         0x00000002u
230 #define TIMERR_IS       0x00000004u
231 #define LATLON_IS       0x00000008u
232 #define ALTITUDE_IS     0x00000010u
233 #define SPEED_IS        0x00000020u
234 #define TRACK_IS        0x00000040u
235 #define CLIMB_IS        0x00000080u
236 #define STATUS_IS       0x00000100u
237 #define MODE_IS         0x00000200u
238 #define DOP_IS          0x00000400u
239 #define HERR_IS         0x00000800u
240 #define VERR_IS         0x00001000u
241 #define PERR_IS         0x00002000u
242 #define SATELLITE_IS    0x00004000u
243 #define RAW_IS          0x00008000u
244 #define USED_IS         0x00010000u
245 #define SPEEDERR_IS     0x00020000u
246 #define DRIVER_IS       0x00040000u
247 #define DEVICEID_IS     0x00100000u
248 #define ERROR_IS        0x00200000u
249 #define RTCM2_IS        0x00400000u
250 #define RTCM3_IS        0x00800000u
251 #define AIS_IS          0x01000000u
252 #define ATT_IS          0x02000000u
253 #define PACKET_IS       0x04000000u
254 #define CLEAR_IS        0x08000000u     /* sentence starts a reporting cycle */
255 #define REPORT_IS       0x10000000u     /* sentence ends a reporting cycle */
256 #define NODATA_IS       0x20000000u     /* no data read from fd */ 
257 #define DATA_IS ~(ONLINE_IS|PACKET_IS|CLEAR_IS|REPORT_IS)
258
259 struct gps_type_t {
260 /* GPS method table, describes how to talk to a particular GPS type */
261     /*@observer@*/char *type_name;
262     int packet_type;
263     /*@observer@*//*@null@*/char *trigger;
264     int channels;
265     /*@null@*/bool (*probe_detect)(struct gps_device_t *session);
266     /*@null@*/ssize_t (*get_packet)(struct gps_device_t *session);
267     /*@null@*/gps_mask_t (*parse_packet)(struct gps_device_t *session);
268     /*@null@*/ssize_t (*rtcm_writer)(struct gps_device_t *session, char *rtcmbuf, size_t rtcmbytes);
269     /*@null@*/void (*event_hook)(struct gps_device_t *session, event_t event);
270 #ifdef ALLOW_RECONFIGURE 
271     /*@null@*/bool (*speed_switcher)(struct gps_device_t *session, 
272                                      speed_t speed, char parity, int stopbits);
273     /*@null@*/void (*mode_switcher)(struct gps_device_t *session, int mode);
274     /*@null@*/bool (*rate_switcher)(struct gps_device_t *session, double rate);
275     double min_cycle;
276 #endif /* ALLOW_RECONFIGURE */
277 #ifdef ALLOW_CONTROLSEND
278     /*@null@*/ssize_t (*control_send)(struct gps_device_t *session, char *buf, size_t buflen);
279 #endif /* ALLOW_CONTROLSEND */
280 #ifdef NTPSHM_ENABLE
281     /*@null@*/double (*ntp_offset)(struct gps_device_t *session);
282 #endif /* NTPSHM_ENABLE */
283 };
284
285 typedef enum {source_unknown,
286               source_blockdev,
287               source_rs232,
288               source_usb,
289               source_bluetooth,
290               source_pty,
291               source_tcp,
292               source_udp}
293     sourcetype_t;
294
295 struct gps_device_t {
296 /* session object, encapsulates all global state */
297     struct gps_data_t gpsdata;
298     /*@relnull@*/const struct gps_type_t *device_type;
299     struct gps_context_t        *context;
300     bool is_serial;
301     sourcetype_t sourcetype;
302     double rtcmtime;    /* timestamp of last RTCM104 correction to GPS */
303 #ifndef _WIN32
304     struct termios ttyset, ttyset_old;
305 #endif
306     unsigned int baudindex;
307     int saved_baud;
308     struct gps_packet_t packet;
309     int getcount;
310     char subtype[64];                   /* firmware version or subtype ID */
311     double opentime;
312     double releasetime;
313     bool zerokill;
314     double reawake;
315 #ifdef NTPSHM_ENABLE
316     int shmindex;
317     double last_fixtime;                /* so updates happen once */
318 # ifdef PPS_ENABLE
319     int shmTimeP;
320 # endif /* PPS_ENABLE */
321 #endif /* NTPSHM_ENABLE */
322     double mag_var;                     /* magnetic variation in degrees */  
323     bool back_to_nmea;                  /* back to NMEA on revert? */
324     char msgbuf[MAX_PACKET_LENGTH*2+1]; /* command message buffer for sends */
325     size_t msgbuflen;
326     int observed;                       /* which packet type`s have we seen? */
327     bool cycle_end_reliable;            /* does driver signal REPORT_MASK */
328     bool notify_clients;                /* ship DEVICE notification on poll? */
329     struct gps_fix_t newdata;           /* where clients put their data */
330     struct gps_fix_t oldfix;            /* previous fix for error modeling */
331     /*
332      * The rest of this structure is driver-specific private storage.
333      * Because the Garmin driver uses a long buffer, you can have
334      * up to 4096+12 bytes of private storage in your own union member
335      * without making this structure larger or changing the API at all.
336      */
337     union {
338 #ifdef NMEA_ENABLE
339         struct {
340             int part, await;            /* for tracking GSV parts */
341             struct tm date;             /* date part of last sentence time */
342             double subseconds;          /* subsec part of last sentence time */
343             char *field[NMEA_MAX];
344             unsigned char fieldcopy[NMEA_MAX+1];
345             /*
346              * State for the cycle-tracking machinery.
347              * The reason these timestamps are separate from the
348              * general sentence timestamps is that we can
349              * use the minutes and seconds part of a sentence
350              * with an incomplete timestasmp (like GGA) for
351              * end-cycle recognition, even if we don't have a previous
352              * RMC or ZDA that lets us get full time from it.
353              */
354             double this_frac_time, last_frac_time;
355             bool latch_frac_time;
356             unsigned int lasttag;
357             unsigned int cycle_enders;
358 #ifdef GPSCLOCK_ENABLE
359             bool ignore_trailing_edge;
360 #endif /* GPSCLOCK_ENABLE */
361         } nmea;
362 #endif /* NMEA_ENABLE */
363 #ifdef GARMINTXT_ENABLE
364         struct {
365             struct tm date;             /* date part of last sentence time */
366             double subseconds;          /* subsec part of last sentence time */
367         } garmintxt;
368 #endif /* NMEA_ENABLE */
369 #ifdef BINARY_ENABLE
370 #ifdef SIRF_ENABLE
371         struct {
372             unsigned int driverstate;   /* for private use */
373 #define SIRF_LT_231     0x01            /* SiRF at firmware rev < 231 */
374 #define SIRF_EQ_231     0x02            /* SiRF at firmware rev == 231 */
375 #define SIRF_GE_232     0x04            /* SiRF at firmware rev >= 232 */
376 #define UBLOX           0x08            /* uBlox firmware with packet 0x62 */
377             unsigned long satcounter;
378             unsigned int time_seen;
379 #define TIME_SEEN_GPS_1 0x01    /* Seen GPS time variant 1? */
380 #define TIME_SEEN_GPS_2 0x02    /* Seen GPS time variant 2? */
381 #define TIME_SEEN_UTC_1 0x04    /* Seen UTC time variant 1? */
382 #define TIME_SEEN_UTC_2 0x08    /* Seen UTC time variant 2? */
383             /* fields from Navigation Parameters message */
384             bool nav_parameters_seen;   /* have we seen one? */
385             unsigned char altitude_hold_mode;
386             unsigned char altitude_hold_source;
387             int16_t altitude_source_input;
388             unsigned char degraded_mode;
389             unsigned char degraded_timeout;
390             unsigned char dr_timeout;
391             unsigned char track_smooth_mode;
392         } sirf;
393 #endif /* SIRF_ENABLE */
394 #ifdef SUPERSTAR2_ENABLE
395         struct {
396             time_t last_iono;
397         } superstar2;
398 #endif /* SUPERSTAR2_ENABLE */
399 #ifdef TSIP_ENABLE
400         struct {
401             bool superpkt;              /* Super Packet mode requested */
402             time_t last_41;             /* Timestamps for packet requests */
403             time_t last_48;
404             time_t last_5c;
405             time_t last_6d;
406             time_t last_46;
407             time_t req_compact;
408             unsigned int stopbits; /* saved RS232 link parameter */
409             char parity;
410         } tsip;
411 #endif /* TSIP_ENABLE */
412 #ifdef GARMIN_ENABLE    /* private housekeeping stuff for the Garmin driver */
413         struct {
414             unsigned char Buffer[4096+12];      /* Garmin packet buffer */
415             size_t BufferLen;           /* current GarminBuffer Length */
416         } garmin;
417 #endif /* GARMIN_ENABLE */
418 #ifdef ZODIAC_ENABLE    /* private housekeeping stuff for the Zodiac driver */
419         struct {
420             unsigned short sn;          /* packet sequence number */
421             /*
422              * Zodiac chipset channel status from PRWIZCH. Keep it so
423              * raw-mode translation of Zodiac binary protocol can send
424              * it up to the client.
425              */
426 #define ZODIAC_CHANNELS 12
427             unsigned int Zs[ZODIAC_CHANNELS];   /* satellite PRNs */
428             unsigned int Zv[ZODIAC_CHANNELS];   /* signal values (0-7) */
429         } zodiac;
430 #endif /* ZODIAC_ENABLE */
431 #ifdef UBX_ENABLE
432         struct {
433             bool have_port_configuration;
434             unsigned char original_port_settings[20];
435             unsigned char sbas_in_use;
436         } ubx;
437 #endif /* UBX_ENABLE */
438 #ifdef NAVCOM_ENABLE
439         struct {
440             uint8_t physical_port;
441             bool warned;
442         } navcom;
443 #endif /* NAVCOM_ENABLE */
444 #ifdef ONCORE_ENABLE
445         struct {
446 #define ONCORE_VISIBLE_CH 12
447             int visible;
448             int PRN[ONCORE_VISIBLE_CH];         /* PRNs of satellite */
449             int elevation[ONCORE_VISIBLE_CH];   /* elevation of satellite */
450             int azimuth[ONCORE_VISIBLE_CH];     /* azimuth */
451             double pps_delay;
452         } oncore;
453 #endif /* ONCORE_ENABLE */
454
455         /*
456          * This is not conditionalized on RTCM104_ENABLE because we need to
457          * be able to build gpsdecode even when RTCM support is not
458          * configured in the daemon.  It doesn't take up extra space.
459          */
460         struct {
461             /* ISGPS200 decoding */
462             bool            locked;
463             int             curr_offset;
464             isgps30bits_t   curr_word;
465             isgps30bits_t   buf[RTCM2_WORDS_MAX];
466             unsigned int    bufindex;
467         } isgps;
468 #endif /* BINARY_ENABLE */
469     } driver;
470     /*
471      * Auxiliary structures for parsing data that can be interleaved with
472      * GPS sentences. Can't be in the driver union or it will get stepped on.
473      * So far the only case of this is AIS reports, which in marine navigation
474      * systems may come over the same wire with GPS NMEA sentences.
475      */
476 #ifdef AIVDM_ENABLE
477     struct aivdm_context_t aivdm[AIVDM_CHANNELS];
478 #endif /* AIVDM_ENABLE */
479
480 #ifdef TIMING_ENABLE
481     /* profiling data for last sentence */
482     char tag[MAXTAGLEN+1];      /* tag of last sentence processed */
483     double d_xmit_time;         /* beginning of sentence transmission */
484     double d_recv_time;         /* daemon receipt time (-> E1+T1) */
485     double d_decode_time;       /* daemon end-of-decode time (-> D1) */
486     double emit_time;           /* emission time (-> E2) */
487 #endif /* TIMING_ENABLE */
488 };
489
490 /* logging levels */
491 #define LOG_ERROR       0       /* errors, display always */
492 #define LOG_SHOUT       0       /* not an error but we should always see it */
493 #define LOG_WARN        1       /* not errors but may indicate a problem */
494 #define LOG_INF         2       /* key informative messages */
495 #define LOG_DATA        3       /* log data management messages */
496 #define LOG_PROG        4       /* progress messages */
497 #define LOG_IO          5       /* IO to and from devices */
498 #define LOG_SPIN        6       /* logging for catching spin bugs */
499 #define LOG_RAW         7       /* raw low-level I/O */
500
501 #define IS_HIGHEST_BIT(v,m)     (v & ~((m<<1)-1))==0
502
503 /* here are the available GPS drivers */
504 extern const struct gps_type_t **gpsd_drivers;
505
506 /* gpsd library internal prototypes */
507 extern gps_mask_t nmea_parse_input(struct gps_device_t *);
508 extern gps_mask_t nmea_parse(char *, struct gps_device_t *);
509 extern ssize_t nmea_write(struct gps_device_t *session, char *buf, size_t len);
510 extern ssize_t nmea_send(struct gps_device_t *session, const char *, ... );
511 extern void nmea_add_checksum(char *);
512
513 ssize_t generic_get(struct gps_device_t *);
514 ssize_t pass_rtcm(struct gps_device_t *, char *, size_t);
515
516 extern gps_mask_t sirf_parse(struct gps_device_t *, unsigned char *, size_t);
517 extern gps_mask_t evermore_parse(struct gps_device_t *, unsigned char *, size_t);
518 extern gps_mask_t navcom_parse(struct gps_device_t *, unsigned char *, size_t);
519 extern gps_mask_t garmin_ser_parse(struct gps_device_t *);
520 extern gps_mask_t garmintxt_parse(struct gps_device_t *);
521 extern gps_mask_t aivdm_parse(struct gps_device_t *);
522
523 extern bool netgnss_uri_check(char *);
524 extern int netgnss_uri_open(struct gps_context_t *, char *);
525 extern int netgnss_poll(struct gps_context_t *);
526 extern void netgnss_report(struct gps_device_t *);
527 extern void netgnss_autoconnect(struct gps_context_t *, double, double);
528
529 extern void rtcm_relay(struct gps_device_t *);
530 extern void rtcm2_output_mag(isgps30bits_t *, FILE *);
531
532 extern int dgpsip_open(struct gps_context_t *, const char *);
533 extern void dgpsip_report(struct gps_device_t *);
534 extern void dgpsip_autoconnect(struct gps_context_t *, 
535                                double, double, const char *);
536 extern int ntrip_open(struct gps_context_t *, char *);
537 extern void ntrip_report(struct gps_device_t *);
538
539 extern void gpsd_tty_init(struct gps_device_t *);
540 extern int gpsd_open(struct gps_device_t *);
541 extern bool gpsd_set_raw(struct gps_device_t *);
542 extern ssize_t gpsd_write(struct gps_device_t *, void const *, size_t);
543 extern bool gpsd_next_hunt_setting(struct gps_device_t *);
544 extern int gpsd_switch_driver(struct gps_device_t *, char *);
545 extern void gpsd_set_speed(struct gps_device_t *, speed_t, char, unsigned int);
546 extern speed_t gpsd_get_speed(const struct termios *);
547 extern void gpsd_assert_sync(struct gps_device_t *);
548 extern void gpsd_close(struct gps_device_t *);
549
550 extern void gpsd_zero_satellites(/*@out@*/struct gps_data_t *sp)/*@modifies sp@*/;
551 extern void gpsd_interpret_subframe(struct gps_device_t *, unsigned int[]);
552 extern int gpsd_interpret_subframe_raw(struct gps_device_t *, unsigned int[]);
553 extern int gpsd_hexdump_level;
554 extern /*@ observer @*/ char *gpsd_hexdump(/*@null@*/const void *, size_t);
555 extern /*@ observer @*/ char *gpsd_hexdump_wrapper(/*@null@*/const void *, size_t, int);
556 extern int gpsd_hexpack(/*@in@*/const char *, /*@out@*/char *, size_t);
557 extern int hex2bin(const char *);
558 extern ssize_t hex_escapes(/*@out@*/char *cooked, const char *raw);
559 extern void ntpd_link_activate(struct gps_device_t *session);
560 extern char /*@observer@*/ *gpsd_id(/*@in@*/struct gps_device_t *);
561 extern void gpsd_position_fix_dump(struct gps_device_t *, /*@out@*/char[], size_t);
562 extern void gpsd_clear_data(struct gps_device_t *);
563 extern socket_t netlib_connectsock(int, const char *, const char *, const char *);
564 extern char /*@observer@*/ *netlib_errstr(const int);
565 extern char /*@observer@*/ *netlib_sock2ip(int);
566
567 extern void nmea_tpv_dump(struct gps_device_t *, /*@out@*/char[], size_t);
568 extern void nmea_sky_dump(struct gps_device_t *, /*@out@*/char[], size_t);
569
570 extern void ntpshm_init(struct gps_context_t *, bool);
571 extern int ntpshm_alloc(struct gps_context_t *);
572 extern bool ntpshm_free(struct gps_context_t *, int);
573 extern int ntpshm_put(struct gps_device_t *, double, double);
574 extern int ntpshm_pps(struct gps_device_t *,struct timeval *);
575
576 extern void ecef_to_wgs84fix(/*@out@*/struct gps_fix_t *,
577                              /*@out@*/double *,
578                              double, double, double, 
579                              double, double, double);
580 extern void clear_dop(/*@out@*/struct dop_t *);
581 extern gps_mask_t fill_dop(/*@in@*/const struct gps_data_t *gpsdata, 
582                            struct dop_t *dop);
583
584 /* srecord.c */
585 extern void hexdump(size_t, unsigned char *, unsigned char *);
586 extern unsigned char sr_sum(unsigned int, unsigned int, unsigned char *);
587 extern int bin2srec(unsigned int, unsigned int, unsigned int, unsigned char *, unsigned char *);
588 extern int srec_hdr(unsigned int, unsigned char *, unsigned char *);
589 extern int srec_fin(unsigned int, unsigned char *);
590 extern unsigned char hc(unsigned char);
591
592 /* application interface */
593 extern void gpsd_init(struct gps_device_t *, 
594                       struct gps_context_t *, 
595                       /*@null@*/char *);
596 extern int gpsd_activate(struct gps_device_t *);
597 extern void gpsd_deactivate(struct gps_device_t *);
598 extern gps_mask_t gpsd_poll(struct gps_device_t *);
599 extern void gpsd_wrap(struct gps_device_t *);
600
601 /* exceptional driver methods */
602 #ifdef UBX_ENABLE
603 extern bool ubx_write(struct gps_device_t *, unsigned int, unsigned int, 
604                       /*@null@*/unsigned char *, unsigned short);
605 #endif /* UBX_ENABLE */
606 #ifdef AIVDM_ENABLE
607 extern bool aivdm_decode(const char *, size_t, 
608                          struct aivdm_context_t [], 
609                          struct ais_t *);
610 extern void  aivdm_json_dump(const struct ais_t *, bool, /*@out@*/char *, size_t);
611 #endif /* AIVDM_ENABLE */
612 #ifdef MTK3301_ENABLE
613 extern gps_mask_t processMTK3301(int c UNUSED, char *field[], struct gps_device_t *session);
614 #endif /* MTK3301_ENABLE */
615
616 /* caller should supply this */
617 # if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
618 __attribute__((__format__(__printf__, 2, 3))) void gpsd_report(int, const char *, ...);
619 # else /* not a new enough GCC, use the unprotected prototype */
620 void gpsd_report(int, const char *, ...);
621 #endif
622 extern /*@observer@*/const char *gpsd_maskdump(gps_mask_t);
623
624
625 #ifdef S_SPLINT_S
626 extern bool finite(double);
627 extern struct protoent *getprotobyname(const char *);
628 extern /*@observer@*/char *strptime(const char *,const char *tp,/*@out@*/struct tm *)/*@modifies tp@*/;
629 extern struct tm *gmtime_r(const time_t *,/*@out@*/struct tm *tp)/*@modifies tp@*/;
630 extern struct tm *localtime_r(const time_t *,/*@out@*/struct tm *tp)/*@modifies tp@*/;
631 extern float roundf(float x);
632 #endif /* S_SPLINT_S */
633
634 /*
635  * How to mix together epx and epy to get a horizontal circular error
636  * eph when reporting requires it. Most devices don't report these;
637  * NMEA 3.x devices reporting $GPGBS are the exception.
638  */
639 #define EMIX(x, y)      (((x) > (y)) ? (x) : (y))
640
641 /* some OSes don't have round(). fake it if need be */
642 #ifndef HAVE_ROUND
643 #define round(x) ((double)rint(x))
644 #define roundf(x) ((float)rintf((double)x))
645 #endif /* !HAVE_ROUND */
646
647 #define NITEMS(x) (int)(sizeof(x)/sizeof(x[0]))
648
649 /* OpenBSD and FreeBSD and Cygwin don't seem to have NAN, NetBSD does, others? */
650 /* FIX-ME: test for this in configure? */
651 #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__CYGWIN__)
652 #ifndef NAN
653 #define NAN (0.0/0.0)
654 #endif /* !NAN */
655 #endif /* list of Operating Systems */
656
657 /* Cygwin, in addition to NAN, doesn't have cfmakeraw */
658 #if defined(__CYGWIN__)
659 void cfmakeraw(struct termios *);
660 #endif /* defined(__CYGWIN__) */
661
662 #endif /* _GPSD_H_ */
663 // Local variables:
664 // mode: c
665 // end: