Merge pull request #88 from sellensr/master

Index checksum explicitly on $ and *
This commit is contained in:
Matt Goodrich 2019-04-17 13:46:39 -04:00 committed by GitHub
commit 3b01dff4c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 11 deletions

View File

@ -57,18 +57,21 @@ boolean Adafruit_GPS::parse(char *nmea) {
// do checksum check // do checksum check
// first look if we even have one // first look if we even have one
size_t len = strlen(nmea); char *ast = strchr(nmea,'*');
if (nmea[len-5] == '*') { if (ast != NULL) {
uint16_t sum = parseHex(nmea[len-4]) * 16; uint16_t sum = parseHex(*(ast+1)) * 16;
sum += parseHex(nmea[len-3]); sum += parseHex(*(ast+2));
// check checksum // check checksum
for (uint8_t i=1; i < (len-5); i++) { char *p = strchr(nmea,'$');
sum ^= nmea[i]; if(p == NULL) return false;
} else{
if (sum != 0) { for (char *p1 = p+1; p1 < ast; p1++) {
// bad checksum :( sum ^= *p1;
return false; }
if (sum != 0) {
// bad checksum :(
return false;
}
} }
} else { } else {
return false; return false;