From 765d4f729bc97929ea12fc919c5c8af616841b09 Mon Sep 17 00:00:00 2001 From: corvus Date: Mon, 19 Jul 2010 16:47:06 +0000 Subject: [PATCH] OP-101 : Put Low level telemetry and HiTL into high priority threads - detached from the user interface. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1139 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/hitl/flightgearbridge.cpp | 25 +++++++++++++----- ground/src/plugins/hitl/flightgearbridge.h | 4 ++- ground/src/plugins/hitlil2/il2bridge.cpp | 1 + .../src/plugins/uavtalk/telemetrymanager.cpp | 26 +++++++++++++++++-- ground/src/plugins/uavtalk/telemetrymanager.h | 9 ++++++- 5 files changed, 54 insertions(+), 11 deletions(-) diff --git a/ground/src/plugins/hitl/flightgearbridge.cpp b/ground/src/plugins/hitl/flightgearbridge.cpp index b7aced44b..8327a41b0 100644 --- a/ground/src/plugins/hitl/flightgearbridge.cpp +++ b/ground/src/plugins/hitl/flightgearbridge.cpp @@ -30,6 +30,13 @@ FlightGearBridge::FlightGearBridge() { + // start thread + start(QThread::TimeCriticalPriority); +} + +void FlightGearBridge::run() +{ + // Init fields fgHost = QHostAddress("127.0.0.1"); inPort = 5500; @@ -62,26 +69,30 @@ FlightGearBridge::FlightGearBridge() } // Setup local ports - inSocket = new QUdpSocket(this); - outSocket = new QUdpSocket(this); + inSocket = new QUdpSocket(); + outSocket = new QUdpSocket(); inSocket->bind(QHostAddress::Any, inPort); - connect(inSocket, SIGNAL(readyRead()), this, SLOT(receiveUpdate())); + connect(inSocket, SIGNAL(readyRead()), this, SLOT(receiveUpdate()),Qt::DirectConnection); // Setup transmit timer - txTimer = new QTimer(this); - connect(txTimer, SIGNAL(timeout()), this, SLOT(transmitUpdate())); + txTimer = new QTimer(); + connect(txTimer, SIGNAL(timeout()), this, SLOT(transmitUpdate()),Qt::DirectConnection); txTimer->setInterval(updatePeriod); txTimer->start(); // Setup FG connection timer - fgTimer = new QTimer(this); - connect(fgTimer, SIGNAL(timeout()), this, SLOT(onFGConnectionTimeout())); + fgTimer = new QTimer(); + connect(fgTimer, SIGNAL(timeout()), this, SLOT(onFGConnectionTimeout()),Qt::DirectConnection); fgTimer->setInterval(fgTimeout); fgTimer->start(); + + exec(); } FlightGearBridge::~FlightGearBridge() { + quit(); + wait(); delete inSocket; delete outSocket; delete txTimer; diff --git a/ground/src/plugins/hitl/flightgearbridge.h b/ground/src/plugins/hitl/flightgearbridge.h index 7391d93bb..f6c31d800 100644 --- a/ground/src/plugins/hitl/flightgearbridge.h +++ b/ground/src/plugins/hitl/flightgearbridge.h @@ -29,6 +29,7 @@ #define FLIGHTGEARBRIDGE_H #include +#include #include #include #include @@ -40,7 +41,7 @@ #include "uavobjects/positionactual.h" #include "uavobjects/gcstelemetrystats.h" -class FlightGearBridge: public QObject +class FlightGearBridge: public QThread { Q_OBJECT @@ -50,6 +51,7 @@ public: bool isAutopilotConnected(); bool isFGConnected(); + void run(); signals: void autopilotConnected(); diff --git a/ground/src/plugins/hitlil2/il2bridge.cpp b/ground/src/plugins/hitlil2/il2bridge.cpp index 1e2eea875..74c81ca09 100644 --- a/ground/src/plugins/hitlil2/il2bridge.cpp +++ b/ground/src/plugins/hitlil2/il2bridge.cpp @@ -130,6 +130,7 @@ void Il2Bridge::run() { Il2Bridge::~Il2Bridge() { quit(); + wait(); delete outSocket; delete txTimer; delete il2Timer; diff --git a/ground/src/plugins/uavtalk/telemetrymanager.cpp b/ground/src/plugins/uavtalk/telemetrymanager.cpp index ad6fa4d55..2167e6941 100644 --- a/ground/src/plugins/uavtalk/telemetrymanager.cpp +++ b/ground/src/plugins/uavtalk/telemetrymanager.cpp @@ -30,19 +30,36 @@ TelemetryManager::TelemetryManager() { + QThread::start(QThread::TimeCriticalPriority); + moveToThread(this); +} + +void TelemetryManager::run() { // Get UAVObjectManager instance ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); objMngr = pm->getObject(); + + // connect to start stop signals + connect(this, SIGNAL(myStart()), this, SLOT(onStart()),Qt::QueuedConnection); + connect(this, SIGNAL(myStop()), this, SLOT(onStop()),Qt::QueuedConnection); + exec(); } TelemetryManager::~TelemetryManager() { - + quit(); + wait(); } void TelemetryManager::start(QIODevice *dev) { - utalk = new UAVTalk(dev, objMngr); + device=dev; + emit myStart(); +} + +void TelemetryManager::onStart() +{ + utalk = new UAVTalk(device, objMngr); telemetry = new Telemetry(utalk, objMngr); telemetryMon = new TelemetryMonitor(objMngr, telemetry); connect(telemetryMon, SIGNAL(connected()), this, SLOT(onConnect())); @@ -50,6 +67,11 @@ void TelemetryManager::start(QIODevice *dev) } void TelemetryManager::stop() +{ + emit myStop(); +} + +void TelemetryManager::onStop() { telemetryMon->disconnect(this); delete telemetryMon; diff --git a/ground/src/plugins/uavtalk/telemetrymanager.h b/ground/src/plugins/uavtalk/telemetrymanager.h index 2cc0b9749..c81eda976 100644 --- a/ground/src/plugins/uavtalk/telemetrymanager.h +++ b/ground/src/plugins/uavtalk/telemetrymanager.h @@ -35,8 +35,9 @@ #include "uavobjects/uavobjectmanager.h" #include #include +#include -class UAVTALK_EXPORT TelemetryManager: public QObject +class UAVTALK_EXPORT TelemetryManager: public QThread { Q_OBJECT @@ -46,20 +47,26 @@ public: void start(QIODevice *dev); void stop(); + void run(); signals: void connected(); void disconnected(); + void myStart(); + void myStop(); private slots: void onConnect(); void onDisconnect(); + void onStart(); + void onStop(); private: UAVObjectManager* objMngr; UAVTalk* utalk; Telemetry* telemetry; TelemetryMonitor* telemetryMon; + QIODevice *device; }; #endif // TELEMETRYMANAGER_H