1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-28 17:54:15 +01:00

OP356/GCS - Makes the dropbox show devices "friendly name". Type of connection and previous serial number accessible via tooltip.

Kind of hacky, we should refractor connectionManager but that can wait for after V1.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@3103 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2011-03-29 18:25:24 +00:00 committed by zedamota
parent 3665209195
commit 6bcacb1630
11 changed files with 843 additions and 823 deletions

View File

@ -106,11 +106,11 @@ void ConnectionManager::init()
*/
bool ConnectionManager::connectDevice()
{
devListItem connection_device = findDevice(m_availableDevList->currentText());
devListItem connection_device = findDevice(m_availableDevList->itemData(m_availableDevList->currentIndex(),Qt::ToolTipRole).toString());
if (!connection_device.connection)
return false;
QIODevice *io_dev = connection_device.connection->openDevice(connection_device.devName);
QIODevice *io_dev = connection_device.connection->openDevice(connection_device.Name);
if (!io_dev)
return false;
@ -244,15 +244,15 @@ void ConnectionManager::onConnectPressed()
/**
* Find a device by its displayed (visible on screen) name
*/
devListItem ConnectionManager::findDevice(const QString &displayedName)
devListItem ConnectionManager::findDevice(const QString &devName)
{
foreach (devListItem d, m_devList)
{
if (d.displayedName == displayedName)
if (d.devName == devName)
return d;
}
qDebug() << "findDevice: cannot find " << displayedName << " in device list";
qDebug() << "findDevice: cannot find " << devName << " in device list";
devListItem d;
d.connection = NULL;
@ -316,13 +316,13 @@ void ConnectionManager::unregisterAll(IConnection *connection)
/**
* Register a device from a specific connection plugin
*/
void ConnectionManager::registerDevice(IConnection *conn, const QString &devN, const QString &disp)
void ConnectionManager::registerDevice(IConnection *conn, const QString &devN, const QString &name, const QString &disp)
{
devListItem d;
d.connection = conn;
d.devName = devN;
d.displayedName = disp;
d.Name = name;
d.displayName=disp;
m_devList.append(d);
}
@ -340,21 +340,22 @@ void ConnectionManager::devChanged(IConnection *connection)
unregisterAll(connection);
//and add them back in the list
QStringList availableDev = connection->availableDevices();
foreach (QString dev, availableDev)
QList <IConnection::device> availableDev = connection->availableDevices();
foreach (IConnection::device dev, availableDev)
{
QString cbName = connection->shortName() + ": " + dev;
registerDevice(connection, dev, cbName);
QString cbName = connection->shortName() + ": " + dev.name;
registerDevice(connection,cbName,dev.name,dev.displayName);
}
//add all the list again to the combobox
foreach (devListItem d, m_devList)
{
m_availableDevList->addItem(d.displayedName);
m_availableDevList->addItem(d.displayName);
m_availableDevList->setItemData(m_availableDevList->count()-1,(const QString)d.devName,Qt::ToolTipRole);
}
//disable connection button if the list is empty
if (m_availableDevList->count() > 0)
//disable connection button if the liNameif (m_availableDevList->count() > 0)
if (m_availableDevList->count() > 0)
m_connectBtn->setEnabled(true);
else
m_connectBtn->setEnabled(false);

View File

@ -54,7 +54,8 @@ struct devListItem
{
IConnection *connection;
QString devName;
QString displayedName;
QString Name;
QString displayName;
};
@ -76,8 +77,8 @@ public:
protected:
void unregisterAll(IConnection *connection);
void registerDevice(IConnection *conn, const QString &devN, const QString &disp);
devListItem findDevice(const QString &displayedName);
void registerDevice(IConnection *conn, const QString &devN, const QString &name, const QString &disp);
devListItem findDevice(const QString &devName);
signals:
void deviceConnected(QIODevice *dev);

View File

@ -1,89 +1,96 @@
/**
******************************************************************************
*
* @file iconnection.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 ICONNECTION_H
#define ICONNECTION_H
#include <QObject>
#include <QtCore/QStringList>
#include <QtCore/QIODevice>
#include "core_global.h"
namespace Core {
/**
* An IConnection object define a "type of connection",
* for instance USB, Serial, Network, ...
*/
class CORE_EXPORT IConnection : public QObject
{
Q_OBJECT
public:
/**
* Return the list of devices found on the system
*/
virtual QStringList availableDevices() = 0;
/**
* Open a device, and return a QIODevice interface from it
* It should be a dynamically created object as it will be
* deleted by the connection manager.
*/
virtual QIODevice *openDevice(const QString &deviceName) = 0;
virtual void closeDevice(const QString &deviceName) { Q_UNUSED(deviceName) };
/**
* Connection type name "USB HID"
*/
virtual QString connectionName() = 0;
/**
* Short name to display in a combo box
*/
virtual QString shortName() {return connectionName();}
/**
* Manage whether the plugin is allowed to poll for devices
* or not
*/
virtual void suspendPolling() {};
virtual void resumePolling() {};
signals:
/**
* Available devices list has changed, signal it to connection manager (and whoever wants to know)
*/
void availableDevChanged(IConnection *);
};
} //namespace Core
#endif // ICONNECTION_H
/**
******************************************************************************
*
* @file iconnection.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 ICONNECTION_H
#define ICONNECTION_H
#include <QObject>
#include <QtCore/QStringList>
#include <QtCore/QIODevice>
#include "core_global.h"
namespace Core {
/**
* An IConnection object define a "type of connection",
* for instance USB, Serial, Network, ...
*/
class CORE_EXPORT IConnection : public QObject
{
Q_OBJECT
public:
/**
* Return the list of devices found on the system
*/
struct device
{
QString name;
QString displayName;
bool operator==(device i){return this->name==i.name;}
};
virtual QList <device> availableDevices() = 0;
/**
* Open a device, and return a QIODevice interface from it
* It should be a dynamically created object as it will be
* deleted by the connection manager.
*/
virtual QIODevice *openDevice(const QString &deviceName) = 0;
virtual void closeDevice(const QString &deviceName) { Q_UNUSED(deviceName) };
/**
* Connection type name "USB HID"
*/
virtual QString connectionName() = 0;
/**
* Short name to display in a combo box
*/
virtual QString shortName() {return connectionName();}
/**
* Manage whether the plugin is allowed to poll for devices
* or not
*/
virtual void suspendPolling() {};
virtual void resumePolling() {};
signals:
/**
* Available devices list has changed, signal it to connection manager (and whoever wants to know)
*/
void availableDevChanged(IConnection *);
};
} //namespace Core
#endif // ICONNECTION_H

