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

OP-706 Added code to handle isKnown for requested and retrieved UAVObjects.

This commit is contained in:
m_thread 2014-10-17 00:47:14 +02:00
parent 1a28d17eff
commit 1e08528d54
4 changed files with 18 additions and 41 deletions

View File

@ -33,20 +33,22 @@
#include <stdlib.h> #include <stdlib.h>
#include <QDebug> #include <QDebug>
#define VERBOSE_TELEMETRY = 1;
/** /**
* Constructor * Constructor
*/ */
Telemetry::Telemetry(TelemetryManager *telemetryManager, UAVTalk *utalk, UAVObjectManager *objMngr) : objMngr(objMngr), utalk(utalk) Telemetry::Telemetry(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(); foreach(QList<UAVObject *> instances, objMngr->getObjects()) {
for (int objidx = 0; objidx < objs.length(); ++objidx) { foreach(UAVObject * object, instances) {
// make sure we 'forget' all objects before we request it from the flight side
object->setIsKnown(false);
}
// we only need to register one instance per object type // we only need to register one instance per object type
registerObject(objs[objidx][0]); registerObject(instances.first());
} }
// Listen to new object creations // Listen to new object creations
@ -76,6 +78,12 @@ Telemetry::Telemetry(TelemetryManager *telemetryManager, UAVTalk *utalk, UAVObje
Telemetry::~Telemetry() Telemetry::~Telemetry()
{ {
closeAllTransactions(); closeAllTransactions();
foreach(QList<UAVObject *> instances, objMngr->getObjects()) {
foreach(UAVObject * object, instances) {
// make sure we 'forget' all objects before we request it from the flight side
object->setIsKnown(false);
}
}
} }
/** /**
@ -83,9 +91,6 @@ 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);
@ -241,13 +246,13 @@ 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. // We now know tat the flight side knows of this object.
emit onKnownObjectsChanged(obj, true); obj->setIsKnown(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); obj->setIsKnown(false);
qWarning() << "Telemetry - !!! transaction failed for object" << obj->toStringBrief(); qWarning() << "Telemetry - !!! transaction failed for object" << obj->toStringBrief();
} }

View File

@ -31,7 +31,6 @@
#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>
@ -74,15 +73,12 @@ public:
quint32 rxCrcErrors; quint32 rxCrcErrors;
} TelemetryStats; } TelemetryStats;
Telemetry(TelemetryManager *telemetryManager, UAVTalk *utalk, UAVObjectManager *objMngr); Telemetry(UAVTalk *utalk, UAVObjectManager *objMngr);
~Telemetry(); ~Telemetry();
TelemetryStats getStats(); TelemetryStats getStats();
void resetStats(); void resetStats();
void transactionTimeout(ObjectTransactionInfo *info); void transactionTimeout(ObjectTransactionInfo *info);
signals:
void onKnownObjectsChanged(UAVObject *object, bool known);
private: private:
// Constants // Constants
static const int REQ_TIMEOUT_MS = 250; static const int REQ_TIMEOUT_MS = 250;

View File

@ -52,11 +52,6 @@ bool TelemetryManager::isConnected()
return m_isAutopilotConnected; return m_isAutopilotConnected;
} }
bool TelemetryManager::isObjectKnown(UAVObject *object) const
{
return m_knownObjects.contains(object);
}
void TelemetryManager::start(QIODevice *dev) void TelemetryManager::start(QIODevice *dev)
{ {
m_telemetryDevice = dev; m_telemetryDevice = dev;
@ -93,7 +88,7 @@ void TelemetryManager::onStart()
connect(m_telemetryDevice, SIGNAL(readyRead()), m_uavTalk, SLOT(processInputStream())); connect(m_telemetryDevice, SIGNAL(readyRead()), m_uavTalk, SLOT(processInputStream()));
} }
m_telemetry = new Telemetry(this, m_uavTalk, m_uavobjectManager); m_telemetry = new Telemetry(m_uavTalk, m_uavobjectManager);
m_telemetryMonitor = new TelemetryMonitor(m_uavobjectManager, m_telemetry); m_telemetryMonitor = new TelemetryMonitor(m_uavobjectManager, m_telemetry);
connect(m_telemetryMonitor, SIGNAL(connected()), this, SLOT(onConnect())); connect(m_telemetryMonitor, SIGNAL(connected()), this, SLOT(onConnect()));
@ -113,9 +108,6 @@ void TelemetryManager::stop()
void TelemetryManager::onStop() void TelemetryManager::onStop()
{ {
foreach(UAVObject * object, m_knownObjects) {
onKnownObjectsChanged(object, false);
}
m_telemetryMonitor->disconnect(this); m_telemetryMonitor->disconnect(this);
delete m_telemetryMonitor; delete m_telemetryMonitor;
delete m_telemetry; delete m_telemetry;
@ -123,19 +115,6 @@ void TelemetryManager::onStop()
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()
{ {
m_isAutopilotConnected = true; m_isAutopilotConnected = true;

View File

@ -47,7 +47,6 @@ 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();
@ -55,7 +54,6 @@ 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();
@ -73,7 +71,6 @@ private:
QIODevice *m_telemetryDevice; QIODevice *m_telemetryDevice;
bool m_isAutopilotConnected; bool m_isAutopilotConnected;
QThread m_telemetryReaderThread; QThread m_telemetryReaderThread;
QSet<UAVObject *> m_knownObjects;
}; };