From 17e25babb1d6d4028bbffa1960563de963449e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 4 May 2023 11:04:43 +0200 Subject: [PATCH 1/8] probably fixes #2451 - please test --- src/gps/NMEAWPL.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 6ab2c85bf..41ebab72c 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -1,5 +1,6 @@ #include "NMEAWPL.h" #include "GeoCoord.h" +#include /* ------------------------------------------- * 1 2 3 4 5 6 @@ -56,12 +57,14 @@ uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_Position &pos, const uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos) { GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude); - uint32_t len = - snprintf(buf, bufsz, "$GNGGA,%06u.%03u,%02d%07.4f,%c,%03d%07.4f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", pos.time / 1000, - pos.time % 1000, geoCoord.getDMSLatDeg(), (abs(geoCoord.getLatitude()) - geoCoord.getDMSLatDeg() * 1e+7) * 6e-6, - geoCoord.getDMSLatCP(), geoCoord.getDMSLonDeg(), - (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, geoCoord.getDMSLonCP(), pos.fix_type, - pos.sats_in_view, pos.HDOP, geoCoord.getAltitude(), 'M', pos.altitude_geoidal_separation, 'M', 0, 0); + tm *t = localtime((time_t *)&pos.timestamp); + + uint32_t len = snprintf( + buf, bufsz, "$GNGGA,%02d%02d%02d.%02d,%02d%07.4f,%c,%03d%07.4f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", t->tm_hour, + t->tm_min, t->tm_sec, pos.timestamp_millis_adjust, geoCoord.getDMSLatDeg(), + (abs(geoCoord.getLatitude()) - geoCoord.getDMSLatDeg() * 1e+7) * 6e-6, geoCoord.getDMSLatCP(), geoCoord.getDMSLonDeg(), + (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, geoCoord.getDMSLonCP(), pos.fix_type, + pos.sats_in_view, pos.HDOP, geoCoord.getAltitude(), 'M', pos.altitude_geoidal_separation, 'M', 0, 0); uint32_t chk = 0; for (uint32_t i = 1; i < len; i++) { From 39aa756100f8126c9d22fc4d846fc144ddca7e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 5 May 2023 09:44:18 +0200 Subject: [PATCH 2/8] wrong datapoint --- src/gps/NMEAWPL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 41ebab72c..70d3d22cb 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -63,7 +63,7 @@ uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos) buf, bufsz, "$GNGGA,%02d%02d%02d.%02d,%02d%07.4f,%c,%03d%07.4f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", t->tm_hour, t->tm_min, t->tm_sec, pos.timestamp_millis_adjust, geoCoord.getDMSLatDeg(), (abs(geoCoord.getLatitude()) - geoCoord.getDMSLatDeg() * 1e+7) * 6e-6, geoCoord.getDMSLatCP(), geoCoord.getDMSLonDeg(), - (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, geoCoord.getDMSLonCP(), pos.fix_type, + (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, geoCoord.getDMSLonCP(), pos.fix_quality, pos.sats_in_view, pos.HDOP, geoCoord.getAltitude(), 'M', pos.altitude_geoidal_separation, 'M', 0, 0); uint32_t chk = 0; From cdc8bf44e997dd344bdc01728cfd7bbc1e8489ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 6 May 2023 18:10:00 +0200 Subject: [PATCH 3/8] use the device time, only use gps timestamp as a fallback. --- src/gps/NMEAWPL.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 70d3d22cb..902ba4c95 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -1,6 +1,7 @@ #include "NMEAWPL.h" #include "GeoCoord.h" #include +#include "RTC.h" /* ------------------------------------------- * 1 2 3 4 5 6 @@ -58,6 +59,9 @@ uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos) { GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude); tm *t = localtime((time_t *)&pos.timestamp); + if (getRTCQuality() > 0) // use the device clock if we got time from somewhere. If not, use the GPS timestamp. + t = localtime((time_t *)getValidTime(RTCQuality::RTCQualityDevice)); + uint32_t len = snprintf( buf, bufsz, "$GNGGA,%02d%02d%02d.%02d,%02d%07.4f,%c,%03d%07.4f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", t->tm_hour, From 694fd04367c0fc0aa4c8f67669047d8d8b361d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 4 May 2023 11:04:43 +0200 Subject: [PATCH 4/8] probably fixes #2451 - please test --- src/gps/NMEAWPL.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 6ab2c85bf..41ebab72c 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -1,5 +1,6 @@ #include "NMEAWPL.h" #include "GeoCoord.h" +#include /* ------------------------------------------- * 1 2 3 4 5 6 @@ -56,12 +57,14 @@ uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_Position &pos, const uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos) { GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude); - uint32_t len = - snprintf(buf, bufsz, "$GNGGA,%06u.%03u,%02d%07.4f,%c,%03d%07.4f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", pos.time / 1000, - pos.time % 1000, geoCoord.getDMSLatDeg(), (abs(geoCoord.getLatitude()) - geoCoord.getDMSLatDeg() * 1e+7) * 6e-6, - geoCoord.getDMSLatCP(), geoCoord.getDMSLonDeg(), - (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, geoCoord.getDMSLonCP(), pos.fix_type, - pos.sats_in_view, pos.HDOP, geoCoord.getAltitude(), 'M', pos.altitude_geoidal_separation, 'M', 0, 0); + tm *t = localtime((time_t *)&pos.timestamp); + + uint32_t len = snprintf( + buf, bufsz, "$GNGGA,%02d%02d%02d.%02d,%02d%07.4f,%c,%03d%07.4f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", t->tm_hour, + t->tm_min, t->tm_sec, pos.timestamp_millis_adjust, geoCoord.getDMSLatDeg(), + (abs(geoCoord.getLatitude()) - geoCoord.getDMSLatDeg() * 1e+7) * 6e-6, geoCoord.getDMSLatCP(), geoCoord.getDMSLonDeg(), + (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, geoCoord.getDMSLonCP(), pos.fix_type, + pos.sats_in_view, pos.HDOP, geoCoord.getAltitude(), 'M', pos.altitude_geoidal_separation, 'M', 0, 0); uint32_t chk = 0; for (uint32_t i = 1; i < len; i++) { From e1c4968c58e60cdf20d4023972b0f0bb16e3c68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 5 May 2023 09:44:18 +0200 Subject: [PATCH 5/8] wrong datapoint --- src/gps/NMEAWPL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 41ebab72c..70d3d22cb 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -63,7 +63,7 @@ uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos) buf, bufsz, "$GNGGA,%02d%02d%02d.%02d,%02d%07.4f,%c,%03d%07.4f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", t->tm_hour, t->tm_min, t->tm_sec, pos.timestamp_millis_adjust, geoCoord.getDMSLatDeg(), (abs(geoCoord.getLatitude()) - geoCoord.getDMSLatDeg() * 1e+7) * 6e-6, geoCoord.getDMSLatCP(), geoCoord.getDMSLonDeg(), - (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, geoCoord.getDMSLonCP(), pos.fix_type, + (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, geoCoord.getDMSLonCP(), pos.fix_quality, pos.sats_in_view, pos.HDOP, geoCoord.getAltitude(), 'M', pos.altitude_geoidal_separation, 'M', 0, 0); uint32_t chk = 0; From 9b6ac98ae0d41023e1d8ccb517098d0fa601cdaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 6 May 2023 18:10:00 +0200 Subject: [PATCH 6/8] use the device time, only use gps timestamp as a fallback. --- src/gps/NMEAWPL.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 70d3d22cb..902ba4c95 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -1,6 +1,7 @@ #include "NMEAWPL.h" #include "GeoCoord.h" #include +#include "RTC.h" /* ------------------------------------------- * 1 2 3 4 5 6 @@ -58,6 +59,9 @@ uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos) { GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude); tm *t = localtime((time_t *)&pos.timestamp); + if (getRTCQuality() > 0) // use the device clock if we got time from somewhere. If not, use the GPS timestamp. + t = localtime((time_t *)getValidTime(RTCQuality::RTCQualityDevice)); + uint32_t len = snprintf( buf, bufsz, "$GNGGA,%02d%02d%02d.%02d,%02d%07.4f,%c,%03d%07.4f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", t->tm_hour, From 81bfd69a41542a22707066b0214aca81d98e8f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 6 May 2023 18:13:52 +0200 Subject: [PATCH 7/8] fmt --- src/gps/NMEAWPL.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 902ba4c95..cf158d993 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -1,7 +1,7 @@ #include "NMEAWPL.h" #include "GeoCoord.h" -#include #include "RTC.h" +#include /* ------------------------------------------- * 1 2 3 4 5 6 @@ -61,7 +61,6 @@ uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos) tm *t = localtime((time_t *)&pos.timestamp); if (getRTCQuality() > 0) // use the device clock if we got time from somewhere. If not, use the GPS timestamp. t = localtime((time_t *)getValidTime(RTCQuality::RTCQualityDevice)); - uint32_t len = snprintf( buf, bufsz, "$GNGGA,%02d%02d%02d.%02d,%02d%07.4f,%c,%03d%07.4f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", t->tm_hour, From b4ff37104a58792f8a5c3519d061880af3f9d791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 6 May 2023 23:16:39 +0200 Subject: [PATCH 8/8] fix NMEA Timestamp for good --- src/gps/NMEAWPL.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index cf158d993..ac11d78f8 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -59,8 +59,10 @@ uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos) { GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude); tm *t = localtime((time_t *)&pos.timestamp); - if (getRTCQuality() > 0) // use the device clock if we got time from somewhere. If not, use the GPS timestamp. - t = localtime((time_t *)getValidTime(RTCQuality::RTCQualityDevice)); + if (getRTCQuality() > 0) { // use the device clock if we got time from somewhere. If not, use the GPS timestamp. + uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice); + t = localtime((time_t *)&rtc_sec); + } uint32_t len = snprintf( buf, bufsz, "$GNGGA,%02d%02d%02d.%02d,%02d%07.4f,%c,%03d%07.4f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", t->tm_hour,