"Initial commit to Gerrit"
[profile/ivi/gpsd.git] / gps.h
1 /*
2  * This file is Copyright (c) 2010 by the GPSD project
3  * BSD terms apply: see the file COPYING in the distribution root for details.
4  */
5 #ifndef _GPSD_GPS_H_
6 #define _GPSD_GPS_H_
7
8 /* gps.h -- interface of the libgps library */
9
10 #ifdef _WIN32
11 #define strtok_r(s,d,p) strtok_s(s,d,p)
12 #endif
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /* Macro for declaring function arguments unused. */
19 #if defined(__GNUC__)
20 #  define UNUSED __attribute__((unused)) /* Flag variable as unused */
21 #else /* not __GNUC__ */
22 #  define UNUSED
23 #endif
24
25
26 #include <sys/types.h>
27 #include <sys/time.h>
28 #include <stdbool.h>
29 #include <inttypes.h>   /* stdint.h would be smaller but not all have it */
30 #include <limits.h>
31 #include <time.h>
32 #include <signal.h>
33 #include <stdio.h>
34 #ifndef S_SPLINT_S
35 #include <pthread.h>    /* pacifies OpenBSD's compiler */
36 #endif
37
38 /*
39  * 4.1 - Base version for initial JSON protocol (Dec 2009)
40  * 4.2 - AIS application IDs split into DAC and FID (May 2010)
41  */
42 #define GPSD_API_MAJOR_VERSION  4       /* bump on incompatible changes */
43 #define GPSD_API_MINOR_VERSION  2       /* bump on compatible changes */
44
45 #define MAXTAGLEN       8       /* maximum length of sentence tag name */
46 #define MAXCHANNELS     20      /* maximum GPS channels (*not* satellites!) */
47 #define GPS_PRNMAX      32      /* above this number are SBAS satellites */
48 #define GPS_PATH_MAX    64      /* dev files usually have short names */
49 #define MAXUSERDEVS     4       /* max devices per user */
50
51 /* 
52  * The structure describing an uncertainty volume in kinematic space.
53  * This is what GPSes are meant to produce; all the other info is 
54  * technical impedimenta.
55  *
56  * All double values use NAN to indicate data not available.
57  *
58  * Usually all the information in this structure was considered valid
59  * by the GPS at the time of update.  This will be so if you are using
60  * a GPS chipset that speaks SiRF binary, Garmin binary, or Zodiac binary.
61  * This covers over 80% of GPS products in early 2005.
62  *
63  * If you are using a chipset that speaks NMEA, this structure is updated
64  * in bits by GPRMC (lat/lon, track, speed), GPGGA (alt, climb), GPGLL 
65  * (lat/lon), and GPGSA (eph, epv).  Most NMEA GPSes take a single fix
66  * at the beginning of a 1-second cycle and report the same timestamp in
67  * GPRMC, GPGGA, and GPGLL; for these, all info is guaranteed correctly
68  * synced to the time member, but you'll get different stages of the same 
69  * update depending on where in the cycle you poll.  A very few GPSes, 
70  * like the Garmin 48, take a new fix before more than one of of 
71  * GPRMC/GPGGA/GPGLL during a single cycle; thus, they may have different 
72  * timestamps and some data in this structure can be up to 1 cycle (usually
73  * 1 second) older than the fix time.
74  *
75  * Error estimates are at 95% confidence.
76  */
77 struct gps_fix_t {
78     double time;        /* Time of update, seconds since Unix epoch */
79     int    mode;        /* Mode of fix */
80 #define MODE_NOT_SEEN   0       /* mode update not seen yet */
81 #define MODE_NO_FIX     1       /* none */
82 #define MODE_2D         2       /* good for latitude/longitude */
83 #define MODE_3D         3       /* good for altitude/climb too */
84     double ept;         /* Expected time uncertainty */
85     double latitude;    /* Latitude in degrees (valid if mode >= 2) */
86     double epy;         /* Latitude position uncertainty, meters */
87     double longitude;   /* Longitude in degrees (valid if mode >= 2) */
88     double epx;         /* Longitude position uncertainty, meters */
89     double altitude;    /* Altitude in meters (valid if mode == 3) */
90     double epv;         /* Vertical position uncertainty, meters */
91     double track;       /* Course made good (relative to true north) */
92     double epd;         /* Track uncertainty, degrees */
93     double speed;       /* Speed over ground, meters/sec */
94     double eps;         /* Speed uncertainty, meters/sec */
95     double climb;       /* Vertical speed, meters/sec */
96     double epc;         /* Vertical speed uncertainty */
97 };
98
99 /*  
100  * From the RCTM104 2.x standard:
101  *
102  * "The 30 bit words (as opposed to 32 bit words) coupled with a 50 Hz
103  * transmission rate provides a convenient timing capability where the
104  * times of word boundaries are a rational multiple of 0.6 seconds."
105  *
106  * "Each frame is N+2 words long, where N is the number of message data
107  * words. For example, a filler message (type 6 or 34) with no message
108  * data will have N=0, and will consist only of two header words. The
109  * maximum number of data words allowed by the format is 31, so that
110  * the longest possible message will have a total of 33 words."
111  */
112 #define RTCM2_WORDS_MAX 33
113 #define MAXCORRECTIONS  18      /* max correction count in type 1 or 9 */
114 #define MAXSTATIONS     10      /* maximum stations in almanac, type 5 */
115 /* RTCM104 doesn't specify this, so give it the largest reasonable value */
116 #define MAXHEALTH       (RTCM2_WORDS_MAX-2)
117
118 #ifndef S_SPLINT_S 
119 /*
120  * A nominally 30-bit word (24 bits of data, 6 bits of parity)
121  * used both in the GPS downlink protocol described in IS-GPS-200
122  * and in the format for DGPS corrections used in RTCM-104v2.
123  */
124 typedef /*@unsignedintegraltype@*/ uint32_t isgps30bits_t;
125 #endif /* S_SPLINT_S */
126
127 /* 
128  * Values for "system" fields.  Note, the encoding logic is senstive to the 
129  * actual values of these; it's not sufficient that they're distinct.
130  */
131 #define NAVSYSTEM_GPS           0
132 #define NAVSYSTEM_GLONASS       1
133 #define NAVSYSTEM_GALILEO       2
134 #define NAVSYSTEM_UNKNOWN       3
135
136 struct rtcm2_t {
137     /* header contents */
138     unsigned type;      /* RTCM message type */
139     unsigned length;    /* length (words) */
140     double   zcount;    /* time within hour: GPS time, no leap secs */
141     unsigned refstaid;  /* reference station ID */
142     unsigned seqnum;    /* message sequence number (modulo 8) */
143     unsigned stathlth;  /* station health */
144
145     /* message data in decoded form */
146     union {
147         struct {
148             unsigned int nentries;
149             struct rangesat_t {         /* data from messages 1 & 9 */
150                 unsigned ident;         /* satellite ID */
151                 unsigned udre;          /* user diff. range error */
152                 unsigned issuedata;     /* issue of data */
153                 double rangerr;         /* range error */
154                 double rangerate;       /* range error rate */
155             } sat[MAXCORRECTIONS];
156         } ranges;
157         struct {                /* data for type 3 messages */
158             bool valid;         /* is message well-formed? */
159             double x, y, z;
160         } ecef;
161         struct {                /* data from type 4 messages */
162             bool valid;         /* is message well-formed? */
163             int system;
164             int sense;
165 #define SENSE_INVALID   0
166 #define SENSE_GLOBAL    1
167 #define SENSE_LOCAL     2
168             char datum[6];
169             double dx, dy, dz;
170         } reference;
171         struct {                /* data from type 5 messages */
172             unsigned int nentries;
173             struct consat_t {
174                 unsigned ident;         /* satellite ID */
175                 bool iodl;              /* issue of data */
176                 unsigned int health;    /* is satellite healthy? */
177 #define HEALTH_NORMAL           (0)     /* Radiobeacon operation normal */
178 #define HEALTH_UNMONITORED      (1)     /* No integrity monitor operating */
179 #define HEALTH_NOINFO           (2)     /* No information available */
180 #define HEALTH_DONOTUSE         (3)     /* Do not use this radiobeacon */
181                int snr;                 /* signal-to-noise ratio, dB */
182 #define SNR_BAD -1                      /* not reported */
183                 bool health_en;         /* health enabled */
184                 bool new_data;          /* new data? */
185                 bool los_warning;       /* line-of-sight warning */
186                 unsigned int tou;       /* time to unhealth, seconds */
187             } sat[MAXHEALTH];
188         } conhealth;
189         struct {                /* data from type 7 messages */
190             unsigned int nentries;
191             struct station_t {
192                 double latitude, longitude;     /* location */
193                 unsigned int range;             /* range in km */
194                 double frequency;               /* broadcast freq */
195                 unsigned int health;            /* station health */
196                 unsigned int station_id;        /* of the transmitter */
197                 unsigned int bitrate;           /* of station transmissions */
198             } station[MAXSTATIONS];
199         } almanac;
200         /* data from type 16 messages */
201         char message[(RTCM2_WORDS_MAX-2) * sizeof(isgps30bits_t)];
202         /* data from messages of unknown type */
203         isgps30bits_t   words[RTCM2_WORDS_MAX-2];
204     };
205 };
206
207 /* RTCM3 report structures begin here */
208
209 #define RTCM3_MAX_SATELLITES    64
210 #define RTCM3_MAX_DESCRIPTOR    31
211 #define RTCM3_MAX_ANNOUNCEMENTS 32
212
213 struct rtcm3_rtk_hdr {          /* header data from 1001, 1002, 1003, 1004 */
214     /* Used for both GPS and GLONASS, but their timebases differ */
215     unsigned int station_id;    /* Reference Station ID */
216     time_t tow;                 /* GPS Epoch Time (TOW) in ms, 
217                                    or GLONASS Epoch Time in ms */
218     bool sync;                  /* Synchronous GNSS Message Flag */
219     unsigned short satcount;    /* # Satellite Signals Processed */
220     bool smoothing;             /* Divergence-free Smoothing Indicator */
221     unsigned short interval;    /* Smoothing Interval */
222 };
223
224 struct rtcm3_basic_rtk {
225     unsigned char indicator;    /* Indicator */
226     unsigned char channel;      /* Satellite Frequency Channel Number 
227                                    (GLONASS only) */
228     double pseudorange;         /* Pseudorange */
229     double rangediff;           /* PhaseRange â€“ Pseudorange in meters */
230     unsigned char locktime;     /* Lock time Indicator */
231 };
232
233 struct rtcm3_extended_rtk {
234     unsigned char indicator;    /* Indicator */
235     unsigned char channel;      /* Satellite Frequency Channel Number 
236                                    (GLONASS only) */
237     double pseudorange;         /* Pseudorange */
238     double rangediff;           /* PhaseRange â€“ L1 Pseudorange */
239     unsigned char locktime;     /* Lock time Indicator */
240     unsigned char ambiguity;    /* Integer Pseudorange 
241                                            Modulus Ambiguity */
242     double CNR;                 /* Carrier-to-Noise Ratio */
243 };
244
245 struct rtcm3_network_rtk_header {
246     unsigned int network_id;    /* Network ID */
247     unsigned int subnetwork_id; /* Subnetwork ID */
248     time_t time;                /* GPS Epoch Time (TOW) in ms */
249     bool multimesg;             /* GPS Multiple Message Indicator */
250     unsigned master_id;         /* Master Reference Station ID */
251     unsigned aux_id;            /* Auxilary Reference Station ID */
252     unsigned char satcount;     /* count of GPS satellites */
253 };
254
255 struct rtcm3_correction_diff {
256     unsigned char ident;        /* satellite ID */
257     enum {reserved, correct, widelane, uncertain} ambiguity;
258     unsigned char nonsync;
259     double geometric_diff;      /* Geometric Carrier Phase 
260                                    Correction Difference (1016, 1017) */
261     unsigned char iode;         /* GPS IODE (1016, 1017) */
262     double ionospheric_diff;    /* Ionospheric Carrier Phase 
263                                    Correction Difference (1015, 1017) */
264 };
265
266 struct rtcm3_t {
267     /* header contents */
268     unsigned type;      /* RTCM 3.x message type */
269     unsigned length;    /* payload length, inclusive of checksum */
270
271     union {
272         /* 1001-1013 were present in the 3.0 version */
273         struct {
274             struct rtcm3_rtk_hdr        header;
275             struct {
276                 unsigned ident;                 /* Satellite ID */
277                 struct rtcm3_basic_rtk L1;
278             } rtk_data[RTCM3_MAX_SATELLITES];
279         } rtcm3_1001;
280         struct {
281             struct rtcm3_rtk_hdr        header;
282             struct {
283                 unsigned ident;                 /* Satellite ID */
284                 struct rtcm3_extended_rtk L1;
285             } rtk_data[RTCM3_MAX_SATELLITES];
286         } rtcm3_1002;
287         struct {
288             struct rtcm3_rtk_hdr        header;
289             struct {
290                 unsigned ident;                 /* Satellite ID */
291                 struct rtcm3_basic_rtk L1;
292                 struct rtcm3_basic_rtk L2;
293             } rtk_data[RTCM3_MAX_SATELLITES];
294         } rtcm3_1003;
295         struct {
296             struct rtcm3_rtk_hdr        header;
297             struct {
298                 unsigned ident;                 /* Satellite ID */
299                 struct rtcm3_extended_rtk L1;
300                 struct rtcm3_extended_rtk L2;
301             } rtk_data[RTCM3_MAX_SATELLITES];
302         } rtcm3_1004;
303         struct {
304             unsigned int station_id;            /* Reference Station ID */
305             int system;                         /* Which system is it? */
306             bool reference_station;             /* Reference-station indicator */
307             bool single_receiver;               /* Single Receiver Oscillator */
308             double ecef_x, ecef_y, ecef_z;      /* ECEF antenna location */
309         } rtcm3_1005;
310         struct {
311             unsigned int station_id;            /* Reference Station ID */
312             int system;                         /* Which system is it? */
313             bool reference_station;             /* Reference-station indicator */
314             bool single_receiver;               /* Single Receiver Oscillator */
315             double ecef_x, ecef_y, ecef_z;      /* ECEF antenna location */
316             double height;                      /* Antenna height */
317         } rtcm3_1006;
318         struct {
319             unsigned int station_id;                    /* Reference Station ID */
320             char descriptor[RTCM3_MAX_DESCRIPTOR+1];    /* Description string */
321             unsigned char setup_id;
322         } rtcm3_1007;
323         struct {
324             unsigned int station_id;                    /* Reference Station ID */
325             char descriptor[RTCM3_MAX_DESCRIPTOR+1];    /* Description string */
326             unsigned char setup_id;
327             char serial[RTCM3_MAX_DESCRIPTOR+1];        /* Serial # string */
328         } rtcm3_1008;
329         struct {
330             struct rtcm3_rtk_hdr        header;
331             struct {
332                 unsigned ident;         /* Satellite ID */
333                 struct rtcm3_basic_rtk L1;
334             } rtk_data[RTCM3_MAX_SATELLITES];
335         } rtcm3_1009;
336         struct {
337             struct rtcm3_rtk_hdr        header;
338             struct {
339                 unsigned ident;         /* Satellite ID */
340                 struct rtcm3_extended_rtk L1;
341             } rtk_data[RTCM3_MAX_SATELLITES];
342         } rtcm3_1010;
343         struct {
344             struct rtcm3_rtk_hdr        header;
345             struct {
346                 unsigned ident;                 /* Satellite ID */
347                 struct rtcm3_extended_rtk L1;
348                 struct rtcm3_extended_rtk L2;
349             } rtk_data[RTCM3_MAX_SATELLITES];
350         } rtcm3_1011;
351         struct {
352             struct rtcm3_rtk_hdr        header;
353             struct {
354                 unsigned ident;                 /* Satellite ID */
355                 struct rtcm3_extended_rtk L1;
356                 struct rtcm3_extended_rtk L2;
357             } rtk_data[RTCM3_MAX_SATELLITES];
358         } rtcm3_1012;
359         struct {
360             unsigned int station_id;    /* Reference Station ID */
361             unsigned short mjd;         /* Modified Julian Day (MJD) Number */
362             unsigned int sod;           /* Seconds of Day (UTC) */
363             unsigned char leapsecs;     /* Leap Seconds, GPS-UTC */
364             unsigned char ncount;       /* Count of announcements to follow */
365             struct {
366                 unsigned short id;
367                 bool sync;
368                 unsigned short interval;
369             } announcements[RTCM3_MAX_ANNOUNCEMENTS];
370         } rtcm3_1013;
371         /* 1014-1017 were added in the 3.1 version */
372         struct {
373             unsigned int network_id;    /* Network ID */
374             unsigned int subnetwork_id; /* Subnetwork ID */
375             unsigned char stationcount; /* # auxiliary stations transmitted */
376             unsigned int master_id;     /* Master Reference Station ID */
377             unsigned int aux_id;        /* Auxilary Reference Station ID */
378             double d_lat, d_lon, d_alt; /* Aux-master location delta */
379         } rtcm3_1014;
380         struct {
381             struct rtcm3_network_rtk_header     header;
382             struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
383         } rtcm3_1015;
384         struct {
385             struct rtcm3_network_rtk_header     header;
386             struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
387         } rtcm3_1016;
388         struct {
389             struct rtcm3_network_rtk_header     header;
390             struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
391         } rtcm3_1017;
392         /* 1018-1029 were in the 3.0 version */
393         struct {
394             unsigned int ident;         /* Satellite ID */
395             unsigned int week;          /* GPS Week Number */
396             unsigned char sv_accuracy;  /* GPS SV ACCURACY */
397             enum {reserved_code, p, ca, l2c} code;
398             double idot;
399             unsigned char iode;
400             /* ephemeris fields, not scaled */
401             unsigned int t_sub_oc;
402             signed int a_sub_f2;
403             signed int a_sub_f1;
404             signed int a_sub_f0;
405             unsigned int iodc;
406             signed int C_sub_rs;
407             signed int delta_sub_n;
408             signed int M_sub_0;
409             signed int C_sub_uc;
410             unsigned int e;
411             signed int C_sub_us;
412             unsigned int sqrt_sub_A;
413             unsigned int t_sub_oe;
414             signed int C_sub_ic;
415             signed int OMEGA_sub_0;
416             signed int C_sub_is;
417             signed int i_sub_0;
418             signed int C_sub_rc;
419             signed int argument_of_perigee;
420             signed int omegadot;
421             signed int t_sub_GD;
422             unsigned char sv_health;
423             bool p_data;
424             bool fit_interval;
425         } rtcm3_1019;
426         struct {
427             unsigned int ident;         /* Satellite ID */
428             unsigned short channel;     /* Satellite Frequency Channel Number */
429             /* ephemeris fields, not scaled */
430             bool C_sub_n;
431             bool health_avAilability_indicator;
432             unsigned char P1;
433             unsigned short t_sub_k;
434             bool msb_of_B_sub_n;
435             bool P2;
436             bool t_sub_b;
437             signed int x_sub_n_t_of_t_sub_b_prime;
438             signed int x_sub_n_t_of_t_sub_b;
439             signed int x_sub_n_t_of_t_sub_b_prime_prime;
440             signed int y_sub_n_t_of_t_sub_b_prime;
441             signed int y_sub_n_t_of_t_sub_b;
442             signed int y_sub_n_t_of_t_sub_b_prime_prime;
443             signed int z_sub_n_t_of_t_sub_b_prime;
444             signed int z_sub_n_t_of_t_sub_b;
445             signed int z_sub_n_t_of_t_sub_b_prime_prime;
446             bool P3;
447             signed int gamma_sub_n_of_t_sub_b;
448             unsigned char MP;
449             bool Ml_n;
450             signed int tau_n_of_t_sub_b;
451             signed int M_delta_tau_sub_n;
452             unsigned int E_sub_n;
453             bool MP4;
454             unsigned char MF_sub_T;
455             unsigned char MN_sub_T;
456             unsigned char MM;
457             bool additioinal_data_availability;
458             unsigned int N_sup_A;
459             unsigned int tau_sub_c;
460             unsigned int M_N_sub_4;
461             signed int M_tau_sub_GPS;
462             bool M_l_sub_n;
463         } rtcm3_1020;
464         struct {
465             unsigned int station_id;    /* Reference Station ID */
466             unsigned short mjd;         /* Modified Julian Day (MJD) Number */
467             unsigned int sod;           /* Seconds of Day (UTC) */
468             unsigned char len;          /* # Chars to follow */
469             unsigned char unicode_units;
470             unsigned char text[128];
471         } rtcm3_1029;
472     } rtcmtypes;
473 };
474
475 typedef /*@unsignedintegraltype@*/ unsigned int gps_mask_t;
476
477 /* 
478  * Is an MMSI number that of an auxiliary associated with a mother ship?
479  * We need to be able to test this for decoding AIS Type 24 messages.
480  * According to <http://www.navcen.uscg.gov/marcomms/gmdss/mmsi.htm#format>,
481  * auxiliary-craft MMSIs have the form 98MIDXXXX, where MID is a country 
482  * code and XXXX the vessel ID.
483  */
484 #define AIS_AUXILIARY_MMSI(n)   ((n) / 10000000 == 98)
485
486 struct ais_t
487 {
488     unsigned int        type;           /* message type */
489     unsigned int        repeat;         /* Repeat indicator */
490     unsigned int        mmsi;           /* MMSI */
491     union {
492         /* Types 1-3 Common navigation info */
493         struct {
494             unsigned int status;                /* navigation status */
495             signed turn;                        /* rate of turn */
496 #define AIS_TURN_HARD_LEFT      -127
497 #define AIS_TURN_HARD_RIGHT     127
498 #define AIS_TURN_NOT_AVAILABLE  128
499             unsigned int speed;                 /* speed over ground in deciknots */
500 #define AIS_SPEED_NOT_AVAILABLE 1023
501 #define AIS_SPEED_FAST_MOVER    1022            /* >= 102.2 knots */
502             bool accuracy;                      /* position accuracy */
503 #define AIS_LATLON_SCALE        600000.0
504             int lon;                            /* longitude */
505 #define AIS_LON_NOT_AVAILABLE   0x6791AC0
506             int lat;                            /* latitude */
507 #define AIS_LAT_NOT_AVAILABLE   0x3412140
508             unsigned int course;                /* course over ground */
509 #define AIS_COURSE_NOT_AVAILABLE        3600
510             unsigned int heading;               /* true heading */
511 #define AIS_HEADING_NOT_AVAILABLE       511
512             unsigned int second;                /* seconds of UTC timestamp */
513 #define AIS_SEC_NOT_AVAILABLE   60
514 #define AIS_SEC_MANUAL          61
515 #define AIS_SEC_ESTIMATED       62
516 #define AIS_SEC_INOPERATIVE     63
517             unsigned int maneuver;      /* maneuver indicator */
518             //unsigned int spare;       spare bits */
519             bool raim;                  /* RAIM flag */
520             unsigned int radio;         /* radio status bits */
521         } type1;
522         /* Type 4 - Base Station Report & Type 11 - UTC and Date Response */
523         struct {
524             unsigned int year;                  /* UTC year */
525 #define AIS_YEAR_NOT_AVAILABLE  0
526             unsigned int month;                 /* UTC month */
527 #define AIS_MONTH_NOT_AVAILABLE 0
528             unsigned int day;                   /* UTC day */
529 #define AIS_DAY_NOT_AVAILABLE   0
530             unsigned int hour;                  /* UTC hour */
531 #define AIS_HOUR_NOT_AVAILABLE  24
532             unsigned int minute;                /* UTC minute */
533 #define AIS_MINUTE_NOT_AVAILABLE        60
534             unsigned int second;                /* UTC second */
535 #define AIS_SECOND_NOT_AVAILABLE        60
536             bool accuracy;              /* fix quality */
537             int lon;                    /* longitude */
538             int lat;                    /* latitude */
539             unsigned int epfd;          /* type of position fix device */
540             //unsigned int spare;       spare bits */
541             bool raim;                  /* RAIM flag */
542             unsigned int radio;         /* radio status bits */
543         } type4;
544         /* Type 5 - Ship static and voyage related data */
545         struct {
546             unsigned int ais_version;   /* AIS version level */
547             unsigned int imo;           /* IMO identification */
548             char callsign[8];           /* callsign */ 
549 #define AIS_SHIPNAME_MAXLEN     20
550             char shipname[AIS_SHIPNAME_MAXLEN+1];       /* vessel name */
551             unsigned int shiptype;      /* ship type code */
552             unsigned int to_bow;        /* dimension to bow */
553             unsigned int to_stern;      /* dimension to stern */
554             unsigned int to_port;       /* dimension to port */
555             unsigned int to_starboard;  /* dimension to starboard */
556             unsigned int epfd;          /* type of position fix deviuce */
557             unsigned int month;         /* UTC month */
558             unsigned int day;           /* UTC day */
559             unsigned int hour;          /* UTC hour */
560             unsigned int minute;        /* UTC minute */
561             unsigned int draught;       /* draft in meters */
562             char destination[21];       /* ship destination */
563             unsigned int dte;           /* data terminal enable */
564             //unsigned int spare;       spare bits */
565         } type5;
566         /* Type 6 - Addressed Binary Message */
567         struct {
568             unsigned int seqno;         /* sequence number */
569             unsigned int dest_mmsi;     /* destination MMSI */
570             bool retransmit;            /* retransmit flag */
571             //unsigned int spare;       spare bit(s) */
572             unsigned int dac;           /* Application ID */
573             unsigned int fid;           /* Functional ID */
574 #define AIS_TYPE6_BINARY_MAX    920     /* 920 bits */
575             size_t bitcount;            /* bit count of the data */
576             char bitdata[(AIS_TYPE6_BINARY_MAX + 7) / 8];
577         } type6;
578         /* Type 7 - Binary Acknowledge */
579         struct {
580             unsigned int mmsi1;
581             unsigned int mmsi2;
582             unsigned int mmsi3;
583             unsigned int mmsi4;
584             /* spares ignored, they're only padding here */
585         } type7;
586         /* Type 8 - Broadcast Binary Message */
587         struct {
588             //unsigned int spare;       spare bit(s) */
589             unsigned int dac;           /* Designated Area Code */
590             unsigned int fid;           /* Functional ID */
591 #define AIS_TYPE8_BINARY_MAX    952     /* 952 bits */
592             size_t bitcount;            /* bit count of the data */
593             char bitdata[(AIS_TYPE8_BINARY_MAX + 7) / 8];
594         } type8;
595         /* Type 9 - Standard SAR Aircraft Position Report */
596         struct {
597             unsigned int alt;           /* altitude in meters */
598 #define AIS_ALT_NOT_AVAILABLE   4095
599 #define AIS_ALT_HIGH            4094    /* 4094 meters or higher */
600             unsigned int speed;         /* speed over ground in deciknots */
601 #define AIS_SAR_SPEED_NOT_AVAILABLE     1023
602 #define AIS_SAR_FAST_MOVER      1022
603             bool accuracy;              /* position accuracy */
604             int lon;                    /* longitude */
605             int lat;                    /* latitude */
606             unsigned int course;        /* course over ground */
607             unsigned int second;        /* seconds of UTC timestamp */
608             unsigned int regional;      /* regional reserved */
609             unsigned int dte;           /* data terminal enable */
610             //unsigned int spare;       spare bits */
611             bool assigned;              /* assigned-mode flag */
612             bool raim;                  /* RAIM flag */
613             unsigned int radio;         /* radio status bits */
614         } type9;
615         /* Type 10 - UTC/Date Inquiry */
616         struct {
617             //unsigned int spare;
618             unsigned int dest_mmsi;     /* destination MMSI */
619             //unsigned int spare2;
620         } type10;
621         /* Type 12 - Safety-Related Message */
622         struct {
623             unsigned int seqno;         /* sequence number */
624             unsigned int dest_mmsi;     /* destination MMSI */
625             bool retransmit;            /* retransmit flag */
626             //unsigned int spare;       spare bit(s) */
627 #define AIS_TYPE12_TEXT_MAX     157     /* 936 bits of six-bit, plus NUL */
628             char text[AIS_TYPE12_TEXT_MAX];
629         } type12;
630         /* Type 14 - Safety-Related Broadcast Message */
631         struct {
632             //unsigned int spare;       spare bit(s) */
633 #define AIS_TYPE14_TEXT_MAX     161     /* 952 bits of six-bit, plus NUL */
634             char text[AIS_TYPE14_TEXT_MAX];
635         } type14;
636         /* Type 15 - Interrogation */
637         struct {
638             //unsigned int spare;       spare bit(s) */
639             unsigned int mmsi1;
640             unsigned int type1_1;
641             unsigned int offset1_1;
642             //unsigned int spare2;      spare bit(s) */
643             unsigned int type1_2;
644             unsigned int offset1_2;
645             //unsigned int spare3;      spare bit(s) */
646             unsigned int mmsi2;
647             unsigned int type2_1;
648             unsigned int offset2_1;
649             //unsigned int spare4;      spare bit(s) */
650         } type15;
651         /* Type 16 - Assigned Mode Command */
652         struct {
653             //unsigned int spare;       spare bit(s) */
654             unsigned int mmsi1;
655             unsigned int offset1;
656             unsigned int increment1;
657             unsigned int mmsi2;
658             unsigned int offset2;
659             unsigned int increment2;
660         } type16;
661         /* Type 17 - GNSS Broadcast Binary Message */
662         struct {
663             //unsigned int spare;       spare bit(s) */
664 #define AIS_GNSS_LATLON_SCALE   600.0
665             int lon;                    /* longitude */
666             int lat;                    /* latitude */
667             //unsigned int spare2;      spare bit(s) */
668 #define AIS_TYPE17_BINARY_MAX   736     /* 920 bits */
669             size_t bitcount;            /* bit count of the data */
670             char bitdata[(AIS_TYPE17_BINARY_MAX + 7) / 8];
671         } type17;
672         /* Type 18 - Standard Class B CS Position Report */
673         struct {
674             unsigned int reserved;      /* altitude in meters */
675             unsigned int speed;         /* speed over ground in deciknots */
676             bool accuracy;              /* position accuracy */
677             int lon;                    /* longitude */
678 #define AIS_GNS_LON_NOT_AVAILABLE       0x1a838
679             int lat;                    /* latitude */
680 #define AIS_GNS_LAT_NOT_AVAILABLE       0xd548
681             unsigned int course;        /* course over ground */
682             unsigned int heading;       /* true heading */
683             unsigned int second;        /* seconds of UTC timestamp */
684             unsigned int regional;      /* regional reserved */
685             bool cs;                    /* carrier sense unit flag */
686             bool display;               /* unit has attached display? */
687             bool dsc;                   /* unit attached to radio with DSC? */
688             bool band;                  /* unit can switch frequency bands? */
689             bool msg22;                 /* can accept Message 22 management? */
690             bool assigned;              /* assigned-mode flag */
691             bool raim;                  /* RAIM flag */
692             unsigned int radio;         /* radio status bits */
693         } type18;
694         /* Type 19 - Extended Class B CS Position Report */
695         struct {
696             unsigned int reserved;      /* altitude in meters */
697             unsigned int speed;         /* speed over ground in deciknots */
698             bool accuracy;              /* position accuracy */
699             int lon;                    /* longitude */
700             int lat;                    /* latitude */
701             unsigned int course;        /* course over ground */
702             unsigned int heading;       /* true heading */
703             unsigned int second;        /* seconds of UTC timestamp */
704             unsigned int regional;      /* regional reserved */
705             char shipname[AIS_SHIPNAME_MAXLEN+1];               /* ship name */
706             unsigned int shiptype;      /* ship type code */
707             unsigned int to_bow;        /* dimension to bow */
708             unsigned int to_stern;      /* dimension to stern */
709             unsigned int to_port;       /* dimension to port */
710             unsigned int to_starboard;  /* dimension to starboard */
711             unsigned int epfd;          /* type of position fix deviuce */
712             bool raim;                  /* RAIM flag */
713             unsigned int dte;           /* date terminal enable */
714             bool assigned;              /* assigned-mode flag */
715             //unsigned int spare;       spare bits */
716         } type19;
717         /* Type 20 - Data Link Management Message */
718         struct {
719             //unsigned int spare;       spare bit(s) */
720             unsigned int offset1;       /* TDMA slot offset */
721             unsigned int number1;       /* number of xlots to allocate */
722             unsigned int timeout1;      /* allocation timeout */
723             unsigned int increment1;    /* repeat increment */
724             unsigned int offset2;       /* TDMA slot offset */
725             unsigned int number2;       /* number of xlots to allocate */
726             unsigned int timeout2;      /* allocation timeout */
727             unsigned int increment2;    /* repeat increment */
728             unsigned int offset3;       /* TDMA slot offset */
729             unsigned int number3;       /* number of xlots to allocate */
730             unsigned int timeout3;      /* allocation timeout */
731             unsigned int increment3;    /* repeat increment */
732             unsigned int offset4;       /* TDMA slot offset */
733             unsigned int number4;       /* number of xlots to allocate */
734             unsigned int timeout4;      /* allocation timeout */
735             unsigned int increment4;    /* repeat increment */
736         } type20;
737         /* Type 21 - Aids to Navigation Report */
738         struct {
739             unsigned int aid_type;      /* aid type */
740             char name[35];              /* name of aid to navigation */
741             bool accuracy;              /* position accuracy */
742             int lon;                    /* longitude */
743             int lat;                    /* latitude */
744             unsigned int to_bow;        /* dimension to bow */
745             unsigned int to_stern;      /* dimension to stern */
746             unsigned int to_port;       /* dimension to port */
747             unsigned int to_starboard;  /* dimension to starboard */
748             unsigned int epfd;          /* type of EPFD */
749             unsigned int second;        /* second of UTC timestamp */
750             bool off_position;          /* off-position indicator */
751             unsigned int regional;      /* regional reserved field */
752             bool raim;                  /* RAIM flag */
753             bool virtual_aid;           /* is virtual station? */
754             bool assigned;              /* assigned-mode flag */
755             //unsigned int spare;       unused */
756         } type21;
757         /* Type 22 - Channel Management */
758         struct {
759             //unsigned int spare;       spare bit(s) */
760             unsigned int channel_a;     /* Channel A number */
761             unsigned int channel_b;     /* Channel B number */
762             unsigned int txrx;          /* transmit/receive mode */
763             bool power;                 /* high-power flag */
764 #define AIS_CHANNEL_LATLON_SCALE        600.0
765             union {
766                 struct {
767                     int ne_lon;         /* NE corner longitude */
768                     int ne_lat;         /* NE corner latitude */
769                     int sw_lon;         /* SW corner longitude */
770                     int sw_lat;         /* SW corner latitude */
771                 } area;
772                 struct {
773                     unsigned int dest1; /* addressed station MMSI 1 */
774                     unsigned int dest2; /* addressed station MMSI 2 */
775                 } mmsi;
776             };
777             bool addressed;             /* addressed vs. broadast flag */
778             bool band_a;                /* fix 1.5kHz band for channel A */
779             bool band_b;                /* fix 1.5kHz band for channel B */
780             unsigned int zonesize;      /* size of transitional zone */
781         } type22;
782         /* Type 23 - Group Assignment Command */
783         struct {
784             int ne_lon;                 /* NE corner longitude */
785             int ne_lat;                 /* NE corner latitude */
786             int sw_lon;                 /* SW corner longitude */
787             int sw_lat;                 /* SW corner latitude */
788             //unsigned int spare;       spare bit(s) */
789             unsigned int stationtype;   /* station type code */
790             unsigned int shiptype;      /* ship type code */
791             //unsigned int spare2;      spare bit(s) */
792             unsigned int txrx;          /* transmit-enable code */
793             unsigned int interval;      /* report interval */
794             unsigned int quiet;         /* quiet time */
795             //unsigned int spare3;      spare bit(s) */
796         } type23;
797         /* Type 24 - Class B CS Static Data Report */
798         struct {
799             char shipname[AIS_SHIPNAME_MAXLEN+1];       /* vessel name */
800             unsigned int shiptype;      /* ship type code */
801             char vendorid[8];           /* vendor ID */
802             char callsign[8];           /* callsign */
803             union {
804                 unsigned int mothership_mmsi;   /* MMSI of main vessel */
805                 struct {
806                     unsigned int to_bow;        /* dimension to bow */
807                     unsigned int to_stern;      /* dimension to stern */
808                     unsigned int to_port;       /* dimension to port */
809                     unsigned int to_starboard;  /* dimension to starboard */
810                 } dim;
811             };
812         } type24;
813         /* Type 25 - Addressed Binary Message */
814         struct {
815             bool addressed;             /* addressed-vs.broadcast flag */
816             bool structured;            /* structured-binary flag */
817             unsigned int dest_mmsi;     /* destination MMSI */
818             unsigned int app_id;        /* Application ID */
819 #define AIS_TYPE25_BINARY_MAX   128     /* Up to 128 bits */
820             size_t bitcount;            /* bit count of the data */
821             char bitdata[(AIS_TYPE25_BINARY_MAX + 7) / 8];
822         } type25;
823         /* Type 26 - Addressed Binary Message */
824         struct {
825             bool addressed;             /* addressed-vs.broadcast flag */
826             bool structured;            /* structured-binary flag */
827             unsigned int dest_mmsi;     /* destination MMSI */
828             unsigned int app_id;        /* Application ID */
829 #define AIS_TYPE26_BINARY_MAX   1004    /* Up to 128 bits */
830             size_t bitcount;            /* bit count of the data */
831             char bitdata[(AIS_TYPE26_BINARY_MAX + 7) / 8];
832             unsigned int radio;         /* radio status bits */
833         } type26;
834     };
835 };
836
837 struct attitude_t {
838     double heading;
839     double pitch;
840     double roll;
841     double yaw;
842     double dip;
843     double mag_len; /* unitvector sqrt(x^2 + y^2 +z^2) */
844     double mag_x;
845     double mag_y;
846     double mag_z;
847     double acc_len; /* unitvector sqrt(x^2 + y^2 +z^2) */
848     double acc_x;
849     double acc_y;
850     double acc_z;
851     double gyro_x;
852     double gyro_y;
853     double temp;
854     double depth;
855     /* compass status -- TrueNorth (and any similar) devices only */
856     char mag_st;
857     char pitch_st;
858     char roll_st;
859     char yaw_st;
860 };
861
862 struct dop_t {
863     /* Dilution of precision factors */
864     double xdop, ydop, pdop, hdop, vdop, tdop, gdop;
865 };
866
867 struct rawdata_t {
868     /* raw measurement data */
869     double codephase[MAXCHANNELS];      /* meters */
870     double carrierphase[MAXCHANNELS];   /* meters */
871     double pseudorange[MAXCHANNELS];    /* meters */
872     double deltarange[MAXCHANNELS];     /* meters/sec */
873     double doppler[MAXCHANNELS];        /* Hz */
874     double mtime[MAXCHANNELS];          /* sec */
875     unsigned satstat[MAXCHANNELS];      /* tracking status */
876 #define SAT_ACQUIRED    0x01            /* satellite acquired */
877 #define SAT_CODE_TRACK  0x02            /* code-tracking loop acquired */
878 #define SAT_CARR_TRACK  0x04            /* carrier-tracking loop acquired */
879 #define SAT_DATA_SYNC   0x08            /* data-bit synchronization done */
880 #define SAT_FRAME_SYNC  0x10            /* frame synchronization done */
881 #define SAT_EPHEMERIS   0x20            /* ephemeris collected */
882 #define SAT_FIX_USED    0x40            /* used for position fix */
883 };
884
885 struct version_t {
886     char release[64];                   /* external version */
887     char rev[64];                       /* internal revision ID */
888     int proto_major, proto_minor;       /* API major and minor versions */
889 };
890
891 struct devconfig_t {
892     char path[GPS_PATH_MAX];
893     int flags;
894 #define SEEN_GPS        0x01
895 #define SEEN_RTCM2      0x02
896 #define SEEN_RTCM3      0x04
897 #define SEEN_AIS        0x08
898     char driver[64];
899     char subtype[64];
900     double activated;
901     unsigned int baudrate, stopbits;    /* RS232 link parameters */
902     char parity;                        /* 'N', 'O', or 'E' */
903     double cycle, mincycle;             /* refresh cycle time in seconds */
904     int driver_mode;                    /* is driver in native mode or not? */
905 };
906
907 struct policy_t {
908     bool watcher;                       /* is watcher mode on? */
909     bool json;                          /* requesting JSON? */
910     bool nmea;                          /* requesting dumping as NMEA? */
911     int raw;                            /* requesting raw data? */
912     bool scaled;                        /* requesting report scaling? */ 
913     bool timing;                        /* requesting timing info */
914     char devpath[GPS_PATH_MAX];         /* specific device to watch */   
915 };
916
917 /* 
918  * Someday we may support Windows, under which socket_t is a separate type.
919  * In the meantime, having a typedef for this semantic kind is no bad thing,
920  * as it makes clearer what some declarations are doing without breaking
921  * binary compatibility. 
922  */
923 typedef int socket_t;
924
925 /* mode flags for setting streaming policy */
926 #define WATCH_ENABLE    0x0001u /* enable streaming */
927 #define WATCH_JSON      0x0002u /* enable JSON output */
928 #define WATCH_NMEA      0x0004u /* enable output in NMEA */
929 #define WATCH_RARE      0x0008u /* enable output of packets in hex */
930 #define WATCH_RAW       0x0010u /* enable output of raw packets */
931 #define WATCH_SCALED    0x0020u /* scale output to floats, when applicable */ 
932 #define WATCH_NEWSTYLE  0x0040u /* force JSON streaming */
933 #define WATCH_OLDSTYLE  0x0080u /* force old-style streaming */
934 #define WATCH_DEVICE    0x0100u /* watch specific device */
935 #define WATCH_DISABLE   0x0200u /* disable watching */
936 #define POLL_NONBLOCK   0x1000u /* set non-blocking poll (experimental!) */
937
938 /* 
939  * Main structure that includes all previous substructures
940  */
941
942 struct gps_data_t {
943     gps_mask_t set;     /* has field been set since this was last cleared? */
944 #define ONLINE_SET      0x00000001u
945 #define TIME_SET        0x00000002u
946 #define TIMERR_SET      0x00000004u
947 #define LATLON_SET      0x00000008u
948 #define ALTITUDE_SET    0x00000010u
949 #define SPEED_SET       0x00000020u
950 #define TRACK_SET       0x00000040u
951 #define CLIMB_SET       0x00000080u
952 #define STATUS_SET      0x00000100u
953 #define MODE_SET        0x00000200u
954 #define DOP_SET         0x00000400u
955 #define VERSION_SET     0x00000800u
956 #define HERR_SET        0x00001000u
957 #define VERR_SET        0x00002000u
958 #define ATTITUDE_SET    0x00004000u
959 #define POLICY_SET      0x00008000u
960 #define SATELLITE_SET   0x00010000u
961 #define RAW_SET         0x00020000u
962 #define USED_SET        0x00040000u
963 #define SPEEDERR_SET    0x00080000u
964 #define TRACKERR_SET    0x00100000u
965 #define CLIMBERR_SET    0x00200000u
966 #define DEVICE_SET      0x00400000u
967 #define DEVICELIST_SET  0x00800000u
968 #define DEVICEID_SET    0x01000000u
969 #define ERROR_SET       0x02000000u
970 #define RTCM2_SET       0x04000000u
971 #define RTCM3_SET       0x08000000u
972 #define AIS_SET         0x10000000u
973 #define PACKET_SET      0x20000000u
974 #define AUXDATA_SET     0x80000000u     /* reserved */
975     double online;              /* NZ if GPS is on line, 0 if not.
976                                  *
977                                  * Note: gpsd clears this time when sentences
978                                  * fail to show up within the GPS's normal
979                                  * send cycle time. If the host-to-GPS 
980                                  * link is lossy enough to drop entire
981                                  * sentences, this field will be
982                                  * prone to false zero values.
983                                  */
984
985 #ifndef USE_QT
986     socket_t gps_fd;            /* socket or file descriptor to GPS */
987 #else
988     void* gps_fd;
989 #endif
990     struct gps_fix_t    fix;    /* accumulated PVT data */
991
992     double separation;          /* Geoidal separation, MSL - WGS84 (Meters) */
993
994     /* GPS status -- always valid */
995     int    status;              /* Do we have a fix? */
996 #define STATUS_NO_FIX   0       /* no */
997 #define STATUS_FIX      1       /* yes, without DGPS */
998 #define STATUS_DGPS_FIX 2       /* yes, with DGPS */
999
1000     /* precision of fix -- valid if satellites_used > 0 */
1001     int satellites_used;        /* Number of satellites used in solution */
1002     int used[MAXCHANNELS];      /* PRNs of satellites used in solution */
1003     struct dop_t dop;
1004
1005     /* redundant with the estimate elements in the fix structure */
1006     double epe;  /* spherical position error, 95% confidence (meters)  */
1007
1008     /* satellite status -- valid when satellites_visible > 0 */
1009     double skyview_time;        /* skyview timestamp */
1010     int satellites_visible;     /* # of satellites in view */
1011     int PRN[MAXCHANNELS];       /* PRNs of satellite */
1012     int elevation[MAXCHANNELS]; /* elevation of satellite */
1013     int azimuth[MAXCHANNELS];   /* azimuth */
1014     double ss[MAXCHANNELS];     /* signal-to-noise ratio (dB) */
1015
1016     struct devconfig_t dev;     /* device that shipped last update */
1017
1018     struct policy_t policy;     /* our listening policy */
1019
1020     char tag[MAXTAGLEN+1];      /* tag of last sentence processed */
1021
1022     void (*raw_hook)(struct gps_data_t *, char *, size_t len);  /* Raw-mode hook for GPS data. */
1023
1024     /* pack things never reported together to reduce structure size */ 
1025 #define UNION_SET       (RTCM2_SET|RTCM3_SET|AIS_SET|VERSION_SET|DEVICELIST_SET|ERROR_SET)
1026     union {
1027         /* unusual forms of sensor data that might come up the pipe */ 
1028         struct rtcm2_t  rtcm2;
1029         struct rtcm3_t  rtcm3;
1030         struct ais_t ais;
1031         struct attitude_t attitude;
1032         struct rawdata_t raw;
1033         /* "artificial" structures for various protocol responses */
1034         struct version_t version;
1035         struct {
1036             double time;
1037             int ndevices;
1038             struct devconfig_t list[MAXUSERDEVS];
1039         } devices;
1040         char error[80];
1041     };
1042
1043     /* Private data - client code must not set this */
1044     void *privdata;
1045 };
1046
1047 extern int gps_open_r(/*@null@*/const char *, /*@null@*/const char *, 
1048                       /*@out@*/struct gps_data_t *);
1049 extern /*@null@*/struct gps_data_t *gps_open(const char *, const char *);
1050 extern int gps_close(struct gps_data_t *);
1051 extern int gps_send(struct gps_data_t *, const char *, ... );
1052 extern int gps_read(/*@out@*/struct gps_data_t *);
1053 extern int gps_poll(/*@out@*/struct gps_data_t *);
1054 extern bool gps_waiting(struct gps_data_t *);
1055 extern int gps_stream(struct gps_data_t *, unsigned int, /*@null@*/void *);
1056 extern void gps_set_raw_hook(struct gps_data_t *, 
1057                              void (*)(struct gps_data_t *, char *, size_t));
1058 extern char /*@observer@*/ *gps_errstr(const int);
1059
1060 /* this only needs to be visible for the unit tests */
1061 extern int gps_unpack(char *, struct gps_data_t *);
1062
1063 /* dependencies on struct gpsdata_t end hrere */
1064
1065 extern void gps_clear_fix(/*@ out @*/struct gps_fix_t *);
1066 extern void gps_merge_fix(/*@ out @*/struct gps_fix_t *,
1067                           gps_mask_t,
1068                           /*@ in @*/struct gps_fix_t *);
1069 extern void gps_enable_debug(int, FILE *);
1070 extern /*@observer@*/const char *gps_maskdump(gps_mask_t);
1071
1072 extern time_t mkgmtime(register struct tm *);
1073 extern double timestamp(void);
1074 extern double iso8601_to_unix(char *);
1075 extern /*@observer@*/char *unix_to_iso8601(double t, /*@ out @*/char[], size_t len);
1076 extern double gpstime_to_unix(int, double);
1077 extern void unix_to_gpstime(double, /*@out@*/int *, /*@out@*/double *);
1078 extern double earth_distance(double, double, double, double);
1079 extern double wgs84_separation(double, double);
1080
1081 /* some multipliers for interpreting GPS output */
1082 #define METERS_TO_FEET  3.2808399       /* Meters to U.S./British feet */
1083 #define METERS_TO_MILES 0.00062137119   /* Meters to miles */
1084 #define KNOTS_TO_MPH    1.1507794       /* Knots to miles per hour */
1085 #define KNOTS_TO_KPH    1.852           /* Knots to kilometers per hour */
1086 #define KNOTS_TO_MPS    0.51444444      /* Knots to meters per second */
1087 #define MPS_TO_KPH      3.6             /* Meters per second to klicks/hr */
1088 #define MPS_TO_MPH      2.2369363       /* Meters/second to miles per hour */
1089 #define MPS_TO_KNOTS    1.9438445       /* Meters per second to knots */
1090 /* miles and knots are both the international standard versions of the units */
1091
1092 /* angle conversion multipliers */
1093 #define GPS_PI          3.1415926535897932384626433832795029
1094 #define RAD_2_DEG       57.2957795130823208767981548141051703
1095 #define DEG_2_RAD       0.0174532925199432957692369076848861271
1096
1097 /* geodetic constants */
1098 #define WGS84A 6378137          /* equatorial radius */
1099 #define WGS84F 298.257223563    /* flattening */
1100 #define WGS84B 6356752.3142     /* polar radius */
1101
1102 /* netlib_connectsock() errno return values */
1103 #define NL_NOSERVICE    -1      /* can't get service entry */
1104 #define NL_NOHOST       -2      /* can't get host entry */
1105 #define NL_NOPROTO      -3      /* can't get protocol entry */
1106 #define NL_NOSOCK       -4      /* can't create socket */
1107 #define NL_NOSOCKOPT    -5      /* error SETSOCKOPT SO_REUSEADDR */
1108 #define NL_NOCONNECT    -6      /* can't connect to host/socket pair */
1109
1110 #define DEFAULT_GPSD_PORT       "2947"  /* IANA assignment */
1111 #define DEFAULT_RTCM_PORT       "2101"  /* IANA assignment */
1112
1113 #ifdef __cplusplus
1114 }  /* End of the 'extern "C"' block */
1115 #endif
1116
1117 /* gps.h ends here */
1118 #endif /* _GPSD_GPS_H_ */