From 75bd9d63a9dd5e51f6b15c429b61484e7af27af5 Mon Sep 17 00:00:00 2001 From: Alex Hirzel Date: Thu, 12 Mar 2020 16:40:51 -0400 Subject: [PATCH] support fractional/floating point seconds --- src/FuGPS.cpp | 15 +++++++++++++-- src/FuGPS.h | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/FuGPS.cpp b/src/FuGPS.cpp index 6b9f6af..ae009fa 100644 --- a/src/FuGPS.cpp +++ b/src/FuGPS.cpp @@ -28,6 +28,17 @@ byte FuGPS::checksum(const char * sentence) return checksum; } +void FuGPS::parseDateTime(float value, byte & val1, byte & val2, float & val3) +{ + val1 = (int)(value / 10000); + value -= val1 * 10000.0; + + val2 = (int)(value / 100); + value -= val2 * 100.0; + + val3 = value; +} + void FuGPS::parseDateTime(float value, byte & val1, byte & val2, byte & val3) { val1 = (int)(value / 10000); @@ -239,7 +250,7 @@ void FuGPS::process() #ifdef FUGPS_DEBUG rmc_counter++; #endif - float time = atoi(_tokens[1]); + float time = atof(_tokens[1]); parseDateTime(time, Hours, Minutes, Seconds); _fix = *_tokens[2] == 'A'; @@ -262,7 +273,7 @@ void FuGPS::process() #ifdef FUGPS_DEBUG gga_counter++; #endif - float time = atoi(_tokens[1]); + float time = atof(_tokens[1]); parseDateTime(time, Hours, Minutes, Seconds); Latitude = atof(_tokens[2]); diff --git a/src/FuGPS.h b/src/FuGPS.h index c0adbc9..ecd2b2f 100644 --- a/src/FuGPS.h +++ b/src/FuGPS.h @@ -82,6 +82,7 @@ class FuGPS static byte checksum(const char * sentence); static void parseDateTime(float data, byte & val1, byte & val2, byte & val3); + static void parseDateTime(float data, byte & val1, byte & val2, float & val3); static float toDecimal(float coordinate, char coordinateRef); void sendCommand(const char* command); @@ -109,7 +110,8 @@ class FuGPS // Reads one char (non blocking) bool read(); - byte Hours, Minutes, Seconds; + byte Hours, Minutes; + float Seconds; byte Days, Months, Years; // Fix Quality