parse checksum to *
Parse the NMEA checksum based on the location of the asterisk, rather than the end of the string. Avoids problems if line ends with other than CRLF.
This commit is contained in:
parent
8e17fcc9a9
commit
0f867b508a
|
|
@ -55,13 +55,14 @@ 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
|
||||||
if (nmea[strlen(nmea)-4] == '*') {
|
char *ast = strchr(nmea,'*');
|
||||||
uint16_t sum = parseHex(nmea[strlen(nmea)-3]) * 16;
|
if (ast != NULL) {
|
||||||
sum += parseHex(nmea[strlen(nmea)-2]);
|
uint16_t sum = parseHex(*(ast+1)) * 16;
|
||||||
|
sum += parseHex(*(ast+2));
|
||||||
|
|
||||||
// check checksum
|
// check checksum
|
||||||
for (uint8_t i=2; i < (strlen(nmea)-4); i++) {
|
for (char *p = nmea+2; p < ast; p++) {
|
||||||
sum ^= nmea[i];
|
sum ^= *p;
|
||||||
}
|
}
|
||||||
if (sum != 0) {
|
if (sum != 0) {
|
||||||
// bad checksum :(
|
// bad checksum :(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue