From 0f867b508a8d5c4ac89c3a902275b8407c76d39a Mon Sep 17 00:00:00 2001 From: sellensr Date: Mon, 15 Apr 2019 11:51:40 -0400 Subject: [PATCH] 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. --- Adafruit_GPS.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Adafruit_GPS.cpp b/Adafruit_GPS.cpp index 20a167b..0535d57 100755 --- a/Adafruit_GPS.cpp +++ b/Adafruit_GPS.cpp @@ -55,13 +55,14 @@ boolean Adafruit_GPS::parse(char *nmea) { // do checksum check // first look if we even have one - if (nmea[strlen(nmea)-4] == '*') { - uint16_t sum = parseHex(nmea[strlen(nmea)-3]) * 16; - sum += parseHex(nmea[strlen(nmea)-2]); + char *ast = strchr(nmea,'*'); + if (ast != NULL) { + uint16_t sum = parseHex(*(ast+1)) * 16; + sum += parseHex(*(ast+2)); // check checksum - for (uint8_t i=2; i < (strlen(nmea)-4); i++) { - sum ^= nmea[i]; + for (char *p = nmea+2; p < ast; p++) { + sum ^= *p; } if (sum != 0) { // bad checksum :(