forked from SlightlyLoony/gpsctl
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gpsctl.c
1426 lines (1161 loc) · 65.3 KB
/
gpsctl.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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* G P S C T L
* (GPS control)
*
* A utility for querying, configuring, and using a U-Blox GPS on Linux.
*
* This program was tested ONLY on a Raspberry Pi 3B, running Jessie, with a Uputronics board that uses a
* U-Blox M8 GPS module.
*
* Created: October 18, 2017
* Author: Tom Dilatush <[email protected]>
* Github:
* License: MIT
*
* Copyright 2017 Tom Dilatush
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so.
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE A
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// TODO: make sure we free any allocated slBuffers!
// TODO: add needed printfs for verbose mode...
// TODO: troll all headers, inserting parameter names and return value comments
// these defines allow compiling on both an OS X development machine and the target Raspberry Pi. If different
// development environments or target machines are needed, these will likely need to be tweaked.
#define _XOPEN_SOURCE 700
#define _DARWIN_C_SOURCE
#define _POSIX_C_SOURCE 199309L
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
// #include <wiringPi.h>
#include <math.h>
#include "sl_return.h"
#include "sl_options.h"
#include "sl_general.h"
#include "sl_serial.h"
#include "ublox.h"
#include "cJSON.h"
typedef enum { fixQuery, versionQuery, configQuery, satelliteQuery } queryType;
typedef enum { syncNone, syncASCII, syncNMEA, syncUBX } syncType;
typedef struct { char* name; syncType type; } syncTypeRec;
static syncTypeRec syncTypeRecs[] = {
{ "ascii", syncASCII },
{ "nmea", syncNMEA },
{ "ubx", syncUBX }
};
struct clientData_slOptions {
int verbosity;
syncType syncMethod;
const char *port;
int baud;
int minBaud;
int newbaud;
bool report;
bool echo;
int nmea;
bool json;
int echoSeconds;
queryType queryType;
bool error;
int fdPort;
bool ubxSynchronized;
};
dictionary *gpsctlConf;
// Set the sync method to that specified in the argument. Returns Ok if there's no argument (and do nothing) or the
// argument was recognized; or an Error if there was an unrecognizable argument.
static slReturn setSyncMethod(const char* arg, clientData_slOptions* clientData) {
// if no argument was supplied, don't do anything at all...
if (arg == NULL) return makeOkReturn();
// otherwise, try to match the argument...
for (int i = 0; i < ARRAY_SIZE(syncTypeRecs); i++) {
if (0 == strncmp(arg, syncTypeRecs[i].name, strlen(arg))) {
clientData->syncMethod = syncTypeRecs[i].type;
return makeOkReturn();
}
}
// if we get here, we couldn't find the method, so do nothing but return a problem...
return makeErrorFmtMsgReturn(ERR_ROOT, "\"%s\" is not a recognized synchronization method", arg);
}
// NMEA baud rate synchronizer. This looks for a complete, valid NMEA sentence and then declares victory.
// Returns Ok with true if synchronized, false if timed out.
static slReturn nmeaBaudRateSynchronizer(int fdPort, int maxTimeMs, int verbosity) {
bool inLine = false;
char last[3];
int cksm = 0;
long long start = currentTimeMs();
// flush any junk we might have in the receiver buffer...
slReturn frResp = flushRx(fdPort);
if (isErrorReturn(frResp))
makeErrorMsgReturn(ERR_CAUSE(frResp), "could not flush receiver prior to synchronization");
// read characters until either we appear to be synchronized or we run out of time...
while (currentTimeMs() < start + maxTimeMs) {
slReturn rscResp = readSerialChar(fdPort, start + maxTimeMs - currentTimeMs());
if (isErrorReturn(rscResp))
return makeErrorMsgReturn(ERR_CAUSE(rscResp), "problem reading a character while synchronizing");
if (isWarningReturn(rscResp))
return makeOkInfoReturn(bool2info(false));
char c = getReturnInfoChar(rscResp);
if (inLine) {
if ((c == '\r') || (c == '\n')) {
if (last[0] == '*') {
int un = hex2int(last[1]);
if (un >= 0) {
int ln = hex2int(last[2]);
if (ln >= 0) {
int ck = (un << 4) | ln;
// correct checksum for the last three characters received...
cksm ^= last[0];
cksm ^= last[1];
cksm ^= last[2];
if (ck == cksm) {
return makeOkInfoReturn(bool2info(true));
}
}
}
}
inLine = false;
}
else {
cksm ^= c;
last[0] = last[1];
last[1] = last[2];
last[2] = c;
}
}
else if (c == '$') {
inLine = true;
cksm = 0;
}
}
return makeOkInfoReturn(bool2info(false));
}
// Attempt to synchronize, using the given method at the current host baud rate. On an Ok response, returns true
// or false for synchronization success as a bool in additional info.
static slReturn syncSerial(const syncType type, clientData_slOptions* clientData) {
// we're going to allow 250 character times, or 1.5 seconds, whichever is greater...
speedInfo si;
slReturn gsiResp = getSpeedInfo(clientData->fdPort, &si);
if (isErrorReturn(gsiResp))
return makeErrorMsgReturn(ERR_CAUSE(gsiResp), "problem getting speed information");
int maxMs = (int) max_ll(1500, si.nsChar * 250 / 1000000);
switch (type) {
case syncNMEA: return nmeaBaudRateSynchronizer(clientData->fdPort, maxMs, clientData->verbosity);
case syncASCII: return asciiBaudRateSynchronizer(clientData->fdPort, maxMs, clientData->verbosity);
case syncUBX:
if (clientData->ubxSynchronized) return makeOkInfoReturn(bool2info(true));
slReturn ubsxResp = ubxSynchronizer(clientData->fdPort, maxMs, clientData->verbosity);
if (isErrorReturn(ubsxResp)) return ubsxResp;
if (getReturnInfoBool(ubsxResp)) clientData->ubxSynchronized = true;
return ubsxResp;
default: return makeErrorFmtMsgReturn(ERR_ROOT, "unknown synchronization type: %d", type);
}
}
// Outputs a fix query, in English or JSON.
static slReturn doFixQuery(const clientData_slOptions* clientData) {
ubxFix fix = {0}; // zeroes all elements...
slReturn result = ubxGetFix(clientData->fdPort, clientData->verbosity, &fix);
double msl_height_feet = 0.00328084 * fix.height_above_sea_level_mm;
double height_accuracy_feet = 0.00328084 * fix.height_accuracy_mm;
double horizontal_accuracy_feet = 0.00328084 * fix.horizontal_accuracy_mm;
double speed_mph = fix.ground_speed_mm_s * 0.00223694;
double speed_accuracy_mph = fix.ground_speed_accuracy_mm_s * 0.00223694;
if (isErrorReturn(result))
return makeErrorMsgReturn(ERR_CAUSE(result), "Problem obtaining fix from GPS");
if (clientData->json) {
cJSON* root = cJSON_CreateObject();
cJSON* objFix = cJSON_CreateObject();
cJSON* time = cJSON_CreateObject();
cJSON_AddItemToObject(root, "fix", objFix);
cJSON_AddNumberToObject(objFix, "latitude_deg", fix.latitude_deg);
cJSON_AddNumberToObject(objFix, "longitude_deg", fix.longitude_deg);
cJSON_AddNumberToObject(objFix, "height_above_ellipsoid_mm", fix.height_above_ellipsoid_mm);
cJSON_AddNumberToObject(objFix, "height_above_mean_sea_level_mm", fix.height_above_sea_level_mm);
cJSON_AddNumberToObject(objFix, "horizontal_accuracy_mm", fix.horizontal_accuracy_mm);
cJSON_AddNumberToObject(objFix, "height_accuracy_mm", fix.height_accuracy_mm);
cJSON_AddNumberToObject(objFix, "ground_speed_mm_sec", fix.ground_speed_mm_s);
cJSON_AddNumberToObject(objFix, "ground_speed_accuracy_mm_sec", fix.ground_speed_accuracy_mm_s);
cJSON_AddNumberToObject(objFix, "heading_deg", fix.heading_deg);
cJSON_AddNumberToObject(objFix, "heading_accuracy_deg", fix.heading_accuracy_deg);
cJSON_AddBoolToObject(objFix, "valid", fix.fix_valid);
cJSON_AddBoolToObject(objFix, "3d", fix.fix_is_3d);
cJSON_AddNumberToObject(root, "number_of_satellites_used", fix.number_of_satellites_used);
cJSON_AddItemToObject(root, "time", time);
cJSON_AddNumberToObject(time, "year", fix.year);
cJSON_AddNumberToObject(time, "month", fix.month);
cJSON_AddNumberToObject(time, "day", fix.day);
cJSON_AddNumberToObject(time, "hour", fix.hour);
cJSON_AddNumberToObject(time, "minute", fix.minute);
cJSON_AddNumberToObject(time, "second", fix.second);
cJSON_AddNumberToObject(time, "accuracy_ns", fix.time_accuracy_ns);
cJSON_AddBoolToObject(time, "valid", fix.time_valid);
cJSON_AddBoolToObject(time, "resolved", fix.time_resolved);
char *jsonStr = cJSON_PrintUnformatted(root);
printf("%s\n", jsonStr);
cJSON_Delete(root);
}
else {
if (fix.time_resolved && fix.time_valid && fix.date_valid)
printf(" Time (UTC): %04d-%02d-%02d %02d:%02d:%02.0f (yyyy-mm-dd hh:mm:ss)\n",
fix.year, fix.month, fix.day, fix.hour, fix.minute, fix.second);
else
printf(" Time (UTC): not resolved or not valid\n");
if (fix.fix_valid) {
printf(" Latitude: %12.8f %c\n", fabs(fix.latitude_deg), (fix.latitude_deg < 0) ? 'S' : 'N');
printf(" Longitude: %12.8f %c\n", fabs(fix.longitude_deg), (fix.longitude_deg < 0) ? 'W' : 'E');
if (fix.fix_is_3d)
printf(" Altitude: %.3f feet\n", msl_height_feet);
else
printf(" Altitude: unknown\n");
printf(" Motion: %.3f mph at %.3f degrees heading\n", speed_mph, fix.heading_deg);
}
else
printf(" Fix: invalid\n");
printf(" Satellites: %d used for computing this fix\n", fix.number_of_satellites_used);
printf(" Accuracy: time (%d ns), height (+/-%.3f feet), position (+/-%.3f feet), heading(+/-%.3f degrees), speed(+/-%.3f mph)\n",
fix.time_accuracy_ns, height_accuracy_feet, horizontal_accuracy_feet, fix.heading_accuracy_deg, speed_accuracy_mph);
}
return makeOkReturn();
}
// Outputs a version query, in English or JSON.
static slReturn doVersionQuery(const clientData_slOptions* clientData) {
ubxVersion version = {0}; // zeroes all elements...
slReturn result = ubxGetVersion(clientData->fdPort, clientData->verbosity, &version);
if (isErrorReturn(result))
return makeErrorMsgReturn(ERR_CAUSE(result), "Problem obtaining version information from GPS");
if (clientData->json) {
cJSON *root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "software_version", cJSON_CreateString(version.software));
cJSON_AddItemToObject(root, "hardware_version", cJSON_CreateString(version.hardware));
cJSON_AddItemToObject(root, "extensions",
cJSON_CreateStringArray((const char**) version.extensions, version.number_of_extensions));
char *jsonStr = cJSON_PrintUnformatted(root);
printf("%s\n", jsonStr);
cJSON_Delete(root);
}
else {
printf("Software version: %s\n", version.software);
free(version.software);
printf("Hardware version: %s\n", version.hardware);
free(version.hardware);
char **ptr = version.extensions;
while ((*ptr) != NULL) {
printf(" Extension: %s\n", *ptr);
free((*ptr));
ptr++;
}
}
return makeOkReturn();
}
// comparison function for satellite search...
int cmpSatellite(const void* a, const void* b) {
ubxSatellite* c = (ubxSatellite*) a;
ubxSatellite* d = (ubxSatellite*) b;
if (c->used && !d->used) return -1;
if (d->used && !c->used) return 1;
return d->cno - c->cno;
}
// Outputs a satellite query, in English or JSON.
static slReturn doSatelliteQuery(const clientData_slOptions* clientData) {
// get the satellite data from the GPS...
ubxSatellites satellites = {0}; // zeroes all elements...
slReturn ugsResp = ubxGetSatellites(clientData->fdPort, clientData->verbosity, &satellites);
if (isErrorReturn(ugsResp))
return makeErrorMsgReturn(ERR_CAUSE(ugsResp), "Problem obtaining satellites information from GPS");
// sort the result by used or not, then in descending order of CNo...
qsort(satellites.satellites, (unsigned) satellites.numberOfSatellites, sizeof(ubxSatellite), cmpSatellite);
if (clientData->json) {
cJSON* root = cJSON_CreateObject();
cJSON* sats = cJSON_CreateArray();
cJSON_AddNumberToObject(root, "number_of_satellites", satellites.numberOfSatellites);
cJSON_AddItemToObject(root, "satellites", sats);
for (int i = 0; i < satellites.numberOfSatellites; i++) {
ubxSatellite* s = satellites.satellites + i;
cJSON* sat = cJSON_CreateObject();
cJSON_AddItemToArray(sats, sat);
cJSON_AddStringToObject(sat, "gnssID", getGnssName(s->gnssID));
cJSON_AddNumberToObject(sat, "satelliteID", s->satelliteID);
cJSON_AddNumberToObject(sat, "CNo", s->cno);
cJSON_AddNumberToObject(sat, "elevation", s->elevation);
cJSON_AddNumberToObject(sat, "azimuth", s->azimuth);
cJSON_AddNumberToObject(sat, "pseudoRangeResidual_meters", s->pseudoRangeResidualM);
cJSON_AddStringToObject(sat, "signalQuality", getSignalQuality(s->signalQuality));
cJSON_AddBoolToObject(sat, "used", s->used);
cJSON_AddStringToObject(sat, "satelliteHealth", getSatelliteHealth(s->health));
cJSON_AddBoolToObject(sat, "diffCorr", s->diffCorr);
cJSON_AddBoolToObject(sat, "smoothed", s->smoothed);
cJSON_AddStringToObject(sat, "orbitSource", getOrbitSource(s->orbitSource));
cJSON_AddBoolToObject(sat, "haveEphemeris", s->haveEphemeris);
cJSON_AddBoolToObject(sat, "haveAlmanac", s->haveAlmanac);
cJSON_AddBoolToObject(sat, "haveAssistNowOff", s->haveAssistNowOff);
cJSON_AddBoolToObject(sat, "haveAssistNowAuto", s->haveAssistNowAuto);
cJSON_AddBoolToObject(sat, "sbasCorrUsed", s->sbasCorrUsed);
cJSON_AddBoolToObject(sat, "rtcmCorrUsed", s->rtcmCorrUsed);
cJSON_AddBoolToObject(sat, "prCorrUsed", s->prCorrUsed);
cJSON_AddBoolToObject(sat, "crCorrUsed", s->crCorrUsed);
cJSON_AddBoolToObject(sat, "doCorrUsed", s->doCorrUsed);
}
char *jsonStr = cJSON_PrintUnformatted(root);
printf("%s\n", jsonStr);
cJSON_Delete(root);
}
else {
// print out our column headers...
printf("\n%-8s%3s %3s %3s %3s %5s %-20s%-8s%-15sFlags\n", "GNSS", "ID", "CNo", "El", "Azi", "PRr", "Signal qual", "Sat Hlt", "Orbit Src");
printf("%-8s%3s %3s %3s %3s %5s %-20s%-8s%-15s=====\n", "=======", "===", "===", "===", "===", "=====", "===================", "=======", "==============");
// now print out all our satellites...
for (int i = 0; i < satellites.numberOfSatellites; i++) {
// build up our flags string...
ubxSatellite* s = satellites.satellites + i;
char* flags = NULL;
if (s->used) append(&flags, "u");
if (s->diffCorr) append(&flags, "d");
if (s->smoothed) append(&flags, "s");
if (s->haveEphemeris) append(&flags, "e");
if (s->haveAlmanac) append(&flags, "a");
if (s->sbasCorrUsed) append(&flags, "S");
if (s->rtcmCorrUsed) append(&flags, "R");
if (s->prCorrUsed) append(&flags, "P");
if (s->crCorrUsed) append(&flags, "C");
if (s->doCorrUsed) append(&flags, "D");
if (flags == NULL) append(&flags, "");
// print our satellite line...
printf("%-8s%3d %3d %3d %3d %5.1f %-20s%-8s%-15s%s\n",
getGnssName(s->gnssID), s->satelliteID, s->cno, s->elevation, s->azimuth, s->pseudoRangeResidualM,
getSignalQuality(s->signalQuality), getSatelliteHealth(s->health), getOrbitSource(s->orbitSource), flags);
free(flags);
}
printf("\nFlags:\n"
" u - used for navigation fix\n"
" d - differential correction is available\n"
" s - carrier-smoothed pseudorange used\n"
" e - ephemeris is available\n"
" a - almanac is available\n"
" S - SBAS corrections used\n"
" R - RTCM corrections used\n"
" P - pseudorange corrections used\n"
" C - carrier range corrections used\n"
" D - range rate (Doppler) corrections used\n"
);
}
// free up the memory we allocated...
free(satellites.satellites);
return makeOkReturn();
}
// Outputs a configuration query, in English or JSON.
static slReturn doConfigQuery(const clientData_slOptions* clientData) {
ubxConfig config = {}; // zeroes all elements...
slReturn result = ubxGetConfig(clientData->fdPort, clientData->verbosity, &config);
if (isErrorReturn(result))
return makeErrorMsgReturn(ERR_CAUSE(result), "Problem obtaining configuration information from GPS");
if (clientData->json) {
cJSON* root = cJSON_CreateObject();
cJSON* ant = cJSON_CreateObject();
cJSON* gnss = cJSON_CreateObject();
cJSON* gnssRecs = cJSON_CreateArray();
cJSON* nav = cJSON_CreateObject();
cJSON* time = cJSON_CreateObject();
cJSON* rate = cJSON_CreateObject();
cJSON* pwr = cJSON_CreateObject();
cJSON* nmea = cJSON_CreateObject();
cJSON_AddItemToObject(root, "antenna", ant);
cJSON_AddItemToObject(root, "GNSS", gnss);
cJSON_AddItemToObject(gnss, "GNSS_records", gnssRecs);
cJSON_AddItemToObject(root, "navigation", nav);
cJSON_AddItemToObject(root, "time_pulse", time);
cJSON_AddItemToObject(root, "fix_rate", rate);
cJSON_AddItemToObject(root, "power_mode", pwr);
cJSON_AddItemToObject(root, "nmea", nmea);
cJSON_AddBoolToObject(ant, "power_on", config.antPwr);
cJSON_AddBoolToObject(ant, "short_detection", config.antShrtDet);
cJSON_AddBoolToObject(ant, "open_detection", config.antOpenDet);
cJSON_AddBoolToObject(ant, "power_down_on_short", config.antPwrDwnOnShrt);
cJSON_AddBoolToObject(ant, "auto_recover_from_short", config.antAutoRec);
cJSON_AddNumberToObject(gnss, "number_of_tracking_channels", config.trkChnnls);
for (int i = 0; i < config.gnssRecs; i++) {
cJSON* gnssRec = cJSON_CreateObject();
cJSON_AddStringToObject(gnssRec, "name", getGnssName(config.gnss[i].id));
cJSON_AddBoolToObject(gnssRec, "enabled", config.gnss[i].enabled);
cJSON_AddNumberToObject(gnssRec, "min_channels", config.gnss[i].minChnnls);
cJSON_AddNumberToObject(gnssRec, "max_channels", config.gnss[i].maxChnnls);
cJSON_AddItemToArray(gnssRecs, gnssRec);
}
cJSON_AddStringToObject(nav, "dynamic_model", getDynamicModelName(config.model));
cJSON_AddStringToObject(nav, "fix_mode", getFixModeName(config.mode));
cJSON_AddNumberToObject(nav, "fixed_altitude_2D_meters", config.fixedAltM);
cJSON_AddNumberToObject(nav, "fixed_altitude_2D_variance_m2", config.fixedAltVarM2);
cJSON_AddNumberToObject(nav, "min_elevation", config.minElevDeg);
cJSON_AddNumberToObject(nav, "position_dop_mask", config.pDoP);
cJSON_AddNumberToObject(nav, "time_dop_mask", config.tDoP);
cJSON_AddNumberToObject(nav, "position_accuracy_mask", config.pAccM);
cJSON_AddNumberToObject(nav, "time_accuracy_mask", config.tAccM);
cJSON_AddNumberToObject(nav, "static_hold_threshold_cms", config.staticHoldThreshCmS);
cJSON_AddNumberToObject(nav, "dgnss_timeout_secs", config.dgnssTimeoutS);
cJSON_AddNumberToObject(nav, "threshold_satellites_above_cno", config.cnoThreshNumSVs);
cJSON_AddNumberToObject(nav, "cno_threshold_dbhz", config.cnoThreshDbHz);
cJSON_AddNumberToObject(nav, "static_hold_max_distance_meters", config.staticHoldMaxDistM);
cJSON_AddStringToObject(nav, "utc_standard", getUTCTypeName(config.utcStandard));
cJSON_AddBoolToObject(time, "enabled", config.timePulse0Enabled);
cJSON_AddBoolToObject(time, "is_freq", config.isFreq);
cJSON_AddBoolToObject(time, "is_length", config.isLength);
cJSON_AddBoolToObject(time, "lock_on_gps_freq", config.lockGpsFreq);
cJSON_AddBoolToObject(time, "locked_other_set", config.lockedOtherSet);
cJSON_AddBoolToObject(time, "align_to_top_of_second", config.alignToTow);
cJSON_AddBoolToObject(time, "polarity_rising_edge", config.polarity);
cJSON_AddStringToObject(time, "time_grid", getTimeGridTypeName(config.gridUtcTnss));
cJSON_AddNumberToObject(time, "antenna_cable_delay_ns", config.antCableDelayNs);
cJSON_AddNumberToObject(time, "rf_group_delay_ns", config.rfGroupDelayNs);
cJSON_AddNumberToObject(time, "user_configured_delay_ns", config.userConfigDelay);
cJSON_AddNumberToObject(time, "freq_period_lock", config.freqPeriodLock * (config.isFreq ? 1 : 0.000001));
cJSON_AddNumberToObject(time, "freq_period", config.freqPeriod * (config.isFreq ? 1 : 0.000001));
cJSON_AddNumberToObject(time, "pulse_length_ratio_lock", config.pulseLenRatioLock * (config.isLength ? 0.000001 : 0.000000023283064));
cJSON_AddNumberToObject(time, "pulse_length_ratio", config.pulseLenRatio * (config.isLength ? 0.000001 : 0.000000023283064));
cJSON_AddNumberToObject(rate, "measurement_rate_ms", config.measRateMs);
cJSON_AddNumberToObject(rate, "measurements_per_fix", config.navRate);
cJSON_AddStringToObject(rate, "time_reference", getFixTimeRefName(config.timeRef));
cJSON_AddStringToObject(pwr, "power_setup", getPowerModeName(config.powerSetup));
cJSON_AddNumberToObject(pwr, "period_secs_for_interval", config.powerIntervalSecs);
cJSON_AddNumberToObject(pwr, "on_time_secs_for_interval", config.powerOnTimeSecs);
cJSON_AddBoolToObject(nmea, "enabled", config.nmeaEnabled);
cJSON_AddNumberToObject(nmea, "version", (config.nmeaVersion / 16) + (config.nmeaVersion % 16) * 0.1);
cJSON_AddBoolToObject(nmea, "GGA", config.GGA);
cJSON_AddBoolToObject(nmea, "GLL", config.GLL);
cJSON_AddBoolToObject(nmea, "GSA", config.GSA);
cJSON_AddBoolToObject(nmea, "GSV", config.GSV);
cJSON_AddBoolToObject(nmea, "RMC", config.RMC);
cJSON_AddBoolToObject(nmea, "VTG", config.VTG);
cJSON_AddBoolToObject(nmea, "GRS", config.GRS);
cJSON_AddBoolToObject(nmea, "GST", config.GST);
cJSON_AddBoolToObject(nmea, "ZDA", config.ZDA);
char *jsonStr = cJSON_PrintUnformatted(root);
printf("%s\n", jsonStr);
cJSON_Delete(root);
}
else {
printf("U-Blox GPS configuration\n");
printf(" Antenna:\n");
printf(" Power enabled: %s\n", yesNo(config.antPwr));
printf(" Short detection: %s\n", yesNo(config.antShrtDet));
printf(" Open detection: %s\n", yesNo(config.antOpenDet));
printf(" Power down on short: %s\n", yesNo(config.antPwrDwnOnShrt));
printf(" Auto recovery from short: %s\n", yesNo(config.antAutoRec));
printf(" GNSS:\n");
printf(" Tracking channels: %d\n", config.trkChnnls);
for (int i = 0; i < config.gnssRecs; i++) {
printf(" Type: %s\n", getGnssName(config.gnss[i].id));
printf(" Enabled: %s\n", yesNo(config.gnss[i].enabled));
printf(" Minimum channels: %d\n", config.gnss[i].minChnnls);
printf(" Maximum channels: %d\n", config.gnss[i].maxChnnls);
}
printf(" Navigation engine:\n");
printf(" Dynamic model: %s\n", getDynamicModelName(config.model));
printf(" Fix mode: %s\n", getFixModeName(config.mode));
printf(" Fixed altitude (2D): %.2f meters\n", config.fixedAltM);
printf(" Fixed altitude variance (2D): %.4f meters^2\n", config.fixedAltVarM2);
printf(" Minimum elevation: %d degrees\n", config.minElevDeg);
printf(" Position DoP mask: %.1f\n", config.pDoP);
printf(" Time DoP mask: %.1f\n", config.tDoP);
printf(" Position accuracy mask: %d meters\n", config.pAccM);
printf(" Time accuracy mask: %d meters\n", config.tAccM);
printf(" Static hold threshold: %d cm/s\n", config.staticHoldThreshCmS);
printf(" Dynamic GNSS timeout: %d seconds\n", config.dgnssTimeoutS);
printf(" Threshold above C/No: %d satellites\n", config.cnoThreshNumSVs);
printf(" C/No threshold: %d dBHz\n", config.cnoThreshDbHz);
printf(" Static hold max distance: %d meters\n", config.staticHoldMaxDistM);
printf(" UTC standard: %s\n", getUTCTypeName(config.utcStandard));
printf(" Time pulse:\n");
printf(" Time pulse 0 enabled: %s\n", yesNo(config.timePulse0Enabled));
printf(" Use frequency vs. period: %s\n", yesNo(config.isFreq));
printf(" Use length vs. duty cycle: %s\n", yesNo(config.isLength));
printf(" Lock on GPS frequency: %s\n", yesNo(config.lockGpsFreq));
printf(" Lock use other set: %s\n", yesNo(config.lockedOtherSet));
printf(" Align to top of second: %s\n", yesNo(config.alignToTow));
printf(" Polarity rising edge: %s\n", yesNo(config.polarity));
printf(" Time grid: %s\n", getTimeGridTypeName(config.gridUtcTnss));
printf(" Antenna cable delay: %d nanoseconds\n", config.antCableDelayNs);
printf(" RF group delay: %d nanoseconds\n", config.rfGroupDelayNs);
if (config.isFreq) {
printf(" Locked pulse frequency: %d Hz\n", config.freqPeriodLock);
printf(" Unlocked pulse frequency: %d Hz\n", config.freqPeriod);
} else {
printf(" Locked pulse period: %d microseconds\n", config.freqPeriodLock);
printf(" Unlocked pulse period: %d microseconds\n", config.freqPeriod);
}
if (config.isLength) {
printf(" Locked pulse length: %d microseconds\n", config.pulseLenRatioLock);
printf(" Unlocked pulse length: %d microseconds\n", config.pulseLenRatio);
} else {
printf(" Locked pulse duty cycle: %.2f%%\n", config.pulseLenRatioLock * 0.000000023283064);
printf(" Unlocked pulse duty cycle: %.2f%%\n", config.pulseLenRatio * 0.000000023283064);
}
printf(" User configurable delay: %d nanoseconds\n", config.userConfigDelay);
printf(" Fix rate:\n");
printf(" Measurement rate: %d milliseconds\n", config.measRateMs);
printf(" Measurements per fix: %d\n", config.navRate);
printf(" Time reference: %s\n", getFixTimeRefName(config.timeRef));
printf(" Power mode:\n");
printf(" Power setup: %s\n", getPowerModeName(config.powerSetup));
printf(" Period (if interval): %d seconds\n", config.powerIntervalSecs);
printf(" On time (if interval): %d seconds\n", config.powerOnTimeSecs);
printf(" NMEA:\n");
printf(" Enabled: %s\n", yesNo(config.nmeaEnabled));
printf(" Version: %01x.%01x\n", config.nmeaVersion / 16, config.nmeaVersion % 16);
printf(" GGA: %s\n", onOff(config.GGA));
printf(" GLL: %s\n", onOff(config.GLL));
printf(" GSA: %s\n", onOff(config.GSA));
printf(" GSV: %s\n", onOff(config.GSV));
printf(" RMC: %s\n", onOff(config.RMC));
printf(" VTG: %s\n", onOff(config.VTG));
printf(" GRS: %s\n", onOff(config.GRS));
printf(" GST: %s\n", onOff(config.GST));
printf(" ZDA: %s\n", onOff(config.ZDA));
}
return makeOkReturn();
}
static slReturn parseMsgHelper(errorInfo_slReturn error, const optionDef_slOptions* def, char *pattern, ...) {
char* resolved;
// first resolve the pattern we were given...
va_list args;
va_start(args, pattern);
vasprintf(&resolved, pattern, args);
va_end(args);
// return our bad news...
slReturn result = makeErrorFmtMsgReturn(error, "option parsing problem: [%s] %s", getName_slOptions(def), resolved);
free(resolved);
return result;
}
// Test the argument to see if it represents a valid serial port. On failure, return an error.
static slReturn parsePort(void* ptrArg, int intArg, const optionDef_slOptions *def, const char *arg, clientData_slOptions *clientData) {
slReturn vsd = verifySerialDevice(arg);
clientData->port = arg;
if (isErrorReturn(vsd))
return makeErrorFmtMsgReturn(ERR_CAUSE(vsd), "device \"%s\" is not a terminal", arg);
// stuff it away to the given pointer...
return makeOkReturn();
}
// Parse the given argument, which is presumed to be a string representing a positive integer that is one of the
// standard baud rates. If the parsing fails for any reason, return an error
static slReturn parseBaud(void* ptrArg, int intArg, const optionDef_slOptions* def, const char* arg, clientData_slOptions* clientData) {
// make sure we can parse the entire argument into an integer...
char *endPtr;
int baud = (int) strtol(arg, &endPtr, 10);
if (*endPtr != 0)
return parseMsgHelper(ERR_ROOT, def, "the specified baud rate (\"%s\") is not an integer", arg);
// make sure the result is a valid baud rate...
if (getBaudRateCookie(baud) < 0)
return parseMsgHelper(ERR_ROOT, def, "the specified baud rate (\"%s\") is not a valid one (4800, 9600, 19200, etc.)", arg);
// we have a valid baud rate, so stuff it away and return in victory...
*((int*)ptrArg) = baud;
return makeOkReturn();
}
// Parse autobaud or sync, which have an optional argument of ascii, nmea, or ubx.
static slReturn parseSyncMethod(void* ptrArg, int intArg, const optionDef_slOptions* def, const char* arg, clientData_slOptions* clientData) {
// set up the sync method...
slReturn ssmResp = setSyncMethod(arg, clientData);
if (isErrorReturn(ssmResp))
return parseMsgHelper(ERR_CAUSE(ssmResp), def, "the specified baud rate inference method (\"%s\") is unrecognizable; should be \"ascii\", \"nmea\", or \"ubx\"", arg);
return makeOkReturn();
}
// Parse the given argument, which is presumed to be a string representing a yes or no value, which if parsed without
// error is stored to the argPtr. If the parsing fails for any reason, return an error.
static slReturn parseBool(void* ptrArg, int intArg, const optionDef_slOptions* def, const char* arg, clientData_slOptions* clientData) {
// see if we've got anything that like a yes or true (otherwise, we make it a false)...
*((int*)ptrArg) = 0;
if (arg) {
*((int*)ptrArg) = (strchr("yYtT1", *arg) != NULL ? 1 : 0);
// now look for "on" and treat it as true
if (strlen(arg) > 1) {
if ((tolower(arg[0]) == 'o') && (tolower(arg[1]) == 'n')) {
*((int*)ptrArg) = 1;
}
}
}
// then return with no error...
return makeOkReturn();
}
// Parse the given argument, which is presumed to be a string representing an integer, which if parsed without error is
// stored to the argPtr. If the parsing fails for any reason, return an error.
static slReturn parseInt(void* ptrArg, int intArg, const optionDef_slOptions* def, const char* arg, clientData_slOptions* clientData) {
// make sure we can parse the entire argument into an integer...
int n = 0;
if (arg != NULL) {
char *endPtr;
n = (int) strtol(arg, &endPtr, 10);
if (*endPtr != 0)
return parseMsgHelper(ERR_ROOT, def, "the specified %s (\"%s\") is not an integer", def->argName, arg);
}
// stuff it away to the given pointer...
*((int*)ptrArg) = n;
// then return with no error...
return makeOkReturn();
}
// Set a boolean flag at the given ptrArg to the given intArg.
static slReturn parseFlag(void* ptrArg, int intArg, const optionDef_slOptions* def, const char* arg, clientData_slOptions* clientData) {
// do what we've been told to do...
*((bool*)ptrArg) = (bool) intArg;
// then return with no error...
return makeOkReturn();
}
typedef struct { char* name; queryType queryType; } queryDef;
static queryDef queryDefs[] = {
{ "fix", fixQuery },
{ "version", versionQuery },
{ "satellites", satelliteQuery },
{ "config", configQuery }
};
// Parse the given query type and store the results. Returns an error on any parsing problem.
static slReturn parseQuery(void* ptrArg, int intArg, const optionDef_slOptions* def, const char* arg, clientData_slOptions* clientData) {
// see what kind of query we've got here...
for (int i = 0; i < ARRAY_SIZE(queryDefs); i++) {
if (0 == strcmp(arg, queryDefs[i].name)) {
clientData->queryType = queryDefs[i].queryType;
return makeOkReturn();
}
}
// if we get here then we have a bogus query type...
return parseMsgHelper(ERR_ROOT, def, "the specified %s (\"%s\") is not a valid query type", def->argName, arg);
}
// Increment the int counter at the given ptrArg.
static slReturn parseCount(void* ptrArg, int intArg, const optionDef_slOptions* def, const char* arg, clientData_slOptions* clientData) {
// do what we've been told to do...
(*((int*)ptrArg))++;
// then return with no error...
return makeOkReturn();
}
#undef V3
#undef V2
#undef V1
#undef V0
#undef CD
// Sync may only be specified if auto baud rate was NOT specified...
static slReturn constrainSync(const optionDef_slOptions* defs, const psloConfig* config, const state_slOptions* state) {
if (hasShortOption_slOptions('a', state))
return makeErrorMsgReturn(ERR_ROOT, "-s, --sync may only be specified if -a, --autobaud is NOT specified");
return makeOkReturn();
}
// JSON may only be specified if a query was specified...
static slReturn constrainJSON(const optionDef_slOptions* defs, const psloConfig* config, const state_slOptions* state) {
if (!hasShortOption_slOptions('Q', state))
return makeErrorMsgReturn(ERR_ROOT, "-j, --json may only be specified if -Q, --query is also specified");
return makeOkReturn();
}
// Baud may only be specified if auto baud rate was NOT specified...
static slReturn constrainBaud(const optionDef_slOptions* defs, const psloConfig* config, const state_slOptions* state) {
if (hasShortOption_slOptions('a', state))
return makeErrorMsgReturn(ERR_ROOT, "-b, --baud may only be specified if -a, --autobaud is NOT specified");
return makeOkReturn();
}
// Minbaud may only be specified if auto baud rate was specified...
static slReturn constrainMinBaud(const optionDef_slOptions* defs, const psloConfig* config, const state_slOptions* state) {
if (!hasShortOption_slOptions('a', state))
return makeErrorMsgReturn(ERR_ROOT, "-M, --minbaud may only be specified if -a, --autobaud is also specified");
return makeOkReturn();
}
// Verbosity may only be specified if quiet was NOT specified...
static slReturn constrainVerbosity(const optionDef_slOptions* defs, const psloConfig* config, const state_slOptions* state) {
if (hasShortOption_slOptions('q', state))
return makeErrorMsgReturn(ERR_ROOT, "-v, --verbosity d may only be specified if -q, --quiet is NOT specified");
return makeOkReturn();
}
#define CD (config->clientData)
#define V0 (CD->verbosity >= 0)
#define V1 (CD->verbosity >= 1)
#define V2 (CD->verbosity >= 2)
#define V3 (CD->verbosity >= 3)
/* remove PPS signal test as wiringPi is now deprecates
// Test for the presence and quality of a 1 Hz signal on GPIO 18 (the PPS signal from the GPS), printing the result.
#define PPS_PIN 1
static slReturn actionTestPPS(const optionDef_slOptions* defs, const psloConfig* config) {
wiringPiSetup();
pinMode(PPS_PIN, INPUT);
struct timespec tenmicro = { 0, 10000 };
struct timespec lastTime = { 0, 0 };
// measure for about 10 seconds...
int lastState = 0;
for (int i = 0; i < 100000; i++) {
// wait 10 microseconds
nanosleep(&tenmicro, NULL);
// check our state...
int state = digitalRead(PPS_PIN);
// if the state has changed, time to measure and report...
if (state != lastState) {
// get the current time...
struct timespec thisTime;
int result = clock_gettime(CLOCK_MONOTONIC, &thisTime);
if (result != 0)
return makeErrorFmtMsgReturn(ERR_ROOT, "problem reading CPU clock: %s", strerror(errno));
// if this isn't our first measurement...
if ((lastTime.tv_sec != 0) || (lastTime.tv_nsec != 0)) {
// figure out how long we were in this state...
long long nanos = thisTime.tv_nsec - lastTime.tv_nsec;
if (nanos < 0) nanos += 1000000000;
double secs = 1.0 * nanos / 1000000000.0;
// tell our results...
char* signal = (lastState == 0) ? " low" : "high";
printf("PPS was %s for %.3f seconds\n", signal, secs);
}
lastTime = thisTime;
lastState = state;
}
}
return makeOkReturn();
}
*/
// Autobaud action function, which infers the GPS baud rate by trying to synchronize at various baud rates.
static slReturn actionAutoBaud(const optionDef_slOptions* defs, const psloConfig* config) {
// first we figure out what synchronization type we're going to use...
baudRateSynchronizer* synchronizer;
clientData_slOptions* cd = config->clientData;
switch (cd->syncMethod) {
case syncASCII:
synchronizer = asciiBaudRateSynchronizer;
break;
case syncNMEA:
synchronizer = nmeaBaudRateSynchronizer;
break;
case syncUBX:
synchronizer = ubxSynchronizer;
break;
default: return makeErrorFmtMsgReturn(ERR_ROOT, "invalid synchronization type: %d", cd->syncMethod);
}
if (V2) printf("Automatically determining baud rate...\n");
// now we set the correct options (the first baud rate, 8 data bits, 1 stop bit, no parity)
slReturn result = setTermOptions(CD->fdPort, 921600, 8, 1, false, false);
if (isErrorReturn(result)) {
close(CD->fdPort);
return makeErrorMsgReturn(ERR_CAUSE(result), "Error when setting terminal options");
}
// now we do the actual work...
slReturn abResp = autoBaudRate(cd->fdPort, cd->minBaud, synchronizer, cd->verbosity);
if (isErrorReturn(abResp))
makeErrorFmtMsgReturn(ERR_CAUSE(abResp), "problem while automatically determining baud rate");
// change the client data to reflect the new baud rate...
cd->baud = cd->newbaud;
return makeOkReturn();
}
// Baud action function, which sets the host's port to the specified baud rate.
static slReturn actionBaud(const optionDef_slOptions* defs, const psloConfig* config) {
if (V2) printf("Setting baud rate to %d...\n", CD->baud);
// now we set the correct options (the specified baud rate, 8 data bits, 1 stop bit, no parity)
slReturn result = setTermOptions(CD->fdPort, CD->baud, 8, 1, false, false);
if (isErrorReturn(result)) {
close(CD->fdPort);
return makeErrorMsgReturn(ERR_CAUSE(result), "Error when setting terminal options");
}
return makeOkReturn();
}
// New baud rate action function, which changes both the U-Blox GPS baud rate and the host baud rate.
static slReturn actionNewBaud(const optionDef_slOptions* defs, const psloConfig* config) {
clientData_slOptions* cd = config->clientData;
if (V2) printf("Changing baud rate to %d...\n", cd->newbaud);
slReturn resp = ubxChangeBaudRate(cd->fdPort, (unsigned) cd->newbaud, cd->verbosity);
if (isErrorReturn(resp))
return makeErrorMsgReturn(ERR_CAUSE(resp), "failed to change baud rate");
return makeOkReturn();
}
// Sync action function, which synchronizes serial port receiver with the data stream using the configured method.
static slReturn actionSync(const optionDef_slOptions* defs, const psloConfig* config) {
slReturn ssResp = syncSerial(CD->syncMethod, config->clientData);
if (isErrorReturn(ssResp))
return makeErrorMsgReturn(ERR_CAUSE(ssResp), "error while synchronizing on serial data");
bool success = getReturnInfoChar(ssResp);
if (success)
return makeOkReturn();
else
return makeErrorMsgReturn(ERR_ROOT, "failed to synchronize");
}
// NMEA action function, which turns NMEA data on or off on the U-Blox GPS.
static slReturn actionNMEA(const optionDef_slOptions* defs, const psloConfig* config) {
clientData_slOptions* clientData = config->clientData;
// If nmea flag is not explicitly 0 or 1 return without touching it
// so nmea enabled option 'enabled=statusquo' wouldn't change setting
if (clientData->nmea < 0 || clientData->nmea > 1)
return makeOkReturn();
slReturn usResp = syncSerial(syncUBX, clientData);
if (isErrorReturn(usResp))
return makeErrorMsgReturn(ERR_CAUSE(usResp), "could not synchronize UBX protocol");
slReturn resp = ubxSetNMEAData(clientData->fdPort, clientData->verbosity, clientData->nmea);
if (isErrorReturn(resp))
return makeErrorFmtMsgReturn(ERR_CAUSE(resp), "failed to turn NMEA data %s", clientData->nmea ? "on" : "off");
return makeOkReturn();
}
// Query action function, which queries the U-Blox GPS for the specified data.
static slReturn actionQuery(const optionDef_slOptions* defs, const psloConfig* config) {
clientData_slOptions* clientData = config->clientData;
slReturn usResp = syncSerial(syncUBX, clientData);
if (isErrorReturn(usResp))
return makeErrorMsgReturn(ERR_CAUSE(usResp), "could not synchronize UBX protocol");
slReturn resp;
switch (clientData->queryType) {
case fixQuery: resp = doFixQuery(clientData); break;
case versionQuery: resp = doVersionQuery(clientData); break;
case configQuery: resp = doConfigQuery(clientData); break;