-
Notifications
You must be signed in to change notification settings - Fork 15
/
gps.h
1804 lines (1726 loc) · 65.7 KB
/
gps.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* gps.h -- interface of the libgps library */
/*
* This file is Copyright (c) 2010 by the GPSD project
* BSD terms apply: see the file COPYING in the distribution root for details.
*/
#ifndef _GPSD_GPS_H_
#define _GPSD_GPS_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Macro for declaring function arguments unused. */
#if defined(__GNUC__)
# define UNUSED __attribute__((unused)) /* Flag variable as unused */
#else /* not __GNUC__ */
# define UNUSED
#endif
#include <sys/types.h>
#include <sys/time.h>
#include <stdbool.h>
#include <inttypes.h> /* stdint.h would be smaller but not all have it */
#include <limits.h>
#include <time.h>
#include <signal.h>
#include <stdio.h>
#ifndef S_SPLINT_S
#include <pthread.h> /* pacifies OpenBSD's compiler */
#endif
/*
* 4.1 - Base version for initial JSON protocol (Dec 2009, release 2.90)
* 4.2 - AIS application IDs split into DAC and FID (July 2010, release 2.95)
* 5.0 - MAXCHANNELS bumped from 20 to 32 for GLONASS (July 2010)
* gps_open() becomes reentrant, what gps_open_r() used to be.
* gps_poll() removed in favor of gps_read(). The raw hook is gone.
*/
#define GPSD_API_MAJOR_VERSION 5 /* bump on incompatible changes */
#define GPSD_API_MINOR_VERSION 0 /* bump on compatible changes */
#define MAXTAGLEN 8 /* maximum length of sentence tag name */
#define MAXCHANNELS 72 /* must be > 12 GPS + 12 GLONASS + 2 WAAS */
#define GPS_PRNMAX 32 /* above this number are SBAS satellites */
#define GPS_PATH_MAX 64 /* dev files usually have short names */
#define MAXUSERDEVS 4 /* max devices per user */
/*
* The structure describing an uncertainty volume in kinematic space.
* This is what GPSes are meant to produce; all the other info is
* technical impedimenta.
*
* All double values use NAN to indicate data not available.
*
* Usually all the information in this structure was considered valid
* by the GPS at the time of update. This will be so if you are using
* a GPS chipset that speaks SiRF binary, Garmin binary, or Zodiac binary.
* This covers over 80% of GPS products in early 2005.
*
* If you are using a chipset that speaks NMEA, this structure is updated
* in bits by GPRMC (lat/lon, track, speed), GPGGA (alt, climb), GPGLL
* (lat/lon), and GPGSA (eph, epv). Most NMEA GPSes take a single fix
* at the beginning of a 1-second cycle and report the same timestamp in
* GPRMC, GPGGA, and GPGLL; for these, all info is guaranteed correctly
* synced to the time member, but you'll get different stages of the same
* update depending on where in the cycle you poll. A very few GPSes,
* like the Garmin 48, take a new fix before more than one of of
* GPRMC/GPGGA/GPGLL during a single cycle; thus, they may have different
* timestamps and some data in this structure can be up to 1 cycle (usually
* 1 second) older than the fix time.
*
* Error estimates are at 95% confidence.
*/
typedef double timestamp_t; /* Unix time in seconds with fractional part */
struct gps_fix_t {
timestamp_t time; /* Time of update */
int mode; /* Mode of fix */
#define MODE_NOT_SEEN 0 /* mode update not seen yet */
#define MODE_NO_FIX 1 /* none */
#define MODE_2D 2 /* good for latitude/longitude */
#define MODE_3D 3 /* good for altitude/climb too */
double ept; /* Expected time uncertainty */
double latitude; /* Latitude in degrees (valid if mode >= 2) */
double epy; /* Latitude position uncertainty, meters */
double longitude; /* Longitude in degrees (valid if mode >= 2) */
double epx; /* Longitude position uncertainty, meters */
double altitude; /* Altitude in meters (valid if mode == 3) */
double epv; /* Vertical position uncertainty, meters */
double track; /* Course made good (relative to true north) */
double epd; /* Track uncertainty, degrees */
double speed; /* Speed over ground, meters/sec */
double eps; /* Speed uncertainty, meters/sec */
double climb; /* Vertical speed, meters/sec */
double epc; /* Vertical speed uncertainty */
};
/*
* The structure describing the pseudorange errors (GPGST)
*/
struct gst_t {
double utctime;
double rms_deviation;
double smajor_deviation;
double sminor_deviation;
double smajor_orientation;
double lat_err_deviation;
double lon_err_deviation;
double alt_err_deviation;
};
/*
* From the RCTM104 2.x standard:
*
* "The 30 bit words (as opposed to 32 bit words) coupled with a 50 Hz
* transmission rate provides a convenient timing capability where the
* times of word boundaries are a rational multiple of 0.6 seconds."
*
* "Each frame is N+2 words long, where N is the number of message data
* words. For example, a filler message (type 6 or 34) with no message
* data will have N=0, and will consist only of two header words. The
* maximum number of data words allowed by the format is 31, so that
* the longest possible message will have a total of 33 words."
*/
#define RTCM2_WORDS_MAX 33
#define MAXCORRECTIONS 18 /* max correction count in type 1 or 9 */
#define MAXSTATIONS 10 /* maximum stations in almanac, type 5 */
/* RTCM104 doesn't specify this, so give it the largest reasonable value */
#define MAXHEALTH (RTCM2_WORDS_MAX-2)
#ifndef S_SPLINT_S
/*
* A nominally 30-bit word (24 bits of data, 6 bits of parity)
* used both in the GPS downlink protocol described in IS-GPS-200
* and in the format for DGPS corrections used in RTCM-104v2.
*/
typedef /*@unsignedintegraltype@*/ uint32_t isgps30bits_t;
#endif /* S_SPLINT_S */
/*
* Values for "system" fields. Note, the encoding logic is senstive to the
* actual values of these; it's not sufficient that they're distinct.
*/
#define NAVSYSTEM_GPS 0
#define NAVSYSTEM_GLONASS 1
#define NAVSYSTEM_GALILEO 2
#define NAVSYSTEM_UNKNOWN 3
struct rtcm2_t {
/* header contents */
unsigned type; /* RTCM message type */
unsigned length; /* length (words) */
double zcount; /* time within hour: GPS time, no leap secs */
unsigned refstaid; /* reference station ID */
unsigned seqnum; /* message sequence number (modulo 8) */
unsigned stathlth; /* station health */
/* message data in decoded form */
union {
struct {
unsigned int nentries;
struct gps_rangesat_t { /* data from messages 1 & 9 */
unsigned ident; /* satellite ID */
unsigned udre; /* user diff. range error */
unsigned iod; /* issue of data */
double prc; /* range error */
double rrc; /* range error rate */
} sat[MAXCORRECTIONS];
} gps_ranges;
struct { /* data for type 3 messages */
bool valid; /* is message well-formed? */
double x, y, z;
} ecef;
struct { /* data from type 4 messages */
bool valid; /* is message well-formed? */
int system;
int sense;
#define SENSE_INVALID 0
#define SENSE_GLOBAL 1
#define SENSE_LOCAL 2
char datum[6];
double dx, dy, dz;
} reference;
struct { /* data from type 5 messages */
unsigned int nentries;
struct consat_t {
unsigned ident; /* satellite ID */
bool iodl; /* issue of data */
unsigned int health; /* is satellite healthy? */
#define HEALTH_NORMAL (0) /* Radiobeacon operation normal */
#define HEALTH_UNMONITORED (1) /* No integrity monitor operating */
#define HEALTH_NOINFO (2) /* No information available */
#define HEALTH_DONOTUSE (3) /* Do not use this radiobeacon */
int snr; /* signal-to-noise ratio, dB */
#define SNR_BAD -1 /* not reported */
bool health_en; /* health enabled */
bool new_data; /* new data? */
bool los_warning; /* line-of-sight warning */
unsigned int tou; /* time to unhealth, seconds */
} sat[MAXHEALTH];
} conhealth;
struct { /* data from type 7 messages */
unsigned int nentries;
struct station_t {
double latitude, longitude; /* location */
unsigned int range; /* range in km */
double frequency; /* broadcast freq */
unsigned int health; /* station health */
unsigned int station_id; /* of the transmitter */
unsigned int bitrate; /* of station transmissions */
} station[MAXSTATIONS];
} almanac;
struct { /* data for type 13 messages */
bool status; /* expect a text message */
bool rangeflag; /* station range altered? */
double lat, lon; /* station longitude/latitude */
unsigned int range; /* transmission range in km */
} xmitter;
struct { /* data from type 14 messages */
unsigned int week; /* GPS week (0-1023) */
unsigned int hour; /* Hour in week (0-167) */
unsigned int leapsecs; /* Leap seconds (0-63) */
} gpstime;
struct {
unsigned int nentries;
struct glonass_rangesat_t { /* data from message type 31 */
unsigned ident; /* satellite ID */
unsigned udre; /* user diff. range error */
unsigned tod; /* issue of data */
bool change; /* ephemeris change bit */
double prc; /* range error */
double rrc; /* range error rate */
} sat[MAXCORRECTIONS];
} glonass_ranges;
/* data from type 16 messages */
char message[(RTCM2_WORDS_MAX-2) * sizeof(isgps30bits_t)];
/* data from messages of unknown type */
isgps30bits_t words[RTCM2_WORDS_MAX-2];
};
};
/* RTCM3 report structures begin here */
#define RTCM3_MAX_SATELLITES 64
#define RTCM3_MAX_DESCRIPTOR 31
#define RTCM3_MAX_ANNOUNCEMENTS 32
struct rtcm3_rtk_hdr { /* header data from 1001, 1002, 1003, 1004 */
/* Used for both GPS and GLONASS, but their timebases differ */
unsigned int station_id; /* Reference Station ID */
time_t tow; /* GPS Epoch Time (TOW) in ms,
or GLONASS Epoch Time in ms */
bool sync; /* Synchronous GNSS Message Flag */
unsigned short satcount; /* # Satellite Signals Processed */
bool smoothing; /* Divergence-free Smoothing Indicator */
unsigned short interval; /* Smoothing Interval */
};
struct rtcm3_basic_rtk {
unsigned char indicator; /* Indicator */
short channel; /* Satellite Frequency Channel Number
(GLONASS only) */
double pseudorange; /* Pseudorange */
double rangediff; /* PhaseRange – Pseudorange in meters */
unsigned char locktime; /* Lock time Indicator */
};
struct rtcm3_extended_rtk {
unsigned char indicator; /* Indicator */
short channel; /* Satellite Frequency Channel Number
(GLONASS only) */
double pseudorange; /* Pseudorange */
double rangediff; /* PhaseRange – L1 Pseudorange */
unsigned char locktime; /* Lock time Indicator */
unsigned char ambiguity; /* Integer Pseudorange
Modulus Ambiguity */
double CNR; /* Carrier-to-Noise Ratio */
};
struct rtcm3_network_rtk_header {
unsigned int network_id; /* Network ID */
unsigned int subnetwork_id; /* Subnetwork ID */
time_t time; /* GPS Epoch Time (TOW) in ms */
bool multimesg; /* GPS Multiple Message Indicator */
unsigned master_id; /* Master Reference Station ID */
unsigned aux_id; /* Auxilary Reference Station ID */
unsigned char satcount; /* count of GPS satellites */
};
struct rtcm3_correction_diff {
unsigned char ident; /* satellite ID */
enum {reserved, correct, widelane, uncertain} ambiguity;
unsigned char nonsync;
double geometric_diff; /* Geometric Carrier Phase
Correction Difference (1016, 1017) */
unsigned char iode; /* GPS IODE (1016, 1017) */
double ionospheric_diff; /* Ionospheric Carrier Phase
Correction Difference (1015, 1017) */
};
struct rtcm3_t {
/* header contents */
unsigned type; /* RTCM 3.x message type */
unsigned length; /* payload length, inclusive of checksum */
union {
/* 1001-1013 were present in the 3.0 version */
struct {
struct rtcm3_rtk_hdr header;
struct rtcm3_1001_t {
unsigned ident; /* Satellite ID */
struct rtcm3_basic_rtk L1;
} rtk_data[RTCM3_MAX_SATELLITES];
} rtcm3_1001;
struct rtcm3_1002_t {
struct rtcm3_rtk_hdr header;
struct {
unsigned ident; /* Satellite ID */
struct rtcm3_extended_rtk L1;
} rtk_data[RTCM3_MAX_SATELLITES];
} rtcm3_1002;
struct rtcm3_1003_t {
struct rtcm3_rtk_hdr header;
struct {
unsigned ident; /* Satellite ID */
struct rtcm3_basic_rtk L1;
struct rtcm3_basic_rtk L2;
} rtk_data[RTCM3_MAX_SATELLITES];
} rtcm3_1003;
struct rtcm3_1004_t {
struct rtcm3_rtk_hdr header;
struct {
unsigned ident; /* Satellite ID */
struct rtcm3_extended_rtk L1;
struct rtcm3_extended_rtk L2;
} rtk_data[RTCM3_MAX_SATELLITES];
} rtcm3_1004;
struct rtcm3_1005_t {
unsigned int station_id; /* Reference Station ID */
int system; /* Which system is it? */
bool reference_station; /* Reference-station indicator */
bool single_receiver; /* Single Receiver Oscillator */
double ecef_x, ecef_y, ecef_z; /* ECEF antenna location */
} rtcm3_1005;
struct rtcm3_1006_t {
unsigned int station_id; /* Reference Station ID */
int system; /* Which system is it? */
bool reference_station; /* Reference-station indicator */
bool single_receiver; /* Single Receiver Oscillator */
double ecef_x, ecef_y, ecef_z; /* ECEF antenna location */
double height; /* Antenna height */
} rtcm3_1006;
struct rtcm3_1007_t {
unsigned int station_id; /* Reference Station ID */
char descriptor[RTCM3_MAX_DESCRIPTOR+1]; /* Description string */
unsigned char setup_id;
} rtcm3_1007;
struct rtcm3_1008_t {
unsigned int station_id; /* Reference Station ID */
char descriptor[RTCM3_MAX_DESCRIPTOR+1]; /* Description string */
unsigned char setup_id;
char serial[RTCM3_MAX_DESCRIPTOR+1]; /* Serial # string */
} rtcm3_1008;
struct rtcm3_1009_t {
struct rtcm3_rtk_hdr header;
struct {
unsigned ident; /* Satellite ID */
struct rtcm3_basic_rtk L1;
} rtk_data[RTCM3_MAX_SATELLITES];
} rtcm3_1009;
struct rtcm3_1010_t {
struct rtcm3_rtk_hdr header;
struct {
unsigned ident; /* Satellite ID */
struct rtcm3_extended_rtk L1;
} rtk_data[RTCM3_MAX_SATELLITES];
} rtcm3_1010;
struct rtcm3_1011_t {
struct rtcm3_rtk_hdr header;
struct {
unsigned ident; /* Satellite ID */
struct rtcm3_extended_rtk L1;
struct rtcm3_extended_rtk L2;
} rtk_data[RTCM3_MAX_SATELLITES];
} rtcm3_1011;
struct rtcm3_1012_t {
struct rtcm3_rtk_hdr header;
struct {
unsigned ident; /* Satellite ID */
struct rtcm3_extended_rtk L1;
struct rtcm3_extended_rtk L2;
} rtk_data[RTCM3_MAX_SATELLITES];
} rtcm3_1012;
struct rtcm3_1013_t {
unsigned int station_id; /* Reference Station ID */
unsigned short mjd; /* Modified Julian Day (MJD) Number */
unsigned int sod; /* Seconds of Day (UTC) */
unsigned char leapsecs; /* Leap Seconds, GPS-UTC */
unsigned char ncount; /* Count of announcements to follow */
struct {
unsigned short id; /* message type ID */
bool sync;
unsigned short interval; /* interval in 0.1sec units */
} announcements[RTCM3_MAX_ANNOUNCEMENTS];
} rtcm3_1013;
/* 1014-1017 were added in the 3.1 version */
struct rtcm3_1014_t {
unsigned int network_id; /* Network ID */
unsigned int subnetwork_id; /* Subnetwork ID */
unsigned char stationcount; /* # auxiliary stations transmitted */
unsigned int master_id; /* Master Reference Station ID */
unsigned int aux_id; /* Auxilary Reference Station ID */
double d_lat, d_lon, d_alt; /* Aux-master location delta */
} rtcm3_1014;
struct rtcm3_1015_t {
struct rtcm3_network_rtk_header header;
struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
} rtcm3_1015;
struct rtcm3_1016_t {
struct rtcm3_network_rtk_header header;
struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
} rtcm3_1016;
struct rtcm3_1017_t {
struct rtcm3_network_rtk_header header;
struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
} rtcm3_1017;
/* 1018-1029 were in the 3.0 version */
struct rtcm3_1019_t {
unsigned int ident; /* Satellite ID */
unsigned int week; /* GPS Week Number */
unsigned char sv_accuracy; /* GPS SV ACCURACY */
enum {reserved_code, p, ca, l2c} code;
double idot;
unsigned char iode;
/* ephemeris fields, not scaled */
unsigned int t_sub_oc;
signed int a_sub_f2;
signed int a_sub_f1;
signed int a_sub_f0;
unsigned int iodc;
signed int C_sub_rs;
signed int delta_sub_n;
signed int M_sub_0;
signed int C_sub_uc;
unsigned int e;
signed int C_sub_us;
unsigned int sqrt_sub_A;
unsigned int t_sub_oe;
signed int C_sub_ic;
signed int OMEGA_sub_0;
signed int C_sub_is;
signed int i_sub_0;
signed int C_sub_rc;
signed int argument_of_perigee;
signed int omegadot;
signed int t_sub_GD;
unsigned char sv_health;
bool p_data;
bool fit_interval;
} rtcm3_1019;
struct rtcm3_1020_t {
unsigned int ident; /* Satellite ID */
unsigned short channel; /* Satellite Frequency Channel Number */
/* ephemeris fields, not scaled */
bool C_sub_n;
bool health_avAilability_indicator;
unsigned char P1;
unsigned short t_sub_k;
bool msb_of_B_sub_n;
bool P2;
bool t_sub_b;
signed int x_sub_n_t_of_t_sub_b_prime;
signed int x_sub_n_t_of_t_sub_b;
signed int x_sub_n_t_of_t_sub_b_prime_prime;
signed int y_sub_n_t_of_t_sub_b_prime;
signed int y_sub_n_t_of_t_sub_b;
signed int y_sub_n_t_of_t_sub_b_prime_prime;
signed int z_sub_n_t_of_t_sub_b_prime;
signed int z_sub_n_t_of_t_sub_b;
signed int z_sub_n_t_of_t_sub_b_prime_prime;
bool P3;
signed int gamma_sub_n_of_t_sub_b;
unsigned char MP;
bool Ml_n;
signed int tau_n_of_t_sub_b;
signed int M_delta_tau_sub_n;
unsigned int E_sub_n;
bool MP4;
unsigned char MF_sub_T;
unsigned char MN_sub_T;
unsigned char MM;
bool additioinal_data_availability;
unsigned int N_sup_A;
unsigned int tau_sub_c;
unsigned int M_N_sub_4;
signed int M_tau_sub_GPS;
bool M_l_sub_n;
} rtcm3_1020;
struct rtcm3_1029_t {
unsigned int station_id; /* Reference Station ID */
unsigned short mjd; /* Modified Julian Day (MJD) Number */
unsigned int sod; /* Seconds of Day (UTC) */
size_t len; /* # chars to follow */
size_t unicode_units; /* # Unicode units in text */
unsigned char text[128];
} rtcm3_1029;
struct rtcm3_1033_t {
unsigned int station_id; /* Reference Station ID */
char descriptor[RTCM3_MAX_DESCRIPTOR+1]; /* Description string */
unsigned char setup_id;
char serial[RTCM3_MAX_DESCRIPTOR+1]; /* Serial # string */
char receiver[RTCM3_MAX_DESCRIPTOR+1]; /* Receiver string */
char firmware[RTCM3_MAX_DESCRIPTOR+1]; /* Firmware string */
} rtcm3_1033;
char data[1024]; /* Max RTCM3 msg length is 1023 bytes */
} rtcmtypes;
};
/* RTCM3 scaling constants */
#define GPS_AMBIGUITY_MODULUS 299792.458 /* 1004, DF014*/
#define GLONASS_AMBIGUITY_MODULUS 599584.916 /* 1012, DF044 */
#define MESSAGE_INTERVAL_UNITS 0.1 /* 1013, DF047 */
/*
* Raw IS_GPS subframe data
*/
/* The almanac is a subset of the clock and ephemeris data, with reduced
* precision. See IS-GPS-200E, Table 20-VI */
struct almanac_t
{
uint8_t sv; /* The satellite this refers to */
/* toa, almanac reference time, 8 bits unsigned, seconds */
uint8_t toa;
long l_toa;
/* SV health data, 8 bit unsigned bit map */
uint8_t svh;
/* deltai, correction to inclination, 16 bits signed, semi-circles */
int16_t deltai;
double d_deltai;
/* M0, Mean Anomaly at Reference Time, 24 bits signed, semi-circles */
int32_t M0;
double d_M0;
/* Omega0, Longitude of Ascending Node of Orbit Plane at Weekly Epoch,
* 24 bits signed, semi-circles */
int32_t Omega0;
double d_Omega0;
/* omega, Argument of Perigee, 24 bits signed, semi-circles */
int32_t omega;
double d_omega;
/* af0, SV clock correction constant term
* 11 bits signed, seconds */
int16_t af0;
double d_af0;
/* af1, SV clock correction first order term
* 11 bits signed, seconds/second */
int16_t af1;
double d_af1;
/* eccentricity, 16 bits, unsigned, dimensionless */
uint16_t e;
double d_eccentricity;
/* sqrt A, Square Root of the Semi-Major Axis
* 24 bits unsigned, square_root(meters) */
uint32_t sqrtA;
double d_sqrtA;
/* Omega dot, Rate of Right Ascension, 16 bits signed, semi-circles/sec */
int16_t Omegad;
double d_Omegad;
};
struct subframe_t {
/* subframe number, 3 bits, unsigned, 1 to 5 */
uint8_t subframe_num;
/* data_id, denotes the NAV data structure of D(t), 2 bits, in
* IS-GPS-200E always == 0x1 */
uint8_t data_id;
/* SV/page id used for subframes 4 & 5, 6 bits */
uint8_t pageid;
/* tSVID, SV ID of the sat that transmitted this frame, 6 bits unsigned */
uint8_t tSVID;
/* TOW, Time of Week of NEXT message, 17 bits unsigned, scale 6, seconds */
uint32_t TOW17;
long l_TOW17;
/* integrity, URA bounds flag, 1 bit */
bool integrity;
/* alert, alert flag, SV URA and/or the SV User Differential Range
* Accuracy (UDRA) may be worse than indicated, 1 bit */
bool alert;
/* antispoof, A-S mode is ON in that SV, 1 bit */
bool antispoof;
int is_almanac;
union {
/* subframe 1, part of ephemeris, see IS-GPS-200E, Table 20-II
* and Table 20-I */
struct {
/* WN, Week Number, 10 bits unsigned, scale 1, weeks */
uint16_t WN;
/* IODC, Issue of Data, Clock, 10 bits, unsigned,
* issued in 8 data ranges at the same time */
uint16_t IODC;
/* toc, clock data reference time, 16 bits, unsigned, seconds
* scale 2**4, issued in 8 data ranges at the same time */
uint16_t toc;
long l_toc;
/* l2, code on L2, 2 bits, bit map */
uint8_t l2;
/* l2p, L2 P data flag, 1 bit */
uint8_t l2p;
/* ura, SV accuracy, 4 bits unsigned index */
unsigned int ura;
/* hlth, SV health, 6 bits unsigned bitmap */
unsigned int hlth;
/* af0, SV clock correction constant term
* 22 bits signed, scale 2**-31, seconds */
int32_t af0;
double d_af0;
/* af1, SV clock correction first order term
* 22 bits signed, scale 2**-43, seconds/second */
int16_t af1;
double d_af1;
/* af2, SV clock correction second order term
* 8 bits signed, scale 2**-55, seconds/second**2 */
int8_t af2;
double d_af2;
/* Tgd, L1-L2 correction term, 8 bits signed, scale 2**-31,
* seconds */
int8_t Tgd;
double d_Tgd;
} sub1;
/* subframe 2, part of ephemeris, see IS-GPS-200E, Table 20-II
* and Table 20-III */
struct {
/* Issue of Data (Ephemeris),
* equal to the 8 LSBs of the 10 bit IODC of the same data set */
uint8_t IODE;
/* Age of Data Offset for the NMCT, 6 bits, scale 900,
* ignore if all ones, seconds */
uint8_t AODO;
uint16_t u_AODO;
/* fit, FIT interval flag, indicates a fit interval greater than
* 4 hour, 1 bit */
uint8_t fit;
/* toe, Reference Time Ephemeris, 16 bits unsigned, scale 2**4,
* seconds */
uint16_t toe;
long l_toe;
/* Crs, Amplitude of the Sine Harmonic Correction Term to the
* Orbit Radius, 16 bits, scale 2**-5, signed, meters */
int16_t Crs;
double d_Crs;
/* Cus, Amplitude of the Sine Harmonic Correction Term to the
* Argument of Latitude, 16 bits, signed, scale 2**-29, radians */
int16_t Cus;
double d_Cus;
/* Cuc, Amplitude of the Cosine Harmonic Correction Term to the
* Argument of Latitude, 16 bits, signed, scale 2**-29, radians */
int16_t Cuc;
double d_Cuc;
/* deltan, Mean Motion Difference From Computed Value
* Mean Motion Difference From Computed Value
* 16 bits, signed, scale 2**-43, semi-circles/sec */
int16_t deltan;
double d_deltan;
/* M0, Mean Anomaly at Reference Time, 32 bits signed,
* scale 2**-31, semi-circles */
int32_t M0;
double d_M0;
/* eccentricity, 32 bits, unsigned, scale 2**-33, dimensionless */
uint32_t e;
double d_eccentricity;
/* sqrt A, Square Root of the Semi-Major Axis
* 32 bits unsigned, scale 2**-19, square_root(meters) */
uint32_t sqrtA;
double d_sqrtA;
} sub2;
/* subframe 3, part of ephemeris, see IS-GPS-200E, Table 20-II,
* Table 20-III */
struct {
/* Issue of Data (Ephemeris), 8 bits, unsigned
* equal to the 8 LSBs of the 10 bit IODC of the same data set */
uint8_t IODE;
/* Rate of Inclination Angle, 14 bits signed, scale2**-43,
* semi-circles/sec */
uint16_t IDOT;
double d_IDOT;
/* Cic, Amplitude of the Cosine Harmonic Correction Term to the
* Angle of Inclination, 16 bits signed, scale 2**-29, radians*/
uint16_t Cic;
double d_Cic;
/* Cis, Amplitude of the Sine Harmonic Correction Term to the
* Angle of Inclination, 16 bits, unsigned, scale 2**-29, radians */
int16_t Cis;
double d_Cis;
/* Crc, Amplitude of the Cosine Harmonic Correction Term to the
* Orbit Radius, 16 bits signed, scale 2**-5, meters */
int16_t Crc;
double d_Crc;
/* i0, Inclination Angle at Reference Time, 32 bits, signed,
* scale 2**-31, semi-circles */
int32_t i0;
double d_i0;
/* Omega0, Longitude of Ascending Node of Orbit Plane at Weekly
* Epoch, 32 bits signed, semi-circles */
int32_t Omega0;
double d_Omega0;
/* omega, Argument of Perigee, 32 bits signed, scale 2**-31,
* semi-circles */
int32_t omega;
double d_omega;
/* Omega dot, Rate of Right Ascension, 24 bits signed,
* scale 2**-43, semi-circles/sec */
int32_t Omegad;
double d_Omegad;
} sub3;
struct {
struct almanac_t almanac;
} sub4;
/* subframe 4, page 13 */
struct {
/* mapping ord ERD# to SV # is non trivial
* leave it alone. See IS-GPS-200E Section 20.3.3.5.1.9 */
/* Estimated Range Deviation, 6 bits signed, meters */
char ERD[33];
/* ai, Availability Indicator, 2bits, bit map */
unsigned char ai;
} sub4_13;
/* subframe 4, page 17, system message, 23 chars, plus nul */
struct {
char str[24];
} sub4_17;
/* subframe 4, page 18 */
struct {
/* ionospheric and UTC data */
/* A0, Bias coefficient of GPS time scale relative to UTC time
* scale, 32 bits signed, scale 2**-30, seconds */
int32_t A0;
double d_A0;
/* A1, Drift coefficient of GPS time scale relative to UTC time
* scale, 24 bits signed, scale 2**-50, seconds/second */
int32_t A1;
double d_A1;
/* alphaX, the four coefficients of a cubic equation representing
* the amplitude of the vertical delay */
/* alpha0, 8 bits signed, scale w**-30, seconds */
int8_t alpha0;
double d_alpha0;
/* alpha1, 8 bits signed, scale w**-27, seconds/semi-circle */
int8_t alpha1;
double d_alpha1;
/* alpha2, 8 bits signed, scale w**-24, seconds/semi-circle**2 */
int8_t alpha2;
double d_alpha2;
/* alpha3, 8 bits signed, scale w**-24, seconds/semi-circle**3 */
int8_t alpha3;
double d_alpha3;
/* betaX, the four coefficients of a cubic equation representing
* the period of the model */
/* beta0, 8 bits signed, scale w**11, seconds */
int8_t beta0;
double d_beta0;
/* beta1, 8 bits signed, scale w**14, seconds/semi-circle */
int8_t beta1;
double d_beta1;
/* beta2, 8 bits signed, scale w**16, seconds/semi-circle**2 */
int8_t beta2;
double d_beta2;
/* beta3, 8 bits signed, scale w**16, seconds/semi-circle**3 */
int8_t beta3;
double d_beta3;
/* leap (delta t ls), current leap second, 8 bits signed,
* scale 1, seconds */
int8_t leap;
/* lsf (delta t lsf), future leap second, 8 bits signed,
* scale 1, seconds */
int8_t lsf;
/* tot, reference time for UTC data,
* 8 bits unsigned, scale 2**12, seconds */
uint8_t tot;
double d_tot;
/* WNt, UTC reference week number, 8 bits unsigned, scale 1,
* weeks */
uint8_t WNt;
/* WNlsf, Leap second reference Week Number,
* 8 bits unsigned, scale 1, weeks */
uint8_t WNlsf;
/* DN, Leap second reference Day Number , 8 bits unsigned,
* scale 1, days */
uint8_t DN;
} sub4_18;
/* subframe 4, page 25 */
struct {
/* svf, A-S status and the configuration code of each SV
* 4 bits unsigned, bitmap */
unsigned char svf[33];
/* svh, SV health data for SV 25 through 32
* 6 bits unsigned bitmap */
uint8_t svhx[8];
} sub4_25;
struct {
struct almanac_t almanac;
} sub5;
struct {
/* toa, Almanac reference Time, 8 bits unsigned, scale 2**12,
* seconds */
uint8_t toa;
long l_toa;
/* WNa, Week Number almanac, 8 bits, scale 2, GPS Week
* Number % 256 */
uint8_t WNa;
/* sv, SV health status, 6 bits, bitmap */
uint8_t sv[25];
} sub5_25;
};
};
#ifndef S_SPLINT_S
typedef uint64_t gps_mask_t;
#else
typedef /*@unsignedintegraltype@*/ unsigned long long gps_mask_t;
#endif /* S_SPLINT_S */
/*
* Is an MMSI number that of an auxiliary associated with a mother ship?
* We need to be able to test this for decoding AIS Type 24 messages.
* According to <http://www.navcen.uscg.gov/marcomms/gmdss/mmsi.htm#format>,
* auxiliary-craft MMSIs have the form 98MIDXXXX, where MID is a country
* code and XXXX the vessel ID.
*/
#define AIS_AUXILIARY_MMSI(n) ((n) / 10000000 == 98)
/* N/A values and scaling constant for 25/24 bit lon/lat pairs */
#define AIS_LON3_NOT_AVAILABLE 181000
#define AIS_LAT3_NOT_AVAILABLE 91000
#define AIS_LATLON3_SCALE 60000.0
/* N/A values and scaling constant for 28/27 bit lon/lat pairs */
#define AIS_LON4_NOT_AVAILABLE 1810000
#define AIS_LAT4_NOT_AVAILABLE 910000
#define AIS_LATLON4_SCALE 600000.0
struct route_info {
unsigned int linkage; /* Message Linkage ID */
unsigned int sender; /* Sender Class */
unsigned int rtype; /* Route Type */
unsigned int month; /* Start month */
unsigned int day; /* Start day */
unsigned int hour; /* Start hour */
unsigned int minute; /* Start minute */
unsigned int duration; /* Duration */
int waycount; /* Waypoint count */
struct waypoint_t {
signed int lon; /* Longitude */
signed int lat; /* Latitude */
} waypoints[16];
};
struct ais_t
{
unsigned int type; /* message type */
unsigned int repeat; /* Repeat indicator */
unsigned int mmsi; /* MMSI */
union {
/* Types 1-3 Common navigation info */
struct {
unsigned int status; /* navigation status */
signed turn; /* rate of turn */
#define AIS_TURN_HARD_LEFT -127
#define AIS_TURN_HARD_RIGHT 127
#define AIS_TURN_NOT_AVAILABLE 128
unsigned int speed; /* speed over ground in deciknots */
#define AIS_SPEED_NOT_AVAILABLE 1023
#define AIS_SPEED_FAST_MOVER 1022 /* >= 102.2 knots */
bool accuracy; /* position accuracy */
#define AIS_LATLON_SCALE 600000.0
int lon; /* longitude */
#define AIS_LON_NOT_AVAILABLE 0x6791AC0
int lat; /* latitude */
#define AIS_LAT_NOT_AVAILABLE 0x3412140
unsigned int course; /* course over ground */
#define AIS_COURSE_NOT_AVAILABLE 3600
unsigned int heading; /* true heading */
#define AIS_HEADING_NOT_AVAILABLE 511
unsigned int second; /* seconds of UTC timestamp */
#define AIS_SEC_NOT_AVAILABLE 60
#define AIS_SEC_MANUAL 61
#define AIS_SEC_ESTIMATED 62
#define AIS_SEC_INOPERATIVE 63
unsigned int maneuver; /* maneuver indicator */
//unsigned int spare; spare bits */
bool raim; /* RAIM flag */
unsigned int radio; /* radio status bits */
} type1;
/* Type 4 - Base Station Report & Type 11 - UTC and Date Response */
struct {
unsigned int year; /* UTC year */
#define AIS_YEAR_NOT_AVAILABLE 0
unsigned int month; /* UTC month */
#define AIS_MONTH_NOT_AVAILABLE 0
unsigned int day; /* UTC day */
#define AIS_DAY_NOT_AVAILABLE 0
unsigned int hour; /* UTC hour */
#define AIS_HOUR_NOT_AVAILABLE 24
unsigned int minute; /* UTC minute */
#define AIS_MINUTE_NOT_AVAILABLE 60
unsigned int second; /* UTC second */
#define AIS_SECOND_NOT_AVAILABLE 60
bool accuracy; /* fix quality */
int lon; /* longitude */
int lat; /* latitude */
unsigned int epfd; /* type of position fix device */
//unsigned int spare; spare bits */
bool raim; /* RAIM flag */
unsigned int radio; /* radio status bits */
} type4;
/* Type 5 - Ship static and voyage related data */
struct {
unsigned int ais_version; /* AIS version level */
unsigned int imo; /* IMO identification */
char callsign[7+1]; /* callsign */
#define AIS_SHIPNAME_MAXLEN 20
char shipname[AIS_SHIPNAME_MAXLEN+1]; /* vessel name */
unsigned int shiptype; /* ship type code */
unsigned int to_bow; /* dimension to bow */
unsigned int to_stern; /* dimension to stern */
unsigned int to_port; /* dimension to port */
unsigned int to_starboard; /* dimension to starboard */
unsigned int epfd; /* type of position fix deviuce */
unsigned int month; /* UTC month */
unsigned int day; /* UTC day */
unsigned int hour; /* UTC hour */
unsigned int minute; /* UTC minute */
unsigned int draught; /* draft in meters */
char destination[20+1]; /* ship destination */
unsigned int dte; /* data terminal enable */
//unsigned int spare; spare bits */
} type5;
/* Type 6 - Addressed Binary Message */
struct {
unsigned int seqno; /* sequence number */
unsigned int dest_mmsi; /* destination MMSI */
bool retransmit; /* retransmit flag */
//unsigned int spare; spare bit(s) */
unsigned int dac; /* Application ID */
unsigned int fid; /* Functional ID */
#define AIS_TYPE6_BINARY_MAX 920 /* 920 bits */
size_t bitcount; /* bit count of the data */
union {
char bitdata[(AIS_TYPE6_BINARY_MAX + 7) / 8];
/* IMO236 - Dangerous Cargo Indication */
struct {
char lastport[5+1]; /* Last Port Of Call */
unsigned int lmonth; /* ETA month */
unsigned int lday; /* ETA day */
unsigned int lhour; /* ETA hour */
unsigned int lminute; /* ETA minute */
char nextport[5+1]; /* Next Port Of Call */
unsigned int nmonth; /* ETA month */
unsigned int nday; /* ETA day */
unsigned int nhour; /* ETA hour */
unsigned int nminute; /* ETA minute */
char dangerous[20+1]; /* Main Dangerous Good */
char imdcat[4+1]; /* IMD Category */
unsigned int unid; /* UN Number */
unsigned int amount; /* Amount of Cargo */
unsigned int unit; /* Unit of Quantity */
} dac1fid12;
/* IMO236 - Extended Ship Static and Voyage Related Data */
struct {
unsigned int airdraught; /* Air Draught */
} dac1fid15;
/* IMO236 - Number of Persons on board */
struct {
unsigned persons; /* number of persons */
} dac1fid16;
/* IMO289 - Clearance Time To Enter Port */
struct {
unsigned int linkage; /* Message Linkage ID */
unsigned int month; /* Month (UTC) */
unsigned int day; /* Day (UTC) */
unsigned int hour; /* Hour (UTC) */
unsigned int minute; /* Minute (UTC) */
char portname[20+1]; /* Name of Port & Berth */
char destination[5+1]; /* Destination */
signed int lon; /* Longitude */
signed int lat; /* Latitude */
} dac1fid18;
/* IMO289 - Berthing Data (addressed) */
struct {
unsigned int linkage; /* Message Linkage ID */
unsigned int berth_length; /* Berth length */
unsigned int berth_depth; /* Berth Water Depth */
unsigned int position; /* Mooring Position */