From 8e988cc926a3523de625a05d16e51411126935a5 Mon Sep 17 00:00:00 2001 From: geeksville Date: Wed, 16 Sep 2020 09:18:44 -0700 Subject: [PATCH] fix #397 from @a-f-G-U-C - bogus GPS positions during locking could be reported btw - from my read of the NMEA, the lowest value that means 'has a valid position' is 1 not 2. But I only know this because you pointed me at it ;-) Thanks! --- src/gps/NEMAGPS.cpp | 12 +++++++++--- src/mesh/MeshService.cpp | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gps/NEMAGPS.cpp b/src/gps/NEMAGPS.cpp index a1d848ad8..b933836d0 100644 --- a/src/gps/NEMAGPS.cpp +++ b/src/gps/NEMAGPS.cpp @@ -44,6 +44,9 @@ void NEMAGPS::loop() isConnected = true; // we seem to have a real GPS (but not necessarily a lock) } + uint8_t fixtype = reader.fixQuality(); + hasValidLocation = ((fixtype >= 1) && (fixtype <= 5)); + if (reader.location.isUpdated()) { if (reader.altitude.isValid()) altitude = reader.altitude.meters(); @@ -58,18 +61,21 @@ void NEMAGPS::loop() dop = reader.hdop.value(); } if (reader.course.isValid()) { - heading = reader.course.value() * 1e3; //Scale the heading (in degrees * 10^-2) to match the expected degrees * 10^-5 + heading = + reader.course.value() * 1e3; // Scale the heading (in degrees * 10^-2) to match the expected degrees * 10^-5 } if (reader.satellites.isValid()) { numSatellites = reader.satellites.value(); } // expect gps pos lat=37.520825, lon=-122.309162, alt=158 - DEBUG_MSG("new NEMA GPS pos lat=%f, lon=%f, alt=%d, hdop=%f, heading=%f\n", latitude * 1e-7, longitude * 1e-7, altitude, dop * 1e-2, heading * 1e-5); + DEBUG_MSG("new NEMA GPS pos lat=%f, lon=%f, alt=%d, hdop=%f, heading=%f\n", latitude * 1e-7, longitude * 1e-7, + altitude, dop * 1e-2, heading * 1e-5); } // Notify any status instances that are observing us - const meshtastic::GPSStatus status = meshtastic::GPSStatus(hasLock(), isConnected, latitude, longitude, altitude, dop, heading, numSatellites); + const meshtastic::GPSStatus status = + meshtastic::GPSStatus(hasLock(), isConnected, latitude, longitude, altitude, dop, heading, numSatellites); newStatus.notifyObservers(&status); } } \ No newline at end of file diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 4b75b4ee7..c614c0866 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -299,8 +299,8 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *unused) p->decoded.which_payload = SubPacket_position_tag; Position &pos = p->decoded.position; - // !zero or !zero lat/long means valid - if (gps->latitude != 0 || gps->longitude != 0) { + + if (gps->hasLock()) { if (gps->altitude != 0) pos.altitude = gps->altitude; pos.latitude_i = gps->latitude;