From 666765f16857ff1f3f0cd67081f45941ce92ca8b Mon Sep 17 00:00:00 2001 From: m_thread Date: Wed, 15 Oct 2014 23:30:57 +0200 Subject: [PATCH] OP-706 Added information about if an UAVO is known or not on the flight/remote side of GCS. --- .../src/plugins/uavtalk/telemetry.cpp | 12 ++- .../src/plugins/uavtalk/telemetry.h | 4 +- .../src/plugins/uavtalk/telemetrymanager.cpp | 76 ++++++++++++------- .../src/plugins/uavtalk/telemetrymanager.h | 25 +++--- 4 files changed, 78 insertions(+), 39 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/uavtalk/telemetry.cpp b/ground/openpilotgcs/src/plugins/uavtalk/telemetry.cpp index 08c81e9e9..a6c4fdd93 100644 --- a/ground/openpilotgcs/src/plugins/uavtalk/telemetry.cpp +++ b/ground/openpilotgcs/src/plugins/uavtalk/telemetry.cpp @@ -36,10 +36,12 @@ /** * 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); + connect(this, SIGNAL(onKnownObjectsChanged(UAVObject*,bool)), telemetryManager, SLOT(onKnownObjectsChanged(UAVObject*,bool))); + // Register all objects in the list QList< QList > objs = objMngr->getObjects(); for (int objidx = 0; objidx < objs.length(); ++objidx) { @@ -81,6 +83,9 @@ Telemetry::~Telemetry() */ void Telemetry::registerObject(UAVObject *obj) { + // Forget this object + emit onKnownObjectsChanged(obj, false); + // Setup object for periodic updates addObject(obj); @@ -235,10 +240,15 @@ void Telemetry::transactionCompleted(UAVObject *obj, bool success) if (transInfo) { if (success) { + // We now know tat the flight side knows of this object. + emit onKnownObjectsChanged(obj, true); + #ifdef VERBOSE_TELEMETRY qDebug() << "Telemetry - transaction successful for object" << obj->toStringBrief(); #endif + } else { + emit onKnownObjectsChanged(obj, false); qWarning() << "Telemetry - !!! transaction failed for object" << obj->toStringBrief(); } diff --git a/ground/openpilotgcs/src/plugins/uavtalk/telemetry.h b/ground/openpilotgcs/src/plugins/uavtalk/telemetry.h index c4ff2374f..c2f0b3867 100644 --- a/ground/openpilotgcs/src/plugins/uavtalk/telemetry.h +++ b/ground/openpilotgcs/src/plugins/uavtalk/telemetry.h @@ -31,6 +31,7 @@ #include "uavtalk.h" #include "uavobjectmanager.h" #include "gcstelemetrystats.h" +#include "telemetrymanager.h" #include #include #include @@ -73,13 +74,14 @@ public: quint32 rxCrcErrors; } TelemetryStats; - Telemetry(UAVTalk *utalk, UAVObjectManager *objMngr); + Telemetry(TelemetryManager *telemetryManager, UAVTalk *utalk, UAVObjectManager *objMngr); ~Telemetry(); TelemetryStats getStats(); void resetStats(); void transactionTimeout(ObjectTransactionInfo *info); signals: + void onKnownObjectsChanged(UAVObject *object, bool known); private: // Constants diff --git a/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.cpp b/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.cpp index 68f432b67..30db576e1 100644 --- a/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.cpp +++ b/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.cpp @@ -26,16 +26,18 @@ */ #include "telemetrymanager.h" +#include "telemetry.h" +#include "telemetrymonitor.h" #include #include #include -TelemetryManager::TelemetryManager() : autopilotConnected(false) +TelemetryManager::TelemetryManager() : m_isAutopilotConnected(false) { moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread()); // Get UAVObjectManager instance ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - objMngr = pm->getObject(); + m_uavobjectManager = pm->getObject(); // connect to start stop signals connect(this, SIGNAL(myStart()), this, SLOT(onStart()), Qt::QueuedConnection); @@ -47,24 +49,29 @@ TelemetryManager::~TelemetryManager() bool TelemetryManager::isConnected() { - return autopilotConnected; + return m_isAutopilotConnected; +} + +bool TelemetryManager::isObjectKnown(UAVObject *object) const +{ + return m_knownObjects.contains(object); } void TelemetryManager::start(QIODevice *dev) { - device = dev; + m_telemetryDevice = dev; // OP-1383 // 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: // 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) - device->moveToThread(thread()); + m_telemetryDevice->moveToThread(thread()); emit myStart(); } void TelemetryManager::onStart() { - utalk = new UAVTalk(device, objMngr); + m_uavTalk = new UAVTalk(m_telemetryDevice, m_uavobjectManager); if (false) { // UAVTalk must be thread safe and for that: // 1- all public methods must lock a mutex @@ -73,25 +80,25 @@ void TelemetryManager::onStart() // It is assumed that the UAVObjectManager is thread safe // Create the reader and move it to the reader thread - IODeviceReader *reader = new IODeviceReader(utalk); - reader->moveToThread(&readerThread); + IODeviceReader *reader = new IODeviceReader(m_uavTalk); + reader->moveToThread(&m_telemetryReaderThread); // 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(device, SIGNAL(readyRead()), reader, SLOT(read())); + connect(m_telemetryDevice, SIGNAL(readyRead()), reader, SLOT(read())); // start the reader thread - readerThread.start(); + m_telemetryReaderThread.start(); } else { // 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); - telemetryMon = new TelemetryMonitor(objMngr, telemetry); + m_telemetry = new Telemetry(this, m_uavTalk, m_uavobjectManager); + m_telemetryMonitor = new TelemetryMonitor(m_uavobjectManager, m_telemetry); - connect(telemetryMon, SIGNAL(connected()), this, SLOT(onConnect())); - connect(telemetryMon, SIGNAL(disconnected()), this, SLOT(onDisconnect())); - connect(telemetryMon, SIGNAL(telemetryUpdated(double, double)), this, SLOT(onTelemetryUpdate(double, double))); + connect(m_telemetryMonitor, SIGNAL(connected()), this, SLOT(onConnect())); + connect(m_telemetryMonitor, SIGNAL(disconnected()), this, SLOT(onDisconnect())); + connect(m_telemetryMonitor, SIGNAL(telemetryUpdated(double, double)), this, SLOT(onTelemetryUpdate(double, double))); } void TelemetryManager::stop() @@ -99,29 +106,44 @@ void TelemetryManager::stop() emit myStop(); if (false) { - readerThread.quit(); - readerThread.wait(); + m_telemetryReaderThread.quit(); + m_telemetryReaderThread.wait(); } } void TelemetryManager::onStop() { - telemetryMon->disconnect(this); - delete telemetryMon; - delete telemetry; - delete utalk; + foreach (UAVObject *object, m_knownObjects) { + onKnownObjectsChanged(object, false); + } + m_telemetryMonitor->disconnect(this); + delete m_telemetryMonitor; + delete m_telemetry; + delete m_uavTalk; 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() { - autopilotConnected = true; + m_isAutopilotConnected = true; emit connected(); } void TelemetryManager::onDisconnect() { - autopilotConnected = false; + m_isAutopilotConnected = false; emit disconnected(); } @@ -130,10 +152,10 @@ void TelemetryManager::onTelemetryUpdate(double txRate, double rxRate) emit telemetryUpdated(txRate, rxRate); } -IODeviceReader::IODeviceReader(UAVTalk *uavTalk) : uavTalk(uavTalk) +IODeviceReader::IODeviceReader(UAVTalk *uavTalk) : m_uavTalk(uavTalk) {} void IODeviceReader::read() { - uavTalk->processInputStream(); + m_uavTalk->processInputStream(); } diff --git a/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.h b/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.h index 0e32fcf55..311d1d529 100644 --- a/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.h +++ b/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.h @@ -29,13 +29,14 @@ #define TELEMETRYMANAGER_H #include "uavtalk_global.h" -#include "telemetrymonitor.h" -#include "telemetry.h" #include "uavtalk.h" #include "uavobjectmanager.h" #include #include +class Telemetry; +class TelemetryMonitor; + class UAVTALK_EXPORT TelemetryManager : public QObject { Q_OBJECT @@ -46,6 +47,7 @@ public: void start(QIODevice *dev); void stop(); bool isConnected(); + bool isObjectKnown(UAVObject* object) const; signals: void connected(); @@ -53,6 +55,7 @@ signals: void telemetryUpdated(double txRate, double rxRate); void myStart(); void myStop(); + void knownObjectsChanged(UAVObject *object, bool known); private slots: void onConnect(); @@ -60,15 +63,17 @@ private slots: void onTelemetryUpdate(double txRate, double rxRate); void onStart(); void onStop(); + void onKnownObjectsChanged(UAVObject *object, bool known); private: - UAVObjectManager *objMngr; - UAVTalk *utalk; - Telemetry *telemetry; - TelemetryMonitor *telemetryMon; - QIODevice *device; - bool autopilotConnected; - QThread readerThread; + UAVObjectManager *m_uavobjectManager; + UAVTalk *m_uavTalk; + Telemetry *m_telemetry; + TelemetryMonitor *m_telemetryMonitor; + QIODevice *m_telemetryDevice; + bool m_isAutopilotConnected; + QThread m_telemetryReaderThread; + QSet m_knownObjects; }; @@ -77,7 +82,7 @@ class IODeviceReader : public QObject { public: IODeviceReader(UAVTalk *uavTalk); - UAVTalk *uavTalk; + UAVTalk *m_uavTalk; public slots: void read();