summaryrefslogtreecommitdiff
path: root/src/plugins/position/geoclue
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@jollamobile.com>2014-02-04 13:45:23 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-04 13:31:36 +0100
commitbe48e390962413258d9c310fbf226759c1229f78 (patch)
tree36aca95675e1329b831ac4203a318b356b75f457 /src/plugins/position/geoclue
parentacba4e0b3341b081ec1b8a4aba7a0c2639e7b2bf (diff)
downloadqtlocation-be48e390962413258d9c310fbf226759c1229f78.tar.gz
Report direction and vertical speed with Geoclue plugin.
Geoclude provides both direction and vertical speed information with the velocity interface. These values were previously being ignored. [ChangeLog][QtPositioning][Geoclue] The Geoclue plugin now reports direction of travel and vertical speed attributes, if supported by the active Geoclue provider. Task-number: QTBUG-36298 Change-Id: I9f99a64f3c2bd78a06a6c60e0ef3af6f75223e9f Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/plugins/position/geoclue')
-rw-r--r--src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp62
-rw-r--r--src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h5
2 files changed, 53 insertions, 14 deletions
diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp
index fc0b8b99..ad1fb4d0 100644
--- a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp
+++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp
@@ -90,14 +90,15 @@ static void velocity_changed (GeoclueVelocity *velocity,
gpointer userdata) // Ptr to this
{
Q_UNUSED(velocity)
- Q_UNUSED(timestamp)
- Q_UNUSED(direction)
- Q_UNUSED(climb)
- if (!(fields & GEOCLUE_VELOCITY_FIELDS_SPEED)) {
- static_cast<QGeoPositionInfoSourceGeoclueMaster *>(userdata)->velocityUpdateFailed();
+
+ QGeoPositionInfoSourceGeoclueMaster *master =
+ static_cast<QGeoPositionInfoSourceGeoclueMaster *>(userdata);
+
+ if (fields == GEOCLUE_VELOCITY_FIELDS_NONE) {
+ master->velocityUpdateFailed();
return;
}
- static_cast<QGeoPositionInfoSourceGeoclueMaster *>(userdata)->velocityUpdateSucceeded(speed);
+ master->velocityUpdateSucceeded(fields, timestamp, speed, direction, climb);
}
// Callback for single async update
@@ -117,10 +118,16 @@ static void position_callback (GeocluePosition *pos, GeocluePositionFields field
}
}
+static double knotsToMetersPerSecond(double knots)
+{
+ return knots * 1852.0 / 3600.0;
+}
+
QGeoPositionInfoSourceGeoclueMaster::QGeoPositionInfoSourceGeoclueMaster(QObject *parent)
: QGeoPositionInfoSource(parent), QGeoclueMaster(this), m_updateInterval(0), m_pos(0), m_vel(0),
- m_lastPositionIsFresh(false), m_lastVelocityIsFresh(false), m_lastVelocity(0),
- m_lastPositionFromSatellite(false), m_methods(AllPositioningMethods), m_running(false)
+ m_lastPositionIsFresh(false), m_lastVelocityIsFresh(false), m_lastVelocity(qQNaN()),
+ m_lastDirection(qQNaN()), m_lastClimb(qQNaN()), m_lastPositionFromSatellite(false),
+ m_methods(AllPositioningMethods), m_running(false)
{
#ifndef QT_NO_DATASTREAM
// Load the last known location
@@ -169,13 +176,31 @@ void QGeoPositionInfoSourceGeoclueMaster::velocityUpdateFailed()
m_lastVelocityIsFresh = false;
}
-void QGeoPositionInfoSourceGeoclueMaster::velocityUpdateSucceeded(double speed)
+void QGeoPositionInfoSourceGeoclueMaster::velocityUpdateSucceeded(GeoclueVelocityFields fields,
+ int timestamp, double speed,
+ double direction, double climb)
{
+ Q_UNUSED(timestamp);
+
#ifdef Q_LOCATION_GEOCLUE_DEBUG
qDebug() << "QGeoPositionInfoSourceGeoclueMaster velocity update succeeded, speed: " << speed;
#endif
// Store the velocity and mark it as fresh. Simple but hopefully adequate.
- m_lastVelocity = speed * 0.514444; // convert knots to m/s
+ if (fields & GEOCLUE_VELOCITY_FIELDS_SPEED)
+ m_lastVelocity = knotsToMetersPerSecond(speed);
+ else
+ m_lastVelocity = qQNaN();
+
+ if (fields & GEOCLUE_VELOCITY_FIELDS_DIRECTION)
+ m_lastDirection = direction;
+ else
+ m_lastDirection = qQNaN();
+
+ if (fields & GEOCLUE_VELOCITY_FIELDS_CLIMB)
+ m_lastClimb = climb;
+ else
+ m_lastClimb = qQNaN();
+
m_lastVelocityIsFresh = true;
}
@@ -190,8 +215,14 @@ void QGeoPositionInfoSourceGeoclueMaster::singleUpdateSucceeded(GeocluePositionF
m_lastPosition = info;
if (m_requestTimer.isActive())
m_requestTimer.stop();
- if (m_lastVelocityIsFresh)
- info.setAttribute(QGeoPositionInfo::GroundSpeed, m_lastVelocity); // assume groundspeed
+ if (m_lastVelocityIsFresh) {
+ if (!qIsNaN(m_lastVelocity))
+ info.setAttribute(QGeoPositionInfo::GroundSpeed, m_lastVelocity);
+ if (!qIsNaN(m_lastDirection))
+ info.setAttribute(QGeoPositionInfo::Direction, m_lastDirection);
+ if (!qIsNaN(m_lastClimb))
+ info.setAttribute(QGeoPositionInfo::VerticalSpeed, m_lastClimb);
+ }
#ifdef Q_LOCATION_GEOCLUE_DEBUG
qDebug() << "QGeoPositionInfoSourceGeoclueMaster single update succeeded: ";
qDebug() << "Lat, lon, alt, speed:" << info.coordinate().latitude() << info.coordinate().longitude() << info.coordinate().altitude() << info.attribute(QGeoPositionInfo::GroundSpeed);
@@ -230,7 +261,12 @@ void QGeoPositionInfoSourceGeoclueMaster::regularUpdateSucceeded(GeocluePosition
m_lastPosition = geoclueToPositionInfo(fields, timestamp, latitude, longitude, altitude, accuracy);
m_lastPositionIsFresh = true;
if (m_lastVelocityIsFresh) {
- m_lastPosition.setAttribute(QGeoPositionInfo::GroundSpeed, m_lastVelocity); // assume groundspeed
+ if (!qIsNaN(m_lastVelocity))
+ m_lastPosition.setAttribute(QGeoPositionInfo::GroundSpeed, m_lastVelocity);
+ if (!qIsNaN(m_lastDirection))
+ m_lastPosition.setAttribute(QGeoPositionInfo::Direction, m_lastDirection);
+ if (!qIsNaN(m_lastClimb))
+ m_lastPosition.setAttribute(QGeoPositionInfo::VerticalSpeed, m_lastClimb);
m_lastVelocityIsFresh = false;
}
// If a non-intervalled startUpdates has been issued, send an update.
diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h
index 4ddf6603..b9cc42e3 100644
--- a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h
+++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h
@@ -94,7 +94,8 @@ public:
double altitude,
GeoclueAccuracy *accuracy);
void velocityUpdateFailed();
- void velocityUpdateSucceeded(double speed);
+ void velocityUpdateSucceeded(GeoclueVelocityFields fields, int timestamp, double speed,
+ double direction, double climb);
Error error() const;
@@ -126,6 +127,8 @@ private:
bool m_lastPositionIsFresh;
bool m_lastVelocityIsFresh;
double m_lastVelocity;
+ double m_lastDirection;
+ double m_lastClimb;
bool m_lastPositionFromSatellite;
QGeoPositionInfo m_lastPosition;
PositioningMethods m_methods;