-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
gps.c
2645 lines (2367 loc) · 99.8 KB
/
gps.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 part of Cleanflight and Betaflight.
*
* Cleanflight and Betaflight are free software. You can redistribute
* this software and/or modify this software under the terms of the
* GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Cleanflight and Betaflight are distributed in the hope that they
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software.
*
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctype.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "platform.h"
#ifdef USE_GPS
#include "build/build_config.h"
#include "build/debug.h"
#include "common/axis.h"
#include "common/gps_conversion.h"
#include "common/maths.h"
#include "common/utils.h"
#include "config/feature.h"
#include "drivers/light_led.h"
#include "drivers/time.h"
#include "io/beeper.h"
#ifdef USE_DASHBOARD
#include "io/dashboard.h"
#endif
#include "io/gps.h"
#include "io/serial.h"
#include "config/config.h"
#include "fc/gps_lap_timer.h"
#include "fc/runtime_config.h"
#include "flight/imu.h"
#include "flight/pid.h"
#include "flight/gps_rescue.h"
#include "scheduler/scheduler.h"
#include "sensors/sensors.h"
#include "common/typeconversion.h"
// **********************
// GPS
// **********************
int32_t GPS_home[2];
uint16_t GPS_distanceToHome; // distance to home point in meters
uint32_t GPS_distanceToHomeCm;
int16_t GPS_directionToHome; // direction to home or hol point in degrees * 10
uint32_t GPS_distanceFlownInCm; // distance flown since armed in centimeters
#define GPS_DISTANCE_FLOWN_MIN_SPEED_THRESHOLD_CM_S 15 // 0.54 km/h 0.335 mph
gpsSolutionData_t gpsSol;
uint8_t GPS_update = 0; // toogle to distinct a GPS position update (directly or via MSP)
uint8_t GPS_numCh; // Details on numCh/svinfo in gps.h
uint8_t GPS_svinfo_chn[GPS_SV_MAXSATS_M8N];
uint8_t GPS_svinfo_svid[GPS_SV_MAXSATS_M8N];
uint8_t GPS_svinfo_quality[GPS_SV_MAXSATS_M8N];
uint8_t GPS_svinfo_cno[GPS_SV_MAXSATS_M8N];
// GPS LOST_COMMUNICATION timeout in ms (max time between received nav solutions)
#define GPS_TIMEOUT_MS 2500
// Timeout for waiting for an ACK or NAK response to a configuration command
#define UBLOX_ACK_TIMEOUT_MS 150
// Time allowed for module to respond to baud rate change during initial configuration
#define GPS_CONFIG_BAUD_CHANGE_INTERVAL 330 // Time to wait, in ms, between 'test this baud rate' messages
#define GPS_CONFIG_CHANGE_INTERVAL 110 // Time to wait, in ms, between CONFIG steps
#define GPS_BAUDRATE_TEST_COUNT 3 // Number of times to repeat the test message when setting baudrate
#define GPS_RECV_TIME_MAX 25 // Max permitted time, in us, for the Receive Data process
// Decay the estimated max task duration by 1/(1 << GPS_TASK_DECAY_SHIFT) on every invocation
#define GPS_TASK_DECAY_SHIFT 9 // Smoothing factor for GPS task re-scheduler
static serialPort_t *gpsPort;
static float gpsDataIntervalSeconds;
typedef struct gpsInitData_s {
uint8_t index;
uint8_t baudrateIndex; // see baudRate_e
const char *ubx;
} gpsInitData_t;
// UBX will cycle through these until valid data is received
static const gpsInitData_t gpsInitData[] = {
{ GPS_BAUDRATE_115200, BAUD_115200, "$PUBX,41,1,0003,0001,115200,0*1E\r\n" },
{ GPS_BAUDRATE_57600, BAUD_57600, "$PUBX,41,1,0003,0001,57600,0*2D\r\n" },
{ GPS_BAUDRATE_38400, BAUD_38400, "$PUBX,41,1,0003,0001,38400,0*26\r\n" },
{ GPS_BAUDRATE_19200, BAUD_19200, "$PUBX,41,1,0003,0001,19200,0*23\r\n" },
{ GPS_BAUDRATE_9600, BAUD_9600, "$PUBX,41,1,0003,0001,9600,0*16\r\n" }
};
#define GPS_INIT_DATA_ENTRY_COUNT ARRAYLEN(gpsInitData)
#define DEFAULT_BAUD_RATE_INDEX 0
#ifdef USE_GPS_UBLOX
#define MAX_VALSET_SIZE 128
typedef enum {
PREAMBLE1 = 0xB5,
PREAMBLE2 = 0x62,
CLASS_NAV = 0x01,
CLASS_ACK = 0x05,
CLASS_CFG = 0x06,
CLASS_MON = 0x0a,
CLASS_NMEA_STD = 0xf0,
MSG_ACK_NACK = 0x00,
MSG_ACK_ACK = 0x01,
MSG_NAV_POSLLH = 0x02,
MSG_NAV_STATUS = 0x03,
MSG_NAV_DOP = 0x04,
MSG_NAV_SOL = 0x06,
MSG_NAV_PVT = 0x07,
MSG_NAV_VELNED = 0x12,
MSG_NAV_SVINFO = 0x30,
MSG_NAV_SAT = 0x35,
MSG_CFG_VALSET = 0x8a,
MSG_CFG_VALGET = 0x8b,
MSG_CFG_MSG = 0x01,
MSG_CFG_PRT = 0x00,
MSG_CFG_RATE = 0x08,
MSG_CFG_SET_RATE = 0x01,
MSG_CFG_SBAS = 0x16,
MSG_CFG_NAV_SETTINGS = 0x24,
MSG_CFG_NAVX_SETTINGS = 0x23,
MSG_CFG_PMS = 0x86,
MSG_CFG_GNSS = 0x3E,
MSG_MON_VER = 0x04,
MSG_NMEA_GGA = 0x00,
MSG_NMEA_GLL = 0x01,
MSG_NMEA_GSA = 0x02,
MSG_NMEA_GSV = 0x03,
MSG_NMEA_RMC = 0x04,
MSG_NMEA_VTG = 0x05,
} ubxProtocolBytes_e;
typedef enum {
UBX_POWER_MODE_FULL = 0x00,
UBX_POWER_MODE_PSMOO = 0x01,
UBX_POWER_MODE_PSMCT = 0x02,
} ubloxPowerMode_e;
#define UBLOX_MODE_ENABLED 0x1
#define UBLOX_MODE_TEST 0x2
#define UBLOX_USAGE_RANGE 0x1
#define UBLOX_USAGE_DIFFCORR 0x2
#define UBLOX_USAGE_INTEGRITY 0x4
#define UBLOX_GNSS_ENABLE 0x1
#define UBLOX_GNSS_DEFAULT_SIGCFGMASK 0x10000
typedef struct ubxHeader_s {
uint8_t preamble1;
uint8_t preamble2;
uint8_t msg_class;
uint8_t msg_id;
uint16_t length;
} ubxHeader_t;
typedef struct ubxConfigblock_s {
uint8_t gnssId;
uint8_t resTrkCh;
uint8_t maxTrkCh;
uint8_t reserved1;
uint32_t flags;
} ubxConfigblock_t;
typedef struct ubxPollMsg_s {
uint8_t msgClass;
uint8_t msgID;
} ubxPollMsg_t;
typedef struct ubxCfgMsg_s {
uint8_t msgClass;
uint8_t msgID;
uint8_t rate;
} ubxCfgMsg_t;
typedef struct ubxCfgRate_s {
uint16_t measRate;
uint16_t navRate;
uint16_t timeRef;
} ubxCfgRate_t;
typedef struct ubxCfgValSet_s {
uint8_t version;
uint8_t layer;
uint8_t reserved[2];
uint8_t cfgData[MAX_VALSET_SIZE];
} ubxCfgValSet_t;
typedef struct ubxCfgValGet_s {
uint8_t version;
uint8_t layer;
uint16_t position;
uint8_t cfgData[MAX_VALSET_SIZE];
} ubxCfgValGet_t;
typedef struct ubxCfgSbas_s {
uint8_t mode;
uint8_t usage;
uint8_t maxSBAS;
uint8_t scanmode2;
uint32_t scanmode1;
} ubxCfgSbas_t;
typedef struct ubxCfgGnss_s {
uint8_t msgVer;
uint8_t numTrkChHw;
uint8_t numTrkChUse;
uint8_t numConfigBlocks;
ubxConfigblock_t configblocks[7];
} ubxCfgGnss_t;
typedef struct ubxCfgPms_s {
uint8_t version;
uint8_t powerSetupValue;
uint16_t period;
uint16_t onTime;
uint8_t reserved1[2];
} ubxCfgPms_t;
typedef struct ubxCfgNav5_s {
uint16_t mask;
uint8_t dynModel;
uint8_t fixMode;
int32_t fixedAlt;
uint32_t fixedAltVar;
int8_t minElev;
uint8_t drLimit;
uint16_t pDOP;
uint16_t tDOP;
uint16_t pAcc;
uint16_t tAcc;
uint8_t staticHoldThresh;
uint8_t dgnssTimeout;
uint8_t cnoThreshNumSVs;
uint8_t cnoThresh;
uint8_t reserved0[2];
uint16_t staticHoldMaxDist;
uint8_t utcStandard;
uint8_t reserved1[5];
} ubxCfgNav5_t;
typedef struct ubxCfgNav5x_s {
uint16_t version;
uint16_t mask1;
uint32_t mask2;
uint8_t reserved0[2];
uint8_t minSVs;
uint8_t maxSVs;
uint8_t minCNO;
uint8_t reserved1;
uint8_t iniFix3D;
uint8_t reserved2[2];
uint8_t ackAiding;
uint16_t wknRollover;
uint8_t sigAttenCompMode;
uint8_t reserved3;
uint8_t reserved4[2];
uint8_t reserved5[2];
uint8_t usePPP;
uint8_t aopCfg;
uint8_t reserved6[2];
uint8_t reserved7[4];
uint8_t reserved8[3];
uint8_t useAdr;
} ubxCfgNav5x_t;
typedef union ubxPayload_s {
ubxPollMsg_t poll_msg;
ubxCfgMsg_t cfg_msg;
ubxCfgRate_t cfg_rate;
ubxCfgValSet_t cfg_valset;
ubxCfgValGet_t cfg_valget;
ubxCfgNav5_t cfg_nav5;
ubxCfgNav5x_t cfg_nav5x;
ubxCfgSbas_t cfg_sbas;
ubxCfgGnss_t cfg_gnss;
ubxCfgPms_t cfg_pms;
} ubxPayload_t;
typedef struct ubxMessage_s {
ubxHeader_t header;
ubxPayload_t payload;
} __attribute__((packed)) ubxMessage_t;
typedef enum {
UBLOX_DETECT_UNIT, // 0
UBLOX_SLOW_NAV_RATE, // 1.
UBLOX_MSG_DISABLE_NMEA, // 2. Disable NMEA, config message
UBLOX_MSG_VGS, // 3. VGS: Course over ground and Ground speed
UBLOX_MSG_GSV, // 4. GSV: GNSS Satellites in View
UBLOX_MSG_GLL, // 5. GLL: Latitude and longitude, with time of position fix and status
UBLOX_MSG_GGA, // 6. GGA: Global positioning system fix data
UBLOX_MSG_GSA, // 7. GSA: GNSS DOP and Active Satellites
UBLOX_MSG_RMC, // 8. RMC: Recommended Minimum data
UBLOX_ACQUIRE_MODEL, // 9
// UBLOX_CFG_ANA, // . ANA: if M10, enable autonomous mode : temporarily disabled.
UBLOX_SET_SBAS, // 10. Sets SBAS
UBLOX_SET_PMS, // 11. Sets Power Mode
UBLOX_MSG_NAV_PVT, // 12. set NAV-PVT rate
UBLOX_MSG_SOL, // 13. set SOL MSG rate
UBLOX_MSG_POSLLH, // 14. set POSLLH MSG rate
UBLOX_MSG_STATUS, // 15: set STATUS MSG rate
UBLOX_MSG_VELNED, // 16. set VELNED MSG rate
UBLOX_MSG_DOP, // 17. MSG_NAV_DOP
UBLOX_SET_NAV_RATE, // 18. set to user requested GPS sample rate
UBLOX_MSG_CFG_GNSS, // 19. For not SBAS or GALILEO
UBLOX_CONFIG_COMPLETE // 20. Config finished, start receiving data
} ubloxStatePosition_e;
baudRate_e initBaudRateIndex;
size_t initBaudRateCycleCount;
#endif // USE_GPS_UBLOX
gpsData_t gpsData;
#ifdef USE_DASHBOARD
// Functions & data used *only* in support of the dashboard device (OLED display).
// Note this should be refactored to move dashboard functionality to the dashboard module, and only have generic hooks in the gps module...
char dashboardGpsPacketLog[GPS_PACKET_LOG_ENTRY_COUNT]; // OLED display of a char for each packet type/event received.
char *dashboardGpsPacketLogCurrentChar = dashboardGpsPacketLog; // Current character of log being updated.
uint32_t dashboardGpsPacketCount = 0; // Packet received count.
uint32_t dashboardGpsNavSvInfoRcvCount = 0; // Count of times sat info updated.
static void shiftPacketLog(void)
{
uint32_t i;
for (i = ARRAYLEN(dashboardGpsPacketLog) - 1; i > 0 ; i--) {
dashboardGpsPacketLog[i] = dashboardGpsPacketLog[i-1];
}
}
static void logErrorToPacketLog(void)
{
shiftPacketLog();
*dashboardGpsPacketLogCurrentChar = DASHBOARD_LOG_ERROR;
gpsData.errors++;
}
#endif // USE_DASHBOARD
// Enable sat info using MSP request
#ifdef USE_GPS_UBLOX
void gpsRequestSatInfo(void)
{
if (!ARMING_FLAG(ARMED)) {
setSatInfoMessageRate(5);
}
}
#endif
static void gpsNewData(uint16_t c);
#ifdef USE_GPS_NMEA
static bool gpsNewFrameNMEA(char c);
#endif
#ifdef USE_GPS_UBLOX
static bool gpsNewFrameUBLOX(uint8_t data);
#endif
static void gpsSetState(gpsState_e state)
{
gpsData.lastNavMessage = gpsData.now;
sensorsClear(SENSOR_GPS);
gpsData.state = state;
gpsData.state_position = 0;
gpsData.state_ts = gpsData.now;
gpsData.ackState = UBLOX_ACK_IDLE;
}
void gpsInit(void)
{
gpsDataIntervalSeconds = 0.1f;
gpsData.userBaudRateIndex = 0;
gpsData.timeouts = 0;
gpsData.state_ts = millis();
#ifdef USE_GPS_UBLOX
gpsData.ubloxUsingFlightModel = false;
#endif
gpsData.updateRateHz = 10; // initialise at 10hz
gpsData.platformVersion = UBX_VERSION_UNDEF;
#ifdef USE_DASHBOARD
gpsData.errors = 0;
memset(dashboardGpsPacketLog, 0x00, sizeof(dashboardGpsPacketLog));
#endif
// init gpsData structure. if we're not actually enabled, don't bother doing anything else
gpsSetState(GPS_STATE_UNKNOWN);
if (gpsConfig()->provider == GPS_MSP) { // no serial ports used when GPS_MSP is configured
gpsSetState(GPS_STATE_INITIALIZED);
return;
}
const serialPortConfig_t *gpsPortConfig = findSerialPortConfig(FUNCTION_GPS);
if (!gpsPortConfig) {
return;
}
// set the user's intended baud rate
initBaudRateIndex = BAUD_COUNT;
initBaudRateCycleCount = 0;
gpsData.userBaudRateIndex = DEFAULT_BAUD_RATE_INDEX;
for (unsigned i = 0; i < GPS_INIT_DATA_ENTRY_COUNT; i++) {
if (gpsInitData[i].baudrateIndex == gpsPortConfig->gps_baudrateIndex) {
gpsData.userBaudRateIndex = i;
break;
}
}
// the user's intended baud rate will be used as the initial baud rate when connecting
gpsData.tempBaudRateIndex = gpsData.userBaudRateIndex;
portMode_e mode = MODE_RXTX;
portOptions_e options = SERIAL_NOT_INVERTED;
#if defined(GPS_NMEA_TX_ONLY)
if (gpsConfig()->provider == GPS_NMEA) {
mode &= ~MODE_TX;
}
#endif
if ((gpsPortConfig->identifier >= SERIAL_PORT_USART1) && (gpsPortConfig->identifier <= SERIAL_PORT_USART_MAX)){
options |= SERIAL_CHECK_TX;
}
// no callback - buffer will be consumed in gpsUpdate()
gpsPort = openSerialPort(gpsPortConfig->identifier, FUNCTION_GPS, NULL, NULL, baudRates[gpsInitData[gpsData.userBaudRateIndex].baudrateIndex], mode, options);
if (!gpsPort) {
return;
}
// signal GPS "thread" to initialize when it gets to it
gpsSetState(GPS_STATE_DETECT_BAUD);
// NB gpsData.state_position is set to zero by gpsSetState(), requesting the fastest baud rate option first time around.
}
#ifdef USE_GPS_UBLOX
const uint8_t ubloxUTCStandardConfig_int[5] = {
UBLOX_UTC_STANDARD_AUTO,
UBLOX_UTC_STANDARD_USNO,
UBLOX_UTC_STANDARD_EU,
UBLOX_UTC_STANDARD_SU,
UBLOX_UTC_STANDARD_NTSC
};
struct ubloxVersion_s ubloxVersionMap[] = {
[UBX_VERSION_UNDEF] = {~0, "UNKNOWN"},
[UBX_VERSION_M5] = {0x00040005, "M5"},
[UBX_VERSION_M6] = {0x00040007, "M6"},
[UBX_VERSION_M7] = {0x00070000, "M7"},
[UBX_VERSION_M8] = {0x00080000, "M8"},
[UBX_VERSION_M9] = {0x00190000, "M9"},
[UBX_VERSION_M10] = {0x000A0000, "M10"},
};
static uint8_t ubloxAddValSet(ubxMessage_t * tx_buffer, ubxValGetSetBytes_e key, const uint8_t * payload, const uint8_t offset) {
size_t len;
switch((key >> (8 * 3)) & 0xff) {
case 0x10:
case 0x20:
len = 1;
break;
case 0x30:
len = 2;
break;
case 0x40:
len = 4;
break;
case 0x50:
len = 8;
break;
default:
return 0;
}
if (offset + 4 + len > MAX_VALSET_SIZE)
{
return 0;
}
tx_buffer->payload.cfg_valset.cfgData[offset + 0] = (uint8_t)(key >> (8 * 0));
tx_buffer->payload.cfg_valset.cfgData[offset + 1] = (uint8_t)(key >> (8 * 1));
tx_buffer->payload.cfg_valset.cfgData[offset + 2] = (uint8_t)(key >> (8 * 2));
tx_buffer->payload.cfg_valset.cfgData[offset + 3] = (uint8_t)(key >> (8 * 3));
for (size_t i = 0; i < len; ++i) {
tx_buffer->payload.cfg_valset.cfgData[offset + 4 + i] = payload[i];
}
return 4 + len;
}
// the following lines are not being used, because we are not currently sending ubloxValGet messages
#if 0
static size_t ubloxAddValGet(ubxMessage_t * tx_buffer, ubxValGetSetBytes_e key, size_t offset) {
const uint8_t zeroes[8] = {0};
return ubloxAddValSet(tx_buffer, key, zeroes, offset);
}
static size_t ubloxValGet(ubxMessage_t * tx_buffer, ubxValGetSetBytes_e key, ubloxValLayer_e layer)
{
tx_buffer->header.preamble1 = PREAMBLE1;
tx_buffer->header.preamble2 = PREAMBLE2;
tx_buffer->header.msg_class = CLASS_CFG;
tx_buffer->header.msg_id = MSG_CFG_VALGET;
tx_buffer->payload.cfg_valget.version = 1;
tx_buffer->payload.cfg_valget.layer = layer;
tx_buffer->payload.cfg_valget.position = 0;
return ubloxAddValGet(tx_buffer, key, 0);
}
#endif // not used
static uint8_t ubloxValSet(ubxMessage_t * tx_buffer, ubxValGetSetBytes_e key, uint8_t * payload, ubloxValLayer_e layer) {
memset(&tx_buffer->payload.cfg_valset, 0, sizeof(ubxCfgValSet_t));
// tx_buffer->payload.cfg_valset.version = 0;
tx_buffer->payload.cfg_valset.layer = layer;
// tx_buffer->payload.cfg_valset.reserved[0] = 0;
// tx_buffer->payload.cfg_valset.reserved[1] = 0;
return ubloxAddValSet(tx_buffer, key, payload, 0);
}
static void ubloxSendByteUpdateChecksum(const uint8_t data, uint8_t *checksumA, uint8_t *checksumB)
{
*checksumA += data;
*checksumB += *checksumA;
serialWrite(gpsPort, data);
}
static void ubloxSendDataUpdateChecksum(const uint8_t *data, uint8_t len, uint8_t *checksumA, uint8_t *checksumB)
{
while (len--) {
ubloxSendByteUpdateChecksum(*data, checksumA, checksumB);
data++;
}
}
static void ubloxSendMessage(const uint8_t *data, uint8_t len, bool skipAck)
{
uint8_t checksumA = 0, checksumB = 0;
serialWrite(gpsPort, data[0]);
serialWrite(gpsPort, data[1]);
ubloxSendDataUpdateChecksum(&data[2], len - 2, &checksumA, &checksumB);
serialWrite(gpsPort, checksumA);
serialWrite(gpsPort, checksumB);
// Save state for ACK waiting
gpsData.ackWaitingMsgId = data[3]; //save message id for ACK
gpsData.ackState = skipAck ? UBLOX_ACK_GOT_ACK : UBLOX_ACK_WAITING;
gpsData.lastMessageSent = gpsData.now;
}
static void ubloxSendClassMessage(ubxProtocolBytes_e class_id, ubxProtocolBytes_e msg_id, uint16_t length)
{
ubxMessage_t tx_buffer;
tx_buffer.header.preamble1 = PREAMBLE1;
tx_buffer.header.preamble2 = PREAMBLE2;
tx_buffer.header.msg_class = class_id;
tx_buffer.header.msg_id = msg_id;
tx_buffer.header.length = length;
ubloxSendMessage((const uint8_t *) &tx_buffer, length + 6, false);
}
static void ubloxSendConfigMessage(ubxMessage_t *message, uint8_t msg_id, uint8_t length, bool skipAck)
{
message->header.preamble1 = PREAMBLE1;
message->header.preamble2 = PREAMBLE2;
message->header.msg_class = CLASS_CFG;
message->header.msg_id = msg_id;
message->header.length = length;
ubloxSendMessage((const uint8_t *) message, length + 6, skipAck);
}
static void ubloxSendPollMessage(uint8_t msg_id)
{
ubxMessage_t tx_buffer;
tx_buffer.header.preamble1 = PREAMBLE1;
tx_buffer.header.preamble2 = PREAMBLE2;
tx_buffer.header.msg_class = CLASS_CFG;
tx_buffer.header.msg_id = msg_id;
tx_buffer.header.length = 0;
ubloxSendMessage((const uint8_t *) &tx_buffer, 6, false);
}
static void ubloxSendNAV5Message(uint8_t model) {
DEBUG_SET(DEBUG_GPS_CONNECTION, 0, model);
ubxMessage_t tx_buffer;
if (gpsData.ubloxM9orAbove) {
uint8_t payload[4];
payload[0] = (model == 0 ? 0 : model + 1);
size_t offset = ubloxValSet(&tx_buffer, CFG_NAVSPG_DYNMODEL, payload, UBX_VAL_LAYER_RAM); // 5
// the commented out payload lines are those which only set the M9 or above module to default values.
// payload[0] = 3; // set 2D/3D fix mode to auto, which is the default
// offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_FIXMODE, payload, offset); // 10
payload[0] = ubloxUTCStandardConfig_int[gpsConfig()->gps_ublox_utc_standard];
offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_UTCSTANDARD, payload, offset); // 15
// payload[0] = 0;
// payload[1] = (uint8_t)(0 >> (8 * 1));
// payload[2] = (uint8_t)(0 >> (8 * 2));
// payload[3] = (uint8_t)(0 >> (8 * 3)); // all payloads are zero, the default MSL for 2D fix
// offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_CONSTR_ALT, payload, offset); // 23
//
// payload[0] = (uint8_t)(10000 >> (8 * 0));
// payload[1] = (uint8_t)(10000 >> (8 * 1));
// payload[2] = (uint8_t)(10000 >> (8 * 2));
// payload[3] = (uint8_t)(10000 >> (8 * 3)); // // all payloads are 1000, the default 2D variance factor
// offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_CONSTR_ALTVAR, payload, offset); // 31
//
// payload[0] = 5; // sets the default minimum elevation in degrees to the default of 5
// offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_INFIL_MINELEV, payload, offset); // 36
//
// payload[0] = (uint8_t)(250 >> (8 * 0));
// payload[1] = (uint8_t)(250 >> (8 * 1)); // sets the output filter PDOP mask to default of 250
// offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_OUTFIL_PDOP, payload, offset); // 42
//
// payload[0] = (uint8_t)(250 >> (8 * 0));
// payload[1] = (uint8_t)(250 >> (8 * 1));
// offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_OUTFIL_TDOP, payload, offset); // 48
//
// payload[0] = (uint8_t)(100 >> (8 * 0));
// payload[1] = (uint8_t)(100 >> (8 * 1));
// offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_OUTFIL_PACC, payload, offset); // 54
//
// payload[0] = (uint8_t)(300 >> (8 * 0));
// payload[1] = (uint8_t)(300 >> (8 * 1));
// offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_OUTFIL_TACC, payload, offset); // 60
//
// payload[0] = 0;
// offset += ubloxAddValSet(&tx_buffer, CFG_MOT_GNSSSPEED_THRS, payload, offset); // 65
//
// payload[0] = (uint8_t)(200 >> (8 * 0));
// payload[1] = (uint8_t)(200 >> (8 * 1));
// offset += ubloxAddValSet(&tx_buffer, CFG_MOT_GNSSDIST_THRS, payload, offset); // 71
// payload[0] = (uint8_t)(60 >> (8 * 0));
// offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_CONSTR_DGNSSTO, payload, offset); // 76
// payload[0] = 0;
// offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_INFIL_NCNOTHRS, payload, offset); // 81
//
// payload[0] = 0;
// offset += ubloxAddValSet(&tx_buffer, CFG_NAVSPG_INFIL_CNOTHRS, payload, offset); // 86
ubloxSendConfigMessage(&tx_buffer, MSG_CFG_VALSET, offsetof(ubxCfgValSet_t, cfgData) + offset, true);
} else {
memset(&tx_buffer, 0, sizeof(ubxMessage_t));
tx_buffer.payload.cfg_nav5.mask = 0xFFFF;
tx_buffer.payload.cfg_nav5.dynModel = model == 0 ? 0 : model + 1; //no model with value 1
tx_buffer.payload.cfg_nav5.fixMode = 3;
tx_buffer.payload.cfg_nav5.fixedAlt = 0;
tx_buffer.payload.cfg_nav5.fixedAltVar = 10000;
tx_buffer.payload.cfg_nav5.minElev = 5;
tx_buffer.payload.cfg_nav5.drLimit = 0;
tx_buffer.payload.cfg_nav5.pDOP = 250;
tx_buffer.payload.cfg_nav5.tDOP = 250;
tx_buffer.payload.cfg_nav5.pAcc = 100;
tx_buffer.payload.cfg_nav5.tAcc = 300;
tx_buffer.payload.cfg_nav5.staticHoldThresh = 0;
tx_buffer.payload.cfg_nav5.dgnssTimeout = 60;
tx_buffer.payload.cfg_nav5.cnoThreshNumSVs = 0;
tx_buffer.payload.cfg_nav5.cnoThresh = 0;
tx_buffer.payload.cfg_nav5.staticHoldMaxDist = 200;
tx_buffer.payload.cfg_nav5.utcStandard = ubloxUTCStandardConfig_int[gpsConfig()->gps_ublox_utc_standard];
ubloxSendConfigMessage(&tx_buffer, MSG_CFG_NAV_SETTINGS, sizeof(ubxCfgNav5_t), false);
}
}
// *** Assist Now Autonomous temporarily disabled until a subsequent PR either includes, or removes it ***
// static void ubloxSendNavX5Message(void) {
// ubxMessage_t tx_buffer;
//
// if (gpsData.ubloxM9orAbove) {
// uint8_t payload[1];
// payload[0] = 1;
// size_t offset = ubloxValSet(&tx_buffer, CFG_ANA_USE_ANA, payload, UBX_VAL_LAYER_RAM); // 5
//
// ubloxSendConfigMessage(&tx_buffer, MSG_CFG_VALSET, offsetof(ubxCfgValSet_t, cfgData) + offset, true);
// } else {
// memset(&tx_buffer, 0, sizeof(ubxMessage_t));
//
// tx_buffer.payload.cfg_nav5x.version = 0x0002;
//
// tx_buffer.payload.cfg_nav5x.mask1 = 0x4000;
// tx_buffer.payload.cfg_nav5x.mask2 = 0x0;
// tx_buffer.payload.cfg_nav5x.minSVs = 0;
// tx_buffer.payload.cfg_nav5x.maxSVs = 0;
// tx_buffer.payload.cfg_nav5x.minCNO = 0;
// tx_buffer.payload.cfg_nav5x.reserved1 = 0;
// tx_buffer.payload.cfg_nav5x.iniFix3D = 0;
// tx_buffer.payload.cfg_nav5x.ackAiding = 0;
// tx_buffer.payload.cfg_nav5x.wknRollover = 0;
// tx_buffer.payload.cfg_nav5x.sigAttenCompMode = 0;
// tx_buffer.payload.cfg_nav5x.usePPP = 0;
//
// tx_buffer.payload.cfg_nav5x.aopCfg = 0x1; //bit 0 = useAOP
//
// tx_buffer.payload.cfg_nav5x.useAdr = 0;
//
// ubloxSendConfigMessage(&tx_buffer, MSG_CFG_NAVX_SETTINGS, sizeof(ubxCfgNav5x_t), false);
// }
// }
static void ubloxSetPowerModeValSet(uint8_t powerSetupValue)
{
ubxMessage_t tx_buffer;
uint8_t payload[1];
payload[0] = powerSetupValue;
size_t offset = ubloxValSet(&tx_buffer, CFG_PM_OPERATEMODE, payload, UBX_VAL_LAYER_RAM);
ubloxSendConfigMessage(&tx_buffer, MSG_CFG_VALSET, offsetof(ubxCfgValSet_t, cfgData) + offset, true);
}
static void ubloxSendPowerMode(void)
{
if (gpsData.ubloxM9orAbove) {
ubloxSetPowerModeValSet(UBX_POWER_MODE_FULL);
} else if (gpsData.ubloxM8orAbove) {
ubxMessage_t tx_buffer;
tx_buffer.payload.cfg_pms.version = 0;
tx_buffer.payload.cfg_pms.powerSetupValue = UBX_POWER_MODE_FULL;
tx_buffer.payload.cfg_pms.period = 0;
tx_buffer.payload.cfg_pms.onTime = 0;
tx_buffer.payload.cfg_pms.reserved1[0] = 0;
tx_buffer.payload.cfg_pms.reserved1[1] = 0;
ubloxSendConfigMessage(&tx_buffer, MSG_CFG_PMS, sizeof(ubxCfgPms_t), false);
}
// M7 and below do not support this type of power mode, so we leave at default.
}
static void ubloxSetMessageRate(uint8_t messageClass, uint8_t messageID, uint8_t rate)
{
ubxMessage_t tx_buffer;
tx_buffer.payload.cfg_msg.msgClass = messageClass;
tx_buffer.payload.cfg_msg.msgID = messageID;
tx_buffer.payload.cfg_msg.rate = rate;
ubloxSendConfigMessage(&tx_buffer, MSG_CFG_MSG, sizeof(ubxCfgMsg_t), false);
}
static void ubloxSetMessageRateValSet(ubxValGetSetBytes_e msgClass, uint8_t rate)
{
ubxMessage_t tx_buffer;
uint8_t payload[1];
payload[0] = rate;
size_t offset = ubloxValSet(&tx_buffer, msgClass, payload, UBX_VAL_LAYER_RAM);
ubloxSendConfigMessage(&tx_buffer, MSG_CFG_VALSET, offsetof(ubxCfgValSet_t, cfgData) + offset, true);
}
static void ubloxDisableNMEAValSet(void)
{
ubxMessage_t tx_buffer;
uint8_t payload[1];
payload[0] = 0;
// size_t offset = ubloxValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GGA_I2C, payload, UBX_VAL_LAYER_RAM);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GGA_SPI, payload, offset);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GGA_UART1, payload, offset);
size_t offset = ubloxValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GGA_UART1, payload, UBX_VAL_LAYER_RAM);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_VTG_I2C, payload, offset);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_VTG_SPI, payload, offset);
offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_VTG_UART1, payload, offset);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GSV_I2C, payload, offset);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GSV_SPI, payload, offset);
offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GSV_UART1, payload, offset);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GLL_I2C, payload, offset);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GLL_SPI, payload, offset);
offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GLL_UART1, payload, offset);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GSA_I2C, payload, offset);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GSA_SPI, payload, offset);
offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_GSA_UART1, payload, offset);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_RMC_I2C, payload, offset);
// offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_RMC_SPI, payload, offset);
offset += ubloxAddValSet(&tx_buffer, CFG_MSGOUT_NMEA_ID_RMC_UART1, payload, offset);
ubloxSendConfigMessage(&tx_buffer, MSG_CFG_VALSET, offsetof(ubxCfgValSet_t, cfgData) + offset, true);
}
static void ubloxSetNavRate(uint16_t measRate, uint16_t navRate, uint8_t timeRef)
{
uint16_t measRateMilliseconds = 1000 / measRate;
ubxMessage_t tx_buffer;
if (gpsData.ubloxM9orAbove) {
uint8_t offset = 0;
uint8_t payload[2];
payload[0] = (uint8_t)(measRateMilliseconds >> (8 * 0));
payload[1] = (uint8_t)(measRateMilliseconds >> (8 * 1));
//rate meas is U2
offset = ubloxValSet(&tx_buffer, CFG_RATE_MEAS, payload, UBX_VAL_LAYER_RAM);
payload[0] = (uint8_t)(navRate >> (8 * 0));
payload[1] = (uint8_t)(navRate >> (8 * 1));
//rate nav is U2
offset += ubloxAddValSet(&tx_buffer, CFG_RATE_NAV, payload, 6);
payload[0] = timeRef;
//rate timeref is E1 = U1
offset += ubloxAddValSet(&tx_buffer, CFG_RATE_TIMEREF, payload, 12);
ubloxSendConfigMessage(&tx_buffer, MSG_CFG_VALSET, offsetof(ubxCfgValSet_t, cfgData) + offset, false);
} else {
tx_buffer.payload.cfg_rate.measRate = measRateMilliseconds;
tx_buffer.payload.cfg_rate.navRate = navRate;
tx_buffer.payload.cfg_rate.timeRef = timeRef;
ubloxSendConfigMessage(&tx_buffer, MSG_CFG_RATE, sizeof(ubxCfgRate_t), true);
}
}
static void ubloxSetSbas(void)
{
ubxMessage_t tx_buffer;
if (gpsData.ubloxM9orAbove) {
uint8_t payload[8];
payload[0] = gpsConfig()->sbasMode != SBAS_NONE;
size_t offset = ubloxValSet(&tx_buffer, CFG_SBAS_USE_TESTMODE, payload, UBX_VAL_LAYER_RAM);
payload[0] = 1;
offset += ubloxAddValSet(&tx_buffer, CFG_SBAS_USE_RANGING, payload, offset);
offset += ubloxAddValSet(&tx_buffer, CFG_SBAS_USE_DIFFCORR, payload, offset);
if (gpsConfig()->sbas_integrity) {
offset += ubloxAddValSet(&tx_buffer, CFG_SBAS_USE_INTEGRITY, payload, offset);
}
uint64_t mask = SBAS_SEARCH_ALL;
switch (gpsConfig()->sbasMode) {
case SBAS_EGNOS:
mask = SBAS_SEARCH_PRN(123) | SBAS_SEARCH_PRN(126) | SBAS_SEARCH_PRN(136);
break;
case SBAS_WAAS:
mask = SBAS_SEARCH_PRN(131) | SBAS_SEARCH_PRN(133) | SBAS_SEARCH_PRN(135) | SBAS_SEARCH_PRN(138);
break;
case SBAS_MSAS:
mask = SBAS_SEARCH_PRN(129) | SBAS_SEARCH_PRN(137);
break;
case SBAS_GAGAN:
mask = SBAS_SEARCH_PRN(127) | SBAS_SEARCH_PRN(128) | SBAS_SEARCH_PRN(132);
break;
case SBAS_AUTO:
default:
break;
}
payload[0] = (uint8_t)(mask >> (8 * 0));
payload[1] = (uint8_t)(mask >> (8 * 1));
payload[2] = (uint8_t)(mask >> (8 * 2));
payload[3] = (uint8_t)(mask >> (8 * 3));
payload[4] = (uint8_t)(mask >> (8 * 4));
payload[5] = (uint8_t)(mask >> (8 * 5));
payload[6] = (uint8_t)(mask >> (8 * 6));
payload[7] = (uint8_t)(mask >> (8 * 7));
offset += ubloxAddValSet(&tx_buffer, CFG_SBAS_PRNSCANMASK, payload, offset);
ubloxSendConfigMessage(&tx_buffer, MSG_CFG_VALSET, offsetof(ubxCfgValSet_t, cfgData) + offset, true);
} else {
//NOTE: default ublox config for sbas mode is: UBLOX_MODE_ENABLED, test is disabled
tx_buffer.payload.cfg_sbas.mode = UBLOX_MODE_TEST;
if (gpsConfig()->sbasMode != SBAS_NONE) {
tx_buffer.payload.cfg_sbas.mode |= UBLOX_MODE_ENABLED;
}
// NOTE: default ublox config for sbas mode is: UBLOX_USAGE_RANGE | UBLOX_USAGE_DIFFCORR, integrity is disabled
tx_buffer.payload.cfg_sbas.usage = UBLOX_USAGE_RANGE | UBLOX_USAGE_DIFFCORR;
if (gpsConfig()->sbas_integrity) {
tx_buffer.payload.cfg_sbas.usage |= UBLOX_USAGE_INTEGRITY;
}
tx_buffer.payload.cfg_sbas.maxSBAS = 3;
tx_buffer.payload.cfg_sbas.scanmode2 = 0;
switch (gpsConfig()->sbasMode) {
case SBAS_AUTO:
tx_buffer.payload.cfg_sbas.scanmode1 = 0;
break;
case SBAS_EGNOS:
tx_buffer.payload.cfg_sbas.scanmode1 = 0x00010048; //PRN123, PRN126, PRN136
break;
case SBAS_WAAS:
tx_buffer.payload.cfg_sbas.scanmode1 = 0x0004A800; //PRN131, PRN133, PRN135, PRN138
break;
case SBAS_MSAS:
tx_buffer.payload.cfg_sbas.scanmode1 = 0x00020200; //PRN129, PRN137
break;
case SBAS_GAGAN:
tx_buffer.payload.cfg_sbas.scanmode1 = 0x00001180; //PRN127, PRN128, PRN132
break;
default:
tx_buffer.payload.cfg_sbas.scanmode1 = 0;
break;
}
ubloxSendConfigMessage(&tx_buffer, MSG_CFG_SBAS, sizeof(ubxCfgSbas_t), false);
}
}
void setSatInfoMessageRate(uint8_t divisor)
{
// enable satInfoMessage at 1:5 of the nav rate if configurator is connected
if (gpsData.ubloxM9orAbove) {
ubloxSetMessageRateValSet(CFG_MSGOUT_UBX_NAV_SAT_UART1, divisor);
} else if (gpsData.ubloxM8orAbove) {
ubloxSetMessageRate(CLASS_NAV, MSG_NAV_SAT, divisor);
} else {
ubloxSetMessageRate(CLASS_NAV, MSG_NAV_SVINFO, divisor);
}
}
#endif // USE_GPS_UBLOX
#ifdef USE_GPS_NMEA
void gpsConfigureNmea(void)
{
// minimal support for NMEA, we only:
// - set the FC's GPS port to the user's configured rate, and
// - send any NMEA custom commands to the GPS Module
// the user must configure the power-up baud rate of the module to be fast enough for their data rate
// Note: we always parse all incoming NMEA messages
DEBUG_SET(DEBUG_GPS_CONNECTION, 4, (gpsData.state * 100 + gpsData.state_position));
// wait 500ms between changes
if (cmp32(gpsData.now, gpsData.state_ts) < 500) {
return;
}
gpsData.state_ts = gpsData.now;
// Check that the GPS transmit buffer is empty
if (!isSerialTransmitBufferEmpty(gpsPort)) {
return;
}
switch (gpsData.state) {
case GPS_STATE_DETECT_BAUD:
// no attempt to read the baud rate of the GPS module, or change it
gpsSetState(GPS_STATE_CHANGE_BAUD);
break;
case GPS_STATE_CHANGE_BAUD:
#if !defined(GPS_NMEA_TX_ONLY)
if (gpsData.state_position < 1) {
// set the FC's baud rate to the user's configured baud rate
serialSetBaudRate(gpsPort, baudRates[gpsInitData[gpsData.userBaudRateIndex].baudrateIndex]);
gpsData.state_position++;
} else if (gpsData.state_position < 2) {
// send NMEA custom commands to select which messages being sent, data rate etc
// use PUBX, MTK, SiRF or GTK format commands, depending on module type
static int commandOffset = 0;
const char *commands = gpsConfig()->nmeaCustomCommands;
const char *cmd = commands + commandOffset;
// skip leading whitespaces and get first command length
int commandLen;
while (*cmd && (commandLen = strcspn(cmd, " \0")) == 0) {
cmd++; // skip separators
}