diff --git a/ground/src/plugins/logging/loggingplugin.cpp b/ground/src/plugins/logging/loggingplugin.cpp index 933c6e963..d0ddcbd4d 100644 --- a/ground/src/plugins/logging/loggingplugin.cpp +++ b/ground/src/plugins/logging/loggingplugin.cpp @@ -44,6 +44,7 @@ #include #include #include +#include "uavobjects/uavobjectmanager.h" #include /** @@ -104,6 +105,17 @@ void LoggingThread::run() } } + GCSTelemetryStats* gcsStatsObj = GCSTelemetryStats::GetInstance(objManager); + GCSTelemetryStats::DataFields gcsStats = gcsStatsObj->getData(); + if ( gcsStats.Status == GCSTelemetryStats::STATUS_CONNECTED ) + { + qDebug() << "Logging: connected already, ask for all settings"; + retrieveSettings(); + } else { + qDebug() << "Logging: not connected, do no ask for settings"; + } + + exec(); } @@ -119,6 +131,84 @@ void LoggingThread::stopLogging() quit(); } +/** + * Initialize queue with settings objects to be retrieved. + */ +void LoggingThread::retrieveSettings() +{ + // Clear object queue + queue.clear(); + // Get all objects, add metaobjects, settings and data objects with OnChange update mode to the queue + // Get UAVObjectManager instance + ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager *objMngr = pm->getObject(); + QList< QList > objs = objMngr->getDataObjects(); + for (int n = 0; n < objs.length(); ++n) + { + UAVDataObject* obj = objs[n][0]; + if ( obj->isSettings() ) + { + queue.enqueue(obj); + } + } + // Start retrieving + qDebug() << tr("Logging: retrieve settings objects from the autopilot (%1 objects)") + .arg( queue.length()); + retrieveNextObject(); +} + + +/** + * Retrieve the next object in the queue + */ +void LoggingThread::retrieveNextObject() +{ + // If queue is empty return + if ( queue.isEmpty() ) + { + qDebug() << "Logging: Object retrieval completed"; + return; + } + // Get next object from the queue + UAVObject* obj = queue.dequeue(); + // Connect to object + connect(obj, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(transactionCompleted(UAVObject*,bool))); + // Request update + obj->requestUpdate(); +} + +/** + * Called by the retrieved object when a transaction is completed. + */ +void LoggingThread::transactionCompleted(UAVObject* obj, bool success) +{ + Q_UNUSED(success); + // Disconnect from sending object + obj->disconnect(this); + // Process next object if telemetry is still available + // Get stats objects + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager *objManager = pm->getObject(); + GCSTelemetryStats* gcsStatsObj = GCSTelemetryStats::GetInstance(objManager); + GCSTelemetryStats::DataFields gcsStats = gcsStatsObj->getData(); + if ( gcsStats.Status == GCSTelemetryStats::STATUS_CONNECTED ) + { + retrieveNextObject(); + } + else + { + qDebug() << "Logging: Object retrieval has been cancelled"; + queue.clear(); + } +} + + + +/**************************************************************** + Logging plugin + ********************************/ + + LoggingPlugin::LoggingPlugin() : state(IDLE) { // Do nothing @@ -306,6 +396,9 @@ void LoggingPlugin::replayStopped() } + + + void LoggingPlugin::extensionsInitialized() { // Do nothing diff --git a/ground/src/plugins/logging/loggingplugin.h b/ground/src/plugins/logging/loggingplugin.h index 7fdd16855..1c4f65791 100644 --- a/ground/src/plugins/logging/loggingplugin.h +++ b/ground/src/plugins/logging/loggingplugin.h @@ -29,10 +29,12 @@ #include #include +#include "uavobjects/gcstelemetrystats.h" #include #include #include +#include #include class LoggingPlugin; @@ -46,6 +48,7 @@ public: private slots: void objectUpdated(UAVObject * obj); + void transactionCompleted(UAVObject* obj, bool success); public slots: void stopLogging(); @@ -55,6 +58,13 @@ protected: QReadWriteLock lock; LogFile logFile; UAVTalk * uavTalk; + +private: + QQueue queue; + + void retrieveSettings(); + void retrieveNextObject(); + }; class LoggingPlugin : public ExtensionSystem::IPlugin @@ -96,6 +106,7 @@ private slots: private: LoggingGadgetFactory *mf; + }; #endif /* LoggingPLUGIN_H_ */ /**