1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +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
*/
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<UAVObject *> > 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();
}

View File

@ -31,6 +31,7 @@
#include "uavtalk.h"
#include "uavobjectmanager.h"
#include "gcstelemetrystats.h"
#include "telemetrymanager.h"
#include <QMutex>
#include <QMutexLocker>
#include <QTimer>
@ -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

View File

@ -26,16 +26,18 @@
*/
#include "telemetrymanager.h"
#include "telemetry.h"
#include "telemetrymonitor.h"
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/threadmanager.h>
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<UAVObjectManager>();
m_uavobjectManager = pm->getObject<UAVObjectManager>();
// 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();
}

View File

@ -29,13 +29,14 @@
#define TELEMETRYMANAGER_H
#include "uavtalk_global.h"
#include "telemetrymonitor.h"
#include "telemetry.h"
#include "uavtalk.h"
#include "uavobjectmanager.h"
#include <QIODevice>
#include <QObject>
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<UAVObject*> m_knownObjects;
};
@ -77,7 +82,7 @@ class IODeviceReader : public QObject {
public:
IODeviceReader(UAVTalk *uavTalk);
UAVTalk *uavTalk;
UAVTalk *m_uavTalk;
public slots:
void read();