1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

OP-706 Added information about if an UAVO is known or not on the flight/remote side of GCS.

This commit is contained in:
m_thread 2014-10-15 23:30:57 +02:00
parent 3f9f11670c
commit 666765f168
4 changed files with 78 additions and 39 deletions

View File

@ -36,10 +36,12 @@
/** /**
* Constructor * Constructor
*/ */
Telemetry::Telemetry(UAVTalk *utalk, UAVObjectManager *objMngr) : objMngr(objMngr), utalk(utalk) Telemetry::Telemetry(TelemetryManager *telemetryManager, UAVTalk *utalk, UAVObjectManager *objMngr) : objMngr(objMngr), utalk(utalk)
{ {
mutex = new QMutex(QMutex::Recursive); mutex = new QMutex(QMutex::Recursive);
connect(this, SIGNAL(onKnownObjectsChanged(UAVObject*,bool)), telemetryManager, SLOT(onKnownObjectsChanged(UAVObject*,bool)));
// Register all objects in the list // Register all objects in the list
QList< QList<UAVObject *> > objs = objMngr->getObjects(); QList< QList<UAVObject *> > objs = objMngr->getObjects();
for (int objidx = 0; objidx < objs.length(); ++objidx) { for (int objidx = 0; objidx < objs.length(); ++objidx) {
@ -81,6 +83,9 @@ Telemetry::~Telemetry()
*/ */
void Telemetry::registerObject(UAVObject *obj) void Telemetry::registerObject(UAVObject *obj)
{ {
// Forget this object
emit onKnownObjectsChanged(obj, false);
// Setup object for periodic updates // Setup object for periodic updates
addObject(obj); addObject(obj);
@ -235,10 +240,15 @@ void Telemetry::transactionCompleted(UAVObject *obj, bool success)
if (transInfo) { if (transInfo) {
if (success) { if (success) {
// We now know tat the flight side knows of this object.
emit onKnownObjectsChanged(obj, true);
#ifdef VERBOSE_TELEMETRY #ifdef VERBOSE_TELEMETRY
qDebug() << "Telemetry - transaction successful for object" << obj->toStringBrief(); qDebug() << "Telemetry - transaction successful for object" << obj->toStringBrief();
#endif #endif
} else { } else {
emit onKnownObjectsChanged(obj, false);
qWarning() << "Telemetry - !!! transaction failed for object" << obj->toStringBrief(); qWarning() << "Telemetry - !!! transaction failed for object" << obj->toStringBrief();
} }

View File

@ -31,6 +31,7 @@
#include "uavtalk.h" #include "uavtalk.h"
#include "uavobjectmanager.h" #include "uavobjectmanager.h"
#include "gcstelemetrystats.h" #include "gcstelemetrystats.h"
#include "telemetrymanager.h"
#include <QMutex> #include <QMutex>
#include <QMutexLocker> #include <QMutexLocker>
#include <QTimer> #include <QTimer>
@ -73,13 +74,14 @@ public:
quint32 rxCrcErrors; quint32 rxCrcErrors;
} TelemetryStats; } TelemetryStats;
Telemetry(UAVTalk *utalk, UAVObjectManager *objMngr); Telemetry(TelemetryManager *telemetryManager, UAVTalk *utalk, UAVObjectManager *objMngr);
~Telemetry(); ~Telemetry();
TelemetryStats getStats(); TelemetryStats getStats();
void resetStats(); void resetStats();
void transactionTimeout(ObjectTransactionInfo *info); void transactionTimeout(ObjectTransactionInfo *info);
signals: signals:
void onKnownObjectsChanged(UAVObject *object, bool known);
private: private:
// Constants // Constants

View File

@ -26,16 +26,18 @@
*/ */
#include "telemetrymanager.h" #include "telemetrymanager.h"
#include "telemetry.h"
#include "telemetrymonitor.h"
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/threadmanager.h> #include <coreplugin/threadmanager.h>
TelemetryManager::TelemetryManager() : autopilotConnected(false) TelemetryManager::TelemetryManager() : m_isAutopilotConnected(false)
{ {
moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread()); moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread());
// Get UAVObjectManager instance // Get UAVObjectManager instance
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
objMngr = pm->getObject<UAVObjectManager>(); m_uavobjectManager = pm->getObject<UAVObjectManager>();
// connect to start stop signals // connect to start stop signals
connect(this, SIGNAL(myStart()), this, SLOT(onStart()), Qt::QueuedConnection); connect(this, SIGNAL(myStart()), this, SLOT(onStart()), Qt::QueuedConnection);
@ -47,24 +49,29 @@ TelemetryManager::~TelemetryManager()
bool TelemetryManager::isConnected() bool TelemetryManager::isConnected()
{ {
return autopilotConnected; return m_isAutopilotConnected;
}
bool TelemetryManager::isObjectKnown(UAVObject *object) const
{
return m_knownObjects.contains(object);
} }
void TelemetryManager::start(QIODevice *dev) void TelemetryManager::start(QIODevice *dev)
{ {
device = dev; m_telemetryDevice = dev;
// OP-1383 // OP-1383
// take ownership of the device by moving it to the TelemetryManager thread (see TelemetryManager constructor) // take ownership of the device by moving it to the TelemetryManager thread (see TelemetryManager constructor)
// this removes the following runtime Qt warning and incidentally fixes GCS crashes: // this removes the following runtime Qt warning and incidentally fixes GCS crashes:
// QObject: Cannot create children for a parent that is in a different thread. // QObject: Cannot create children for a parent that is in a different thread.
// (Parent is QSerialPort(0x56af73f8), parent's thread is QThread(0x23f69ae8), current thread is QThread(0x2649cfd8) // (Parent is QSerialPort(0x56af73f8), parent's thread is QThread(0x23f69ae8), current thread is QThread(0x2649cfd8)
device->moveToThread(thread()); m_telemetryDevice->moveToThread(thread());
emit myStart(); emit myStart();
} }
void TelemetryManager::onStart() void TelemetryManager::onStart()
{ {
utalk = new UAVTalk(device, objMngr); m_uavTalk = new UAVTalk(m_telemetryDevice, m_uavobjectManager);
if (false) { if (false) {
// UAVTalk must be thread safe and for that: // UAVTalk must be thread safe and for that:
// 1- all public methods must lock a mutex // 1- all public methods must lock a mutex
@ -73,25 +80,25 @@ void TelemetryManager::onStart()
// It is assumed that the UAVObjectManager is thread safe // It is assumed that the UAVObjectManager is thread safe
// Create the reader and move it to the reader thread // Create the reader and move it to the reader thread
IODeviceReader *reader = new IODeviceReader(utalk); IODeviceReader *reader = new IODeviceReader(m_uavTalk);
reader->moveToThread(&readerThread); reader->moveToThread(&m_telemetryReaderThread);
// The reader will be deleted (later) when the thread finishes // The reader will be deleted (later) when the thread finishes
connect(&readerThread, &QThread::finished, reader, &QObject::deleteLater); connect(&m_telemetryReaderThread, &QThread::finished, reader, &QObject::deleteLater);
// Connect IO device to reader // Connect IO device to reader
connect(device, SIGNAL(readyRead()), reader, SLOT(read())); connect(m_telemetryDevice, SIGNAL(readyRead()), reader, SLOT(read()));
// start the reader thread // start the reader thread
readerThread.start(); m_telemetryReaderThread.start();
} else { } else {
// Connect IO device to reader // Connect IO device to reader
connect(device, SIGNAL(readyRead()), utalk, SLOT(processInputStream())); connect(m_telemetryDevice, SIGNAL(readyRead()), m_uavTalk, SLOT(processInputStream()));
} }
telemetry = new Telemetry(utalk, objMngr); m_telemetry = new Telemetry(this, m_uavTalk, m_uavobjectManager);
telemetryMon = new TelemetryMonitor(objMngr, telemetry); m_telemetryMonitor = new TelemetryMonitor(m_uavobjectManager, m_telemetry);
connect(telemetryMon, SIGNAL(connected()), this, SLOT(onConnect())); connect(m_telemetryMonitor, SIGNAL(connected()), this, SLOT(onConnect()));
connect(telemetryMon, SIGNAL(disconnected()), this, SLOT(onDisconnect())); connect(m_telemetryMonitor, SIGNAL(disconnected()), this, SLOT(onDisconnect()));
connect(telemetryMon, SIGNAL(telemetryUpdated(double, double)), this, SLOT(onTelemetryUpdate(double, double))); connect(m_telemetryMonitor, SIGNAL(telemetryUpdated(double, double)), this, SLOT(onTelemetryUpdate(double, double)));
} }
void TelemetryManager::stop() void TelemetryManager::stop()
@ -99,29 +106,44 @@ void TelemetryManager::stop()
emit myStop(); emit myStop();
if (false) { if (false) {
readerThread.quit(); m_telemetryReaderThread.quit();
readerThread.wait(); m_telemetryReaderThread.wait();
} }
} }
void TelemetryManager::onStop() void TelemetryManager::onStop()
{ {
telemetryMon->disconnect(this); foreach (UAVObject *object, m_knownObjects) {
delete telemetryMon; onKnownObjectsChanged(object, false);
delete telemetry; }
delete utalk; m_telemetryMonitor->disconnect(this);
delete m_telemetryMonitor;
delete m_telemetry;
delete m_uavTalk;
onDisconnect(); onDisconnect();
} }
void TelemetryManager::onKnownObjectsChanged(UAVObject *object, bool known)
{
bool contains = m_knownObjects.contains(object);
if (known && !contains) {
m_knownObjects.insert(object);
emit knownObjectsChanged(object, known);
} else if (contains) {
m_knownObjects.remove(object);
emit knownObjectsChanged(object, known);
}
}
void TelemetryManager::onConnect() void TelemetryManager::onConnect()
{ {
autopilotConnected = true; m_isAutopilotConnected = true;
emit connected(); emit connected();
} }
void TelemetryManager::onDisconnect() void TelemetryManager::onDisconnect()
{ {
autopilotConnected = false; m_isAutopilotConnected = false;
emit disconnected(); emit disconnected();
} }
@ -130,10 +152,10 @@ void TelemetryManager::onTelemetryUpdate(double txRate, double rxRate)
emit telemetryUpdated(txRate, rxRate); emit telemetryUpdated(txRate, rxRate);
} }
IODeviceReader::IODeviceReader(UAVTalk *uavTalk) : uavTalk(uavTalk) IODeviceReader::IODeviceReader(UAVTalk *uavTalk) : m_uavTalk(uavTalk)
{} {}
void IODeviceReader::read() void IODeviceReader::read()
{ {
uavTalk->processInputStream(); m_uavTalk->processInputStream();
} }

View File

@ -29,13 +29,14 @@
#define TELEMETRYMANAGER_H #define TELEMETRYMANAGER_H
#include "uavtalk_global.h" #include "uavtalk_global.h"
#include "telemetrymonitor.h"
#include "telemetry.h"
#include "uavtalk.h" #include "uavtalk.h"
#include "uavobjectmanager.h" #include "uavobjectmanager.h"
#include <QIODevice> #include <QIODevice>
#include <QObject> #include <QObject>
class Telemetry;
class TelemetryMonitor;
class UAVTALK_EXPORT TelemetryManager : public QObject { class UAVTALK_EXPORT TelemetryManager : public QObject {
Q_OBJECT Q_OBJECT
@ -46,6 +47,7 @@ public:
void start(QIODevice *dev); void start(QIODevice *dev);
void stop(); void stop();
bool isConnected(); bool isConnected();
bool isObjectKnown(UAVObject* object) const;
signals: signals:
void connected(); void connected();
@ -53,6 +55,7 @@ signals:
void telemetryUpdated(double txRate, double rxRate); void telemetryUpdated(double txRate, double rxRate);
void myStart(); void myStart();
void myStop(); void myStop();
void knownObjectsChanged(UAVObject *object, bool known);
private slots: private slots:
void onConnect(); void onConnect();
@ -60,15 +63,17 @@ private slots:
void onTelemetryUpdate(double txRate, double rxRate); void onTelemetryUpdate(double txRate, double rxRate);
void onStart(); void onStart();
void onStop(); void onStop();
void onKnownObjectsChanged(UAVObject *object, bool known);
private: private:
UAVObjectManager *objMngr; UAVObjectManager *m_uavobjectManager;
UAVTalk *utalk; UAVTalk *m_uavTalk;
Telemetry *telemetry; Telemetry *m_telemetry;
TelemetryMonitor *telemetryMon; TelemetryMonitor *m_telemetryMonitor;
QIODevice *device; QIODevice *m_telemetryDevice;
bool autopilotConnected; bool m_isAutopilotConnected;
QThread readerThread; QThread m_telemetryReaderThread;
QSet<UAVObject*> m_knownObjects;
}; };
@ -77,7 +82,7 @@ class IODeviceReader : public QObject {
public: public:
IODeviceReader(UAVTalk *uavTalk); IODeviceReader(UAVTalk *uavTalk);
UAVTalk *uavTalk; UAVTalk *m_uavTalk;
public slots: public slots:
void read(); void read();