forked from tomojitakasu/RTKLIB
-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathrtkrcv.c
More file actions
1962 lines (1802 loc) · 69.8 KB
/
Copy pathrtkrcv.c
File metadata and controls
1962 lines (1802 loc) · 69.8 KB
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
/*------------------------------------------------------------------------------
* rtkrcv.c : rtk-gps/gnss receiver console ap
*
* Copyright (C) 2009-2015 by T.TAKASU, All rights reserved.
*
* notes :
* current version does not support win32 without pthread library
*
* version : $Revision:$ $Date:$
* history : 2009/12/13 1.0 new
* 2010/07/18 1.1 add option -m
* 2010/08/12 1.2 fix bug on ftp/http
* 2011/01/22 1.3 add option misc-proxyaddr,misc-fswapmargin
* 2011/08/19 1.4 fix bug on size of arg solopt arg for rtksvrstart()
* 2012/11/03 1.5 fix bug on setting output format
* 2013/06/30 1.6 add "nvs" option for inpstr*-format
* 2014/02/10 1.7 fix bug on printing obs data
* add print of status, glonass nav data
* ignore SIGHUP
* 2014/04/27 1.8 add "binex" option for inpstr*-format
* 2014/08/10 1.9 fix cpu overload with abnormal telnet shutdown
* 2014/08/26 1.10 support input format "rt17"
* change file paths of solution status and debug trace
* 2015/01/10 1.11 add line editing and command history
* separate codes for virtual console to vt.c
* 2015/05/22 1.12 fix bug on sp3 id in inpstr*-format options
* 2015/07/31 1.13 accept 4:stat for outstr1-format or outstr2-format
* add reading satellite dcb
* 2015/12/14 1.14 add option -sta for station name (#339)
* 2015/12/25 1.15 fix bug on -sta option (#339)
* 2015/01/26 1.16 support septentrio
* 2016/07/01 1.17 support CMR/CMR+
* 2016/08/20 1.18 add output of patch level with version
* 2016/09/05 1.19 support ntrip caster for output stream
* 2016/09/19 1.20 support multiple remote console connections
* add option -w
* 2017/09/01 1.21 add command ssr
*-----------------------------------------------------------------------------*/
#define _POSIX_C_SOURCE 200112L
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include "rtklib.h"
#include "vt.h"
#define PRGNAME "rtkrcv" /* program name */
#define CMDPROMPT "rtkrcv> " /* command prompt */
#define MAXCON 32 /* max number of consoles */
#define MAXARG 10 /* max number of args in a command */
#define MAXCMD 256 /* max length of a command */
#define MAXSTR 1024 /* max length of a stream */
#define OPTSDIR "." /* default config directory */
#define OPTSFILE "rtkrcv.conf" /* default config file */
#define NAVIFILE "rtkrcv.nav" /* navigation save file */
#define STATFILE "rtkrcv_%Y%m%d%h%M.stat" /* solution status file */
#define TRACEFILE "rtkrcv_%Y%m%d%h%M.trace" /* debug trace file */
#define LOGFILE "rtkrcv_%Y%m%d%h%M.log" /* Daemon log file */
#define INTKEEPALIVE 1000 /* keep alive interval (ms) */
#define ESC_CLEAR "\033[H\033[2J" /* ansi/vt100 escape: erase screen */
#define ESC_RESET "\033[0m" /* ansi/vt100: reset attribute */
#define ESC_BOLD "\033[1m" /* ansi/vt100: bold */
#define SQRT(x) ((x)<=0.0||(x)!=(x)?0.0:sqrt(x))
/* type definitions ----------------------------------------------------------*/
typedef struct { /* console type */
int state; /* state (0:stop,1:run) */
vt_t *vt; /* virtual terminal */
pthread_t thread; /* console thread */
} con_t;
/* global variables ----------------------------------------------------------*/
static rtksvr_t svr; /* rtk server struct */
static stream_t moni; /* monitor stream */
static int intflg =0; /* interrupt flag (2:shutdown) */
static char passwd[MAXSTR]="admin"; /* login password */
static int timetype =0; /* time format (0:gpst,1:utc,2:jst,3:tow) */
static int soltype =0; /* sol format (0:dms,1:deg,2:xyz,3:enu,4:pyl) */
static int solflag =2; /* sol flag (1:std+2:age/ratio/ns) */
static int strtype[]={ /* stream types */
STR_SERIAL,STR_NONE,STR_NONE,STR_NONE,STR_NONE,STR_NONE,STR_NONE,STR_NONE
};
static char strpath[8][MAXSTR]={"","","","","","","",""}; /* stream paths */
static int strfmt[]={ /* stream formats */
STRFMT_UBX,STRFMT_RTCM3,STRFMT_SP3,SOLF_LLH,SOLF_NMEA
};
static char rcvopt[3][256]={""}; /* Receiver options */
static int svrcycle =10; /* server cycle (ms) */
static int timeout =10000; /* timeout time (ms) */
static int reconnect =10000; /* reconnect interval (ms) */
static int nmeacycle =5000; /* nmea request cycle (ms) */
static int buffsize =32768; /* input buffer size (bytes) */
static int navmsgsel =0; /* navigation message select */
static char proxyaddr[256]=""; /* http/ntrip proxy */
static int nmeareq =0; /* nmea request type (0:off,1:lat/lon,2:single) */
static double nmeapos[] ={0,0,0}; /* nmea position (lat/lon/height) (deg,m) */
static char rcvcmds[3][MAXSTR]={""}; /* receiver commands files */
#ifdef RTKSHELLCMDS
static char startcmd[MAXSTR]=""; /* start command */
static char stopcmd [MAXSTR]=""; /* stop command */
#endif
static int modflgr[256] ={0}; /* modified flags of receiver options */
static int modflgs[256] ={0}; /* modified flags of system options */
static int moniport =0; /* monitor port */
static int keepalive =0; /* keep alive flag */
static int start =0; /* auto start */
static int fswapmargin =30; /* file swap margin (s) */
static char sta_name[256]=""; /* station name */
static prcopt_t prcopt; /* processing options */
static solopt_t solopt[2]={{0}}; /* solution options */
static filopt_t filopt ={""}; /* file options */
/* help text -----------------------------------------------------------------*/
static const char *usage[]={
"usage: rtkrcv [-s][-p port][-d dev][-o file][-w pwd][-r level][-t level][-sta sta]",
"options",
" -s start RTK server on program startup",
" -nc start RTK server on program startup with no console",
" -p port port number for telnet console",
" -m port port number for monitor stream",
" -d dev terminal device for console",
" -o file processing options file",
" -w pwd login password for remote console (\"\": no password)",
" -r level output solution status file (0:off,1:states,2:residuals)",
" -t level debug trace level (0:off,1-5:on)",
" -sta sta station name for receiver dcb",
" --daemon detach from the console",
" --version print the version and exit"
};
static const char *helptxt[]={
"start : start rtk server",
"stop : stop rtk server",
"restart : restart rtk sever",
"solution [cycle] : show solution",
"status [cycle] : show rtk status",
"satellite [-n] [cycle]: show satellite status",
"observ [-n] [cycle] : show observation data",
"navidata [cycle] : show navigation data",
"stream [cycle] : show stream status",
"ssr [-c] [-p] [cycle] : show ssr corrections",
"error : show error/warning messages",
"option [opt] : show option(s)",
"set opt [val] : set option",
"mark [name] [comment] : log a marker",
"mode ['g'|'s'|'f'|n] : set the processing mode",
"load [file] : load options from file",
"save [file] : save options to file",
"log [file|off] : start/stop log to file",
"help|? [path] : print help",
"exit|ctr-D : logout console (only for telnet)",
"shutdown : shutdown rtk server",
""
};
static const char *pathopts[]={ /* path options help */
"stream path formats",
"serial : port[:bit_rate[:byte[:parity(n|o|e)[:stopb[:fctr(off|on)[#port]]]]]]]",
"file : path[::T[::+offset][::xspeed]]",
"tcpsvr : :port",
"tcpcli : addr:port",
"ntripsvr : [passwd@]addr:port/mntpnt[:str]",
"ntripcli : user:passwd@addr:port/mntpnt",
"ntripcas : user:passwd@:[port]/mpoint[:srctbl]",
"ftp : user:passwd@addr/path[::T=poff,tint,off,rint]",
"http : addr/path[::T=poff,tint,off,rint]",
""
};
/* receiver options table ----------------------------------------------------*/
#define TIMOPT "0:gpst,1:utc,2:jst,3:tow"
#define CONOPT "0:dms,1:deg,2:xyz,3:enu,4:pyl"
#define FLGOPT "0:off,1:std+2:age/ratio/ns"
#define ISTOPT "0:off,1:serial,2:file,3:tcpsvr,4:tcpcli,6:ntripcli,7:ftp,8:http"
#define OSTOPT "0:off,1:serial,2:file,3:tcpsvr,4:tcpcli,5:ntripsvr,9:ntripcas,11:udpcli"
#define FMTOPT "0:rtcm2,1:rtcm3,2:oem4,4:ubx,5:swift,6:hemis,7:skytraq,8:javad,9:nvs,10:binex,11:rt17,12:sbf,14:unicore,15:rinex,16:sp3,17:clk"
#define NMEOPT "0:off,1:latlon,2:single"
#define SOLOPT "0:llh,1:xyz,2:enu,3:nmea,4:stat"
#define MSGOPT "0:all,1:rover,2:base,3:corr"
static opt_t rcvopts[]={
{"console-passwd", 2, (void *)passwd, "" },
{"console-timetype",3, (void *)&timetype, TIMOPT },
{"console-soltype", 3, (void *)&soltype, CONOPT },
{"console-solflag", 0, (void *)&solflag, FLGOPT },
{"inpstr1-type", 3, (void *)&strtype[0], ISTOPT },
{"inpstr2-type", 3, (void *)&strtype[1], ISTOPT },
{"inpstr3-type", 3, (void *)&strtype[2], ISTOPT },
{"inpstr1-path", 2, (void *)strpath [0], "" },
{"inpstr2-path", 2, (void *)strpath [1], "" },
{"inpstr3-path", 2, (void *)strpath [2], "" },
{"inpstr1-format", 3, (void *)&strfmt [0], FMTOPT },
{"inpstr2-format", 3, (void *)&strfmt [1], FMTOPT },
{"inpstr3-format", 3, (void *)&strfmt [2], FMTOPT },
{"inpstr1-rcvopt", 2, (void *)rcvopt[0], "" },
{"inpstr2-rcvopt", 2, (void *)rcvopt[1], "" },
{"inpstr3-rcvopt", 2, (void *)rcvopt[2], "" },
{"inpstr2-nmeareq", 3, (void *)&nmeareq, NMEOPT },
{"inpstr2-nmealat", 1, (void *)&nmeapos[0], "deg" },
{"inpstr2-nmealon", 1, (void *)&nmeapos[1], "deg" },
{"inpstr2-nmeahgt", 1, (void *)&nmeapos[2], "m" },
{"outstr1-type", 3, (void *)&strtype[3], OSTOPT },
{"outstr2-type", 3, (void *)&strtype[4], OSTOPT },
{"outstr1-path", 2, (void *)strpath [3], "" },
{"outstr2-path", 2, (void *)strpath [4], "" },
{"outstr1-format", 3, (void *)&strfmt [3], SOLOPT },
{"outstr2-format", 3, (void *)&strfmt [4], SOLOPT },
{"logstr1-type", 3, (void *)&strtype[5], OSTOPT },
{"logstr2-type", 3, (void *)&strtype[6], OSTOPT },
{"logstr3-type", 3, (void *)&strtype[7], OSTOPT },
{"logstr1-path", 2, (void *)strpath [5], "" },
{"logstr2-path", 2, (void *)strpath [6], "" },
{"logstr3-path", 2, (void *)strpath [7], "" },
{"misc-svrcycle", 0, (void *)&svrcycle, "ms" },
{"misc-timeout", 0, (void *)&timeout, "ms" },
{"misc-reconnect", 0, (void *)&reconnect, "ms" },
{"misc-nmeacycle", 0, (void *)&nmeacycle, "ms" },
{"misc-buffsize", 0, (void *)&buffsize, "bytes"},
{"misc-navmsgsel", 3, (void *)&navmsgsel, MSGOPT },
{"misc-proxyaddr", 2, (void *)proxyaddr, "" },
{"misc-fswapmargin",0, (void *)&fswapmargin, "s" },
#ifdef RTKSHELLCMDS
{"misc-startcmd", 2, (void *)startcmd, "" },
{"misc-stopcmd", 2, (void *)stopcmd, "" },
#endif
{"file-cmdfile1", 2, (void *)rcvcmds[0], "" },
{"file-cmdfile2", 2, (void *)rcvcmds[1], "" },
{"file-cmdfile3", 2, (void *)rcvcmds[2], "" },
{"",0,NULL,""}
};
/* print usage ---------------------------------------------------------------*/
static void printusage(void)
{
int i;
for (i=0;i<(int)(sizeof(usage)/sizeof(*usage));i++) {
fprintf(stderr,"%s\n",usage[i]);
}
exit(0);
}
/* external stop signal ------------------------------------------------------*/
static void sigshut(int sig)
{
trace(3,"sigshut: sig=%d\n",sig);
intflg=1;
}
/* discard space characters at tail ------------------------------------------*/
static void chop(char *str)
{
char *p;
for (p=str+strlen(str)-1;p>=str&&!isgraph((int)*p);p--) *p='\0';
}
/* thread to send keep alive for monitor port --------------------------------*/
static void *sendkeepalive(void *arg)
{
trace(3,"sendkeepalive: start\n");
while (keepalive) {
strwrite(&moni,(uint8_t *)"\r",1);
sleepms(INTKEEPALIVE);
}
trace(3,"sendkeepalive: stop\n");
return NULL;
}
/* open monitor port ---------------------------------------------------------*/
static int openmoni(int port)
{
pthread_t thread;
char path[64];
trace(3,"openmomi: port=%d\n",port);
sprintf(path,":%d",port);
if (!stropen(&moni,STR_TCPSVR,STR_MODE_RW,path)) return 0;
strsettimeout(&moni,timeout,reconnect);
keepalive=1;
pthread_create(&thread,NULL,sendkeepalive,NULL);
return 1;
}
/* close monitor port --------------------------------------------------------*/
static void closemoni(void)
{
trace(3,"closemoni:\n");
keepalive=0;
/* send disconnect message */
strwrite(&moni,(uint8_t *)MSG_DISCONN,strlen(MSG_DISCONN));
/* wait fin from clients */
sleepms(1000);
strclose(&moni);
}
/* confirm overwrite ---------------------------------------------------------*/
static int confwrite(vt_t *vt, const char *file)
{
FILE *fp;
char buff[MAXSTR],*p;
strcpy(buff,file);
if ((p=strstr(buff,"::"))) *p='\0'; /* omit options in path */
if (!vt->state||!(fp=fopen(buff,"r"))) return 1; /* no existing file */
fclose(fp);
vt_printf(vt,"overwrite %-16s ? (y/n): ",buff);
if (!vt_gets(vt,buff,sizeof(buff))||vt->brk) return 0;
return toupper((int)buff[0])=='Y';
}
/* login ---------------------------------------------------------------------*/
static int login(vt_t *vt)
{
char buff[256];
trace(3,"login: passwd=%s type=%d\n",passwd,vt->type);
if (!*passwd||!vt->type) return 1;
while (!(intflg&2)) {
if (!vt_printf(vt,"password: ",PRGNAME)) return 0;
vt->blind=1;
if (!vt_gets(vt,buff,sizeof(buff))||vt->brk) {
vt->blind=0;
return 0;
}
vt->blind=0;
if (!strcmp(buff,passwd)) break;
vt_printf(vt,"\ninvalid password\n");
}
return 1;
}
/* read receiver commands ----------------------------------------------------*/
static int readcmd(const char *file, char *cmd, int type)
{
FILE *fp;
char buff[MAXSTR],*p=cmd;
int i=0;
trace(3,"readcmd: file=%s\n",file);
if (!(fp=fopen(file,"r"))) return 0;
while (fgets(buff,sizeof(buff),fp)) {
if (*buff=='@') i++;
else if (i==type&&p+strlen(buff)+1<cmd+MAXRCVCMD) {
p+=sprintf(p,"%s",buff);
}
}
fclose(fp);
return 1;
}
/* Read antenna file ---------------------------------------------------------*/
static void readant(vt_t *vt, prcopt_t *opt, nav_t *nav, pcvs_t *pcvsr) {
trace(3,"readant:\n");
const pcv_t pcv0 = {0};
opt->pcvr[0] = opt->pcvr[1] = pcv0;
if (*filopt.rcvantp) {
gtime_t time = timeget();
if (readpcv(filopt.rcvantp, pcvsr)) {
for (int i = 0; i < 2; i++) {
if (!*opt->anttype[i] || !strcmp(opt->anttype[i], "*")) continue;
pcv_t *pcv = searchpcv(0, opt->anttype[i], time, pcvsr);
if (!pcv) {
vt_printf(vt, "no antenna %s in %s", opt->anttype[i], filopt.rcvantp);
continue;
}
opt->pcvr[i] = *pcv;
}
} else
vt_printf(vt, "antenna file open error %s", filopt.rcvantp);
}
if (*filopt.satantp) {
pcvs_t pcvs = {0};
if (readpcv(filopt.satantp, &pcvs)) {
gtime_t time = timeget();
#ifdef TRACE
int found[MAXSAT] = {0}, missing = 0;
#endif
for (int i = 0; i < MAXSAT; i++) {
pcv_t *pcv = searchpcv(i + 1, "", time, &pcvs);
if (!pcv) {
#ifdef TRACE
missing++;
#endif
continue;
}
nav->pcvs[i]=*pcv;
#ifdef TRACE
found[i] = 1;
#endif
}
free_pcvs(&pcvs);
#ifdef TRACE
if (missing > 0) {
// Report satellites not found.
char satlst[MAXSAT * 4] = "", *p = satlst;
for (int i = 0; i < MAXSAT; i++) {
if (!found[i]) {
char id[8];
satno2id(i + 1, id);
int len = strlen(satlst);
if (len + strlen(id) > sizeof(satlst) - 1) continue;
p += sprintf(p, " %s", id);
}
}
trace(2, "Satellites missing pcv in %s:%s\n", filopt.satantp, satlst);
}
#endif
} else
vt_printf(vt, "antenna file open error %s", filopt.satantp);
}
}
/* start rtk server ----------------------------------------------------------*/
static int startsvr(vt_t *vt)
{
static sta_t sta[MAXRCV]={{""}};
double pos[3],npos[3];
char s1[3][MAXRCVCMD]={"","",""},*cmds[]={NULL,NULL,NULL};
char s2[3][MAXRCVCMD]={"","",""},*cmds_periodic[]={NULL,NULL,NULL};
char *ropts[]={rcvopt[0],rcvopt[1],rcvopt[2]};
char *paths[]={
strpath[0],strpath[1],strpath[2],strpath[3],strpath[4],strpath[5],
strpath[6],strpath[7]
};
char errmsg[2048]="";
int i,stropt[8]={0};
trace(3,"startsvr:\n");
/* read start commands from command files */
for (i=0;i<3;i++) {
if (!*rcvcmds[i]) continue;
if (!readcmd(rcvcmds[i],s1[i],0)) {
vt_printf(vt,"no command file: %s\n",rcvcmds[i]);
}
else cmds[i]=s1[i];
if (!readcmd(rcvcmds[i],s2[i],2)) {
vt_printf(vt,"no command file: %s\n",rcvcmds[i]);
}
else cmds_periodic[i]=s2[i];
}
/* confirm overwrite */
if (vt!=NULL) {
for (i=3;i<8;i++) {
if (strtype[i]==STR_FILE&&!confwrite(vt,strpath[i])) return 0;
}
}
if (prcopt.refpos==POSOPT_RTCM) { /* rtcm */
for (i=0;i<3;i++) prcopt.rb[i]=0.0;
}
pos[0]=nmeapos[0]*D2R;
pos[1]=nmeapos[1]*D2R;
pos[2]=nmeapos[2];
pos2ecef(pos,npos);
/* read antenna file */
readant(vt,&prcopt,&svr.nav,&svr.pcvsr);
/* read dcb file */
if (*filopt.dcb) {
strcpy(sta[0].name,sta_name);
readdcb(filopt.dcb,&svr.nav,sta);
}
/* open geoid data file */
if (solopt[0].geoid>0&&!opengeoid(solopt[0].geoid,filopt.geoid)) {
trace(2,"geoid data open error: %s\n",filopt.geoid);
vt_printf(vt,"geoid data open error: %s\n",filopt.geoid);
}
for (i=0;*rcvopts[i].name;i++) modflgr[i]=0;
for (i=0;*sysopts[i].name;i++) modflgs[i]=0;
/* set stream options */
stropt[0]=timeout;
stropt[1]=reconnect;
stropt[2]=1000;
stropt[3]=buffsize;
stropt[4]=fswapmargin;
strsetopt(stropt);
/* set ftp/http directory and proxy */
strsetdir(filopt.tempdir);
strsetproxy(proxyaddr);
#ifdef RTKSHELLCMDS
/* execute start command */
int ret;
if (*startcmd&&(ret=system(startcmd))) {
trace(2,"command exec error: %s (%d)\n",startcmd,ret);
vt_printf(vt,"command exec error: %s (%d)\n",startcmd,ret);
}
#endif
solopt[0].posf=strfmt[3];
solopt[1].posf=strfmt[4];
/* start rtk server */
if (!rtksvrstart(&svr,svrcycle,buffsize,strtype,(const char **)paths,strfmt,navmsgsel,
(const char **)cmds,(const char **)cmds_periodic,(const char **)ropts,nmeacycle,nmeareq,npos,&prcopt,
solopt,&moni,errmsg)) {
trace(2,"rtk server start error (%s)\n",errmsg);
vt_printf(vt,"rtk server start error (%s)\n",errmsg);
free_pcvs(&svr.pcvsr);
return 0;
}
return 1;
}
/* stop rtk server -----------------------------------------------------------*/
static void stopsvr(vt_t *vt)
{
char s[3][MAXRCVCMD]={"","",""},*cmds[]={NULL,NULL,NULL};
int i;
trace(3,"stopsvr:\n");
if (!svr.state) return;
/* read stop commands from command files */
for (i=0;i<3;i++) {
if (!*rcvcmds[i]) continue;
if (!readcmd(rcvcmds[i],s[i],1)) {
vt_printf(vt,"no command file: %s\n",rcvcmds[i]);
}
else cmds[i]=s[i];
}
/* stop rtk server */
rtksvrstop(&svr,(const char **)cmds);
#ifdef RTKSHELLCMDS
/* execute stop command */
int ret;
if (*stopcmd&&(ret=system(stopcmd))) {
trace(2,"command exec error: %s (%d)\n",stopcmd,ret);
vt_printf(vt,"command exec error: %s (%d)\n",stopcmd,ret);
}
#endif
if (solopt[0].geoid>0) closegeoid();
free_pcvs(&svr.pcvsr);
vt_printf(vt,"stop rtk server\n");
}
/* print time ----------------------------------------------------------------*/
static void prtime(vt_t *vt, gtime_t time)
{
double tow;
int week;
char tstr[40]="";
if (timetype==1) {
time2str(gpst2utc(time),tstr,2);
}
else if (timetype==2) {
time2str(timeadd(gpst2utc(time),9*3600.0),tstr,2);
}
else if (timetype==3) {
tow=time2gpst(time,&week); snprintf(tstr,sizeof(tstr)," %04d %9.2f",week,tow);
}
else time2str(time,tstr,1);
vt_printf(vt,"%s ",tstr);
}
/* print solution ------------------------------------------------------------*/
static void prsolution(vt_t *vt, const sol_t *sol, const double *rb)
{
const char *solstr[]={"------","FIX","FLOAT","SBAS","DGPS","SINGLE","PPP",""};
double pos[3]={0},Qr[9],Qe[9]={0},dms1[3]={0},dms2[3]={0},bl[3]={0};
double enu[3]={0},pitch=0.0,yaw=0.0,len;
int i;
trace(4,"prsolution:\n");
if (sol->time.time==0||!sol->stat) return;
prtime(vt,sol->time);
vt_printf(vt,"(%-6s)",solstr[sol->stat]);
if (norm(sol->rr,3)>0.0&&norm(rb,3)>0.0) {
for (i=0;i<3;i++) bl[i]=sol->rr[i]-rb[i];
}
len=norm(bl,3);
Qr[0]=sol->qr[0];
Qr[4]=sol->qr[1];
Qr[8]=sol->qr[2];
Qr[1]=Qr[3]=sol->qr[3];
Qr[5]=Qr[7]=sol->qr[4];
Qr[2]=Qr[6]=sol->qr[5];
if (soltype==0) {
if (norm(sol->rr,3)>0.0) {
ecef2pos(sol->rr,pos);
covenu(pos,Qr,Qe);
deg2dms(pos[0]*R2D,dms1,4);
deg2dms(pos[1]*R2D,dms2,4);
if (solopt[0].height==1) pos[2]-=geoidh(pos); /* geodetic */
}
vt_printf(vt," %s:%2.0f %02.0f %07.4f",pos[0]<0?"S":"N",fabs(dms1[0]),dms1[1],dms1[2]);
vt_printf(vt," %s:%3.0f %02.0f %07.4f",pos[1]<0?"W":"E",fabs(dms2[0]),dms2[1],dms2[2]);
vt_printf(vt," H:%8.3f",pos[2]);
if (solflag&1) {
vt_printf(vt," (N:%6.3f E:%6.3f U:%6.3f)",SQRT(Qe[4]),SQRT(Qe[0]),SQRT(Qe[8]));
}
}
else if (soltype==1) {
if (norm(sol->rr,3)>0.0) {
ecef2pos(sol->rr,pos);
covenu(pos,Qr,Qe);
if (solopt[0].height==1) pos[2]-=geoidh(pos); /* geodetic */
}
vt_printf(vt," %s:%11.8f",pos[0]<0.0?"S":"N",fabs(pos[0])*R2D);
vt_printf(vt," %s:%12.8f",pos[1]<0.0?"W":"E",fabs(pos[1])*R2D);
vt_printf(vt," H:%8.3f",pos[2]);
if (solflag&1) {
vt_printf(vt," (E:%6.3f N:%6.3f U:%6.3fm)",SQRT(Qe[0]),SQRT(Qe[4]),SQRT(Qe[8]));
}
}
else if (soltype==2) {
vt_printf(vt," X:%12.3f",sol->rr[0]);
vt_printf(vt," Y:%12.3f",sol->rr[1]);
vt_printf(vt," Z:%12.3f",sol->rr[2]);
if (solflag&1) {
vt_printf(vt," (X:%6.3f Y:%6.3f Z:%6.3f)",SQRT(Qr[0]),SQRT(Qr[4]),SQRT(Qr[8]));
}
}
else if (soltype==3) {
if (len>0.0) {
ecef2pos(rb,pos);
ecef2enu(pos,bl,enu);
covenu(pos,Qr,Qe);
}
vt_printf(vt," E:%12.3f",enu[0]);
vt_printf(vt," N:%12.3f",enu[1]);
vt_printf(vt," U:%12.3f",enu[2]);
if (solflag&1) {
vt_printf(vt," (E:%6.3f N:%6.3f U:%6.3f)",SQRT(Qe[0]),SQRT(Qe[4]),SQRT(Qe[8]));
}
}
else if (soltype==4) {
if (len>0.0) {
ecef2pos(rb,pos);
ecef2enu(pos,bl,enu);
covenu(pos,Qr,Qe);
pitch=asin(enu[2]/len);
yaw=atan2(enu[0],enu[1]); if (yaw<0.0) yaw+=2.0*PI;
}
vt_printf(vt," P:%12.3f",pitch*R2D);
vt_printf(vt," Y:%12.3f",yaw*R2D);
vt_printf(vt," L:%12.3f",len);
if (solflag&1) {
vt_printf(vt," (E:%6.3f N:%6.3f U:%6.3f)",SQRT(Qe[0]),SQRT(Qe[4]),SQRT(Qe[8]));
}
}
if (solflag&2) {
vt_printf(vt," A:%4.1f R:%5.1f N:%2d",sol->age,sol->ratio,sol->ns);
}
vt_printf(vt,"\n");
}
/* print status --------------------------------------------------------------*/
static void prstatus(vt_t *vt)
{
const char *svrstate[]={"stop","run"},*type[]={"rover","base","corr"};
const char *sol[]={"-","fix","float","SBAS","DGPS","single","PPP",""};
const char *mode[]={
"single","DGPS","kinematic","static","static-start","moving-base","fixed",
"PPP-kinema","PPP-static"
};
gtime_t eventime={0};
const char *freq[]={"-","L1","L1+L2","L1+L2+E5b","L1+L2+E5b+L5","5","6","7"};
rtcm_t rtcm[3];
pthread_t thread;
int i,j,n,cycle,state,rtkstat,nsat0,nsat1,prcout,rcvcount,tmcount,timevalid,nave;
int cputime,nb[3]={0},nmsg[3][10]={{0}};
char tstr[40],tmstr[40],s[1024],*p;
double runtime,rt[3]={0},dop[4]={0},rr[3],bl1=0.0,bl2=0.0;
double azel[MAXSAT*2],pos[3],vel[3],*del;
trace(4,"prstatus:\n");
rtk_t *rtk = (rtk_t *)malloc(sizeof(rtk_t));
if (rtk == NULL) return;
rtksvrlock(&svr);
*rtk=svr.rtk;
thread=svr.thread;
cycle=svr.cycle;
state=svr.state;
rtkstat=svr.rtk.sol.stat;
nsat0=svr.obs[0][0].n;
nsat1=svr.obs[1][0].n;
rcvcount = svr.raw[0].obs.rcvcount;
tmcount = svr.raw[0].obs.tmcount;
cputime=svr.cputime;
prcout=svr.prcout;
nave=svr.nave;
for (i=0;i<3;i++) nb[i]=svr.nb[i];
for (i=0;i<3;i++) for (j=0;j<10;j++) {
nmsg[i][j]=svr.nmsg[i][j];
}
if (svr.state) {
runtime=(double)(tickget()-svr.tick)/1000.0;
rt[0]=floor(runtime/3600.0); runtime-=rt[0]*3600.0;
rt[1]=floor(runtime/60.0); rt[2]=runtime-rt[1]*60.0;
}
for (i=0;i<3;i++) rtcm[i]=svr.rtcm[i];
if (svr.raw[0].obs.data != NULL) {
timevalid = svr.raw[0].obs.data[0].timevalid;
eventime = svr.raw[0].obs.data[0].eventime;
}
time2str(eventime,tmstr,9);
rtksvrunlock(&svr);
for (i=n=0;i<MAXSAT;i++) {
if (rtk->opt.mode == PMODE_SINGLE) {
if (!rtk->ssat[i].vs) continue;
} else {
int any = 0;
for (int fi = 0; fi < NFREQ; fi++)
if (rtk->ssat[i].vsat[fi]) { any = 1; break; }
if (!any) continue;
}
azel[ n*2]=rtk->ssat[i].azel[0];
azel[1+n*2]=rtk->ssat[i].azel[1];
n++;
}
dops(n,azel,0.0,dop);
vt_printf(vt,"\n%s%-28s: %s%s\n",ESC_BOLD,"Parameter","Value",ESC_RESET);
vt_printf(vt,"%-28s: %s %s\n","rtklib version",VER_RTKLIB,PATCH_LEVEL);
vt_printf(vt,"%-28s: %lx\n","rtk server thread",(unsigned long)thread);
vt_printf(vt,"%-28s: %s\n","rtk server state",svrstate[state]);
vt_printf(vt,"%-28s: %d\n","processing cycle (ms)",cycle);
vt_printf(vt,"%-28s: %s\n","positioning mode",mode[rtk->opt.mode]);
vt_printf(vt,"%-28s: %s\n","frequencies",freq[rtk->opt.nf]);
vt_printf(vt,"%-28s: %02.0f:%02.0f:%04.1f\n","accumulated time to run",rt[0],rt[1],rt[2]);
vt_printf(vt,"%-28s: %d\n","cpu time for a cycle (ms)",cputime);
vt_printf(vt,"%-28s: %d\n","missing obs data count",prcout);
vt_printf(vt,"%-28s: %d,%d\n","bytes in input buffer",nb[0],nb[1]);
for (i=0;i<3;i++) {
sprintf(s,"# of input data %s",type[i]);
vt_printf(vt,"%-28s: obs(%d),nav(%d),gnav(%d),ion(%d),sbs(%d),pos(%d),dgps(%d),ssr(%d),err(%d)\n",
s,nmsg[i][0],nmsg[i][1],nmsg[i][6],nmsg[i][2],nmsg[i][3],
nmsg[i][4],nmsg[i][5],nmsg[i][7],nmsg[i][9]);
}
for (i=0;i<3;i++) {
p=s; *p='\0';
for (j=1;j<100;j++) {
if (rtcm[i].nmsg2[j]==0) continue;
p+=sprintf(p,"%s%d(%d)",p>s?",":"",j,rtcm[i].nmsg2[j]);
}
if (rtcm[i].nmsg2[0]>0) {
sprintf(p,"%sother2(%d)",p>s?",":"",rtcm[i].nmsg2[0]);
}
for (j=1;j<300;j++) {
if (rtcm[i].nmsg3[j]==0) continue;
p+=sprintf(p,"%s%d(%d)",p>s?",":"",j+1000,rtcm[i].nmsg3[j]);
}
for (j=300;j<399;j++) {
if (rtcm[i].nmsg3[j]==0) continue;
p+=sprintf(p,"%s%d(%d)",p>s?",":"",j+3770,rtcm[i].nmsg3[j]);
}
if (rtcm[i].nmsg3[0]>0) {
sprintf(p,"%sother3(%d)",p>s?",":"",rtcm[i].nmsg3[0]);
}
vt_printf(vt,"%-15s %-9s: %s\n","# of rtcm messages",type[i],s);
}
vt_printf(vt,"%-28s: %s\n","solution status",sol[rtkstat]);
time2str(rtk->sol.time,tstr,9);
vt_printf(vt,"%-28s: %s\n","time of receiver clock rover",rtk->sol.time.time?tstr:"-");
vt_printf(vt,"%-28s: %.3f,%.3f,%.3f,%.3f\n","time sys offset (ns)",rtk->sol.dtr[1]*1e9,
rtk->sol.dtr[2]*1e9,rtk->sol.dtr[3]*1e9,rtk->sol.dtr[4]*1e9);
vt_printf(vt,"%-28s: %.3f\n","solution interval (s)",rtk->tt);
vt_printf(vt,"%-28s: %.3f\n","age of differential (s)",rtk->sol.age);
vt_printf(vt,"%-28s: %.3f\n","ratio for ar validation",rtk->sol.ratio);
vt_printf(vt,"%-28s: %d\n","# of satellites rover",nsat0);
vt_printf(vt,"%-28s: %d\n","# of satellites base",nsat1);
vt_printf(vt,"%-28s: %d\n","# of valid satellites",rtk->sol.ns);
vt_printf(vt,"%-28s: %.1f,%.1f,%.1f,%.1f\n","GDOP/PDOP/HDOP/VDOP",dop[0],dop[1],dop[2],dop[3]);
vt_printf(vt,"%-28s: %d\n","# of real estimated states",rtk->na);
vt_printf(vt,"%-28s: %d\n","# of all estimated states",rtk->nx);
vt_printf(vt,"%-28s: %.3f,%.3f,%.3f\n","pos xyz single (m) rover",
rtk->sol.rr[0],rtk->sol.rr[1],rtk->sol.rr[2]);
if (norm(rtk->sol.rr,3)>0.0) ecef2pos(rtk->sol.rr,pos); else pos[0]=pos[1]=pos[2]=0.0;
vt_printf(vt,"%-28s: %.8f,%.8f,%.3f\n","pos llh single (deg,m) rover",
pos[0]*R2D,pos[1]*R2D,pos[2]);
ecef2enu(pos,rtk->sol.rr+3,vel);
vt_printf(vt,"%-28s: %.3f,%.3f,%.3f\n","vel enu (m/s) rover",vel[0],vel[1],vel[2]);
vt_printf(vt,"%-28s: %.3f,%.3f,%.3f\n","pos xyz float (m) rover",
rtk->x?rtk->x[0]:0,rtk->x?rtk->x[1]:0,rtk->x?rtk->x[2]:0);
vt_printf(vt,"%-28s: %.3f,%.3f,%.3f\n","pos xyz float std (m) rover",
rtk->P?SQRT(rtk->P[0]):0,rtk->P?SQRT(rtk->P[1+1*rtk->nx]):0,rtk->P?SQRT(rtk->P[2+2*rtk->nx]):0);
vt_printf(vt,"%-28s: %.3f,%.3f,%.3f\n","pos xyz fixed (m) rover",
rtk->xa?rtk->xa[0]:0,rtk->xa?rtk->xa[1]:0,rtk->xa?rtk->xa[2]:0);
vt_printf(vt,"%-28s: %.3f,%.3f,%.3f\n","pos xyz fixed std (m) rover",
rtk->Pa?SQRT(rtk->Pa[0]):0,rtk->Pa?SQRT(rtk->Pa[1+1*rtk->na]):0,rtk->Pa?SQRT(rtk->Pa[2+2*rtk->na]):0);
vt_printf(vt,"%-28s: %.3f,%.3f,%.3f\n","pos xyz (m) base",
rtk->rb[0],rtk->rb[1],rtk->rb[2]);
if (norm(rtk->rb,3)>0.0) ecef2pos(rtk->rb,pos); else pos[0]=pos[1]=pos[2]=0.0;
vt_printf(vt,"%-28s: %.8f,%.8f,%.3f\n","pos llh (deg,m) base",
pos[0]*R2D,pos[1]*R2D,pos[2]);
vt_printf(vt,"%-28s: %d\n","# of average single pos base",nave);
vt_printf(vt,"%-28s: %s\n","ant type rover",rtk->opt.pcvr[0].type);
del=rtk->opt.antdel[0];
vt_printf(vt,"%-28s: %.4f %.4f %.4f\n","ant delta rover",del[0],del[1],del[2]);
vt_printf(vt,"%-28s: %s\n","ant type base" ,rtk->opt.pcvr[1].type);
del=rtk->opt.antdel[1];
vt_printf(vt,"%-28s: %.4f %.4f %.4f\n","ant delta base",del[0],del[1],del[2]);
ecef2enu(pos,rtk->rb+3,vel);
vt_printf(vt,"%-28s: %.3f,%.3f,%.3f\n","vel enu (m/s) base",
vel[0],vel[1],vel[2]);
if (rtk->opt.mode>0&&rtk->x&&norm(rtk->x,3)>0.0) {
for (i=0;i<3;i++) rr[i]=rtk->x[i]-rtk->rb[i];
bl1=norm(rr,3);
}
if (rtk->opt.mode>0&&rtk->xa&&norm(rtk->xa,3)>0.0) {
for (i=0;i<3;i++) rr[i]=rtk->xa[i]-rtk->rb[i];
bl2=norm(rr,3);
}
vt_printf(vt,"%-28s: %.3f\n","baseline length float (m)",bl1);
vt_printf(vt,"%-28s: %.3f\n","baseline length fixed (m)",bl2);
vt_printf(vt,"%-28s: %s\n","last time mark",tmcount ? tmstr : "-");
vt_printf(vt,"%-28s: %d\n","receiver time mark count",rcvcount);
vt_printf(vt,"%-28s: %d\n","rtklib time mark count",tmcount);
free(rtk);
}
/* print satellite -----------------------------------------------------------*/
static void prsatellite(vt_t *vt, int nf)
{
double az,el;
char id[8];
int i,j,fix,frq[]={1,2,5,7,8,6};
trace(4,"prsatellite:\n");
rtk_t *rtk = (rtk_t *)malloc(sizeof(rtk_t));
if (rtk == NULL) return;
rtksvrlock(&svr);
*rtk=svr.rtk;
rtksvrunlock(&svr);
if (nf<=0||nf>NFREQ) nf=NFREQ;
vt_printf(vt,"\n%s%3s %2s %5s %4s",ESC_BOLD,"SAT","V","Az","El");
for (j=0;j<nf;j++) vt_printf(vt," L%d" ,frq[j]);
for (j=0;j<nf;j++) vt_printf(vt," Fix%d" ,frq[j]);
for (j=0;j<nf;j++) vt_printf(vt," P%dRes",frq[j]);
for (j=0;j<nf;j++) vt_printf(vt," L%dRes",frq[j]);
for (j=0;j<nf;j++) vt_printf(vt," Sl%d" ,frq[j]);
for (j=0;j<nf;j++) vt_printf(vt," Lock%d",frq[j]);
for (j=0;j<nf;j++) vt_printf(vt," Rj%d" ,frq[j]);
vt_printf(vt,"%s\n",ESC_RESET);
for (i=0;i<MAXSAT;i++) {
if (rtk->ssat[i].azel[1]<=0.0) continue;
satno2id(i+1,id);
int vsat = 0;
if (rtk->opt.mode == PMODE_SINGLE) {
vsat = rtk->ssat[i].vs;
} else {
for (int fi = 0; fi < NFREQ; fi++)
if (rtk->ssat[i].vsat[fi]) { vsat = 1; break; }
}
vt_printf(vt,"%3s %2s",id,vsat?"OK":"-");
az=rtk->ssat[i].azel[0]*R2D; if (az<0.0) az+=360.0;
el=rtk->ssat[i].azel[1]*R2D;
vt_printf(vt," %5.1f %4.1f",az,el);
for (j=0;j<nf;j++) vt_printf(vt," %2s",rtk->ssat[i].vsat[j]?"OK":"-");
for (j=0;j<nf;j++) {
fix=rtk->ssat[i].fix[j];
vt_printf(vt," %5s",fix==1?"FLOAT":(fix==2?"FIX":(fix==3?"HOLD":"-")));
}
for (j=0;j<nf;j++) vt_printf(vt,"%7.3f",rtk->ssat[i].resp[j]);
for (j=0;j<nf;j++) vt_printf(vt,"%8.4f",rtk->ssat[i].resc[j]);
for (j=0;j<nf;j++) vt_printf(vt," %4d",rtk->ssat[i].slipc[j]);
for (j=0;j<nf;j++) vt_printf(vt," %6d",rtk->ssat[i].lock [j]);
for (j=0;j<nf;j++) vt_printf(vt," %3d",rtk->ssat[i].rejc [j]);
vt_printf(vt,"\n");
}
free(rtk);
}
/* print observation data ----------------------------------------------------*/
static void probserv(vt_t *vt, int nf)
{
char tstr[40],id[8];
int i,j,n=0,frq[]={1,2,5,7,8,6,9};
trace(4,"probserv:\n");
obsd_t *obs = (obsd_t *)calloc(MAXOBS * 2, sizeof(obsd_t));
if (obs == NULL) {
trace(1, "probserv obsd_t alloc failed\n");
return;
}
rtksvrlock(&svr);
for (i=0;i<svr.obs[0][0].n&&n<MAXOBS*2;i++) {
obs[n++]=svr.obs[0][0].data[i];
}
for (i=0;i<svr.obs[1][0].n&&n<MAXOBS*2;i++) {
obs[n++]=svr.obs[1][0].data[i];
}
rtksvrunlock(&svr);
if (nf<=0||nf>NFREQ) nf=NFREQ;
vt_printf(vt,"\n%s%-22s %3s %s",ESC_BOLD," TIME(GPST)","SAT","R");
for (i=0;i<nf;i++) vt_printf(vt," P%d(m)" ,frq[i]);
for (i=0;i<nf;i++) vt_printf(vt," L%d(cyc)",frq[i]);
for (i=0;i<nf;i++) vt_printf(vt," D%d(Hz)" ,frq[i]);
for (i=0;i<nf;i++) vt_printf(vt," S%d" ,frq[i]);
vt_printf(vt," LLI%s\n",ESC_RESET);
for (i=0;i<n;i++) {
time2str(obs[i].time,tstr,2);
satno2id(obs[i].sat,id);
vt_printf(vt,"%s %3s %d",tstr,id,obs[i].rcv);
for (j=0;j<nf;j++) vt_printf(vt,"%13.3f",obs[i].P[j]);
for (j=0;j<nf;j++) vt_printf(vt,"%14.3f",obs[i].L[j]);
for (j=0;j<nf;j++) vt_printf(vt,"%8.1f" ,obs[i].D[j]);
for (j=0;j<nf;j++) vt_printf(vt,"%3.0f" ,obs[i].SNR[j]);
for (j=0;j<nf;j++) vt_printf(vt,"%2d" ,obs[i].LLI[j]);
vt_printf(vt,"\n");
}
free(obs);
}
/* print navigation data -----------------------------------------------------*/
static void prnavidata(vt_t *vt)
{
eph_t eph[MAXSAT];
geph_t geph[MAXPRNGLO];
double ion[8],utc[8];
gtime_t time;
char id[8],s1[64],s2[64],s3[64];
int i,valid;
trace(4,"prnavidata:\n");
rtksvrlock(&svr);
time=svr.rtk.sol.time;
for (i=0;i<MAXSAT;i++) eph[i]=svr.nav.eph[i];
for (i=0;i<MAXPRNGLO;i++) geph[i]=svr.nav.geph[i];
for (i=0;i<8;i++) ion[i]=svr.nav.ion_gps[i];
for (i=0;i<8;i++) utc[i]=svr.nav.utc_gps[i];
rtksvrunlock(&svr);
vt_printf(vt,"\n%s%3s %3s %3s %3s %3s %3s %3s %19s %19s %19s %3s %3s%s\n",
ESC_BOLD,"SAT","S","IOD","IOC","FRQ","A/A","SVH","Toe","Toc",
"Ttr/Tof","L2C","L2P",ESC_RESET);
for (i=0;i<MAXSAT;i++) {
int sys = satsys(i + 1, NULL);
if ((sys & (SYS_GPS | SYS_GAL | SYS_QZS | SYS_CMP) & prcopt.navsys) == 0 ||
eph[i].sat!=i+1) continue;
// Mask QZS LEX health.
valid=eph[i].toe.time!=0&&fabs(timediff(time,eph[i].toe))<=MAXDTOE &&
(sys == SYS_QZS ? (eph[i].svh & 0xfe) == 0 : eph[i].svh == 0);
satno2id(i+1,id);
if (eph[i].toe.time!=0) time2str(eph[i].toe,s1,0); else strcpy(s1,"-");
if (eph[i].toc.time!=0) time2str(eph[i].toc,s2,0); else strcpy(s2,"-");
if (eph[i].ttr.time!=0) time2str(eph[i].ttr,s3,0); else strcpy(s3,"-");
vt_printf(vt,"%3s %3s %3d %3d %3d %3d %03X %19s %19s %19s %3d %3d\n",
id,valid?"OK":"-",eph[i].iode,eph[i].iodc,0,eph[i].sva,
eph[i].svh,s1,s2,s3,eph[i].code,eph[i].flag);
}
for (i=0;i<MAXSAT;i++) {
int prn, sys = satsys(i + 1, &prn);
if ((sys & SYS_GLO & prcopt.navsys) == 0 || geph[prn - 1].sat != i + 1) continue;
valid=geph[prn-1].toe.time!=0&&fabs(timediff(time,geph[prn-1].toe))<=MAXDTOE_GLO &&
(geph[prn-1].svh & 9) == 0 && (geph[prn-1].svh & 6) != 4;
satno2id(i+1,id);
if (geph[prn-1].toe.time!=0) time2str(geph[prn-1].toe,s1,0); else strcpy(s1,"-");
if (geph[prn-1].tof.time!=0) time2str(geph[prn-1].tof,s2,0); else strcpy(s2,"-");
vt_printf(vt,"%3s %3s %3d %3d %3d %3d %02X %19s %19s %19s %3d %3d\n",
id,valid?"OK":"-",geph[prn-1].iode,0,geph[prn-1].frq,
geph[prn-1].age,geph[prn-1].svh,s1,"-",s2,0,0);
}
vt_printf(vt,"ION: %9.2E %9.2E %9.2E %9.2E %9.2E %9.2E %9.2E %9.2E\n",
ion[0],ion[1],ion[2],ion[3],ion[4],ion[5],ion[6],ion[7]);
vt_printf(vt,"UTC: %9.2E %9.2E %9.2E %9.2E LEAPS: %.0f\n",utc[0],utc[1],utc[2],
utc[3],utc[4]);
}
/* print error/warning messages ----------------------------------------------*/
static void prerror(vt_t *vt)
{
int n;
trace(4,"prerror:\n");
rtksvrlock(&svr);
if ((n=svr.rtk.neb)>0) {
svr.rtk.errbuf[n]='\0';