View File

@ -1,261 +1,263 @@
/**
******************************************************************************
*
* @file IPconnectionplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup IPConnPlugin IP Telemetry Plugin
* @{
* @brief IP Connection Plugin impliment telemetry over TCP/IP and UDP/IP
*****************************************************************************/
/*
* 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
*/
//The core of this plugin has been directly copied from the serial plugin and converted to work over a TCP link instead of a direct serial link
#include "ipconnectionplugin.h"
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
#include "ipconnection_internal.h"
#include <QtCore/QtPlugin>
#include <QtGui/QMainWindow>
#include <QtGui/QMessageBox>
#include <QtNetwork/QAbstractSocket>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QUdpSocket>
#include <QWaitCondition>
#include <QMutex>
#include <coreplugin/threadmanager.h>
#include <QDebug>
//Communication between IPconnectionConnection::OpenDevice() and IPConnection::onOpenDevice()
QString errorMsg;
QWaitCondition openDeviceWait;
QWaitCondition closeDeviceWait;
//QReadWriteLock dummyLock;
QMutex ipConMutex;
QAbstractSocket *ret;
IPConnection::IPConnection(IPconnectionConnection *connection) : QObject()
{
moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread());
QObject::connect(connection, SIGNAL(CreateSocket(QString,int,bool)),
this, SLOT(onOpenDevice(QString,int,bool)));
QObject::connect(connection, SIGNAL(CloseSocket(QAbstractSocket*)),
this, SLOT(onCloseDevice(QAbstractSocket*)));
}
/*IPConnection::~IPConnection()
{
}*/
void IPConnection::onOpenDevice(QString HostName, int Port, bool UseTCP)
{
QAbstractSocket *ipSocket;
const int Timeout = 5 * 1000;
int state;
ipConMutex.lock();
if (UseTCP) {
ipSocket = new QTcpSocket(this);
} else {
ipSocket = new QUdpSocket(this);
}
//do sanity check on hostname and port...
if((HostName.length()==0)||(Port<1)){
errorMsg = "Please configure Host and Port options before opening the connection";
}
else {
//try to connect...
ipSocket->connectToHost(HostName, Port);
//in blocking mode so we wait for the connection to succeed
if (ipSocket->waitForConnected(Timeout)) {
ret = ipSocket;
openDeviceWait.wakeAll();
ipConMutex.unlock();
return;
}
//tell user something went wrong
errorMsg = ipSocket->errorString ();
}
/* BUGBUG TODO - returning null here leads to segfault because some caller still calls disconnect without checking our return value properly
* someone needs to debug this, I got lost in the calling chain.*/
ret = NULL;
openDeviceWait.wakeAll();
ipConMutex.unlock();
}
void IPConnection::onCloseDevice(QAbstractSocket *ipSocket)
{
ipConMutex.lock();
ipSocket->close ();
delete(ipSocket);
closeDeviceWait.wakeAll();
ipConMutex.unlock();
}
IPConnection * connection = 0;
IPconnectionConnection::IPconnectionConnection()
{
ipSocket = NULL;
//create all our objects
m_config = new IPconnectionConfiguration("IP Network Telemetry", NULL, this);
m_config->restoresettings();
m_optionspage = new IPconnectionOptionsPage(m_config,this);
if(!connection)
connection = new IPConnection(this);
//just signal whenever we have a device event...
QMainWindow *mw = Core::ICore::instance()->mainWindow();
QObject::connect(mw, SIGNAL(deviceChange()),
this, SLOT(onEnumerationChanged()));
QObject::connect(m_optionspage, SIGNAL(availableDevChanged()),
this, SLOT(onEnumerationChanged()));
}
IPconnectionConnection::~IPconnectionConnection()
{//clean up out resources...
if (ipSocket){
ipSocket->close ();
delete(ipSocket);
}
if(connection)
{
delete connection;
connection = NULL;
}
}
void IPconnectionConnection::onEnumerationChanged()
{//no change from serial plugin
emit availableDevChanged(this);
}
QStringList IPconnectionConnection::availableDevices()
{
QStringList list;
//we only have one "device" as defined by the configuration m_config
list.append((const QString )m_config->HostName());
return list;
}
QIODevice *IPconnectionConnection::openDevice(const QString &deviceName)
{
QString HostName;
int Port;
bool UseTCP;
QMessageBox msgBox;
//get the configuration info
HostName = m_config->HostName();
Port = m_config->Port();
UseTCP = m_config->UseTCP();
if (ipSocket){
//Andrew: close any existing socket... this should never occur
ipConMutex.lock();
emit CloseSocket(ipSocket);
closeDeviceWait.wait(&ipConMutex);
ipConMutex.unlock();
ipSocket = NULL;
}
ipConMutex.lock();
emit CreateSocket(HostName, Port, UseTCP);
openDeviceWait.wait(&ipConMutex);
ipConMutex.unlock();
ipSocket = ret;
if(ipSocket == NULL)
{
msgBox.setText((const QString )errorMsg);
msgBox.exec();
}
return ipSocket;
}
void IPconnectionConnection::closeDevice(const QString &deviceName)
{
if (ipSocket){
ipConMutex.lock();
emit CloseSocket(ipSocket);
closeDeviceWait.wait(&ipConMutex);
ipConMutex.unlock();
ipSocket = NULL;
}
}
QString IPconnectionConnection::connectionName()
{//updated from serial plugin
return QString("Network telemetry port");
}
QString IPconnectionConnection::shortName()
{//updated from serial plugin
if (m_config->UseTCP()) {
return QString("TCP");
} else {
return QString("UDP");
}
}
IPconnectionPlugin::IPconnectionPlugin()
{//no change from serial plugin
}
IPconnectionPlugin::~IPconnectionPlugin()
{//manually remove the options page object
removeObject(m_connection->Optionspage());
}
void IPconnectionPlugin::extensionsInitialized()
{
addAutoReleasedObject(m_connection);
}
bool IPconnectionPlugin::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(arguments);
Q_UNUSED(errorString);
m_connection = new IPconnectionConnection();
//must manage this registration of child object ourselves
//if we use an autorelease here it causes the GCS to crash
//as it is deleting objects as the app closes...
addObject(m_connection->Optionspage());
return true;
}
Q_EXPORT_PLUGIN(IPconnectionPlugin)
/**
******************************************************************************
*
* @file IPconnectionplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup IPConnPlugin IP Telemetry Plugin
* @{
* @brief IP Connection Plugin impliment telemetry over TCP/IP and UDP/IP
*****************************************************************************/
/*
* 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
*/
//The core of this plugin has been directly copied from the serial plugin and converted to work over a TCP link instead of a direct serial link
#include "ipconnectionplugin.h"
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
#include "ipconnection_internal.h"
#include <QtCore/QtPlugin>
#include <QtGui/QMainWindow>
#include <QtGui/QMessageBox>
#include <QtNetwork/QAbstractSocket>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QUdpSocket>
#include <QWaitCondition>
#include <QMutex>
#include <coreplugin/threadmanager.h>
#include <QDebug>
//Communication between IPconnectionConnection::OpenDevice() and IPConnection::onOpenDevice()
QString errorMsg;
QWaitCondition openDeviceWait;
QWaitCondition closeDeviceWait;
//QReadWriteLock dummyLock;
QMutex ipConMutex;
QAbstractSocket *ret;
IPConnection::IPConnection(IPconnectionConnection *connection) : QObject()
{
moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread());
QObject::connect(connection, SIGNAL(CreateSocket(QString,int,bool)),
this, SLOT(onOpenDevice(QString,int,bool)));
QObject::connect(connection, SIGNAL(CloseSocket(QAbstractSocket*)),
this, SLOT(onCloseDevice(QAbstractSocket*)));
}
/*IPConnection::~IPConnection()
{
}*/
void IPConnection::onOpenDevice(QString HostName, int Port, bool UseTCP)
{
QAbstractSocket *ipSocket;
const int Timeout = 5 * 1000;
int state;
ipConMutex.lock();
if (UseTCP) {
ipSocket = new QTcpSocket(this);
} else {
ipSocket = new QUdpSocket(this);
}
//do sanity check on hostname and port...
if((HostName.length()==0)||(Port<1)){
errorMsg = "Please configure Host and Port options before opening the connection";
}
else {
//try to connect...
ipSocket->connectToHost(HostName, Port);
//in blocking mode so we wait for the connection to succeed
if (ipSocket->waitForConnected(Timeout)) {
ret = ipSocket;
openDeviceWait.wakeAll();
ipConMutex.unlock();
return;
}
//tell user something went wrong
errorMsg = ipSocket->errorString ();
}
/* BUGBUG TODO - returning null here leads to segfault because some caller still calls disconnect without checking our return value properly
* someone needs to debug this, I got lost in the calling chain.*/
ret = NULL;
openDeviceWait.wakeAll();
ipConMutex.unlock();
}
void IPConnection::onCloseDevice(QAbstractSocket *ipSocket)
{
ipConMutex.lock();
ipSocket->close ();
delete(ipSocket);
closeDeviceWait.wakeAll();
ipConMutex.unlock();
}
IPConnection * connection = 0;
IPconnectionConnection::IPconnectionConnection()
{
ipSocket = NULL;
//create all our objects
m_config = new IPconnectionConfiguration("IP Network Telemetry", NULL, this);
m_config->restoresettings();
m_optionspage = new IPconnectionOptionsPage(m_config,this);
if(!connection)
connection = new IPConnection(this);
//just signal whenever we have a device event...
QMainWindow *mw = Core::ICore::instance()->mainWindow();
QObject::connect(mw, SIGNAL(deviceChange()),
this, SLOT(onEnumerationChanged()));
QObject::connect(m_optionspage, SIGNAL(availableDevChanged()),
this, SLOT(onEnumerationChanged()));
}
IPconnectionConnection::~IPconnectionConnection()
{//clean up out resources...
if (ipSocket){
ipSocket->close ();
delete(ipSocket);
}
if(connection)
{
delete connection;
connection = NULL;
}
}
void IPconnectionConnection::onEnumerationChanged()
{//no change from serial plugin
emit availableDevChanged(this);
}
QList <Core::IConnection::device> IPconnectionConnection::availableDevices()
{
QList <Core::IConnection::device> list;
device d;
d.displayName=(const QString )m_config->HostName();
d.name=(const QString )m_config->HostName();
//we only have one "device" as defined by the configuration m_config
list.append(d);
return list;
}
QIODevice *IPconnectionConnection::openDevice(const QString &deviceName)
{
QString HostName;
int Port;
bool UseTCP;
QMessageBox msgBox;
//get the configuration info
HostName = m_config->HostName();
Port = m_config->Port();
UseTCP = m_config->UseTCP();
if (ipSocket){
//Andrew: close any existing socket... this should never occur
ipConMutex.lock();
emit CloseSocket(ipSocket);
closeDeviceWait.wait(&ipConMutex);
ipConMutex.unlock();
ipSocket = NULL;
}
ipConMutex.lock();
emit CreateSocket(HostName, Port, UseTCP);
openDeviceWait.wait(&ipConMutex);
ipConMutex.unlock();
ipSocket = ret;
if(ipSocket == NULL)
{
msgBox.setText((const QString )errorMsg);
msgBox.exec();
}
return ipSocket;
}
void IPconnectionConnection::closeDevice(const QString &deviceName)
{
if (ipSocket){
ipConMutex.lock();
emit CloseSocket(ipSocket);
closeDeviceWait.wait(&ipConMutex);
ipConMutex.unlock();
ipSocket = NULL;
}
}
QString IPconnectionConnection::connectionName()
{//updated from serial plugin
return QString("Network telemetry port");
}
QString IPconnectionConnection::shortName()
{//updated from serial plugin
if (m_config->UseTCP()) {
return QString("TCP");
} else {
return QString("UDP");
}
}
IPconnectionPlugin::IPconnectionPlugin()
{//no change from serial plugin
}
IPconnectionPlugin::~IPconnectionPlugin()
{//manually remove the options page object
removeObject(m_connection->Optionspage());
}
void IPconnectionPlugin::extensionsInitialized()
{
addAutoReleasedObject(m_connection);
}
bool IPconnectionPlugin::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(arguments);
Q_UNUSED(errorString);
m_connection = new IPconnectionConnection();
//must manage this registration of child object ourselves
//if we use an autorelease here it causes the GCS to crash
//as it is deleting objects as the app closes...
addObject(m_connection->Optionspage());
return true;
}
Q_EXPORT_PLUGIN(IPconnectionPlugin)

