summaryrefslogtreecommitdiff
path: root/driver_rtcm3.c
blob: c30bfb5cc2b2d315683dac3809c57dcdc74eaae0 (plain)
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
/* $Id$ */
/*****************************************************************************

This is a decoder for RTCM-104 3.x, a serial protocol used for
broadcasting pseudorange corrections from differential-GPS reference
stations.  The applicable specification is RTCM 10403.1: RTCM Paper
177-2006-SC104-STD.  This obsolesces the esrlier RTCM-104 2.x
specifications. The specification document is proprietary; ordering 
instructions are accessible from <http://www.rtcm.org/>
under "Publications".  

Unike the RTCM 2.x protocol, RTCM3.x does not use the strange
sliding-bit-window IS-GPS-200 protocol as a transport layer, but is a
self-contained byte-oriented packet protocol.  Packet recognition is
handled in the GPSD packet-getter state machine; this code is
concerned with unpacking the packets into well-behaved C structures,
coping with odd field lengths and fields that may overlap byte
boudaries.  These report structures live in gps.h.

Note that the unpacking this module does is probably useful only for
RTCM reporting and diagnostic tools.  It is not necessary when
passing RTCM corrections to a GPS, which normally should just be
passed an entire correction packet for processing by their internal
firmware.

*****************************************************************************/

#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <assert.h>
#include <arpa/inet.h>	/* for ntohl(3) and friends */

#include "gpsd_config.h"
#include "gpsd.h"
#include "bits.h"

#ifdef RTCM104V3_ENABLE

/* scaling constants for RTCM3 real number types */
#define PSEUDORANGE_RESOLUTION		0.2	/* DF011 */
#define PSEUDORANGE_DIFF_RESOLUTION	0.0005	/* DF012 */
#define CARRIER_NOISE_RATIO_UNITS	0.25	/* DF015 */
#define ANTENNA_POSITION_RESOLUTION	0.0001	/* DF025-027 */
#define ANTENNA_DEGREE_RESOLUTION	25e-6	/* DF062 */
#define GPS_EPOCH_TIME_RESOLUTION	0.1	/* DF065 */
#define PHASE_CORRECTION_RESOLUTION	0.5	/* DF069-070 */

/* Other magic values */
#define INVALID_PSEUDORANGE		0x80000	/* DF012 */

/*@ -type @*/	/* re-enable when we're ready to take this live */

