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