work with more NMEA gps sentences

This commit is contained in:
Kevin Hester 2020-10-16 14:00:17 +08:00
parent 79aea8231f
commit 2fb5cd8c1c

View File

@ -1,6 +1,6 @@
#include "NMEAGPS.h" #include "NMEAGPS.h"
#include "configuration.h"
#include "RTC.h" #include "RTC.h"
#include "configuration.h"
static int32_t toDegInt(RawDegrees d) static int32_t toDegInt(RawDegrees d)
{ {
@ -32,7 +32,7 @@ bool NMEAGPS::lookForTime()
{ {
auto ti = reader.time; auto ti = reader.time;
auto d = reader.date; auto d = reader.date;
if (ti.isUpdated() && ti.isValid() && d.isValid()) { if (ti.isValid() && d.isValid()) { // Note: we don't check for updated, because we'll only be called if needed
/* Convert to unix time /* Convert to unix time
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970
(midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
@ -65,27 +65,27 @@ bool NMEAGPS::lookForLocation()
// uint8_t fixtype = reader.fixQuality(); // uint8_t fixtype = reader.fixQuality();
// hasValidLocation = ((fixtype >= 1) && (fixtype <= 5)); // hasValidLocation = ((fixtype >= 1) && (fixtype <= 5));
if (reader.location.isUpdated()) { if (reader.satellites.isUpdated()) {
if (reader.altitude.isValid()) setNumSatellites(reader.satellites.value());
}
// Diminution of precision (an accuracy metric) is reported in 10^2 units, so we need to scale down when we use it
if (reader.hdop.isUpdated()) {
dop = reader.hdop.value();
}
if (reader.course.isUpdated()) {
heading = reader.course.value() * 1e3; // Scale the heading (in degrees * 10^-2) to match the expected degrees * 10^-5
}
if (reader.altitude.isUpdated())
altitude = reader.altitude.meters(); altitude = reader.altitude.meters();
if (reader.location.isValid()) { if (reader.location.isUpdated()) {
auto loc = reader.location.value(); auto loc = reader.location.value();
latitude = toDegInt(loc.lat); latitude = toDegInt(loc.lat);
longitude = toDegInt(loc.lng); longitude = toDegInt(loc.lng);
foundLocation = true; foundLocation = true;
}
// Diminution of precision (an accuracy metric) is reported in 10^2 units, so we need to scale down when we use it
if (reader.hdop.isValid()) {
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
}
if (reader.satellites.isValid()) {
setNumSatellites(reader.satellites.value());
}
// expect gps pos lat=37.520825, lon=-122.309162, alt=158 // expect gps pos lat=37.520825, lon=-122.309162, alt=158
DEBUG_MSG("new NMEA GPS pos lat=%f, lon=%f, alt=%d, hdop=%g, heading=%f\n", latitude * 1e-7, longitude * 1e-7, altitude, DEBUG_MSG("new NMEA GPS pos lat=%f, lon=%f, alt=%d, hdop=%g, heading=%f\n", latitude * 1e-7, longitude * 1e-7, altitude,