Skip to content

Commit edf18d3

Browse files
committed
Bangle.js: GPS event now works even if only GGA NMEA events are enabled (which you might do for speed)
1 parent 2bf66f0 commit edf18d3

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

libs/misc/nmea.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ bool nmea_decode(NMEAFixInfo *gpsFix, const char *nmeaLine) {
4646
char buf[NMEA_MAX_SIZE];
4747
strcpy(buf, nmeaLine);
4848
char *nmea = buf, *nextComma;
49-
bool lastWasGSV = gpsFix->lastWasGSV;
5049
bool thisIsGSV = false;
51-
gpsFix->lastWasGSV = false;
50+
bool thisIsGGA = false;
5251
if (nmea[0]=='$' && nmea[1]=='G') {
5352
if (nmea[3]=='R' && nmea[4]=='M' && nmea[5]=='C') {
5453
// $GNRMC,161945.00,A,5139.11397,N,00116.07202,W,1.530,,190919,,,A*7E
@@ -115,13 +114,14 @@ bool nmea_decode(NMEAFixInfo *gpsFix, const char *nmeaLine) {
115114
gpsFix->alt = nmea_decode_float(nmea, nextComma);
116115
nmea = nextComma+1; nextComma = nmea_next_comma(nmea);
117116
// ....
117+
thisIsGGA = true;
118118
}
119119
if (nmea[3]=='G' && nmea[4]=='S' && nmea[5]=='V') {
120120
// loads of cool data about what satellites we have and signal strength...
121121
thisIsGSV = true;
122-
gpsFix->lastWasGSV = true;
123122
}
124123
}
124+
bool createGPSEvent = false;
125125
/* When to create GPS data event?
126126
F18 (UBlox) GPS gives a bunch of data ending in GLL
127127
No fix:
@@ -153,14 +153,20 @@ bool nmea_decode(NMEAFixInfo *gpsFix, const char *nmeaLine) {
153153
$BDGSV,1,1,00,0*74
154154
155155
The thing they have in common is they have GSV, then some stuff after that
156-
we don't care about. So when that happens, trigger success
156+
we don't care about. So when that happens, trigger success.
157157
*/
158-
if (lastWasGSV && !thisIsGSV) {
158+
if (gpsFix->lastWasGSV && !thisIsGSV) { // we got something other than GSV (the item right after)
159159
// Complete set of data received
160-
return true;
160+
createGPSEvent = true;
161161
}
162-
163-
return false;
162+
if (gpsFix->lastWasGGA && thisIsGGA) { // We got two GGAs - we can do this if
163+
// Complete set of data received
164+
createGPSEvent = true;
165+
}
166+
// update info we had last
167+
gpsFix->lastWasGSV = thisIsGSV;
168+
gpsFix->lastWasGGA = thisIsGGA;
169+
return createGPSEvent;
164170
}
165171

166172

libs/misc/nmea.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef struct {
2424
uint8_t satellites; // how many satellites
2525
double hdop; // GGA HDOP - Relative accuracy of horizontal position. Multiply by 5 to get an EXTREMELY ROUGH value in meters
2626
bool lastWasGSV; // Was the last entry received $GPGSV?
27+
bool lastWasGGA; // Was the last entry received $GNGGA?
2728
} NMEAFixInfo;
2829

2930
#define NMEA_MAX_SIZE 82 // 82 is the max for NMEA

0 commit comments

Comments
 (0)