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