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
|
/* subframe.c -- interpret satellite subframe data.
*
* This file is Copyright (c) 2010 by the GPSD project
* BSD terms apply: see the file COPYING in the distribution root for details.
*/
#include <math.h>
#include "gpsd.h"
#include "timebase.h"
/* convert unsigned to signed */
#define uint2int( u, bit) ( u & (1<<bit) ? u - (1<<bit) : u)
/*@ -usedef @*/
int gpsd_interpret_subframe_raw(struct gps_device_t *session,
unsigned int svid, uint32_t words[])
{
unsigned int i;
uint32_t preamble, parity;
/*
* This function assumes an array of 10 ints, each of which carries
* a raw 30-bit GPS word use your favorite search engine to find the
* latest version of the specification: IS-GPS-200.
*
* Each raw 30-bit word is made of 24 data bits and 6 parity bits. The
* raw word and transport word are emitted from the GPS MSB-first and
* right justified. In other words, masking the raw word against 0x3f
* will return just the parity bits. Masking with 0x3fffffff and shifting
* 6 bits to the right returns just the 24 data bits. The top two bits
* (b31 and b30) are undefined; chipset designers may store copies of
* the bits D29* and D30* here to aid parity checking.
*
* Since bits D29* and D30* are not available in word 0, it is tested for
* a known preamble to help check its validity and determine whether the
* word is inverted.
*
*/
gpsd_report(LOG_IO, "50B: gpsd_interpret_subframe_raw: "
"%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
words[0], words[1], words[2], words[3], words[4],
words[5], words[6], words[7], words[8], words[9]);
preamble = (words[0] >> 22) & 0xff;
if (preamble == 0x8b) { /* preamble is inverted */
words[0] ^= 0x3fffffc0; /* invert */
} else if (preamble != 0x74) {
/* strangely this is very common, so don't log it */
gpsd_report(LOG_IO,
"50B: gpsd_interpret_subframe_raw: bad preamble 0x%x\n",
preamble);
return 0;
}
words[0] = (words[0] >> 6) & 0xffffff;
for (i = 1; i < 10; i++) {
int invert;
/* D30* says invert */
invert = (words[i] & 0x40000000) ? 1 : 0;
/* inverted data, invert it back */
if (invert) {
words[i] ^= 0x3fffffc0;
}
parity = (uint32_t)isgps_parity((isgps30bits_t)words[i]);
if (parity != (words[i] & 0x3f)) {
gpsd_report(LOG_IO,
"50B: gpsd_interpret_subframe_raw parity fail words[%d] 0x%x != 0x%x\n",
i, parity, (words[i] & 0x1));
return 0;
}
words[i] = (words[i] >> 6) & 0xffffff;
}
gpsd_interpret_subframe(session, svid, words);
return 0;
}
/* The almanac is a subset of the clock and ephemeris data, with reduced
* precision. See IS-GPS-200E, Table 20-VI */
struct almanac
{
/* 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;
};
/* you can find up to date almanac data for comparision here:
* https://gps.afspc.af.mil/gps/Current/current.alm
*/
static void subframe_almanac(unsigned int svid, uint32_t words[],
unsigned int subframe, unsigned int sv,
unsigned int data_id,
/*@out@*/struct almanac *almp)
{
almp->e = ( words[2] & 0x00FFFF);
almp->d_eccentricity = pow(2.0,-21) * almp->e;
/* carefull, each SV can have more than 2 toa's active at the same time
* you can not just store one or two almanacs for each sat */
almp->toa = ((words[3] >> 16) & 0x0000FF);
almp->l_toa = almp->toa << 12;
almp->deltai = ( words[3] & 0x00FFFF);
almp->d_deltai = pow(2.0, -19) * almp->deltai;
almp->Omegad = ((words[4] >> 8) & 0x00FFFF);
almp->d_Omegad = pow(2.0, -38) * almp->Omegad;
almp->svh = ( words[4] & 0x0000FF);
almp->sqrtA = ( words[5] & 0xFFFFFF);
almp->d_sqrtA = pow(2.0,-11) * almp->sqrtA;
almp->Omega0 = ( words[6] & 0xFFFFFF);
almp->Omega0 = uint2int(almp->Omega0, 24);
almp->d_Omega0 = pow(2.0, -23) * almp->Omega0;
almp->omega = ( words[7] & 0xFFFFFF);
almp->omega = uint2int(almp->omega, 24);
almp->d_omega = pow(2.0, -23) * almp->omega;
almp->M0 = ( words[8] & 0xFFFFFF);
almp->M0 = uint2int(almp->M0, 24);
almp->d_M0 = pow(2.0,-23) * almp->M0;
almp->af1 = ((words[9] >> 5) & 0x0007FF);
almp->af1 = uint2int(almp->af1, 11);
almp->d_af1 = pow(2.0,-38) * almp->af1;
almp->af0 = ((words[9] >> 16) & 0x0000FF);
almp->af0 <<= 3;
almp->af0 |= ((words[9] >> 2) & 0x000007);
almp->af0 = uint2int(almp->af0, 11);
almp->d_af0 = pow(2.0,-20) * almp->af0;
gpsd_report(LOG_PROG,
"50B: SF:%d SV:%2u TSV:%2u data_id %d e:%g toa:%lu "
"deltai:%.10e Omegad:%.5e svh:%u sqrtA:%.8g Omega0:%.10e "
"omega:%.10e M0:%.11e af0:%.5e af1:%.5e\n",
subframe, sv, svid, data_id,
almp->d_eccentricity,
almp->l_toa,
almp->d_deltai,
almp->d_Omegad,
almp->svh,
almp->d_sqrtA,
almp->d_Omega0,
almp->d_omega,
almp->d_M0,
almp->d_af0,
almp->d_af1);
}
struct subframe {
int subtype;
union {
/* subframe 1, part of ephemeris, see IS-GPS-200E, Table 20-II
* and Table 20-I */
struct {
/* 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
* 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 */
unsigned int ura;
/* hlth, SV health, 6 bits unsigned bitmap */
unsigned int hlth;
/* af0, SV clock correction constant term
* 22 bits signed, seconds */
int32_t af0;
double d_af0;
/* af1, SV clock correction first order term
* 22 bits signed, seconds/second */
int16_t af1;
double d_af1;
/* af2, SV clock correction second order term
* 8 bits signed, seconds/second**2 */
int8_t af2;
double d_af2;
/* Tgd, L1-L2 correction term, 8 bits signed, 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, ignore if all ones */
uint8_t AODO;
/* Age of Data Offset for the NMCT, seconds */
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, seconds */
uint16_t toe;
long l_toe;
/* Crs, Amplitude of the Sine Harmonic Correction Term to the
* Orbit Radius, 16 bits, signed, meters */
int16_t Crs;
double d_Crs;
/* Cus, Amplitude of the Sine Harmonic Correction Term to the
* Argument of Latitude, 16 bits, signed, radians */
int16_t Cus;
double d_Cus;
/* Cuc, Amplitude of the Cosine Harmonic Correction Term to the
* Argument of Latitude, 16 bits, signed, radians */
int16_t Cuc;
double d_Cuc;
/* deltan, Mean Motion Difference From Computed Value
* Mean Motion Difference From Computed Value
* 16 bits, signed, semi-circles/sec */
int16_t deltan;
double d_deltan;
/* M0, Mean Anomaly at Reference Time, 32 bits signed,
* semi-circles */
int32_t M0;
double d_M0;
/* eccentricity, 32 bits, unsigned, dimensionless */
uint32_t e;
double d_eccentricity;
/* sqrt A, Square Root of the Semi-Major Axis
* 32 bits unsigned, square_root(meters) */
uint32_t sqrtA;
double d_sqrtA;
} sub2;
/* subframe 3, part of ephemeris, see IS-GPS-200E, Table 20-II */
struct {
struct almanac almanac;
} sub4;
struct {
struct almanac almanac;
} sub5;
};
};
struct subframe subframe;
void gpsd_interpret_subframe(struct gps_device_t *session,
unsigned int svid, uint32_t words[])
{
/*
* Heavy black magic begins here!
*
* A description of how to decode these bits is at
* <http://home-2.worldonline.nl/~samsvl/nav2eu.htm>
*
* We're mostly looking for subframe 4 page 18 word 9, the leap second
* correction. This functions assumes an array of words without parity
* or inversion (inverted word 0 is OK). It may be called directly by a
* driver if the chipset emits acceptable data.
*
* To date this code has been tested on iTrax, SiRF and ublox.
*/
/* FIXME!! I really doubt this is Big Endian compatible */
unsigned int pageid, data_id, preamble;
uint32_t tow17;
bool alert, antispoof;
struct subframe *subp = &subframe;
gpsd_report(LOG_IO,
"50B: gpsd_interpret_subframe: (%d) "
"%06x %06x %06x %06x %06x %06x %06x %06x %06x %06x\n",
svid, words[0], words[1], words[2], words[3], words[4],
words[5], words[6], words[7], words[8], words[9]);
preamble = (unsigned int)((words[0] >> 16) & 0x0ffL);
if (preamble == 0x8b) {
preamble ^= 0xff;
words[0] ^= 0xffffff;
}
if (preamble != 0x74) {
gpsd_report(LOG_WARN,
"50B: gpsd_interpret_subframe bad preamble: 0x%x header 0x%x\n",
preamble, words[0]);
return;
}
/* The subframe ID is in the Hand Over Word (page 80) */
tow17 = ((words[1] >> 7) & 0x01FFFF);
subp->subtype = ((words[1] >> 2) & 0x07);
alert = (bool)((words[1] >> 6) & 0x01);
antispoof = (bool)((words[1] >> 6) & 0x01);
gpsd_report(LOG_PROG,
"50B: SF:%d SV:%2u TOW17:%6u Alert:%u AS:%u\n",
subp->subtype, svid, tow17, (unsigned)alert, (unsigned)antispoof);
/*
* Consult the latest revision of IS-GPS-200 for the mapping
* between magic SVIDs and pages.
*/
pageid = (words[2] >> 16) & 0x00003F; /* only in frames 4 & 5 */
data_id = (words[2] >> 22) & 0x3; /* only in frames 4 & 5 */
switch (subp->subtype) {
case 1:
/* subframe 1: clock parameters for transmitting SV */
/* get Week Number (WN) from subframe 1 */
{
/*
* This only extracts 10 bits of GPS week.
* 13 bits are available in the extension CNAV message,
* which we don't decode yet because we don't know
* of any receiver that reports it.
*/
session->context->gps_week =
(unsigned short)((words[2] >> 14) & 0x03ff);
subp->sub1.l2 = ((words[2] >> 10) & 0x000003); /* L2 Code */
subp->sub1.ura = ((words[2] >> 8) & 0x00000F); /* URA Index */
subp->sub1.hlth = ((words[2] >> 2) & 0x00003F); /* SV health */
subp->sub1.IODC = (words[2] & 0x000003); /* IODC 2 MSB */
subp->sub1.l2p = ((words[3] >> 23) & 0x000001); /* L2 P flag */
subp->sub1.Tgd = ( words[6] & 0x0000FF);
subp->sub1.d_Tgd = pow(2.0, -31) * subp->sub1.Tgd;
subp->sub1.toc = ( words[7] & 0x00FFFF);
subp->sub1.l_toc = subp->sub1.toc << 4;
subp->sub1.af2 = ((words[8] >> 16) & 0x0FF);
subp->sub1.d_af2 = pow(2.0, -55) * subp->sub1.af2;
subp->sub1.af1 = ( words[8] & 0x00FFFF);
subp->sub1.d_af1 = pow(2.0, -43) * subp->sub1.af1;
subp->sub1.af0 = ((words[9] >> 1) & 0x03FFFFF);
subp->sub1.af0 = uint2int(subp->sub1.af0, 22);
subp->sub1.d_af0 = pow(2.0, -31) * subp->sub1.af0;
subp->sub1.IODC <<= 8;
subp->sub1.IODC |= ((words[7] >> 16) & 0x00FF);
gpsd_report(LOG_PROG, "50B: SF:1 SV:%2u WN:%4u IODC:%4u"
" L2:%u ura:%u hlth:%u L2P:%u Tgd:%g toc:%lu af2:%.4g"
" af1:%.6e af0:%.7e\n", svid,
session->context->gps_week,
subp->sub1.IODC,
subp->sub1.l2,
subp->sub1.ura,
subp->sub1.hlth,
subp->sub1.l2p,
subp->sub1.d_Tgd,
subp->sub1.l_toc,
subp->sub1.d_af2,
subp->sub1.d_af1,
subp->sub1.d_af0);
}
break;
case 2:
/* subframe 2: ephemeris for transmitting SV */
{
subp->sub2.IODE = ((words[2] >> 16) & 0x00FF);
subp->sub2.Crs = ( words[2] & 0x00FFFF);
subp->sub2.d_Crs = pow(2.0,-5) * subp->sub2.Crs;
subp->sub2.deltan = ((words[3] >> 8) & 0x00FFFF);
subp->sub2.d_deltan = pow(2.0,-43) * subp->sub2.deltan;
subp->sub2.M0 = ( words[3] & 0x0000FF);
subp->sub2.M0 <<= 24;
subp->sub2.M0 |= ( words[4] & 0x00FFFFFF);
subp->sub2.M0 = uint2int(subp->sub2.M0, 24);
subp->sub2.d_M0 = pow(2.0,-31) * subp->sub2.M0;
subp->sub2.Cuc = ((words[5] >> 8) & 0x00FFFF);
subp->sub2.d_Cuc = pow(2.0,-29) * subp->sub2.Cuc;
subp->sub2.e = ( words[5] & 0x0000FF);
subp->sub2.e <<= 24;
subp->sub2.e |= ( words[6] & 0x00FFFFFF);
subp->sub2.d_eccentricity = pow(2.0,-33) * subp->sub2.e;
subp->sub2.Cus = ((words[7] >> 8) & 0x00FFFF);
subp->sub2.d_Cus = pow(2.0,-29) * subp->sub2.Cus;
subp->sub2.sqrtA = ( words[7] & 0x0000FF);
subp->sub2.sqrtA <<= 24;
subp->sub2.sqrtA |= ( words[8] & 0x00FFFFFF);
subp->sub2.d_sqrtA = pow(2.0, -19) * subp->sub2.sqrtA;
subp->sub2.toe = ((words[9] >> 8) & 0x00FFFF);
subp->sub2.l_toe = subp->sub2.toe << 4;
subp->sub2.fit = ((words[9] >> 7) & 0x000001);
subp->sub2.AODO = ((words[9] >> 2) & 0x00001F);
subp->sub2.u_AODO = subp->sub2.AODO * 900;
gpsd_report(LOG_PROG,
"50B: SF:2 SV:%2u IODE:%3u Crs:%.6e deltan:%.6e "
"M0:%.11e Cuc:%.6e e:%f Cus:%.6e sqrtA:%.11g "
"toe:%lu FIT:%u AODO:%5u\n",
svid,
subp->sub2.IODE,
subp->sub2.d_Crs,
subp->sub2.d_deltan,
subp->sub2.d_M0,
subp->sub2.d_Cuc,
subp->sub2.d_eccentricity,
subp->sub2.d_Cus,
subp->sub2.d_sqrtA,
subp->sub2.l_toe,
subp->sub2.fit,
subp->sub2.u_AODO);
}
break;
case 3:
/* subframe 3: ephemeris for transmitting SV */
{
/* 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, 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, 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;
int32_t 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, semi-circles */
int32_t omega;
double d_omega;
/* Omega dot, Rate of Right Ascension, 24 bits signed,
* semi-circles/sec */
int32_t Omegad;
double d_Omegad;
Cic = ((words[2] >> 8) & 0x00FFFF);
d_Cic = pow(2.0, -29) * Cic;
Omega0 = ( words[2] & 0x0000FF);
Omega0 <<= 24;
Omega0 |= ( words[3] & 0x00FFFFFF);
d_Omega0 = pow(2.0, -31) * Omega0;
Cis = ((words[4] >> 8) & 0x00FFFF);
d_Cis = pow(2.0, -29) * Cis;
i0 = ( words[4] & 0x0000FF);
i0 <<= 24;
i0 |= ( words[5] & 0x00FFFFFF);
Crc = ((words[6] >> 8) & 0x00FFFF);
d_Crc = pow(2.0, -5) * Crc;
omega = ( words[6] & 0x0000FF);
omega <<= 24;
omega |= ( words[7] & 0x00FFFFFF);
d_omega = pow(2.0, -31) * omega;
Omegad = ( words[8] & 0x00FFFFFF);
Omegad = uint2int(Omegad, 24);
d_Omegad = pow(2.0, -43) * Omegad;
IODE = ((words[9] >> 16) & 0x0000FF);
IDOT = ((words[9] >> 2) & 0x003FFF);
d_IDOT = pow(2.0, -43) * IDOT;
gpsd_report(LOG_PROG,
"50B: SF:3 SV:%2u IODE:%3u I IDOT:%.6g Cic:%.6e Omega0:%.11e "
" Cis:%.7g i0:%d Crc:%.7g omega:%.11e Omegad:%.6e\n",
svid, IODE, d_IDOT, d_Cic, d_Omega0, d_Cis, i0, d_Crc,
d_omega, d_Omegad );
}
break;
case 4:
{
int sv = -2;
switch (pageid) {
case 0:
/* almanac for dummy sat 0, which is same as transmitting sat */
sv = 0;
break;
case 1:
case 6:
case 11:
case 16:
case 21:
case 57:
/* for some inscutable reason these pages are all sent
* as page 57, IS-GPS-200E Table 20-V */
break;
case 12:
case 24:
case 62:
/* for some inscrutable reason these pages are all sent
* as page 62, IS-GPS-200E Table 20-V */
break;
case 14:
case 53:
/* for some inscrutable reason page 14 is sent
* as page 53, IS-GPS-200E Table 20-V */
break;
case 15:
case 54:
/* for some inscrutable reason page 15 is sent
* as page 54, IS-GPS-200E Table 20-V */
break;
case 19:
/* for some inscrutable reason page 20 is sent
* as page 58, IS-GPS-200E Table 20-V */
/* reserved page */
break;
case 20:
/* for some inscrutable reason page 20 is sent
* as page 59, IS-GPS-200E Table 20-V */
/* reserved page */
break;
case 22:
case 60:
/* for some inscrutable reason page 22 is sent
* as page 60, IS-GPS-200E Table 20-V */
/* reserved page */
break;
case 23:
case 61:
/* for some inscrutable reason page 23 is sent
* as page 61, IS-GPS-200E Table 20-V */
/* reserved page */
break;
/* almanac data for SV 25 through 32 respectively; */
case 2:
sv = 25;
break;
case 3:
sv = 26;
break;
case 4:
sv = 27;
break;
case 5:
sv = 28;
break;
case 7:
sv = 29;
break;
case 8:
sv = 30;
break;
case 9:
sv = 31;
break;
case 10:
sv = 32;
break;
case 13:
case 52:
/* NMCT */
{
/* mapping ord ERD# to SV # is non trivial
* leave it alone */
char ERD[33];
unsigned char ai;
int i;
sv = -1;
ai = ((words[2] >> 22) & 0x000003);
ERD[1] = (char)((words[2] >> 8) & 0x00003F);
ERD[2] = (char)((words[2] >> 2) & 0x00003F);
ERD[3] = (char)((words[2] >> 0) & 0x000003);
ERD[3] <<= 2;
ERD[3] |= (char)((words[3] >> 20) & 0x00000F);
ERD[4] = (char)((words[3] >> 14) & 0x00003F);
ERD[5] = (char)((words[3] >> 8) & 0x00003F);
ERD[6] = (char)((words[3] >> 2) & 0x00003F);
ERD[7] = (char)((words[3] >> 0) & 0x000003);
ERD[7] <<= 2;
ERD[7] |= (char)((words[4] >> 20) & 0x00000F);
ERD[8] = (char)((words[4] >> 14) & 0x00003F);
ERD[9] = (char)((words[4] >> 8) & 0x00003F);
ERD[10] = (char)((words[4] >> 2) & 0x00003F);
ERD[11] = (char)((words[4] >> 0) & 0x00000F);
ERD[11] <<= 2;
ERD[11] |= (char)((words[5] >> 20) & 0x00000F);
ERD[12] = (char)((words[5] >> 14) & 0x00003F);
ERD[13] = (char)((words[5] >> 8) & 0x00003F);
ERD[14] = (char)((words[5] >> 2) & 0x00003F);
ERD[15] = (char)((words[5] >> 0) & 0x000003);
ERD[15] <<= 2;
ERD[15] |= (char)((words[6] >> 20) & 0x00000F);
ERD[16] = (char)((words[6] >> 14) & 0x00003F);
ERD[17] = (char)((words[6] >> 8) & 0x00003F);
ERD[18] = (char)((words[6] >> 2) & 0x00003F);
ERD[19] = (char)((words[6] >> 0) & 0x000003);
ERD[19] <<= 2;
ERD[19] |= (char)((words[7] >> 20) & 0x00000F);
ERD[20] = (char)((words[7] >> 14) & 0x00003F);
ERD[21] = (char)((words[7] >> 8) & 0x00003F);
ERD[22] = (char)((words[7] >> 2) & 0x00003F);
ERD[23] = (char)((words[7] >> 0) & 0x000003);
ERD[23] <<= 2;
ERD[23] |= (char)((words[8] >> 20) & 0x00000F);
ERD[24] = (char)((words[8] >> 14) & 0x00003F);
ERD[25] = (char)((words[8] >> 8) & 0x00003F);
ERD[26] = (char)((words[8] >> 2) & 0x00003F);
ERD[27] = (char)((words[8] >> 0) & 0x000003);
ERD[27] <<= 2;
ERD[27] |= (char)((words[9] >> 20) & 0x00000F);
ERD[28] = (char)((words[9] >> 14) & 0x00003F);
ERD[29] = (char)((words[9] >> 8) & 0x00003F);
ERD[30] = (char)((words[9] >> 2) & 0x00003F);
for ( i = 1; i < 31; i++ ) {
ERD[i] = uint2int(ERD[i], 6);
}
gpsd_report(LOG_PROG, "50B: SF:4-13 data_id %d ai:%u "
"ERD1:%d ERD2:%d ERD3:%d ERD4:%d "
"ERD5:%d ERD6:%d ERD7:%d ERD8:%d "
"ERD9:%d ERD10:%d ERD11:%d ERD12:%d "
"ERD13:%d ERD14:%d ERD15:%d ERD16:%d "
"ERD17:%d ERD18:%d ERD19:%d ERD20:%d "
"ERD21:%d ERD22:%d ERD23:%d ERD24:%d "
"ERD25:%d ERD26:%d ERD27:%d ERD28:%d "
"ERD29:%d ERD30:%d\n",
data_id, ai,
ERD[1], ERD[2], ERD[3], ERD[4],
ERD[5], ERD[5], ERD[6], ERD[4],
ERD[9], ERD[10], ERD[11], ERD[12],
ERD[13], ERD[14], ERD[15], ERD[16],
ERD[17], ERD[18], ERD[19], ERD[20],
ERD[21], ERD[22], ERD[23], ERD[24],
ERD[25], ERD[26], ERD[27], ERD[28],
ERD[29], ERD[30]);
}
break;
case 25:
case 63:
/* for some inscrutable reason page 25 is sent
* as page 63, IS-GPS-200E Table 20-V */
/* A-S flags/SV configurations for 32 SVs,
* plus SV health for SV 25 through 32
*/
{
unsigned char svf[33];
/* SV health data, 6 bits unsigned bit map */
uint8_t svh25, svh26, svh27, svh28;
uint8_t svh29, svh30, svh31, svh32;
svh25 = ((words[7] >> 0) & 0x00003F);
svh26 = ((words[8] >> 18) & 0x00003F);
svh27 = ((words[8] >> 12) & 0x00003F);
svh28 = ((words[8] >> 6) & 0x00003F);
svh29 = ((words[8] >> 0) & 0x00003F);
svh30 = ((words[9] >> 18) & 0x00003F);
svh31 = ((words[9] >> 12) & 0x00003F);
svh32 = ((words[9] >> 6) & 0x00003F);
sv = -1;
svf[1] = (unsigned char)((words[2] >> 12) & 0x00000F);
svf[2] = (unsigned char)((words[2] >> 8) & 0x00000F);
svf[3] = (unsigned char)((words[2] >> 4) & 0x00000F);
svf[4] = (unsigned char)((words[2] >> 0) & 0x00000F);
svf[5] = (unsigned char)((words[3] >> 20) & 0x00000F);
svf[6] = (unsigned char)((words[3] >> 16) & 0x00000F);
svf[7] = (unsigned char)((words[3] >> 12) & 0x00000F);
svf[8] = (unsigned char)((words[3] >> 8) & 0x00000F);
svf[9] = (unsigned char)((words[3] >> 4) & 0x00000F);
svf[10] = (unsigned char)((words[3] >> 0) & 0x00000F);
svf[11] = (unsigned char)((words[4] >> 20) & 0x00000F);
svf[12] = (unsigned char)((words[4] >> 16) & 0x00000F);
svf[13] = (unsigned char)((words[4] >> 12) & 0x00000F);
svf[14] = (unsigned char)((words[4] >> 8) & 0x00000F);
svf[15] = (unsigned char)((words[4] >> 4) & 0x00000F);
svf[16] = (unsigned char)((words[4] >> 0) & 0x00000F);
svf[17] = (unsigned char)((words[5] >> 20) & 0x00000F);
svf[18] = (unsigned char)((words[5] >> 16) & 0x00000F);
svf[19] = (unsigned char)((words[5] >> 12) & 0x00000F);
svf[20] = (unsigned char)((words[5] >> 8) & 0x00000F);
svf[21] = (unsigned char)((words[5] >> 4) & 0x00000F);
svf[22] = (unsigned char)((words[5] >> 0) & 0x00000F);
svf[23] = (unsigned char)((words[6] >> 20) & 0x00000F);
svf[24] = (unsigned char)((words[6] >> 16) & 0x00000F);
svf[25] = (unsigned char)((words[6] >> 12) & 0x00000F);
svf[26] = (unsigned char)((words[6] >> 8) & 0x00000F);
svf[27] = (unsigned char)((words[6] >> 4) & 0x00000F);
svf[28] = (unsigned char)((words[6] >> 0) & 0x00000F);
svf[29] = (unsigned char)((words[7] >> 20) & 0x00000F);
svf[30] = (unsigned char)((words[7] >> 16) & 0x00000F);
svf[31] = (unsigned char)((words[7] >> 12) & 0x00000F);
svf[32] = (unsigned char)((words[7] >> 8) & 0x00000F);
gpsd_report(LOG_PROG, "50B: SF:4-25 data_id %d "
"SV1:%u SV2:%u SV3:%u SV4:%u "
"SV5:%u SV6:%u SV7:%u SV8:%u "
"SV9:%u SV10:%u SV11:%u SV12:%u "
"SV13:%u SV14:%u SV15:%u SV16:%u "
"SV17:%u SV18:%u SV19:%u SV20:%u "
"SV21:%u SV22:%u SV23:%u SV24:%u "
"SV25:%u SV26:%u SV27:%u SV28:%u "
"SV29:%u SV30:%u SV31:%u SV32:%u "
"SVH25:%u SVH26:%u SVH27:%u SVH28:%u "
"SVH29:%u SVH30:%u SVH31:%u SVH32:%u\n",
data_id,
svf[1], svf[2], svf[3], svf[4],
svf[5], svf[5], svf[6], svf[4],
svf[9], svf[10], svf[11], svf[12],
svf[13], svf[14], svf[15], svf[16],
svf[17], svf[18], svf[19], svf[20],
svf[21], svf[22], svf[23], svf[24],
svf[25], svf[26], svf[27], svf[28],
svf[29], svf[30], svf[31], svf[32],
svh25, svh26, svh27, svh28,
svh29, svh30, svh31, svh32);
}
break;
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:
case 47:
case 48:
case 49:
case 50:
/* unassigned */
break;
case 51:
/* unknown */
break;
case 17:
case 55:
/* for some inscrutable reason page 17 is sent
* as page 55, IS-GPS-200E Table 20-V */
sv = -1;
/*
* "The requisite 176 bits shall occupy bits 9 through 24
* of word TWO, the 24 MSBs of words THREE through EIGHT,
* plus the 16 MSBs of word NINE." (word numbers changed
* to account for zero-indexing)
* Since we've already stripped the low six parity bits,
* and shifted the data to a byte boundary, we can just
* copy it out. */
{
char str[24];
int j = 0;
/*@ -type @*/
str[j++] = (words[2] >> 8) & 0xff;
str[j++] = (words[2]) & 0xff;
str[j++] = (words[3] >> 16) & 0xff;
str[j++] = (words[3] >> 8) & 0xff;
str[j++] = (words[3]) & 0xff;
str[j++] = (words[4] >> 16) & 0xff;
str[j++] = (words[4] >> 8) & 0xff;
str[j++] = (words[4]) & 0xff;
str[j++] = (words[5] >> 16) & 0xff;
str[j++] = (words[5] >> 8) & 0xff;
str[j++] = (words[5]) & 0xff;
str[j++] = (words[6] >> 16) & 0xff;
str[j++] = (words[6] >> 8) & 0xff;
str[j++] = (words[6]) & 0xff;
str[j++] = (words[7] >> 16) & 0xff;
str[j++] = (words[7] >> 8) & 0xff;
str[j++] = (words[7]) & 0xff;
str[j++] = (words[8] >> 16) & 0xff;
str[j++] = (words[8] >> 8) & 0xff;
str[j++] = (words[8]) & 0xff;
str[j++] = (words[9] >> 16) & 0xff;
str[j++] = (words[9] >> 8) & 0xff;
str[j++] = '\0';
/*@ +type @*/
gpsd_report(LOG_INF, "50B: SF:4-17 system message: %s\n",
str);
}
break;
case 18:
case 56:
/* for some inscrutable reason page 18 is sent
* as page 56, IS-GPS-200E Table 20-V */
/* ionospheric and UTC data */
{
int32_t A0, A1;
int8_t alpha0, alpha1, alpha2, alpha3;
int8_t beta0, beta1, beta2, beta3;
int8_t leap, lsf;
uint8_t tot, WNt, WNlsf, DN;
sv = -1;
/* current leap seconds */
alpha0 = ((words[2] >> 16) & 0x0000FF);
alpha1 = ((words[2] >> 8) & 0x0000FF);
alpha2 = ((words[3] >> 16) & 0x0000FF);
alpha3 = ((words[3] >> 8) & 0x0000FF);
beta0 = ((words[3] >> 0) & 0x0000FF);
beta1 = ((words[4] >> 16) & 0x0000FF);
beta2 = ((words[4] >> 8) & 0x0000FF);
beta3 = ((words[4] >> 0) & 0x0000FF);
A1 = ((words[5] >> 0) & 0xFFFFFF);
A1 = uint2int(A1, 24);
A0 = ((words[6] >> 0) & 0xFFFFFF);
A0 <<= 8;
A0 |= ((words[7] >> 16) & 0x00FFFF);
/* careful WN is 10 bits, but WNt is 8 bits! */
/* WNt (Week Number of LSF) */
tot = ((words[7] >> 8) & 0x0000FF);
WNt = ((words[7] >> 0) & 0x0000FF);
leap = ((words[8] >> 16) & 0x0000FF);
WNlsf = ((words[8] >> 8) & 0x0000FF);
/* DN (Day Number of LSF) */
DN = (words[8] & 0x0000FF);
/* leap second future */
lsf = ((words[9] >> 16) & 0x0000FF);
/*
* On SiRFs, the 50BPS data is passed on even when the
* parity fails. This happens frequently. So the driver
* must be extra careful that bad data does not reach here.
*/
if (LEAP_SECONDS > leap) {
/* something wrong */
gpsd_report(LOG_ERROR,
"50B: SF:4-18 Invalid leap_seconds: %d\n",
leap);
leap = LEAP_SECONDS;
session->context->valid &= ~LEAP_SECOND_VALID;
} else {
gpsd_report(LOG_INF,
"50B: SF:4-18 leap-seconds:%d lsf:%d WNlsf:%u "
"DN:%d\n",
leap, lsf, WNlsf, DN);
gpsd_report(LOG_PROG,
"50B: SF:4-18 a0:%d a1:%d a2:%d a3:%d "
"b0:%d b1:%d b2:%d b3:%d "
"A1:%d A0:%d tot:%u WNt:%u "
"ls: %d WNlsf:%u DN:%u, lsf:%d\n",
alpha0, alpha1, alpha2, alpha3,
beta0, beta1, beta2, beta3,
A1, A0, tot, WNt,
leap, WNlsf, DN, lsf);
session->context->valid |= LEAP_SECOND_VALID;
if (leap != lsf) {
gpsd_report(LOG_PROG,
"50B: SF:4-18 leap-second change coming\n");
}
}
session->context->leap_seconds = (int)leap;
}
break;
default:
; /* no op */
}
if ( -1 < sv ) {
subframe_almanac(svid, words, subp->subtype, sv, data_id,
&subp->sub4.almanac);
} else if ( -2 == sv ) {
gpsd_report(LOG_PROG,
"50B: SF:4-%d data_id %d\n",
pageid, data_id);
}
/* else, already handled */
}
break;
case 5:
/* Pages 0, dummy almanc for dummy SV 0
* Pages 1 through 24: almanac data for SV 1 through 24
* Page 25: SV health data for SV 1 through 24, the almanac
* reference time, the almanac reference week number.
*/
if ( 25 > pageid ) {
subframe_almanac(svid, words, subp->subtype, pageid, data_id,
&subp->sub5.almanac);
} else if ( 51 == pageid ) {
/* for some inscrutable reason page 25 is sent as page 51
* IS-GPS-200E Table 20-V */
/* toa, Almanac reference Time, 8 bits, unsigned, seconds */
uint8_t toa;
long l_toa;
/* WNa, Week Number almanac, 8 bits, GPS Week Number % 256 */
uint8_t WNa;
uint8_t sv[25];
toa = ((words[2] >> 8) & 0x0000FF);
l_toa = toa << 12;
WNa = ( words[2] & 0x0000FF);
sv[1] = ((words[2] >> 18) & 0x00003F);
sv[2] = ((words[2] >> 12) & 0x00003F);
sv[3] = ((words[2] >> 6) & 0x00003F);
sv[4] = ((words[2] >> 0) & 0x00003F);
sv[5] = ((words[3] >> 18) & 0x00003F);
sv[6] = ((words[3] >> 12) & 0x00003F);
sv[7] = ((words[3] >> 6) & 0x00003F);
sv[8] = ((words[3] >> 0) & 0x00003F);
sv[9] = ((words[4] >> 18) & 0x00003F);
sv[10] = ((words[4] >> 12) & 0x00003F);
sv[11] = ((words[4] >> 6) & 0x00003F);
sv[12] = ((words[4] >> 0) & 0x00003F);
sv[13] = ((words[5] >> 18) & 0x00003F);
sv[14] = ((words[5] >> 12) & 0x00003F);
sv[15] = ((words[5] >> 6) & 0x00003F);
sv[16] = ((words[5] >> 0) & 0x00003F);
sv[17] = ((words[6] >> 18) & 0x00003F);
sv[18] = ((words[6] >> 12) & 0x00003F);
sv[19] = ((words[6] >> 6) & 0x00003F);
sv[20] = ((words[6] >> 0) & 0x00003F);
sv[21] = ((words[7] >> 18) & 0x00003F);
sv[22] = ((words[7] >> 12) & 0x00003F);
sv[23] = ((words[7] >> 6) & 0x00003F);
sv[24] = ((words[7] >> 0) & 0x00003F);
gpsd_report(LOG_PROG,
"50B: SF:5-25 SV:%2u DI:%u toa:%lu WNa:%u "
"SV1:%u SV2:%u SV3:%uSV4:%u "
"SV5:%u SV6:%u SV7:%uSV8:%u "
"SV9:%u SV10:%u SV11:%uSV12:%u "
"SV13:%u SV14:%u SV15:%uSV16:%u "
"SV17:%u SV18:%u SV19:%uSV20:%u "
"SV21:%u SV22:%u SV23:%uSV24:%u\n",
svid, data_id, l_toa, WNa,
sv[1], sv[2], sv[3], sv[4],
sv[5], sv[5], sv[6], sv[4],
sv[9], sv[10], sv[11], sv[12],
sv[13], sv[14], sv[15], sv[16],
sv[17], sv[18], sv[19], sv[20],
sv[21], sv[22], sv[23], sv[24]);
} else {
/* unknown page */
gpsd_report(LOG_PROG, "50B: SF:5-%d data_id %d uknown page\n",
pageid, data_id);
}
break;
default:
/* unknown/illegal subframe */
break;
}
return;
}
/*@ +usedef @*/
|