From 8bad5eacfb5aefc15ad3f81ab4db38fd1004d3b7 Mon Sep 17 00:00:00 2001 From: sellensr Date: Mon, 15 Apr 2019 13:50:37 -0400 Subject: [PATCH] tidy lines and checksum Parse start of checksum as character after first $. Don't include '\n' or '\r' in GPS lines read. Previous code was putting '\r' at the end of each line and '\n' at the start before the $, thus having to start the checksum calculation at the third character. This may break the spacing on some code that prints out the NMEA lines. --- Adafruit_GPS.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_GPS.cpp b/Adafruit_GPS.cpp index 0535d57..c1891d0 100755 --- a/Adafruit_GPS.cpp +++ b/Adafruit_GPS.cpp @@ -61,7 +61,7 @@ boolean Adafruit_GPS::parse(char *nmea) { sum += parseHex(*(ast+2)); // check checksum - for (char *p = nmea+2; p < ast; p++) { + for (char *p = strchr(nmea,'$')+1; p < ast; p++) { sum ^= *p; } if (sum != 0) { @@ -414,7 +414,7 @@ char Adafruit_GPS::read(void) { recvdflag = true; } - currentline[lineidx++] = c; + if(c != '\n' && c != '\r') currentline[lineidx++] = c; if (lineidx >= MAXLINELENGTH) lineidx = MAXLINELENGTH-1;