From 1f8c5a58d72cf179c5ddd64a411cb8a57f372d36 Mon Sep 17 00:00:00 2001 From: Rick Sellens Date: Sun, 29 Sep 2019 12:26:01 -0400 Subject: [PATCH] Change GPS time alignment Detect time first character of NMEA sentence received and treat that as corresponding to GPS timestamp in the sentence. Still some latency, but less than using the end of the receipt. --- Adafruit_GPS.cpp | 14 ++++++++++---- Adafruit_GPS.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Adafruit_GPS.cpp b/Adafruit_GPS.cpp index 963ccda..b32a501 100755 --- a/Adafruit_GPS.cpp +++ b/Adafruit_GPS.cpp @@ -103,7 +103,7 @@ boolean Adafruit_GPS::parse(char *nmea) { fixquality = atoi(p); if(fixquality > 0){ fix = true; - lastFix = recvdTime; + lastFix = sentTime; } else fix = false; } @@ -178,7 +178,7 @@ boolean Adafruit_GPS::parse(char *nmea) { day = fulldate / 10000; month = (fulldate % 10000) / 100; year = (fulldate % 100); - lastDate = recvdTime; + lastDate = sentTime; } return true; } @@ -227,7 +227,7 @@ void Adafruit_GPS::parseTime(char *p) { p = strchr(p, '.')+1; milliseconds = atoi(p); - lastTime = recvdTime; + lastTime = sentTime; } /**************************************************************************/ @@ -343,7 +343,7 @@ boolean Adafruit_GPS::parseLonDir(char *p) { boolean Adafruit_GPS::parseFix(char *p) { if (p[0] == 'A'){ fix = true; - lastFix = recvdTime; + lastFix = sentTime; } else if (p[0] == 'V') fix = false; @@ -392,6 +392,8 @@ float Adafruit_GPS::secondsSinceDate() { */ /**************************************************************************/ char Adafruit_GPS::read(void) { + static uint32_t firstChar = 0; // first character received in current sentence + uint32_t tStart = millis(); // as close as we can get to time char was sent char c = 0; if (paused) return c; @@ -434,8 +436,12 @@ char Adafruit_GPS::read(void) { lineidx = 0; recvdflag = true; recvdTime = millis(); // time we got the end of the string + sentTime = firstChar; + firstChar = 0; // there are no characters yet + return c; // wait until next character to set time } + if(firstChar == 0) firstChar = tStart; return c; } diff --git a/Adafruit_GPS.h b/Adafruit_GPS.h index 4ee45c6..a128f04 100644 --- a/Adafruit_GPS.h +++ b/Adafruit_GPS.h @@ -187,6 +187,7 @@ class Adafruit_GPS { uint32_t lastTime = 2000000000L; // millis() when last time received uint32_t lastDate = 2000000000L; // millis() when last date received uint32_t recvdTime = 2000000000L; // millis() when last full sentence received + uint32_t sentTime = 2000000000L; // millis() when first character of last full sentence received boolean paused; uint8_t parseResponse(char *response);