1 /* gps.h -- interface of the libgps library */
2 /*
3  * This file is Copyright (c) 2010 by the GPSD project
4  *
5  * 			COPYRIGHTS
6  *
7  * Compilation copyright is held by the GPSD project.  All rights reserved.
8  *
9  * GPSD project copyrights are assigned to the project lead, currently
10  * Eric S. Raymond. Other portions of the GPSD code are Copyright (c)
11  * 1997, 1998, 1999, 2000, 2001, 2002 by Remco Treffkorn, and others
12  * Copyright (c) 2005 by Eric S. Raymond.  For other copyrights, see
13  * individual files.
14  *
15  * 			BSD LICENSE
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:<P>
20  *
21  * Redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer.<P>
23  *
24  * Redistributions in binary form must reproduce the above copyright
25  * notice, this list of conditions and the following disclaimer in the
26  * documentation and/or other materials provided with the distribution.<P>
27  *
28  * Neither name of the GPSD project nor the names of its contributors
29  * may be used to endorse or promote products derived from this software
30  * without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
36  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
39  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43  */
44 /*
45  * This file originated from GPSD version 3.11.
46  */
47 #ifndef _GPSD_GPS_H_
48 #define _GPSD_GPS_H_
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 #include <sys/types.h>
55 #include <sys/time.h>
56 #include <stdbool.h>
57 #include <inttypes.h>	/* stdint.h would be smaller but not all have it */
58 #include <limits.h>
59 #include <time.h>
60 #include <signal.h>
61 #include <stdio.h>
62 #include <pthread.h>	/* pacifies OpenBSD's compiler */
63 
64 /*
65  * 4.1 - Base version for initial JSON protocol (Dec 2009, release 2.90)
66  * 4.2 - AIS application IDs split into DAC and FID (July 2010, release 2.95)
67  * 5.0 - MAXCHANNELS bumped from 20 to 32 for GLONASS (Mar 2011, release 2.96)
68  *       gps_open() becomes reentrant, what gps_open_r() used to be.
69  *       gps_poll() removed in favor of gps_read().  The raw hook is gone.
70  *       (Aug 2011, release 3.0)
71  * 5.1 - GPS_PATH_MAX uses system PATH_MAX; split24 flag added. New
72  *       model and serial members in part B of AIS type 24, conforming
73  *       with ITU-R 1371-4. New timedrift structure (Nov 2013, release 3.10).
74  * 6.0 - AIS type 6 and 8 get 'structured' flag; GPS_PATH_MAX
75  *       shortened because devices has moved out of the tail union. Sentence
76  *       tag fields dropped from emitted JSON. The shape of the skyview
77  *       structure has changed to make working with the satellites-used
78  *       bits less confusing. (January 2015, release 3.12).
79  * 6.1 - Add navdata_t for more (nmea2000) info.
80  */
81 #define GPSD_API_MAJOR_VERSION	6	/* bump on incompatible changes */
82 #define GPSD_API_MINOR_VERSION	1	/* bump on compatible changes */
83 
84 #define MAXCHANNELS	72	/* must be > 12 GPS + 12 GLONASS + 2 WAAS */
85 #define MAXUSERDEVS	4	/* max devices per user */
86 #define GPS_PATH_MAX	128	/* for names like /dev/serial/by-id/... */
87 
88 /*
89  * The structure describing an uncertainty volume in kinematic space.
90  * This is what GPSes are meant to produce; all the other info is
91  * technical impedimenta.
92  *
93  * All double values use NAN to indicate data not available.
94  *
95  * All the information in this structure was considered valid
96  * by the GPS at the time of update.
97  *
98  * Error estimates are at 95% confidence.
99  */
100 /* WARNING!  potential loss of precision in timestamp_t
101  * a double is 53 significant bits.
102  * UNIX time to nanoSec precision is 62 significant bits
103  * UNIX time to nanoSec precision after 2038 is 63 bits
104  * timestamp_t is only microSec precision
105  * timestamp_t and PPS do not play well together
106  */
107 typedef double timestamp_t;	/* Unix time in seconds with fractional part */
108 
109 struct gps_fix_t {
110     timestamp_t time;	/* Time of update */
111     int    mode;	/* Mode of fix */
112 #define MODE_NOT_SEEN	0	/* mode update not seen yet */
113 #define MODE_NO_FIX	1	/* none */
114 #define MODE_2D  	2	/* good for latitude/longitude */
115 #define MODE_3D  	3	/* good for altitude/climb too */
116     double ept;		/* Expected time uncertainty */
117     double latitude;	/* Latitude in degrees (valid if mode >= 2) */
118     double epy;  	/* Latitude position uncertainty, meters */
119     double longitude;	/* Longitude in degrees (valid if mode >= 2) */
120     double epx;  	/* Longitude position uncertainty, meters */
121     double altitude;	/* Altitude in meters (valid if mode == 3) */
122     double epv;  	/* Vertical position uncertainty, meters */
123     double track;	/* Course made good (relative to true north) */
124     double epd;		/* Track uncertainty, degrees */
125     double speed;	/* Speed over ground, meters/sec */
126     double eps;		/* Speed uncertainty, meters/sec */
127     double climb;       /* Vertical speed, meters/sec */
128     double epc;		/* Vertical speed uncertainty */
129 };
130 
131 /*
132  * Satellite ID classes.
133  * According to IS-GPS-200 Revision H paragraph 6.3.6, and earlier revisions
134  * at least back to E, the upper bound of U.S. GPS PRNs is actually 64. However,
135  * NMEA0183 only allocates 1-32 for U.S. GPS IDs; it uses 33-64 for IDs ub the
136  * SBAS range.
137  */
138 #define GPS_PRN(n)	(((n) >= 1) && ((n) <= 32))	/* U.S. GPS satellite */
139 #define GBAS_PRN(n)	((n) >= 64 && ((n) <= 119))	/* Other GNSS (GLONASS) and Ground Based Augmentation System (eg WAAS)*/
140 #define SBAS_PRN(n)	((n) >= 120 && ((n) <= 158))	/* Satellite Based Augmentation System (eg GAGAN)*/
141 #define GNSS_PRN(n)	((n) >= 159 && ((n) <= 210))	/* other GNSS (eg BeiDou) */
142 
143 /*
144  * GLONASS birds reuse GPS PRNs.
145  * It is an NMEA0183 convention to map them to pseudo-PRNs 65..96.
146  * (some other programs push them to 33 and above).
147  * The US GPS constellation plans to use the 33-63 range.
148  */
149 #define GLONASS_PRN_OFFSET	64
150 
151 /*
152  * The structure describing the pseudorange errors (GPGST)
153  */
154 struct gst_t {
155     double utctime;
156     double rms_deviation;
157     double smajor_deviation;
158     double sminor_deviation;
159     double smajor_orientation;
160     double lat_err_deviation;
161     double lon_err_deviation;
162     double alt_err_deviation;
163 };
164 
165 /*
166  * From the RCTM104 2.x standard:
167  *
168  * "The 30 bit words (as opposed to 32 bit words) coupled with a 50 Hz
169  * transmission rate provides a convenient timing capability where the
170  * times of word boundaries are a rational multiple of 0.6 seconds."
171  *
172  * "Each frame is N+2 words long, where N is the number of message data
173  * words. For example, a filler message (type 6 or 34) with no message
174  * data will have N=0, and will consist only of two header words. The
175  * maximum number of data words allowed by the format is 31, so that
176  * the longest possible message will have a total of 33 words."
177  */
178 #define RTCM2_WORDS_MAX	33
179 #define MAXCORRECTIONS	18	/* max correction count in type 1 or 9 */
180 #define MAXSTATIONS	10	/* maximum stations in almanac, type 5 */
181 /* RTCM104 doesn't specify this, so give it the largest reasonable value */
182 #define MAXHEALTH	(RTCM2_WORDS_MAX-2)
183 
184 /*
185  * A nominally 30-bit word (24 bits of data, 6 bits of parity)
186  * used both in the GPS downlink protocol described in IS-GPS-200
187  * and in the format for DGPS corrections used in RTCM-104v2.
188  */
189 typedef uint32_t isgps30bits_t;
190 
191 /*
192  * Values for "system" fields.  Note, the encoding logic is senstive to the
193  * actual values of these; it's not sufficient that they're distinct.
194  */
195 #define NAVSYSTEM_GPS   	0
196 #define NAVSYSTEM_GLONASS	1
197 #define NAVSYSTEM_GALILEO	2
198 #define NAVSYSTEM_UNKNOWN	3
199 
200 struct rtcm2_t {
201     /* header contents */
202     unsigned type;	/* RTCM message type */
203     unsigned length;	/* length (words) */
204     double   zcount;	/* time within hour: GPS time, no leap secs */
205     unsigned refstaid;	/* reference station ID */
206     unsigned seqnum;	/* message sequence number (modulo 8) */
207     unsigned stathlth;	/* station health */
208 
209     /* message data in decoded form */
210     union {
211 	struct {
212 	    unsigned int nentries;
213 	    struct gps_rangesat_t {	/* data from messages 1 & 9 */
214 		unsigned ident;		/* satellite ID */
215 		unsigned udre;		/* user diff. range error */
216 		unsigned iod;		/* issue of data */
217 		double prc;		/* range error */
218 		double rrc;		/* range error rate */
219 	    } sat[MAXCORRECTIONS];
220 	} gps_ranges;
221 	struct {		/* data for type 3 messages */
222 	    bool valid;		/* is message well-formed? */
223 	    double x, y, z;
224 	} ecef;
225 	struct {		/* data from type 4 messages */
226 	    bool valid;		/* is message well-formed? */
227 	    int system;
228 	    int sense;
229 #define SENSE_INVALID	0
230 #define SENSE_GLOBAL	1
231 #define SENSE_LOCAL   	2
232 	    char datum[6];
233 	    double dx, dy, dz;
234 	} reference;
235 	struct {		/* data from type 5 messages */
236 	    unsigned int nentries;
237 	    struct consat_t {
238 		unsigned ident;		/* satellite ID */
239 		bool iodl;		/* issue of data */
240 		unsigned int health;	/* is satellite healthy? */
241 #define HEALTH_NORMAL		(0)	/* Radiobeacon operation normal */
242 #define HEALTH_UNMONITORED	(1)	/* No integrity monitor operating */
243 #define HEALTH_NOINFO		(2)	/* No information available */
244 #define HEALTH_DONOTUSE		(3)	/* Do not use this radiobeacon */
245 	       int snr;			/* signal-to-noise ratio, dB */
246 #define SNR_BAD	-1			/* not reported */
247 		bool health_en; 	/* health enabled */
248 		bool new_data;		/* new data? */
249 		bool los_warning;	/* line-of-sight warning */
250 		unsigned int tou;	/* time to unhealth, seconds */
251 	    } sat[MAXHEALTH];
252 	} conhealth;
253 	struct {		/* data from type 7 messages */
254 	    unsigned int nentries;
255 	    struct station_t {
256 		double latitude, longitude;	/* location */
257 		unsigned int range;		/* range in km */
258 		double frequency;		/* broadcast freq */
259 		unsigned int health;		/* station health */
260 		unsigned int station_id;	/* of the transmitter */
261 		unsigned int bitrate;		/* of station transmissions */
262 	    } station[MAXSTATIONS];
263 	} almanac;
264 	struct {		/* data for type 13 messages */
265 	    bool status;		/* expect a text message */
266 	    bool rangeflag;		/* station range altered? */
267 	    double lat, lon;		/* station longitude/latitude */
268 	    unsigned int range;		/* transmission range in km */
269 	} xmitter;
270 	struct {		/* data from type 14 messages */
271 	    unsigned int week;			/* GPS week (0-1023) */
272 	    unsigned int hour;			/* Hour in week (0-167) */
273 	    unsigned int leapsecs;		/* Leap seconds (0-63) */
274 	} gpstime;
275 	struct {
276 	    unsigned int nentries;
277 	    struct glonass_rangesat_t {		/* data from message type 31 */
278 		unsigned ident;		/* satellite ID */
279 		unsigned udre;		/* user diff. range error */
280 		unsigned tod;		/* issue of data */
281 		bool change;		/* ephemeris change bit */
282 		double prc;		/* range error */
283 		double rrc;		/* range error rate */
284 	    } sat[MAXCORRECTIONS];
285 	} glonass_ranges;
286 	/* data from type 16 messages */
287 	char message[(RTCM2_WORDS_MAX-2) * sizeof(isgps30bits_t)];
288 	/* data from messages of unknown type */
289 	isgps30bits_t	words[RTCM2_WORDS_MAX-2];
290     };
291 };
292 
293 /* RTCM3 report structures begin here */
294 
295 #define RTCM3_MAX_SATELLITES	64
296 #define RTCM3_MAX_DESCRIPTOR	31
297 #define RTCM3_MAX_ANNOUNCEMENTS	32
298 
299 struct rtcm3_rtk_hdr {		/* header data from 1001, 1002, 1003, 1004 */
300     /* Used for both GPS and GLONASS, but their timebases differ */
301     unsigned int station_id;	/* Reference Station ID */
302     time_t tow;			/* GPS Epoch Time (TOW) in ms,
303 				   or GLONASS Epoch Time in ms */
304     bool sync;			/* Synchronous GNSS Message Flag */
305     unsigned short satcount;	/* # Satellite Signals Processed */
306     bool smoothing;		/* Divergence-free Smoothing Indicator */
307     unsigned int interval;	/* Smoothing Interval */
308 };
309 
310 struct rtcm3_basic_rtk {
311     unsigned char indicator;	/* Indicator */
312     unsigned int channel;	/* Satellite Frequency Channel Number
313 				   (GLONASS only) */
314     double pseudorange;		/* Pseudorange */
315     double rangediff;		/* PhaseRange – Pseudorange in meters */
316     unsigned char locktime;	/* Lock time Indicator */
317 };
318 
319 struct rtcm3_extended_rtk {
320     unsigned char indicator;	/* Indicator */
321     unsigned int channel;	/* Satellite Frequency Channel Number
322 				   (GLONASS only) */
323     double pseudorange;		/* Pseudorange */
324     double rangediff;		/* PhaseRange – L1 Pseudorange */
325     unsigned char locktime;	/* Lock time Indicator */
326     unsigned char ambiguity;	/* Integer Pseudorange
327 					   Modulus Ambiguity */
328     double CNR;			/* Carrier-to-Noise Ratio */
329 };
330 
331 struct rtcm3_network_rtk_header {
332     unsigned int network_id;	/* Network ID */
333     unsigned int subnetwork_id;	/* Subnetwork ID */
334     time_t time;		/* GPS Epoch Time (TOW) in ms */
335     bool multimesg;		/* GPS Multiple Message Indicator */
336     unsigned master_id;		/* Master Reference Station ID */
337     unsigned aux_id;		/* Auxilary Reference Station ID */
338     unsigned char satcount;	/* count of GPS satellites */
339 };
340 
341 struct rtcm3_correction_diff {
342     unsigned char ident;	/* satellite ID */
343     enum {reserved, correct, widelane, uncertain} ambiguity;
344     unsigned char nonsync;
345     double geometric_diff;	/* Geometric Carrier Phase
346 				   Correction Difference (1016, 1017) */
347     unsigned char iode;		/* GPS IODE (1016, 1017) */
348     double ionospheric_diff;	/* Ionospheric Carrier Phase
349 				   Correction Difference (1015, 1017) */
350 };
351 
352 struct rtcm3_t {
353     /* header contents */
354     unsigned type;	/* RTCM 3.x message type */
355     unsigned length;	/* payload length, inclusive of checksum */
356 
357     union {
358 	/* 1001-1013 were present in the 3.0 version */
359 	struct {
360 	    struct rtcm3_rtk_hdr	header;
361 	    struct rtcm3_1001_t {
362 		unsigned ident;			/* Satellite ID */
363 		struct rtcm3_basic_rtk L1;
364 	    } rtk_data[RTCM3_MAX_SATELLITES];
365 	} rtcm3_1001;
366 	struct {
367 	    struct rtcm3_rtk_hdr	header;
368 	    struct rtcm3_1002_t {
369 		unsigned ident;			/* Satellite ID */
370 		struct rtcm3_extended_rtk L1;
371 	    } rtk_data[RTCM3_MAX_SATELLITES];
372 	} rtcm3_1002;
373 	struct rtcm3_1003_t {
374 	    struct rtcm3_rtk_hdr	header;
375 	    struct {
376 		unsigned ident;			/* Satellite ID */
377 		struct rtcm3_basic_rtk L1;
378 		struct rtcm3_basic_rtk L2;
379 	    } rtk_data[RTCM3_MAX_SATELLITES];
380 	} rtcm3_1003;
381 	struct rtcm3_1004_t {
382 	    struct rtcm3_rtk_hdr	header;
383 	    struct {
384 		unsigned ident;			/* Satellite ID */
385 		struct rtcm3_extended_rtk L1;
386 		struct rtcm3_extended_rtk L2;
387 	    } rtk_data[RTCM3_MAX_SATELLITES];
388 	} rtcm3_1004;
389 	struct rtcm3_1005_t {
390 	    unsigned int station_id;		/* Reference Station ID */
391 	    int system;				/* Which system is it? */
392 	    bool reference_station;		/* Reference-station indicator */
393 	    bool single_receiver;		/* Single Receiver Oscillator */
394 	    double ecef_x, ecef_y, ecef_z;	/* ECEF antenna location */
395 	} rtcm3_1005;
396 	struct rtcm3_1006_t {
397 	    unsigned int station_id;		/* Reference Station ID */
398 	    int system;				/* Which system is it? */
399 	    bool reference_station;		/* Reference-station indicator */
400 	    bool single_receiver;		/* Single Receiver Oscillator */
401 	    double ecef_x, ecef_y, ecef_z;	/* ECEF antenna location */
402 	    double height;			/* Antenna height */
403 	} rtcm3_1006;
404 	struct {
405 	    unsigned int station_id;			/* Reference Station ID */
406 	    char descriptor[RTCM3_MAX_DESCRIPTOR+1];	/* Description string */
407 	    unsigned int setup_id;
408 	} rtcm3_1007;
409 	struct {
410 	    unsigned int station_id;			/* Reference Station ID */
411 	    char descriptor[RTCM3_MAX_DESCRIPTOR+1];	/* Description string */
412 	    unsigned int setup_id;
413 	    char serial[RTCM3_MAX_DESCRIPTOR+1];	/* Serial # string */
414 	} rtcm3_1008;
415 	struct {
416 	    struct rtcm3_rtk_hdr	header;
417 	    struct rtcm3_1009_t {
418 		unsigned ident;		/* Satellite ID */
419 		struct rtcm3_basic_rtk L1;
420 	    } rtk_data[RTCM3_MAX_SATELLITES];
421 	} rtcm3_1009;
422 	struct {
423 	    struct rtcm3_rtk_hdr	header;
424 	    struct rtcm3_1010_t {
425 		unsigned ident;		/* Satellite ID */
426 		struct rtcm3_extended_rtk L1;
427 	    } rtk_data[RTCM3_MAX_SATELLITES];
428 	} rtcm3_1010;
429 	struct {
430 	    struct rtcm3_rtk_hdr	header;
431 	    struct rtcm3_1011_t {
432 		unsigned ident;			/* Satellite ID */
433 		struct rtcm3_extended_rtk L1;
434 		struct rtcm3_extended_rtk L2;
435 	    } rtk_data[RTCM3_MAX_SATELLITES];
436 	} rtcm3_1011;
437 	struct {
438 	    struct rtcm3_rtk_hdr	header;
439 	    struct rtcm3_1012_t {
440 		unsigned ident;			/* Satellite ID */
441 		struct rtcm3_extended_rtk L1;
442 		struct rtcm3_extended_rtk L2;
443 	    } rtk_data[RTCM3_MAX_SATELLITES];
444 	} rtcm3_1012;
445 	struct {
446 	    unsigned int station_id;	/* Reference Station ID */
447 	    unsigned short mjd;		/* Modified Julian Day (MJD) Number */
448 	    unsigned int sod;		/* Seconds of Day (UTC) */
449 	    unsigned char leapsecs;	/* Leap Seconds, GPS-UTC */
450 	    unsigned char ncount;	/* Count of announcements to follow */
451 	    struct rtcm3_1013_t {
452 		unsigned short id;		/* message type ID */
453 		bool sync;
454 		unsigned short interval;	/* interval in 0.1sec units */
455 	    } announcements[RTCM3_MAX_ANNOUNCEMENTS];
456 	} rtcm3_1013;
457 	/* 1014-1017 were added in the 3.1 version */
458 	struct rtcm3_1014_t {
459 	    unsigned int network_id;	/* Network ID */
460 	    unsigned int subnetwork_id;	/* Subnetwork ID */
461 	    unsigned int stationcount;	/* # auxiliary stations transmitted */
462 	    unsigned int master_id;	/* Master Reference Station ID */
463 	    unsigned int aux_id;	/* Auxilary Reference Station ID */
464 	    double d_lat, d_lon, d_alt;	/* Aux-master location delta */
465 	} rtcm3_1014;
466 	struct rtcm3_1015_t {
467 	    struct rtcm3_network_rtk_header	header;
468 	    struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
469 	} rtcm3_1015;
470 	struct rtcm3_1016_t {
471 	    struct rtcm3_network_rtk_header	header;
472 	    struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
473 	} rtcm3_1016;
474 	struct rtcm3_1017_t {
475 	    struct rtcm3_network_rtk_header	header;
476 	    struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
477 	} rtcm3_1017;
478 	/* 1018-1029 were in the 3.0 version */
479 	struct rtcm3_1019_t {
480 	    unsigned int ident;		/* Satellite ID */
481 	    unsigned int week;		/* GPS Week Number */
482 	    unsigned char sv_accuracy;	/* GPS SV ACCURACY */
483 	    enum {reserved_code, p, ca, l2c} code;
484 	    double idot;
485 	    unsigned char iode;
486 	    /* ephemeris fields, not scaled */
487 	    unsigned int t_sub_oc;
488 	    signed int a_sub_f2;
489 	    signed int a_sub_f1;
490 	    signed int a_sub_f0;
491 	    unsigned int iodc;
492 	    signed int C_sub_rs;
493 	    signed int delta_sub_n;
494 	    signed int M_sub_0;
495 	    signed int C_sub_uc;
496 	    unsigned int e;
497 	    signed int C_sub_us;
498 	    unsigned int sqrt_sub_A;
499 	    unsigned int t_sub_oe;
500 	    signed int C_sub_ic;
501 	    signed int OMEGA_sub_0;
502 	    signed int C_sub_is;
503 	    signed int i_sub_0;
504 	    signed int C_sub_rc;
505 	    signed int argument_of_perigee;
506 	    signed int omegadot;
507 	    signed int t_sub_GD;
508 	    unsigned char sv_health;
509 	    bool p_data;
510 	    bool fit_interval;
511 	} rtcm3_1019;
512 	struct rtcm3_1020_t {
513 	    unsigned int ident;		/* Satellite ID */
514 	    unsigned short channel;	/* Satellite Frequency Channel Number */
515 	    /* ephemeris fields, not scaled */
516 	    bool C_sub_n;
517 	    bool health_avAilability_indicator;
518 	    unsigned char P1;
519 	    unsigned short t_sub_k;
520 	    bool msb_of_B_sub_n;
521 	    bool P2;
522 	    bool t_sub_b;
523 	    signed int x_sub_n_t_of_t_sub_b_prime;
524 	    signed int x_sub_n_t_of_t_sub_b;
525 	    signed int x_sub_n_t_of_t_sub_b_prime_prime;
526 	    signed int y_sub_n_t_of_t_sub_b_prime;
527 	    signed int y_sub_n_t_of_t_sub_b;
528 	    signed int y_sub_n_t_of_t_sub_b_prime_prime;
529 	    signed int z_sub_n_t_of_t_sub_b_prime;
530 	    signed int z_sub_n_t_of_t_sub_b;
531 	    signed int z_sub_n_t_of_t_sub_b_prime_prime;
532 	    bool P3;
533 	    signed int gamma_sub_n_of_t_sub_b;
534 	    unsigned char MP;
535 	    bool Ml_n;
536 	    signed int tau_n_of_t_sub_b;
537 	    signed int M_delta_tau_sub_n;
538 	    unsigned int E_sub_n;
539 	    bool MP4;
540 	    unsigned char MF_sub_T;
541 	    unsigned char MN_sub_T;
542 	    unsigned char MM;
543 	    bool additioinal_data_availability;
544 	    unsigned int N_sup_A;
545 	    unsigned int tau_sub_c;
546 	    unsigned int M_N_sub_4;
547 	    signed int M_tau_sub_GPS;
548 	    bool M_l_sub_n;
549 	} rtcm3_1020;
550 	struct rtcm3_1029_t {
551 	    unsigned int station_id;	/* Reference Station ID */
552 	    unsigned short mjd;		/* Modified Julian Day (MJD) Number */
553 	    unsigned int sod;		/* Seconds of Day (UTC) */
554 	    size_t len;			/* # chars to follow */
555 	    size_t unicode_units;	/* # Unicode units in text */
556 	    unsigned char text[128];
557 	} rtcm3_1029;
558 	struct rtcm3_1033_t {
559 	    unsigned int station_id;			/* Reference Station ID */
560 	    char descriptor[RTCM3_MAX_DESCRIPTOR+1];	/* Description string */
561 	    unsigned int setup_id;
562 	    char serial[RTCM3_MAX_DESCRIPTOR+1];	/* Serial # string */
563 	    char receiver[RTCM3_MAX_DESCRIPTOR+1];	/* Receiver string */
564 	    char firmware[RTCM3_MAX_DESCRIPTOR+1];	/* Firmware string */
565 	} rtcm3_1033;
566 	char data[1024];		/* Max RTCM3 msg length is 1023 bytes */
567     } rtcmtypes;
568 };
569 
570 /* RTCM3 scaling constants */
571 #define GPS_AMBIGUITY_MODULUS		299792.458	/* 1004, DF014*/
572 #define GLONASS_AMBIGUITY_MODULUS	599584.916	/* 1012, DF044 */
573 #define MESSAGE_INTERVAL_UNITS		0.1		/* 1013, DF047 */
574 
575 /*
576  * Raw IS_GPS subframe data
577  */
578 
579 /* The almanac is a subset of the clock and ephemeris data, with reduced
580  * precision. See IS-GPS-200E, Table 20-VI  */
581 struct almanac_t
582 {
583     uint8_t sv;  /* The satellite this refers to */
584     /* toa, almanac reference time, 8 bits unsigned, seconds */
585     uint8_t toa;
586     long l_toa;
587     /* SV health data, 8 bit unsigned bit map */
588     uint8_t svh;
589     /* deltai, correction to inclination, 16 bits signed, semi-circles */
590     int16_t deltai;
591     double d_deltai;
592     /* M0, Mean Anomaly at Reference Time, 24 bits signed, semi-circles */
593     int32_t M0;
594     double d_M0;
595     /* Omega0, Longitude of Ascending Node of Orbit Plane at Weekly Epoch,
596      * 24 bits signed, semi-circles */
597     int32_t Omega0;
598     double d_Omega0;
599     /* omega, Argument of Perigee, 24 bits signed, semi-circles */
600     int32_t omega;
601     double d_omega;
602     /* af0, SV clock correction constant term
603      * 11 bits signed, seconds */
604     int16_t af0;
605     double d_af0;
606     /* af1, SV clock correction first order term
607      * 11 bits signed, seconds/second */
608     int16_t af1;
609     double d_af1;
610     /* eccentricity, 16 bits, unsigned, dimensionless */
611     uint16_t e;
612     double d_eccentricity;
613     /* sqrt A, Square Root of the Semi-Major Axis
614      * 24 bits unsigned, square_root(meters) */
615     uint32_t sqrtA;
616     double d_sqrtA;
617     /* Omega dot, Rate of Right Ascension, 16 bits signed, semi-circles/sec */
618     int16_t Omegad;
619     double d_Omegad;
620 };
621 
622 struct subframe_t {
623     /* subframe number, 3 bits, unsigned, 1 to 5 */
624     uint8_t subframe_num;
625     /* data_id, denotes the NAV data structure of D(t), 2 bits, in
626      * IS-GPS-200E always == 0x1 */
627     uint8_t data_id;
628     /* SV/page id used for subframes 4 & 5, 6 bits */
629     uint8_t pageid;
630     /* tSVID, SV ID of the sat that transmitted this frame, 6 bits unsigned */
631     uint8_t tSVID;
632     /* TOW, Time of Week of NEXT message, 17 bits unsigned, scale 6, seconds */
633     uint32_t TOW17;
634     long l_TOW17;
635     /* integrity, URA bounds flag, 1 bit */
636     bool integrity;
637     /* alert, alert flag, SV URA and/or the SV User Differential Range
638      * Accuracy (UDRA) may be worse than indicated, 1 bit */
639     bool alert;
640     /* antispoof, A-S mode is ON in that SV, 1 bit */
641     bool antispoof;
642     int is_almanac;
643     union {
644         /* subframe 1, part of ephemeris, see IS-GPS-200E, Table 20-II
645 	 * and Table 20-I */
646 	struct {
647 	    /* WN, Week Number, 10 bits unsigned, scale 1, weeks */
648 	    uint16_t WN;
649 	    /* IODC, Issue of Data, Clock, 10 bits, unsigned,
650 	     * issued in 8 data ranges at the same time */
651 	    uint16_t IODC;
652 	    /* toc, clock data reference time, 16 bits, unsigned, seconds
653 	     * scale 2**4, issued in 8 data ranges at the same time */
654 	    uint16_t toc;
655 	    long l_toc;
656 	    /* l2, code on L2, 2 bits, bit map */
657 	    uint8_t l2;
658 	    /* l2p, L2 P data flag, 1 bit */
659 	    uint8_t l2p;
660 	    /* ura, SV accuracy, 4 bits unsigned index */
661 	    unsigned int ura;
662 	    /* hlth, SV health, 6 bits unsigned bitmap */
663 	    unsigned int hlth;
664 	    /* af0, SV clock correction constant term
665 	     * 22 bits signed, scale 2**-31, seconds */
666 	    int32_t af0;
667 	    double d_af0;
668 	    /* af1, SV clock correction first order term
669 	     * 22 bits signed, scale 2**-43, seconds/second */
670 	    int16_t af1;
671 	    double d_af1;
672 	    /* af2, SV clock correction second order term
673 	     * 8 bits signed, scale 2**-55, seconds/second**2 */
674 	    int8_t af2;
675 	    double d_af2;
676 	    /* Tgd,  L1-L2 correction term, 8 bits signed,  scale 2**-31,
677 	     * seconds */
678 	    int8_t Tgd;
679 	    double d_Tgd;
680 	} sub1;
681         /* subframe 2, part of ephemeris, see IS-GPS-200E, Table 20-II
682 	 * and Table 20-III */
683 	struct {
684 	    /* Issue of Data (Ephemeris),
685 	     * equal to the 8 LSBs of the 10 bit IODC of the same data set */
686 	    uint8_t IODE;
687 	    /* Age of Data Offset for the NMCT, 6 bits, scale 900,
688 	     * ignore if all ones, seconds */
689 	    uint8_t AODO;
690 	    uint16_t u_AODO;
691 	    /* fit, FIT interval flag, indicates a fit interval greater than
692 	     * 4 hour, 1 bit */
693 	    uint8_t fit;
694 	    /* toe, Reference Time Ephemeris, 16 bits unsigned, scale 2**4,
695 	     * seconds */
696 	    uint16_t toe;
697 	    long l_toe;
698 	    /* Crs, Amplitude of the Sine Harmonic Correction Term to the
699 	     * Orbit Radius, 16 bits, scale 2**-5, signed, meters */
700 	    int16_t Crs;
701 	    double d_Crs;
702 	    /* Cus, Amplitude of the Sine Harmonic Correction Term to the
703 	     * Argument of Latitude, 16 bits, signed, scale 2**-29, radians */
704 	    int16_t Cus;
705 	    double d_Cus;
706 	    /* Cuc, Amplitude of the Cosine Harmonic Correction Term to the
707 	     * Argument of Latitude, 16 bits, signed, scale 2**-29, radians */
708 	    int16_t Cuc;
709 	    double d_Cuc;
710 	    /* deltan, Mean Motion Difference From Computed Value
711 	     * Mean Motion Difference From Computed Value
712 	     * 16 bits, signed, scale 2**-43, semi-circles/sec */
713 	    int16_t deltan;
714 	    double d_deltan;
715 	    /* M0, Mean Anomaly at Reference Time, 32 bits signed,
716 	     * scale 2**-31, semi-circles */
717 	    int32_t M0;
718 	    double d_M0;
719 	    /* eccentricity, 32 bits, unsigned, scale 2**-33, dimensionless */
720 	    uint32_t e;
721 	    double d_eccentricity;
722 	    /* sqrt A, Square Root of the Semi-Major Axis
723 	     * 32 bits unsigned, scale 2**-19, square_root(meters) */
724 	    uint32_t sqrtA;
725 	    double d_sqrtA;
726 	} sub2;
727         /* subframe 3, part of ephemeris, see IS-GPS-200E, Table 20-II,
728 	 * Table 20-III */
729 	struct {
730 	    /* Issue of Data (Ephemeris), 8 bits, unsigned
731 	     * equal to the 8 LSBs of the 10 bit IODC of the same data set */
732 	    uint8_t IODE;
733 	    /* Rate of Inclination Angle, 14 bits signed, scale2**-43,
734 	     * semi-circles/sec */
735 	    int16_t IDOT;
736 	    double d_IDOT;
737 	    /* Cic, Amplitude of the Cosine Harmonic Correction Term to the
738 	     * Angle of Inclination, 16 bits signed, scale 2**-29, radians*/
739 	    int16_t Cic;
740 	    double d_Cic;
741 	    /* Cis, Amplitude of the Sine Harmonic Correction Term to the
742 	     * Angle of Inclination, 16 bits, unsigned, scale 2**-29, radians */
743 	    int16_t Cis;
744 	    double d_Cis;
745             /* Crc, Amplitude of the Cosine Harmonic Correction Term to the
746 	     * Orbit Radius, 16 bits signed, scale 2**-5, meters */
747 	    int16_t Crc;
748 	    double d_Crc;
749 	    /* i0, Inclination Angle at Reference Time, 32 bits, signed,
750 	     * scale 2**-31, semi-circles */
751 	    int32_t i0;
752 	    double d_i0;
753 	    /* Omega0, Longitude of Ascending Node of Orbit Plane at Weekly
754 	     * Epoch, 32 bits signed, semi-circles */
755 	    int32_t Omega0;
756 	    double d_Omega0;
757 	    /* omega, Argument of Perigee, 32 bits signed, scale 2**-31,
758 	     * semi-circles */
759 	    int32_t omega;
760 	    double d_omega;
761 	    /* Omega dot, Rate of Right Ascension, 24 bits signed,
762 	     * scale 2**-43, semi-circles/sec */
763 	    int32_t Omegad;
764 	    double d_Omegad;
765 	} sub3;
766 	struct {
767 	    struct almanac_t almanac;
768 	} sub4;
769 	/* subframe 4, page 13 */
770 	struct {
771 	    /* mapping ord ERD# to SV # is non trivial
772 	     * leave it alone.  See IS-GPS-200E Section 20.3.3.5.1.9 */
773 	    /* Estimated Range Deviation, 6 bits signed, meters */
774 	    char ERD[33];
775 	    /* ai, Availability Indicator, 2bits, bit map */
776 	    unsigned char ai;
777 	} sub4_13;
778 	/* subframe 4, page 17, system message, 23 chars, plus nul */
779 	struct {
780 	    char str[24];
781 	} sub4_17;
782 	/* subframe 4, page 18 */
783 	struct {
784 	    /* ionospheric and UTC data */
785 	    /* A0, Bias coefficient of GPS time scale relative to UTC time
786 	     * scale, 32 bits signed, scale 2**-30, seconds */
787 	    int32_t A0;
788 	    double d_A0;
789 	    /* A1, Drift coefficient of GPS time scale relative to UTC time
790 	     * scale, 24 bits signed, scale 2**-50, seconds/second */
791 	    int32_t A1;
792 	    double d_A1;
793 
794 	    /* alphaX, the four coefficients of a cubic equation representing
795 	     * the amplitude of the vertical delay */
796 
797 	    /* alpha0, 8 bits signed, scale w**-30, seconds */
798 	    int8_t alpha0;
799 	    double d_alpha0;
800 	    /* alpha1, 8 bits signed, scale w**-27, seconds/semi-circle */
801 	    int8_t alpha1;
802 	    double d_alpha1;
803 	    /* alpha2, 8 bits signed, scale w**-24, seconds/semi-circle**2 */
804 	    int8_t alpha2;
805 	    double d_alpha2;
806 	    /* alpha3, 8 bits signed, scale w**-24, seconds/semi-circle**3 */
807 	    int8_t alpha3;
808 	    double d_alpha3;
809 
810 	    /* betaX, the four coefficients of a cubic equation representing
811 	     * the period of the model */
812 
813 	    /* beta0, 8 bits signed, scale w**11, seconds */
814 	    int8_t beta0;
815 	    double d_beta0;
816 	    /* beta1, 8 bits signed, scale w**14, seconds/semi-circle */
817 	    int8_t beta1;
818 	    double d_beta1;
819 	    /* beta2, 8 bits signed, scale w**16, seconds/semi-circle**2 */
820 	    int8_t beta2;
821 	    double d_beta2;
822 	    /* beta3, 8 bits signed, scale w**16, seconds/semi-circle**3 */
823 	    int8_t beta3;
824 	    double d_beta3;
825 
826 	    /* leap (delta t ls), current leap second, 8 bits signed,
827 	     * scale 1, seconds */
828 	    int8_t leap;
829 	    /* lsf (delta t lsf), future leap second, 8 bits signed,
830 	     * scale 1, seconds */
831 	    int8_t lsf;
832 
833 	    /* tot, reference time for UTC data,
834 	     * 8 bits unsigned, scale 2**12, seconds */
835 	    uint8_t tot;
836 	    double d_tot;
837 
838 	    /* WNt, UTC reference week number, 8 bits unsigned, scale 1,
839 	     * weeks */
840 	    uint8_t WNt;
841 	    /* WNlsf, Leap second reference Week Number,
842 	     * 8 bits unsigned, scale 1, weeks */
843 	    uint8_t WNlsf;
844 	    /* DN, Leap second reference Day Number , 8 bits unsigned,
845 	     * scale 1, days */
846 	    uint8_t DN;
847 	} sub4_18;
848 	/* subframe 4, page 25 */
849 	struct {
850 	    /* svf, A-S status and the configuration code of each SV
851 	     * 4 bits unsigned, bitmap */
852 	    unsigned char svf[33];
853 	    /* svh, SV health data for SV 25 through 32
854 	     * 6 bits unsigned bitmap */
855 	    uint8_t svhx[8];
856 	} sub4_25;
857 	struct {
858 	    struct almanac_t almanac;
859 	} sub5;
860 	struct {
861 	    /* toa, Almanac reference Time, 8 bits unsigned, scale 2**12,
862 	     * seconds */
863 	    uint8_t toa;
864 	    long l_toa;
865 	    /* WNa, Week Number almanac, 8 bits, scale 2, GPS Week
866 	     * Number % 256 */
867 	    uint8_t WNa;
868 	    /* sv, SV health status, 6 bits, bitmap */
869 	    uint8_t sv[25];
870 	} sub5_25;
871     };
872 };
873 
874 typedef uint64_t gps_mask_t;
875 
876 /*
877  * Is an MMSI number that of an auxiliary associated with a mother ship?
878  * We need to be able to test this for decoding AIS Type 24 messages.
879  * According to <http://www.navcen.uscg.gov/marcomms/gmdss/mmsi.htm#format>,
880  * auxiliary-craft MMSIs have the form 98MIDXXXX, where MID is a country
881  * code and XXXX the vessel ID.
882  */
883 #define AIS_AUXILIARY_MMSI(n)	((n) / 10000000 == 98)
884 
885 /* N/A values and scaling constant for 25/24 bit lon/lat pairs */
886 #define AIS_LON3_NOT_AVAILABLE	181000
887 #define AIS_LAT3_NOT_AVAILABLE	91000
888 #define AIS_LATLON3_DIV	60000.0
889 
890 /* N/A values and scaling constant for 28/27 bit lon/lat pairs */
891 #define AIS_LON4_NOT_AVAILABLE	1810000
892 #define AIS_LAT4_NOT_AVAILABLE	910000
893 #define AIS_LATLON4_DIV	600000.0
894 
895 struct route_info {
896     unsigned int linkage;	/* Message Linkage ID */
897     unsigned int sender;	/* Sender Class */
898     unsigned int rtype;		/* Route Type */
899     unsigned int month;		/* Start month */
900     unsigned int day;		/* Start day */
901     unsigned int hour;		/* Start hour */
902     unsigned int minute;	/* Start minute */
903     unsigned int duration;	/* Duration */
904     int waycount;		/* Waypoint count */
905     struct waypoint_t {
906 	signed int lon;		/* Longitude */
907 	signed int lat;		/* Latitude */
908     } waypoints[16];
909 };
910 
911 struct ais_t
912 {
913     unsigned int	type;		/* message type */
914     unsigned int    	repeat;		/* Repeat indicator */
915     unsigned int	mmsi;		/* MMSI */
916     union {
917 	/* Types 1-3 Common navigation info */
918 	struct {
919 	    unsigned int status;		/* navigation status */
920 	    signed turn;			/* rate of turn */
921 #define AIS_TURN_HARD_LEFT	-127
922 #define AIS_TURN_HARD_RIGHT	127
923 #define AIS_TURN_NOT_AVAILABLE	128
924 	    unsigned int speed;			/* speed over ground in deciknots */
925 #define AIS_SPEED_NOT_AVAILABLE	1023
926 #define AIS_SPEED_FAST_MOVER	1022		/* >= 102.2 knots */
927 	    bool accuracy;			/* position accuracy */
928 #define AIS_LATLON_DIV	600000.0
929 	    int lon;				/* longitude */
930 #define AIS_LON_NOT_AVAILABLE	0x6791AC0
931 	    int lat;				/* latitude */
932 #define AIS_LAT_NOT_AVAILABLE	0x3412140
933 	    unsigned int course;		/* course over ground */
934 #define AIS_COURSE_NOT_AVAILABLE	3600
935 	    unsigned int heading;		/* true heading */
936 #define AIS_HEADING_NOT_AVAILABLE	511
937 	    unsigned int second;		/* seconds of UTC timestamp */
938 #define AIS_SEC_NOT_AVAILABLE	60
939 #define AIS_SEC_MANUAL		61
940 #define AIS_SEC_ESTIMATED	62
941 #define AIS_SEC_INOPERATIVE	63
942 	    unsigned int maneuver;	/* maneuver indicator */
943 	    //unsigned int spare;	spare bits */
944 	    bool raim;			/* RAIM flag */
945 	    unsigned int radio;		/* radio status bits */
946 	} type1;
947 	/* Type 4 - Base Station Report & Type 11 - UTC and Date Response */
948 	struct {
949 	    unsigned int year;			/* UTC year */
950 #define AIS_YEAR_NOT_AVAILABLE	0
951 	    unsigned int month;			/* UTC month */
952 #define AIS_MONTH_NOT_AVAILABLE	0
953 	    unsigned int day;			/* UTC day */
954 #define AIS_DAY_NOT_AVAILABLE	0
955 	    unsigned int hour;			/* UTC hour */
956 #define AIS_HOUR_NOT_AVAILABLE	24
957 	    unsigned int minute;		/* UTC minute */
958 #define AIS_MINUTE_NOT_AVAILABLE	60
959 	    unsigned int second;		/* UTC second */
960 #define AIS_SECOND_NOT_AVAILABLE	60
961 	    bool accuracy;		/* fix quality */
962 	    int lon;			/* longitude */
963 	    int lat;			/* latitude */
964 	    unsigned int epfd;		/* type of position fix device */
965 	    //unsigned int spare;	spare bits */
966 	    bool raim;			/* RAIM flag */
967 	    unsigned int radio;		/* radio status bits */
968 	} type4;
969 	/* Type 5 - Ship static and voyage related data */
970 	struct {
971 	    unsigned int ais_version;	/* AIS version level */
972 	    unsigned int imo;		/* IMO identification */
973 	    char callsign[7+1];		/* callsign */
974 #define AIS_SHIPNAME_MAXLEN	20
975 	    char shipname[AIS_SHIPNAME_MAXLEN+1];	/* vessel name */
976 	    unsigned int shiptype;	/* ship type code */
977 	    unsigned int to_bow;	/* dimension to bow */
978 	    unsigned int to_stern;	/* dimension to stern */
979 	    unsigned int to_port;	/* dimension to port */
980 	    unsigned int to_starboard;	/* dimension to starboard */
981 	    unsigned int epfd;		/* type of position fix deviuce */
982 	    unsigned int month;		/* UTC month */
983 	    unsigned int day;		/* UTC day */
984 	    unsigned int hour;		/* UTC hour */
985 	    unsigned int minute;	/* UTC minute */
986 	    unsigned int draught;	/* draft in meters */
987 	    char destination[20+1];	/* ship destination */
988 	    unsigned int dte;		/* data terminal enable */
989 	    //unsigned int spare;	spare bits */
990 	} type5;
991 	/* Type 6 - Addressed Binary Message */
992 	struct {
993 	    unsigned int seqno;		/* sequence number */
994 	    unsigned int dest_mmsi;	/* destination MMSI */
995 	    bool retransmit;		/* retransmit flag */
996 	    //unsigned int spare;	spare bit(s) */
997 	    unsigned int dac;           /* Application ID */
998 	    unsigned int fid;           /* Functional ID */
999 	    bool structured;		/* True match for DAC/FID? */
1000 #define AIS_TYPE6_BINARY_MAX	920	/* 920 bits */
1001 	    size_t bitcount;		/* bit count of the data */
1002 	    union {
1003 		char bitdata[(AIS_TYPE6_BINARY_MAX + 7) / 8];
1004 		/* Inland AIS - ETA at lock/bridge/terminal */
1005 		struct {
1006 		    char country[2+1];	/* UN Country Code */
1007 		    char locode[3+1];	/* UN/LOCODE */
1008 		    char section[5+1];	/* Fairway section */
1009 		    char terminal[5+1];	/* Terminal code */
1010 		    char hectometre[5+1];	/* Fairway hectometre */
1011 		    unsigned int month;	/* ETA month */
1012 		    unsigned int day;	/* ETA day */
1013 		    unsigned int hour;	/* ETA hour */
1014 		    unsigned int minute;	/* ETA minute */
1015 		    unsigned int tugs;	/* Assisting Tugs */
1016 		    unsigned int airdraught;	/* Air Draught */
1017 		} dac200fid21;
1018 		/* Inland AIS - ETA at lock/bridge/terminal */
1019 		struct {
1020 		    char country[2+1];	/* UN Country Code */
1021 		    char locode[3+1];	/* UN/LOCODE */
1022 		    char section[5+1];	/* Fairway section */
1023 		    char terminal[5+1];	/* Terminal code */
1024 		    char hectometre[5+1];	/* Fairway hectometre */
1025 		    unsigned int month;	/* RTA month */
1026 		    unsigned int day;	/* RTA day */
1027 		    unsigned int hour;	/* RTA hour */
1028 		    unsigned int minute;	/* RTA minute */
1029 		    unsigned int status;	/* Status */
1030 #define DAC200FID22_STATUS_OPERATIONAL	0
1031 #define DAC200FID22_STATUS_LIMITED	1
1032 #define DAC200FID22_STATUS_OUT_OF_ORDER	2
1033 #define DAC200FID22_STATUS_NOT_AVAILABLE	0
1034 		} dac200fid22;
1035 		/* Inland AIS - Number of persons on board */
1036 		struct {
1037 		    unsigned int crew;	/* # crew on board */
1038 		    unsigned int passengers;	/* # passengers on board */
1039 		    unsigned int personnel;	/* # personnel on board */
1040 #define DAC200FID55_COUNT_NOT_AVAILABLE	255
1041 		} dac200fid55;
1042 		/* GLA - AtoN monitoring data (UK/ROI) */
1043 		struct {
1044 		    unsigned int ana_int;       /* Analogue (internal) */
1045 		    unsigned int ana_ext1;      /* Analogue (external #1) */
1046 		    unsigned int ana_ext2;      /* Analogue (external #2) */
1047 		    unsigned int racon; /* RACON status */
1048 		    unsigned int light; /* Light status */
1049 		    bool alarm; /* Health alarm*/
1050 		    unsigned int stat_ext;      /* Status bits (external) */
1051 		    bool off_pos;    /* Off position status */
1052 		} dac235fid10;
1053 		/* IMO236 - Dangerous Cargo Indication */
1054 		struct {
1055 		    char lastport[5+1];		/* Last Port Of Call */
1056 		    unsigned int lmonth;	/* ETA month */
1057 		    unsigned int lday;		/* ETA day */
1058 		    unsigned int lhour;		/* ETA hour */
1059 		    unsigned int lminute;	/* ETA minute */
1060 		    char nextport[5+1];		/* Next Port Of Call */
1061 		    unsigned int nmonth;	/* ETA month */
1062 		    unsigned int nday;		/* ETA day */
1063 		    unsigned int nhour;		/* ETA hour */
1064 		    unsigned int nminute;	/* ETA minute */
1065 		    char dangerous[20+1];	/* Main Dangerous Good */
1066 		    char imdcat[4+1];		/* IMD Category */
1067 		    unsigned int unid;		/* UN Number */
1068 		    unsigned int amount;	/* Amount of Cargo */
1069 		    unsigned int unit;		/* Unit of Quantity */
1070 		} dac1fid12;
1071 		/* IMO236 - Extended Ship Static and Voyage Related Data */
1072 		struct {
1073 		    unsigned int airdraught;	/* Air Draught */
1074 		} dac1fid15;
1075 		/* IMO236 - Number of Persons on board */
1076 		struct {
1077 		    unsigned persons;	/* number of persons */
1078 		} dac1fid16;
1079 		/* IMO289 - Clearance Time To Enter Port */
1080 		struct {
1081 		    unsigned int linkage;	/* Message Linkage ID */
1082 		    unsigned int month;	/* Month (UTC) */
1083 		    unsigned int day;	/* Day (UTC) */
1084 		    unsigned int hour;	/* Hour (UTC) */
1085 		    unsigned int minute;	/* Minute (UTC) */
1086 		    char portname[20+1];	/* Name of Port & Berth */
1087 		    char destination[5+1];	/* Destination */
1088 		    signed int lon;	/* Longitude */
1089 		    signed int lat;	/* Latitude */
1090 		} dac1fid18;
1091 		/* IMO289 - Berthing Data (addressed) */
1092 		struct {
1093 		    unsigned int linkage;	/* Message Linkage ID */
1094 		    unsigned int berth_length;	/* Berth length */
1095 		    unsigned int berth_depth;	/* Berth Water Depth */
1096 		    unsigned int position;	/* Mooring Position */
1097 		    unsigned int month;	/* Month (UTC) */
1098 		    unsigned int day;	/* Day (UTC) */
1099 		    unsigned int hour;	/* Hour (UTC) */
1100 		    unsigned int minute;	/* Minute (UTC) */
1101 		    unsigned int availability;	/* Services Availability */
1102 		    unsigned int agent;	/* Agent */
1103 		    unsigned int fuel;	/* Bunker/fuel */
1104 		    unsigned int chandler;	/* Chandler */
1105 		    unsigned int stevedore;	/* Stevedore */
1106 		    unsigned int electrical;	/* Electrical */
1107 		    unsigned int water;	/* Potable water */
1108 		    unsigned int customs;	/* Customs house */
1109 		    unsigned int cartage;	/* Cartage */
1110 		    unsigned int crane;	/* Crane(s) */
1111 		    unsigned int lift;	/* Lift(s) */
1112 		    unsigned int medical;	/* Medical facilities */
1113 		    unsigned int navrepair;	/* Navigation repair */
1114 		    unsigned int provisions;	/* Provisions */
1115 		    unsigned int shiprepair;	/* Ship repair */
1116 		    unsigned int surveyor;	/* Surveyor */
1117 		    unsigned int steam;	/* Steam */
1118 		    unsigned int tugs;	/* Tugs */
1119 		    unsigned int solidwaste;	/* Waste disposal (solid) */
1120 		    unsigned int liquidwaste;	/* Waste disposal (liquid) */
1121 		    unsigned int hazardouswaste;	/* Waste disposal (hazardous) */
1122 		    unsigned int ballast;	/* Reserved ballast exchange */
1123 		    unsigned int additional;	/* Additional services */
1124 		    unsigned int regional1;	/* Regional reserved 1 */
1125 		    unsigned int regional2;	/* Regional reserved 2 */
1126 		    unsigned int future1;	/* Reserved for future */
1127 		    unsigned int future2;	/* Reserved for future */
1128 		    char berth_name[20+1];	/* Name of Berth */
1129 		    signed int berth_lon;	/* Longitude */
1130 		    signed int berth_lat;	/* Latitude */
1131 		} dac1fid20;
1132 		/* IMO289 - Weather observation report from ship */
1133 		/*** WORK IN PROGRESS - NOT YET DECODED ***/
1134 		struct {
1135 		    bool wmo;			/* true if WMO variant */
1136 		    union {
1137 			struct {
1138 			    char location[20+1];	/* Location */
1139 			    signed int lon;		/* Longitude */
1140 			    signed int lat;		/* Latitude */
1141 			    unsigned int day;		/* Report day */
1142 			    unsigned int hour;		/* Report hour */
1143 			    unsigned int minute;	/* Report minute */
1144 			    bool vislimit;		/* Max range? */
1145 			    unsigned int visibility;	/* Units of 0.1 nm */
1146 #define DAC1FID21_VISIBILITY_NOT_AVAILABLE	127
1147 #define DAC1FID21_VISIBILITY_SCALE		10.0
1148 			    unsigned humidity;		/* units of 1% */
1149 			    unsigned int wspeed;	/* average wind speed */
1150 			    unsigned int wgust;		/* wind gust */
1151 #define DAC1FID21_WSPEED_NOT_AVAILABLE		127
1152 			    unsigned int wdir;		/* wind direction */
1153 #define DAC1FID21_WDIR_NOT_AVAILABLE		360
1154 			    unsigned int pressure;	/* air pressure, hpa */
1155 #define DAC1FID21_NONWMO_PRESSURE_NOT_AVAILABLE	403
1156 #define DAC1FID21_NONWMO_PRESSURE_HIGH		402	/* > 1200hPa */
1157 #define DAC1FID21_NONWMO_PRESSURE_OFFSET		400	/* N/A */
1158 			    unsigned int pressuretend;	/* tendency */
1159 		    	    int airtemp;		/* temp, units 0.1C */
1160 #define DAC1FID21_AIRTEMP_NOT_AVAILABLE		-1024
1161 #define DAC1FID21_AIRTEMP_SCALE			10.0
1162 			    unsigned int watertemp;	/* units 0.1degC */
1163 #define DAC1FID21_WATERTEMP_NOT_AVAILABLE	501
1164 #define DAC1FID21_WATERTEMP_SCALE		10.0
1165 			    unsigned int waveperiod;	/* in seconds */
1166 #define DAC1FID21_WAVEPERIOD_NOT_AVAILABLE	63
1167 			    unsigned int wavedir;	/* direction in deg */
1168 #define DAC1FID21_WAVEDIR_NOT_AVAILABLE		360
1169 			    unsigned int swellheight;	/* in decimeters */
1170 			    unsigned int swellperiod;	/* in seconds */
1171 			    unsigned int swelldir;	/* direction in deg */
1172 			} nonwmo_obs;
1173 			struct {
1174 			    signed int lon;		/* Longitude */
1175 			    signed int lat;		/* Latitude */
1176 			    unsigned int month;		/* UTC month */
1177 			    unsigned int day;		/* Report day */
1178 			    unsigned int hour;		/* Report hour */
1179 			    unsigned int minute;	/* Report minute */
1180 			    unsigned int course;	/* course over ground */
1181 			    unsigned int speed;		/* speed, m/s */
1182 #define DAC1FID21_SOG_NOT_AVAILABLE		31
1183 #define DAC1FID21_SOG_HIGH_SPEED		30
1184 #define DAC1FID21_SOG_SCALE			2.0
1185 			    unsigned int heading;	/* true heading */
1186 #define DAC1FID21_HDG_NOT_AVAILABLE		127
1187 #define DAC1FID21_HDG_SCALE			5.0
1188 			    unsigned int pressure;	/* units of hPa * 0.1 */
1189 #define DAC1FID21_WMO_PRESSURE_SCALE		10
1190 #define DAC1FID21_WMO_PRESSURE_OFFSET		90.0
1191 			    unsigned int pdelta;	/* units of hPa * 0.1 */
1192 #define DAC1FID21_PDELTA_SCALE			10
1193 #define DAC1FID21_PDELTA_OFFSET			50.0
1194 			    unsigned int ptend;		/* enumerated */
1195 			    unsigned int twinddir;	/* in 5 degree steps */
1196 #define DAC1FID21_TWINDDIR_NOT_AVAILABLE	127
1197 			    unsigned int twindspeed;	/* meters per second */
1198 #define DAC1FID21_TWINDSPEED_SCALE		2
1199 #define DAC1FID21_RWINDSPEED_NOT_AVAILABLE	255
1200 			    unsigned int rwinddir;	/* in 5 degree steps */
1201 #define DAC1FID21_RWINDDIR_NOT_AVAILABLE	127
1202 			    unsigned int rwindspeed;	/* meters per second */
1203 #define DAC1FID21_RWINDSPEED_SCALE		2
1204 #define DAC1FID21_RWINDSPEED_NOT_AVAILABLE	255
1205 			    unsigned int mgustspeed;	/* meters per second */
1206 #define DAC1FID21_MGUSTSPEED_SCALE		2
1207 #define DAC1FID21_MGUSTSPEED_NOT_AVAILABLE	255
1208 			    unsigned int mgustdir;	/* in 5 degree steps */
1209 #define DAC1FID21_MGUSTDIR_NOT_AVAILABLE	127
1210 			    unsigned int airtemp;	/* degress K */
1211 #define DAC1FID21_AIRTEMP_OFFSET		223
1212 			    unsigned humidity;		/* units of 1% */
1213 #define DAC1FID21_HUMIDITY_NOT_VAILABLE		127
1214 			    /* some trailing fields are missing */
1215 			} wmo_obs;
1216 		    };
1217 	        } dac1fid21;
1218 		/*** WORK IN PROGRESS ENDS HERE ***/
1219 		/* IMO289 - Dangerous Cargo Indication */
1220 		struct {
1221 		    unsigned int unit;	/* Unit of Quantity */
1222 		    unsigned int amount;	/* Amount of Cargo */
1223 		    int ncargos;
1224 		    struct cargo_t {
1225 			unsigned int code;	/* Cargo code */
1226 			unsigned int subtype;	/* Cargo subtype */
1227 		    } cargos[28];
1228 		} dac1fid25;
1229 		/* IMO289 - Route info (addressed) */
1230 		struct route_info dac1fid28;
1231 		/* IMO289 - Text message (addressed) */
1232 		struct {
1233 		    unsigned int linkage;
1234 #define AIS_DAC1FID30_TEXT_MAX	154	/* 920 bits of six-bit, plus NUL */
1235 		    char text[AIS_DAC1FID30_TEXT_MAX];
1236 		} dac1fid30;
1237 		/* IMO289 & IMO236 - Tidal Window */
1238 		struct {
1239 		    unsigned int month;	/* Month */
1240 		    unsigned int day;	/* Day */
1241 		    signed int ntidals;
1242 		    struct tidal_t {
1243 			signed int lon;	/* Longitude */
1244 			signed int lat;	/* Latitude */
1245 			unsigned int from_hour;	/* From UTC Hour */
1246 			unsigned int from_min;	/* From UTC Minute */
1247 			unsigned int to_hour;	/* To UTC Hour */
1248 			unsigned int to_min;	/* To UTC Minute */
1249 #define DAC1FID32_CDIR_NOT_AVAILABLE		360
1250 			unsigned int cdir;	/* Current Dir. Predicted */
1251 #define DAC1FID32_CSPEED_NOT_AVAILABLE		127
1252 			unsigned int cspeed;	/* Current Speed Predicted */
1253 		    } tidals[3];
1254 		} dac1fid32;
1255 	    };
1256 	} type6;
1257 	/* Type 7 - Binary Acknowledge */
1258 	struct {
1259 	    unsigned int mmsi1;
1260 	    unsigned int mmsi2;
1261 	    unsigned int mmsi3;
1262 	    unsigned int mmsi4;
1263 	    /* spares ignored, they're only padding here */
1264 	} type7;
1265 	/* Type 8 - Broadcast Binary Message */
1266 	struct {
1267 	    unsigned int dac;       	/* Designated Area Code */
1268 	    unsigned int fid;       	/* Functional ID */
1269 #define AIS_TYPE8_BINARY_MAX	952	/* 952 bits */
1270 	    size_t bitcount;		/* bit count of the data */
1271 	    bool structured;		/* True match for DAC/FID? */
1272 	    union {
1273 		char bitdata[(AIS_TYPE8_BINARY_MAX + 7) / 8];
1274 		/* Inland static ship and voyage-related data */
1275 		struct {
1276 		    char vin[8+1];      	/* European Vessel ID */
1277 		    unsigned int length;	/* Length of ship */
1278 		    unsigned int beam;  	/* Beam of ship */
1279 		    unsigned int shiptype;	/* Ship/combination type */
1280 		    unsigned int hazard;	/* Hazardous cargo */
1281 #define DAC200FID10_HAZARD_MAX	5
1282 		    unsigned int draught;	/* Draught */
1283 		    unsigned int loaded;	/* Loaded/Unloaded */
1284 		    bool speed_q;	/* Speed inf. quality */
1285 		    bool course_q;	/* Course inf. quality */
1286 		    bool heading_q;	/* Heading inf. quality */
1287 		} dac200fid10;
1288 		/* Inland AIS EMMA Warning */
1289 		struct {
1290 		    unsigned int start_year;	/* Start Year */
1291 		    unsigned int start_month;	/* Start Month */
1292 		    unsigned int start_day;	/* Start Day */
1293 		    unsigned int end_year;	/* End Year */
1294 		    unsigned int end_month;	/* End Month */
1295 		    unsigned int end_day;	/* End Day */
1296 		    unsigned int start_hour;	/* Start Hour */
1297 		    unsigned int start_minute;	/* Start Minute */
1298 		    unsigned int end_hour;	/* End Hour */
1299 		    unsigned int end_minute;	/* End Minute */
1300 		    signed int start_lon;	/* Start Longitude */
1301 		    signed int start_lat;	/* Start Latitude */
1302 		    signed int end_lon;	/* End Longitude */
1303 		    signed int end_lat;	/* End Latitude */
1304 		    unsigned int type;	/* Type */
1305 #define DAC200FID23_TYPE_UNKNOWN		0
1306 		    signed int min;	/* Min value */
1307 #define DAC200FID23_MIN_UNKNOWN			255
1308 		    signed int max;	/* Max value */
1309 #define DAC200FID23_MAX_UNKNOWN			255
1310 		    unsigned int intensity;	/* Classification */
1311 #define DAC200FID23_CLASS_UNKNOWN		0
1312 		    unsigned int wind;	/* Wind Direction */
1313 #define DAC200FID23_WIND_UNKNOWN		0
1314 		} dac200fid23;
1315 		struct {
1316 		    char country[2+1];	/* UN Country Code */
1317 		    signed int ngauges;
1318 		    struct gauge_t {
1319 			unsigned int id;	/* Gauge ID */
1320 #define DAC200FID24_GAUGE_ID_UNKNOWN		0
1321 			signed int level;	/* Water Level */
1322 #define DAC200FID24_GAUGE_LEVEL_UNKNOWN		0
1323 		    } gauges[4];
1324 		} dac200fid24;
1325 		struct {
1326 		    signed int lon;	/* Signal Longitude */
1327 		    signed int lat;	/* Signal Latitude */
1328 		    unsigned int form;	/* Signal form */
1329 #define DAC200FID40_FORM_UNKNOWN		0
1330 		    unsigned int facing;	/* Signal orientation */
1331 #define DAC200FID40_FACING_UNKNOWN		0
1332 		    unsigned int direction;	/* Direction of impact */
1333 #define DAC200FID40_DIRECTION_UNKNOWN		0
1334 		    unsigned int status;	/* Light Status */
1335 #define DAC200FID40_STATUS_UNKNOWN		0
1336 		} dac200fid40;
1337 		/* IMO236  - Meteorological-Hydrological data
1338 		 * Trial message, not to be used after January 2013
1339 		 * Replaced by IMO289 (DAC 1, FID 31)
1340 		 */
1341 		struct {
1342 #define DAC1FID11_LATLON_SCALE			1000
1343 		    int lon;			/* longitude in minutes * .001 */
1344 #define DAC1FID11_LON_NOT_AVAILABLE		0xFFFFFF
1345 		    int lat;			/* latitude in minutes * .001 */
1346 #define DAC1FID11_LAT_NOT_AVAILABLE		0x7FFFFF
1347 		    unsigned int day;		/* UTC day */
1348 		    unsigned int hour;		/* UTC hour */
1349 		    unsigned int minute;	/* UTC minute */
1350 		    unsigned int wspeed;	/* average wind speed */
1351 		    unsigned int wgust;		/* wind gust */
1352 #define DAC1FID11_WSPEED_NOT_AVAILABLE		127
1353 		    unsigned int wdir;		/* wind direction */
1354 		    unsigned int wgustdir;	/* wind gust direction */
1355 #define DAC1FID11_WDIR_NOT_AVAILABLE		511
1356 		    unsigned int airtemp;	/* temperature, units 0.1C */
1357 #define DAC1FID11_AIRTEMP_NOT_AVAILABLE		2047
1358 #define DAC1FID11_AIRTEMP_OFFSET		600
1359 #define DAC1FID11_AIRTEMP_DIV			10.0
1360 		    unsigned int humidity;	/* relative humidity, % */
1361 #define DAC1FID11_HUMIDITY_NOT_AVAILABLE	127
1362 		    unsigned int dewpoint;	/* dew point, units 0.1C */
1363 #define DAC1FID11_DEWPOINT_NOT_AVAILABLE	1023
1364 #define DAC1FID11_DEWPOINT_OFFSET		200
1365 #define DAC1FID11_DEWPOINT_DIV		10.0
1366 		    unsigned int pressure;	/* air pressure, hpa */
1367 #define DAC1FID11_PRESSURE_NOT_AVAILABLE	511
1368 #define DAC1FID11_PRESSURE_OFFSET		-800
1369 		    unsigned int pressuretend;	/* tendency */
1370 #define DAC1FID11_PRESSURETREND_NOT_AVAILABLE	3
1371 		    unsigned int visibility;	/* units 0.1 nautical miles */
1372 #define DAC1FID11_VISIBILITY_NOT_AVAILABLE	255
1373 #define DAC1FID11_VISIBILITY_DIV		10.0
1374 		    int waterlevel;		/* decimeters */
1375 #define DAC1FID11_WATERLEVEL_NOT_AVAILABLE	511
1376 #define DAC1FID11_WATERLEVEL_OFFSET		100
1377 #define DAC1FID11_WATERLEVEL_DIV		10.0
1378 		    unsigned int leveltrend;	/* water level trend code */
1379 #define DAC1FID11_WATERLEVELTREND_NOT_AVAILABLE	3
1380 		    unsigned int cspeed;	/* surface current speed in deciknots */
1381 #define DAC1FID11_CSPEED_NOT_AVAILABLE		255
1382 #define DAC1FID11_CSPEED_DIV			10.0
1383 		    unsigned int cdir;		/* surface current dir., degrees */
1384 #define DAC1FID11_CDIR_NOT_AVAILABLE		511
1385 		    unsigned int cspeed2;	/* current speed in deciknots */
1386 		    unsigned int cdir2;		/* current dir., degrees */
1387 		    unsigned int cdepth2;	/* measurement depth, m */
1388 #define DAC1FID11_CDEPTH_NOT_AVAILABLE		31
1389 		    unsigned int cspeed3;	/* current speed in deciknots */
1390 		    unsigned int cdir3;		/* current dir., degrees */
1391 		    unsigned int cdepth3;	/* measurement depth, m */
1392 		    unsigned int waveheight;	/* in decimeters */
1393 #define DAC1FID11_WAVEHEIGHT_NOT_AVAILABLE	255
1394 #define DAC1FID11_WAVEHEIGHT_DIV		10.0
1395 		    unsigned int waveperiod;	/* in seconds */
1396 #define DAC1FID11_WAVEPERIOD_NOT_AVAILABLE	63
1397 		    unsigned int wavedir;	/* direction in degrees */
1398 #define DAC1FID11_WAVEDIR_NOT_AVAILABLE		511
1399 		    unsigned int swellheight;	/* in decimeters */
1400 		    unsigned int swellperiod;	/* in seconds */
1401 		    unsigned int swelldir;	/* direction in degrees */
1402 		    unsigned int seastate;	/* Beaufort scale, 0-12 */
1403 #define DAC1FID11_SEASTATE_NOT_AVAILABLE	15
1404 		    unsigned int watertemp;	/* units 0.1deg Celsius */
1405 #define DAC1FID11_WATERTEMP_NOT_AVAILABLE	1023
1406 #define DAC1FID11_WATERTEMP_OFFSET		100
1407 #define DAC1FID11_WATERTEMP_DIV		10.0
1408 		    unsigned int preciptype;	/* 0-7, enumerated */
1409 #define DAC1FID11_PRECIPTYPE_NOT_AVAILABLE	7
1410 		    unsigned int salinity;	/* units of 0.1ppt */
1411 #define DAC1FID11_SALINITY_NOT_AVAILABLE	511
1412 #define DAC1FID11_SALINITY_DIV		10.0
1413 		    unsigned int ice;		/* is there sea ice? */
1414 #define DAC1FID11_ICE_NOT_AVAILABLE		3
1415 		} dac1fid11;
1416 		/* IMO236 - Fairway Closed */
1417 		struct {
1418 		    char reason[20+1];		/* Reason For Closing */
1419 		    char closefrom[20+1];	/* Location Of Closing From */
1420 		    char closeto[20+1];		/* Location of Closing To */
1421 		    unsigned int radius;	/* Radius extension */
1422 #define AIS_DAC1FID13_RADIUS_NOT_AVAILABLE 10001
1423 		    unsigned int extunit;	/* Unit of extension */
1424 #define AIS_DAC1FID13_EXTUNIT_NOT_AVAILABLE 0
1425 		    unsigned int fday;		/* From day (UTC) */
1426 		    unsigned int fmonth;	/* From month (UTC) */
1427 		    unsigned int fhour;		/* From hour (UTC) */
1428 		    unsigned int fminute;	/* From minute (UTC) */
1429 		    unsigned int tday;		/* To day (UTC) */
1430 		    unsigned int tmonth;	/* To month (UTC) */
1431 		    unsigned int thour;		/* To hour (UTC) */
1432 		    unsigned int tminute;	/* To minute (UTC) */
1433 		} dac1fid13;
1434 	        /* IMO236 - Extended ship and voyage data */
1435 		struct {
1436 		    unsigned int airdraught;	/* Air Draught */
1437 		} dac1fid15;
1438 		/* IMO286 - Number of Persons on board */
1439 		struct {
1440 		    unsigned persons;	/* number of persons */
1441 		} dac1fid16;
1442 		/* IMO289 - VTS-generated/Synthetic Targets */
1443 		struct {
1444 		    signed int ntargets;
1445 		    struct target_t {
1446 #define DAC1FID17_IDTYPE_MMSI		0
1447 #define DAC1FID17_IDTYPE_IMO		1
1448 #define DAC1FID17_IDTYPE_CALLSIGN	2
1449 #define DAC1FID17_IDTYPE_OTHER		3
1450 			unsigned int idtype;	/* Identifier type */
1451 			union target_id {	/* Target identifier */
1452 			    unsigned int mmsi;
1453 			    unsigned int imo;
1454 #define DAC1FID17_ID_LENGTH		7
1455 			    char callsign[DAC1FID17_ID_LENGTH+1];
1456 			    char other[DAC1FID17_ID_LENGTH+1];
1457 			} id;
1458 			signed int lat;		/* Latitude */
1459 			signed int lon;		/* Longitude */
1460 #define DAC1FID17_COURSE_NOT_AVAILABLE		360
1461 			unsigned int course;	/* Course Over Ground */
1462 			unsigned int second;	/* Time Stamp */
1463 #define DAC1FID17_SPEED_NOT_AVAILABLE		255
1464 			unsigned int speed;	/* Speed Over Ground */
1465 		    } targets[4];
1466 		} dac1fid17;
1467 		/* IMO 289 - Marine Traffic Signal */
1468 		struct {
1469 		    unsigned int linkage;	/* Message Linkage ID */
1470 		    char station[20+1];		/* Name of Signal Station */
1471 		    signed int lon;		/* Longitude */
1472 		    signed int lat;		/* Latitude */
1473 		    unsigned int status;	/* Status of Signal */
1474 		    unsigned int signal;	/* Signal In Service */
1475 		    unsigned int hour;		/* UTC hour */
1476 		    unsigned int minute;	/* UTC minute */
1477 		    unsigned int nextsignal;	/* Expected Next Signal */
1478 		} dac1fid19;
1479 		/* IMO289 - Route info (broadcast) */
1480 		struct route_info dac1fid27;
1481 		/* IMO289 - Text message (broadcast) */
1482 		struct {
1483 		    unsigned int linkage;
1484 #define AIS_DAC1FID29_TEXT_MAX	162	/* 920 bits of six-bit, plus NUL */
1485 		    char text[AIS_DAC1FID29_TEXT_MAX];
1486 		} dac1fid29;
1487 		/* IMO289 - Meteorological-Hydrological data */
1488 		struct {
1489 		    bool accuracy;	/* position accuracy, <10m if true */
1490 #define DAC1FID31_LATLON_SCALE	1000
1491 		    int lon;		/* longitude in minutes * .001 */
1492 #define DAC1FID31_LON_NOT_AVAILABLE	(181*60*DAC1FID31_LATLON_SCALE)
1493 		    int lat;		/* longitude in minutes * .001 */
1494 #define DAC1FID31_LAT_NOT_AVAILABLE	(91*60*DAC1FID31_LATLON_SCALE)
1495 		    unsigned int day;		/* UTC day */
1496 		    unsigned int hour;		/* UTC hour */
1497 		    unsigned int minute;	/* UTC minute */
1498 		    unsigned int wspeed;	/* average wind speed */
1499 		    unsigned int wgust;		/* wind gust */
1500 #define DAC1FID31_WIND_HIGH			126
1501 #define DAC1FID31_WIND_NOT_AVAILABLE		127
1502 		    unsigned int wdir;		/* wind direction */
1503 		    unsigned int wgustdir;	/* wind gust direction */
1504 #define DAC1FID31_DIR_NOT_AVAILABLE		360
1505 		    int airtemp;		/* temperature, units 0.1C */
1506 #define DAC1FID31_AIRTEMP_NOT_AVAILABLE		-1024
1507 #define DAC1FID31_AIRTEMP_DIV			10.0
1508 		    unsigned int humidity;	/* relative humidity, % */
1509 #define DAC1FID31_HUMIDITY_NOT_AVAILABLE	101
1510 		    int dewpoint;		/* dew point, units 0.1C */
1511 #define DAC1FID31_DEWPOINT_NOT_AVAILABLE	501
1512 #define DAC1FID31_DEWPOINT_DIV		10.0
1513 		    unsigned int pressure;	/* air pressure, hpa */
1514 #define DAC1FID31_PRESSURE_NOT_AVAILABLE	511
1515 #define DAC1FID31_PRESSURE_HIGH			402
1516 #define DAC1FID31_PRESSURE_OFFSET		-799
1517 		    unsigned int pressuretend;	/* tendency */
1518 #define DAC1FID31_PRESSURETEND_NOT_AVAILABLE	3
1519 		    bool visgreater;            /* visibility greater than */
1520 		    unsigned int visibility;	/* units 0.1 nautical miles */
1521 #define DAC1FID31_VISIBILITY_NOT_AVAILABLE	127
1522 #define DAC1FID31_VISIBILITY_DIV		10.0
1523 		    int waterlevel;		/* cm */
1524 #define DAC1FID31_WATERLEVEL_NOT_AVAILABLE	4001
1525 #define DAC1FID31_WATERLEVEL_OFFSET		1000
1526 #define DAC1FID31_WATERLEVEL_DIV		100.0
1527 		    unsigned int leveltrend;	/* water level trend code */
1528 #define DAC1FID31_WATERLEVELTREND_NOT_AVAILABLE	3
1529 		    unsigned int cspeed;	/* current speed in deciknots */
1530 #define DAC1FID31_CSPEED_NOT_AVAILABLE		255
1531 #define DAC1FID31_CSPEED_DIV			10.0
1532 		    unsigned int cdir;		/* current dir., degrees */
1533 		    unsigned int cspeed2;	/* current speed in deciknots */
1534 		    unsigned int cdir2;		/* current dir., degrees */
1535 		    unsigned int cdepth2;	/* measurement depth, 0.1m */
1536 #define DAC1FID31_CDEPTH_NOT_AVAILABLE		301
1537 #define DAC1FID31_CDEPTH_SCALE			10.0
1538 		    unsigned int cspeed3;	/* current speed in deciknots */
1539 		    unsigned int cdir3;		/* current dir., degrees */
1540 		    unsigned int cdepth3;	/* measurement depth, 0.1m */
1541 		    unsigned int waveheight;	/* in decimeters */
1542 #define DAC1FID31_HEIGHT_NOT_AVAILABLE		31
1543 #define DAC1FID31_HEIGHT_DIV			10.0
1544 		    unsigned int waveperiod;	/* in seconds */
1545 #define DAC1FID31_PERIOD_NOT_AVAILABLE		63
1546 		    unsigned int wavedir;	/* direction in degrees */
1547 		    unsigned int swellheight;	/* in decimeters */
1548 		    unsigned int swellperiod;	/* in seconds */
1549 		    unsigned int swelldir;	/* direction in degrees */
1550 		    unsigned int seastate;	/* Beaufort scale, 0-12 */
1551 #define DAC1FID31_SEASTATE_NOT_AVAILABLE	15
1552 		    int watertemp;		/* units 0.1deg Celsius */
1553 #define DAC1FID31_WATERTEMP_NOT_AVAILABLE	601
1554 #define DAC1FID31_WATERTEMP_DIV		10.0
1555 		    unsigned int preciptype;	/* 0-7, enumerated */
1556 #define DAC1FID31_PRECIPTYPE_NOT_AVAILABLE	7
1557 		    unsigned int salinity;	/* units of 0.1 permil (ca. PSU) */
1558 #define DAC1FID31_SALINITY_NOT_AVAILABLE	510
1559 #define DAC1FID31_SALINITY_DIV		10.0
1560 		    unsigned int ice;		/* is there sea ice? */
1561 #define DAC1FID31_ICE_NOT_AVAILABLE		3
1562 		} dac1fid31;
1563 	    };
1564 	} type8;
1565 	/* Type 9 - Standard SAR Aircraft Position Report */
1566 	struct {
1567 	    unsigned int alt;		/* altitude in meters */
1568 #define AIS_ALT_NOT_AVAILABLE	4095
1569 #define AIS_ALT_HIGH    	4094	/* 4094 meters or higher */
1570 	    unsigned int speed;		/* speed over ground in deciknots */
1571 #define AIS_SAR_SPEED_NOT_AVAILABLE	1023
1572 #define AIS_SAR_FAST_MOVER  	1022
1573 	    bool accuracy;		/* position accuracy */
1574 	    int lon;			/* longitude */
1575 	    int lat;			/* latitude */
1576 	    unsigned int course;	/* course over ground */
1577 	    unsigned int second;	/* seconds of UTC timestamp */
1578 	    unsigned int regional;	/* regional reserved */
1579 	    unsigned int dte;		/* data terminal enable */
1580 	    //unsigned int spare;	spare bits */
1581 	    bool assigned;		/* assigned-mode flag */
1582 	    bool raim;			/* RAIM flag */
1583 	    unsigned int radio;		/* radio status bits */
1584 	} type9;
1585 	/* Type 10 - UTC/Date Inquiry */
1586 	struct {
1587 	    //unsigned int spare;
1588 	    unsigned int dest_mmsi;	/* destination MMSI */
1589 	    //unsigned int spare2;
1590 	} type10;
1591 	/* Type 12 - Safety-Related Message */
1592 	struct {
1593 	    unsigned int seqno;		/* sequence number */
1594 	    unsigned int dest_mmsi;	/* destination MMSI */
1595 	    bool retransmit;		/* retransmit flag */
1596 	    //unsigned int spare;	spare bit(s) */
1597 #define AIS_TYPE12_TEXT_MAX	157	/* 936 bits of six-bit, plus NUL */
1598 	    char text[AIS_TYPE12_TEXT_MAX];
1599 	} type12;
1600 	/* Type 14 - Safety-Related Broadcast Message */
1601 	struct {
1602 	    //unsigned int spare;	spare bit(s) */
1603 #define AIS_TYPE14_TEXT_MAX	161	/* 952 bits of six-bit, plus NUL */
1604 	    char text[AIS_TYPE14_TEXT_MAX];
1605 	} type14;
1606 	/* Type 15 - Interrogation */
1607 	struct {
1608 	    //unsigned int spare;	spare bit(s) */
1609 	    unsigned int mmsi1;
1610 	    unsigned int type1_1;
1611 	    unsigned int offset1_1;
1612 	    //unsigned int spare2;	spare bit(s) */
1613 	    unsigned int type1_2;
1614 	    unsigned int offset1_2;
1615 	    //unsigned int spare3;	spare bit(s) */
1616 	    unsigned int mmsi2;
1617 	    unsigned int type2_1;
1618 	    unsigned int offset2_1;
1619 	    //unsigned int spare4;	spare bit(s) */
1620 	} type15;
1621 	/* Type 16 - Assigned Mode Command */
1622 	struct {
1623 	    //unsigned int spare;	spare bit(s) */
1624 	    unsigned int mmsi1;
1625 	    unsigned int offset1;
1626 	    unsigned int increment1;
1627 	    unsigned int mmsi2;
1628 	    unsigned int offset2;
1629 	    unsigned int increment2;
1630 	} type16;
1631 	/* Type 17 - GNSS Broadcast Binary Message */
1632 	struct {
1633 	    //unsigned int spare;	spare bit(s) */
1634 #define AIS_GNSS_LATLON_DIV	600.0
1635 	    int lon;			/* longitude */
1636 	    int lat;			/* latitude */
1637 	    //unsigned int spare2;	spare bit(s) */
1638 #define AIS_TYPE17_BINARY_MAX	736	/* 920 bits */
1639 	    size_t bitcount;		/* bit count of the data */
1640 	    char bitdata[(AIS_TYPE17_BINARY_MAX + 7) / 8];
1641 	} type17;
1642 	/* Type 18 - Standard Class B CS Position Report */
1643 	struct {
1644 	    unsigned int reserved;	/* altitude in meters */
1645 	    unsigned int speed;		/* speed over ground in deciknots */
1646 	    bool accuracy;		/* position accuracy */
1647 	    int lon;			/* longitude */
1648 #define AIS_GNS_LON_NOT_AVAILABLE	0x1a838
1649 	    int lat;			/* latitude */
1650 #define AIS_GNS_LAT_NOT_AVAILABLE	0xd548
1651 	    unsigned int course;	/* course over ground */
1652 	    unsigned int heading;	/* true heading */
1653 	    unsigned int second;	/* seconds of UTC timestamp */
1654 	    unsigned int regional;	/* regional reserved */
1655 	    bool cs;     		/* carrier sense unit flag */
1656 	    bool display;		/* unit has attached display? */
1657 	    bool dsc;   		/* unit attached to radio with DSC? */
1658 	    bool band;   		/* unit can switch frequency bands? */
1659 	    bool msg22;	        	/* can accept Message 22 management? */
1660 	    bool assigned;		/* assigned-mode flag */
1661 	    bool raim;			/* RAIM flag */
1662 	    unsigned int radio;		/* radio status bits */
1663 	} type18;
1664 	/* Type 19 - Extended Class B CS Position Report */
1665 	struct {
1666 	    unsigned int reserved;	/* altitude in meters */
1667 	    unsigned int speed;		/* speed over ground in deciknots */
1668 	    bool accuracy;		/* position accuracy */
1669 	    int lon;			/* longitude */
1670 	    int lat;			/* latitude */
1671 	    unsigned int course;	/* course over ground */
1672 	    unsigned int heading;	/* true heading */
1673 	    unsigned int second;	/* seconds of UTC timestamp */
1674 	    unsigned int regional;	/* regional reserved */
1675 	    char shipname[AIS_SHIPNAME_MAXLEN+1];		/* ship name */
1676 	    unsigned int shiptype;	/* ship type code */
1677 	    unsigned int to_bow;	/* dimension to bow */
1678 	    unsigned int to_stern;	/* dimension to stern */
1679 	    unsigned int to_port;	/* dimension to port */
1680 	    unsigned int to_starboard;	/* dimension to starboard */
1681 	    unsigned int epfd;		/* type of position fix deviuce */
1682 	    bool raim;			/* RAIM flag */
1683 	    unsigned int dte;    	/* date terminal enable */
1684 	    bool assigned;		/* assigned-mode flag */
1685 	    //unsigned int spare;	spare bits */
1686 	} type19;
1687 	/* Type 20 - Data Link Management Message */
1688 	struct {
1689 	    //unsigned int spare;	spare bit(s) */
1690 	    unsigned int offset1;	/* TDMA slot offset */
1691 	    unsigned int number1;	/* number of xlots to allocate */
1692 	    unsigned int timeout1;	/* allocation timeout */
1693 	    unsigned int increment1;	/* repeat increment */
1694 	    unsigned int offset2;	/* TDMA slot offset */
1695 	    unsigned int number2;	/* number of xlots to allocate */
1696 	    unsigned int timeout2;	/* allocation timeout */
1697 	    unsigned int increment2;	/* repeat increment */
1698 	    unsigned int offset3;	/* TDMA slot offset */
1699 	    unsigned int number3;	/* number of xlots to allocate */
1700 	    unsigned int timeout3;	/* allocation timeout */
1701 	    unsigned int increment3;	/* repeat increment */
1702 	    unsigned int offset4;	/* TDMA slot offset */
1703 	    unsigned int number4;	/* number of xlots to allocate */
1704 	    unsigned int timeout4;	/* allocation timeout */
1705 	    unsigned int increment4;	/* repeat increment */
1706 	} type20;
1707 	/* Type 21 - Aids to Navigation Report */
1708 	struct {
1709 	    unsigned int aid_type;	/* aid type */
1710 	    char name[35];		/* name of aid to navigation */
1711 	    bool accuracy;		/* position accuracy */
1712 	    int lon;			/* longitude */
1713 	    int lat;			/* latitude */
1714 	    unsigned int to_bow;	/* dimension to bow */
1715 	    unsigned int to_stern;	/* dimension to stern */
1716 	    unsigned int to_port;	/* dimension to port */
1717 	    unsigned int to_starboard;	/* dimension to starboard */
1718 	    unsigned int epfd;		/* type of EPFD */
1719 	    unsigned int second;	/* second of UTC timestamp */
1720 	    bool off_position;		/* off-position indicator */
1721 	    unsigned int regional;	/* regional reserved field */
1722 	    bool raim;			/* RAIM flag */
1723 	    bool virtual_aid;		/* is virtual station? */
1724 	    bool assigned;		/* assigned-mode flag */
1725 	    //unsigned int spare;	unused */
1726 	} type21;
1727 	/* Type 22 - Channel Management */
1728 	struct {
1729 	    //unsigned int spare;	spare bit(s) */
1730 	    unsigned int channel_a;	/* Channel A number */
1731 	    unsigned int channel_b;	/* Channel B number */
1732 	    unsigned int txrx;		/* transmit/receive mode */
1733 	    bool power;			/* high-power flag */
1734 #define AIS_CHANNEL_LATLON_DIV	600.0
1735 	    union {
1736 		struct {
1737 		    int ne_lon;		/* NE corner longitude */
1738 		    int ne_lat;		/* NE corner latitude */
1739 		    int sw_lon;		/* SW corner longitude */
1740 		    int sw_lat;		/* SW corner latitude */
1741 		} area;
1742 		struct {
1743 		    unsigned int dest1;	/* addressed station MMSI 1 */
1744 		    unsigned int dest2;	/* addressed station MMSI 2 */
1745 		} mmsi;
1746 	    };
1747 	    bool addressed;		/* addressed vs. broadast flag */
1748 	    bool band_a;		/* fix 1.5kHz band for channel A */
1749 	    bool band_b;		/* fix 1.5kHz band for channel B */
1750 	    unsigned int zonesize;	/* size of transitional zone */
1751 	} type22;
1752 	/* Type 23 - Group Assignment Command */
1753 	struct {
1754 	    int ne_lon;			/* NE corner longitude */
1755 	    int ne_lat;			/* NE corner latitude */
1756 	    int sw_lon;			/* SW corner longitude */
1757 	    int sw_lat;			/* SW corner latitude */
1758 	    //unsigned int spare;	spare bit(s) */
1759 	    unsigned int stationtype;	/* station type code */
1760 	    unsigned int shiptype;	/* ship type code */
1761 	    //unsigned int spare2;	spare bit(s) */
1762 	    unsigned int txrx;		/* transmit-enable code */
1763 	    unsigned int interval;	/* report interval */
1764 	    unsigned int quiet;		/* quiet time */
1765 	    //unsigned int spare3;	spare bit(s) */
1766 	} type23;
1767 	/* Type 24 - Class B CS Static Data Report */
1768 	struct {
1769 	    char shipname[AIS_SHIPNAME_MAXLEN+1];	/* vessel name */
1770 	    enum {
1771 		both,
1772 		part_a,
1773 		part_b,
1774 	    } part;
1775 	    unsigned int shiptype;	/* ship type code */
1776 	    char vendorid[8];		/* vendor ID */
1777 	    unsigned int model;		/* unit model code */
1778 	    unsigned int serial;	/* serial number */
1779 	    char callsign[8];		/* callsign */
1780 	    union {
1781 		unsigned int mothership_mmsi;	/* MMSI of main vessel */
1782 		struct {
1783 		    unsigned int to_bow;	/* dimension to bow */
1784 		    unsigned int to_stern;	/* dimension to stern */
1785 		    unsigned int to_port;	/* dimension to port */
1786 		    unsigned int to_starboard;	/* dimension to starboard */
1787 		} dim;
1788 	    };
1789 	} type24;
1790 	/* Type 25 - Addressed Binary Message */
1791 	struct {
1792 	    bool addressed;		/* addressed-vs.broadcast flag */
1793 	    bool structured;		/* structured-binary flag */
1794 	    unsigned int dest_mmsi;	/* destination MMSI */
1795 	    unsigned int app_id;        /* Application ID */
1796 #define AIS_TYPE25_BINARY_MAX	128	/* Up to 128 bits */
1797 	    size_t bitcount;		/* bit count of the data */
1798 	    char bitdata[(AIS_TYPE25_BINARY_MAX + 7) / 8];
1799 	} type25;
1800 	/* Type 26 - Addressed Binary Message */
1801 	struct {
1802 	    bool addressed;		/* addressed-vs.broadcast flag */
1803 	    bool structured;		/* structured-binary flag */
1804 	    unsigned int dest_mmsi;	/* destination MMSI */
1805 	    unsigned int app_id;        /* Application ID */
1806 #define AIS_TYPE26_BINARY_MAX	1004	/* Up to 128 bits */
1807 	    size_t bitcount;		/* bit count of the data */
1808 	    char bitdata[(AIS_TYPE26_BINARY_MAX + 7) / 8];
1809 	    unsigned int radio;		/* radio status bits */
1810 	} type26;
1811 	/* Type 27 - Long Range AIS Broadcast message */
1812 	struct {
1813 	    bool accuracy;		/* position accuracy */
1814 	    bool raim;			/* RAIM flag */
1815 	    unsigned int status;	/* navigation status */
1816 #define AIS_LONGRANGE_LATLON_DIV	600.0
1817 	    int lon;			/* longitude */
1818 #define AIS_LONGRANGE_LON_NOT_AVAILABLE	0x1a838
1819 	    int lat;			/* latitude */
1820 #define AIS_LONGRANGE_LAT_NOT_AVAILABLE	0xd548
1821 	    unsigned int speed;		/* speed over ground in deciknots */
1822 #define AIS_LONGRANGE_SPEED_NOT_AVAILABLE 63
1823 	    unsigned int course;	/* course over ground */
1824 #define AIS_LONGRANGE_COURSE_NOT_AVAILABLE 511
1825 	    bool gnss;			/* are we reporting GNSS position? */
1826 	} type27;
1827     };
1828 };
1829 
1830 struct satellite_t {
1831     double ss;		/* signal-to-noise ratio (dB) */
1832     bool used;		/* PRNs of satellites used in solution */
1833     short PRN;		/* PRNs of satellite */
1834     short elevation;	/* elevation of satellite */
1835     short azimuth;	/* azimuth */
1836 };
1837 
1838 struct attitude_t {
1839     double heading;
1840     double pitch;
1841     double roll;
1842     double yaw;
1843     double dip;
1844     double mag_len; /* unitvector sqrt(x^2 + y^2 +z^2) */
1845     double mag_x;
1846     double mag_y;
1847     double mag_z;
1848     double acc_len; /* unitvector sqrt(x^2 + y^2 +z^2) */
1849     double acc_x;
1850     double acc_y;
1851     double acc_z;
1852     double gyro_x;
1853     double gyro_y;
1854     double temp;
1855     double depth;
1856     /* compass status -- TrueNorth (and any similar) devices only */
1857     char mag_st;
1858     char pitch_st;
1859     char roll_st;
1860     char yaw_st;
1861 };
1862 
1863 struct navdata_t {
1864     unsigned int version;
1865     double compass_heading;
1866     double compass_deviation;
1867     double compass_variation;
1868     double air_temp;
1869     double air_pressure;
1870     double water_temp;
1871     double depth;
1872     double depth_offset;
1873     double wind_speed;
1874     double wind_dir;
1875     double crosstrack_error;
1876     unsigned int compass_status;
1877     unsigned int log_cumulative;
1878     unsigned int log_trip;
1879     unsigned int crosstrack_status;
1880 };
1881 
1882 struct dop_t {
1883     /* Dilution of precision factors */
1884     double xdop, ydop, pdop, hdop, vdop, tdop, gdop;
1885 };
1886 
1887 struct rawdata_t {
1888     /* raw measurement data */
1889     double codephase[MAXCHANNELS];	/* meters */
1890     double carrierphase[MAXCHANNELS];	/* meters */
1891     double pseudorange[MAXCHANNELS];	/* meters */
1892     double deltarange[MAXCHANNELS];	/* meters/sec */
1893     double doppler[MAXCHANNELS];	/* Hz */
1894     double mtime[MAXCHANNELS];		/* sec */
1895     unsigned satstat[MAXCHANNELS];	/* tracking status */
1896 #define SAT_ACQUIRED	0x01		/* satellite acquired */
1897 #define SAT_CODE_TRACK	0x02		/* code-tracking loop acquired */
1898 #define SAT_CARR_TRACK	0x04		/* carrier-tracking loop acquired */
1899 #define SAT_DATA_SYNC	0x08		/* data-bit synchronization done */
1900 #define SAT_FRAME_SYNC	0x10		/* frame synchronization done */
1901 #define SAT_EPHEMERIS	0x20		/* ephemeris collected */
1902 #define SAT_FIX_USED	0x40		/* used for position fix */
1903 };
1904 
1905 struct version_t {
1906     char release[64];			/* external version */
1907     char rev[64];			/* internal revision ID */
1908     int proto_major, proto_minor;	/* API major and minor versions */
1909     char remote[GPS_PATH_MAX];		/* could be from a remote device */
1910 };
1911 
1912 struct devconfig_t {
1913     char path[GPS_PATH_MAX];
1914     int flags;
1915 #define SEEN_GPS 	0x01
1916 #define SEEN_RTCM2	0x02
1917 #define SEEN_RTCM3	0x04
1918 #define SEEN_AIS 	0x08
1919     char driver[64];
1920     char subtype[64];
1921     double activated;
1922     unsigned int baudrate, stopbits;	/* RS232 link parameters */
1923     char parity;			/* 'N', 'O', or 'E' */
1924     double cycle, mincycle;     	/* refresh cycle time in seconds */
1925     int driver_mode;    		/* is driver in native mode or not? */
1926 };
1927 
1928 struct policy_t {
1929     bool watcher;			/* is watcher mode on? */
1930     bool json;				/* requesting JSON? */
1931     bool nmea;				/* requesting dumping as NMEA? */
1932     int raw;				/* requesting raw data? */
1933     bool scaled;			/* requesting report scaling? */
1934     bool timing;			/* requesting timing info */
1935     bool split24;			/* requesting split AIS Type 24s */
1936     bool pps;				/* requesting PPS in NMEA/raw modes */
1937     int loglevel;			/* requested log level of messages */
1938     char devpath[GPS_PATH_MAX];		/* specific device to watch */
1939     char remote[GPS_PATH_MAX];		/* ...if this was passthrough */
1940 };
1941 
1942 #ifndef TIMEDELTA_DEFINED
1943 #define TIMEDELTA_DEFINED
1944 
1945 struct timedelta_t {
1946     struct timespec	real;
1947     struct timespec	clock;
1948 };
1949 #endif /* TIMEDELTA_DEFINED */
1950 
1951 /*
1952  * Someday we may support Windows, under which socket_t is a separate type.
1953  * In the meantime, having a typedef for this semantic kind is no bad thing,
1954  * as it makes clearer what some declarations are doing without breaking
1955  * binary compatibility.
1956  */
1957 typedef int socket_t;
1958 #define BAD_SOCKET(s)	((s) == -1)
1959 #define INVALIDATE_SOCKET(s)	do { s = -1; } while (0)
1960 
1961 /* mode flags for setting streaming policy */
1962 #define WATCH_ENABLE	0x000001u	/* enable streaming */
1963 #define WATCH_DISABLE	0x000002u	/* disable watching */
1964 #define WATCH_JSON	0x000010u	/* JSON output */
1965 #define WATCH_NMEA	0x000020u	/* output in NMEA */
1966 #define WATCH_RARE	0x000040u	/* output of packets in hex */
1967 #define WATCH_RAW	0x000080u	/* output of raw packets */
1968 #define WATCH_SCALED	0x000100u	/* scale output to floats */
1969 #define WATCH_TIMING	0x000200u	/* timing information */
1970 #define WATCH_DEVICE	0x000800u	/* watch specific device */
1971 #define WATCH_SPLIT24	0x001000u	/* split AIS Type 24s */
1972 #define WATCH_PPS	0x002000u	/* enable PPS JSON */
1973 #define WATCH_NEWSTYLE	0x010000u	/* force JSON streaming */
1974 
1975 /*
1976  * Main structure that includes all previous substructures
1977  */
1978 
1979 struct gps_data_t {
1980     gps_mask_t set;	/* has field been set since this was last cleared? */
1981 #define ONLINE_SET	(1llu<<1)
1982 #define TIME_SET	(1llu<<2)
1983 #define TIMERR_SET	(1llu<<3)
1984 #define LATLON_SET	(1llu<<4)
1985 #define ALTITUDE_SET	(1llu<<5)
1986 #define SPEED_SET	(1llu<<6)
1987 #define TRACK_SET	(1llu<<7)
1988 #define CLIMB_SET	(1llu<<8)
1989 #define STATUS_SET	(1llu<<9)
1990 #define MODE_SET	(1llu<<10)
1991 #define DOP_SET  	(1llu<<11)
1992 #define HERR_SET	(1llu<<12)
1993 #define VERR_SET	(1llu<<13)
1994 #define ATTITUDE_SET	(1llu<<14)
1995 #define SATELLITE_SET	(1llu<<15)
1996 #define SPEEDERR_SET	(1llu<<16)
1997 #define TRACKERR_SET	(1llu<<17)
1998 #define CLIMBERR_SET	(1llu<<18)
1999 #define DEVICE_SET	(1llu<<19)
2000 #define DEVICELIST_SET	(1llu<<20)
2001 #define DEVICEID_SET	(1llu<<21)
2002 #define RTCM2_SET	(1llu<<22)
2003 #define RTCM3_SET	(1llu<<23)
2004 #define AIS_SET 	(1llu<<24)
2005 #define PACKET_SET	(1llu<<25)
2006 #define SUBFRAME_SET	(1llu<<26)
2007 #define GST_SET 	(1llu<<27)
2008 #define VERSION_SET	(1llu<<28)
2009 #define POLICY_SET	(1llu<<29)
2010 #define LOGMESSAGE_SET	(1llu<<30)
2011 #define ERROR_SET	(1llu<<31)
2012 #define TOFF_SET	(1llu<<32)	/* not yet used */
2013 #define PPS_SET 	(1llu<<33)
2014 #define NAVDATA_SET     (1llu<<34)
2015 #define SET_HIGH_BIT	35
2016     timestamp_t online;		/* NZ if GPS is on line, 0 if not.
2017 				 *
2018 				 * Note: gpsd clears this time when sentences
2019 				 * fail to show up within the GPS's normal
2020 				 * send cycle time. If the host-to-GPS
2021 				 * link is lossy enough to drop entire
2022 				 * sentences, this field will be
2023 				 * prone to false zero values.
2024 				 */
2025 
2026 #ifndef USE_QT
2027     socket_t gps_fd;		/* socket or file descriptor to GPS */
2028 #else
2029     void* gps_fd;
2030 #endif
2031     struct gps_fix_t	fix;	/* accumulated PVT data */
2032 
2033     /* this should move to the per-driver structure */
2034     double separation;		/* Geoidal separation, MSL - WGS84 (Meters) */
2035 
2036     /* GPS status -- always valid */
2037     int    status;		/* Do we have a fix? */
2038 #define STATUS_NO_FIX	0	/* no */
2039 #define STATUS_FIX	1	/* yes */
2040 
2041     /* precision of fix -- valid if satellites_used > 0 */
2042     int satellites_used;	/* Number of satellites used in solution */
2043     struct dop_t dop;
2044 
2045     /* redundant with the estimate elements in the fix structure */
2046     double epe;  /* spherical position error, 95% confidence (meters)  */
2047 
2048     /* satellite status -- valid when satellites_visible > 0 */
2049     timestamp_t skyview_time;	/* skyview timestamp */
2050     int satellites_visible;	/* # of satellites in view */
2051     struct satellite_t skyview[MAXCHANNELS];
2052 
2053     struct devconfig_t dev;	/* device that shipped last update */
2054 
2055     struct policy_t policy;	/* our listening policy */
2056 
2057     struct {
2058 	timestamp_t time;
2059 	int ndevices;
2060 	struct devconfig_t list[MAXUSERDEVS];
2061     } devices;
2062 
2063     /* pack things never reported together to reduce structure size */
2064 #define UNION_SET	(RTCM2_SET|RTCM3_SET|SUBFRAME_SET|AIS_SET|ATTITUDE_SET|GST_SET|VERSION_SET|LOGMESSAGE_SET|ERROR_SET|TOFF_SET|PPS_SET)
2065     union {
2066 	/* unusual forms of sensor data that might come up the pipe */
2067 	struct rtcm2_t	rtcm2;
2068 	struct rtcm3_t	rtcm3;
2069 	struct subframe_t subframe;
2070 	struct ais_t ais;
2071 	struct attitude_t attitude;
2072         struct navdata_t navdata;
2073 	struct rawdata_t raw;
2074 	struct gst_t gst;
2075 	/* "artificial" structures for various protocol responses */
2076 	struct version_t version;
2077 	char error[256];
2078 	struct timedelta_t toff;
2079 	struct timedelta_t pps;
2080     };
2081     /* FIXME! next lib rev need to add a place to put PPS precision */
2082 
2083     /* Private data - client code must not set this */
2084     void *privdata;
2085 };
2086 
2087 extern int gps_open(const char *, const char *,
2088 		      struct gps_data_t *);
2089 extern int gps_close(struct gps_data_t *);
2090 extern int gps_send(struct gps_data_t *, const char *, ... );
2091 extern int gps_read(struct gps_data_t *);
2092 extern int gps_unpack(char *, struct gps_data_t *);
2093 extern bool gps_waiting(const struct gps_data_t *, int);
2094 extern int gps_stream(struct gps_data_t *, unsigned int, void *);
2095 extern int gps_mainloop(struct gps_data_t *, int,
2096 			void (*)(struct gps_data_t *));
2097 extern const char *gps_data(const struct gps_data_t *);
2098 extern const char *gps_errstr(const int);
2099 
2100 int json_toff_read(const char *buf, struct gps_data_t *,
2101 		  const char **);
2102 int json_pps_read(const char *buf, struct gps_data_t *,
2103 		  const char **);
2104 
2105 /* dependencies on struct gpsdata_t end here */
2106 
2107 extern void libgps_trace(int errlevel, const char *, ...);
2108 
2109 extern void gps_clear_fix(struct gps_fix_t *);
2110 extern void gps_clear_dop( struct dop_t *);
2111 extern void gps_merge_fix(struct gps_fix_t *, gps_mask_t, struct gps_fix_t *);
2112 extern void gps_enable_debug(int, FILE *);
2113 extern const char *gps_maskdump(gps_mask_t);
2114 
2115 extern double safe_atof(const char *);
2116 extern time_t mkgmtime(register struct tm *);
2117 extern timestamp_t timestamp(void);
2118 extern timestamp_t iso8601_to_unix(char *);
2119 extern char *unix_to_iso8601(timestamp_t t, char[], size_t len);
2120 extern double earth_distance(double, double, double, double);
2121 extern double earth_distance_and_bearings(double, double, double, double,
2122 					  double *,
2123 					  double *);
2124 extern double wgs84_separation(double, double);
2125 
2126 /* some multipliers for interpreting GPS output */
2127 #define METERS_TO_FEET	3.2808399	/* Meters to U.S./British feet */
2128 #define METERS_TO_MILES	0.00062137119	/* Meters to miles */
2129 #define METERS_TO_FATHOMS	0.54680665	/* Meters to fathoms */
2130 #define KNOTS_TO_MPH	1.1507794	/* Knots to miles per hour */
2131 #define KNOTS_TO_KPH	1.852		/* Knots to kilometers per hour */
2132 #define KNOTS_TO_MPS	0.51444444	/* Knots to meters per second */
2133 #define MPS_TO_KPH	3.6		/* Meters per second to klicks/hr */
2134 #define MPS_TO_MPH	2.2369363	/* Meters/second to miles per hour */
2135 #define MPS_TO_KNOTS	1.9438445	/* Meters per second to knots */
2136 /* miles and knots are both the international standard versions of the units */
2137 
2138 /* angle conversion multipliers */
2139 #define GPS_PI      	3.1415926535897932384626433832795029
2140 #define RAD_2_DEG	57.2957795130823208767981548141051703
2141 #define DEG_2_RAD	0.0174532925199432957692369076848861271
2142 
2143 /* geodetic constants */
2144 #define WGS84A 6378137		/* equatorial radius */
2145 #define WGS84F 298.257223563	/* flattening */
2146 #define WGS84B 6356752.3142	/* polar radius */
2147 
2148 /* netlib_connectsock() errno return values */
2149 #define NL_NOSERVICE	-1	/* can't get service entry */
2150 #define NL_NOHOST	-2	/* can't get host entry */
2151 #define NL_NOPROTO	-3	/* can't get protocol entry */
2152 #define NL_NOSOCK	-4	/* can't create socket */
2153 #define NL_NOSOCKOPT	-5	/* error SETSOCKOPT SO_REUSEADDR */
2154 #define NL_NOCONNECT	-6	/* can't connect to host/socket pair */
2155 #define SHM_NOSHARED	-7	/* shared-memory segment not available */
2156 #define SHM_NOATTACH	-8	/* shared-memory attach failed */
2157 #define DBUS_FAILURE	-9	/* DBUS initialization failure */
2158 
2159 #define DEFAULT_GPSD_PORT	"2947"	/* IANA assignment */
2160 #define DEFAULT_RTCM_PORT	"2101"	/* IANA assignment */
2161 
2162 /* special host values for non-socket exports */
2163 #define GPSD_SHARED_MEMORY	"shared memory"
2164 #define GPSD_DBUS_EXPORT	"DBUS export"
2165 
2166 #ifdef __cplusplus
2167 }  /* End of the 'extern "C"' block */
2168 #endif
2169 
2170 #endif /* _GPSD_GPS_H_ */
2171 /* gps.h ends here */
2172