mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-15 07:29:15 +01:00
OP-101: re-work of UAVTalk + HiTL threading code.
Telemetry and HiTL now run in the same global high priority thread. Threads are managed by a new class ThreadManager in icore as suggested by PeterG git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1193 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
07d168e8ab
commit
1a019b5836
@ -102,6 +102,11 @@ VariableManager *CoreImpl::variableManager() const
|
||||
return m_mainwindow->variableManager();
|
||||
}
|
||||
|
||||
ThreadManager *CoreImpl::threadManager() const
|
||||
{
|
||||
return m_mainwindow->threadManager();
|
||||
}
|
||||
|
||||
ModeManager *CoreImpl::modeManager() const
|
||||
{
|
||||
return m_mainwindow->modeManager();
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
ConnectionManager *connectionManager() const;
|
||||
UAVGadgetInstanceManager *uavGadgetInstanceManager() const;
|
||||
VariableManager *variableManager() const;
|
||||
ThreadManager *threadManager() const;
|
||||
ModeManager *modeManager() const;
|
||||
MimeDatabase *mimeDatabase() const;
|
||||
|
||||
|
@ -40,6 +40,7 @@ SOURCES += mainwindow.cpp \
|
||||
baseview.cpp \
|
||||
coreplugin.cpp \
|
||||
variablemanager.cpp \
|
||||
threadmanager.cpp \
|
||||
modemanager.cpp \
|
||||
coreimpl.cpp \
|
||||
plugindialog.cpp \
|
||||
@ -100,6 +101,7 @@ HEADERS += mainwindow.h \
|
||||
baseview.h \
|
||||
coreplugin.h \
|
||||
variablemanager.h \
|
||||
threadmanager.h \
|
||||
modemanager.h \
|
||||
coreimpl.h \
|
||||
plugindialog.h \
|
||||
|
@ -147,6 +147,15 @@
|
||||
can be resolved/expanded from anywhere in the application.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn ThreadManager *ICore::threadManager() const
|
||||
\brief Returns the application's thread manager.
|
||||
|
||||
The thread manager is used to manage application wide QThread objects,
|
||||
allowing certain critical objects to synchronize directly within the same
|
||||
real time thread - anywhere in the application.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn ModeManager *ICore::modeManager() const
|
||||
\brief Returns the application's mode manager.
|
||||
|
@ -50,6 +50,7 @@ class ModeManager;
|
||||
class SettingsDatabase;
|
||||
class UniqueIDManager;
|
||||
class VariableManager;
|
||||
class ThreadManager;
|
||||
class UAVGadgetManager;
|
||||
class UAVGadgetInstanceManager;
|
||||
|
||||
@ -77,6 +78,7 @@ public:
|
||||
virtual UniqueIDManager *uniqueIDManager() const = 0;
|
||||
virtual MessageManager *messageManager() const = 0;
|
||||
virtual VariableManager *variableManager() const = 0;
|
||||
virtual ThreadManager *threadManager() const = 0;
|
||||
virtual ModeManager *modeManager() const = 0;
|
||||
virtual ConnectionManager *connectionManager() const = 0;
|
||||
virtual UAVGadgetInstanceManager *uavGadgetInstanceManager() const = 0;
|
||||
|
@ -51,6 +51,7 @@
|
||||
|
||||
#include "settingsdialog.h"
|
||||
#include "variablemanager.h"
|
||||
#include "threadmanager.h"
|
||||
#include "versiondialog.h"
|
||||
#include "viewmanager.h"
|
||||
#include "uniqueidmanager.h"
|
||||
@ -115,6 +116,7 @@ MainWindow::MainWindow() :
|
||||
this)),
|
||||
m_actionManager(new ActionManagerPrivate(this)),
|
||||
m_variableManager(new VariableManager(this)),
|
||||
m_threadManager(new ThreadManager(this)),
|
||||
m_viewManager(0),
|
||||
m_modeManager(0),
|
||||
m_connectionManager(0),
|
||||
@ -771,6 +773,11 @@ VariableManager *MainWindow::variableManager() const
|
||||
return m_variableManager;
|
||||
}
|
||||
|
||||
ThreadManager *MainWindow::threadManager() const
|
||||
{
|
||||
return m_threadManager;
|
||||
}
|
||||
|
||||
ConnectionManager *MainWindow::connectionManager() const
|
||||
{
|
||||
return m_connectionManager;
|
||||
|
@ -57,6 +57,7 @@ class RightPaneWidget;
|
||||
class SettingsDatabase;
|
||||
class UniqueIDManager;
|
||||
class VariableManager;
|
||||
class ThreadManager;
|
||||
class ViewManagerInterface;
|
||||
class UAVGadgetManager;
|
||||
class UAVGadgetInstanceManager;
|
||||
@ -100,6 +101,7 @@ public:
|
||||
UAVGadgetInstanceManager *uavGadgetInstanceManager() const;
|
||||
Core::ConnectionManager *connectionManager() const;
|
||||
Core::VariableManager *variableManager() const;
|
||||
Core::ThreadManager *threadManager() const;
|
||||
Core::ModeManager *modeManager() const;
|
||||
Core::MimeDatabase *mimeDatabase() const;
|
||||
|
||||
@ -171,6 +173,7 @@ private:
|
||||
ActionManagerPrivate *m_actionManager;
|
||||
MessageManager *m_messageManager;
|
||||
VariableManager *m_variableManager;
|
||||
ThreadManager *m_threadManager;
|
||||
ViewManager *m_viewManager;
|
||||
ModeManager *m_modeManager;
|
||||
QList<UAVGadgetManager*> m_uavGadgetManagers;
|
||||
|
53
ground/src/plugins/coreplugin/threadmanager.cpp
Normal file
53
ground/src/plugins/coreplugin/threadmanager.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file threadmanager.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup CorePlugin Core Plugin
|
||||
* @{
|
||||
* @brief The Core GCS plugin
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "threadmanager.h"
|
||||
|
||||
|
||||
using namespace Core;
|
||||
|
||||
ThreadManager *ThreadManager::m_instance = 0;
|
||||
|
||||
ThreadManager::ThreadManager(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_instance = this;
|
||||
realTimeThread= new QThread(this);
|
||||
realTimeThread->start(QThread::TimeCriticalPriority);
|
||||
}
|
||||
|
||||
ThreadManager::~ThreadManager()
|
||||
{
|
||||
realTimeThread->quit();
|
||||
realTimeThread->wait();
|
||||
m_instance = 0;
|
||||
}
|
||||
|
||||
QThread *ThreadManager::getRealTimeThread()
|
||||
{
|
||||
return realTimeThread;
|
||||
}
|
62
ground/src/plugins/coreplugin/threadmanager.h
Normal file
62
ground/src/plugins/coreplugin/threadmanager.h
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file threadmanager.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup CorePlugin Core Plugin
|
||||
* @{
|
||||
* @brief The Core GCS plugin
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef THREADMANAGER_H
|
||||
#define THREADMANAGER_H
|
||||
|
||||
#include "core_global.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QThread>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
|
||||
class CORE_EXPORT ThreadManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ThreadManager(QObject *parent);
|
||||
~ThreadManager();
|
||||
|
||||
static ThreadManager* instance() { return m_instance; }
|
||||
|
||||
QThread *getRealTimeThread();
|
||||
|
||||
|
||||
private:
|
||||
QThread *realTimeThread;
|
||||
static ThreadManager *m_instance;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
||||
#endif // THREADMANAGER_H
|
@ -27,14 +27,20 @@
|
||||
|
||||
#include "flightgearbridge.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "coreplugin/icore.h"
|
||||
#include "coreplugin/threadmanager.h"
|
||||
|
||||
FlightGearBridge::FlightGearBridge()
|
||||
{
|
||||
// start thread
|
||||
start(QThread::TimeCriticalPriority);
|
||||
// move to thread
|
||||
moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread());
|
||||
|
||||
connect(this, SIGNAL(myStart()), this, SLOT(onStart()),Qt::QueuedConnection);
|
||||
emit myStart();
|
||||
|
||||
}
|
||||
|
||||
void FlightGearBridge::run()
|
||||
void FlightGearBridge::onStart()
|
||||
{
|
||||
|
||||
// Init fields
|
||||
@ -86,13 +92,10 @@ void FlightGearBridge::run()
|
||||
fgTimer->setInterval(fgTimeout);
|
||||
fgTimer->start();
|
||||
|
||||
exec();
|
||||
}
|
||||
|
||||
FlightGearBridge::~FlightGearBridge()
|
||||
{
|
||||
quit();
|
||||
wait();
|
||||
delete inSocket;
|
||||
delete outSocket;
|
||||
delete txTimer;
|
||||
|
@ -29,7 +29,6 @@
|
||||
#define FLIGHTGEARBRIDGE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QUdpSocket>
|
||||
#include <QTimer>
|
||||
#include <math.h>
|
||||
@ -41,7 +40,7 @@
|
||||
#include "uavobjects/positionactual.h"
|
||||
#include "uavobjects/gcstelemetrystats.h"
|
||||
|
||||
class FlightGearBridge: public QThread
|
||||
class FlightGearBridge: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -51,15 +50,16 @@ public:
|
||||
|
||||
bool isAutopilotConnected();
|
||||
bool isFGConnected();
|
||||
void run();
|
||||
|
||||
signals:
|
||||
void myStart();
|
||||
void autopilotConnected();
|
||||
void autopilotDisconnected();
|
||||
void fgConnected();
|
||||
void fgDisconnected();
|
||||
|
||||
private slots:
|
||||
void onStart();
|
||||
void transmitUpdate();
|
||||
void receiveUpdate();
|
||||
void onAutopilotConnect();
|
||||
|
@ -61,6 +61,8 @@
|
||||
*/
|
||||
#include "il2bridge.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/threadmanager.h>
|
||||
#include <math.h>
|
||||
|
||||
Il2Bridge::Il2Bridge(QString il2HostName, int il2Port, QString il2Latitude, QString il2Longitude)
|
||||
@ -74,12 +76,19 @@ Il2Bridge::Il2Bridge(QString il2HostName, int il2Port, QString il2Latitude, QStr
|
||||
il2ConnectionStatus = false;
|
||||
latitude=il2Latitude.toFloat();
|
||||
longitude=il2Longitude.toFloat();
|
||||
// start thread
|
||||
start(QThread::TimeCriticalPriority);
|
||||
|
||||
|
||||
|
||||
// move to thread
|
||||
moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread());
|
||||
|
||||
connect(this, SIGNAL(myStart()), this, SLOT(onStart()),Qt::QueuedConnection);
|
||||
emit myStart();
|
||||
}
|
||||
|
||||
void Il2Bridge::onStart()
|
||||
{
|
||||
|
||||
void Il2Bridge::run() {
|
||||
// Get required UAVObjects
|
||||
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager* objManager = pm->getObject<UAVObjectManager>();
|
||||
@ -124,13 +133,11 @@ void Il2Bridge::run() {
|
||||
time->start();
|
||||
|
||||
current.T=0;
|
||||
exec();
|
||||
|
||||
}
|
||||
|
||||
Il2Bridge::~Il2Bridge()
|
||||
{
|
||||
quit();
|
||||
wait();
|
||||
delete outSocket;
|
||||
delete txTimer;
|
||||
delete il2Timer;
|
||||
|
@ -29,7 +29,6 @@
|
||||
#define IL2BRIDGE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QUdpSocket>
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
@ -76,7 +75,7 @@ struct flightParams {
|
||||
};
|
||||
|
||||
|
||||
class Il2Bridge: public QThread
|
||||
class Il2Bridge: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -86,15 +85,16 @@ public:
|
||||
|
||||
bool isAutopilotConnected();
|
||||
bool isIl2Connected();
|
||||
void run();
|
||||
|
||||
signals:
|
||||
void myStart();
|
||||
void autopilotConnected();
|
||||
void autopilotDisconnected();
|
||||
void il2Connected();
|
||||
void il2Disconnected();
|
||||
|
||||
private slots:
|
||||
void onStart();
|
||||
void transmitUpdate();
|
||||
void receiveUpdate();
|
||||
void onAutopilotConnect();
|
||||
|
@ -27,14 +27,12 @@
|
||||
|
||||
#include "telemetrymanager.h"
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/threadmanager.h>
|
||||
|
||||
TelemetryManager::TelemetryManager()
|
||||
{
|
||||
QThread::start(QThread::TimeCriticalPriority);
|
||||
moveToThread(this);
|
||||
}
|
||||
|
||||
void TelemetryManager::run() {
|
||||
moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread());
|
||||
// Get UAVObjectManager instance
|
||||
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
||||
objMngr = pm->getObject<UAVObjectManager>();
|
||||
@ -42,13 +40,10 @@ void TelemetryManager::run() {
|
||||
// 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)
|
||||
|
@ -35,9 +35,8 @@
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include <QIODevice>
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
|
||||
class UAVTALK_EXPORT TelemetryManager: public QThread
|
||||
class UAVTALK_EXPORT TelemetryManager: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -47,7 +46,6 @@ public:
|
||||
|
||||
void start(QIODevice *dev);
|
||||
void stop();
|
||||
void run();
|
||||
|
||||
signals:
|
||||
void connected();
|
||||
|
Loading…
x
Reference in New Issue
Block a user