fix parser when no fix

RMC and GGA sentences were no properly parsed when there was no fix.
They were assuming numeric values between commas, but you just get a
string of commas when there’s no fix. This was causing the RMC ate to
be parsed incorrectly.
This commit is contained in:
driverblock 2014-09-27 08:02:59 -04:00
parent e7a91195e5
commit 04fc848c26
1 changed files with 134 additions and 85 deletions

View File

@ -47,6 +47,8 @@ boolean Adafruit_GPS::parse(char *nmea) {
//return false; //return false;
} }
} }
int32_t degree;
long minutes;
char degreebuff[10]; char degreebuff[10];
// look for a few common sentences // look for a few common sentences
if (strstr(nmea, "$GPGGA")) { if (strstr(nmea, "$GPGGA")) {
@ -64,26 +66,34 @@ boolean Adafruit_GPS::parse(char *nmea) {
// parse out latitude // parse out latitude
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
strncpy(degreebuff, p, 2); strncpy(degreebuff, p, 2);
p += 2; p += 2;
degreebuff[2] = '\0'; degreebuff[2] = '\0';
int32_t degree = atol(degreebuff) * 10000000; degree = atol(degreebuff) * 10000000;
strncpy(degreebuff, p, 2); // minutes strncpy(degreebuff, p, 2); // minutes
p += 3; // skip decimal point p += 3; // skip decimal point
strncpy(degreebuff + 2, p, 4); strncpy(degreebuff + 2, p, 4);
degreebuff[6] = '\0'; degreebuff[6] = '\0';
long minutes = 50 * atol(degreebuff) / 3; minutes = 50 * atol(degreebuff) / 3;
latitude_fixed = degree + minutes; latitude_fixed = degree + minutes;
latitude = degree / 100000 + minutes * 0.000006F; latitude = degree / 100000 + minutes * 0.000006F;
}
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
if (p[0] == 'N') lat = 'N'; if (p[0] == 'N') lat = 'N';
else if (p[0] == 'S') lat = 'S'; else if (p[0] == 'S') lat = 'S';
else if (p[0] == ',') lat = 0; else if (p[0] == ',') lat = 0;
else return false; else return false;
}
// parse out longitude // parse out longitude
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
strncpy(degreebuff, p, 3); strncpy(degreebuff, p, 3);
p += 3; p += 3;
degreebuff[3] = '\0'; degreebuff[3] = '\0';
@ -95,27 +105,47 @@ boolean Adafruit_GPS::parse(char *nmea) {
minutes = 50 * atol(degreebuff) / 3; minutes = 50 * atol(degreebuff) / 3;
longitude_fixed = degree + minutes; longitude_fixed = degree + minutes;
longitude = degree / 100000 + minutes * 0.000006F; longitude = degree / 100000 + minutes * 0.000006F;
}
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
if (p[0] == 'W') lon = 'W'; if (p[0] == 'W') lon = 'W';
else if (p[0] == 'E') lon = 'E'; else if (p[0] == 'E') lon = 'E';
else if (p[0] == ',') lon = 0; else if (p[0] == ',') lon = 0;
else return false; else return false;
}
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
fixquality = atoi(p); fixquality = atoi(p);
}
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
satellites = atoi(p); satellites = atoi(p);
}
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
HDOP = atof(p); HDOP = atof(p);
}
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
altitude = atof(p); altitude = atof(p);
}
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
geoidheight = atof(p); geoidheight = atof(p);
}
return true; return true;
} }
if (strstr(nmea, "$GPRMC")) { if (strstr(nmea, "$GPRMC")) {
@ -143,6 +173,8 @@ boolean Adafruit_GPS::parse(char *nmea) {
// parse out latitude // parse out latitude
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
strncpy(degreebuff, p, 2); strncpy(degreebuff, p, 2);
p += 2; p += 2;
degreebuff[2] = '\0'; degreebuff[2] = '\0';
@ -154,15 +186,21 @@ boolean Adafruit_GPS::parse(char *nmea) {
long minutes = 50 * atol(degreebuff) / 3; long minutes = 50 * atol(degreebuff) / 3;
latitude_fixed = degree + minutes; latitude_fixed = degree + minutes;
latitude = degree / 100000 + minutes * 0.000006F; latitude = degree / 100000 + minutes * 0.000006F;
}
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
if (p[0] == 'N') lat = 'N'; if (p[0] == 'N') lat = 'N';
else if (p[0] == 'S') lat = 'S'; else if (p[0] == 'S') lat = 'S';
else if (p[0] == ',') lat = 0; else if (p[0] == ',') lat = 0;
else return false; else return false;
}
// parse out longitude // parse out longitude
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
strncpy(degreebuff, p, 3); strncpy(degreebuff, p, 3);
p += 3; p += 3;
degreebuff[3] = '\0'; degreebuff[3] = '\0';
@ -174,27 +212,38 @@ boolean Adafruit_GPS::parse(char *nmea) {
minutes = 50 * atol(degreebuff) / 3; minutes = 50 * atol(degreebuff) / 3;
longitude_fixed = degree + minutes; longitude_fixed = degree + minutes;
longitude = degree / 100000 + minutes * 0.000006F; longitude = degree / 100000 + minutes * 0.000006F;
}
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
if (p[0] == 'W') lon = 'W'; if (p[0] == 'W') lon = 'W';
else if (p[0] == 'E') lon = 'E'; else if (p[0] == 'E') lon = 'E';
else if (p[0] == ',') lon = 0; else if (p[0] == ',') lon = 0;
else return false; else return false;
}
// speed // speed
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
speed = atof(p); speed = atof(p);
}
// angle // angle
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
angle = atof(p); angle = atof(p);
}
p = strchr(p, ',')+1; p = strchr(p, ',')+1;
if (',' != *p)
{
uint32_t fulldate = atof(p); uint32_t fulldate = atof(p);
day = fulldate / 10000; day = fulldate / 10000;
month = (fulldate % 10000) / 100; month = (fulldate % 10000) / 100;
year = (fulldate % 100); year = (fulldate % 100);
}
// we dont parse the remaining, yet! // we dont parse the remaining, yet!
return true; return true;
} }