From 8c0c5b0e4dfe54d8518cb6f71279425f1c5b299c Mon Sep 17 00:00:00 2001 From: corvus Date: Mon, 19 Jul 2010 15:16:21 +0000 Subject: [PATCH] Made hitl-IL2 plugin multi threaded (separate thread for sim connection) git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1138 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/hitlil2/il2bridge.cpp | 26 +++++++++++++++++------- ground/src/plugins/hitlil2/il2bridge.h | 4 +++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ground/src/plugins/hitlil2/il2bridge.cpp b/ground/src/plugins/hitlil2/il2bridge.cpp index d7205afa5..1e2eea875 100644 --- a/ground/src/plugins/hitlil2/il2bridge.cpp +++ b/ground/src/plugins/hitlil2/il2bridge.cpp @@ -74,7 +74,12 @@ Il2Bridge::Il2Bridge(QString il2HostName, int il2Port, QString il2Latitude, QStr il2ConnectionStatus = false; latitude=il2Latitude.toFloat(); longitude=il2Longitude.toFloat(); + // start thread + start(QThread::TimeCriticalPriority); +} + +void Il2Bridge::run() { // Get required UAVObjects ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager* objManager = pm->getObject(); @@ -98,19 +103,19 @@ Il2Bridge::Il2Bridge(QString il2HostName, int il2Port, QString il2Latitude, QStr } // Setup local ports - outSocket = new QUdpSocket(this); - outSocket->connectToHost((const QString )il2HostName,il2Port); - connect(outSocket, SIGNAL(readyRead()), this, SLOT(receiveUpdate())); + outSocket = new QUdpSocket(); + outSocket->connectToHost(il2Host,outPort); + connect(outSocket, 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 - il2Timer = new QTimer(this); - connect(il2Timer, SIGNAL(timeout()), this, SLOT(onIl2ConnectionTimeout())); + il2Timer = new QTimer(); + connect(il2Timer, SIGNAL(timeout()), this, SLOT(onIl2ConnectionTimeout()),Qt::DirectConnection); il2Timer->setInterval(il2Timeout); il2Timer->start(); @@ -119,10 +124,12 @@ Il2Bridge::Il2Bridge(QString il2HostName, int il2Port, QString il2Latitude, QStr time->start(); current.T=0; + exec(); } Il2Bridge::~Il2Bridge() { + quit(); delete outSocket; delete txTimer; delete il2Timer; @@ -361,6 +368,11 @@ void Il2Bridge::processUpdate(QString& data) gpsData.Satellites = 7; gpsData.Status = PositionActual::STATUS_FIX3D; posActual->setData(gpsData); + + // issue manual update + attActual->updated(); + altActual->updated(); + posActual->updated(); } void Il2Bridge::telStatsUpdated(UAVObject* obj) diff --git a/ground/src/plugins/hitlil2/il2bridge.h b/ground/src/plugins/hitlil2/il2bridge.h index 87241909f..36c5d9405 100644 --- a/ground/src/plugins/hitlil2/il2bridge.h +++ b/ground/src/plugins/hitlil2/il2bridge.h @@ -29,6 +29,7 @@ #define IL2BRIDGE_H #include +#include #include #include #include @@ -75,7 +76,7 @@ struct flightParams { }; -class Il2Bridge: public QObject +class Il2Bridge: public QThread { Q_OBJECT @@ -85,6 +86,7 @@ public: bool isAutopilotConnected(); bool isIl2Connected(); + void run(); signals: void autopilotConnected();