View File

@ -1,103 +1,103 @@
/**
******************************************************************************
*
* @file IPconnectionplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup IPConnPlugin IP Telemetry Plugin
* @{
* @brief IP Connection Plugin impliment telemetry over TCP/IP and UDP/IP
*****************************************************************************/
/*
* 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 IPconnectionPLUGIN_H
#define IPconnectionPLUGIN_H
#include "ipconnection_global.h"
#include "ipconnectionoptionspage.h"
#include "ipconnectionconfiguration.h"
#include "coreplugin/iconnection.h"
#include <extensionsystem/iplugin.h>
//#include <QtCore/QSettings>
class QAbstractSocket;
class QTcpSocket;
class QUdpSocket;
class IConnection;
/**
* Define a connection via the IConnection interface
* Plugin will add a instance of this class to the pool,
* so the connection manager can use it.
*/
class IPconnection_EXPORT IPconnectionConnection
: public Core::IConnection
{
Q_OBJECT
public:
IPconnectionConnection();
virtual ~IPconnectionConnection();
virtual QStringList availableDevices();
virtual QIODevice *openDevice(const QString &deviceName);
virtual void closeDevice(const QString &deviceName);
virtual QString connectionName();
virtual QString shortName();
IPconnectionConfiguration * Config() const { return m_config; }
IPconnectionOptionsPage * Optionspage() const { return m_optionspage; }
protected slots:
void onEnumerationChanged();
signals: //For the benefit of IPConnection
void CreateSocket(QString HostName, int Port, bool UseTCP);
void CloseSocket(QAbstractSocket *socket);
private:
QAbstractSocket *ipSocket;
IPconnectionConfiguration *m_config;
IPconnectionOptionsPage *m_optionspage;
//QSettings* settings;
};
class IPconnection_EXPORT IPconnectionPlugin
: public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
IPconnectionPlugin();
~IPconnectionPlugin();
virtual bool initialize(const QStringList &arguments, QString *error_message);
virtual void extensionsInitialized();
private:
IPconnectionConnection *m_connection;
};
#endif // IPconnectionPLUGIN_H
/**
******************************************************************************
*
* @file IPconnectionplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup IPConnPlugin IP Telemetry Plugin
* @{
* @brief IP Connection Plugin impliment telemetry over TCP/IP and UDP/IP
*****************************************************************************/
/*
* 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 IPconnectionPLUGIN_H
#define IPconnectionPLUGIN_H
#include "ipconnection_global.h"
#include "ipconnectionoptionspage.h"
#include "ipconnectionconfiguration.h"
#include "coreplugin/iconnection.h"
#include <extensionsystem/iplugin.h>
//#include <QtCore/QSettings>
class QAbstractSocket;
class QTcpSocket;
class QUdpSocket;
class IConnection;
/**
* Define a connection via the IConnection interface
* Plugin will add a instance of this class to the pool,
* so the connection manager can use it.
*/
class IPconnection_EXPORT IPconnectionConnection
: public Core::IConnection
{
Q_OBJECT
public:
IPconnectionConnection();
virtual ~IPconnectionConnection();
virtual QList <Core::IConnection::device> availableDevices();
virtual QIODevice *openDevice(const QString &deviceName);
virtual void closeDevice(const QString &deviceName);
virtual QString connectionName();
virtual QString shortName();
IPconnectionConfiguration * Config() const { return m_config; }
IPconnectionOptionsPage * Optionspage() const { return m_optionspage; }
protected slots:
void onEnumerationChanged();
signals: //For the benefit of IPConnection
void CreateSocket(QString HostName, int Port, bool UseTCP);
void CloseSocket(QAbstractSocket *socket);
private:
QAbstractSocket *ipSocket;
IPconnectionConfiguration *m_config;
IPconnectionOptionsPage *m_optionspage;
//QSettings* settings;
};
class IPconnection_EXPORT IPconnectionPlugin
: public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
IPconnectionPlugin();
~IPconnectionPlugin();
virtual bool initialize(const QStringList &arguments, QString *error_message);
virtual void extensionsInitialized();
private:
IPconnectionConnection *m_connection;
};
#endif // IPconnectionPLUGIN_H

