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:
parent
3665209195
commit
6bcacb1630
@ -106,11 +106,11 @@ void ConnectionManager::init()
|
|||||||
*/
|
*/
|
||||||
bool ConnectionManager::connectDevice()
|
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)
|
if (!connection_device.connection)
|
||||||
return false;
|
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)
|
if (!io_dev)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -244,15 +244,15 @@ void ConnectionManager::onConnectPressed()
|
|||||||
/**
|
/**
|
||||||
* Find a device by its displayed (visible on screen) name
|
* 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)
|
foreach (devListItem d, m_devList)
|
||||||
{
|
{
|
||||||
if (d.displayedName == displayedName)
|
if (d.devName == devName)
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "findDevice: cannot find " << displayedName << " in device list";
|
qDebug() << "findDevice: cannot find " << devName << " in device list";
|
||||||
|
|
||||||
devListItem d;
|
devListItem d;
|
||||||
d.connection = NULL;
|
d.connection = NULL;
|
||||||
@ -316,13 +316,13 @@ void ConnectionManager::unregisterAll(IConnection *connection)
|
|||||||
/**
|
/**
|
||||||
* Register a device from a specific connection plugin
|
* 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;
|
devListItem d;
|
||||||
d.connection = conn;
|
d.connection = conn;
|
||||||
d.devName = devN;
|
d.devName = devN;
|
||||||
d.displayedName = disp;
|
d.Name = name;
|
||||||
|
d.displayName=disp;
|
||||||
m_devList.append(d);
|
m_devList.append(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,21 +340,22 @@ void ConnectionManager::devChanged(IConnection *connection)
|
|||||||
unregisterAll(connection);
|
unregisterAll(connection);
|
||||||
|
|
||||||
//and add them back in the list
|
//and add them back in the list
|
||||||
QStringList availableDev = connection->availableDevices();
|
QList <IConnection::device> availableDev = connection->availableDevices();
|
||||||
foreach (QString dev, availableDev)
|
foreach (IConnection::device dev, availableDev)
|
||||||
{
|
{
|
||||||
QString cbName = connection->shortName() + ": " + dev;
|
QString cbName = connection->shortName() + ": " + dev.name;
|
||||||
registerDevice(connection, dev, cbName);
|
registerDevice(connection,cbName,dev.name,dev.displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//add all the list again to the combobox
|
//add all the list again to the combobox
|
||||||
foreach (devListItem d, m_devList)
|
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
|
//disable connection button if the liNameif (m_availableDevList->count() > 0)
|
||||||
if (m_availableDevList->count() > 0)
|
if (m_availableDevList->count() > 0)
|
||||||
m_connectBtn->setEnabled(true);
|
m_connectBtn->setEnabled(true);
|
||||||
else
|
else
|
||||||
m_connectBtn->setEnabled(false);
|
m_connectBtn->setEnabled(false);
|
||||||
|
@ -54,7 +54,8 @@ struct devListItem
|
|||||||
{
|
{
|
||||||
IConnection *connection;
|
IConnection *connection;
|
||||||
QString devName;
|
QString devName;
|
||||||
QString displayedName;
|
QString Name;
|
||||||
|
QString displayName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -76,8 +77,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void unregisterAll(IConnection *connection);
|
void unregisterAll(IConnection *connection);
|
||||||
void registerDevice(IConnection *conn, const QString &devN, const QString &disp);
|
void registerDevice(IConnection *conn, const QString &devN, const QString &name, const QString &disp);
|
||||||
devListItem findDevice(const QString &displayedName);
|
devListItem findDevice(const QString &devName);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deviceConnected(QIODevice *dev);
|
void deviceConnected(QIODevice *dev);
|
||||||
|
@ -1,89 +1,96 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file iconnection.h
|
* @file iconnection.h
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||||
* @addtogroup GCSPlugins GCS Plugins
|
* @addtogroup GCSPlugins GCS Plugins
|
||||||
* @{
|
* @{
|
||||||
* @addtogroup CorePlugin Core Plugin
|
* @addtogroup CorePlugin Core Plugin
|
||||||
* @{
|
* @{
|
||||||
* @brief The Core GCS plugin
|
* @brief The Core GCS plugin
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* 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.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ICONNECTION_H
|
#ifndef ICONNECTION_H
|
||||||
#define ICONNECTION_H
|
#define ICONNECTION_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
#include <QtCore/QIODevice>
|
#include <QtCore/QIODevice>
|
||||||
|
|
||||||
#include "core_global.h"
|
#include "core_global.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An IConnection object define a "type of connection",
|
* An IConnection object define a "type of connection",
|
||||||
* for instance USB, Serial, Network, ...
|
* for instance USB, Serial, Network, ...
|
||||||
*/
|
*/
|
||||||
class CORE_EXPORT IConnection : public QObject
|
class CORE_EXPORT IConnection : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Return the list of devices found on the system
|
* Return the list of devices found on the system
|
||||||
*/
|
*/
|
||||||
virtual QStringList availableDevices() = 0;
|
struct device
|
||||||
|
{
|
||||||
/**
|
QString name;
|
||||||
* Open a device, and return a QIODevice interface from it
|
QString displayName;
|
||||||
* It should be a dynamically created object as it will be
|
bool operator==(device i){return this->name==i.name;}
|
||||||
* deleted by the connection manager.
|
};
|
||||||
*/
|
|
||||||
virtual QIODevice *openDevice(const QString &deviceName) = 0;
|
virtual QList <device> availableDevices() = 0;
|
||||||
|
|
||||||
virtual void closeDevice(const QString &deviceName) { Q_UNUSED(deviceName) };
|
/**
|
||||||
|
* Open a device, and return a QIODevice interface from it
|
||||||
/**
|
* It should be a dynamically created object as it will be
|
||||||
* Connection type name "USB HID"
|
* deleted by the connection manager.
|
||||||
*/
|
*/
|
||||||
virtual QString connectionName() = 0;
|
virtual QIODevice *openDevice(const QString &deviceName) = 0;
|
||||||
|
|
||||||
/**
|
virtual void closeDevice(const QString &deviceName) { Q_UNUSED(deviceName) };
|
||||||
* Short name to display in a combo box
|
|
||||||
*/
|
/**
|
||||||
virtual QString shortName() {return connectionName();}
|
* Connection type name "USB HID"
|
||||||
|
*/
|
||||||
/**
|
virtual QString connectionName() = 0;
|
||||||
* Manage whether the plugin is allowed to poll for devices
|
|
||||||
* or not
|
/**
|
||||||
*/
|
* Short name to display in a combo box
|
||||||
virtual void suspendPolling() {};
|
*/
|
||||||
virtual void resumePolling() {};
|
virtual QString shortName() {return connectionName();}
|
||||||
|
|
||||||
signals:
|
/**
|
||||||
/**
|
* Manage whether the plugin is allowed to poll for devices
|
||||||
* Available devices list has changed, signal it to connection manager (and whoever wants to know)
|
* or not
|
||||||
*/
|
*/
|
||||||
void availableDevChanged(IConnection *);
|
virtual void suspendPolling() {};
|
||||||
};
|
virtual void resumePolling() {};
|
||||||
|
|
||||||
} //namespace Core
|
signals:
|
||||||
|
/**
|
||||||
#endif // ICONNECTION_H
|
* Available devices list has changed, signal it to connection manager (and whoever wants to know)
|
||||||
|
*/
|
||||||
|
void availableDevChanged(IConnection *);
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace Core
|
||||||
|
|
||||||
|
#endif // ICONNECTION_H
|
||||||
|
@ -1,261 +1,263 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file IPconnectionplugin.cpp
|
* @file IPconnectionplugin.cpp
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
* @addtogroup GCSPlugins GCS Plugins
|
* @addtogroup GCSPlugins GCS Plugins
|
||||||
* @{
|
* @{
|
||||||
* @addtogroup IPConnPlugin IP Telemetry Plugin
|
* @addtogroup IPConnPlugin IP Telemetry Plugin
|
||||||
* @{
|
* @{
|
||||||
* @brief IP Connection Plugin impliment telemetry over TCP/IP and UDP/IP
|
* @brief IP Connection Plugin impliment telemetry over TCP/IP and UDP/IP
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* 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.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 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
|
//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 "ipconnectionplugin.h"
|
||||||
|
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include "ipconnection_internal.h"
|
#include "ipconnection_internal.h"
|
||||||
|
|
||||||
#include <QtCore/QtPlugin>
|
#include <QtCore/QtPlugin>
|
||||||
#include <QtGui/QMainWindow>
|
#include <QtGui/QMainWindow>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
#include <QtNetwork/QAbstractSocket>
|
#include <QtNetwork/QAbstractSocket>
|
||||||
#include <QtNetwork/QTcpSocket>
|
#include <QtNetwork/QTcpSocket>
|
||||||
#include <QtNetwork/QUdpSocket>
|
#include <QtNetwork/QUdpSocket>
|
||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <coreplugin/threadmanager.h>
|
#include <coreplugin/threadmanager.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
//Communication between IPconnectionConnection::OpenDevice() and IPConnection::onOpenDevice()
|
//Communication between IPconnectionConnection::OpenDevice() and IPConnection::onOpenDevice()
|
||||||
QString errorMsg;
|
QString errorMsg;
|
||||||
QWaitCondition openDeviceWait;
|
QWaitCondition openDeviceWait;
|
||||||
QWaitCondition closeDeviceWait;
|
QWaitCondition closeDeviceWait;
|
||||||
//QReadWriteLock dummyLock;
|
//QReadWriteLock dummyLock;
|
||||||
QMutex ipConMutex;
|
QMutex ipConMutex;
|
||||||
QAbstractSocket *ret;
|
QAbstractSocket *ret;
|
||||||
|
|
||||||
IPConnection::IPConnection(IPconnectionConnection *connection) : QObject()
|
IPConnection::IPConnection(IPconnectionConnection *connection) : QObject()
|
||||||
{
|
{
|
||||||
moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread());
|
moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread());
|
||||||
|
|
||||||
QObject::connect(connection, SIGNAL(CreateSocket(QString,int,bool)),
|
QObject::connect(connection, SIGNAL(CreateSocket(QString,int,bool)),
|
||||||
this, SLOT(onOpenDevice(QString,int,bool)));
|
this, SLOT(onOpenDevice(QString,int,bool)));
|
||||||
QObject::connect(connection, SIGNAL(CloseSocket(QAbstractSocket*)),
|
QObject::connect(connection, SIGNAL(CloseSocket(QAbstractSocket*)),
|
||||||
this, SLOT(onCloseDevice(QAbstractSocket*)));
|
this, SLOT(onCloseDevice(QAbstractSocket*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*IPConnection::~IPConnection()
|
/*IPConnection::~IPConnection()
|
||||||
{
|
{
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
void IPConnection::onOpenDevice(QString HostName, int Port, bool UseTCP)
|
void IPConnection::onOpenDevice(QString HostName, int Port, bool UseTCP)
|
||||||
{
|
{
|
||||||
QAbstractSocket *ipSocket;
|
QAbstractSocket *ipSocket;
|
||||||
const int Timeout = 5 * 1000;
|
const int Timeout = 5 * 1000;
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
ipConMutex.lock();
|
ipConMutex.lock();
|
||||||
if (UseTCP) {
|
if (UseTCP) {
|
||||||
ipSocket = new QTcpSocket(this);
|
ipSocket = new QTcpSocket(this);
|
||||||
} else {
|
} else {
|
||||||
ipSocket = new QUdpSocket(this);
|
ipSocket = new QUdpSocket(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//do sanity check on hostname and port...
|
//do sanity check on hostname and port...
|
||||||
if((HostName.length()==0)||(Port<1)){
|
if((HostName.length()==0)||(Port<1)){
|
||||||
errorMsg = "Please configure Host and Port options before opening the connection";
|
errorMsg = "Please configure Host and Port options before opening the connection";
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//try to connect...
|
//try to connect...
|
||||||
ipSocket->connectToHost(HostName, Port);
|
ipSocket->connectToHost(HostName, Port);
|
||||||
|
|
||||||
//in blocking mode so we wait for the connection to succeed
|
//in blocking mode so we wait for the connection to succeed
|
||||||
if (ipSocket->waitForConnected(Timeout)) {
|
if (ipSocket->waitForConnected(Timeout)) {
|
||||||
ret = ipSocket;
|
ret = ipSocket;
|
||||||
openDeviceWait.wakeAll();
|
openDeviceWait.wakeAll();
|
||||||
ipConMutex.unlock();
|
ipConMutex.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//tell user something went wrong
|
//tell user something went wrong
|
||||||
errorMsg = ipSocket->errorString ();
|
errorMsg = ipSocket->errorString ();
|
||||||
}
|
}
|
||||||
/* BUGBUG TODO - returning null here leads to segfault because some caller still calls disconnect without checking our return value properly
|
/* 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.*/
|
* someone needs to debug this, I got lost in the calling chain.*/
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
openDeviceWait.wakeAll();
|
openDeviceWait.wakeAll();
|
||||||
ipConMutex.unlock();
|
ipConMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPConnection::onCloseDevice(QAbstractSocket *ipSocket)
|
void IPConnection::onCloseDevice(QAbstractSocket *ipSocket)
|
||||||
{
|
{
|
||||||
ipConMutex.lock();
|
ipConMutex.lock();
|
||||||
ipSocket->close ();
|
ipSocket->close ();
|
||||||
delete(ipSocket);
|
delete(ipSocket);
|
||||||
closeDeviceWait.wakeAll();
|
closeDeviceWait.wakeAll();
|
||||||
ipConMutex.unlock();
|
ipConMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IPConnection * connection = 0;
|
IPConnection * connection = 0;
|
||||||
|
|
||||||
IPconnectionConnection::IPconnectionConnection()
|
IPconnectionConnection::IPconnectionConnection()
|
||||||
{
|
{
|
||||||
ipSocket = NULL;
|
ipSocket = NULL;
|
||||||
//create all our objects
|
//create all our objects
|
||||||
m_config = new IPconnectionConfiguration("IP Network Telemetry", NULL, this);
|
m_config = new IPconnectionConfiguration("IP Network Telemetry", NULL, this);
|
||||||
m_config->restoresettings();
|
m_config->restoresettings();
|
||||||
|
|
||||||
m_optionspage = new IPconnectionOptionsPage(m_config,this);
|
m_optionspage = new IPconnectionOptionsPage(m_config,this);
|
||||||
|
|
||||||
if(!connection)
|
if(!connection)
|
||||||
connection = new IPConnection(this);
|
connection = new IPConnection(this);
|
||||||
|
|
||||||
//just signal whenever we have a device event...
|
//just signal whenever we have a device event...
|
||||||
QMainWindow *mw = Core::ICore::instance()->mainWindow();
|
QMainWindow *mw = Core::ICore::instance()->mainWindow();
|
||||||
QObject::connect(mw, SIGNAL(deviceChange()),
|
QObject::connect(mw, SIGNAL(deviceChange()),
|
||||||
this, SLOT(onEnumerationChanged()));
|
this, SLOT(onEnumerationChanged()));
|
||||||
QObject::connect(m_optionspage, SIGNAL(availableDevChanged()),
|
QObject::connect(m_optionspage, SIGNAL(availableDevChanged()),
|
||||||
this, SLOT(onEnumerationChanged()));
|
this, SLOT(onEnumerationChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
IPconnectionConnection::~IPconnectionConnection()
|
IPconnectionConnection::~IPconnectionConnection()
|
||||||
{//clean up out resources...
|
{//clean up out resources...
|
||||||
if (ipSocket){
|
if (ipSocket){
|
||||||
ipSocket->close ();
|
ipSocket->close ();
|
||||||
delete(ipSocket);
|
delete(ipSocket);
|
||||||
}
|
}
|
||||||
if(connection)
|
if(connection)
|
||||||
{
|
{
|
||||||
delete connection;
|
delete connection;
|
||||||
connection = NULL;
|
connection = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPconnectionConnection::onEnumerationChanged()
|
void IPconnectionConnection::onEnumerationChanged()
|
||||||
{//no change from serial plugin
|
{//no change from serial plugin
|
||||||
emit availableDevChanged(this);
|
emit availableDevChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QStringList IPconnectionConnection::availableDevices()
|
QList <Core::IConnection::device> IPconnectionConnection::availableDevices()
|
||||||
{
|
{
|
||||||
QStringList list;
|
QList <Core::IConnection::device> list;
|
||||||
|
device d;
|
||||||
//we only have one "device" as defined by the configuration m_config
|
d.displayName=(const QString )m_config->HostName();
|
||||||
list.append((const QString )m_config->HostName());
|
d.name=(const QString )m_config->HostName();
|
||||||
|
//we only have one "device" as defined by the configuration m_config
|
||||||
return list;
|
list.append(d);
|
||||||
}
|
|
||||||
|
return list;
|
||||||
QIODevice *IPconnectionConnection::openDevice(const QString &deviceName)
|
}
|
||||||
{
|
|
||||||
QString HostName;
|
QIODevice *IPconnectionConnection::openDevice(const QString &deviceName)
|
||||||
int Port;
|
{
|
||||||
bool UseTCP;
|
QString HostName;
|
||||||
QMessageBox msgBox;
|
int Port;
|
||||||
|
bool UseTCP;
|
||||||
//get the configuration info
|
QMessageBox msgBox;
|
||||||
HostName = m_config->HostName();
|
|
||||||
Port = m_config->Port();
|
//get the configuration info
|
||||||
UseTCP = m_config->UseTCP();
|
HostName = m_config->HostName();
|
||||||
|
Port = m_config->Port();
|
||||||
if (ipSocket){
|
UseTCP = m_config->UseTCP();
|
||||||
//Andrew: close any existing socket... this should never occur
|
|
||||||
ipConMutex.lock();
|
if (ipSocket){
|
||||||
emit CloseSocket(ipSocket);
|
//Andrew: close any existing socket... this should never occur
|
||||||
closeDeviceWait.wait(&ipConMutex);
|
ipConMutex.lock();
|
||||||
ipConMutex.unlock();
|
emit CloseSocket(ipSocket);
|
||||||
ipSocket = NULL;
|
closeDeviceWait.wait(&ipConMutex);
|
||||||
}
|
ipConMutex.unlock();
|
||||||
|
ipSocket = NULL;
|
||||||
ipConMutex.lock();
|
}
|
||||||
emit CreateSocket(HostName, Port, UseTCP);
|
|
||||||
openDeviceWait.wait(&ipConMutex);
|
ipConMutex.lock();
|
||||||
ipConMutex.unlock();
|
emit CreateSocket(HostName, Port, UseTCP);
|
||||||
ipSocket = ret;
|
openDeviceWait.wait(&ipConMutex);
|
||||||
if(ipSocket == NULL)
|
ipConMutex.unlock();
|
||||||
{
|
ipSocket = ret;
|
||||||
msgBox.setText((const QString )errorMsg);
|
if(ipSocket == NULL)
|
||||||
msgBox.exec();
|
{
|
||||||
}
|
msgBox.setText((const QString )errorMsg);
|
||||||
return ipSocket;
|
msgBox.exec();
|
||||||
}
|
}
|
||||||
|
return ipSocket;
|
||||||
void IPconnectionConnection::closeDevice(const QString &deviceName)
|
}
|
||||||
{
|
|
||||||
if (ipSocket){
|
void IPconnectionConnection::closeDevice(const QString &deviceName)
|
||||||
ipConMutex.lock();
|
{
|
||||||
emit CloseSocket(ipSocket);
|
if (ipSocket){
|
||||||
closeDeviceWait.wait(&ipConMutex);
|
ipConMutex.lock();
|
||||||
ipConMutex.unlock();
|
emit CloseSocket(ipSocket);
|
||||||
ipSocket = NULL;
|
closeDeviceWait.wait(&ipConMutex);
|
||||||
}
|
ipConMutex.unlock();
|
||||||
}
|
ipSocket = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
QString IPconnectionConnection::connectionName()
|
|
||||||
{//updated from serial plugin
|
|
||||||
return QString("Network telemetry port");
|
QString IPconnectionConnection::connectionName()
|
||||||
}
|
{//updated from serial plugin
|
||||||
|
return QString("Network telemetry port");
|
||||||
QString IPconnectionConnection::shortName()
|
}
|
||||||
{//updated from serial plugin
|
|
||||||
if (m_config->UseTCP()) {
|
QString IPconnectionConnection::shortName()
|
||||||
return QString("TCP");
|
{//updated from serial plugin
|
||||||
} else {
|
if (m_config->UseTCP()) {
|
||||||
return QString("UDP");
|
return QString("TCP");
|
||||||
}
|
} else {
|
||||||
}
|
return QString("UDP");
|
||||||
|
}
|
||||||
|
}
|
||||||
IPconnectionPlugin::IPconnectionPlugin()
|
|
||||||
{//no change from serial plugin
|
|
||||||
}
|
IPconnectionPlugin::IPconnectionPlugin()
|
||||||
|
{//no change from serial plugin
|
||||||
IPconnectionPlugin::~IPconnectionPlugin()
|
}
|
||||||
{//manually remove the options page object
|
|
||||||
removeObject(m_connection->Optionspage());
|
IPconnectionPlugin::~IPconnectionPlugin()
|
||||||
}
|
{//manually remove the options page object
|
||||||
|
removeObject(m_connection->Optionspage());
|
||||||
void IPconnectionPlugin::extensionsInitialized()
|
}
|
||||||
{
|
|
||||||
addAutoReleasedObject(m_connection);
|
void IPconnectionPlugin::extensionsInitialized()
|
||||||
}
|
{
|
||||||
|
addAutoReleasedObject(m_connection);
|
||||||
bool IPconnectionPlugin::initialize(const QStringList &arguments, QString *errorString)
|
}
|
||||||
{
|
|
||||||
Q_UNUSED(arguments);
|
bool IPconnectionPlugin::initialize(const QStringList &arguments, QString *errorString)
|
||||||
Q_UNUSED(errorString);
|
{
|
||||||
m_connection = new IPconnectionConnection();
|
Q_UNUSED(arguments);
|
||||||
//must manage this registration of child object ourselves
|
Q_UNUSED(errorString);
|
||||||
//if we use an autorelease here it causes the GCS to crash
|
m_connection = new IPconnectionConnection();
|
||||||
//as it is deleting objects as the app closes...
|
//must manage this registration of child object ourselves
|
||||||
addObject(m_connection->Optionspage());
|
//if we use an autorelease here it causes the GCS to crash
|
||||||
|
//as it is deleting objects as the app closes...
|
||||||
return true;
|
addObject(m_connection->Optionspage());
|
||||||
}
|
|
||||||
|
return true;
|
||||||
Q_EXPORT_PLUGIN(IPconnectionPlugin)
|
}
|
||||||
|
|
||||||
|
Q_EXPORT_PLUGIN(IPconnectionPlugin)
|
||||||
|
@ -1,103 +1,103 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file IPconnectionplugin.h
|
* @file IPconnectionplugin.h
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
* @addtogroup GCSPlugins GCS Plugins
|
* @addtogroup GCSPlugins GCS Plugins
|
||||||
* @{
|
* @{
|
||||||
* @addtogroup IPConnPlugin IP Telemetry Plugin
|
* @addtogroup IPConnPlugin IP Telemetry Plugin
|
||||||
* @{
|
* @{
|
||||||
* @brief IP Connection Plugin impliment telemetry over TCP/IP and UDP/IP
|
* @brief IP Connection Plugin impliment telemetry over TCP/IP and UDP/IP
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* 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.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef IPconnectionPLUGIN_H
|
#ifndef IPconnectionPLUGIN_H
|
||||||
#define IPconnectionPLUGIN_H
|
#define IPconnectionPLUGIN_H
|
||||||
|
|
||||||
#include "ipconnection_global.h"
|
#include "ipconnection_global.h"
|
||||||
#include "ipconnectionoptionspage.h"
|
#include "ipconnectionoptionspage.h"
|
||||||
#include "ipconnectionconfiguration.h"
|
#include "ipconnectionconfiguration.h"
|
||||||
#include "coreplugin/iconnection.h"
|
#include "coreplugin/iconnection.h"
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
//#include <QtCore/QSettings>
|
//#include <QtCore/QSettings>
|
||||||
|
|
||||||
|
|
||||||
class QAbstractSocket;
|
class QAbstractSocket;
|
||||||
class QTcpSocket;
|
class QTcpSocket;
|
||||||
class QUdpSocket;
|
class QUdpSocket;
|
||||||
|
|
||||||
class IConnection;
|
class IConnection;
|
||||||
/**
|
/**
|
||||||
* Define a connection via the IConnection interface
|
* Define a connection via the IConnection interface
|
||||||
* Plugin will add a instance of this class to the pool,
|
* Plugin will add a instance of this class to the pool,
|
||||||
* so the connection manager can use it.
|
* so the connection manager can use it.
|
||||||
*/
|
*/
|
||||||
class IPconnection_EXPORT IPconnectionConnection
|
class IPconnection_EXPORT IPconnectionConnection
|
||||||
: public Core::IConnection
|
: public Core::IConnection
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
IPconnectionConnection();
|
IPconnectionConnection();
|
||||||
virtual ~IPconnectionConnection();
|
virtual ~IPconnectionConnection();
|
||||||
|
|
||||||
virtual QStringList availableDevices();
|
virtual QList <Core::IConnection::device> availableDevices();
|
||||||
virtual QIODevice *openDevice(const QString &deviceName);
|
virtual QIODevice *openDevice(const QString &deviceName);
|
||||||
virtual void closeDevice(const QString &deviceName);
|
virtual void closeDevice(const QString &deviceName);
|
||||||
|
|
||||||
virtual QString connectionName();
|
virtual QString connectionName();
|
||||||
virtual QString shortName();
|
virtual QString shortName();
|
||||||
|
|
||||||
IPconnectionConfiguration * Config() const { return m_config; }
|
IPconnectionConfiguration * Config() const { return m_config; }
|
||||||
IPconnectionOptionsPage * Optionspage() const { return m_optionspage; }
|
IPconnectionOptionsPage * Optionspage() const { return m_optionspage; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onEnumerationChanged();
|
void onEnumerationChanged();
|
||||||
|
|
||||||
signals: //For the benefit of IPConnection
|
signals: //For the benefit of IPConnection
|
||||||
void CreateSocket(QString HostName, int Port, bool UseTCP);
|
void CreateSocket(QString HostName, int Port, bool UseTCP);
|
||||||
void CloseSocket(QAbstractSocket *socket);
|
void CloseSocket(QAbstractSocket *socket);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QAbstractSocket *ipSocket;
|
QAbstractSocket *ipSocket;
|
||||||
IPconnectionConfiguration *m_config;
|
IPconnectionConfiguration *m_config;
|
||||||
IPconnectionOptionsPage *m_optionspage;
|
IPconnectionOptionsPage *m_optionspage;
|
||||||
//QSettings* settings;
|
//QSettings* settings;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class IPconnection_EXPORT IPconnectionPlugin
|
class IPconnection_EXPORT IPconnectionPlugin
|
||||||
: public ExtensionSystem::IPlugin
|
: public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IPconnectionPlugin();
|
IPconnectionPlugin();
|
||||||
~IPconnectionPlugin();
|
~IPconnectionPlugin();
|
||||||
|
|
||||||
virtual bool initialize(const QStringList &arguments, QString *error_message);
|
virtual bool initialize(const QStringList &arguments, QString *error_message);
|
||||||
virtual void extensionsInitialized();
|
virtual void extensionsInitialized();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IPconnectionConnection *m_connection;
|
IPconnectionConnection *m_connection;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // IPconnectionPLUGIN_H
|
#endif // IPconnectionPLUGIN_H
|
||||||
|
@ -58,10 +58,13 @@ void LoggingConnection::onEnumerationChanged()
|
|||||||
emit availableDevChanged(this);
|
emit availableDevChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList LoggingConnection::availableDevices()
|
QList <Core::IConnection::device> LoggingConnection::availableDevices()
|
||||||
{
|
{
|
||||||
QStringList list;
|
QList <device> list;
|
||||||
list << "Logfile replay...";
|
device d;
|
||||||
|
d.displayName="Logfile replay...";
|
||||||
|
d.name="Logfile replay...";
|
||||||
|
list <<d;
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public:
|
|||||||
LoggingConnection();
|
LoggingConnection();
|
||||||
virtual ~LoggingConnection();
|
virtual ~LoggingConnection();
|
||||||
|
|
||||||
virtual QStringList availableDevices();
|
virtual QList <Core::IConnection::device> availableDevices();
|
||||||
virtual QIODevice *openDevice(const QString &deviceName);
|
virtual QIODevice *openDevice(const QString &deviceName);
|
||||||
virtual void closeDevice(const QString &deviceName);
|
virtual void closeDevice(const QString &deviceName);
|
||||||
|
|
||||||
|
@ -79,14 +79,17 @@ void RawHIDConnection::onDeviceDisconnected()
|
|||||||
/**
|
/**
|
||||||
Returns the list of all currently available devices
|
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);
|
QList<USBPortInfo> portsList = m_usbMonitor->availableDevices(USBMonitor::idVendor_OpenPilot, -1, -1,USBMonitor::Running);
|
||||||
// We currently list devices by their serial number
|
// We currently list devices by their serial number
|
||||||
|
device dev;
|
||||||
foreach(USBPortInfo prt, portsList) {
|
foreach(USBPortInfo prt, portsList) {
|
||||||
devices.append(prt.serialNumber);
|
dev.name=prt.serialNumber;
|
||||||
|
dev.displayName=prt.product;
|
||||||
|
devices.append(dev);
|
||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public:
|
|||||||
RawHIDConnection();
|
RawHIDConnection();
|
||||||
virtual ~RawHIDConnection();
|
virtual ~RawHIDConnection();
|
||||||
|
|
||||||
virtual QStringList availableDevices();
|
virtual QList < Core::IConnection::device> availableDevices();
|
||||||
virtual QIODevice *openDevice(const QString &deviceName);
|
virtual QIODevice *openDevice(const QString &deviceName);
|
||||||
virtual void closeDevice(const QString &deviceName);
|
virtual void closeDevice(const QString &deviceName);
|
||||||
|
|
||||||
|
@ -1,222 +1,225 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file serialplugin.cpp
|
* @file serialplugin.cpp
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
* @addtogroup GCSPlugins GCS Plugins
|
* @addtogroup GCSPlugins GCS Plugins
|
||||||
* @{
|
* @{
|
||||||
* @addtogroup SerialPlugin Serial Connection Plugin
|
* @addtogroup SerialPlugin Serial Connection Plugin
|
||||||
* @{
|
* @{
|
||||||
* @brief Impliments serial connection to the flight hardware for Telemetry
|
* @brief Impliments serial connection to the flight hardware for Telemetry
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* 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.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "serialplugin.h"
|
#include "serialplugin.h"
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <QtCore/QtPlugin>
|
#include <QtCore/QtPlugin>
|
||||||
#include <QtGui/QMainWindow>
|
#include <QtGui/QMainWindow>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SerialEnumerationThread::SerialEnumerationThread(SerialConnection *serial)
|
SerialEnumerationThread::SerialEnumerationThread(SerialConnection *serial)
|
||||||
: m_serial(serial),
|
: m_serial(serial),
|
||||||
m_running(true)
|
m_running(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SerialEnumerationThread::~SerialEnumerationThread()
|
SerialEnumerationThread::~SerialEnumerationThread()
|
||||||
{
|
{
|
||||||
m_running = false;
|
m_running = false;
|
||||||
//wait for the thread to terminate
|
//wait for the thread to terminate
|
||||||
if(wait(2100) == false)
|
if(wait(2100) == false)
|
||||||
qDebug() << "Cannot terminate SerialEnumerationThread";
|
qDebug() << "Cannot terminate SerialEnumerationThread";
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialEnumerationThread::run()
|
void SerialEnumerationThread::run()
|
||||||
{
|
{
|
||||||
QStringList devices = m_serial->availableDevices();
|
QList <Core::IConnection::device> devices = m_serial->availableDevices();
|
||||||
|
|
||||||
while(m_running)
|
while(m_running)
|
||||||
{
|
{
|
||||||
if(!m_serial->deviceOpened())
|
if(!m_serial->deviceOpened())
|
||||||
{
|
{
|
||||||
QStringList newDev = m_serial->availableDevices();
|
QList <Core::IConnection::device> newDev = m_serial->availableDevices();
|
||||||
if(devices != newDev)
|
if(devices != newDev)
|
||||||
{
|
{
|
||||||
devices = newDev;
|
devices = newDev;
|
||||||
emit enumerationChanged();
|
emit enumerationChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msleep(2000); //update available devices every two seconds (doesn't need more)
|
msleep(2000); //update available devices every two seconds (doesn't need more)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SerialConnection::SerialConnection()
|
SerialConnection::SerialConnection()
|
||||||
: enablePolling(true), m_enumerateThread(this)
|
: enablePolling(true), m_enumerateThread(this)
|
||||||
{
|
{
|
||||||
serialHandle = NULL;
|
serialHandle = NULL;
|
||||||
|
|
||||||
// Experimental: enable polling on all OS'es since there
|
// Experimental: enable polling on all OS'es since there
|
||||||
// were reports that autodetect does not work on XP amongst
|
// were reports that autodetect does not work on XP amongst
|
||||||
// others.
|
// others.
|
||||||
|
|
||||||
//#ifdef Q_OS_WIN
|
//#ifdef Q_OS_WIN
|
||||||
// //I'm cheating a little bit here:
|
// //I'm cheating a little bit here:
|
||||||
// //Knowing if the device enumeration really changed is a bit complicated
|
// //Knowing if the device enumeration really changed is a bit complicated
|
||||||
// //so I just signal it whenever we have a device event...
|
// //so I just signal it whenever we have a device event...
|
||||||
// QMainWindow *mw = Core::ICore::instance()->mainWindow();
|
// QMainWindow *mw = Core::ICore::instance()->mainWindow();
|
||||||
// QObject::connect(mw, SIGNAL(deviceChange()),
|
// QObject::connect(mw, SIGNAL(deviceChange()),
|
||||||
// this, SLOT(onEnumerationChanged()));
|
// this, SLOT(onEnumerationChanged()));
|
||||||
//#else
|
//#else
|
||||||
// Other OSes do not send such signals:
|
// Other OSes do not send such signals:
|
||||||
QObject::connect(&m_enumerateThread, SIGNAL(enumerationChanged()),
|
QObject::connect(&m_enumerateThread, SIGNAL(enumerationChanged()),
|
||||||
this, SLOT(onEnumerationChanged()));
|
this, SLOT(onEnumerationChanged()));
|
||||||
m_enumerateThread.start();
|
m_enumerateThread.start();
|
||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
SerialConnection::~SerialConnection()
|
SerialConnection::~SerialConnection()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialConnection::onEnumerationChanged()
|
void SerialConnection::onEnumerationChanged()
|
||||||
{
|
{
|
||||||
if (enablePolling)
|
if (enablePolling)
|
||||||
emit availableDevChanged(this);
|
emit availableDevChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sortPorts(const QextPortInfo &s1,const QextPortInfo &s2)
|
bool sortPorts(const QextPortInfo &s1,const QextPortInfo &s2)
|
||||||
{
|
{
|
||||||
return s1.portName<s2.portName;
|
return s1.portName<s2.portName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SerialConnection::availableDevices()
|
QList <Core::IConnection::device> SerialConnection::availableDevices()
|
||||||
{
|
{
|
||||||
QStringList list;
|
QList <Core::IConnection::device> list;
|
||||||
|
|
||||||
if (enablePolling) {
|
if (enablePolling) {
|
||||||
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
||||||
|
|
||||||
//sort the list by port number (nice idea from PT_Dreamer :))
|
//sort the list by port number (nice idea from PT_Dreamer :))
|
||||||
qSort(ports.begin(), ports.end(),sortPorts);
|
qSort(ports.begin(), ports.end(),sortPorts);
|
||||||
foreach( QextPortInfo port, ports ) {
|
foreach( QextPortInfo port, ports ) {
|
||||||
list.append(port.friendName);
|
device d;
|
||||||
}
|
d.displayName=port.friendName;
|
||||||
}
|
d.name=port.friendName;
|
||||||
|
list.append(d);
|
||||||
return list;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QIODevice *SerialConnection::openDevice(const QString &deviceName)
|
return list;
|
||||||
{
|
}
|
||||||
if (serialHandle){
|
|
||||||
closeDevice(deviceName);
|
QIODevice *SerialConnection::openDevice(const QString &deviceName)
|
||||||
}
|
{
|
||||||
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
if (serialHandle){
|
||||||
foreach( QextPortInfo port, ports ) {
|
closeDevice(deviceName);
|
||||||
if(port.friendName == deviceName)
|
}
|
||||||
{
|
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
||||||
//we need to handle port settings here...
|
foreach( QextPortInfo port, ports ) {
|
||||||
PortSettings set;
|
if(port.friendName == deviceName)
|
||||||
set.BaudRate = BAUD57600;
|
{
|
||||||
set.DataBits = DATA_8;
|
//we need to handle port settings here...
|
||||||
set.Parity = PAR_NONE;
|
PortSettings set;
|
||||||
set.StopBits = STOP_1;
|
set.BaudRate = BAUD57600;
|
||||||
set.FlowControl = FLOW_OFF;
|
set.DataBits = DATA_8;
|
||||||
set.Timeout_Millisec = 500;
|
set.Parity = PAR_NONE;
|
||||||
#ifdef Q_OS_WIN
|
set.StopBits = STOP_1;
|
||||||
serialHandle = new QextSerialPort(port.portName, set);
|
set.FlowControl = FLOW_OFF;
|
||||||
#else
|
set.Timeout_Millisec = 500;
|
||||||
serialHandle = new QextSerialPort(port.physName, set);
|
#ifdef Q_OS_WIN
|
||||||
#endif
|
serialHandle = new QextSerialPort(port.portName, set);
|
||||||
m_deviceOpened = true;
|
#else
|
||||||
return serialHandle;
|
serialHandle = new QextSerialPort(port.physName, set);
|
||||||
}
|
#endif
|
||||||
}
|
m_deviceOpened = true;
|
||||||
return NULL;
|
return serialHandle;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void SerialConnection::closeDevice(const QString &deviceName)
|
return NULL;
|
||||||
{
|
}
|
||||||
Q_UNUSED(deviceName);
|
|
||||||
//we have to delete the serial connection we created
|
void SerialConnection::closeDevice(const QString &deviceName)
|
||||||
if (serialHandle){
|
{
|
||||||
serialHandle->close ();
|
Q_UNUSED(deviceName);
|
||||||
delete(serialHandle);
|
//we have to delete the serial connection we created
|
||||||
serialHandle = NULL;
|
if (serialHandle){
|
||||||
m_deviceOpened = false;
|
serialHandle->close ();
|
||||||
}
|
delete(serialHandle);
|
||||||
}
|
serialHandle = NULL;
|
||||||
|
m_deviceOpened = false;
|
||||||
|
}
|
||||||
QString SerialConnection::connectionName()
|
}
|
||||||
{
|
|
||||||
return QString("Serial port");
|
|
||||||
}
|
QString SerialConnection::connectionName()
|
||||||
|
{
|
||||||
QString SerialConnection::shortName()
|
return QString("Serial port");
|
||||||
{
|
}
|
||||||
return QString("Serial");
|
|
||||||
}
|
QString SerialConnection::shortName()
|
||||||
|
{
|
||||||
/**
|
return QString("Serial");
|
||||||
Tells the Serial plugin to stop polling for serial devices
|
}
|
||||||
*/
|
|
||||||
void SerialConnection::suspendPolling()
|
/**
|
||||||
{
|
Tells the Serial plugin to stop polling for serial devices
|
||||||
enablePolling = false;
|
*/
|
||||||
}
|
void SerialConnection::suspendPolling()
|
||||||
|
{
|
||||||
/**
|
enablePolling = false;
|
||||||
Tells the Serial plugin to resume polling for serial devices
|
}
|
||||||
*/
|
|
||||||
void SerialConnection::resumePolling()
|
/**
|
||||||
{
|
Tells the Serial plugin to resume polling for serial devices
|
||||||
enablePolling = true;
|
*/
|
||||||
}
|
void SerialConnection::resumePolling()
|
||||||
|
{
|
||||||
|
enablePolling = true;
|
||||||
SerialPlugin::SerialPlugin()
|
}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
SerialPlugin::SerialPlugin()
|
||||||
SerialPlugin::~SerialPlugin()
|
{
|
||||||
{
|
}
|
||||||
|
|
||||||
}
|
SerialPlugin::~SerialPlugin()
|
||||||
|
{
|
||||||
void SerialPlugin::extensionsInitialized()
|
|
||||||
{
|
}
|
||||||
addAutoReleasedObject(new SerialConnection);
|
|
||||||
}
|
void SerialPlugin::extensionsInitialized()
|
||||||
|
{
|
||||||
bool SerialPlugin::initialize(const QStringList &arguments, QString *errorString)
|
addAutoReleasedObject(new SerialConnection);
|
||||||
{
|
}
|
||||||
Q_UNUSED(arguments);
|
|
||||||
Q_UNUSED(errorString);
|
bool SerialPlugin::initialize(const QStringList &arguments, QString *errorString)
|
||||||
|
{
|
||||||
return true;
|
Q_UNUSED(arguments);
|
||||||
}
|
Q_UNUSED(errorString);
|
||||||
|
|
||||||
Q_EXPORT_PLUGIN(SerialPlugin)
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_EXPORT_PLUGIN(SerialPlugin)
|
||||||
|
@ -1,122 +1,122 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file serialplugin.h
|
* @file serialplugin.h
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
* @addtogroup GCSPlugins GCS Plugins
|
* @addtogroup GCSPlugins GCS Plugins
|
||||||
* @{
|
* @{
|
||||||
* @addtogroup SerialPlugin Serial Connection Plugin
|
* @addtogroup SerialPlugin Serial Connection Plugin
|
||||||
* @{
|
* @{
|
||||||
* @brief Impliments serial connection to the flight hardware for Telemetry
|
* @brief Impliments serial connection to the flight hardware for Telemetry
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* 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.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SERIALPLUGIN_H
|
#ifndef SERIALPLUGIN_H
|
||||||
#define SERIALPLUGIN_H
|
#define SERIALPLUGIN_H
|
||||||
|
|
||||||
//#include "serial_global.h"
|
//#include "serial_global.h"
|
||||||
#include <qextserialport.h>
|
#include <qextserialport.h>
|
||||||
#include <qextserialenumerator.h>
|
#include <qextserialenumerator.h>
|
||||||
#include "coreplugin/iconnection.h"
|
#include "coreplugin/iconnection.h"
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
class IConnection;
|
class IConnection;
|
||||||
class QextSerialEnumerator;
|
class QextSerialEnumerator;
|
||||||
class SerialConnection;
|
class SerialConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper thread to check on new serial port connection/disconnection
|
* Helper thread to check on new serial port connection/disconnection
|
||||||
* Some operating systems do not send device insertion events so
|
* Some operating systems do not send device insertion events so
|
||||||
* for those we have to poll
|
* for those we have to poll
|
||||||
*/
|
*/
|
||||||
//class SERIAL_EXPORT SerialEnumerationThread : public QThread
|
//class SERIAL_EXPORT SerialEnumerationThread : public QThread
|
||||||
class SerialEnumerationThread : public QThread
|
class SerialEnumerationThread : public QThread
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SerialEnumerationThread(SerialConnection *serial);
|
SerialEnumerationThread(SerialConnection *serial);
|
||||||
virtual ~SerialEnumerationThread();
|
virtual ~SerialEnumerationThread();
|
||||||
|
|
||||||
virtual void run();
|
virtual void run();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void enumerationChanged();
|
void enumerationChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SerialConnection *m_serial;
|
SerialConnection *m_serial;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a connection via the IConnection interface
|
* Define a connection via the IConnection interface
|
||||||
* Plugin will add a instance of this class to the pool,
|
* Plugin will add a instance of this class to the pool,
|
||||||
* so the connection manager can use it.
|
* so the connection manager can use it.
|
||||||
*/
|
*/
|
||||||
//class SERIAL_EXPORT SerialConnection
|
//class SERIAL_EXPORT SerialConnection
|
||||||
class SerialConnection
|
class SerialConnection
|
||||||
: public Core::IConnection
|
: public Core::IConnection
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SerialConnection();
|
SerialConnection();
|
||||||
virtual ~SerialConnection();
|
virtual ~SerialConnection();
|
||||||
|
|
||||||
virtual QStringList availableDevices();
|
virtual QList <Core::IConnection::device> availableDevices();
|
||||||
virtual QIODevice *openDevice(const QString &deviceName);
|
virtual QIODevice *openDevice(const QString &deviceName);
|
||||||
virtual void closeDevice(const QString &deviceName);
|
virtual void closeDevice(const QString &deviceName);
|
||||||
|
|
||||||
virtual QString connectionName();
|
virtual QString connectionName();
|
||||||
virtual QString shortName();
|
virtual QString shortName();
|
||||||
virtual void suspendPolling();
|
virtual void suspendPolling();
|
||||||
virtual void resumePolling();
|
virtual void resumePolling();
|
||||||
|
|
||||||
bool deviceOpened() {return m_deviceOpened;}
|
bool deviceOpened() {return m_deviceOpened;}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QextSerialPort* serialHandle;
|
QextSerialPort* serialHandle;
|
||||||
bool enablePolling;
|
bool enablePolling;
|
||||||
|
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onEnumerationChanged();
|
void onEnumerationChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SerialEnumerationThread m_enumerateThread;
|
SerialEnumerationThread m_enumerateThread;
|
||||||
bool m_deviceOpened;
|
bool m_deviceOpened;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//class SERIAL_EXPORT SerialPlugin
|
//class SERIAL_EXPORT SerialPlugin
|
||||||
class SerialPlugin
|
class SerialPlugin
|
||||||
: public ExtensionSystem::IPlugin
|
: public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SerialPlugin();
|
SerialPlugin();
|
||||||
~SerialPlugin();
|
~SerialPlugin();
|
||||||
|
|
||||||
virtual bool initialize(const QStringList &arguments, QString *error_message);
|
virtual bool initialize(const QStringList &arguments, QString *error_message);
|
||||||
virtual void extensionsInitialized();
|
virtual void extensionsInitialized();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // SERIALPLUGIN_H
|
#endif // SERIALPLUGIN_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user