Merge pull request #98 from sellensr/master

Change GPS time alignment
This commit is contained in:
Matt Goodrich 2019-09-30 09:13:58 -04:00 committed by GitHub
commit d50e0435ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -103,7 +103,7 @@ boolean Adafruit_GPS::parse(char *nmea) {
fixquality = atoi(p); fixquality = atoi(p);
if(fixquality > 0){ if(fixquality > 0){
fix = true; fix = true;
lastFix = recvdTime; lastFix = sentTime;
} else } else
fix = false; fix = false;
} }
@ -178,7 +178,7 @@ boolean Adafruit_GPS::parse(char *nmea) {
day = fulldate / 10000; day = fulldate / 10000;
month = (fulldate % 10000) / 100; month = (fulldate % 10000) / 100;
year = (fulldate % 100); year = (fulldate % 100);
lastDate = recvdTime; lastDate = sentTime;
} }
return true; return true;
} }
@ -227,7 +227,7 @@ void Adafruit_GPS::parseTime(char *p) {
p = strchr(p, '.')+1; p = strchr(p, '.')+1;
milliseconds = atoi(p); milliseconds = atoi(p);
lastTime = recvdTime; lastTime = sentTime;
} }
/**************************************************************************/ /**************************************************************************/
@ -343,7 +343,7 @@ boolean Adafruit_GPS::parseLonDir(char *p) {
boolean Adafruit_GPS::parseFix(char *p) { boolean Adafruit_GPS::parseFix(char *p) {
if (p[0] == 'A'){ if (p[0] == 'A'){
fix = true; fix = true;
lastFix = recvdTime; lastFix = sentTime;
} }
else if (p[0] == 'V') else if (p[0] == 'V')
fix = false; fix = false;
@ -392,6 +392,8 @@ float Adafruit_GPS::secondsSinceDate() {
*/ */
/**************************************************************************/ /**************************************************************************/
char Adafruit_GPS::read(void) { 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; char c = 0;
if (paused) return c; if (paused) return c;
@ -434,8 +436,12 @@ char Adafruit_GPS::read(void) {
lineidx = 0; lineidx = 0;
recvdflag = true; recvdflag = true;
recvdTime = millis(); // time we got the end of the string 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; return c;
} }

View File

@ -187,6 +187,7 @@ class Adafruit_GPS {
uint32_t lastTime = 2000000000L; // millis() when last time received uint32_t lastTime = 2000000000L; // millis() when last time received
uint32_t lastDate = 2000000000L; // millis() when last date received uint32_t lastDate = 2000000000L; // millis() when last date received
uint32_t recvdTime = 2000000000L; // millis() when last full sentence 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; boolean paused;
uint8_t parseResponse(char *response); uint8_t parseResponse(char *response);