View File

@ -58,10 +58,13 @@ void LoggingConnection::onEnumerationChanged()
emit availableDevChanged(this);
}
QStringList LoggingConnection::availableDevices()
QList <Core::IConnection::device> LoggingConnection::availableDevices()
{
QStringList list;
list << "Logfile replay...";
QList <device> list;
device d;
d.displayName="Logfile replay...";
d.name="Logfile replay...";
list <<d;
return list;
}

View File

@ -57,7 +57,7 @@ public:
LoggingConnection();
virtual ~LoggingConnection();
virtual QStringList availableDevices();
virtual QList <Core::IConnection::device> availableDevices();
virtual QIODevice *openDevice(const QString &deviceName);
virtual void closeDevice(const QString &deviceName);

View File

@ -79,14 +79,17 @@ void RawHIDConnection::onDeviceDisconnected()
/**
Returns the list of all currently available devices
*/
QStringList RawHIDConnection::availableDevices()
QList < Core::IConnection::device> RawHIDConnection::availableDevices()
{
QStringList devices;
QList < Core::IConnection::device> devices;
QList<USBPortInfo> portsList = m_usbMonitor->availableDevices(USBMonitor::idVendor_OpenPilot, -1, -1,USBMonitor::Running);
// We currently list devices by their serial number
device dev;
foreach(USBPortInfo prt, portsList) {
devices.append(prt.serialNumber);
dev.name=prt.serialNumber;
dev.displayName=prt.product;
devices.append(dev);
}
return devices;
}

