-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathdriver_tsip.c
3379 lines (3253 loc) · 117 KB
/
driver_tsip.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
/*
* Handle the Trimble TSIP packet format
* by Rob Janssen, PE1CHL.
* Acutime Gold support by Igor Socec <[email protected]>
* Trimble RES multi-constellation support by Nuno Goncalves <[email protected]>
*
* Week counters are not limited to 10 bits. It's unknown what
* the firmware is doing to disambiguate them, if anything; it might just
* be adding a fixed offset based on a hidden epoch value, in which case
* unhappy things will occur on the next rollover.
*
* This file is Copyright (c) 2010-2019 by the GPSD project
* SPDX-License-Identifier: BSD-2-clause
*/
#include "gpsd_config.h" /* must be before all includes */
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h> // For llabs()
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "gpsd.h"
#include "bits.h"
#include "strfuncs.h"
#include "timespec.h"
#ifdef TSIP_ENABLE
// RES SMT 360 has 32 max channels, use 64 for next gen
#define TSIP_CHANNELS 64
/* defines for Set or Request I/O Options (0x35)
* SMT 360 default: IO1_DP|IO1_LLA, IO2_ENU, 0, IO4_DBHZ */
// byte 1 Position
#define IO1_ECEF 1
#define IO1_LLA 2
#define IO1_MSL 4
#define IO1_DP 0x10
// IO1_8F20 not in SMT 360
#define IO1_8F20 0x20
// byte 2 Velocity
#define IO2_VECEF 1
#define IO2_ENU 2
// byte 3 Timing
#define IO3_UTC 1
// byte 4 Aux/Reserved
#define IO4_RAW 1
#define IO4_DBHZ 8
#define SEMI_2_DEG (180.0 / 2147483647) /* 2^-31 semicircle to deg */
void configuration_packets_acutime_gold(struct gps_device_t *session);
void configuration_packets_res360(struct gps_device_t *session);
void configuration_packets_generic(struct gps_device_t *session);
/* convert TSIP SV Type to satellite_t.gnssid and satellite_t.svid
* return gnssid directly, svid indirectly through pointer */
static unsigned char tsip_gnssid(unsigned svtype, short prn,
unsigned char *svid)
{
// initialized to shut up clang
unsigned char gnssid = 0;
*svid = 0;
switch (svtype) {
case 0:
if (0 < prn && 33 > prn) {
gnssid = GNSSID_GPS;
*svid = prn;
} else if (32 < prn && 55 > prn) {
// RES SMT 360 and ICM SMT 360 put SBAS in 33-54
gnssid = GNSSID_SBAS;
*svid = prn + 87;
} else if (64 < prn && 97 > prn) {
// RES SMT 360 and ICM SMT 360 put GLONASS in 65-96
gnssid = GNSSID_GLO;
*svid = prn - 64;
} else if (96 < prn && 134 > prn) {
// RES SMT 360 and ICM SMT 360 put Galileo in 97-133
gnssid = GNSSID_GAL;
*svid = prn - 96;
} else if (119 < prn && 139 > prn) {
// Copernicus (II) put SBAS in 120-138
gnssid = GNSSID_SBAS;
*svid = prn + 87;
} else if (183 == prn) {
gnssid = GNSSID_QZSS;
*svid = 1;
} else if (192 >= prn && 193 >= prn) {
gnssid = GNSSID_QZSS;
*svid = prn - 190;
} else if (200 == prn) {
gnssid = GNSSID_QZSS;
*svid = 4;
} else if (200 < prn && 238 > prn) {
// BeidDou in 201-237
gnssid = GNSSID_BD;
*svid = prn - 200;
}
// else: huh?
break;
case 1:
gnssid = GNSSID_GLO; // GLONASS
*svid = prn - 64;
break;
case 2:
gnssid = GNSSID_BD; // BeiDou
*svid = prn - 200;
break;
case 3:
gnssid = GNSSID_GAL; // Galileo
*svid = prn - 96;
break;
case 5:
gnssid = GNSSID_QZSS; // QZSS
switch (prn) {
case 183:
*svid = 1;
break;
case 192:
*svid = 2;
break;
case 193:
*svid = 3;
break;
case 200:
*svid = 4;
break;
default:
*svid = prn;
break;
}
break;
case 4:
// FALLTHROUGH
case 6:
// FALLTHROUGH
case 7:
// FALLTHROUGH
default:
svid = 0;
gnssid = 0;
break;
}
return gnssid;
}
static int tsip_write(struct gps_device_t *session,
unsigned int id, unsigned char *buf, size_t len)
{
char *ep, *cp;
char obuf[100];
size_t olen = len;
session->msgbuf[0] = '\x10';
session->msgbuf[1] = (char)id;
ep = session->msgbuf + 2;
for (cp = (char *)buf; olen-- > 0; cp++) {
if (*cp == '\x10')
*ep++ = '\x10';
*ep++ = *cp;
}
*ep++ = '\x10';
*ep++ = '\x03';
session->msgbuflen = (size_t) (ep - session->msgbuf);
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Sent packet id 0x%s\n",
gpsd_hexdump(obuf, sizeof(obuf), &session->msgbuf[1], len + 1));
if (gpsd_write(session, session->msgbuf, session->msgbuflen) !=
(ssize_t) session->msgbuflen)
return -1;
return 0;
}
/* tsip_detect()
*
* see if it looks like a TSIP device (speaking 9600O81) is listening and
* return 1 if found, 0 if not
*/
static bool tsip_detect(struct gps_device_t *session)
{
char buf[BUFSIZ];
bool ret = false;
int myfd;
speed_t old_baudrate;
char old_parity;
unsigned int old_stopbits;
old_baudrate = session->gpsdata.dev.baudrate;
old_parity = session->gpsdata.dev.parity;
old_stopbits = session->gpsdata.dev.stopbits;
// FIXME. Should respect fixed speed/framing
gpsd_set_speed(session, 9600, 'O', 1);
/* request firmware revision and look for a valid response */
putbyte(buf, 0, 0x10);
putbyte(buf, 1, 0x1f);
putbyte(buf, 2, 0x10);
putbyte(buf, 3, 0x03);
myfd = session->gpsdata.gps_fd;
if (write(myfd, buf, 4) == 4) {
unsigned int n;
for (n = 0; n < 3; n++) {
if (!nanowait(myfd, NS_IN_SEC))
break;
if (generic_get(session) >= 0) {
if (session->lexer.type == TSIP_PACKET) {
GPSD_LOG(LOG_RAW, &session->context->errout,
"TSIP: tsip_detect found\n");
ret = true;
break;
}
}
}
}
if (!ret)
/* return serial port to original settings */
gpsd_set_speed(session, old_baudrate, old_parity, old_stopbits);
return ret;
}
/* This is the meat of parsing all the TSIP packets */
static gps_mask_t tsip_parse_input(struct gps_device_t *session)
{
int i, j, len, count;
gps_mask_t mask = 0;
unsigned int id;
unsigned short week;
uint8_t u1, u2, u3, u4, u5, u6, u7, u8, u9, u10;
int16_t s1, s2, s3, s4;
int32_t sl1, sl2, sl3;
uint32_t ul1, ul2;
float f1, f2, f3, f4;
double d1, d2, d3, d4, d5;
time_t now;
unsigned char buf[BUFSIZ];
char buf2[BUFSIZ];
uint32_t tow; // time of week in milli seconds
double ftow; // time of week in seconds
double temp; // tempurature in degrees C
double fqErr; // PPS Offset. positive is slow.
timespec_t ts_tow;
char ts_buf[TIMESPEC_LEN];
int bad_len = 0;
const char *name;
if (session->lexer.type != TSIP_PACKET) {
// this should not happen
GPSD_LOG(LOG_INF, &session->context->errout,
"TSIP: tsip_analyze packet type %d\n",
session->lexer.type);
return 0;
}
if (session->lexer.outbuflen < 4 || session->lexer.outbuffer[0] != 0x10) {
/* packet too short, or does not start with DLE */
GPSD_LOG(LOG_INF, &session->context->errout,
"TSIP: tsip_analyze packet bad packet\n");
return 0;
}
// get receive time, first
(void)time(&now);
/* remove DLE stuffing and put data part of message in buf */
memset(buf, 0, sizeof(buf));
buf2[len = 0] = '\0';
for (i = 2; i < (int)session->lexer.outbuflen; i++) {
if (session->lexer.outbuffer[i] == 0x10)
if (session->lexer.outbuffer[++i] == 0x03)
break;
// FIXME expensive way to do hex
str_appendf(buf2, sizeof(buf2),
"%02x", buf[len++] = session->lexer.outbuffer[i]);
}
id = (unsigned)session->lexer.outbuffer[1];
GPSD_LOG(LOG_DATA, &session->context->errout,
"TSIP: got packet id 0x%02x length %d: %s\n",
id, len, buf2);
// session->cycle_end_reliable = true;
switch (id) {
case 0x13:
/* Packet Received
* Present in:
* pre-2000 models
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
* Not present in:
* Copernicus II
*/
if (1 > len) {
bad_len = 1;
break;
}
u1 = getub(buf, 0); // Packet ID of non-parsable packet
if (2 <= len) {
u2 = getub(buf, 1); // Data byte 0 of non-parsable packet
} else {
u2 = 0;
}
GPSD_LOG(LOG_WARN, &session->context->errout,
"TSIP: Report Packet (0x13): type x%02x %02x "
"cannot be parsed\n",
u1, u2);
// ignore the rest of the bad data
if ((int)u1 == 0x8e && (int)u2 == 0x23) {
/* no Compact Super Packet 0x8e-23 */
GPSD_LOG(LOG_WARN, &session->context->errout,
"TSIP: No 0x8e-23, use LFwEI (0x8f-20)\n");
/* Request LFwEI Super Packet instead
* SMT 360 does not support 0x8e-20 either */
putbyte(buf, 0, 0x20);
putbyte(buf, 1, 0x01); /* auto-report */
(void)tsip_write(session, 0x8e, buf, 2);
}
break;
case 0x1c: // Hardware/Software Version Information
/* Present in:
* Acutime Gold
* Lassen iQ (2005) fw 1.16+
* Copernicus (2006)
* Copernicus II (2009)
* Thunderbolt E (2012)
* RES SMT 360 (2018)
* ICM SMT 360 (2018)
* RES360 17x22 (2018)
* Acutime 360
* Not Present in:
* pre-2000 models
* ACE II (1999)
* ACE III (2000)
* Lassen SQ (2002)
* Lassen iQ (2005) pre fw 1.16
*/
u1 = (uint8_t) getub(buf, 0);
// decode by sub-code
switch (u1) {
case 0x81:
/* Firmware component version information (0x1c-81)
* polled by 0x1c-01
* Present in:
* Copernicus II (2009)
*/
// byte 1, reserved
u2 = getub(buf, 2); // Major version
u3 = getub(buf, 3); // Minor version
u4 = getub(buf, 4); // Build number
u5 = getub(buf, 5); // Build Month
u6 = getub(buf, 6); // Build Day
ul1 = getbeu16(buf, 7); // Build Year
u7 = getub(buf, 9); // Length of product name
// check for valid module name length
if (40 < u7) {
u7 = 40;
}
// check for valid module name length, again
if (u7 > (len - 10)) {
u7 = len - 10;
}
/* Product name in ASCII */
memcpy(buf2, &buf[10], u7);
buf2[u7] = '\0';
(void)snprintf(session->subtype, sizeof(session->subtype),
"fw %u.%u %u %02u/%02u/%04u %.40s",
u2, u3, u4, u6, u5, ul1, buf2);
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Firmware version (0x1c-81): %s\n",
session->subtype);
mask |= DEVICEID_SET;
if ('\0' == session->subtype1[0]) {
// request actual subtype1 from 0x1c-83
putbyte(buf, 0, 0x03);
(void)tsip_write(session, 0x1c, buf, 1);
}
break;
case 0x83:
/* Hardware component version information (0x1c-83)
* polled by 0x1c-03
* Not Present in:
* Copernicus II (2009)
*/
ul1 = getbeu32(buf, 1); // Serial number
u2 = getub(buf, 5); // Build day
u3 = getub(buf, 6); // Build month
ul2 = getbeu16(buf, 7); // Build year
u4 = getub(buf, 9); // Build hour
/* Hardware Code */
session->driver.tsip.hardware_code = getbeu16(buf, 10);
u5 = getub(buf, 12); /* Length of Hardware ID */
// check for valid module name length
// copernicus ii is 27 long
if (40 < u5) {
u5 = 40;
}
// check for valid module name length, again
if (u5 > (len - 13)) {
u5 = len - 13;
}
memcpy(buf2, &buf[13], u5);
buf2[u5] = '\0';
(void)snprintf(session->subtype1, sizeof(session->subtype1),
"hw %u %02u/%02u/%04u %02u %04u %.40s",
ul1, u2, u3, ul2, u4,
session->driver.tsip.hardware_code,
buf2);
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Hardware version (0x1c-83): %s\n",
session->subtype1);
mask |= DEVICEID_SET;
/* Detecting device by Hardware Code */
switch (session->driver.tsip.hardware_code) {
case 3001: // Acutime Gold
session->driver.tsip.subtype = TSIP_ACUTIME_GOLD;
configuration_packets_acutime_gold(session);
break;
case 3023: // RES SMT 360
session->driver.tsip.subtype = TSIP_RESSMT360;
configuration_packets_res360(session);
break;
case 3026: // ICM SMT 360
session->driver.tsip.subtype = TSIP_ICMSMT360;
configuration_packets_res360(session);
break;
case 3031: // RES360 17x22
session->driver.tsip.subtype = TSIP_RES36017x22;
configuration_packets_res360(session);
break;
case 1001: // Lassen iQ
// FALLTHROUGH
case 1002: // Copernicus, Copernicus II
// FALLTHROUGH
case 3007: // Thunderbolt E
// FALLTHROUGH
case 3032: // Acutime 360
// FALLTHROUGH
default:
configuration_packets_generic(session);
break;
}
break;
default:
GPSD_LOG(LOG_ERROR, &session->context->errout,
"TSIP: Unhandled subpacket ID 0x1c-%x\n", u1);
break;
}
break;
case 0x41:
/* GPS Time (0x41). polled by 0x21
* Note: this is not the time of current fix
* Present in:
* pre-2000 models
* Copernicus II (2009)
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
*/
if (len != 10) {
bad_len = 10;
break;
}
session->driver.tsip.last_41 = now; /* keep timestamp for request */
ftow = getbef32((char *)buf, 0); /* gpstime */
week = getbeu16(buf, 4); /* week */
f2 = getbef32((char *)buf, 6); /* leap seconds */
if (ftow >= 0.0 && f2 > 10.0) {
session->context->leap_seconds = (int)round(f2);
session->context->valid |= LEAP_SECOND_VALID;
DTOTS(&ts_tow, ftow);
session->newdata.time =
gpsd_gpstime_resolv(session, week, ts_tow);
mask |= TIME_SET | NTPTIME_IS;
/* Note: this is not the time of current fix
* Do not use in tsip.last_tow */
}
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: GPS Time (0x41): tow %.2f week %u ls %.1f %s\n",
ftow, week, f2,
timespec_str(&session->newdata.time, ts_buf, sizeof(ts_buf)));
break;
case 0x42:
/* Single-Precision Position Fix, XYZ ECEF
* Present in:
* pre-2000 models
* Copernicus II (2009)
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
*/
if (16 > len) {
bad_len = 16;
break;
}
session->newdata.ecef.x = getbef32((char *)buf, 0); /* X */
session->newdata.ecef.y = getbef32((char *)buf, 4); /* Y */
session->newdata.ecef.z = getbef32((char *)buf, 8); /* Z */
ftow = getbef32((char *)buf, 12); /* time-of-fix */
DTOTS(&ts_tow, ftow);
session->newdata.time = gpsd_gpstime_resolv(session,
session->context->gps_week,
ts_tow);
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: SP-XYZ (0x42): %f %f %f ftow %f\n",
session->newdata.ecef.x,
session->newdata.ecef.y,
session->newdata.ecef.z,
ftow);
mask = ECEF_SET | TIME_SET | NTPTIME_IS;
if (!TS_EQ(&ts_tow, &session->driver.tsip.last_tow)) {
mask |= CLEAR_IS;
session->driver.tsip.last_tow = ts_tow;
}
break;
case 0x43:
/* Velocity Fix, XYZ ECEF
* Present in:
* pre-2000 models
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
* Not Present in:
* Copernicus II (2009)
*/
if (len != 20) {
bad_len = 20;
break;
}
session->newdata.ecef.vx = getbef32((char *)buf, 0); // X velocity
session->newdata.ecef.vy = getbef32((char *)buf, 4); // Y velocity
session->newdata.ecef.vz = getbef32((char *)buf, 8); // Z velocity
f4 = getbef32((char *)buf, 12); /* bias rate */
ftow = getbef32((char *)buf, 16); /* time-of-fix */
DTOTS(&ts_tow, ftow);
session->newdata.time = gpsd_gpstime_resolv(session,
session->context->gps_week,
ts_tow);
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Vel XYZ (0x43): %f %f %f %f ftow %f\n",
session->newdata.ecef.vx,
session->newdata.ecef.vy,
session->newdata.ecef.vz,
f4, ftow);
mask = VECEF_SET | TIME_SET | NTPTIME_IS;
if (!TS_EQ(&ts_tow, &session->driver.tsip.last_tow)) {
mask |= CLEAR_IS;
session->driver.tsip.last_tow = ts_tow;
}
break;
case 0x45:
/* Software Version Information (0x45)
* Present in:
* pre-2000 models
* ACE II (1999)
* ACE III (2000)
* Lassen SQ (2002)
* Lassen iQ (2005)
* Copernicus II (2009)
* ICM SMT 360
* RES SMT 360
* Probably all TSIP
*/
if (10 > len) {
bad_len = 10;
break;
}
// convert 2 digit years to 4 digit years
ul1 = getub(buf, 3);
if (80 > ul1) {
ul1 += 2000;
} else {
ul1 += 1900;
}
ul2 = getub(buf, 8);
if (80 > ul2) {
ul2 += 2000;
} else {
ul2 += 1900;
}
/* ACE calls these "NAV processor firmware" and
* "SIG processor firmware".
* RES SMT 360 calls these "application" and "GPS core".
*/
(void)snprintf(session->subtype, sizeof(session->subtype),
"sw %d.%d %02d/%02d/%04d hw %d.%d %02d/%02d/%04d",
getub(buf, 0),
getub(buf, 1),
getub(buf, 4),
getub(buf, 2),
ul1,
getub(buf, 5),
getub(buf, 6),
getub(buf, 9),
getub(buf, 7),
ul2);
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Software version (0x45): %s\n", session->subtype);
mask |= DEVICEID_SET;
break;
case 0x46:
/* Health of Receiver (0x46). Poll with 0x26
* Present in:
* pre-2000 models
* Copernicus II (2009)
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
* all models?
* RES SMT 360 says use 0x8f-ab or 0x8f-ac instead
*/
if ( 2 > len) {
bad_len = 2;
break;
}
session->driver.tsip.last_46 = now;
u1 = getub(buf, 0); /* Status code */
/* Error codes, model dependent
* 0x01 -- no battery, always set on RES SMT 360
* 0x10 -- antenna fault
* 0x20 -- antenna is shorted
*/
u2 = getub(buf, 1);
if ((uint8_t)0 != u1) {
session->gpsdata.status = STATUS_NO_FIX;
mask |= STATUS_SET;
} else if (session->gpsdata.status < STATUS_FIX) {
session->gpsdata.status = STATUS_FIX;
mask |= STATUS_SET;
}
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Receiver Health (0x46): %x %x\n", u1, u2);
break;
case 0x47:
/* Signal Levels for all Satellites
* Present in:
* pre-2000 models
* Copernicus II (2009)
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
*/
if (1 > len) {
bad_len = 1;
break;
}
gpsd_zero_satellites(&session->gpsdata);
/* satellite count, RES SMT 360 doc says 12 max */
count = (int)getub(buf, 0);
if (len != (5 * count + 1)) {
bad_len = 5 * count + 1;
break;
}
buf2[0] = '\0';
for (i = 0; i < count; i++) {
u1 = getub(buf, 5 * i + 1);
if ((f1 = getbef32((char *)buf, 5 * i + 2)) < 0)
f1 = 0.0;
for (j = 0; j < TSIP_CHANNELS; j++)
if (session->gpsdata.skyview[j].PRN == (short)u1) {
session->gpsdata.skyview[j].ss = f1;
break;
}
str_appendf(buf2, sizeof(buf2), " %d=%.1f", (int)u1, f1);
}
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Signal Levels (0x47): (%d):%s\n", count, buf2);
mask |= SATELLITE_SET;
break;
case 0x48:
/* GPS System Message
* Present in:
* pre-2000 models
* Not Present in:
* Copernicus II (2009)
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
*/
buf[len] = '\0';
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: GPS System Message (0x48): %s\n", buf);
break;
case 0x4a:
/* Single-Precision Position LLA
* Present in:
* pre-2000 models
* Copernicus II (2009)
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
*/
if (len != 20) {
bad_len = 20;
break;
}
session->newdata.latitude = getbef32((char *)buf, 0) * RAD_2_DEG;
session->newdata.longitude = getbef32((char *)buf, 4) * RAD_2_DEG;
/* depending on GPS config, could be either WGS84 or MSL */
d1 = getbef32((char *)buf, 8);
if (0 == session->driver.tsip.alt_is_msl) {
session->newdata.altHAE = d1;
} else {
session->newdata.altMSL = d1;
}
//f1 = getbef32((char *)buf, 12); clock bias */
ftow = getbef32((char *)buf, 16); /* time-of-fix */
if ((session->context->valid & GPS_TIME_VALID)!=0) {
DTOTS(&ts_tow, ftow);
session->newdata.time =
gpsd_gpstime_resolv(session, session->context->gps_week,
ts_tow);
mask |= TIME_SET | NTPTIME_IS;
if (!TS_EQ(&ts_tow, &session->driver.tsip.last_tow)) {
mask |= CLEAR_IS;
session->driver.tsip.last_tow = ts_tow;
}
}
// this seems to be often first in cycle
// REPORT_IS here breaks reports in read-only mode
mask |= LATLON_SET | ALTITUDE_SET;
GPSD_LOG(LOG_DATA, &session->context->errout,
"TSIP: SP-LLA (0x4a): time=%s lat=%.2f lon=%.2f "
"alt=%.2f\n",
timespec_str(&session->newdata.time, ts_buf, sizeof(ts_buf)),
session->newdata.latitude,
session->newdata.longitude, d1);
break;
case 0x4b:
/* Machine/Code ID and Additional Status (0x4b)
* polled by i0x25 or 0x26. Sent with 0x46.
* Present in:
* pre-2000 models
* Copernicus II (2009)
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
* all receivers?
*/
if (len != 3) {
bad_len = 3;
break;
}
session->driver.tsip.machine_id = getub(buf, 0); /* Machine ID */
/* Status 1
* bit 1 -- No RTC at power up
* bit 3 -- almanac not complete and current */
u2 = getub(buf, 1);
u3 = getub(buf, 2); /* Status 2/Superpacket Support */
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Machine ID (0x4b): %02x %02x %02x\n",
session->driver.tsip.machine_id,
u2, u3);
if ('\0' == session->subtype[0]) {
// better than nothing
switch (session->driver.tsip.machine_id) {
case 1:
// should use better name from superpacket
name = " SMT 360";
/* request actual subtype from 0x1c-81
* which in turn requests 0x1c-83 */
putbyte(buf, 0, 0x01);
(void)tsip_write(session, 0x1c, buf, 1);
break;
case 0x32:
name = " Acutime 360";
break;
case 0x5a:
name = " Lassen iQ";
/* request actual subtype from 0x1c-81
* which in turn requests 0x1c-83.
* Only later firmware Lassen iQ supports this */
putbyte(buf, 0, 0x01);
(void)tsip_write(session, 0x1c, buf, 1);
break;
case 0x61:
name = " Acutime 2000";
break;
case 0x62:
name = " ACE UTC";
break;
case 0x96:
// Also Copernicus II
name = " Copernicus, Thunderbolt E";
/* so request actual subtype from 0x1c-81
* which in turn requests 0x1c-83 */
putbyte(buf, 0, 0x01);
(void)tsip_write(session, 0x1c, buf, 1);
break;
default:
name = "";
}
(void)snprintf(session->subtype, sizeof(session->subtype),
"Machine ID x%x%s",
session->driver.tsip.machine_id, name);
}
if (u3 != session->driver.tsip.superpkt) {
session->driver.tsip.superpkt = u3;
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Switching to Super Packet mode %d\n", u3);
switch (u3){
default:
// FALLTHROUGH
case 0:
// old Trimble, no superpackets
break;
case 1:
// 1 == superpacket is acutime 360, support 0x8f-20
/* set I/O Options for Super Packet output */
/* Position: 8F20, ECEF, DP */
putbyte(buf, 0, IO1_8F20|IO1_DP|IO1_ECEF);
putbyte(buf, 1, 0x00); /* Velocity: none (via SP) */
putbyte(buf, 2, 0x00); /* Time: GPS */
putbyte(buf, 3, IO4_DBHZ); /* Aux: dBHz */
(void)tsip_write(session, 0x35, buf, 4);
break;
case 2:
// 2 == SMT 360, no 0x8f-20
break;
}
}
break;
case 0x4c:
/* Operating Parameters Report (0x4c). Polled by 0x2c
* Present in:
* pre-2000 models
* Lassen iQ, but not documented
* Not Present in:
* Copernicus II (2009)
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
*/
if (len != 17) {
bad_len = 17;
break;
}
u1 = getub(buf, 0); // Dynamics Code
f1 = getbef32((char *)buf, 1); // Elevation Mask
f2 = getbef32((char *)buf, 5); // Signal Level Mask
f3 = getbef32((char *)buf, 9); // PDOP Mask
f4 = getbef32((char *)buf, 13); // PDOP Switch
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Operating Params (0x4c): x%02x %f %f %f %f\n",
u1, f1, f2, f3, f4);
break;
case 0x54:
/* Bias and Bias Rate Report (0x54)
* Present in:
* pre-2000 models
* Acutime 360
* ICM SMT 360 (undocumented)
* RES SMT 360 (undocumented)
* Not Present in:
* Copernicus II (2009)
*/
{
float bias, bias_rate;
bias = getbef32((char *)buf, 0); // Bias
bias_rate = getbef32((char *)buf, 4); // Bias rate
ftow = getbef32((char *)buf, 8); // tow
DTOTS(&ts_tow, ftow);
session->newdata.time =
gpsd_gpstime_resolv(session, session->context->gps_week,
ts_tow);
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Bias and Bias Rate Report (0x54) %f %f %f\n",
bias, bias_rate, ftow);
mask |= TIME_SET | NTPTIME_IS;
if (!TS_EQ(&ts_tow, &session->driver.tsip.last_tow)) {
mask |= CLEAR_IS;
session->driver.tsip.last_tow = ts_tow;
}
}
break;
case 0x55:
/* IO Options (0x55), polled by 0x35
* Present in:
* pre-2000 models
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
* all TSIP?
*
* Lassen iQ defaults: 02 02 00 00
* RES SMT 360 defaults: 12 02 00 08
*/
if (len != 4) {
bad_len = 4;
break;
}
u1 = getub(buf, 0); /* Position */
// decode HAE/MSL from Position byte
if (IO1_MSL == (IO1_MSL & u1)) {
session->driver.tsip.alt_is_msl = 1;
} else {
session->driver.tsip.alt_is_msl = 0;
}
u2 = getub(buf, 1); /* Velocity */
/* Timing
* bit 0 - reserved use 0x8e-a2 ?
*/
u3 = getub(buf, 2);
/* Aux
* bit 0 - packet 0x5a (raw data)
* bit 3 -- Output dbHz
*/
u4 = getub(buf, 3);
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: IO Options (0x55): %02x %02x %02x %02x\n",
u1, u2, u3, u4);
if ((u1 & 0x20) != (uint8_t) 0) {
/* Try to get Super Packets */
/* Turn off 0x8f-20 LFwEI Super Packet */
putbyte(buf, 0, 0x20);
putbyte(buf, 1, 0x00); /* disabled */
(void)tsip_write(session, 0x8e, buf, 2);
/* Turn on Compact Super Packet 0x8f-23 */
putbyte(buf, 0, 0x23);
putbyte(buf, 1, 0x01); /* enabled */
(void)tsip_write(session, 0x8e, buf, 2);
session->driver.tsip.req_compact = now;
}
break;
case 0x56:
/* Velocity Fix, East-North-Up (ENU)
* Present in:
* pre-2000 models
* Copernicus II (2009)
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
*/
if (len != 20) {
bad_len = 20;
break;
}
f1 = getbef32((char *)buf, 0); /* East velocity */
f2 = getbef32((char *)buf, 4); /* North velocity */
f3 = getbef32((char *)buf, 8); /* Up velocity */
f4 = getbef32((char *)buf, 12); /* clock bias rate */
ftow = getbef32((char *)buf, 16); /* time-of-fix */
DTOTS(&ts_tow, ftow);
session->newdata.time = gpsd_gpstime_resolv(session,
session->context->gps_week,
ts_tow);
session->newdata.NED.velN = f2;
session->newdata.NED.velE = f1;
session->newdata.NED.velD = -f3;
mask |= VNED_SET | TIME_SET | NTPTIME_IS;
if (!TS_EQ(&ts_tow, &session->driver.tsip.last_tow)) {
mask |= CLEAR_IS;
session->driver.tsip.last_tow = ts_tow;
}
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Vel ENU (0x56): %f %f %f %f ftow %f\n",
f1, f2, f3, f4, ftow);
break;
case 0x57:
/* Information About Last Computed Fix
* Present in:
* pre-2000 models
* Copernicus II (2009)
* ICM SMT 360 (2018)
* RES SMT 360 (2018)
*/
if (len != 8) {
bad_len = 8;
break;
}
u1 = getub(buf, 0); /* Source of information */
u2 = getub(buf, 1); /* Mfg. diagnostic */
ftow = getbef32((char *)buf, 2); /* gps_time */
week = getbeu16(buf, 6); /* tsip.gps_week */
if (getub(buf, 0) == 0x01) {
/* good current fix */
DTOTS(&ts_tow, ftow);
(void)gpsd_gpstime_resolv(session, week, ts_tow);
mask |= TIME_SET | NTPTIME_IS;
if (!TS_EQ(&ts_tow, &session->driver.tsip.last_tow)) {
mask |= CLEAR_IS;
session->driver.tsip.last_tow = ts_tow;
}
}
GPSD_LOG(LOG_PROG, &session->context->errout,
"TSIP: Fix info (0x57): %02x %02x %u %f\n", u1, u2, week, f1);
break;
case 0x5a:
/* Raw Measurement Data
* Present in:
* pre-2000 models