1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Logging plugin will refresh all the settings if telemetry is already connected, so that the log file always contains all the setting objects, which is vital for post-flight analysis.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2184 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-12-04 16:47:55 +00:00 committed by edouard
parent 327252f5c0
commit 477657ea6e
2 changed files with 104 additions and 0 deletions

View File

@ -44,6 +44,7 @@
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/icore.h>
#include <QKeySequence>
#include "uavobjects/uavobjectmanager.h"
#include <uavobjects/uavobjectmanager.h>
/**
@ -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<UAVObjectManager>();
QList< QList<UAVDataObject*> > 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<UAVObjectManager>();
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

View File

@ -29,10 +29,12 @@
#include <extensionsystem/iplugin.h>
#include <uavobjects/uavobjectmanager.h>
#include "uavobjects/gcstelemetrystats.h"
#include <uavtalk/uavtalk.h>
#include <logfile.h>
#include <QThread>
#include <QQueue>
#include <QReadWriteLock>
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<UAVDataObject*> queue;
void retrieveSettings();
void retrieveNextObject();
};
class LoggingPlugin : public ExtensionSystem::IPlugin
@ -96,6 +106,7 @@ private slots:
private:
LoggingGadgetFactory *mf;
};
#endif /* LoggingPLUGIN_H_ */
/**