-
Notifications
You must be signed in to change notification settings - Fork 2
/
drivers.c
1860 lines (1728 loc) · 65 KB
/
drivers.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
/*
* This file is Copyright (c) 2010 by the GPSD project
* BSD terms apply: see the file COPYING in the distribution root for details.
*/
/* for vsnprintf() FreeBSD wants __ISO_C_VISIBLE >= 1999 */
#define __ISO_C_VISIBLE 1999
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include <unistd.h>
#include "gpsd.h"
#include "bits.h" /* for getbeu16(), to extract big-endian words */
#include "strfuncs.h"
ssize_t generic_get(struct gps_device_t *session)
{
return packet_get(session->gpsdata.gps_fd, &session->lexer);
}
gps_mask_t generic_parse_input(struct gps_device_t *session)
{
if (session->lexer.type == BAD_PACKET)
return 0;
else if (session->lexer.type == COMMENT_PACKET) {
gpsd_set_century(session);
return 0;
#ifdef NMEA0183_ENABLE
} else if (session->lexer.type == NMEA_PACKET) {
const struct gps_type_t **dp;
gps_mask_t st = 0;
char *sentence = (char *)session->lexer.outbuffer;
if (sentence[strlen(sentence)-1] != '\n')
gpsd_log(&session->context->errout, LOG_IO,
"<= GPS: %s\n", sentence);
else
gpsd_log(&session->context->errout, LOG_IO,
"<= GPS: %s", sentence);
if ((st=nmea_parse(sentence, session)) == 0) {
gpsd_log(&session->context->errout, LOG_WARN,
"unknown sentence: \"%s\"\n", sentence);
}
for (dp = gpsd_drivers; *dp; dp++) {
char *trigger = (*dp)->trigger;
if (trigger!=NULL && str_starts_with(sentence, trigger)) {
gpsd_log(&session->context->errout, LOG_PROG,
"found trigger string %s.\n", trigger);
if (*dp != session->device_type) {
(void)gpsd_switch_driver(session, (*dp)->type_name);
if (session->device_type != NULL
&& session->device_type->event_hook != NULL)
session->device_type->event_hook(session,
event_triggermatch);
st |= DEVICEID_SET;
}
}
}
return st;
#endif /* NMEA0183_ENABLE */
} else {
gpsd_log(&session->context->errout, LOG_SHOUT,
"packet type %d fell through (should never happen): %s.\n",
session->lexer.type, gpsd_prettydump(session));
return 0;
}
}
/**************************************************************************
*
* Generic driver -- make no assumptions about the device type
*
**************************************************************************/
/* *INDENT-OFF* */
const struct gps_type_t driver_unknown = {
.type_name = "Unknown", /* full name of type */
.packet_type = COMMENT_PACKET, /* associated lexer packet type */
.flags = DRIVER_NOFLAGS, /* no flags set */
.trigger = NULL, /* it's the default */
.channels = 12, /* consumer-grade GPS */
.probe_detect = NULL, /* no probe */
.get_packet = generic_get, /* use generic packet getter */
.parse_packet = generic_parse_input, /* how to interpret a packet */
.rtcm_writer = NULL, /* write RTCM data straight */
.init_query = NULL, /* non-perturbing initial query */
.event_hook = NULL, /* lifetime event handler */
#ifdef RECONFIGURE_ENABLE
.speed_switcher = NULL, /* no speed switcher */
.mode_switcher = NULL, /* no mode switcher */
.rate_switcher = NULL, /* no sample-rate switcher */
.min_cycle = 1, /* not relevant, no rate switch */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = NULL, /* how to send control strings */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL, /* no method for NTP fudge factor */
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#ifdef NMEA0183_ENABLE
/**************************************************************************
*
* NMEA 0183
*
* This is separate from the 'unknown' driver because we don't want to
* ship NMEA subtype probe strings to a device until we've seen at
* least one NMEA packet. This avoids spamming devices that might
* actually be USB modems or other things in USB device class FF that
* just happen to have one of 'our' adaptor chips in front of them.
*
**************************************************************************/
static void nmea_event_hook(struct gps_device_t *session, event_t event)
{
if (session->context->readonly)
return;
/*
* This is where we try to tickle NMEA devices into revealing their
* inner natures.
*/
if (event == event_configure) {
/*
* The reason for splitting these probes up by packet sequence
* number, interleaving them with the first few packet receives,
* is because many generic-NMEA devices get confused if you send
* too much at them in one go.
*
* A fast response to an early probe will change drivers so the
* later ones won't be sent at all. Thus, for best overall
* performance, order these to probe for the most popular types
* soonest.
*
* Note: don't make the trigger strings identical to the probe,
* because some NMEA devices (notably SiRFs) will just echo
* unknown strings right back at you. A useful dodge is to append
* a comma to the trigger, because that won't be in the response
* unless there is actual following data.
*/
switch (session->lexer.counter) {
#ifdef NMEA0183_ENABLE
case 0:
/* probe for Garmin serial GPS -- expect $PGRMC followed by data */
gpsd_log(&session->context->errout, LOG_PROG,
"=> Probing for Garmin NMEA\n");
(void)nmea_send(session, "$PGRMCE");
break;
#endif /* NMEA0183_ENABLE */
#ifdef SIRF_ENABLE
case 1:
/*
* We used to try to probe for SiRF by issuing
* "$PSRF105,1" and expecting "$Ack Input105.". But it
* turns out this only works for SiRF-IIs; SiRF-I and
* SiRF-III don't respond. Sadly, the MID132 binary
* request for firmware version is ignored in NMEA mode.
* Thus the only reliable probe is to try to flip the SiRF
* into binary mode, cluing in the library to revert it on
* close.
*
* SiRFs dominate the consumer-grade GPS-mouse market, so
* we used to put this test first. Unfortunately this
* causes problems for gpsctl, as it cannot select the
* NMEA driver without switching the device back to binary
* mode! Fix this if we ever find a nondisruptive probe
* string.
*/
gpsd_log(&session->context->errout, LOG_PROG,
"=> Probing for SiRF\n");
(void)nmea_send(session,
"$PSRF100,0,%d,%d,%d,0",
session->gpsdata.dev.baudrate,
9 - session->gpsdata.dev.stopbits,
session->gpsdata.dev.stopbits);
session->back_to_nmea = true;
break;
#endif /* SIRF_ENABLE */
#ifdef NMEA0183_ENABLE
case 2:
/* probe for the FV-18 -- expect $PFEC,GPint followed by data */
gpsd_log(&session->context->errout, LOG_PROG,
"=> Probing for FV-18\n");
(void)nmea_send(session, "$PFEC,GPint");
break;
case 3:
/* probe for the Trimble Copernicus */
gpsd_log(&session->context->errout, LOG_PROG,
"=> Probing for Trimble Copernicus\n");
(void)nmea_send(session, "$PTNLSNM,0139,01");
break;
#endif /* NMEA0183_ENABLE */
#ifdef EVERMORE_ENABLE
case 4:
gpsd_log(&session->context->errout, LOG_PROG,
"=> Probing for Evermore\n");
/* Enable checksum and GGA(1s), GLL(0s), GSA(1s), GSV(1s), RMC(1s), VTG(0s), PEMT101(0s) */
/* EverMore will reply with: \x10\x02\x04\x38\x8E\xC6\x10\x03 */
(void)gpsd_write(session,
"\x10\x02\x12\x8E\x7F\x01\x01\x00\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x13\x10\x03",
22);
break;
#endif /* EVERMORE_ENABLE */
#ifdef GPSCLOCK_ENABLE
case 5:
/* probe for Furuno Electric GH-79L4-N (GPSClock); expect $PFEC,GPssd */
gpsd_log(&session->context->errout, LOG_PROG,
"=> Probing for GPSClock\n");
(void)nmea_send(session, "$PFEC,GPsrq");
break;
#endif /* GPSCLOCK_ENABLE */
#ifdef ASHTECH_ENABLE
case 6:
/* probe for Ashtech -- expect $PASHR,RID */
gpsd_log(&session->context->errout, LOG_PROG,
"=> Probing for Ashtech\n");
(void)nmea_send(session, "$PASHQ,RID");
break;
#endif /* ASHTECH_ENABLE */
#ifdef UBLOX_ENABLE
case 7:
/* probe for UBX -- query port configuration */
gpsd_log(&session->context->errout, LOG_PROG,
"=> Probing for UBX\n");
(void)ubx_write(session, 0x06, 0x00, NULL, 0);
break;
#endif /* UBLOX_ENABLE */
#ifdef MTK3301_ENABLE
case 8:
/* probe for MTK-3301 -- expect $PMTK705 */
gpsd_log(&session->context->errout, LOG_PROG,
"=> Probing for MediaTek\n");
(void)nmea_send(session, "$PMTK605");
break;
#endif /* MTK3301_ENABLE */
default:
break;
}
}
}
/* *INDENT-OFF* */
const struct gps_type_t driver_nmea0183 = {
.type_name = "NMEA0183", /* full name of type */
.packet_type = NMEA_PACKET, /* associated lexer packet type */
.flags = DRIVER_NOFLAGS, /* remember this */
.trigger = NULL, /* it's the default */
.channels = 12, /* consumer-grade GPS */
.probe_detect = NULL, /* no probe */
.get_packet = generic_get, /* use generic packet getter */
.parse_packet = generic_parse_input, /* how to interpret a packet */
.rtcm_writer = gpsd_write, /* write RTCM data straight */
.init_query = NULL, /* non-perturbing initial query */
.event_hook = nmea_event_hook, /* lifetime event handler */
#ifdef RECONFIGURE_ENABLE
.speed_switcher = NULL, /* no speed switcher */
#ifdef BINARY_ENABLE
.mode_switcher = NULL, /* maybe switchable if it was a SiRF */
#else
.mode_switcher = NULL, /* no binary mode to revert to */
#endif /* BINARY_ENABLE */
.rate_switcher = NULL, /* no sample-rate switcher */
.min_cycle = 1, /* not relevant, no rate switch */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = nmea_write, /* how to send control strings */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL, /* no method for NTP fudge factor */
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#if defined(GARMIN_ENABLE) && defined(NMEA0183_ENABLE)
/**************************************************************************
*
* Garmin NMEA
*
**************************************************************************/
#ifdef RECONFIGURE_ENABLE
static void garmin_mode_switch(struct gps_device_t *session, int mode)
/* only does anything in one direction, going to Garmin binary driver */
{
struct timespec delay;
if (mode == MODE_BINARY) {
(void)nmea_send(session, "$PGRMC1,1,2,1,,,,2,W,N");
(void)nmea_send(session, "$PGRMI,,,,,,,R");
/* wait 333 uSec, standard Garmin settling time */
delay.tv_sec = 0;
delay.tv_nsec = 333000L;
nanosleep(&delay, NULL);
}
}
#endif /* RECONFIGURE_ENABLE */
static void garmin_nmea_event_hook(struct gps_device_t *session,
event_t event)
{
if (session->context->readonly)
return;
if (event == event_driver_switch) {
/* forces a reconfigure as the following packets come in */
session->lexer.counter = 0;
}
if (event == event_configure) {
/*
* And here's that reconfigure. It's split up like this because
* receivers like the Garmin GPS-10 don't handle having having a lot of
* probes shoved at them very well.
*/
switch (session->lexer.counter) {
case 0:
/* reset some config, AutoFix, WGS84, PPS
* Set the PPS pulse length to 40ms which leaves the Garmin 18-5hz
* with a 160ms low state.
* NOTE: new PPS only takes effect after next power cycle
*/
(void)nmea_send(session, "$PGRMC,A,,100,,,,,,A,,1,2,1,30");
break;
case 1:
/* once a sec, no averaging, NMEA 2.3, WAAS */
(void)nmea_send(session, "$PGRMC1,1,1,1,,,,2,W,N");
break;
case 2:
/* get some more config info */
(void)nmea_send(session, "$PGRMC1E");
break;
case 3:
/* turn off all output except GGA */
(void)nmea_send(session, "$PGRMO,,2");
(void)nmea_send(session, "$PGRMO,GPGGA,1");
break;
case 4:
/* enable GPGGA, GPGSA, GPGSV, GPRMC on Garmin serial GPS */
(void)nmea_send(session, "$PGRMO,GPGSA,1");
break;
case 5:
(void)nmea_send(session, "$PGRMO,GPGSV,1");
break;
case 6:
(void)nmea_send(session, "$PGRMO,GPRMC,1");
break;
case 7:
(void)nmea_send(session, "$PGRMO,PGRME,1");
break;
}
}
}
/* *INDENT-OFF* */
const struct gps_type_t driver_garmin = {
.type_name = "Garmin NMEA", /* full name of type */
.packet_type = NMEA_PACKET, /* associated lexer packet type */
.flags = DRIVER_STICKY, /* remember this */
.trigger = "$PGRMC,", /* Garmin private */
.channels = 12, /* not used by this driver */
.probe_detect = NULL, /* no probe */
.get_packet = generic_get, /* use generic packet getter */
.parse_packet = generic_parse_input, /* how to interpret a packet */
.rtcm_writer = NULL, /* some do, some don't, skip for now */
.init_query = NULL, /* non-perturbing initial query */
.event_hook = garmin_nmea_event_hook, /* lifetime event handler */
#ifdef RECONFIGURE_ENABLE
.speed_switcher = NULL, /* no speed switcher */
.mode_switcher = garmin_mode_switch, /* mode switcher */
.rate_switcher = NULL, /* no sample-rate switcher */
.min_cycle = 1, /* not relevant, no rate switch */
#endif /*RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = nmea_write, /* how to send control strings */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL, /* no method for NTP fudge factor */
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#endif /* GARMIN_ENABLE && NMEA0183_ENABLE */
#ifdef ASHTECH_ENABLE
/**************************************************************************
*
* Ashtech (then Thales, now Magellan Professional) Receivers
*
**************************************************************************/
static void ashtech_event_hook(struct gps_device_t *session, event_t event)
{
if (session->context->readonly)
return;
if (event == event_wakeup)
(void)nmea_send(session, "$PASHQ,RID");
if (event == event_identified) {
/* turn WAAS on. can't hurt... */
(void)nmea_send(session, "$PASHS,WAS,ON");
/* reset to known output state */
(void)nmea_send(session, "$PASHS,NME,ALL,A,OFF");
/* then turn on some useful sentences */
#ifdef __future__
/* we could parse these, but they're oversize so they get dropped */
(void)nmea_send(session, "$PASHS,NME,POS,A,ON");
(void)nmea_send(session, "$PASHS,NME,SAT,A,ON");
#else
(void)nmea_send(session, "$PASHS,NME,GGA,A,ON");
(void)nmea_send(session, "$PASHS,NME,GSA,A,ON");
(void)nmea_send(session, "$PASHS,NME,GSV,A,ON");
(void)nmea_send(session, "$PASHS,NME,RMC,A,ON");
#endif
(void)nmea_send(session, "$PASHS,NME,ZDA,A,ON");
}
}
/* *INDENT-OFF* */
const struct gps_type_t driver_ashtech = {
.type_name = "Ashtech", /* full name of type */
.packet_type = NMEA_PACKET, /* associated lexer packet type */
.flags = DRIVER_STICKY, /* remember this */
.trigger = "$PASHR,RID,", /* Ashtech receivers respond thus */
.channels = 24, /* not used, GG24 has 24 channels */
.probe_detect = NULL, /* no probe */
.get_packet = generic_get, /* how to get a packet */
.parse_packet = generic_parse_input, /* how to interpret a packet */
.rtcm_writer = gpsd_write, /* write RTCM data straight */
.init_query = NULL, /* non-perturbing initial query */
.event_hook = ashtech_event_hook, /* lifetime event handler */
#ifdef RECONFIGURE_ENABLE
.speed_switcher = NULL, /* no speed switcher */
.mode_switcher = NULL, /* no mode switcher */
.rate_switcher = NULL, /* no sample-rate switcher */
.min_cycle = 1, /* not relevant, no rate switch */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = nmea_write, /* how to send control strings */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL, /* no method for NTP fudge factor */
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#endif /* ASHTECH_ENABLE */
#ifdef FV18_ENABLE
/**************************************************************************
*
* FV18 -- uses 2 stop bits, needs to be told to send GSAs
*
**************************************************************************/
static void fv18_event_hook(struct gps_device_t *session, event_t event)
{
if (session->context->readonly)
return;
/*
* Tell an FV18 to send GSAs so we'll know if 3D is accurate.
* Suppress GLL and VTG. Enable ZDA so dates will be accurate for replay.
* It's possible we might not need to redo this on event_reactivate,
* but doing so is safe and cheap.
*/
if (event == event_identified || event == event_reactivate)
(void)nmea_send(session,
"$PFEC,GPint,GSA01,DTM00,ZDA01,RMC01,GLL00,VTG00,GSV05");
}
/* *INDENT-OFF* */
const struct gps_type_t driver_fv18 = {
.type_name = "San Jose Navigation FV18", /* full name of type */
.packet_type = NMEA_PACKET, /* associated lexer packet type */
.flags = DRIVER_STICKY, /* remember this */
.trigger = "$PFEC,GPint,", /* FV18s should echo the probe */
.channels = 12, /* not used by this driver */
.probe_detect = NULL, /* no probe */
.get_packet = generic_get, /* how to get a packet */
.parse_packet = generic_parse_input, /* how to interpret a packet */
.rtcm_writer = gpsd_write, /* write RTCM data straight */
.init_query = NULL, /* non-perturbing initial query */
.event_hook = fv18_event_hook, /* lifetime event handler */
#ifdef RECONFIGURE_ENABLE
.speed_switcher = NULL, /* no speed switcher */
.mode_switcher = NULL, /* no mode switcher */
.rate_switcher = NULL, /* no sample-rate switcher */
.min_cycle = 1, /* not relevant, no rate switch */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = nmea_write, /* how to send control strings */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL, /* no method for NTP fudge factor */
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#endif /* FV18_ENABLE */
#ifdef GPSCLOCK_ENABLE
/**************************************************************************
*
* Furuno Electric GPSClock (GH-79L4)
*
**************************************************************************/
/*
* Based on http://www.tecsys.de/fileadmin/user_upload/pdf/gh79_1an_intant.pdf
*/
/* *INDENT-OFF* */
const struct gps_type_t driver_gpsclock = {
.type_name = "Furuno Electric GH-79L4", /* full name of type */
.packet_type = NMEA_PACKET, /* associated lexer packet type */
.flags = DRIVER_STICKY, /* remember this */
.trigger = "$PFEC,GPssd", /* GPSClock should return this */
.channels = 12, /* not used by this driver */
.probe_detect = NULL, /* no probe */
.get_packet = generic_get, /* how to get a packet */
.parse_packet = generic_parse_input, /* how to interpret a packet */
.rtcm_writer = gpsd_write, /* write RTCM data straight */
.init_query = NULL, /* non-perturbing initial query */
.event_hook = NULL, /* no lifetime event handler */
#ifdef RECONFIGURE_ENABLE
.speed_switcher = NULL, /* no speed switcher */
.mode_switcher = NULL, /* no mode switcher */
.rate_switcher = NULL, /* sample rate is fixed */
.min_cycle = 1, /* sample rate is fixed */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = nmea_write, /* how to send control strings */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL, /* no method for NTP fudge factor */
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#endif /* GPSCLOCK_ENABLE */
#ifdef TRIPMATE_ENABLE
/**************************************************************************
*
* TripMate -- extended NMEA, gets faster fix when primed with lat/long/time
*
**************************************************************************/
/*
* Some technical FAQs on the TripMate:
* http://vancouver-webpages.com/pub/peter/tripmate.faq
* http://www.asahi-net.or.jp/~KN6Y-GTU/tripmate/trmfaqe.html
* The TripMate was discontinued sometime before November 1998
* and was replaced by the Zodiac EarthMate.
*/
static void tripmate_event_hook(struct gps_device_t *session, event_t event)
{
if (session->context->readonly)
return;
/* TripMate requires this response to the ASTRAL it sends at boot time */
if (event == event_identified)
(void)nmea_send(session, "$IIGPQ,ASTRAL");
/* stop it sending PRWIZCH */
if (event == event_identified || event == event_reactivate)
(void)nmea_send(session, "$PRWIILOG,ZCH,V,,");
}
/* *INDENT-OFF* */
static const struct gps_type_t driver_tripmate = {
.type_name = "Delorme TripMate", /* full name of type */
.packet_type = NMEA_PACKET, /* lexer packet type */
.flags = DRIVER_STICKY, /* no rollover or other flags */
.trigger ="ASTRAL", /* tells us to switch */
.channels = 12, /* consumer-grade GPS */
.probe_detect = NULL, /* no probe */
.get_packet = generic_get, /* how to get a packet */
.parse_packet = generic_parse_input, /* how to interpret a packet */
.rtcm_writer = gpsd_write, /* send RTCM data straight */
.init_query = NULL, /* non-perturbing query */
.event_hook = tripmate_event_hook, /* lifetime event handler */
#ifdef RECONFIGURE_ENABLE
.speed_switcher= NULL, /* no speed switcher */
.mode_switcher = NULL, /* no mode switcher */
.rate_switcher = NULL, /* no sample-rate switcher */
.min_cycle = 1, /* no rate switch */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = nmea_write, /* how to send control strings */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL, /* no method for NTP fudge factor */
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#endif /* TRIPMATE_ENABLE */
#ifdef EARTHMATE_ENABLE
/**************************************************************************
*
* Zodiac EarthMate textual mode
*
* Note: This is the pre-2003 version using Zodiac binary protocol.
* There is a good HOWTO at <http://www.hamhud.net/ka9mva/earthmate.htm>.
* It has been replaced with a design that uses a SiRF chipset.
*
**************************************************************************/
static void earthmate_event_hook(struct gps_device_t *session, event_t event)
{
struct timespec delay;
if (session->context->readonly)
return;
if (event == event_triggermatch) {
(void)gpsd_write(session, "EARTHA\r\n", 8);
/* wait 10,000 uSec */
delay.tv_sec = 0;
delay.tv_nsec = 10000000L;
nanosleep(&delay, NULL);
(void)gpsd_switch_driver(session, "Zodiac");
}
}
/* *INDENT-OFF* */
static const struct gps_type_t driver_earthmate = {
.type_name = "Pre-2003 Delorme EarthMate",
.packet_type = NMEA_PACKET, /* associated lexer packet type */
.flags = DRIVER_STICKY, /* no rollover or other flags */
.trigger = "EARTHA", /* Earthmate trigger string */
.channels = 12, /* not used by NMEA parser */
.probe_detect = NULL, /* no probe */
.get_packet = generic_get, /* how to get a packet */
.parse_packet = generic_parse_input, /* how to interpret a packet */
.rtcm_writer = NULL, /* don't send RTCM data */
.init_query = NULL, /* non-perturbing query */
.event_hook = earthmate_event_hook, /* lifetime event handler */
#ifdef RECONFIGURE_ENABLE
.speed_switcher= NULL, /* no speed switcher */
.mode_switcher = NULL, /* no mode switcher */
.rate_switcher = NULL, /* no sample-rate switcher */
.min_cycle = 1, /* no rate switch */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = nmea_write, /* never actually used. */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL, /* no method for NTP fudge factor */
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#endif /* EARTHMATE_ENABLE */
#endif /* NMEA0183_ENABLE */
#ifdef TNT_ENABLE
/**************************************************************************
* True North Technologies - Revolution 2X Digital compass
*
* More info: http://www.tntc.com/
*
* This is a digital compass which uses magnetometers to measure the
* strength of the earth's magnetic field. Based on these measurements
* it provides a compass heading using NMEA formatted output strings.
* This is useful to supplement the heading provided by another GPS
* unit. A GPS heading is unreliable at slow speed or no speed.
*
**************************************************************************/
static ssize_t tnt_control_send(struct gps_device_t *session,
char *msg, size_t len UNUSED)
/* send a control string in TNT native formal */
{
ssize_t status;
unsigned char sum = '\0';
char c, *p = msg;
if (*p == '@') {
p++;
}
#ifdef __UNUSED__
else {
gpsd_log(&session->context->errout, LOG_ERROR,
"Bad TNT sentence: '%s'\n", msg);
}
#endif /* __UNUSED__ */
while (((c = *p) != '\0')) {
sum ^= c;
p++;
}
(void)snprintf(p, 6, "*%02X\r\n", (unsigned int)sum);
status = gpsd_write(session, msg, strlen(msg));
return status;
}
static bool tnt_send(struct gps_device_t *session, const char *fmt, ...)
/* printf(3)-like TNT command generator */
{
char buf[BUFSIZ];
va_list ap;
ssize_t sent;
va_start(ap, fmt);
(void)vsnprintf(buf, sizeof(buf) - 5, fmt, ap);
va_end(ap);
sent = tnt_control_send(session, buf, strlen(buf));
if (sent == (ssize_t) strlen(buf)) {
gpsd_log(&session->context->errout, LOG_IO,
"=> GPS: %s\n", buf);
return true;
} else {
gpsd_log(&session->context->errout, LOG_WARN,
"=> GPS: %s FAILED\n", buf);
return false;
}
}
#ifdef RECONFIGURE_ENABLE
static bool tnt_speed(struct gps_device_t *session,
speed_t speed, char parity UNUSED, int stopbits UNUSED)
{
/*
* Baud rate change followed by device reset.
* See page 40 of Technical Guide 1555-B. We need:
* 2400 -> 1, 4800 -> 2, 9600 -> 3, 19200 -> 4, 38400 -> 5
*/
unsigned int val = speed / 2400u; /* 2400->1, 4800->2, 9600->4, 19200->8... */
unsigned int i = 0;
/* fast way to compute log2(val) */
while ((val >> i) > 1)
++i;
return tnt_send(session, "@B6=%d", i + 1)
&& tnt_send(session, "@F28.6=1");
}
#endif /* RECONFIGURE_ENABLE */
static void tnt_event_hook(struct gps_device_t *session, event_t event)
/* TNT lifetime event hook */
{
if (session->context->readonly)
return;
if (event == event_wakeup) {
(void)tnt_send(session, "@F0.3=1"); /* set run mode */
(void)tnt_send(session, "@F2.2=1"); /* report in degrees */
}
}
/* *INDENT-OFF* */
const struct gps_type_t driver_trueNorth = {
.type_name = "True North", /* full name of type */
.packet_type = NMEA_PACKET, /* associated lexer packet type */
.flags = DRIVER_STICKY, /* remember this */
.trigger = "$PTNTHTM", /* their proprietary sentence */
.channels = 0, /* not an actual GPS at all */
.probe_detect = NULL, /* no probe in run mode */
.get_packet = generic_get, /* how to get a packet */
.parse_packet = generic_parse_input, /* how to interpret a packet */
.rtcm_writer = NULL, /* Don't send */
.init_query = NULL, /* non-perturbing initial query */
.event_hook = tnt_event_hook, /* lifetime event handler */
#ifdef RECONFIGURE_ENABLE
.speed_switcher = tnt_speed, /* no speed switcher */
.mode_switcher = NULL, /* no mode switcher */
.rate_switcher = NULL, /* no wrapup */
.min_cycle = 0.5, /* fixed at 20 samples per second */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = tnt_control_send, /* how to send control strings */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL,
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#endif
#ifdef OCEANSERVER_ENABLE
/**************************************************************************
* OceanServer - Digital Compass, OS5000 Series
*
* More info: http://www.ocean-server.com/download/OS5000_Compass_Manual.pdf
*
* This is a digital compass which uses magnetometers to measure the
* strength of the earth's magnetic field. Based on these measurements
* it provides a compass heading using NMEA formatted output strings.
* This is useful to supplement the heading provided by another GPS
* unit. A GPS heading is unreliable at slow speed or no speed.
*
**************************************************************************/
static int oceanserver_send(struct gpsd_errout_t *errout,
const int fd, const char *fmt, ...)
{
int status;
char buf[BUFSIZ];
va_list ap;
va_start(ap, fmt);
(void)vsnprintf(buf, sizeof(buf) - 5, fmt, ap);
va_end(ap);
(void)strlcat(buf, "", sizeof(buf));
status = (int)write(fd, buf, strlen(buf));
(void)tcdrain(fd);
if (status == (int)strlen(buf)) {
gpsd_log(errout, LOG_IO, "=> GPS: %s\n", buf);
return status;
} else {
gpsd_log(errout, LOG_WARN, "=> GPS: %s FAILED\n", buf);
return -1;
}
}
static void oceanserver_event_hook(struct gps_device_t *session,
event_t event)
{
if (session->context->readonly)
return;
if (event == event_configure && session->lexer.counter == 0) {
/* report in NMEA format */
(void)oceanserver_send(&session->context->errout,
session->gpsdata.gps_fd, "2\n");
/* ship all fields */
(void)oceanserver_send(&session->context->errout,
session->gpsdata.gps_fd, "X2047");
}
}
/* *INDENT-OFF* */
static const struct gps_type_t driver_oceanServer = {
.type_name = "OceanServer OS5000", /* full name of type */
.packet_type = NMEA_PACKET, /* associated lexer packet type */
.flags = DRIVER_STICKY, /* no rollover or other flags */
.trigger = "$OHPR,", /* detect their main sentence */
.channels = 0, /* not an actual GPS at all */
.probe_detect = NULL,
.get_packet = generic_get, /* how to get a packet */
.parse_packet = generic_parse_input, /* how to interpret a packet */
.rtcm_writer = NULL, /* Don't send */
.init_query = NULL, /* non-perturbing initial query */
.event_hook = oceanserver_event_hook,
#ifdef RECONFIGURE_ENABLE
.speed_switcher = NULL, /* no speed switcher */
.mode_switcher = NULL, /* no mode switcher */
.rate_switcher = NULL, /* no wrapup */
.min_cycle = 1, /* not relevant, no rate switch */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = nmea_write, /* how to send control strings */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL,
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#endif
#ifdef FURY_ENABLE
/**************************************************************************
*
* Jackson Labs Fury, a high-precision laboratory clock
*
* Will also support other Jackon Labs boards, including the Firefly.
*
* Note: you must either build with fixed_port_speed=115200 or tweak the
* speed on the port to 115200 before running. The device's default mode
* does not stream output, so our hunt loop will simply time out otherwise.
*
**************************************************************************/
static bool fury_rate_switcher(struct gps_device_t *session, double rate)
{
char buf[78];
double inverted;
/* rate is a frequency, but the command takes interval in # of seconds */
if (rate == 0.0)
inverted = 0.0;
else
inverted = 1.0/rate;
if (inverted > 256)
return false;
(void)snprintf(buf, sizeof(buf), "GPS:GPGGA %d\r\n", (int)inverted);
(void)gpsd_write(session, buf, strlen(buf));
return true;
}
static void fury_event_hook(struct gps_device_t *session, event_t event)
{
if (event == event_wakeup && gpsd_get_speed(session) == 115200)
(void)fury_rate_switcher(session, 1.0);
else if (event == event_deactivate)
(void)fury_rate_switcher(session, 0.0);
}
/* *INDENT-OFF* */
static const struct gps_type_t driver_fury = {
.type_name = "Jackson Labs Fury", /* full name of type */
.packet_type = NMEA_PACKET, /* associated lexer packet type */
.flags = DRIVER_STICKY, /* no rollover or other flags */
.trigger = NULL, /* detect their main sentence */
.channels = 0, /* not an actual GPS at all */
.probe_detect = NULL,
.get_packet = generic_get, /* how to get a packet */
.parse_packet = generic_parse_input, /* how to interpret a packet */
.rtcm_writer = NULL, /* Don't send */
.init_query = NULL, /* non-perturbing initial query */
.event_hook = fury_event_hook,
#ifdef RECONFIGURE_ENABLE
.speed_switcher = NULL, /* no speed switcher */
.mode_switcher = NULL, /* no mode switcher */
.rate_switcher = fury_rate_switcher,
.min_cycle = 1, /* has rate switch */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = nmea_write, /* how to send control strings */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL,
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#endif /* FURY_ENABLE */
#ifdef RTCM104V2_ENABLE
/**************************************************************************
*
* RTCM-104 (v2), used for broadcasting DGPS corrections and by DGPS radios
*
**************************************************************************/
static gps_mask_t rtcm104v2_analyze(struct gps_device_t *session)
{
rtcm2_unpack(&session->gpsdata.rtcm2, (char *)session->lexer.isgps.buf);
/* extra guard prevents expensive hexdump calls */
if (session->context->errout.debug >= LOG_RAW)
gpsd_log(&session->context->errout, LOG_RAW,
"RTCM 2.x packet type 0x%02x length %d words from %zd bytes: %s\n",
session->gpsdata.rtcm2.type,
session->gpsdata.rtcm2.length + 2,
session->lexer.isgps.buflen,
gpsd_hexdump(session->msgbuf, sizeof(session->msgbuf),
(char *)session->lexer.isgps.buf,
(session->gpsdata.rtcm2.length +
2) * sizeof(isgps30bits_t)));
session->cycle_end_reliable = true;
return RTCM2_SET;
}
/* *INDENT-OFF* */
static const struct gps_type_t driver_rtcm104v2 = {
.type_name = "RTCM104V2", /* full name of type */
.packet_type = RTCM2_PACKET, /* associated lexer packet type */
.flags = DRIVER_NOFLAGS, /* no rollover or other flags */
.trigger = NULL, /* no recognition string */
.channels = 0, /* not used */
.probe_detect = NULL, /* no probe */
.get_packet = generic_get, /* how to get a packet */
.parse_packet = rtcm104v2_analyze, /* */
.rtcm_writer = NULL, /* don't send RTCM data, */
.init_query = NULL, /* non-perturbing initial query */
.event_hook = NULL, /* no event_hook */
#ifdef RECONFIGURE_ENABLE
.speed_switcher= NULL, /* no speed switcher */
.mode_switcher = NULL, /* no mode switcher */
.rate_switcher = NULL, /* no sample-rate switcher */
.min_cycle = 1, /* not relevant, no rate switch */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
.control_send = NULL, /* how to send control strings */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
.time_offset = NULL,
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */
#endif /* RTCM104V2_ENABLE */
#ifdef RTCM104V3_ENABLE
/**************************************************************************
*
* RTCM-104 (v3), used for broadcasting DGPS corrections and by DGPS radios
*
**************************************************************************/
static gps_mask_t rtcm104v3_analyze(struct gps_device_t *session)
{
uint16_t type = getbeu16(session->lexer.inbuffer, 3) >> 4;
gpsd_log(&session->context->errout, LOG_RAW, "RTCM 3.x packet %d\n", type);
rtcm3_unpack(session->context,
&session->gpsdata.rtcm3,
(char *)session->lexer.outbuffer);