void rtcm3_unpack(/*@out@*/struct rtcm3_t *rtcm, char *buf)
/* break out the raw bits into the scaled report-structure fields */
{
    unsigned int n, n2;
    int bitcount = 0;
    unsigned int i;
    signed long temp;

    /*@ -evalorder -sefparams -mayaliasunique @*/    
#define ugrab(width)	(bitcount += width, ubits(buf, bitcount-width, width))
#define sgrab(width)	(bitcount += width, sbits(buf, bitcount-width, width))
    assert(ugrab(8) == 0xD3);
    assert(ugrab(6) == 0x00);

    rtcm->length = (uint)ugrab(10);
    rtcm->type = (uint)ugrab(12);

    switch(rtcm->type) {
    case 1001:	/* GPS Basic RTK, L1 Only */
	rtcm->rtcmtypes.rtcm3_1001.header.station_id = (uint)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1001.header.tow        = (time_t)ugrab(30);
	rtcm->rtcmtypes.rtcm3_1001.header.sync       = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1001.header.satcount   = (ushort)ugrab(5);
	rtcm->rtcmtypes.rtcm3_1001.header.smoothing  = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1001.header.interval   = (ushort)ugrab(3);
	for (i = 0; i < rtcm->rtcmtypes.rtcm3_1001.header.satcount; i++) {
	    rtcm->rtcmtypes.rtcm3_1001.rtk_data[i].ident = (ushort)ugrab(6);
	    rtcm->rtcmtypes.rtcm3_1001.rtk_data[i].L1.indicator = (unsigned char)ugrab(1);
	    temp = (unsigned long)ugrab(24);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1001.rtk_data[i].L1.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1001.rtk_data[i].L1.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1001.rtk_data[i].L1.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1001.rtk_data[i].L1.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1001.rtk_data[i].L1.locktime = (unsigned char)sgrab(7);
	}
	assert(bitcount == 64 + 58*rtcm->rtcmtypes.rtcm3_1001.header.satcount);
	break;

    case 1002:	/* GPS Extended RTK, L1 Only */
	rtcm->rtcmtypes.rtcm3_1002.header.station_id = (uint)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1002.header.tow        = (time_t)ugrab(30);
	rtcm->rtcmtypes.rtcm3_1002.header.sync       = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1002.header.satcount   = (ushort)ugrab(5);
	rtcm->rtcmtypes.rtcm3_1002.header.smoothing  = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1002.header.interval   = (ushort)ugrab(3);
	for (i = 0; i < rtcm->rtcmtypes.rtcm3_1002.header.satcount; i++) {
	    rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].ident = (ushort)ugrab(6);
	    rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.indicator = (unsigned char)ugrab(1);
	    temp = (unsigned long)ugrab(24);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.locktime = (unsigned char)sgrab(7);
	    rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.ambiguity = (bool)ugrab(8);
	    rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.CNR = (bool)ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
	}
	assert(bitcount == 64 + 74*rtcm->rtcmtypes.rtcm3_1002.header.satcount);
	break;

    case 1003:	/* GPS Basic RTK, L1 & L2 */
	rtcm->rtcmtypes.rtcm3_1003.header.station_id = (uint)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1003.header.tow        = (time_t)ugrab(30);
	rtcm->rtcmtypes.rtcm3_1003.header.sync       = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1003.header.satcount   = (ushort)ugrab(5);
	rtcm->rtcmtypes.rtcm3_1003.header.smoothing  = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1003.header.interval   = (ushort)ugrab(3);
	for (i = 0; i < rtcm->rtcmtypes.rtcm3_1003.header.satcount; i++) {
	    rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].ident = (ushort)ugrab(6);
	    rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.indicator = (unsigned char)ugrab(1);
	    temp = (unsigned long)ugrab(24);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.locktime = (unsigned char)sgrab(7);
	    rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L2.indicator = (unsigned char)ugrab(2);
	    temp = (unsigned long)ugrab(24);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L2.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L2.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L2.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L2.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L2.locktime = (unsigned char)sgrab(7);
	}
	assert(bitcount == 64 + 101*rtcm->rtcmtypes.rtcm3_1003.header.satcount);
	break;

    case 1004:	/* GPS Extended RTK, L1 & L2 */
	rtcm->rtcmtypes.rtcm3_1004.header.station_id = (uint)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1004.header.tow        = (time_t)ugrab(30);
	rtcm->rtcmtypes.rtcm3_1004.header.sync       = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1004.header.satcount   = (ushort)ugrab(5);
	rtcm->rtcmtypes.rtcm3_1004.header.smoothing  = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1004.header.interval   = (ushort)ugrab(3);
	for (i = 0; i < rtcm->rtcmtypes.rtcm3_1004.header.satcount; i++) {
	    rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].ident = (ushort)ugrab(6);
	    rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.indicator = (bool)ugrab(1);
	    temp = (unsigned long)ugrab(24);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.locktime = (unsigned char)sgrab(7);
	    rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.ambiguity = (bool)ugrab(8);
	    rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.CNR = (bool)ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
	    rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.indicator = (unsigned char)ugrab(2);
	    temp = (unsigned long)ugrab(24);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.locktime = (unsigned char)sgrab(7);
	    rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.ambiguity = (bool)ugrab(8);
	    rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.CNR = (bool)ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
	}
	assert(bitcount == 64 + 125*rtcm->rtcmtypes.rtcm3_1004.header.satcount);
	break;

    case 1005:	/* Stationary Antenna Reference Point, No Height Information */
	rtcm->rtcmtypes.rtcm3_1005.station_id = (unsigned short)ugrab(12);
	ugrab(6);	/* reserved */
	if ((bool)ugrab(1))
	    rtcm->rtcmtypes.rtcm3_1005.system = gps;
	else if ((bool)ugrab(1))
	    rtcm->rtcmtypes.rtcm3_1005.system = glonass;
	else if ((bool)ugrab(1))
	    rtcm->rtcmtypes.rtcm3_1005.system = galileo;
	rtcm->rtcmtypes.rtcm3_1005.reference_station = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1005.ecef_x = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
	rtcm->rtcmtypes.rtcm3_1005.single_receiver = ugrab(1);
	ugrab(1);
	rtcm->rtcmtypes.rtcm3_1005.ecef_y = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
	ugrab(2);
	rtcm->rtcmtypes.rtcm3_1005.ecef_z = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
	assert(bitcount == 152);
	break;

    case 1006:	/* Stationary Antenna Reference Point, with Height Information */
	rtcm->rtcmtypes.rtcm3_1006.station_id = (unsigned short)ugrab(12);
	ugrab(6);	/* reserved */
	if ((bool)ugrab(1))
	    rtcm->rtcmtypes.rtcm3_1006.system = gps;
	else if ((bool)ugrab(1))
	    rtcm->rtcmtypes.rtcm3_1006.system = glonass;
	else if ((bool)ugrab(1))
	    rtcm->rtcmtypes.rtcm3_1006.system = galileo;
	rtcm->rtcmtypes.rtcm3_1006.reference_station = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1006.ecef_x = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
	rtcm->rtcmtypes.rtcm3_1006.single_receiver = ugrab(1);
	ugrab(1);
	rtcm->rtcmtypes.rtcm3_1006.ecef_y = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
	ugrab(2);
	rtcm->rtcmtypes.rtcm3_1006.ecef_z = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
	rtcm->rtcmtypes.rtcm3_1006.height = ugrab(16) * ANTENNA_POSITION_RESOLUTION;
	assert(bitcount == 168);
	break;

    case 1007:	/* Antenna Descriptor */
	rtcm->rtcmtypes.rtcm3_1007.station_id = (unsigned short)ugrab(12);
	n = (unsigned long)ugrab(8);
	(void)memcpy(rtcm->rtcmtypes.rtcm3_1007.descriptor, buf + 4, n);
	rtcm->rtcmtypes.rtcm3_1007.descriptor[n] = '\0';
	bitcount += 8 * n;
	rtcm->rtcmtypes.rtcm3_1007.setup_id = ugrab(8);
	assert(bitcount == (int)(40 + 8*n));
	break;

    case 1008:	/* Antenna Descriptor & Serial Number */
	rtcm->rtcmtypes.rtcm3_1008.station_id = (unsigned short)ugrab(12);
	n = (unsigned long)ugrab(8);
	(void)memcpy(rtcm->rtcmtypes.rtcm3_1008.descriptor, buf + 4, n);
	rtcm->rtcmtypes.rtcm3_1008.descriptor[n] = '\0';
	bitcount += 8 * n;
	rtcm->rtcmtypes.rtcm3_1008.setup_id = ugrab(8);
	n2 = (unsigned long)ugrab(8);
	(void)memcpy(rtcm->rtcmtypes.rtcm3_1008.serial, buf + 6 + n, n2);
	rtcm->rtcmtypes.rtcm3_1008.serial[n2] = '\0';
	bitcount += 8 * n2;
	assert(bitcount == (int)(48 + 8*(n+n2)));
	break;

    case 1009:	/* GLONASS Basic RTK, L1 Only */
	rtcm->rtcmtypes.rtcm3_1009.header.station_id = (unsigned short)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1009.header.tow = (time_t)ugrab(27);
	rtcm->rtcmtypes.rtcm3_1009.header.sync = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1009.header.satcount = (ushort)ugrab(5);
	rtcm->rtcmtypes.rtcm3_1009.header.smoothing = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1009.header.interval   = (ushort)ugrab(3);
	for (i = 0; i < rtcm->rtcmtypes.rtcm3_1009.header.satcount; i++) {
	    rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].ident = (ushort)ugrab(6);
	    rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].L1.indicator = (bool)ugrab(1);
	    rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].L1.channel = (ushort)ugrab(5);
	    temp = (unsigned long)ugrab(25);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].L1.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].L1.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].L1.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].L1.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].L1.locktime = (unsigned char)sgrab(7);
	}
	assert(bitcount == 61 + 64*rtcm->rtcmtypes.rtcm3_1009.header.satcount);
	break;

    case 1010:	/* GLONASS Extended RTK, L1 Only */
	rtcm->rtcmtypes.rtcm3_1010.header.station_id = (unsigned short)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1010.header.tow = (time_t)ugrab(27);
	rtcm->rtcmtypes.rtcm3_1010.header.sync = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1010.header.satcount = (ushort)ugrab(5);
	rtcm->rtcmtypes.rtcm3_1010.header.smoothing = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1010.header.interval   = (ushort)ugrab(3);
	for (i = 0; i < rtcm->rtcmtypes.rtcm3_1010.header.satcount; i++) {
	    rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].ident = (ushort)ugrab(6);
	    rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.indicator = (bool)ugrab(1);
	    rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.channel = (ushort)ugrab(5);
	    temp = (unsigned long)ugrab(25);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.locktime = (unsigned char)sgrab(7);
	    rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.ambiguity = (bool)ugrab(7);
	    rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.CNR = (bool)ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
	}
	assert(bitcount == 61 + 79*rtcm->rtcmtypes.rtcm3_1010.header.satcount);
	break;

    case 1011:	/* GLONASS Basic RTK, L1 & L2 */
	rtcm->rtcmtypes.rtcm3_1011.header.station_id = (unsigned short)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1011.header.tow = (time_t)ugrab(27);
	rtcm->rtcmtypes.rtcm3_1011.header.sync = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1011.header.satcount = (ushort)ugrab(5);
	rtcm->rtcmtypes.rtcm3_1011.header.smoothing = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1011.header.interval   = (ushort)ugrab(3);
	for (i = 0; i < rtcm->rtcmtypes.rtcm3_1011.header.satcount; i++) {
	    rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].ident = (ushort)ugrab(6);
	    rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.indicator = (bool)ugrab(1);
	    rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.channel = (ushort)ugrab(5);
	    temp = (unsigned long)ugrab(25);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.locktime = (unsigned char)sgrab(7);
	    rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.ambiguity = (bool)ugrab(7);
	    rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.CNR = (bool)ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
	    rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.indicator = (bool)ugrab(1);
	    rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.channel = (ushort)ugrab(5);
	    temp = (unsigned long)ugrab(25);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.locktime = (unsigned char)sgrab(7);
	    rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.ambiguity = (bool)ugrab(7);
	    rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.CNR = (bool)ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
	}
	assert(bitcount == 61 + 107*rtcm->rtcmtypes.rtcm3_1011.header.satcount);
	break;

    case 1012:	/* GLONASS Extended RTK, L1 & L2 */
	rtcm->rtcmtypes.rtcm3_1012.header.station_id = (unsigned short)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1012.header.tow = (time_t)ugrab(27);
	rtcm->rtcmtypes.rtcm3_1012.header.sync = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1012.header.satcount = (ushort)ugrab(5);
	rtcm->rtcmtypes.rtcm3_1012.header.smoothing = (bool)ugrab(1);
	rtcm->rtcmtypes.rtcm3_1012.header.interval   = (ushort)ugrab(3);
	for (i = 0; i < rtcm->rtcmtypes.rtcm3_1012.header.satcount; i++) {
	    rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].ident = (ushort)ugrab(6);
	    rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.indicator = (bool)ugrab(1);
	    rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.channel = (ushort)ugrab(5);
	    temp = (unsigned long)ugrab(25);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.locktime = (unsigned char)sgrab(7);
	    rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.indicator = (bool)ugrab(1);
	    temp = (unsigned long)ugrab(25);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.pseudorange  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.pseudorange  = temp * PSEUDORANGE_RESOLUTION;
	    temp = (long)sgrab(20);
	    if (temp == INVALID_PSEUDORANGE)
		rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.rangediff  = 0;
	    else
		rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.rangediff  = temp * PSEUDORANGE_DIFF_RESOLUTION;
	    rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.locktime = (unsigned char)sgrab(7);
	}
	assert(bitcount == 61 + 130*rtcm->rtcmtypes.rtcm3_1012.header.satcount);
	break;

    case 1013:	/* System Parameters */
	rtcm->rtcmtypes.rtcm3_1013.station_id =(unsigned short)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1013.mjd = (unsigned short)ugrab(16);
	rtcm->rtcmtypes.rtcm3_1013.sod = (unsigned short)ugrab(17);
	rtcm->rtcmtypes.rtcm3_1013.ncount = (unsigned long)ugrab(5);
	rtcm->rtcmtypes.rtcm3_1013.leapsecs = (unsigned char)ugrab(8);
	for (i = 0; i < rtcm->rtcmtypes.rtcm3_1013.ncount; i++) {
	    rtcm->rtcmtypes.rtcm3_1013.announcements[i].id =  (unsigned short)ugrab(12);
	    rtcm->rtcmtypes.rtcm3_1013.announcements[i].sync =  (bool)ugrab(1);
	    rtcm->rtcmtypes.rtcm3_1013.announcements[i].interval =  (unsigned short)ugrab(16);
	}
	assert(bitcount == 70 + 29*rtcm->rtcmtypes.rtcm3_1013.ncount);
	break;

    case 1014:
	rtcm->rtcmtypes.rtcm3_1014.network_id =(int)ugrab(8);
	rtcm->rtcmtypes.rtcm3_1014.subnetwork_id =(int)ugrab(4);
	rtcm->rtcmtypes.rtcm3_1014.stationcount =(char)ugrab(5);
	rtcm->rtcmtypes.rtcm3_1014.master_id =(int)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1014.aux_id =(int)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1014.d_lat =(unsigned short)ugrab(20) * ANTENNA_DEGREE_RESOLUTION;
	rtcm->rtcmtypes.rtcm3_1014.d_lon =(unsigned short)ugrab(21) * ANTENNA_DEGREE_RESOLUTION;
	rtcm->rtcmtypes.rtcm3_1014.d_alt =(unsigned short)ugrab(23) / 1000;
	assert(bitcount == 117);
	break;

    case 1015:
	break;

    case 1016:
	break;

    case 1017:
	break;

    case 1018:
	break;

    case 1019:
	break;

    case 1020:
	break;

    case 1029:
	rtcm->rtcmtypes.rtcm3_1029.station_id = (unsigned short)ugrab(12);
	rtcm->rtcmtypes.rtcm3_1029.mjd = (unsigned short)ugrab(16);
	rtcm->rtcmtypes.rtcm3_1029.sod = (unsigned short)ugrab(17);
	rtcm->rtcmtypes.rtcm3_1029.len = (unsigned long)ugrab(7);
	n = rtcm->rtcmtypes.rtcm3_1029.unicode_units = (unsigned long)ugrab(8);
	(void)memcpy(rtcm->rtcmtypes.rtcm3_1029.text, buf+9, n);
	bitcount += 8*n;
	assert(bitcount == (int)(72+8*n));
	break;
    }