View File

@ -55,7 +55,7 @@ public:
RawHIDConnection();
virtual ~RawHIDConnection();
virtual QStringList availableDevices();
virtual QList < Core::IConnection::device> availableDevices();
virtual QIODevice *openDevice(const QString &deviceName);
virtual void closeDevice(const QString &deviceName);

View File

@ -1,222 +1,225 @@
/**
******************************************************************************
*
* @file serialplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup SerialPlugin Serial Connection Plugin
* @{
* @brief Impliments serial connection to the flight hardware for Telemetry
*****************************************************************************/
/*
* 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 "serialplugin.h"
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
#include <QtCore/QtPlugin>
#include <QtGui/QMainWindow>
#include <QDebug>
SerialEnumerationThread::SerialEnumerationThread(SerialConnection *serial)
: m_serial(serial),
m_running(true)
{
}
SerialEnumerationThread::~SerialEnumerationThread()
{
m_running = false;
//wait for the thread to terminate
if(wait(2100) == false)
qDebug() << "Cannot terminate SerialEnumerationThread";
}
void SerialEnumerationThread::run()
{
QStringList devices = m_serial->availableDevices();
while(m_running)
{
if(!m_serial->deviceOpened())
{
QStringList newDev = m_serial->availableDevices();
if(devices != newDev)
{
devices = newDev;
emit enumerationChanged();
}
}
msleep(2000); //update available devices every two seconds (doesn't need more)
}
}
SerialConnection::SerialConnection()
: enablePolling(true), m_enumerateThread(this)
{
serialHandle = NULL;
// Experimental: enable polling on all OS'es since there
// were reports that autodetect does not work on XP amongst
// others.
//#ifdef Q_OS_WIN
// //I'm cheating a little bit here:
// //Knowing if the device enumeration really changed is a bit complicated
// //so I just signal it whenever we have a device event...
// QMainWindow *mw = Core::ICore::instance()->mainWindow();
// QObject::connect(mw, SIGNAL(deviceChange()),
// this, SLOT(onEnumerationChanged()));
//#else
// Other OSes do not send such signals:
QObject::connect(&m_enumerateThread, SIGNAL(enumerationChanged()),
this, SLOT(onEnumerationChanged()));
m_enumerateThread.start();
//#endif
}
SerialConnection::~SerialConnection()
{
}
void SerialConnection::onEnumerationChanged()
{
if (enablePolling)
emit availableDevChanged(this);
}
bool sortPorts(const QextPortInfo &s1,const QextPortInfo &s2)
{
return s1.portName<s2.portName;
}
QStringList SerialConnection::availableDevices()
{
QStringList list;
if (enablePolling) {
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
//sort the list by port number (nice idea from PT_Dreamer :))
qSort(ports.begin(), ports.end(),sortPorts);
foreach( QextPortInfo port, ports ) {
list.append(port.friendName);
}
}
return list;
}
QIODevice *SerialConnection::openDevice(const QString &deviceName)
{
if (serialHandle){
closeDevice(deviceName);
}
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
foreach( QextPortInfo port, ports ) {
if(port.friendName == deviceName)
{
//we need to handle port settings here...
PortSettings set;
set.BaudRate = BAUD57600;
set.DataBits = DATA_8;
set.Parity = PAR_NONE;
set.StopBits = STOP_1;
set.FlowControl = FLOW_OFF;
set.Timeout_Millisec = 500;
#ifdef Q_OS_WIN
serialHandle = new QextSerialPort(port.portName, set);
#else
serialHandle = new QextSerialPort(port.physName, set);
#endif
m_deviceOpened = true;
return serialHandle;
}
}
return NULL;
}
void SerialConnection::closeDevice(const QString &deviceName)
{
Q_UNUSED(deviceName);
//we have to delete the serial connection we created
if (serialHandle){
serialHandle->close ();
delete(serialHandle);
serialHandle = NULL;
m_deviceOpened = false;
}
}
QString SerialConnection::connectionName()
{
return QString("Serial port");
}
QString SerialConnection::shortName()
{
return QString("Serial");
}
/**
Tells the Serial plugin to stop polling for serial devices
*/
void SerialConnection::suspendPolling()
{
enablePolling = false;
}
/**
Tells the Serial plugin to resume polling for serial devices
*/
void SerialConnection::resumePolling()
{
enablePolling = true;
}
SerialPlugin::SerialPlugin()
{
}
SerialPlugin::~SerialPlugin()
{
}
void SerialPlugin::extensionsInitialized()
{
addAutoReleasedObject(new SerialConnection);
}
bool SerialPlugin::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(arguments);
Q_UNUSED(errorString);
return true;
}
Q_EXPORT_PLUGIN(SerialPlugin)
/**
******************************************************************************
*
* @file serialplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup SerialPlugin Serial Connection Plugin
* @{
* @brief Impliments serial connection to the flight hardware for Telemetry
*****************************************************************************/
/*
* 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 "serialplugin.h"
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
#include <QtCore/QtPlugin>
#include <QtGui/QMainWindow>
#include <QDebug>
SerialEnumerationThread::SerialEnumerationThread(SerialConnection *serial)
: m_serial(serial),
m_running(true)
{
}
SerialEnumerationThread::~SerialEnumerationThread()
{
m_running = false;
//wait for the thread to terminate
if(wait(2100) == false)
qDebug() << "Cannot terminate SerialEnumerationThread";
}
void SerialEnumerationThread::run()
{
QList <Core::IConnection::device> devices = m_serial->availableDevices();
while(m_running)
{
if(!m_serial->deviceOpened())
{
QList <Core::IConnection::device> newDev = m_serial->availableDevices();
if(devices != newDev)
{
devices = newDev;
emit enumerationChanged();
}
}
msleep(2000); //update available devices every two seconds (doesn't need more)
}
}
SerialConnection::SerialConnection()
: enablePolling(true), m_enumerateThread(this)
{
serialHandle = NULL;
// Experimental: enable polling on all OS'es since there
// were reports that autodetect does not work on XP amongst
// others.
//#ifdef Q_OS_WIN
// //I'm cheating a little bit here:
// //Knowing if the device enumeration really changed is a bit complicated
// //so I just signal it whenever we have a device event...
// QMainWindow *mw = Core::ICore::instance()->mainWindow();
// QObject::connect(mw, SIGNAL(deviceChange()),
// this, SLOT(onEnumerationChanged()));
//#else
// Other OSes do not send such signals:
QObject::connect(&m_enumerateThread, SIGNAL(enumerationChanged()),
this, SLOT(onEnumerationChanged()));
m_enumerateThread.start();
//#endif
}
SerialConnection::~SerialConnection()
{
}
void SerialConnection::onEnumerationChanged()
{
if (enablePolling)
emit availableDevChanged(this);
}
bool sortPorts(const QextPortInfo &s1,const QextPortInfo &s2)
{
return s1.portName<s2.portName;
}
QList <Core::IConnection::device> SerialConnection::availableDevices()
{
QList <Core::IConnection::device> list;
if (enablePolling) {
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
//sort the list by port number (nice idea from PT_Dreamer :))
qSort(ports.begin(), ports.end(),sortPorts);
foreach( QextPortInfo port, ports ) {
device d;
d.displayName=port.friendName;
d.name=port.friendName;
list.append(d);
}
}
return list;
}
QIODevice *SerialConnection::openDevice(const QString &deviceName)
{
if (serialHandle){
closeDevice(deviceName);
}
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
foreach( QextPortInfo port, ports ) {
if(port.friendName == deviceName)
{
//we need to handle port settings here...
PortSettings set;
set.BaudRate = BAUD57600;
set.DataBits = DATA_8;
set.Parity = PAR_NONE;
set.StopBits = STOP_1;
set.FlowControl = FLOW_OFF;
set.Timeout_Millisec = 500;
#ifdef Q_OS_WIN
serialHandle = new QextSerialPort(port.portName, set);
#else
serialHandle = new QextSerialPort(port.physName, set);
#endif
m_deviceOpened = true;
return serialHandle;
}
}
return NULL;
}
void SerialConnection::closeDevice(const QString &deviceName)
{
Q_UNUSED(deviceName);
//we have to delete the serial connection we created
if (serialHandle){
serialHandle->close ();
delete(serialHandle);
serialHandle = NULL;
m_deviceOpened = false;
}
}
QString SerialConnection::connectionName()
{
return QString("Serial port");
}
QString SerialConnection::shortName()
{
return QString("Serial");
}
/**
Tells the Serial plugin to stop polling for serial devices
*/
void SerialConnection::suspendPolling()
{
enablePolling = false;
}
/**
Tells the Serial plugin to resume polling for serial devices
*/
void SerialConnection::resumePolling()
{
enablePolling = true;
}
SerialPlugin::SerialPlugin()
{
}
SerialPlugin::~SerialPlugin()
{
}
void SerialPlugin::extensionsInitialized()
{
addAutoReleasedObject(new SerialConnection);
}
bool SerialPlugin::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(arguments);
Q_UNUSED(errorString);
return true;
}
Q_EXPORT_PLUGIN(SerialPlugin)

