-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtcm3e.c
2482 lines (2278 loc) · 94.4 KB
/
rtcm3e.c
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
/*------------------------------------------------------------------------------
* rtcm3e.c : rtcm ver.3 message encoder functions
*
* Copyright (C) 2012-2017 by T.TAKASU, All rights reserved.
*
* options :
* -DSSR_QZSS_DRAFT_V05: qzss ssr messages based on ref [16]
*
* references :
* see rtcm.c
*
* version : $Revision:$ $Date:$
* history : 2012/12/05 1.0 new
* 2012/12/16 1.1 fix bug on ssr high rate clock correction
* 2012/12/24 1.2 fix bug on msm carrier-phase offset correction
* fix bug on SBAS sat id in 1001-1004
* fix bug on carrier-phase in 1001-1004,1009-1012
* 2012/12/28 1.3 fix bug on compass carrier wave length
* 2013/01/18 1.4 fix bug on ssr message generation
* 2013/05/11 1.5 change type of arg value of setbig()
* 2013/05/19 1.5 gpst -> bdt of time-tag in beidou msm message
* 2013/04/27 1.7 comply with rtcm 3.2 with amendment 1/2 (ref[15])
* delete MT 1046 according to ref [15]
* 2014/05/15 1.8 set NT field in MT 1020 glonass ephemeris
* 2014/12/06 1.9 support SBAS/BeiDou SSR messages (ref [16])
* fix bug on invalid staid in qzss ssr messages
* 2015/03/22 1.9 add handling of iodcrc for beidou/sbas ssr messages
* 2015/08/03 1.10 fix bug on wrong udint and iod in ssr 7.
* support rtcm ssr fcb message mt 2065-2069.
* 2015/09/07 1.11 add message count of MT 2000-2099
* 2015/10/21 1.12 add MT1046 support for IGS MGEX
* 2015/12/04 1.13 add MT63 beidou ephemeris (rtcm draft)
* fix bug on msm message generation of beidou
* fix bug on ssr 3 message generation (#321)
* 2016/06/12 1.14 fix bug on segmentation fault by generating msm1
* 2016/09/20 1.15 fix bug on MT1045 Galileo week rollover
* 2017/04/11 1.16 fix bug on gst-week in MT1045/1046
*-----------------------------------------------------------------------------*/
#include "rtklib.h"
/* constants and macros ------------------------------------------------------*/
#define PRUNIT_GPS 299792.458 /* rtcm 3 unit of gps pseudorange (m) */
#define PRUNIT_GLO 599584.916 /* rtcm 3 unit of glo pseudorange (m) */
#define RANGE_MS (CLIGHT*0.001) /* range in 1 ms */
#define P2_10 0.0009765625 /* 2^-10 */
#define P2_34 5.820766091346740E-11 /* 2^-34 */
#define P2_46 1.421085471520200E-14 /* 2^-46 */
#define P2_59 1.734723475976810E-18 /* 2^-59 */
#define P2_66 1.355252715606880E-20 /* 2^-66 */
#define ROUND(x) ((int)floor((x)+0.5))
#define ROUND_U(x) ((unsigned int)floor((x)+0.5))
#define MIN(x,y) ((x)<(y)?(x):(y))
/* msm signal id table -------------------------------------------------------*/
extern const char *msm_sig_gps[32];
extern const char *msm_sig_glo[32];
extern const char *msm_sig_gal[32];
extern const char *msm_sig_qzs[32];
extern const char *msm_sig_sbs[32];
extern const char *msm_sig_cmp[32];
/* ssr update intervals ------------------------------------------------------*/
static const double ssrudint[16]={
1,2,5,10,15,30,60,120,240,300,600,900,1800,3600,7200,10800
};
/* set sign-magnitude bits ---------------------------------------------------*/
static void setbitg(unsigned char *buff, int pos, int len, int value)
{
setbitu(buff,pos,1,value<0?1:0);
setbitu(buff,pos+1,len-1,value<0?-value:value);
}
/* set signed 38 bit field ---------------------------------------------------*/
static void set38bits(unsigned char *buff, int pos, double value)
{
int word_h=(int)floor(value/64.0);
unsigned int word_l=(unsigned int)(value-word_h*64.0);
setbits(buff,pos ,32,word_h);
setbitu(buff,pos+32,6,word_l);
}
/* lock time -----------------------------------------------------------------*/
static int locktime(gtime_t time, gtime_t *lltime, unsigned char LLI)
{
if (!lltime->time||(LLI&1)) *lltime=time;
return (int)timediff(time,*lltime);
}
/* glonass frequency channel number in rtcm (0-13,-1:error) ------------------*/
static int fcn_glo(int sat, rtcm_t *rtcm)
{
int prn;
if (satsys(sat,&prn)!=SYS_GLO||rtcm->nav.geph[prn-1].sat!=sat) return -1;
return rtcm->nav.geph[prn-1].frq+7;
}
/* lock time indicator (ref [2] table 3.4-2) ---------------------------------*/
static int to_lock(int lock)
{
if (lock<0 ) return 0;
if (lock<24 ) return lock;
if (lock<72 ) return (lock+24 )/2;
if (lock<168) return (lock+120 )/4;
if (lock<360) return (lock+408 )/8;
if (lock<744) return (lock+1176)/16;
if (lock<937) return (lock+3096)/32;
return 127;
}
/* msm lock time indicator (ref [11] table 3.4-1D) ---------------------------*/
static int to_msm_lock(int lock)
{
if (lock<32 ) return 0;
if (lock<64 ) return 1;
if (lock<128 ) return 2;
if (lock<256 ) return 3;
if (lock<512 ) return 4;
if (lock<1024 ) return 5;
if (lock<2048 ) return 6;
if (lock<4096 ) return 7;
if (lock<8192 ) return 8;
if (lock<16384 ) return 9;
if (lock<32768 ) return 10;
if (lock<65536 ) return 11;
if (lock<131072) return 12;
if (lock<262144) return 13;
if (lock<524288) return 14;
return 15;
}
/* msm lock time indicator with extended-resolution (ref [11] table 3.4-1E) --*/
static int to_msm_lock_ex(int lock)
{
if (lock<0 ) return 0;
if (lock<64 ) return lock;
if (lock<128 ) return (lock+64 )/2;
if (lock<256 ) return (lock+256 )/4;
if (lock<512 ) return (lock+768 )/8;
if (lock<1024 ) return (lock+2048 )/16;
if (lock<2048 ) return (lock+5120 )/32;
if (lock<4096 ) return (lock+12288 )/64;
if (lock<8192 ) return (lock+28672 )/128;
if (lock<16384 ) return (lock+65536 )/256;
if (lock<32768 ) return (lock+147456 )/512;
if (lock<65536 ) return (lock+327680 )/1024;
if (lock<131072 ) return (lock+720896 )/2048;
if (lock<262144 ) return (lock+1572864 )/4096;
if (lock<524288 ) return (lock+3407872 )/8192;
if (lock<1048576 ) return (lock+7340032 )/16384;
if (lock<2097152 ) return (lock+15728640 )/32768;
if (lock<4194304 ) return (lock+33554432 )/65536;
if (lock<8388608 ) return (lock+71303168 )/131072;
if (lock<16777216) return (lock+150994944)/262144;
if (lock<33554432) return (lock+318767104)/524288;
if (lock<67108864) return (lock+671088640)/1048576;
return 704;
}
/* L1 code indicator gps -----------------------------------------------------*/
static int to_code1_gps(unsigned char code)
{
switch (code) {
case CODE_L1C: return 0; /* L1 C/A */
case CODE_L1P:
case CODE_L1W:
case CODE_L1Y:
case CODE_L1N: return 1; /* L1 P(Y) direct */
}
return 0;
}
/* L2 code indicator gps -----------------------------------------------------*/
static int to_code2_gps(unsigned char code)
{
switch (code) {
case CODE_L2C:
case CODE_L2S:
case CODE_L2L:
case CODE_L2X: return 0; /* L2 C/A or L2C */
case CODE_L2P:
case CODE_L2Y: return 1; /* L2 P(Y) direct */
case CODE_L2D: return 2; /* L2 P(Y) cross-correlated */
case CODE_L2W:
case CODE_L2N: return 3; /* L2 correlated P/Y */
}
return 0;
}
/* L1 code indicator glonass -------------------------------------------------*/
static int to_code1_glo(unsigned char code)
{
switch (code) {
case CODE_L1C: return 0; /* L1 C/A */
case CODE_L1P: return 1; /* L1 P */
}
return 0;
}
/* L2 code indicator glonass -------------------------------------------------*/
static int to_code2_glo(unsigned char code)
{
switch (code) {
case CODE_L2C: return 0; /* L2 C/A */
case CODE_L2P: return 1; /* L2 P */
}
return 0;
}
/* carrier-phase - pseudorange in cycle --------------------------------------*/
static double cp_pr(double cp, double pr_cyc)
{
return fmod(cp-pr_cyc+1500.0,3000.0)-1500.0;
}
/* generate obs field data gps -----------------------------------------------*/
static void gen_obs_gps(rtcm_t *rtcm, const obsd_t *data, int *code1, int *pr1,
int *ppr1, int *lock1, int *amb, int *cnr1, int *code2,
int *pr21, int *ppr2, int *lock2, int *cnr2)
{
double lam1,lam2,pr1c=0.0,ppr;
int lt1,lt2;
lam1=CLIGHT/FREQ1;
lam2=CLIGHT/FREQ2;
*pr1=*amb=0;
if (ppr1) *ppr1=0xFFF80000; /* invalid values */
if (pr21) *pr21=0xFFFFE000;
if (ppr2) *ppr2=0xFFF80000;
/* L1 peudorange */
if (data->P[0]!=0.0&&data->code[0]) {
*amb=(int)floor(data->P[0]/PRUNIT_GPS);
*pr1=ROUND((data->P[0]-*amb*PRUNIT_GPS)/0.02);
pr1c=*pr1*0.02+*amb*PRUNIT_GPS;
}
/* L1 phaserange - L1 pseudorange */
if (data->P[0]!=0.0&&data->L[0]!=0.0&&data->code[0]) {
ppr=cp_pr(data->L[0],pr1c/lam1);
if (ppr1) *ppr1=ROUND(ppr*lam1/0.0005);
}
/* L2 -L1 pseudorange */
if (data->P[0]!=0.0&&data->P[1]!=0.0&&data->code[0]&&data->code[1]&&
fabs(data->P[1]-pr1c)<=163.82) {
if (pr21) *pr21=ROUND((data->P[1]-pr1c)/0.02);
}
/* L2 phaserange - L1 pseudorange */
if (data->P[0]!=0.0&&data->L[1]!=0.0&&data->code[0]&&data->code[1]) {
ppr=cp_pr(data->L[1],pr1c/lam2);
if (ppr2) *ppr2=ROUND(ppr*lam2/0.0005);
}
lt1=locktime(data->time,rtcm->lltime[data->sat-1] ,data->LLI[0]);
lt2=locktime(data->time,rtcm->lltime[data->sat-1]+1,data->LLI[1]);
if (lock1) *lock1=to_lock(lt1);
if (lock2) *lock2=to_lock(lt2);
if (cnr1 ) *cnr1=data->SNR[0];
if (cnr2 ) *cnr2=data->SNR[1];
if (code1) *code1=to_code1_gps(data->code[0]);
if (code2) *code2=to_code2_gps(data->code[1]);
}
/* generate obs field data glonass -------------------------------------------*/
static void gen_obs_glo(rtcm_t *rtcm, const obsd_t *data, int fcn, int *code1,
int *pr1, int *ppr1, int *lock1, int *amb, int *cnr1,
int *code2, int *pr21, int *ppr2, int *lock2, int *cnr2)
{
double lam1=0.0,lam2=0.0,pr1c=0.0,ppr;
int lt1,lt2;
if (fcn>=0) {
lam1=CLIGHT/(FREQ1_GLO+DFRQ1_GLO*(fcn-7));
lam2=CLIGHT/(FREQ2_GLO+DFRQ2_GLO*(fcn-7));
}
*pr1=*amb=0;
if (ppr1) *ppr1=0xFFF80000; /* invalid values */
if (pr21) *pr21=0xFFFFE000;
if (ppr2) *ppr2=0xFFF80000;
/* L1 peudorange */
if (data->P[0]!=0.0) {
*amb=(int)floor(data->P[0]/PRUNIT_GLO);
*pr1=ROUND((data->P[0]-*amb*PRUNIT_GLO)/0.02);
pr1c=*pr1*0.02+*amb*PRUNIT_GLO;
}
/* L1 phaserange - L1 pseudorange */
if (data->P[0]!=0.0&&data->L[0]!=0.0&&data->code[0]&&lam1>0.0) {
ppr=cp_pr(data->L[0],pr1c/lam1);
if (ppr1) *ppr1=ROUND(ppr*lam1/0.0005);
}
/* L2 -L1 pseudorange */
if (data->P[0]!=0.0&&data->P[1]!=0.0&&data->code[0]&&data->code[1]&&
fabs(data->P[1]-pr1c)<=163.82) {
if (pr21) *pr21=ROUND((data->P[1]-pr1c)/0.02);
}
/* L2 phaserange - L1 pseudorange */
if (data->P[0]!=0.0&&data->L[1]!=0.0&&data->code[0]&&data->code[1]&&
lam2>0.0) {
ppr=cp_pr(data->L[1],pr1c/lam2);
if (ppr2) *ppr2=ROUND(ppr*lam2/0.0005);
}
lt1=locktime(data->time,rtcm->lltime[data->sat-1] ,data->LLI[0]);
lt2=locktime(data->time,rtcm->lltime[data->sat-1]+1,data->LLI[1]);
if (lock1) *lock1=to_lock(lt1);
if (lock2) *lock2=to_lock(lt2);
if (cnr1 ) *cnr1=data->SNR[0];
if (cnr2 ) *cnr2=data->SNR[1];
if (code1) *code1=to_code1_glo(data->code[0]);
if (code2) *code2=to_code2_glo(data->code[1]);
}
/* encode rtcm header --------------------------------------------------------*/
static int encode_head(int type, rtcm_t *rtcm, int sys, int sync, int nsat)
{
double tow;
int i=24,week,epoch;
trace(4,"encode_head: type=%d sync=%d sys=%d nsat=%d\n",type,sync,sys,nsat);
setbitu(rtcm->buff,i,12,type ); i+=12; /* message no */
setbitu(rtcm->buff,i,12,rtcm->staid); i+=12; /* ref station id */
if (sys==SYS_GLO) {
tow=time2gpst(timeadd(gpst2utc(rtcm->time),10800.0),&week);
epoch=ROUND(fmod(tow,86400.0)/0.001);
setbitu(rtcm->buff,i,27,epoch); i+=27; /* glonass epoch time */
}
else {
tow=time2gpst(rtcm->time,&week);
epoch=ROUND(tow/0.001);
setbitu(rtcm->buff,i,30,epoch); i+=30; /* gps epoch time */
}
setbitu(rtcm->buff,i, 1,sync); i+= 1; /* synchronous gnss flag */
setbitu(rtcm->buff,i, 5,nsat); i+= 5; /* no of satellites */
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* smoothing indicator */
setbitu(rtcm->buff,i, 3,0 ); i+= 3; /* smoothing interval */
return i;
}
/* encode type 1001: basic L1-only gps rtk observables -----------------------*/
static int encode_type1001(rtcm_t *rtcm, int sync)
{
int i,j,nsat=0,sys,prn;
int code1,pr1,ppr1,lock1,amb;
trace(3,"encode_type1001: sync=%d\n",sync);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sys=satsys(rtcm->obs.data[j].sat,&prn);
if (!(sys&(SYS_GPS|SYS_SBS))) continue;
nsat++;
}
/* encode header */
i=encode_head(1001,rtcm,SYS_GPS,sync,nsat);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sys=satsys(rtcm->obs.data[j].sat,&prn);
if (!(sys&(SYS_GPS|SYS_SBS))) continue;
if (sys==SYS_SBS) prn-=80; /* 40-58: sbas 120-138 */
/* generate obs field data gps */
gen_obs_gps(rtcm,rtcm->obs.data+j,&code1,&pr1,&ppr1,&lock1,&amb,NULL,
NULL,NULL,NULL,NULL,NULL);
setbitu(rtcm->buff,i, 6,prn ); i+= 6;
setbitu(rtcm->buff,i, 1,code1); i+= 1;
setbitu(rtcm->buff,i,24,pr1 ); i+=24;
setbits(rtcm->buff,i,20,ppr1 ); i+=20;
setbitu(rtcm->buff,i, 7,lock1); i+= 7;
}
rtcm->nbit=i;
return 1;
}
/* encode type 1002: extended L1-only gps rtk observables --------------------*/
static int encode_type1002(rtcm_t *rtcm, int sync)
{
int i,j,nsat=0,sys,prn;
int code1,pr1,ppr1,lock1,amb,cnr1;
trace(3,"encode_type1002: sync=%d\n",sync);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sys=satsys(rtcm->obs.data[j].sat,&prn);
if (!(sys&(SYS_GPS|SYS_SBS))) continue;
nsat++;
}
/* encode header */
i=encode_head(1002,rtcm,SYS_GPS,sync,nsat);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sys=satsys(rtcm->obs.data[j].sat,&prn);
if (!(sys&(SYS_GPS|SYS_SBS))) continue;
if (sys==SYS_SBS) prn-=80; /* 40-58: sbas 120-138 */
/* generate obs field data gps */
gen_obs_gps(rtcm,rtcm->obs.data+j,&code1,&pr1,&ppr1,&lock1,&amb,&cnr1,
NULL,NULL,NULL,NULL,NULL);
setbitu(rtcm->buff,i, 6,prn ); i+= 6;
setbitu(rtcm->buff,i, 1,code1); i+= 1;
setbitu(rtcm->buff,i,24,pr1 ); i+=24;
setbits(rtcm->buff,i,20,ppr1 ); i+=20;
setbitu(rtcm->buff,i, 7,lock1); i+= 7;
setbitu(rtcm->buff,i, 8,amb ); i+= 8;
setbitu(rtcm->buff,i, 8,cnr1 ); i+= 8;
}
rtcm->nbit=i;
return 1;
}
/* encode type 1003: basic L1&L2 gps rtk observables -------------------------*/
static int encode_type1003(rtcm_t *rtcm, int sync)
{
int i,j,nsat=0,sys,prn;
int code1,pr1,ppr1,lock1,amb,code2,pr21,ppr2,lock2;
trace(3,"encode_type1003: sync=%d\n",sync);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sys=satsys(rtcm->obs.data[j].sat,&prn);
if (!(sys&(SYS_GPS|SYS_SBS))) continue;
nsat++;
}
/* encode header */
i=encode_head(1003,rtcm,SYS_GPS,sync,nsat);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sys=satsys(rtcm->obs.data[j].sat,&prn);
if (!(sys&(SYS_GPS|SYS_SBS))) continue;
if (sys==SYS_SBS) prn-=80; /* 40-58: sbas 120-138 */
/* generate obs field data gps */
gen_obs_gps(rtcm,rtcm->obs.data+j,&code1,&pr1,&ppr1,&lock1,&amb,
NULL,&code2,&pr21,&ppr2,&lock2,NULL);
setbitu(rtcm->buff,i, 6,prn ); i+= 6;
setbitu(rtcm->buff,i, 1,code1); i+= 1;
setbitu(rtcm->buff,i,24,pr1 ); i+=24;
setbits(rtcm->buff,i,20,ppr1 ); i+=20;
setbitu(rtcm->buff,i, 7,lock1); i+= 7;
setbitu(rtcm->buff,i, 2,code2); i+= 2;
setbits(rtcm->buff,i,14,pr21 ); i+=14;
setbits(rtcm->buff,i,20,ppr2 ); i+=20;
setbitu(rtcm->buff,i, 7,lock2); i+= 7;
}
rtcm->nbit=i;
return 1;
}
/* encode type 1004: extended L1&L2 gps rtk observables ----------------------*/
static int encode_type1004(rtcm_t *rtcm, int sync)
{
int i,j,nsat=0,sys,prn;
int code1,pr1,ppr1,lock1,amb,cnr1,code2,pr21,ppr2,lock2,cnr2;
trace(3,"encode_type1004: sync=%d\n",sync);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sys=satsys(rtcm->obs.data[j].sat,&prn);
if (!(sys&(SYS_GPS|SYS_SBS))) continue;
nsat++;
}
/* encode header */
i=encode_head(1004,rtcm,SYS_GPS,sync,nsat);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sys=satsys(rtcm->obs.data[j].sat,&prn);
if (!(sys&(SYS_GPS|SYS_SBS))) continue;
if (sys==SYS_SBS) prn-=80; /* 40-58: sbas 120-138 */
/* generate obs field data gps */
gen_obs_gps(rtcm,rtcm->obs.data+j,&code1,&pr1,&ppr1,&lock1,&amb,
&cnr1,&code2,&pr21,&ppr2,&lock2,&cnr2);
setbitu(rtcm->buff,i, 6,prn ); i+= 6;
setbitu(rtcm->buff,i, 1,code1); i+= 1;
setbitu(rtcm->buff,i,24,pr1 ); i+=24;
setbits(rtcm->buff,i,20,ppr1 ); i+=20;
setbitu(rtcm->buff,i, 7,lock1); i+= 7;
setbitu(rtcm->buff,i, 8,amb ); i+= 8;
setbitu(rtcm->buff,i, 8,cnr1 ); i+= 8;
setbitu(rtcm->buff,i, 2,code2); i+= 2;
setbits(rtcm->buff,i,14,pr21 ); i+=14;
setbits(rtcm->buff,i,20,ppr2 ); i+=20;
setbitu(rtcm->buff,i, 7,lock2); i+= 7;
setbitu(rtcm->buff,i, 8,cnr2 ); i+= 8;
}
rtcm->nbit=i;
return 1;
}
/* encode type 1005: stationary rtk reference station arp --------------------*/
static int encode_type1005(rtcm_t *rtcm, int sync)
{
double *p=rtcm->sta.pos;
int i=24;
trace(3,"encode_type1005: sync=%d\n",sync);
setbitu(rtcm->buff,i,12,1005 ); i+=12; /* message no */
setbitu(rtcm->buff,i,12,rtcm->staid); i+=12; /* ref station id */
setbitu(rtcm->buff,i, 6,0 ); i+= 6; /* itrf realization year */
setbitu(rtcm->buff,i, 1,1 ); i+= 1; /* gps indicator */
setbitu(rtcm->buff,i, 1,1 ); i+= 1; /* glonass indicator */
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* galileo indicator */
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* ref station indicator */
set38bits(rtcm->buff,i,p[0]/0.0001 ); i+=38; /* antenna ref point ecef-x */
setbitu(rtcm->buff,i, 1,1 ); i+= 1; /* oscillator indicator */
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* reserved */
set38bits(rtcm->buff,i,p[1]/0.0001 ); i+=38; /* antenna ref point ecef-y */
setbitu(rtcm->buff,i, 2,0 ); i+= 2; /* quarter cycle indicator */
set38bits(rtcm->buff,i,p[2]/0.0001 ); i+=38; /* antenna ref point ecef-z */
rtcm->nbit=i;
return 1;
}
/* encode type 1006: stationary rtk reference station arp with height --------*/
static int encode_type1006(rtcm_t *rtcm, int sync)
{
double *p=rtcm->sta.pos;
int i=24,hgt=0;
trace(3,"encode_type1006: sync=%d\n",sync);
if (0.0<=rtcm->sta.hgt&&rtcm->sta.hgt<=6.5535) {
hgt=ROUND(rtcm->sta.hgt/0.0001);
}
else {
trace(2,"antenna height error: h=%.4f\n",rtcm->sta.hgt);
}
setbitu(rtcm->buff,i,12,1006 ); i+=12; /* message no */
setbitu(rtcm->buff,i,12,rtcm->staid); i+=12; /* ref station id */
setbitu(rtcm->buff,i, 6,0 ); i+= 6; /* itrf realization year */
setbitu(rtcm->buff,i, 1,1 ); i+= 1; /* gps indicator */
setbitu(rtcm->buff,i, 1,1 ); i+= 1; /* glonass indicator */
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* galileo indicator */
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* ref station indicator */
set38bits(rtcm->buff,i,p[0]/0.0001 ); i+=38; /* antenna ref point ecef-x */
setbitu(rtcm->buff,i, 1,1 ); i+= 1; /* oscillator indicator */
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* reserved */
set38bits(rtcm->buff,i,p[1]/0.0001 ); i+=38; /* antenna ref point ecef-y */
setbitu(rtcm->buff,i, 2,0 ); i+= 2; /* quarter cycle indicator */
set38bits(rtcm->buff,i,p[2]/0.0001 ); i+=38; /* antenna ref point ecef-z */
setbitu(rtcm->buff,i,16,hgt ); i+=16; /* antenna height */
rtcm->nbit=i;
return 1;
}
/* encode type 1007: antenna descriptor --------------------------------------*/
static int encode_type1007(rtcm_t *rtcm, int sync)
{
int i=24,j,antsetup=rtcm->sta.antsetup;
int n=MIN(strlen(rtcm->sta.antdes),31);
trace(3,"encode_type1007: sync=%d\n",sync);
setbitu(rtcm->buff,i,12,1007 ); i+=12; /* message no */
setbitu(rtcm->buff,i,12,rtcm->staid); i+=12; /* ref station id */
/* antenna descriptor */
setbitu(rtcm->buff,i,8,n); i+=8;
for (j=0;j<n;j++) {
setbitu(rtcm->buff,i,8,rtcm->sta.antdes[j]); i+=8;
}
setbitu(rtcm->buff,i,8,antsetup); i+=8; /* antetnna setup id */
rtcm->nbit=i;
return 1;
}
/* encode type 1008: antenna descriptor & serial number ----------------------*/
static int encode_type1008(rtcm_t *rtcm, int sync)
{
int i=24,j,antsetup=rtcm->sta.antsetup;
int n=MIN(strlen(rtcm->sta.antdes),31);
int m=MIN(strlen(rtcm->sta.antsno),31);
trace(3,"encode_type1008: sync=%d\n",sync);
setbitu(rtcm->buff,i,12,1008 ); i+=12; /* message no */
setbitu(rtcm->buff,i,12,rtcm->staid); i+=12; /* ref station id */
/* antenna descriptor */
setbitu(rtcm->buff,i,8,n); i+=8;
for (j=0;j<n;j++) {
setbitu(rtcm->buff,i,8,rtcm->sta.antdes[j]); i+=8;
}
setbitu(rtcm->buff,i,8,antsetup); i+=8; /* antenna setup id */
/* antenna serial number */
setbitu(rtcm->buff,i,8,m); i+=8;
for (j=0;j<m;j++) {
setbitu(rtcm->buff,i,8,rtcm->sta.antsno[j]); i+=8;
}
rtcm->nbit=i;
return 1;
}
/* encode type 1009: basic L1-only glonass rtk observables -------------------*/
static int encode_type1009(rtcm_t *rtcm, int sync)
{
int i,j,nsat=0,sat,prn,fcn;
int code1,pr1,ppr1,lock1,amb;
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sat=rtcm->obs.data[j].sat;
if (satsys(sat,&prn)!=SYS_GLO) continue;
nsat++;
}
/* encode header */
i=encode_head(1009,rtcm,SYS_GLO,sync,nsat);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sat=rtcm->obs.data[j].sat;
if (satsys(sat,&prn)!=SYS_GLO) continue;
fcn=fcn_glo(sat,rtcm);
/* generate obs field data glonass */
gen_obs_glo(rtcm,rtcm->obs.data+j,fcn,&code1,&pr1,&ppr1,&lock1,&amb,
NULL,NULL,NULL,NULL,NULL,NULL);
if (fcn<0) fcn=0;
setbitu(rtcm->buff,i, 6,prn ); i+= 6;
setbitu(rtcm->buff,i, 1,code1); i+= 1;
setbitu(rtcm->buff,i, 5,fcn ); i+= 5;
setbitu(rtcm->buff,i,25,pr1 ); i+=25;
setbits(rtcm->buff,i,20,ppr1 ); i+=20;
setbitu(rtcm->buff,i, 7,lock1); i+= 7;
}
rtcm->nbit=i;
return 1;
}
/* encode type 1010: extended L1-only glonass rtk observables ----------------*/
static int encode_type1010(rtcm_t *rtcm, int sync)
{
int i,j,nsat=0,sat,prn,fcn;
int code1,pr1,ppr1,lock1,amb,cnr1;
trace(3,"encode_type1010: sync=%d\n",sync);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sat=rtcm->obs.data[j].sat;
if (satsys(sat,&prn)!=SYS_GLO) continue;
nsat++;
}
/* encode header */
i=encode_head(1010,rtcm,SYS_GLO,sync,nsat);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sat=rtcm->obs.data[j].sat;
if (satsys(sat,&prn)!=SYS_GLO) continue;
fcn=fcn_glo(sat,rtcm);
/* generate obs field data glonass */
gen_obs_glo(rtcm,rtcm->obs.data+j,fcn,&code1,&pr1,&ppr1,&lock1,&amb,
&cnr1,NULL,NULL,NULL,NULL,NULL);
if (fcn<0) fcn=0;
setbitu(rtcm->buff,i, 6,prn ); i+= 6;
setbitu(rtcm->buff,i, 1,code1); i+= 1;
setbitu(rtcm->buff,i, 5,fcn ); i+= 5;
setbitu(rtcm->buff,i,25,pr1 ); i+=25;
setbits(rtcm->buff,i,20,ppr1 ); i+=20;
setbitu(rtcm->buff,i, 7,lock1); i+= 7;
setbitu(rtcm->buff,i, 7,amb ); i+= 7;
setbitu(rtcm->buff,i, 8,cnr1 ); i+= 8;
}
rtcm->nbit=i;
return 1;
}
/* encode type 1011: basic L1&L2 glonass rtk observables --------------------*/
static int encode_type1011(rtcm_t *rtcm, int sync)
{
int i,j,nsat=0,sat,prn,fcn;
int code1,pr1,ppr1,lock1,amb,code2,pr21,ppr2,lock2;
trace(3,"encode_type1011: sync=%d\n",sync);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sat=rtcm->obs.data[j].sat;
if (satsys(sat,&prn)!=SYS_GLO) continue;
nsat++;
}
/* encode header */
i=encode_head(1011,rtcm,SYS_GLO,sync,nsat);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sat=rtcm->obs.data[j].sat;
if (satsys(sat,&prn)!=SYS_GLO) continue;
fcn=fcn_glo(sat,rtcm);
/* generate obs field data glonass */
gen_obs_glo(rtcm,rtcm->obs.data+j,fcn,&code1,&pr1,&ppr1,&lock1,&amb,
NULL,&code2,&pr21,&ppr2,&lock2,NULL);
if (fcn<0) fcn=0;
setbitu(rtcm->buff,i, 6,prn ); i+= 6;
setbitu(rtcm->buff,i, 1,code1); i+= 1;
setbitu(rtcm->buff,i, 5,fcn ); i+= 5;
setbitu(rtcm->buff,i,25,pr1 ); i+=25;
setbits(rtcm->buff,i,20,ppr1 ); i+=20;
setbitu(rtcm->buff,i, 7,lock1); i+= 7;
setbitu(rtcm->buff,i, 2,code2); i+= 2;
setbits(rtcm->buff,i,14,pr21 ); i+=14;
setbits(rtcm->buff,i,20,ppr2 ); i+=20;
setbitu(rtcm->buff,i, 7,lock2); i+= 7;
}
rtcm->nbit=i;
return 1;
}
/* encode type 1012: extended L1&L2 glonass rtk observables ------------------*/
static int encode_type1012(rtcm_t *rtcm, int sync)
{
int i,j,nsat=0,sat,prn,fcn;
int code1,pr1,ppr1,lock1,amb,cnr1,code2,pr21,ppr2,lock2,cnr2;
trace(3,"encode_type1012: sync=%d\n",sync);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sat=rtcm->obs.data[j].sat;
if (satsys(sat,&prn)!=SYS_GLO) continue;
nsat++;
}
/* encode header */
i=encode_head(1012,rtcm,SYS_GLO,sync,nsat);
for (j=0;j<rtcm->obs.n&&nsat<MAXOBS;j++) {
sat=rtcm->obs.data[j].sat;
if (satsys(sat,&prn)!=SYS_GLO) continue;
fcn=fcn_glo(sat,rtcm);
/* generate obs field data glonass */
gen_obs_glo(rtcm,rtcm->obs.data+j,fcn,&code1,&pr1,&ppr1,&lock1,&amb,
&cnr1,&code2,&pr21,&ppr2,&lock2,&cnr2);
if (fcn<0) fcn=0;
setbitu(rtcm->buff,i, 6,prn ); i+= 6;
setbitu(rtcm->buff,i, 1,code1); i+= 1;
setbitu(rtcm->buff,i, 5,fcn ); i+= 5;
setbitu(rtcm->buff,i,25,pr1 ); i+=25;
setbits(rtcm->buff,i,20,ppr1 ); i+=20;
setbitu(rtcm->buff,i, 7,lock1); i+= 7;
setbitu(rtcm->buff,i, 7,amb ); i+= 7;
setbitu(rtcm->buff,i, 8,cnr1 ); i+= 8;
setbitu(rtcm->buff,i, 2,code2); i+= 2;
setbits(rtcm->buff,i,14,pr21 ); i+=14;
setbits(rtcm->buff,i,20,ppr2 ); i+=20;
setbitu(rtcm->buff,i, 7,lock2); i+= 7;
setbitu(rtcm->buff,i, 8,cnr2 ); i+= 8;
}
rtcm->nbit=i;
return 1;
}
/* encode type 1019: gps ephemerides -----------------------------------------*/
static int encode_type1019(rtcm_t *rtcm, int sync)
{
eph_t *eph;
unsigned int sqrtA,e;
int i=24,prn,week,toe,toc,i0,OMG0,omg,M0,deln,idot,OMGd,crs,crc;
int cus,cuc,cis,cic,af0,af1,af2,tgd;
trace(3,"encode_type1019: sync=%d\n",sync);
if (satsys(rtcm->ephsat,&prn)!=SYS_GPS) return 0;
eph=rtcm->nav.eph+rtcm->ephsat-1;
if (eph->sat!=rtcm->ephsat) return 0;
week=eph->week%1024;
toe =ROUND(eph->toes/16.0);
toc =ROUND(time2gpst(eph->toc,NULL)/16.0);
sqrtA=ROUND_U(sqrt(eph->A)/P2_19);
e =ROUND_U(eph->e/P2_33);
i0 =ROUND(eph->i0 /P2_31/SC2RAD);
OMG0 =ROUND(eph->OMG0/P2_31/SC2RAD);
omg =ROUND(eph->omg /P2_31/SC2RAD);
M0 =ROUND(eph->M0 /P2_31/SC2RAD);
deln =ROUND(eph->deln/P2_43/SC2RAD);
idot =ROUND(eph->idot/P2_43/SC2RAD);
OMGd =ROUND(eph->OMGd/P2_43/SC2RAD);
crs =ROUND(eph->crs/P2_5 );
crc =ROUND(eph->crc/P2_5 );
cus =ROUND(eph->cus/P2_29);
cuc =ROUND(eph->cuc/P2_29);
cis =ROUND(eph->cis/P2_29);
cic =ROUND(eph->cic/P2_29);
af0 =ROUND(eph->f0 /P2_31);
af1 =ROUND(eph->f1 /P2_43);
af2 =ROUND(eph->f2 /P2_55);
tgd =ROUND(eph->tgd[0]/P2_31);
setbitu(rtcm->buff,i,12,1019 ); i+=12;
setbitu(rtcm->buff,i, 6,prn ); i+= 6;
setbitu(rtcm->buff,i,10,week ); i+=10;
setbitu(rtcm->buff,i, 4,eph->sva ); i+= 4;
setbitu(rtcm->buff,i, 2,eph->code); i+= 2;
setbits(rtcm->buff,i,14,idot ); i+=14;
setbitu(rtcm->buff,i, 8,eph->iode); i+= 8;
setbitu(rtcm->buff,i,16,toc ); i+=16;
setbits(rtcm->buff,i, 8,af2 ); i+= 8;
setbits(rtcm->buff,i,16,af1 ); i+=16;
setbits(rtcm->buff,i,22,af0 ); i+=22;
setbitu(rtcm->buff,i,10,eph->iodc); i+=10;
setbits(rtcm->buff,i,16,crs ); i+=16;
setbits(rtcm->buff,i,16,deln ); i+=16;
setbits(rtcm->buff,i,32,M0 ); i+=32;
setbits(rtcm->buff,i,16,cuc ); i+=16;
setbitu(rtcm->buff,i,32,e ); i+=32;
setbits(rtcm->buff,i,16,cus ); i+=16;
setbitu(rtcm->buff,i,32,sqrtA ); i+=32;
setbitu(rtcm->buff,i,16,toe ); i+=16;
setbits(rtcm->buff,i,16,cic ); i+=16;
setbits(rtcm->buff,i,32,OMG0 ); i+=32;
setbits(rtcm->buff,i,16,cis ); i+=16;
setbits(rtcm->buff,i,32,i0 ); i+=32;
setbits(rtcm->buff,i,16,crc ); i+=16;
setbits(rtcm->buff,i,32,omg ); i+=32;
setbits(rtcm->buff,i,24,OMGd ); i+=24;
setbits(rtcm->buff,i, 8,tgd ); i+= 8;
setbitu(rtcm->buff,i, 6,eph->svh ); i+= 6;
setbitu(rtcm->buff,i, 1,eph->flag); i+= 1;
setbitu(rtcm->buff,i, 1,eph->fit>0.0?0:1); i+=1;
rtcm->nbit=i;
return 1;
}
/* encode type 1020: glonass ephemerides -------------------------------------*/
static int encode_type1020(rtcm_t *rtcm, int sync)
{
geph_t *geph;
gtime_t time;
double ep[6];
int i=24,j,prn,tk_h,tk_m,tk_s,tb,pos[3],vel[3],acc[3],gamn,taun,dtaun;
int fcn,NT;
trace(3,"encode_type1020: sync=%d\n",sync);
if (satsys(rtcm->ephsat,&prn)!=SYS_GLO) return 0;
geph=rtcm->nav.geph+prn-1;
if (geph->sat!=rtcm->ephsat) return 0;
fcn=geph->frq+7;
/* time of frame within day (utc(su) + 3 hr) */
time=timeadd(gpst2utc(geph->tof),10800.0);
time2epoch(time,ep);
tk_h=(int)ep[3];
tk_m=(int)ep[4];
tk_s=ROUND(ep[5]/30.0);
/* # of days since jan 1 in leap year */
ep[0]=floor(ep[0]/4.0)*4.0; ep[1]=ep[2]=1.0;
ep[3]=ep[4]=ep[5]=0.0;
NT=(int)floor(timediff(time,epoch2time(ep))/86400.+1.0);
/* index of time interval within day (utc(su) + 3 hr) */
time=timeadd(gpst2utc(geph->toe),10800.0);
time2epoch(time,ep);
tb=ROUND((ep[3]*3600.0+ep[4]*60.0+ep[5])/900.0);
for (j=0;j<3;j++) {
pos[j]=ROUND(geph->pos[j]/P2_11/1E3);
vel[j]=ROUND(geph->vel[j]/P2_20/1E3);
acc[j]=ROUND(geph->acc[j]/P2_30/1E3);
}
gamn =ROUND(geph->gamn /P2_40);
taun =ROUND(geph->taun /P2_30);
dtaun=ROUND(geph->dtaun/P2_30);
setbitu(rtcm->buff,i,12,1020 ); i+=12;
setbitu(rtcm->buff,i, 6,prn ); i+= 6;
setbitu(rtcm->buff,i, 5,fcn ); i+= 5;
setbitu(rtcm->buff,i, 4,0 ); i+= 4; /* almanac health,P1 */
setbitu(rtcm->buff,i, 5,tk_h ); i+= 5;
setbitu(rtcm->buff,i, 6,tk_m ); i+= 6;
setbitu(rtcm->buff,i, 1,tk_s ); i+= 1;
setbitu(rtcm->buff,i, 1,geph->svh); i+= 1; /* Bn */
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* P2 */
setbitu(rtcm->buff,i, 7,tb ); i+= 7;
setbitg(rtcm->buff,i,24,vel[0] ); i+=24;
setbitg(rtcm->buff,i,27,pos[0] ); i+=27;
setbitg(rtcm->buff,i, 5,acc[0] ); i+= 5;
setbitg(rtcm->buff,i,24,vel[1] ); i+=24;
setbitg(rtcm->buff,i,27,pos[1] ); i+=27;
setbitg(rtcm->buff,i, 5,acc[1] ); i+= 5;
setbitg(rtcm->buff,i,24,vel[2] ); i+=24;
setbitg(rtcm->buff,i,27,pos[2] ); i+=27;
setbitg(rtcm->buff,i, 5,acc[2] ); i+= 5;
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* P3 */
setbitg(rtcm->buff,i,11,gamn ); i+=11;
setbitu(rtcm->buff,i, 3,0 ); i+= 3; /* P,ln */
setbitg(rtcm->buff,i,22,taun ); i+=22;
setbitu(rtcm->buff,i, 5,dtaun ); i+= 5;
setbitu(rtcm->buff,i, 5,geph->age); i+= 5; /* En */
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* P4 */
setbitu(rtcm->buff,i, 4,0 ); i+= 4; /* FT */
setbitu(rtcm->buff,i,11,NT ); i+=11;
setbitu(rtcm->buff,i, 2,0 ); i+= 2; /* M */
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* flag for addtional data */
setbitu(rtcm->buff,i,11,0 ); i+=11; /* NA */
setbitu(rtcm->buff,i,32,0 ); i+=32; /* tauc */
setbitu(rtcm->buff,i, 5,0 ); i+= 5; /* N4 */
setbitu(rtcm->buff,i,22,0 ); i+=22; /* taugps */
setbitu(rtcm->buff,i, 1,0 ); i+= 1; /* ln */
setbitu(rtcm->buff,i, 7,0 ); i+= 7;
rtcm->nbit=i;
return 1;
}
/* encode type 1033: receiver and antenna descriptor -------------------------*/
static int encode_type1033(rtcm_t *rtcm, int sync)
{
int i=24,j,antsetup=rtcm->sta.antsetup;
int n=MIN(strlen(rtcm->sta.antdes ),31);
int m=MIN(strlen(rtcm->sta.antsno ),31);
int I=MIN(strlen(rtcm->sta.rectype),31);
int J=MIN(strlen(rtcm->sta.recver ),31);
int K=MIN(strlen(rtcm->sta.recsno ),31);
trace(3,"encode_type1033: sync=%d\n",sync);
setbitu(rtcm->buff,i,12,1033 ); i+=12;
setbitu(rtcm->buff,i,12,rtcm->staid); i+=12;
setbitu(rtcm->buff,i,8,n); i+= 8;
for (j=0;j<n;j++) {
setbitu(rtcm->buff,i,8,rtcm->sta.antdes[j]); i+=8;
}
setbitu(rtcm->buff,i,8,antsetup); i+= 8;
setbitu(rtcm->buff,i,8,m); i+= 8;
for (j=0;j<m;j++) {
setbitu(rtcm->buff,i,8,rtcm->sta.antsno[j]); i+=8;
}
setbitu(rtcm->buff,i,8,I); i+= 8;
for (j=0;j<I;j++) {
setbitu(rtcm->buff,i,8,rtcm->sta.rectype[j]); i+=8;
}
setbitu(rtcm->buff,i,8,J); i+= 8;
for (j=0;j<J;j++) {
setbitu(rtcm->buff,i,8,rtcm->sta.recver[j]); i+=8;
}
setbitu(rtcm->buff,i,8,K); i+= 8;
for (j=0;j<K;j++) {
setbitu(rtcm->buff,i,8,rtcm->sta.recsno[j]); i+=8;
}
rtcm->nbit=i;
return 1;
}
/* encode type 1044: qzss ephemerides (ref [15]) -----------------------------*/
static int encode_type1044(rtcm_t *rtcm, int sync)
{
eph_t *eph;
unsigned int sqrtA,e;
int i=24,prn,week,toe,toc,i0,OMG0,omg,M0,deln,idot,OMGd,crs,crc;
int cus,cuc,cis,cic,af0,af1,af2,tgd;
trace(3,"encode_type1044: sync=%d\n",sync);
if (satsys(rtcm->ephsat,&prn)!=SYS_QZS) return 0;
eph=rtcm->nav.eph+rtcm->ephsat-1;
if (eph->sat!=rtcm->ephsat) return 0;
week=eph->week%1024;
toe =ROUND(eph->toes/16.0);
toc =ROUND(time2gpst(eph->toc,NULL)/16.0);
sqrtA=ROUND_U(sqrt(eph->A)/P2_19);
e =ROUND_U(eph->e/P2_33);
i0 =ROUND(eph->i0 /P2_31/SC2RAD);
OMG0 =ROUND(eph->OMG0/P2_31/SC2RAD);
omg =ROUND(eph->omg /P2_31/SC2RAD);
M0 =ROUND(eph->M0 /P2_31/SC2RAD);
deln =ROUND(eph->deln/P2_43/SC2RAD);
idot =ROUND(eph->idot/P2_43/SC2RAD);
OMGd =ROUND(eph->OMGd/P2_43/SC2RAD);
crs =ROUND(eph->crs/P2_5 );
crc =ROUND(eph->crc/P2_5 );
cus =ROUND(eph->cus/P2_29);
cuc =ROUND(eph->cuc/P2_29);
cis =ROUND(eph->cis/P2_29);
cic =ROUND(eph->cic/P2_29);
af0 =ROUND(eph->f0 /P2_31);
af1 =ROUND(eph->f1 /P2_43);
af2 =ROUND(eph->f2 /P2_55);
tgd =ROUND(eph->tgd[0]/P2_31);
setbitu(rtcm->buff,i,12,1044 ); i+=12;
setbitu(rtcm->buff,i, 4,prn-192 ); i+= 4;
setbitu(rtcm->buff,i,16,toc ); i+=16;
setbits(rtcm->buff,i, 8,af2 ); i+= 8;
setbits(rtcm->buff,i,16,af1 ); i+=16;
setbits(rtcm->buff,i,22,af0 ); i+=22;
setbitu(rtcm->buff,i, 8,eph->iode); i+= 8;
setbits(rtcm->buff,i,16,crs ); i+=16;
setbits(rtcm->buff,i,16,deln ); i+=16;
setbits(rtcm->buff,i,32,M0 ); i+=32;
setbits(rtcm->buff,i,16,cuc ); i+=16;
setbitu(rtcm->buff,i,32,e ); i+=32;
setbits(rtcm->buff,i,16,cus ); i+=16;
setbitu(rtcm->buff,i,32,sqrtA ); i+=32;
setbitu(rtcm->buff,i,16,toe ); i+=16;
setbits(rtcm->buff,i,16,cic ); i+=16;
setbits(rtcm->buff,i,32,OMG0 ); i+=32;
setbits(rtcm->buff,i,16,cis ); i+=16;
setbits(rtcm->buff,i,32,i0 ); i+=32;
setbits(rtcm->buff,i,16,crc ); i+=16;
setbits(rtcm->buff,i,32,omg ); i+=32;
setbits(rtcm->buff,i,24,OMGd ); i+=24;
setbits(rtcm->buff,i,14,idot ); i+=14;
setbitu(rtcm->buff,i, 2,eph->code); i+= 2;
setbitu(rtcm->buff,i,10,week ); i+=10;
setbitu(rtcm->buff,i, 4,eph->sva ); i+= 4;
setbitu(rtcm->buff,i, 6,eph->svh ); i+= 6;
setbits(rtcm->buff,i, 8,tgd ); i+= 8;
setbitu(rtcm->buff,i,10,eph->iodc); i+=10;
setbitu(rtcm->buff,i, 1,eph->fit==2.0?0:1); i+=1;
rtcm->nbit=i;
return 1;
}
/* encode type 1045: galileo satellite ephemerides (ref [15]) ----------------*/
static int encode_type1045(rtcm_t *rtcm, int sync)
{
eph_t *eph;