#undef sgrab
#undef ugrab
    /*@ +evalorder +sefparams +mayaliasunique @*/    
}

void rtcm3_dump(struct rtcm3_t *rtcm, FILE *fp)
/* dump the contents of a parsed RTCM104 message */
{
    int i;

    char *systems[] = {"GPS", "Glonass", "Galileo", "unknown"};

    (void)fprintf(fp, "%u (%u):\n", rtcm->type, rtcm->length);

#define BOOL(c)	(c!=0 ? 't' : 'f')
#define CODE(x) (unsigned int)(x)
#define INT(x) (unsigned int)(x)
    switch(rtcm->type) {
	case 1001:
	    (void)fprintf(fp, 
			  "  #station_id=%u, tow=%d sync=%c smoothing=%c interval=%u satcount=%u", 
			  rtcm->rtcmtypes.rtcm3_1001.header.station_id,
			  (int)rtcm->rtcmtypes.rtcm3_1001.header.tow,
			  BOOL(rtcm->rtcmtypes.rtcm3_1001.header.sync),
			  BOOL(rtcm->rtcmtypes.rtcm3_1001.header.smoothing),
			  rtcm->rtcmtypes.rtcm3_1001.header.interval,
			  rtcm->rtcmtypes.rtcm3_1001.header.satcount);
	    for (i = 0; i < rtcm->rtcmtypes.rtcm3_1001.header.satcount; i++) {
		(void)fprintf(fp, 
			      "    ident=%u\n      L1: ind=%u prange=%8.1f delta=%6.4f lockt=%u\n", 
			      rtcm->rtcmtypes.rtcm3_1001.rtk_data[i].ident,
			      CODE(rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.indicator),
			      rtcm->rtcmtypes.rtcm3_1001.rtk_data[i].L1.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1001.rtk_data[i].L1.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1001.rtk_data[i].L1.locktime));
	    }		
	    break;

	case 1002:
	    (void)fprintf(fp, 
			  "  #station_id=%u, tow=%d sync=%c smoothing=%c interval=%u satcount=%u", 
			  rtcm->rtcmtypes.rtcm3_1002.header.station_id,
			  (int)rtcm->rtcmtypes.rtcm3_1002.header.tow,
			  BOOL(rtcm->rtcmtypes.rtcm3_1002.header.sync),
			  BOOL(rtcm->rtcmtypes.rtcm3_1002.header.smoothing),
			  rtcm->rtcmtypes.rtcm3_1002.header.interval,
			  rtcm->rtcmtypes.rtcm3_1002.header.satcount);	    
	    for (i = 0; i < rtcm->rtcmtypes.rtcm3_1002.header.satcount; i++) {
		(void)fprintf(fp, 
			      "    ident=%u\n      L1: ind=%u prange=%8.1f delta=%6.4f lockt=%u amb=%u CNR=%.2f\n",
			      rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].ident,
			      CODE(rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.indicator),
			      rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.locktime),
			      INT(rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.ambiguity),
			      rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.CNR);
	    }		
	    break;

	case 1003:
	    (void)fprintf(fp,
			  "  #station_id=%u, tow=%d sync=%c smoothing=%c interval=%u satcount=%u", 
			  rtcm->rtcmtypes.rtcm3_1003.header.station_id,
			  (int)rtcm->rtcmtypes.rtcm3_1003.header.tow,
			  BOOL(rtcm->rtcmtypes.rtcm3_1003.header.sync),
			  BOOL(rtcm->rtcmtypes.rtcm3_1003.header.smoothing),
			  rtcm->rtcmtypes.rtcm3_1003.header.interval,
			  rtcm->rtcmtypes.rtcm3_1003.header.satcount);	    
	    for (i = 0; i < rtcm->rtcmtypes.rtcm3_1003.header.satcount; i++) {
		(void)fprintf(fp, 
			      "    ident=%u\n      L1: ind=%u prange=%8.1f delta=%6.4f lockt=%u\n      L2: ind=%u prange=%8.1f delta=%6.4f lockt=%u\n", 
			      rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].ident,
			      CODE(rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.indicator),
			      rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.locktime),
			      CODE(rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L2.indicator),
			      rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L2.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L2.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L2.locktime));
	    }		
	    break;

	case 1004:
	    (void)fprintf(fp, 
			  "  #station_id=%u, tow=%d sync=%c smoothing=%c interval=%u satcount=%u\n", 
			  rtcm->rtcmtypes.rtcm3_1004.header.station_id,
			  (int)rtcm->rtcmtypes.rtcm3_1004.header.tow,
			  BOOL(rtcm->rtcmtypes.rtcm3_1004.header.sync),
			  BOOL(rtcm->rtcmtypes.rtcm3_1004.header.smoothing),
			  rtcm->rtcmtypes.rtcm3_1004.header.interval,
			  rtcm->rtcmtypes.rtcm3_1004.header.satcount);
	    for (i = 0; i < rtcm->rtcmtypes.rtcm3_1004.header.satcount; i++) {
		(void)fprintf(fp, 
			      "    ident=%u\n      L1: ind=%u prange=%8.1f delta=%6.4f lockt=%u amb=%u CNR=%.2f\n      L2: ind=%u prange=%8.1f delta=%6.4f lockt=%u amb=%u CNR=%.2f\n", 
			      rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].ident,
			      CODE(rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.indicator),
			      rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L1.locktime),
			      INT(rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.ambiguity),
			      rtcm->rtcmtypes.rtcm3_1002.rtk_data[i].L1.CNR,
			      CODE(rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.indicator),
			      rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.locktime),
			      INT(rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.ambiguity),
			      rtcm->rtcmtypes.rtcm3_1004.rtk_data[i].L2.CNR);
	    }		
	    break;

	case 1005:
	    (void)fprintf(fp, 
			  "  station_id=%u, %s refstation=%c sro=%c x=%f y=%f z=%f\n", 
			  rtcm->rtcmtypes.rtcm3_1005.station_id,
			  systems[rtcm->rtcmtypes.rtcm3_1005.system],
			  BOOL(rtcm->rtcmtypes.rtcm3_1005.reference_station),
			  BOOL(rtcm->rtcmtypes.rtcm3_1005.single_receiver),
			  rtcm->rtcmtypes.rtcm3_1005.ecef_x,
			  rtcm->rtcmtypes.rtcm3_1005.ecef_y,
			  rtcm->rtcmtypes.rtcm3_1005.ecef_z);
	    break;

	case 1006:
	    (void)fprintf(fp, 
			  "  station_id=%u, %s refstation=%c sro=%c x=%f y=%f z=%f a=%f\n", 
			  rtcm->rtcmtypes.rtcm3_1006.station_id,
			  systems[rtcm->rtcmtypes.rtcm3_1006.system],
			  BOOL(rtcm->rtcmtypes.rtcm3_1006.reference_station),
			  BOOL(rtcm->rtcmtypes.rtcm3_1006.single_receiver),
			  rtcm->rtcmtypes.rtcm3_1006.ecef_x,
			  rtcm->rtcmtypes.rtcm3_1006.ecef_y,
			  rtcm->rtcmtypes.rtcm3_1006.ecef_z,
			  rtcm->rtcmtypes.rtcm3_1006.height);
	    break;

	case 1007:
	    (void)fprintf(fp, 
			  "  station_id=%u, desc=%s setup-id=%u\n",
			  rtcm->rtcmtypes.rtcm3_1007.station_id,
			  rtcm->rtcmtypes.rtcm3_1007.descriptor,
			  INT(rtcm->rtcmtypes.rtcm3_1007.setup_id));
	    break;

	case 1008:
	    (void)fprintf(fp, 
			  "  station_id=%u, desc=%s setup-id=%u serial=%s\n",
			  rtcm->rtcmtypes.rtcm3_1008.station_id,
			  rtcm->rtcmtypes.rtcm3_1008.descriptor,
			  INT(rtcm->rtcmtypes.rtcm3_1008.setup_id),
			  rtcm->rtcmtypes.rtcm3_1008.serial);
	    break;

	case 1009:
	    (void)fprintf(fp, 
			  "  #station_id=%u, tow=%d sync=%c smooting=%c interval=%u satcount=%u", 
			  rtcm->rtcmtypes.rtcm3_1009.header.station_id,
			  (int)rtcm->rtcmtypes.rtcm3_1009.header.tow,
			  BOOL(rtcm->rtcmtypes.rtcm3_1009.header.sync),
			  BOOL(rtcm->rtcmtypes.rtcm3_1009.header.smoothing),
			  rtcm->rtcmtypes.rtcm3_1009.header.interval,
			  rtcm->rtcmtypes.rtcm3_1009.header.satcount);
	    for (i = 0; i < rtcm->rtcmtypes.rtcm3_1009.header.satcount; i++) {
		(void)fprintf(fp, 
			      "    ident=%u\n      L1: ind=%u channel=%u prange=%8.1f delta=%6.4f lockt=%u\n", 
			      rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].ident,
			      CODE(rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.indicator),
			      INT(rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].L1.channel),
			      rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].L1.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].L1.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1009.rtk_data[i].L1.locktime));
	    }		
	    break;

	case 1010:
	    (void)fprintf(fp, 
			  "  #station_id=%u, tow=%d sync=%c smooting=%c interval=%u satcount=%u", 
			  rtcm->rtcmtypes.rtcm3_1010.header.station_id,
			  (int)rtcm->rtcmtypes.rtcm3_1010.header.tow,
			  BOOL(rtcm->rtcmtypes.rtcm3_1010.header.sync),
			  BOOL(rtcm->rtcmtypes.rtcm3_1010.header.smoothing),
			  rtcm->rtcmtypes.rtcm3_1010.header.interval,
			  rtcm->rtcmtypes.rtcm3_1010.header.satcount);
	    for (i = 0; i < rtcm->rtcmtypes.rtcm3_1010.header.satcount; i++) {
		(void)fprintf(fp, 
			      "    ident=%u\n      L1: ind=%u channel=%u prange=%8.1f delta=%6.4f lockt=%u amb=%u CNR=%.2f\n", 
			      rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].ident,
			      CODE(rtcm->rtcmtypes.rtcm3_1003.rtk_data[i].L1.indicator),
			      INT(rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.channel),
			      rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.locktime),
			      INT(rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.ambiguity),
			      rtcm->rtcmtypes.rtcm3_1010.rtk_data[i].L1.CNR);
	    }		
	    break;

	case 1011:
	    (void)fprintf(fp, 
			  "  #station_id=%u, tow=%d sync=%c smooting=%c interval=%u satcount=%u", 
			  rtcm->rtcmtypes.rtcm3_1011.header.station_id,
			  (int)rtcm->rtcmtypes.rtcm3_1011.header.tow,
			  BOOL(rtcm->rtcmtypes.rtcm3_1011.header.sync),
			  BOOL(rtcm->rtcmtypes.rtcm3_1011.header.smoothing),
			  rtcm->rtcmtypes.rtcm3_1011.header.interval,
			  rtcm->rtcmtypes.rtcm3_1011.header.satcount);
	    for (i = 0; i < rtcm->rtcmtypes.rtcm3_1011.header.satcount; i++) {
		(void)fprintf(fp, 
			      "    ident=%u\n      L1: ind=%u channel=%u prange=%8.1f delta=%6.4f lockt=%u\n      L2: ind=%u prange=%8.1f delta=%6.4f lockt=%u\n", 
			      rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].ident,
			      CODE(rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.indicator),
			      INT(rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.channel),
			      rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L1.locktime),
			      CODE(rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.indicator),
			      rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1011.rtk_data[i].L2.locktime));
	    }
	    break;

	case 1012:
	    (void)fprintf(fp, 
			  "  #station_id=%u, tow=%d sync=%c smooting=%c interval=%u satcount=%u", 
			  rtcm->rtcmtypes.rtcm3_1012.header.station_id,
			  (int)rtcm->rtcmtypes.rtcm3_1012.header.tow,
			  BOOL(rtcm->rtcmtypes.rtcm3_1012.header.sync),
			  BOOL(rtcm->rtcmtypes.rtcm3_1012.header.smoothing),
			  rtcm->rtcmtypes.rtcm3_1012.header.interval,
			  rtcm->rtcmtypes.rtcm3_1012.header.satcount);
	    for (i = 0; i < rtcm->rtcmtypes.rtcm3_1012.header.satcount; i++) {
		(void)fprintf(fp, 
			      "    ident=%u\n      L1: ind=%u channel=%u prange=%8.1f delta=%6.4f lockt=%u amb=%u CNR=%.2f\n      L2: ind=%u prange=%8.1f delta=%6.4f lockt=%u amb=%u CNR=%.2f\n", 
			      rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].ident,
			      CODE(rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.indicator),
			      INT(rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.channel),
			      rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.locktime),
			      INT(rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.ambiguity),
			      rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L1.CNR,
			      CODE(rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.indicator),
			      rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.pseudorange,
			      rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.rangediff,
			      INT(rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.locktime),
			      INT(rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.ambiguity),
			      rtcm->rtcmtypes.rtcm3_1012.rtk_data[i].L2.CNR);
	    }
	    break;

	case 1013:
	    (void)fprintf(fp,
			  "  station_id=%u, mjd=%u sec=%u leapsecs=%u ncount=%u\n",
			  rtcm->rtcmtypes.rtcm3_1013.station_id,
			  rtcm->rtcmtypes.rtcm3_1013.mjd,
			  rtcm->rtcmtypes.rtcm3_1013.sod,
			  INT(rtcm->rtcmtypes.rtcm3_1013.leapsecs),
			  INT(rtcm->rtcmtypes.rtcm3_1013.ncount));
	for (i = 0; i < rtcm->rtcmtypes.rtcm3_1013.ncount; i++)
	    (void)fprintf(fp,
			  "    id=%u sync=%c interval=%u\n",
			  rtcm->rtcmtypes.rtcm3_1013.announcements[i].id,
			  BOOL(rtcm->rtcmtypes.rtcm3_1013.announcements[i].sync),
			  rtcm->rtcmtypes.rtcm3_1013.announcements[i].interval);
	    break;

	case 1014:
	    (void)fprintf(fp,
			  "    netid=%u subnetid=%u statcount=%u master=%u aux=%u lat=%f, lon=%f, alt=%f\n",
			  rtcm->rtcmtypes.rtcm3_1014.network_id,
			  rtcm->rtcmtypes.rtcm3_1014.subnetwork_id,
			  (uint)rtcm->rtcmtypes.rtcm3_1014.stationcount,
			  rtcm->rtcmtypes.rtcm3_1014.master_id,
			  rtcm->rtcmtypes.rtcm3_1014.aux_id,
			  rtcm->rtcmtypes.rtcm3_1014.d_lat,
			  rtcm->rtcmtypes.rtcm3_1014.d_lon,
			  rtcm->rtcmtypes.rtcm3_1014.d_alt);
	    break;

	case 1015:
	    break;

	case 1016:
	    break;

	case 1017:
	    break;

	case 1018:
	    break;

	case 1019:
	    break;

	case 1020:
	    break;

	case 1029:
	    (void)fprintf(fp,
			  "  station_id=%u, mjd=%u sec=%u len=%u units=%u msg=%s\n",
			  rtcm->rtcmtypes.rtcm3_1029.station_id,
			  rtcm->rtcmtypes.rtcm3_1029.mjd,
			  rtcm->rtcmtypes.rtcm3_1029.sod,
			  INT(rtcm->rtcmtypes.rtcm3_1029.len),
			  INT(rtcm->rtcmtypes.rtcm3_1029.unicode_units),
			  (char *)rtcm->rtcmtypes.rtcm3_1029.text);
	    break;

	default:
	    (void)fprintf(fp, "    Unknown content\n"); 
	    break;
    }
#undef CODE
#undef BOOL
#undef INT
}

/*@ +type @*/

#endif /* RTCM104V3_ENABLE */