View File

@ -1,122 +1,122 @@
/**
******************************************************************************
*
* @file serialplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup SerialPlugin Serial Connection Plugin
* @{
* @brief Impliments serial connection to the flight hardware for Telemetry
*****************************************************************************/
/*
* 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 SERIALPLUGIN_H
#define SERIALPLUGIN_H
//#include "serial_global.h"
#include <qextserialport.h>
#include <qextserialenumerator.h>
#include "coreplugin/iconnection.h"
#include <extensionsystem/iplugin.h>
#include <QThread>
class IConnection;
class QextSerialEnumerator;
class SerialConnection;
/**
* Helper thread to check on new serial port connection/disconnection
* Some operating systems do not send device insertion events so
* for those we have to poll
*/
//class SERIAL_EXPORT SerialEnumerationThread : public QThread
class SerialEnumerationThread : public QThread
{
Q_OBJECT
public:
SerialEnumerationThread(SerialConnection *serial);
virtual ~SerialEnumerationThread();
virtual void run();
signals:
void enumerationChanged();
protected:
SerialConnection *m_serial;
bool m_running;
};
/**
* Define a connection via the IConnection interface
* Plugin will add a instance of this class to the pool,
* so the connection manager can use it.
*/
//class SERIAL_EXPORT SerialConnection
class SerialConnection
: public Core::IConnection
{
Q_OBJECT
public:
SerialConnection();
virtual ~SerialConnection();
virtual QStringList availableDevices();
virtual QIODevice *openDevice(const QString &deviceName);
virtual void closeDevice(const QString &deviceName);
virtual QString connectionName();
virtual QString shortName();
virtual void suspendPolling();
virtual void resumePolling();
bool deviceOpened() {return m_deviceOpened;}
private:
QextSerialPort* serialHandle;
bool enablePolling;
protected slots:
void onEnumerationChanged();
protected:
SerialEnumerationThread m_enumerateThread;
bool m_deviceOpened;
};
//class SERIAL_EXPORT SerialPlugin
class SerialPlugin
: public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
SerialPlugin();
~SerialPlugin();
virtual bool initialize(const QStringList &arguments, QString *error_message);
virtual void extensionsInitialized();
};
#endif // SERIALPLUGIN_H
/**
******************************************************************************
*
* @file serialplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup SerialPlugin Serial Connection Plugin
* @{
* @brief Impliments serial connection to the flight hardware for Telemetry
*****************************************************************************/
/*
* 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 SERIALPLUGIN_H
#define SERIALPLUGIN_H
//#include "serial_global.h"
#include <qextserialport.h>
#include <qextserialenumerator.h>
#include "coreplugin/iconnection.h"
#include <extensionsystem/iplugin.h>
#include <QThread>
class IConnection;
class QextSerialEnumerator;
class SerialConnection;
/**
* Helper thread to check on new serial port connection/disconnection
* Some operating systems do not send device insertion events so
* for those we have to poll
*/
//class SERIAL_EXPORT SerialEnumerationThread : public QThread
class SerialEnumerationThread : public QThread
{
Q_OBJECT
public:
SerialEnumerationThread(SerialConnection *serial);
virtual ~SerialEnumerationThread();
virtual void run();
signals:
void enumerationChanged();
protected:
SerialConnection *m_serial;
bool m_running;
};
/**
* Define a connection via the IConnection interface
* Plugin will add a instance of this class to the pool,
* so the connection manager can use it.
*/
//class SERIAL_EXPORT SerialConnection
class SerialConnection
: public Core::IConnection
{
Q_OBJECT
public:
SerialConnection();
virtual ~SerialConnection();
virtual QList <Core::IConnection::device> availableDevices();
virtual QIODevice *openDevice(const QString &deviceName);
virtual void closeDevice(const QString &deviceName);
virtual QString connectionName();
virtual QString shortName();
virtual void suspendPolling();
virtual void resumePolling();
bool deviceOpened() {return m_deviceOpened;}
private:
QextSerialPort* serialHandle;
bool enablePolling;
protected slots:
void onEnumerationChanged();
protected:
SerialEnumerationThread m_enumerateThread;
bool m_deviceOpened;
};
//class SERIAL_EXPORT SerialPlugin
class SerialPlugin
: public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
SerialPlugin();
~SerialPlugin();
virtual bool initialize(const QStringList &arguments, QString *error_message);
virtual void extensionsInitialized();
};
#endif // SERIALPLUGIN_H