aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2018-04-14 12:00:57 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-04-14 13:38:19 -0700
commit1de4321ca133498ae2e56e86363ba46cfa61dc3f (patch)
tree9d1e2cb16d7b0f7f8e302f6af1011e0ab23eac84
parent1d95cc4cbfb229c55580b46512c9df1c5016247e (diff)
downloadsubsurface-1de4321ca133498ae2e56e86363ba46cfa61dc3f.tar.gz
GPS: untangle the timestamp comparison
And calculate the correct time since last fix. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--core/gpslocation.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp
index 9b01402bc..79a44379c 100644
--- a/core/gpslocation.cpp
+++ b/core/gpslocation.cpp
@@ -134,14 +134,20 @@ QString GpsLocation::currentPosition()
qDebug() << "current position requested";
if (!hasLocationsSource())
return tr("Unknown GPS location (no GPS source)");
- if (m_trackers.count() && m_trackers.lastKey() + 300 >= QDateTime::currentMSecsSinceEpoch() / 1000) {
- // we can simply use the last position that we tracked
- gpsTracker gt = m_trackers.last();
- QString gpsString = printGPSCoords(gt.latitude.udeg, gt.longitude.udeg);
- qDebug() << "returning last position" << gpsString;
- return gpsString;
- } else {
- qDebug() << "last position saved was too old" << QDateTime().fromMSecsSinceEpoch(m_trackers.lastKey() * 1000).toString();
+ if (m_trackers.count()) {
+ QDateTime lastFixTime = QDateTime().fromMSecsSinceEpoch((m_trackers.lastKey() - gettimezoneoffset(m_trackers.lastKey())) * 1000);
+ QDateTime now = QDateTime::currentDateTime();
+ int delta = lastFixTime.secsTo(now);
+ qDebug() << "lastFixTime" << lastFixTime.toString() << "now" << now.toString() << "delta" << delta;
+ if (delta < 300) {
+ // we can simply use the last position that we tracked
+ gpsTracker gt = m_trackers.last();
+ QString gpsString = printGPSCoords(gt.latitude.udeg, gt.longitude.udeg);
+ qDebug() << "returning last position" << gpsString;
+ return gpsString;
+ } else {
+ qDebug() << "last position saved was too old" << lastFixTime.toString();
+ }
}
qDebug() << "requesting new GPS position";
m_GpsSource->requestUpdate();
@@ -179,7 +185,7 @@ void GpsLocation::newPosition(QGeoPositionInfo pos)
gt.longitude.udeg = lrint(pos.coordinate().longitude() * 1000000);
addFixToStorage(gt);
gpsTracker gtNew = m_trackers.last();
- qDebug() << "newest fix is now at" << QDateTime().fromSecsSinceEpoch(gtNew.when).toString();
+ qDebug() << "newest fix is now at" << QDateTime().fromSecsSinceEpoch(gtNew.when - gettimezoneoffset(gtNew.when)).toString();
}
}