-
Notifications
You must be signed in to change notification settings - Fork 9
/
nmea.c
1518 lines (1282 loc) · 41.3 KB
/
nmea.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
#include <time.h>
#include <stdio.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "nmea.h"
#include "consts.h"
#include "structs.h"
#include "globals.h"
#include "FwInter.h"
#include "serport.h"
/*extern char gSimulate;*/
/***********************************************************************
// Clifford Kelley <cwkelley@earthlink.net>
// This program is licensed under GNU GENERAL PUBLIC LICENSE
Version 0.7 3/13/04
1.) Added Geoidal Seperation to GGA. Hard coded to 0.0
2.) Set Mode to A in GAS
Version 0.6 2/26/04 Removed channels structure definition
Version 0.5 2/22/04 Fixed bug in checksum routine
Version 0.4 Added baud rate selection and NMEA sentence
selection capablity
Version 0.3 Turned off hardware flow control
Version 0.2 Fixed SV in view bug
Version 0.1 Initial release
***********************************************************************/
void
SendNMEA (void)
{
if (GPGGA != 0)
NMEASendGPGGA (); /* NMEA, use sentance options */
if (GPGSA != 0)
NMEASendGPGSA ();
if (GPGSV != 0)
NMEASendGPGSV ();
if (GPRMC != 0)
NMEASendGPRMC ();
if (GPZDA != 0)
NMEASendGPZDA ();
}
/**
* NMEA Notes
*
* Longitude and latitude can be expressed in several different
* representations:
*
* dms (deg,min,sec) - Degrees, minutes and seconds format
* (e.g. 5045'23.99")
*
* degrees - Decimal degrees (e.g. 50.7567)
*
* radians - Radians (e.g. 0.88587090)
*
* degrees, minutes - Degrees and minutes format (e.g. 5045.3998')
*
* Select the appropriate representation found in the string files
*
* Converting Between Decimal Degrees, Degrees, Minutes and Seconds,
* and Radians (dd + mm/60 +ss/3600) to Decimal degrees (dd.ff)
*
* dd = whole degrees, mm = minutes, ss = seconds
*
* dd.ff = dd + mm/60 + ss/3600
*
* Example: 30 degrees 15 minutes 22 seconds = 30 + 15/60 +
* 22/3600 = 30.2561
*
* Decimal degrees (dd.ff) to (dd + mm/60 +ss/3600)
*
* For the reverse conversion, we want to convert dd.ff to dd mm
* ss. Here ff = the fractional part of a decimal degree.
*
* mm = 60*ff
*
* ss = 60*(fractional part of mm)
*
* Use only the whole number part of mm in the final result.
*
* 30.2561 degrees = 30 degrees
*
* .2561*60 = 15.366 minutes
*
* .366 minutes = 22 seconds, so the final result is 30 degrees 15
* minutes 22 seconds
*
* Decimal degrees (dd.ff) to Radians
*
* Radians = (dd.ff)*pi/180
*
* Radians to Decimal degrees (dd.ff)
*
* (dd.ff) = Radians*180/pi
*
* Degrees, Minutes and Seconds to Distance
*
* A degree of longitude at the equator is 111.2 kilometers. A minute
* is 1853 meters. A second is 30.9 meters. For other latitudes
* multiply by cos(lat). Distances for degrees, minutes and seconds in
* latitude are very similar and differ very slightly with latitude.
* (Before satellites, observing those differences was a principal
* method for determining the exact shape of the earth.)
*
*
* D = Degrees
* M = Minutes
* S = Seconds
* .m = Decimal Minutes
* .s = Decimal Seconds
*
* DM.m = Degrees, Minutes, Decimal Minutes (eg. 45 22.6333)
* D.d = Degrees, Decimal Degrees (eg. 45.3772)
* DMS = Degrees, Minutes, Seconds (eg. 45 22'38")
*
* Process for Converting Latitude/Longitude Coordinates:
*
* 1) DMS --> DM.m (45o22'38" --> 45o22.6333)
*
* - Divide S by 60 to get .m (38/60=.6333)
* - Add .m to M to get M.m (22+.6333=22.6333)
*
* 2) DM.m --> D.d (45o 22.6333 --> 45.3772)
*
* - Divide M.m by 60 to get .d (22.6333/60=.3772)
* - Add .d to D to get D.d (45+.3772=45.3772)
*
* 3) D.d --> DM.m ( 45.3772 --> 45 22.6333)
*
* - Multiply .d by 60 to get M.m (.3772 * 60 = 22.6333)
*
* 4) DM.m --> DMS (45o22.6333 --> 45 22'38")
*
* - Multiply .m by 60 to get S(.6333*60=38)
*
*
* Converting Degrees, Minutes, Seconds to Decimal Format
*
* latitude and longitude in a decimal format: 42.1361
*
* latitude and longitude in degree, minute, second format: 42deg,
* 08min, 10sec
*
* To convert coordinates from degrees, minutes, seconds format to
* decimal format, use this easy formula:
*
* degrees + (minutes/60) +
* (seconds/3600)
*
* The example coordinate above would be
* calculated as:
* 42 + (8/60) + (10/3600) = 42.1361
* or
* 42 + (.1333) + (.0028) = 42.1361
*
*
**/
void
NMEAAddCRLF (char *TransmitBuffer, int *TXBufferIndex)
{
char *TempPtr = TransmitBuffer + *TXBufferIndex;
*TempPtr++ = 0x0D;
*TempPtr++ = 0x0A;
/**
* Update the index.
**/
*TXBufferIndex += 2;
*TempPtr++ = '\0';
}
void
NMEAAddField (char *TransmitBuffer, int *TXBufferIndex, char *StringToAdd)
{
int NumberOfChars = 0;
NumberOfChars = strlen (StringToAdd);
/**
* Copy the data.
**/
memcpy (&TransmitBuffer[*TXBufferIndex], StringToAdd, NumberOfChars);
/**
* Update the index.
**/
*TXBufferIndex += NumberOfChars;
}
double
ConvertLatLonFromDegreestoDegreesMinutes (double PositionDegrees)
{
double Degrees = (int) PositionDegrees;
double Minutes = PositionDegrees - Degrees;
double DegreesMinutes = Minutes * 60 + (Degrees * 10 * 10);
return DegreesMinutes;
}
/**
* The checksum is the 8-bit exclusive OR (no start or stop bits) of
* all characters in the sentence, including the "," delimiters,
* between -- but not including -- the "$" and "*" delimiters.
*
* The hexadecimal value of the most significant and least significant
* 4 bits of the result are converted to two ASCII characters (0-9,
* A-F) for transmission. The most significant character is
* transmitted first.
**/
unsigned char
CalculateNmeaCheckSum (char *NmeaSentence)
{
int Index;
unsigned char NmeaCheckSum = 0;
for (Index = 1; NmeaSentence[Index] != '*'; Index++)
{
NmeaCheckSum ^= NmeaSentence[Index];
}
return NmeaCheckSum;
}
void
NMEAAddCheckSum (char *TransmitBuffer, int *TXBufferIndex)
{
unsigned char CheckSum;
unsigned char TXCheckSum;
char TempBuf[10];
NMEAAddField (TransmitBuffer, TXBufferIndex, NMEA_SENTENCE_ASTERISK);
CheckSum = CalculateNmeaCheckSum (TransmitBuffer);
TXCheckSum = CheckSum & 0xf0;
TempBuf[0] = (TXCheckSum >> 4) + '0';
TempBuf[1] = '\0';
if (TempBuf[0] > '9')
{
TempBuf[0] += 'A' - ('9' + 1);
TempBuf[1] = '\0';
}
NMEAAddField (TransmitBuffer, TXBufferIndex, TempBuf);
TXCheckSum = CheckSum & 0x0f;
TempBuf[0] = (TXCheckSum & 0xf) + '0';
TempBuf[1] = '\0';
if (TempBuf[0] > '9')
{
TempBuf[0] += 'A' - ('9' + 1);
TempBuf[1] = '\0';
}
NMEAAddField (TransmitBuffer, TXBufferIndex, TempBuf);
}
NMEA_STATUS
NMEAGetGPGGAData (pNMEA_GGA_DATA pNmeaGGAData)
{
/**
* Need to convert from degrees to degrees and minutes format.
**/
pNmeaGGAData->TimeOfFixUTC = GetTimeOfFixUTC ();
pNmeaGGAData->Lat =
ConvertLatLonFromDegreestoDegreesMinutes (GetLatitudeAbs ());
pNmeaGGAData->NorthSouth = GetNorthSouth ();
pNmeaGGAData->Long =
ConvertLatLonFromDegreestoDegreesMinutes (GetLongitudeAbs ());
pNmeaGGAData->EastWest = GetEastWest ();
pNmeaGGAData->FixQuality = GetFixQuality ();
pNmeaGGAData->NumberOfTrackingSV = GetNumberOfTrackingSVs ();
pNmeaGGAData->HDOP = GetHDOP ();
pNmeaGGAData->Altitude = GetAltitude ();
pNmeaGGAData->HeightOfGeoid = GetHeightOfGeoid ();
return NMEA_SUCCESS;
}
/**
* GGA - essential fix data which provide 3D location and accuracy data.
*
* $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
*
* Where:
* GGA Global Positioning System Fix Data
* 123519 Fix taken at 12:35:19 UTC
* 4807.038,N Latitude 48 deg 07.038' N
* 01131.000,E Longitude 11 deg 31.000' E
* 1 Fix quality: 0 = invalid
* 1 = GPS fix (SPS)
* 2 = DGPS fix
* 3 = PPS fix
* 4 = Real Time Kinematic
* 5 = Float RTK
* 6 = estimated (dead reckoning) (2.3 feature)
* 7 = Manual input mode
* 8 = Simulation mode
* 08 Number of satellites being tracked
* 0.9 Horizontal dilution of position
* 545.4,M Altitude, Meters, above mean sea level
* 46.9,M Height of geoid (mean sea level) above WGS84 ellipsoid
* (empty field) time in seconds since last DGPS update
* (empty field) DGPS station ID number
* *47 the checksum data, always begins with *
*
* If the height of geoid is missing then the altitude should be suspect.
*
* Some non-standard implementations report altitude with respect to
* the ellipsoid rather than geoid altitude. Some units do not report
* negative altitudes at all. This is the only sentence that reports
* altitude.
*
**/
NMEA_STATUS
NMEASendGPGGA (void)
{
NMEA_GGA_DATA NmeaGGAData;
char pFieldBuffer[MAX_NMEA_FIELD];
int TXBufferIndex = 0;
char TransmitBuffer[MAX_NMEA_BUFFER];
memset (TransmitBuffer, 0, MAX_NMEA_BUFFER);
/**
* Get the necessary data from the FW.
**/
NMEAGetGPGGAData (&NmeaGGAData);
/**
* Add the header
**/
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_START);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_GPGGA);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 0 Time
*
* The time field must be 6 digits long. If the hour is less than 10 you
* must pad it with an extra zero.
**/
sprintf (pFieldBuffer, "%06ld.00", (long) NmeaGGAData.TimeOfFixUTC);
/* ftod( NmeaGGAData.TimeOfFixUTC, pFieldBuffer ); */
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 1 Latitude
**/
ftod4 (NmeaGGAData.Lat, pFieldBuffer); /* 4 decimal places */
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 2 North/South
**/
if (NmeaGGAData.NorthSouth == NMEA_SOUTH)
{
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_SOUTH);
}
else
{
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_NORTH);
}
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 3 Longitude
**/
ftod4 (NmeaGGAData.Long, pFieldBuffer); /* 4 decimal places */
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 4 East/West
**/
if (NmeaGGAData.EastWest == NMEA_WEST)
{
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_WEST);
}
else
{
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_EAST);
}
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 5 Fix Quality
**/
sprintf (pFieldBuffer, "%d", NmeaGGAData.FixQuality);
/* ftod( NmeaGGAData.FixQuality, pFieldBuffer ); */
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 6 Number of SV's used.
**/
sprintf (pFieldBuffer, "%02d", NmeaGGAData.NumberOfTrackingSV);
/*itoa( NmeaGGAData.NumberOfTrackingSV, pFieldBuffer, 10 );*/
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 7 HDOP
**/
ftodPrecision1 (NmeaGGAData.HDOP, pFieldBuffer);
/* ftod( NmeaGGAData.HDOP, pFieldBuffer ); */
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 8 Altitude
**/
ftodPrecision1 (NmeaGGAData.Altitude, pFieldBuffer);
/* ftod( NmeaGGAData.Altitude, pFieldBuffer ); */
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 9 Altitude Units
**/
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_UNITS_METERS);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 10 Geoid Seperation ( Height of geoid above WGS84 ellipsoid )
**/
ftodPrecision1 (0.0, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 11 Geoid Seperation units
**/
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_UNITS_METERS);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 12 DGPS Age
**/
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 12 DGPS StationID
**/
/**
* Check Sum
**/
NMEAAddCheckSum (TransmitBuffer, &TXBufferIndex);
/**
* CR/LF
**/
NMEAAddCRLF (TransmitBuffer, &TXBufferIndex);
/**
* Now send the sentence.
**/
if (!ComPortWrite ((unsigned char *) &TransmitBuffer[0], TXBufferIndex))
{
return NMEA_FAILED;
}
else
{
return NMEA_SUCCESS;
}
}
NMEA_STATUS
NMEAGetGPGSAData (pNMEA_GSA_DATA pNmeaGSVData)
{
int i;
TRACKING_PRNs TrackingPRNs[12];
memset (TrackingPRNs, 0, sizeof (TrackingPRNs));
pNmeaGSVData->Mode = NMEA_MODE_A; /* Cliff */
if (GetNavStatus ())
{
pNmeaGSVData->FixMode = NMEA_FIX_MODE_3D_FIX;
}
else
{
pNmeaGSVData->FixMode = NMEA_FIX_MODE_NO_FIX;
}
/* if (gSimulate)
{
pNmeaGSVData->FixMode = NMEA_FIX_MODE_3D_FIX;
} */
GetTrackingPRNs (&TrackingPRNs[0]);
for (i = 0; i < 11; i++)
{
pNmeaGSVData->PRNs[i] = TrackingPRNs[i].PRN;
}
/* if (gSimulate)
{
pNmeaGSVData->PRNs[0] = 7;
pNmeaGSVData->PRNs[1] = 9;
pNmeaGSVData->PRNs[2] = 24;
pNmeaGSVData->PRNs[3] = 4;
} */
pNmeaGSVData->PDOP = GetPDOP (); /* ( float )2.5; */
pNmeaGSVData->HDOP = GetHDOP (); /* ( float )1.3; */
pNmeaGSVData->VDOP = GetVDOP (); /* ( float )2.1; */
return NMEA_SUCCESS;
}
/**
* GSA - GPS DOP and active satellites
**/
/**
* GSA - GPS DOP and active satellites. This sentence provides details
* on the nature of the fix. It includes the numbers of the
* satellites being used in the current solution and the DOP. DOP
* (dilution of precision) is an indication of the effect of satellite
* geometry on the accuracy of the fix. It is a unitless number where
* smaller is better. For 3D fixes using 4 satellites a 1.0 would be
* considered to be a perfect number, however for overdetermined
* solutions it is possible to see numbers below 1.0.
*
* There are differences in the way the PRN's are presented which
* can effect the ability of some programs to display this data. For
* example, in the example shown below there are 5 satellites in the
* solution and the null fields are scattered indicating that the
* almanac would show satellites in the null positions that are not
* being used as part of this solution. Other receivers might output
* all of the satellites used at the beginning of the sentence with
* the null field all stacked up at the end. This difference accounts
* for some satellite display programs not always being able to
* display the satellites being tracked. Some units may show all
* satellites that have ephemeris data without regard to their use as
* part of the solution but this is non-standard.
*
* $GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39
*
* Where:
* GSA Satellite status
* A Auto selection of 2D or 3D fix (M = manual)
* 3 3D fix - values include: 1 = no fix
* 2 = 2D fix
* 3 = 3D fix
* 04,05... PRNs of satellites used for fix (space for 12)
* 2.5 PDOP (dilution of precision)
* 1.3 Horizontal dilution of precision (HDOP)
* 2.1 Vertical dilution of precision (VDOP)
* *39 the checksum data, always begins with *
*
**/
NMEA_STATUS
NMEASendGPGSA (void)
{
NMEA_GSA_DATA NmeaGSAData;
char pFieldBuffer[MAX_NMEA_FIELD];
int i, TXBufferIndex = 0;
char TransmitBuffer[MAX_NMEA_BUFFER];
memset (TransmitBuffer, 0, MAX_NMEA_BUFFER);
/**
* Get the necessary data from the FW.
**/
memset (&NmeaGSAData, 0, sizeof (NMEA_GSA_DATA));
NMEAGetGPGSAData (&NmeaGSAData);
/**
* Add the header
**/
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_START);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_GPGSA);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 0 Mode
**/
if (NmeaGSAData.Mode == NMEA_MODE_A)
{
strcpy (pFieldBuffer, NMEA_MODE_A_STR);
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
}
else if (NmeaGSAData.Mode == NMEA_MODE_M)
{
strcpy (pFieldBuffer, NMEA_MODE_M_STR);
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
}
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 1 FixMode
**/
sprintf (pFieldBuffer, "%d", NmeaGSAData.FixMode);
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Now the satellites
**/
for (i = 0; i < 12; i++)
{
if (NmeaGSAData.PRNs[i])
{
sprintf (pFieldBuffer, "%02d", NmeaGSAData.PRNs[i]);
/* itoa( NmeaGSAData.PRNs[ i ], pFieldBuffer, 10 ); */
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
}
else
{
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
}
}
/**
* PDOP
**/
ftoa (NmeaGSAData.PDOP, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* HDOP
**/
ftoa (NmeaGSAData.HDOP, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* VDOP
**/
ftoa (NmeaGSAData.VDOP, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
/* NMEAAddField( TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA );*/
/**
* Check Sum
**/
NMEAAddCheckSum (TransmitBuffer, &TXBufferIndex);
/**
* CR/LF
**/
NMEAAddCRLF (TransmitBuffer, &TXBufferIndex);
/**
* Now send the sentence.
**/
if (!ComPortWrite ((unsigned char *) &TransmitBuffer[0], TXBufferIndex))
{
return NMEA_FAILED;
}
else
{
return NMEA_SUCCESS;
}
}
NMEA_STATUS
NMEAGetGPGSVData (pNMEA_GSV_DATA pNmeaGSVData)
{
int Satellite;
pVISIBLE_SV_DATA pVisibleSVData;
pNmeaGSVData->NumberOfSatellites = GetNumberOfVisibleSVs ();
/**
* Calculate the number of sentences.
**/
if (pNmeaGSVData->NumberOfSatellites <= 4)
{
pNmeaGSVData->NumberOfSentences = 1;
}
else
{
pNmeaGSVData->NumberOfSentences = pNmeaGSVData->NumberOfSatellites / 4;
if (pNmeaGSVData->NumberOfSatellites % 4)
{
pNmeaGSVData->NumberOfSentences += 1;
}
}
pVisibleSVData = GetVisibleSVData ();
for (Satellite = 0; Satellite < pNmeaGSVData->NumberOfSatellites;
Satellite++)
{
pNmeaGSVData->SvViewData[Satellite].Valid = 1;
/* pNmeaGSVData->SvViewData[ Satellite ].Azimuth = pVisibleSVData[ Satellite ].azimuth; */
if (pVisibleSVData[Satellite].azimuth < 0)
{
pNmeaGSVData->SvViewData[Satellite].Azimuth =
180 + (180 - ((abs (pVisibleSVData[Satellite].azimuth))));
}
else
{
pNmeaGSVData->SvViewData[Satellite].Azimuth =
pVisibleSVData[Satellite].azimuth;
}
pNmeaGSVData->SvViewData[Satellite].Elevation =
pVisibleSVData[Satellite].elevation;
pNmeaGSVData->SvViewData[Satellite].SatellitePRN =
pVisibleSVData[Satellite].PRN;
pNmeaGSVData->SvViewData[Satellite].SNR = pVisibleSVData[Satellite].CNo;
}
return NMEA_SUCCESS;
}
/**
* GSV - Satellites in View shows data about the satellites that the
* unit might be able to find based on its viewing mask and almanac
* data. It also shows current ability to track this data. Note that
* one GSV sentence only can provide data for up to 4 satellites and
* thus there may need to be 3 sentences for the full information. It
* is reasonable for the GSV sentence to contain more satellites than
* GGA might indicate since GSV may include satellites that are not
* used as part of the solution. It is not a requirment that the GSV
* sentences all appear in sequence. To avoid overloading the data
* bandwidth some receivers may place the various sentences in totally
* different samples since each sentence identifies which one it is.
*
* The field called SNR (Signal to Noise Ratio) in the NMEA standard
* is often referred to as signal strength. SNR is an indirect but
* more useful value that raw signal strength. It can range from 0 to
* 99 and has units of dB according to the NMEA standard, but the
* various manufacturers send different ranges of numbers with
* different starting numbers so the values themselves cannot
* necessarily be used to evaluate different units. The range of
* working values in a given gps will usually show a difference of
* about 25 to 35 between the lowest and highest values, however 0 is
* a special case and may be shown on satellites that are in view but
* not being tracked.
*
*
* $GPGSV,2,1,08,01,40,083,46,02,17,308,41,12,07,344,39,14,22,228,45*75
*
* Where:
* GSV Satellites in view
* 2 Number of sentences for full data
* 1 sentence 1 of 2
* 08 Number of satellites in view
*
* 01 Satellite PRN number
* 40 Elevation, degrees
* 083 Azimuth, degrees
* 46 SNR - higher is better
* for up to 4 satellites per sentence
* *75 the checksum data, always begins with *
*
**/
NMEA_STATUS
NMEASendGPGSV (void)
{
NMEA_GSV_DATA NmeaGSVData;
char pFieldBuffer[MAX_NMEA_FIELD];
int TXBufferIndex = 0;
char TransmitBuffer[MAX_NMEA_BUFFER];
TRACKING_PRNs TrackingPRNs[12];
int Satellite = 0;
int SequenceNumber;
int NumSatelliteThisSentence;
memset (TransmitBuffer, 0, MAX_NMEA_BUFFER);
memset (&NmeaGSVData, 0, sizeof (NMEA_GSV_DATA));
/**
* Get the necessary data from the FW.
**/
NMEAGetGPGSVData (&NmeaGSVData);
GetTrackingPRNs (&TrackingPRNs[0]);
for (SequenceNumber = 0; SequenceNumber < NmeaGSVData.NumberOfSentences;
SequenceNumber++)
{
TXBufferIndex = 0;
/**
* Add the header
**/
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_START);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_GPGSV);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 0 Number of sentences for full data
**/
sprintf (pFieldBuffer, "%d", NmeaGSVData.NumberOfSentences);
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 1 SequenceNumber
**/
sprintf (pFieldBuffer, "%d", SequenceNumber + 1);
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Field 2 Number of satellites in view
**/
sprintf (pFieldBuffer, "%02d", NmeaGSVData.NumberOfSatellites);
/*itoa( NmeaGSVData.NumberOfSatellites, pFieldBuffer, 10 );*/
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex, NMEA_SENTENCE_COMMA);
/**
* Now add the satellite data.
**/
for (NumSatelliteThisSentence = 0; NumSatelliteThisSentence < 4;
NumSatelliteThisSentence++)
{
if (NmeaGSVData.SvViewData[Satellite].Valid)
{
int i;
/**
* PRN
**/
sprintf (pFieldBuffer, "%02d",
NmeaGSVData.SvViewData[Satellite].SatellitePRN);
/* itoa( NmeaGSVData.SvViewData[ Satellite ].SatellitePRN, pFieldBuffer, 10 ); */
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex,
NMEA_SENTENCE_COMMA);
/**
* Elevation
**/
sprintf (pFieldBuffer, "%02d",
NmeaGSVData.SvViewData[Satellite].Elevation);
/*itoa( NmeaGSVData.SvViewData[ Satellite ].Elevation, pFieldBuffer, 10 );*/
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex,
NMEA_SENTENCE_COMMA);
/**
* Azimuth Needs to be 0 - 360
**/
sprintf (pFieldBuffer, "%03d",
NmeaGSVData.SvViewData[Satellite].Azimuth);
/* itoa( NmeaGSVData.SvViewData[ Satellite ].Azimuth, pFieldBuffer, 10 ); */
NMEAAddField (TransmitBuffer, &TXBufferIndex, pFieldBuffer);
NMEAAddField (TransmitBuffer, &TXBufferIndex,
NMEA_SENTENCE_COMMA);
/**
* SNR
*
*
* If we are not tracking then do not display
* the SNR.
**/
for (i = 0; i < 11; i++)
{
/**
* See if we are tracking this guy.
**/
if ((unsigned)
NmeaGSVData.SvViewData[Satellite].SatellitePRN ==
TrackingPRNs[i].PRN)
{
sprintf (pFieldBuffer, "%02d",
NmeaGSVData.SvViewData[Satellite].SNR);
NMEAAddField (TransmitBuffer, &TXBufferIndex,
pFieldBuffer);
break;
}
}
if (NumSatelliteThisSentence < 3)
{
NMEAAddField (TransmitBuffer, &TXBufferIndex,
NMEA_SENTENCE_COMMA);
}
}
else
{
NMEAAddField (TransmitBuffer, &TXBufferIndex,
NMEA_SENTENCE_COMMA);
NMEAAddField (TransmitBuffer, &TXBufferIndex,
NMEA_SENTENCE_COMMA);
NMEAAddField (TransmitBuffer, &TXBufferIndex,
NMEA_SENTENCE_COMMA);
if (NumSatelliteThisSentence < 3)
{
NMEAAddField (TransmitBuffer, &TXBufferIndex,
NMEA_SENTENCE_COMMA);
}
}
Satellite++;
/*SequenceNumber++; */
}
/**
* Check Sum
**/
NMEAAddCheckSum (TransmitBuffer, &TXBufferIndex);
/**
* CR/LF
**/
NMEAAddCRLF (TransmitBuffer, &TXBufferIndex);
/**
* Now send the sentence.
**/
if (!ComPortWrite ((unsigned char *) &TransmitBuffer[0], TXBufferIndex))
{
return NMEA_FAILED;
}
memset (TransmitBuffer, 0, MAX_NMEA_BUFFER);
}
return NMEA_SUCCESS;
}
/**
*
* RMC - NMEA has its own version of essential gps pvt (position,
* velocity, time) data. It is called RMC, The Recommended Minimum,
* which will look similar to:
*
* $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
*
* Where:
* RMC Recommended Minimum sentence C
* 123519 Fix taken at 12:35:19 UTC
* A Status A=active or V=Void.
* 4807.038,N Latitude 48 deg 07.038' N
* 01131.000,E Longitude 11 deg 31.000' E
* 022.4 Speed over the ground in knots
* 084.4 Track angle in degrees True
* 230394 Date - 23rd of March 1994
* 003.1,W Magnetic Variation
* *6A The checksum data, always begins with *
*
*
**/