-
Notifications
You must be signed in to change notification settings - Fork 0
/
NMEA0183.cpp
1756 lines (1485 loc) · 86.1 KB
/
NMEA0183.cpp
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
/*!*****************************************************************************
* @file NMEA0183.c
* @author Fabien 'Emandhal' MAILLY
* @version 1.0.2
* @date 22/04/2024
* @brief NMEA decoder library
* @details Supports common GPS frames
******************************************************************************/
//-----------------------------------------------------------------------------
#if !defined(__cplusplus)
# include "NMEA0183.h"
#else
# if !defined(ARDUINO)
# include <cstdint>
# endif
# include "NMEA0183.hpp"
extern "C" {
#endif
//-----------------------------------------------------------------------------
//=============================================================================
// Prototypes for private functions
//=============================================================================
/*! @brief Convert a string to int float
* This function will stop parsing at first char not in '0'..'9', '.'
* @param[in/out] **pStr Is the string to parse (the original pointer will be advanced) and returns the new position in the string, the field separator ',' or the end of the string
* @param[in] max Is the max count of digit to extract. Set to 0 if no limit wanted. If >20 then it is the stop character
* @param[in] digits Is the digit count to extract from the string after the decimal separator '.'
* @return Returns the value extracted from string
*/
static int32_t __NMEA0183_StringToInt(char** pStr, size_t max, size_t digits);
//-----------------------------------------------------------------------------
/*! @brief Hex string to value
* This function will stop parsing at first char not in '0'..'9', 'a'..'f', 'A'..'F'
* @param[in/out] **pStr Is the string to parse (the original pointer will be advanced) and returns the new position in the string, the field separator ',' or the end of the string
* @param[in] max Is the max count of digit to extract. Set to 0 if no limit wanted. If >20 then it is the stop character
* @return Returns the value extracted
*/
static uint32_t __NMEA0183_HexStringToUint(char** pStr, size_t max);
//-----------------------------------------------------------------------------
/*! @brief Extract coordinate from string
* This function will stop parsing at first parsing error
* @param[in] **pStr Is the string to parse (the original pointer will be advanced)
* @param[out] *pData Is the coordinate extracted
* @return Returns 'true' if the parse is successful else 'false'
*/
static bool __NMEA0183_ExtractCoordinate(char** pStr, NMEA0183_Coordinate* pData);
/*! @brief Extract time from string
* This function will stop parsing at first parsing error
* @param[in] **pStr Is the string to parse (the original pointer will be advanced)
* @param[out] *pData Is the time extracted
* @return Returns 'true' if the parse is successful else 'false'
*/
static bool __NMEA0183_ExtractTime(char** pStr, NMEA0183_Time* pData);
//-----------------------------------------------------------------------------
#define NMEA0183_CHECK_FIELD_DELIMITER do{ if (*pStr != NMEA0183_FIELD_DELIMITER) return ERR__PARSE_ERROR; ++pStr; } while(0) // Should be a ',' and go to the next character of the string
//-----------------------------------------------------------------------------
//********************************************************************************************************************
// NMEA0183 decoder API
//********************************************************************************************************************
#ifdef NMEA0183_USE_INPUT_BUFFER
//=============================================================================
// Initialize NMEA0183
//=============================================================================
eERRORRESULT Init_NMEA0183(NMEA0183_DecodeInput* pDecoder)
{
#ifdef CHECK_NULL_PARAM
if (pDecoder == NULL) return ERR__PARAMETER_ERROR;
#endif
//--- Initialize vars ---
memset(pDecoder, 0, sizeof(NMEA0183_DecodeInput)); // Init GPS input structure
pDecoder->PosCRC = sizeof(pDecoder->CRC); // Set that this is not the CRC for now
return ERR_OK;
}
//-----------------------------------------------------------------------------
//**********************************************************************************************************************************************************
//=============================================================================
// Add NMEA0183 received frame character data
//=============================================================================
eERRORRESULT NMEA0183_AddReceivedCharacter(NMEA0183_DecodeInput* pDecoder, char data)
{
#ifdef CHECK_NULL_PARAM
if (pDecoder == NULL) return ERR__PARAMETER_ERROR;
#endif
eERRORRESULT Error = ERR_OK;
//--- Checks ---
if (pDecoder->State == NMEA0183_IN_PROCESS) return ERR__BUSY; // The previous frame is being parced
//--- Process character ---
switch (data) // Do something with the current character received
{
case NMEA0183_START_DELIMITER: // Start a new frame
pDecoder->BufferPos = 0; // Initialize buffer position
pDecoder->PosCRC = sizeof(pDecoder->CRC); // Initialize to current char is for frame input
pDecoder->CurrCalcCRC = 0; // Initialize the current CRC calculus
if (pDecoder->State == NMEA0183_TO_PROCESS) Error = ERR__BUFFER_OVERRIDE; // The previous buffer does not have been processed but new data available
pDecoder->State = NMEA0183_ACCUMULATE;
break;
case NMEA0183_CHECKSUM_DELIMITER: // Next characters will be for CRC
pDecoder->PosCRC = 0; // Next will be the CRC value
break;
case NMEA0183_END_CR_DELIMITER:
case NMEA0183_END_LF_DELIMITER:
if (pDecoder->State != NMEA0183_WAIT_START)
pDecoder->State = NMEA0183_TO_PROCESS; // Frame have to be processed as soon as possible (in the main loop). Not now, in case we are in an interrupt...
data = '\0'; // The data received is now a end of string character
break;
default:
if (pDecoder->PosCRC < sizeof(pDecoder->CRC)) // In CRC?
{
pDecoder->CRC[pDecoder->PosCRC] = (char)data; // Set CRC char
++pDecoder->PosCRC; // Select next char
}
else pDecoder->CurrCalcCRC ^= data; // Else compute CRC
break;
}
//--- Add char to raw frame buffer ---
if (pDecoder->State != NMEA0183_TO_PROCESS)
{
if (pDecoder->BufferPos < NMEA0183_FRAME_BUFFER_SIZE)
{
pDecoder->RawFrame[pDecoder->BufferPos] = (char)data; // Set Frame char
pDecoder->BufferPos++; // Select next char
}
else if (pDecoder->State != NMEA0183_WAIT_START) Error = ERR__BUFFER_FULL;
}
return Error;
}
#endif
//-----------------------------------------------------------------------------
//**********************************************************************************************************************************************************
//=============================================================================
// [STATIC] Convert a string to int
//=============================================================================
int32_t __NMEA0183_StringToInt(char** pStr, size_t max, size_t digits)
{
if (**pStr == '\0') return NMEA0183_NO_VALUE; // Empty string? return error value
bool Sign = (**pStr == '-'); // Minus character? Save it
if (Sign || (**pStr == '+')) ++(*pStr); // Minus character or Plus character? Go to next one
if (**pStr == '\0') return NMEA0183_NO_VALUE; // Empty string? return error value
if ((**pStr == NMEA0183_FIELD_DELIMITER) || (**pStr == NMEA0183_CHECKSUM_DELIMITER)) return NMEA0183_NO_VALUE; // If the field is empty, set no data
size_t CharCount = (max == 0 ? NMEA0183_FRAME_BUFFER_SIZE : max); // If max = 0, then extract until ',', '*', or '\0'
int32_t Result = 0;
//--- Extract value ---
bool PointFound = false;
while (CharCount > 0)
{
if (**pStr == (char)max) break; // Stop char found
if (**pStr != '.')
{
if ((uint_fast8_t)(**pStr - '0') > 9) break; // If pStr[0] = '\0' or other char, the result should be > 9 then break the while...
if (PointFound) // Decrement digit only if the char '.' have been found
{
if (digits == 0) break;
--digits;
}
Result *= 10; // Multiply the int part by 10
Result += (int32_t)(**pStr - '0'); // Add the unit value
}
else PointFound = true;
--CharCount;
++(*pStr); // Next char
}
while (digits > 0) { Result *= 10; --digits; } // Force multiplier to digits
if (max == 0)
while ((**pStr != NMEA0183_FIELD_DELIMITER) && (**pStr != NMEA0183_CHECKSUM_DELIMITER) && (**pStr != 0)) ++(*pStr); // Go to the end of the field or the end of the string
if (Sign) Result = -Result; // If negative value, then set negative IntPart as result
return Result; // Return the new position
}
//-----------------------------------------------------------------------------
//=============================================================================
// [STATIC] Hex string to value
//=============================================================================
uint32_t __NMEA0183_HexStringToUint(char** pStr, size_t max)
{
if (**pStr == '\0') return NMEA0183_NO_VALUE; // Empty string? return error value
if ((**pStr == NMEA0183_FIELD_DELIMITER) || (**pStr == NMEA0183_CHECKSUM_DELIMITER)) return NMEA0183_NO_VALUE; // If the field is empty, set no data
size_t CharCount = (max == 0 ? NMEA0183_FRAME_BUFFER_SIZE : max); // If max = 0, then extract until ',', '*', or '\0'
uint32_t Result = 0;
//--- Extract uint32 from hex string ---
while ((CharCount > 0) && (**pStr != 0))
{
if (**pStr == (char)max) break; // Stop char found
uint32_t CurChar = (uint32_t)(**pStr);
if ((CurChar - 0x30) <= 9u) // Char in '0'..'9' ?
{
Result <<= 4;
Result += (CurChar - 0x30); // 0x30 for '0'
}
else
{
CurChar &= 0xDF; // Transform 'a'..'f' into 'A'..'F'
if ((CurChar - 0x41) <= 5u) // Char in 'A'..'F' ?
{
Result <<= 4;
Result += (CurChar - 0x41) + 10u; // 0x41 for 'A' and add 10 to the value
}
else break;
}
++(*pStr);
--CharCount;
}
return Result;
}
//-----------------------------------------------------------------------------
//**********************************************************************************************************************************************************
//=============================================================================
// [STATIC] Extract coordinate
//=============================================================================
bool __NMEA0183_ExtractCoordinate(char** pStr, NMEA0183_Coordinate* pData)
{
if (**pStr != NMEA0183_FIELD_DELIMITER) // Value found?
{
int32_t Value = __NMEA0183_StringToInt(pStr, '.', 0); //*** Get degree and minute <(d)ddmm>
//--- Get Degree ---
pData->Degree = (uint8_t)(Value / 100); // And save degree
//--- Get Minute ---
pData->Minute = (uint32_t)__NMEA0183_StringToInt(pStr, 0, 7); //*** Get and save decimal minute <.mmmm[m][m][m]> (divide by 10^7 to get the real minute)*/
pData->Minute += ((Value % 100) * 10000000); // And save minute with decimal minute
if (**pStr != NMEA0183_FIELD_DELIMITER) return false; // Parsing: Should be a ','
++(*pStr); // Parsing: Skip ','
}
else // else no value found
{
pData->Degree = (uint8_t)NMEA0183_NO_VALUE;
pData->Minute = (uint32_t)NMEA0183_NO_VALUE;
++(*pStr); // Parsing: Skip ','
}
//--- Get Direction ---
if (**pStr != NMEA0183_FIELD_DELIMITER) // Value found?
{
pData->Direction = **pStr; //*** Get coordinate direction <N/S or E/W>
++(*pStr); // Parsing: Skip <N/S or E/W>
}
else pData->Direction = ' '; // Else no direction
if (**pStr != NMEA0183_FIELD_DELIMITER) return false; // Parsing: Should be a ','
++(*pStr); // Parsing: Skip ','
return true;
}
//=============================================================================
// [STATIC] Extract time
//=============================================================================
bool __NMEA0183_ExtractTime(char** pStr, NMEA0183_Time* pData)
{
//--- Get Time ---
pData->Hour = (uint8_t)__NMEA0183_StringToInt(pStr, 2, 0); //*** Get and save hour <hh>
pData->Minute = (uint8_t)__NMEA0183_StringToInt(pStr, 2, 0); //*** Get and save minute <mm>
pData->Second = (uint8_t)__NMEA0183_StringToInt(pStr, 2, 0); //*** Get and save second <ss>
//--- Get milliseconds ---
if (**pStr == '.') // If the next char is '.' then there is a millisecond value to get
{
pData->MilliS = (uint16_t)__NMEA0183_StringToInt(pStr, 0, 3); //*** Get and save milliseconds <zzz>
} else pData->MilliS = (uint16_t)NMEA0183_NO_VALUE; // else set no value
if (**pStr != NMEA0183_FIELD_DELIMITER) return false; // Parsing: Should be a ','
++(*pStr); // Parsing: Skip ','
return true;
}
//-----------------------------------------------------------------------------
//**********************************************************************************************************************************************************
#ifdef NMEA0183_DECODE_AAM
//=============================================================================
// [STATIC] Process the AAM (Waypoint Arrival Alarm) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessAAM(const char* pSentence, NMEA0183_AAMdata* pData)
{ // Format: $--AAM,<Entered:A/V>,<Waypoint:A/V>,<Circle:r.rr[r][r]>,N,<WaypointID>*<CheckSum>
char* pStr = (char*)pSentence;
eERRORRESULT Error = ERR_OK;
//--- Get Status ---
pData->ArrivalStatus = *pStr; //*** Get status of arrival: 'A' = arrival circle entered ; 'V' = arrival circle not entered
++pStr; // Parsing: Skip <A/V>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->PassedWaypoint = *pStr; //*** Get status of the passed waypoint: 'A' = arrival circle entered ; 'V' = arrival circle not entered
++pStr; // Parsing: Skip <A/V>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Arrival circle radius ---
pData->CircleRadius = (uint32_t)__NMEA0183_StringToInt(&pStr, 0, 4); //*** Get and save Arrival circle radius <Circle:r.rr[r][r]> (divide by 10^4 to get the circle radius in nautical miles)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'N') return ERR__PARSE_ERROR; // Parsing: Should be 'N'
++pStr; // Parsing: Skip 'N'
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Waypoint ID ---
size_t TxtPos = 0;
while (TxtPos < (NMEA0183_AAM_WAYPOINT_ID_MAX_SIZE-1))
{
if ((*pStr == '\0') || (*pStr == NMEA0183_CHECKSUM_DELIMITER)) break;
pData->WaypointID[TxtPos] = *pStr; //*** Get char
++TxtPos;
++pStr;
}
pData->WaypointID[TxtPos] = '\0';
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) Error = ERR__PARSE_ERROR; // Should be a '*'
return Error;
}
#endif
#ifdef NMEA0183_DECODE_ALM
//=============================================================================
// [STATIC] Process the ALM (GPS Almanac Data) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessALM(const char* pSentence, NMEA0183_ALMdata* pData)
{ // Format: $--ALM,<Total:t>,<Curr:c>,<SatPRN:ss>,<WeekNum:[w][w][w]w>,<SV:vv>,<e:eeee>,<toa:yy>,<Sigma_i:iiii>,<OMEGADOT:dddd>,<rootA:rrrrrr>,<OMEGA:oooooo>,<OMEGA0:aaaaaa>,<Mo:mmmmmm>,<af0:aaa>,<af1:bbb>*<CheckSum>
char* pStr = (char*)pSentence;
uint32_t Value;
//--- Get message informations ---
pData->TotalSentence = (uint8_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save total sentence <t>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->SentenceNumber = (uint8_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save sequence number <c>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->SatellitePRNnumber = (uint8_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save satellite PRN number <ss>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->GPSweekNumber = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save GPS week number <[w][w][w]w>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get data ---
pData->SV_NAVhealth = (uint8_t)__NMEA0183_HexStringToUint(&pStr, ','); //*** Get and save NAV+SV health <vv>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->e = (uint16_t)__NMEA0183_HexStringToUint(&pStr, ','); //*** Get and save inclination eccentricity <eeee>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->toa = (uint8_t)__NMEA0183_HexStringToUint(&pStr, ','); //*** Get and save almanac reference time in seconds <yy>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->Sigma_i = (int16_t)__NMEA0183_HexStringToUint(&pStr, ','); //*** Get and save inclination angle <iiii>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->OMEGADOT = (int16_t)__NMEA0183_HexStringToUint(&pStr, ','); //*** Get and save rate of right ascension <dddd>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->Root_A = (uint32_t)__NMEA0183_HexStringToUint(&pStr, ','); //*** Get and save root of semi-major axis <rrrrrr>
NMEA0183_CHECK_FIELD_DELIMITER;
Value = (uint32_t)__NMEA0183_HexStringToUint(&pStr, ','); //*** Get 24-bit signed longitude of ascension node <oooooo>
pData->OMEGA = NMEA0183_DATA_EXTRACT_TO_SIGNED(int32_t, Value, 0, 24); //*** Save 32-bit signed longitude of ascension node <oooooo>
NMEA0183_CHECK_FIELD_DELIMITER;
Value = (uint32_t)__NMEA0183_HexStringToUint(&pStr, ','); //*** Get 24-bit signed argument of perigee <aaaaaa>
pData->OMEGA_0 = NMEA0183_DATA_EXTRACT_TO_SIGNED(int32_t, Value, 0, 24); //*** Save 32-bit signed argument of perigee <aaaaaa>
NMEA0183_CHECK_FIELD_DELIMITER;
Value = (uint32_t)__NMEA0183_HexStringToUint(&pStr, ','); //*** Get 24-bit signed mean anomaly <mmmmmm>
pData->Mo = NMEA0183_DATA_EXTRACT_TO_SIGNED(int32_t, Value, 0, 24); //*** Save 32-bit signed mean anomaly <mmmmmm>
NMEA0183_CHECK_FIELD_DELIMITER;
Value = (uint32_t)__NMEA0183_HexStringToUint(&pStr, ','); //*** Get 11-bit clock parameter <aaa>
pData->af0 = NMEA0183_DATA_EXTRACT_TO_SIGNED(int16_t, Value, 0, 11); //*** Save 16-bit clock parameter <aaa>
NMEA0183_CHECK_FIELD_DELIMITER;
Value = (uint32_t)__NMEA0183_HexStringToUint(&pStr, ','); //*** Get 11-bit clock parameter <bbb>
pData->af1 = NMEA0183_DATA_EXTRACT_TO_SIGNED(int16_t, Value, 0, 11); //*** Save 16-bit clock parameter <bbb>
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_APB
//=============================================================================
// [STATIC] Process the APB (Heading/Track Controller (Autopilot) Sentence "B") sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessAPB(const char* pSentence, NMEA0183_APBdata* pData)
{ // Format: $--APB,<Status:A/V>,<Status:A/V>,<Magnitude:m.m[m][m][m]>,<L/R>,<N/K>,<A/V>,<A/V>,<BOtoD:b[.b][b]>,<M/T>,<WaypointID>,<BCPtoD:c[.c][c]>,<M/T>,<H2StoD:h[.h][h]>,<M/T>,<FAA:A/D/E/M/S/N>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Status ---
pData->Status1 = *pStr; //*** Get status1 <A/V>
++pStr; // Parsing: Skip <A/V>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->Status2 = *pStr; //*** Get status2 <A/V>
++pStr; // Parsing: Skip <A/V>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get magnitude of XTE ---
pData->MagnitudeXTE = (int32_t)__NMEA0183_StringToInt(&pStr, 0, 4); //*** Get magnitude of XTE (cross-track-error) <m.m[m][m][m]> (divide by 10^4 to get the real magnitude of XTE)
NMEA0183_CHECK_FIELD_DELIMITER;
pData->DirectionSteer = *pStr; //*** Get direction to steer <L/R>
++pStr; // Parsing: Skip <L/R>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->XTEunit = *pStr; //*** Get XTE unit <N/K>
++pStr; // Parsing: Skip <N/K>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Status ---
pData->ArrivalStatus = *pStr; //*** Get status of arrival: 'A' = arrival circle entered ; 'V' = arrival circle not entered
++pStr; // Parsing: Skip <A/V>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->PassedWaypoint = *pStr; //*** Get status of the passed waypoint: 'A' = arrival circle entered ; 'V' = arrival circle not entered
++pStr; // Parsing: Skip <A/V>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Bearing origin ---
pData->BearingOriginToDest = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get bearing origin to destination <b[.b][b]> (divide by 10^2 to get the real bearing origin to destination)
NMEA0183_CHECK_FIELD_DELIMITER;
pData->BearingOtoDunit = *pStr; //*** Get bearing origin to destination unit: 'M' = magnetic ; 'T' = true
++pStr; // Parsing: Skip <M/T>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Waypoint ID ---
size_t TxtPos = 0;
while (TxtPos < (NMEA0183_APB_WAYPOINT_ID_MAX_SIZE - 1))
{
if ((*pStr == '\0') || (*pStr == NMEA0183_FIELD_DELIMITER)) break;
pData->WaypointID[TxtPos] = *pStr; //*** Get char
++TxtPos;
++pStr;
}
pData->WaypointID[TxtPos] = '\0';
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Bearing current position ---
pData->BearingCurPosToDest = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get bearing present position to destination <c[.c][c]> (divide by 10^2 to get the real bearing origin to destination)
NMEA0183_CHECK_FIELD_DELIMITER;
pData->BearingCPtoDunit = *pStr; //*** Get bearing present position to destination unit: 'M' = magnetic ; 'T' = true
++pStr; // Parsing: Skip <M/T>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Heading to steer ---
pData->HeadingToSteerToDest = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get heading-to-steer to destination waypoint <h[.h][h]> (divide by 10^2 to get the real bearing origin to destination)
NMEA0183_CHECK_FIELD_DELIMITER;
pData->H2StoDunit = *pStr; //*** Get heading-to-steer to destination waypoint unit: 'M' = magnetic ; 'T' = true
++pStr; // Parsing: Skip <M/T>
if (*pStr == NMEA0183_FIELD_DELIMITER)
{
//--- Get FAA mode (if available) ---
++pStr; // Parsing: Skip ','
pData->FAAmode = *pStr; //*** Get FAA mode <A/D/E/M/S/N>
++pStr; // Parsing: Skip <A/D/E/M/S/N>
}
else pData->FAAmode = ' '; //*** Set FAA mode not specified
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_BEC
//=============================================================================
// [STATIC] Process the BEC (Bearing and distance to waypoint - dead reckoning) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessBEC(const char* pSentence, NMEA0183_BECdata* pData)
{ // Format: $--BEC,<hhmmss.zzz>,<Latitude:ddmm.mmmm[m][m][m]>,<N/S>,<Longitude:dddmm.mmmm[m][m][m]>,<E/W>,<BearingTrue:t[.t][t]>,T,<BearingMag:m[.m][m]>,M,<Distance:sss.ss[s][s]>,N,<WaypointID>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Time ---
if (__NMEA0183_ExtractTime(&pStr, &pData->Time) == false) return ERR__PARSE_ERROR; //*** Get time
//--- Get Latitude and Longitude ---
if (__NMEA0183_ExtractCoordinate(&pStr, &pData->WaypointLat ) == false) return ERR__PARSE_ERROR; //*** Get latitude
if (__NMEA0183_ExtractCoordinate(&pStr, &pData->WaypointLong) == false) return ERR__PARSE_ERROR; //*** Get longitude
//--- Get Bearing True ---
pData->BearingTrue = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get bearing True <t[.t][t]> (divide by 10^2 to get the real bearing True)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'T') return ERR__PARSE_ERROR; // Parsing: Should be 'T'
++pStr; // Parsing: Skip 'T'
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Bearing Magntic ---
pData->BearingMagnetic = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get bearing Magntic <m[.m][m]> (divide by 10^2 to get the real bearing Magntic)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'M') return ERR__PARSE_ERROR; // Parsing: Should be 'M'
++pStr; // Parsing: Skip 'M'
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Distance ---
pData->Distance = (uint32_t)__NMEA0183_StringToInt(&pStr, 0, 4); //*** Get distance <sss.ss[s][s]> (divide by 10^4 to get the real distance)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'N') return ERR__PARSE_ERROR; // Parsing: Should be 'N'
++pStr; // Parsing: Skip 'N'
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Waypoint ID ---
size_t TxtPos = 0;
while (TxtPos < (NMEA0183_BEC_WAYPOINT_ID_MAX_SIZE - 1))
{
if ((*pStr == '\0') || (*pStr == NMEA0183_CHECKSUM_DELIMITER)) break;
pData->WaypointID[TxtPos] = *pStr; //*** Get char
++TxtPos;
++pStr;
}
pData->WaypointID[TxtPos] = '\0';
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_BOD
//=============================================================================
// [STATIC] Process the BOD (Bearing - Origin to Destination) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessBOD(const char* pSentence, NMEA0183_BODdata* pData)
{ // Format: $--BOD,<BearingTrue:t[.t][t]>,T,<BearingMag:m[.m][m]>,M,<DestWaypointID>,<OriginWaypointID>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Bearing True ---
pData->BearingTrue = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get bearing True <t[.t][t]> (divide by 10^2 to get the real bearing True)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'T') return ERR__PARSE_ERROR; // Parsing: Should be 'T'
++pStr; // Parsing: Skip 'T'
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Bearing Magntic ---
pData->BearingMagnetic = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get bearing Magntic <m[.m][m]> (divide by 10^2 to get the real bearing Magntic)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'M') return ERR__PARSE_ERROR; // Parsing: Should be 'M'
++pStr; // Parsing: Skip 'M'
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Destination Waypoint ID ---
size_t TxtPos = 0;
while (TxtPos < (NMEA0183_BOD_WAYPOINT_ID_MAX_SIZE - 1))
{
if ((*pStr == '\0') || (*pStr == NMEA0183_FIELD_DELIMITER) || (*pStr == NMEA0183_CHECKSUM_DELIMITER)) break;
pData->DestWaypointID[TxtPos] = *pStr; //*** Get char
++TxtPos;
++pStr;
}
pData->DestWaypointID[TxtPos] = '\0';
//--- Get Origin Waypoint ID ---
TxtPos = 0;
if (*pStr == NMEA0183_FIELD_DELIMITER)
{
++pStr;
while (TxtPos < (NMEA0183_BOD_WAYPOINT_ID_MAX_SIZE - 1))
{
if ((*pStr == '\0') || (*pStr == NMEA0183_CHECKSUM_DELIMITER)) break;
pData->OriginWaypointID[TxtPos] = *pStr; //*** Get char
++TxtPos;
++pStr;
}
}
pData->OriginWaypointID[TxtPos] = '\0';
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_BWW
//=============================================================================
// [STATIC] Process the BWW (Bearing - Waypoint to Waypoint) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessBWW(const char* pSentence, NMEA0183_BWWdata* pData)
{ // Format: $--BWW,<BearingTrue:t[.t][t]>,T,<BearingMag:m[.m][m]>,M,<DestWaypointID>,<OriginWaypointID>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Bearing True ---
pData->BearingTrue = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get bearing True <t[.t][t]> (divide by 10^2 to get the real bearing True)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'T') return ERR__PARSE_ERROR; // Parsing: Should be 'T'
++pStr; // Parsing: Skip 'T'
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Bearing Magntic ---
pData->BearingMagnetic = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get bearing Magntic <m[.m][m]> (divide by 10^2 to get the real bearing Magntic)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'M') return ERR__PARSE_ERROR; // Parsing: Should be 'M'
++pStr; // Parsing: Skip 'M'
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Destination Waypoint ID ---
size_t TxtPos = 0;
while (TxtPos < (NMEA0183_BWW_WAYPOINT_ID_MAX_SIZE - 1))
{
if ((*pStr == '\0') || (*pStr == NMEA0183_FIELD_DELIMITER) || (*pStr == NMEA0183_CHECKSUM_DELIMITER)) break;
pData->FromWaypointID[TxtPos] = *pStr; //*** Get char
++TxtPos;
++pStr;
}
pData->FromWaypointID[TxtPos] = '\0';
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Origin Waypoint ID ---
TxtPos = 0;
while (TxtPos < (NMEA0183_BWW_WAYPOINT_ID_MAX_SIZE - 1))
{
if ((*pStr == '\0') || (*pStr == NMEA0183_CHECKSUM_DELIMITER)) break;
pData->ToWaypointID[TxtPos] = *pStr; //*** Get char
++TxtPos;
++pStr;
}
pData->ToWaypointID[TxtPos] = '\0';
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#if defined(NMEA0183_DECODE_DBK) || defined(NMEA0183_DECODE_DBS) || defined(NMEA0183_DECODE_DBT)
//=============================================================================
// [STATIC] Process the DBK (Depth Below Keel), DBS (Depth Below Surface), or DBT (Depth Below Tranducer) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessDBx(const char* pSentence, NMEA0183_DBxdata* pData)
{ // Format: $--DBx,<DepthFeet:d[.d][d][d]>,f,<DepthMeter:m[.m][m][m]>,M,<DepthMeter:f[.f][f][f]>,F*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Depth ---
pData->DepthFeet = (uint32_t)__NMEA0183_StringToInt(&pStr, 0, 3); //*** Get and save depth <d[.d][d][d]> (divide by 10^3 to get the real depth)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'f') return ERR__PARSE_ERROR; // Parsing: Should be 'f'
++pStr;
NMEA0183_CHECK_FIELD_DELIMITER;
pData->DepthMeter = (uint32_t)__NMEA0183_StringToInt(&pStr, 0, 3); //*** Get and save depth <m[.m][m][m]> (divide by 10^3 to get the real depth)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'M') return ERR__PARSE_ERROR; // Parsing: Should be 'M'
++pStr;
NMEA0183_CHECK_FIELD_DELIMITER;
pData->DepthFathom = (uint32_t)__NMEA0183_StringToInt(&pStr, 0, 3); //*** Get and save depth <f[.f][f][f]> (divide by 10^3 to get the real depth)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'F') return ERR__PARSE_ERROR; // Parsing: Should be 'F'
++pStr;
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_DPT
//=============================================================================
// [STATIC] Process the DPT (Depth) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessDPT(const char* pSentence, NMEA0183_DPTdata* pData)
{ // Format: $--DPT,<WaterDepth:m[.m][m][m]>,<OffsetTrans:(-)o[.o][o]>,<RangeScale:r[.r][r]>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Water Depth ---
pData->DepthMeter = (uint32_t)__NMEA0183_StringToInt(&pStr, 0, 3); //*** Get and save water depth <m[.m][m][m]> (divide by 10^3 to get the real depth)
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Offset from Transducer ---
if ((*pStr != NMEA0183_FIELD_DELIMITER) && (*pStr != NMEA0183_CHECKSUM_DELIMITER))
{
pData->OffsetTrans = (int16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get and save offset from transducer <(-)o[.o][o]> (divide by 10^2 to get the real offset)
}
else pData->OffsetTrans = 0; // If no offset, in this case, the depth offset will always be zero (see NMEA-0183-Information-sheet-issue-4-1-1)
if (*pStr == NMEA0183_FIELD_DELIMITER) ++pStr; // Parsing: Skip ','
if ((*pStr != NMEA0183_FIELD_DELIMITER) && (*pStr != NMEA0183_CHECKSUM_DELIMITER))
{
//--- Get Maximum range scale in use (if available) ---
pData->RangeScale = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save maximum range scale in use <r[.r][r]>
}
else pData->RangeScale = NMEA0183_NO_VALUE;
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_FSI
//=============================================================================
// [STATIC] Process the FSI (Frequency Set Information) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessFSI(const char* pSentence, NMEA0183_FSIdata* pData)
{ // Format: $--FSI,<TxFreq:tttttt>,<RxFreq:rrrrrr>,<Mode:d/e/m/o/q/s/t/w/x/{/|>,<PowerLevel:0/1..9>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Tx Frequency ---
pData->TxFrequency = (uint32_t)__NMEA0183_StringToInt(&pStr, 0, 3); //*** Get and save transmitting frequency <tttttt>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Rx Frequency ---
pData->RxFrequency = (uint32_t)__NMEA0183_StringToInt(&pStr, 0, 3); //*** Get and save receiving frequency <rrrrrr>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Mode of Operation ---
pData->Mode = *pStr; //*** Get mode of Operation
++pStr; // Parsing: Skip <d/e/m/o/q/s/t/w/x/{/|>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Power Level ---
pData->PowerLevel = *pStr; //*** Get power level: '0' = Standby ; '1' = Lowest ; ... ; '9' = Highest
++pStr; // Parsing: Skip <0/1..9>
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_GGA
//=============================================================================
// [STATIC] Process the GGA (Global positioning system fixed data) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessGGA(const char* pSentence, NMEA0183_GGAdata* pData)
{ // Format: $--GGA,<hhmmss.zzz>,<Latitude:ddmm.mmmm[m][m][m]>,<N/S>,<Longitude:dddmm.mmmm[m][m][m]>,<E/W>,<GPSquality:0/1/2/3/4/5/6/7/8>,<SatUsed:ss>,<HDOP:h.h(h)>,<Altitude:(-)aaa.a[a]>,M,<GeoidSep:(-)gg.g[g]>,M,<AgeDiff:cc.c[c]>,<DiffRef:rrrr>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Time ---
if (__NMEA0183_ExtractTime(&pStr, &pData->Time) == false) return ERR__PARSE_ERROR; //*** Get time
//--- Get Latitude and Longitude ---
if (__NMEA0183_ExtractCoordinate(&pStr, &pData->Latitude ) == false) return ERR__PARSE_ERROR; //*** Get latitude
if (__NMEA0183_ExtractCoordinate(&pStr, &pData->Longitude) == false) return ERR__PARSE_ERROR; //*** Get longitude
//--- Get GPS Quality Indicator ---
pData->GPSquality = *pStr; //*** Get GPS quality indicator <0/1/2/3/4/5/6/7/8>
++pStr; // Parsing: Skip <0/1/2/3/4/5/6/7/8>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Satellite Used ---
pData->SatellitesUsed = (uint8_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save satellite used <ss>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get HDOP ---
pData->HDOP = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get and save HDOP <h.h(h)> (divide by 100 to get the real HDOP)
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Altitude ---
pData->Altitude = __NMEA0183_StringToInt(&pStr, 0, 2); //*** Get and save altitude <(-)aaa.a[a]> (divide by 10^2 to get the real altitude)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'M') return ERR__PARSE_ERROR; // Parsing: Should be 'M'
++pStr; // Parsing: Skip 'M'
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Geoid Separation ---
pData->GeoidSeparation = __NMEA0183_StringToInt(&pStr, 0, 2); //*** Get and save geoid separation <(-)gg.g[g]> (divide by 10^2 to get the real geoid separation)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'M') return ERR__PARSE_ERROR; // Parsing: Should be 'M'
++pStr; // Parsing: Skip 'M'
if (*pStr == NMEA0183_FIELD_DELIMITER)
{
//--- Get Age of differential GPS data (if available) ---
++pStr; // Parsing: Skip ','
pData->AgeOfDiffCorr = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get age of differential GPS data <cc.c[c]> (divide by 10^2 to get the real age of differential GPS data)
if (*pStr == NMEA0183_FIELD_DELIMITER)
{
//--- Get Differential reference station ID (if available) ---
++pStr; // Parsing: Skip ','
pData->DiffRefStationID = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save differential reference station ID <rrrr>
}
else pData->DiffRefStationID = (uint16_t)NMEA0183_NO_VALUE; //*** Set age of differential GPS data not specified
}
else pData->AgeOfDiffCorr = (uint16_t)NMEA0183_NO_VALUE; //*** Set age of differential GPS data not specified
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_GLL
//=============================================================================
// [STATIC] Process the GLL (Geographic Position - Latitude/Longitude) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessGLL(const char* pSentence, NMEA0183_GLLdata* pData)
{ // Format: $--GLL,<Latitude:ddmm.mmmm[m][m][m]>,<N/S>,<Longitude:dddmm.mmmm[m][m][m]>,<E/W>,<hhmmss.zzz>,<Status:A/V>,<FAA:A/D/E/M/S/N>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Latitude and Longitude ---
if (__NMEA0183_ExtractCoordinate(&pStr, &pData->Latitude ) == false) return ERR__PARSE_ERROR; //*** Get latitude
if (__NMEA0183_ExtractCoordinate(&pStr, &pData->Longitude) == false) return ERR__PARSE_ERROR; //*** Get longitude
//--- Get Time ---
if (__NMEA0183_ExtractTime(&pStr, &pData->Time) == false) return ERR__PARSE_ERROR; //*** Get time
//--- Get Status ---
pData->Status = *pStr; //*** Get status: A=Active=Good ; V=Void=NotGood
++pStr; // Parsing: Skip <A/V>
if (*pStr == NMEA0183_FIELD_DELIMITER)
{
//--- Get FAA mode (if available) ---
++pStr; // Parsing: Skip ','
pData->FAAmode = *pStr; //*** Get FAA mode <A/D/E/M/S/N>
++pStr; // Parsing: Skip <A/D/E/M/S/N>
}
else pData->FAAmode = ' '; //*** Set FAA mode not specified
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_GSA
//=============================================================================
// [STATIC] Process the GSA (GNSS DOP and Active Satellites) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessGSA(const char* pSentence, NMEA0183_GSAdata* pData)
{ // Format: $--GSA,<Mode1:A/M>,<Mode2:1/2/3>,[<Sat1:xx>],[<Sat2:xx>],[<Sat3:xx>],[<Sat4:xx>],[<Sat5:xx>],[<Sat6:xx>],[<Sat7:xx>],[<Sat8:xx>],[<Sat9:xx>],[<Sat10:xx>],[<Sat11:xx>],[<Sat12:xx>],<PDOP:p.p>,<HDOP:h.h>,<VDOP:v.v>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Mode 1 ---
pData->Mode1 = *pStr; //*** Get mode <A/M>
++pStr; // Parsing: Skip <A/M>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Mode 2 ---
pData->Mode2 = *pStr; //*** Get mode <1/2/3>
++pStr; // Parsing: Skip <1/2/3>
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Satellite IDs ---
for (size_t zSat = 0; zSat < NMEA0183_SATELLITE_ID_COUNT; ++zSat)
{
//--- Get Satellite ID ---
pData->SatelliteIDs[zSat] = (uint8_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save satellite ID <xx>
NMEA0183_CHECK_FIELD_DELIMITER;
}
//--- Get DOPs ---
pData->PDOP = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get PDOP <p.p> (divide by 100 to get the real PDOP)
NMEA0183_CHECK_FIELD_DELIMITER;
pData->HDOP = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get HDOP <h.h> (divide by 100 to get the real HDOP)
NMEA0183_CHECK_FIELD_DELIMITER;
pData->VDOP = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get VDOP <v.v> (divide by 100 to get the real VDOP)
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_GSV
//=============================================================================
// [STATIC] Process the GSV (GNSS Satellites in View) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessGSV(const char* pSentence, NMEA0183_GSVdata* pData)
{ // Format: $--GSV,<Total:t>,<Curr:c>,<SatCount:ss>,<SV1:<SatNum:nn>,<Elev:ee>,<Azim:aaa>,<SNR:rr>>[,<SV2:<SatNum:nn>,<Elev:ee>,<Azim:aaa>,<SNR:rr>>][,<SV3:<SatNum:nn>,<Elev:ee>,<Azim:aaa>,<SNR:rr>>][,<SV4:<SatNum:nn>,<Elev:ee>,<Azim:aaa>,<SNR:rr>>],<Text>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get message informations ---
pData->TotalSentence = (uint8_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save total sentence <t>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->SentenceNumber = (uint8_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save sequence number <c>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->TotalSatellite = (uint8_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save total satellite <ss>
NMEA0183_CHECK_FIELD_DELIMITER;
size_t zSat = 0;
while (zSat < NMEA0183_SAT_VIEW_COUNT_PER_MESSAGES)
{
//--- Get Satellite informations ---
pData->SatView[zSat].SatelliteID = (uint8_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save satellite ID <nn>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->SatView[zSat].Elevation = (uint8_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save elevation <ee>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->SatView[zSat].Azimuth = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 0); //*** Get and save azimuth <aaa>
NMEA0183_CHECK_FIELD_DELIMITER;
pData->SatView[zSat].SNR = (uint8_t)__NMEA0183_StringToInt(&pStr, 2, 0); //*** Get and save SNR <rr>
++zSat;
if (*pStr == NMEA0183_CHECKSUM_DELIMITER) break;
NMEA0183_CHECK_FIELD_DELIMITER;
}
for (size_t z = zSat; z < NMEA0183_SAT_VIEW_COUNT_PER_MESSAGES; ++z)
memset(&pData->SatView[z], 0xFF, sizeof(NMEA0183_SatelliteView)); // Clear data of satellite in view not setted
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_HDG
//=============================================================================
// [STATIC] Process the HDG (Heading - Deviation and Variation) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessHDG(const char* pSentence, NMEA0183_HDGdata* pData)
{ // Format: $--HDG,<Heading:hh.h[h]>,<MagDev:dd.d[d]>,<E/W>,<MagVar:vv.v[v]>,<E/W>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Heading ---
pData->Heading = (uint32_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get and save heading <hh.h[h]> (divide by 10^2 to get the real heading)
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Magnetic Deviation ---
pData->Deviation.Value = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get track <dd.d[d]> (divide by 10^2 to get the real magnetic deviation)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != NMEA0183_FIELD_DELIMITER)
{
pData->Deviation.Direction = *pStr; //*** Get magnetic deviation direction <E/W>
++pStr; // Parsing: Skip <E/W>
}
else pData->Deviation.Direction = ' '; //*** Set magnetic deviation direction not specified
NMEA0183_CHECK_FIELD_DELIMITER;
//--- Get Magnetic Variation ---
pData->Variation.Value = (uint16_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get track <vv.v[v]> (divide by 10^2 to get the real magnetic variation)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != NMEA0183_FIELD_DELIMITER)
{
pData->Variation.Direction = *pStr; //*** Get magnetic variation direction <E/W>
++pStr; // Parsing: Skip <E/W>
}
else pData->Variation.Direction = ' '; //*** Set magnetic variation direction not specified
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_HDM
//=============================================================================
// [STATIC] Process the HDM (Heading - Magnetic) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessHDM(const char* pSentence, NMEA0183_HDMdata* pData)
{ // Format: $--HDM,<Heading:hh.h[h]>,M,<E/W>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Heading ---
pData->Heading = (uint32_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get and save heading <hh.h[h]> (divide by 10^2 to get the real heading)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'M') return ERR__PARSE_ERROR; // Parsing: Should be 'M'
++pStr;
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_HDT
//=============================================================================
// [STATIC] Process the HDT (Heading - True) sentence
//=============================================================================
static eERRORRESULT NMEA0183_ProcessHDT(const char* pSentence, NMEA0183_HDTdata* pData)
{ // Format: $--HDT,<Heading:hh.h[h]>,T,<E/W>*<CheckSum>
char* pStr = (char*)pSentence;
//--- Get Heading ---
pData->Heading = (uint32_t)__NMEA0183_StringToInt(&pStr, 0, 2); //*** Get and save heading <hh.h[h]> (divide by 10^2 to get the real heading)
NMEA0183_CHECK_FIELD_DELIMITER;
if (*pStr != 'T') return ERR__PARSE_ERROR; // Parsing: Should be 'T'
++pStr;
if (*pStr != NMEA0183_CHECKSUM_DELIMITER) return ERR__PARSE_ERROR; // Should be a '*'
return ERR_OK;
}
#endif
#ifdef NMEA0183_DECODE_MTW
//=============================================================================
// [STATIC] Process the MTW (Water Temperature) sentence