mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-26 15:54:15 +01:00
GCS/connectionManager: some light cleanup and refactoring
GCS/serialconnection: added a new connection plugin for serial port git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@483 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
a862f9638e
commit
a4147d5fb2
@ -51,7 +51,7 @@ namespace Core {
|
|||||||
ConnectionManager::ConnectionManager(Internal::MainWindow *mainWindow, Internal::FancyTabWidget *modeStack)
|
ConnectionManager::ConnectionManager(Internal::MainWindow *mainWindow, Internal::FancyTabWidget *modeStack)
|
||||||
: m_availableDevList(0),
|
: m_availableDevList(0),
|
||||||
m_connectBtn(0),
|
m_connectBtn(0),
|
||||||
m_deviceConnected(false)
|
m_ioDev(NULL)
|
||||||
{
|
{
|
||||||
QVBoxLayout *top = new QVBoxLayout;
|
QVBoxLayout *top = new QVBoxLayout;
|
||||||
top->setSpacing(0);
|
top->setSpacing(0);
|
||||||
@ -128,37 +128,24 @@ void ConnectionManager::aboutToRemoveObject(QObject *obj)
|
|||||||
*/
|
*/
|
||||||
void ConnectionManager::onConnectPressed()
|
void ConnectionManager::onConnectPressed()
|
||||||
{
|
{
|
||||||
if(!m_deviceConnected)
|
//check if we are trying to connect a new device
|
||||||
|
//or if we are disconnecting it
|
||||||
|
if(!m_ioDev)
|
||||||
{
|
{
|
||||||
m_connectBtn->setText("Disconnect");
|
m_connectBtn->setText("Disconnect");
|
||||||
m_availableDevList->setEnabled(false);
|
m_availableDevList->setEnabled(false);
|
||||||
|
|
||||||
m_deviceConnected = true;
|
|
||||||
m_connectionDevice = findDevice(m_availableDevList->currentText());
|
m_connectionDevice = findDevice(m_availableDevList->currentText());
|
||||||
|
|
||||||
if(m_connectionDevice.connection)
|
if(m_connectionDevice.connection)
|
||||||
{
|
{
|
||||||
QIODevice *ioDev = m_connectionDevice.connection->openDevice(m_connectionDevice.devName);
|
m_ioDev = m_connectionDevice.connection->openDevice(m_connectionDevice.devName);
|
||||||
/*QextSerialPort *ioDev = new QextSerialPort("COM5");
|
|
||||||
ioDev->setBaudRate(BAUD57600);
|
if(m_ioDev)
|
||||||
ioDev->setFlowControl(FLOW_OFF);*/
|
|
||||||
ioDev->open(QIODevice::ReadWrite);
|
|
||||||
/*if(ioDev->isOpen())
|
|
||||||
ioDev->putChar('M');*/
|
|
||||||
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
|
||||||
qDebug() << "List of ports:";
|
|
||||||
for (int i = 0; i < ports.size(); i++) {
|
|
||||||
qDebug() << "port name:" << ports.at(i).portName;
|
|
||||||
qDebug() << "friendly name:" << ports.at(i).friendName;
|
|
||||||
qDebug() << "physical name:" << ports.at(i).physName;
|
|
||||||
qDebug() << "enumerator name:" << ports.at(i).enumName;
|
|
||||||
qDebug() << "vendor ID:" << QString::number(ports.at(i).vendorID, 16);
|
|
||||||
qDebug() << "product ID:" << QString::number(ports.at(i).productID, 16);
|
|
||||||
qDebug() << "===================================";
|
|
||||||
}
|
|
||||||
if(ioDev)
|
|
||||||
{
|
{
|
||||||
emit deviceConnected(ioDev);
|
m_ioDev->open(QIODevice::ReadWrite);
|
||||||
|
//signal interested plugins that the user wants to connect to the device
|
||||||
|
emit deviceConnected(m_ioDev);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -172,13 +159,20 @@ void ConnectionManager::onConnectPressed()
|
|||||||
m_connectBtn->setText("Connect");
|
m_connectBtn->setText("Connect");
|
||||||
m_availableDevList->setEnabled(true);
|
m_availableDevList->setEnabled(true);
|
||||||
|
|
||||||
m_deviceConnected = false;
|
//signal interested plugins that user is disconnecting his device
|
||||||
|
emit deviceDisconnected();
|
||||||
|
|
||||||
|
//close the device
|
||||||
|
if(m_ioDev)
|
||||||
|
{
|
||||||
|
m_ioDev->close();
|
||||||
|
m_ioDev = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if(m_connectionDevice.connection)
|
if(m_connectionDevice.connection)
|
||||||
m_connectionDevice.connection->closeDevice(m_connectionDevice.devName);
|
m_connectionDevice.connection->closeDevice(m_connectionDevice.devName);
|
||||||
|
|
||||||
m_connectionDevice.connection = NULL;
|
m_connectionDevice.connection = NULL;
|
||||||
emit deviceDisconnected();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,8 +90,12 @@ protected:
|
|||||||
QComboBox *m_availableDevList;
|
QComboBox *m_availableDevList;
|
||||||
QPushButton *m_connectBtn;
|
QPushButton *m_connectBtn;
|
||||||
QLinkedList<devListItem> m_devList;
|
QLinkedList<devListItem> m_devList;
|
||||||
|
|
||||||
|
//currently connected connection plugin
|
||||||
devListItem m_connectionDevice;
|
devListItem m_connectionDevice;
|
||||||
bool m_deviceConnected;
|
|
||||||
|
//currently connected QIODevice
|
||||||
|
QIODevice *m_ioDev;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace Core
|
} //namespace Core
|
||||||
|
@ -18,11 +18,16 @@ plugin_welcome.subdir = welcome
|
|||||||
plugin_welcome.depends = plugin_coreplugin
|
plugin_welcome.depends = plugin_coreplugin
|
||||||
SUBDIRS += plugin_welcome
|
SUBDIRS += plugin_welcome
|
||||||
|
|
||||||
# RawHID plug-in
|
# RawHID connection plugin
|
||||||
SUBDIRS += plugin_rawhid
|
SUBDIRS += plugin_rawhid
|
||||||
plugin_rawhid.subdir = rawhid
|
plugin_rawhid.subdir = rawhid
|
||||||
plugin_rawhid.depends = plugin_coreplugin
|
plugin_rawhid.depends = plugin_coreplugin
|
||||||
|
|
||||||
|
# Serial port connection plugin
|
||||||
|
SUBDIRS += plugin_serial
|
||||||
|
plugin_serial.subdir = serialconnection
|
||||||
|
plugin_serial.depends = plugin_coreplugin
|
||||||
|
|
||||||
# UAVObjects plug-in
|
# UAVObjects plug-in
|
||||||
SUBDIRS += plugin_uavobjects
|
SUBDIRS += plugin_uavobjects
|
||||||
plugin_uavobjects.subdir = uavobjects
|
plugin_uavobjects.subdir = uavobjects
|
||||||
|
@ -126,7 +126,7 @@ int pjrc_rawhid::open(int max, int vid, int pid, int usage_page, int usage)
|
|||||||
if (h == INVALID_HANDLE_VALUE) continue;
|
if (h == INVALID_HANDLE_VALUE) continue;
|
||||||
attrib.Size = sizeof(HIDD_ATTRIBUTES);
|
attrib.Size = sizeof(HIDD_ATTRIBUTES);
|
||||||
ret = HidD_GetAttributes(h, &attrib);
|
ret = HidD_GetAttributes(h, &attrib);
|
||||||
printf("vid: %4x\n", attrib.VendorID);
|
//printf("vid: %4x\n", attrib.VendorID);
|
||||||
if (!ret || (vid > 0 && attrib.VendorID != vid) ||
|
if (!ret || (vid > 0 && attrib.VendorID != vid) ||
|
||||||
(pid > 0 && attrib.ProductID != pid) ||
|
(pid > 0 && attrib.ProductID != pid) ||
|
||||||
!HidD_GetPreparsedData(h, &hid_data)) {
|
!HidD_GetPreparsedData(h, &hid_data)) {
|
||||||
|
10
ground/src/plugins/serialconnection/Serial.pluginspec
Normal file
10
ground/src/plugins/serialconnection/Serial.pluginspec
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<plugin name="Serial" version="1.0.0" compatVersion="1.0.0">
|
||||||
|
<vendor>The OpenPilot Project</vendor>
|
||||||
|
<copyright>(C) 2010 OpenPilot Project</copyright>
|
||||||
|
<license>GNU Public License (GPL) Version 3</license>
|
||||||
|
<description>Connection to OpenPilot board using serial link interface</description>
|
||||||
|
<url>http://www.openpilot.org</url>
|
||||||
|
<dependencyList>
|
||||||
|
<dependency name="Core" version="1.0.0"/>
|
||||||
|
</dependencyList>
|
||||||
|
</plugin>
|
3
ground/src/plugins/serialconnection/serial.pri
Normal file
3
ground/src/plugins/serialconnection/serial.pri
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
include(serial_dependencies.pri)
|
||||||
|
|
||||||
|
LIBS *= -l$$qtLibraryTarget(Serial)
|
@ -0,0 +1 @@
|
|||||||
|
include(../../plugins/coreplugin/coreplugin.pri)
|
39
ground/src/plugins/serialconnection/serial_global.h
Normal file
39
ground/src/plugins/serialconnection/serial_global.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file serial_global.h
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup serial_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 SERIAL_GLOBAL_H
|
||||||
|
#define SERIAL_GLOBAL_H
|
||||||
|
|
||||||
|
#include <QtCore/qglobal.h>
|
||||||
|
|
||||||
|
#if defined(SERIAL_LIBRARY)
|
||||||
|
# define SERIAL_EXPORT Q_DECL_EXPORT
|
||||||
|
#else
|
||||||
|
# define SERIAL_EXPORT Q_DECL_IMPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // SERIAL_GLOBAL_H
|
12
ground/src/plugins/serialconnection/serialconnection.pro
Normal file
12
ground/src/plugins/serialconnection/serialconnection.pro
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
TEMPLATE = lib
|
||||||
|
TARGET = Serial
|
||||||
|
include(../../openpilotgcsplugin.pri)
|
||||||
|
include(serial_dependencies.pri)
|
||||||
|
INCLUDEPATH += ../../libs\qextserialport\src
|
||||||
|
HEADERS += serialplugin.h \
|
||||||
|
serial_global.h
|
||||||
|
SOURCES += serialplugin.cpp
|
||||||
|
FORMS +=
|
||||||
|
RESOURCES +=
|
||||||
|
DEFINES += SERIAL_LIBRARY
|
||||||
|
OTHER_FILES += Serial.pluginspec
|
122
ground/src/plugins/serialconnection/serialplugin.cpp
Normal file
122
ground/src/plugins/serialconnection/serialplugin.cpp
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file serialplugin.cpp
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief Register connection object for the core connection manager
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup serial_plugin
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "serialplugin.h"
|
||||||
|
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <QtCore/QtPlugin>
|
||||||
|
#include <QtGui/QMainWindow>
|
||||||
|
#include <qextserialport.h>
|
||||||
|
#include <qextserialenumerator.h>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
SerialConnection::SerialConnection()
|
||||||
|
{
|
||||||
|
//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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
SerialConnection::~SerialConnection()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SerialConnection::onEnumerationChanged()
|
||||||
|
{
|
||||||
|
emit availableDevChanged(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList SerialConnection::availableDevices()
|
||||||
|
{
|
||||||
|
QStringList list;
|
||||||
|
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
||||||
|
foreach( QextPortInfo port, ports ) {
|
||||||
|
list.append(port.friendName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
QIODevice *SerialConnection::openDevice(const QString &deviceName)
|
||||||
|
{
|
||||||
|
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
||||||
|
foreach( QextPortInfo port, ports ) {
|
||||||
|
if(port.friendName == deviceName)
|
||||||
|
{
|
||||||
|
//we need to handle port settings here...
|
||||||
|
return new QextSerialPort(port.portName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SerialConnection::closeDevice(const QString &deviceName)
|
||||||
|
{
|
||||||
|
//nothing to do here
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString SerialConnection::connectionName()
|
||||||
|
{
|
||||||
|
return QString("Serial port");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SerialConnection::shortName()
|
||||||
|
{
|
||||||
|
return QString("Serial");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
78
ground/src/plugins/serialconnection/serialplugin.h
Normal file
78
ground/src/plugins/serialconnection/serialplugin.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file serialplugin.h
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup serial_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 SERIALPLUGIN_H
|
||||||
|
#define SERIALPLUGIN_H
|
||||||
|
|
||||||
|
#include "serial_global.h"
|
||||||
|
|
||||||
|
#include "coreplugin/iconnection.h"
|
||||||
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
|
class IConnection;
|
||||||
|
class QextSerialEnumerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
: 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();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void onEnumerationChanged();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class SERIAL_EXPORT SerialPlugin
|
||||||
|
: public ExtensionSystem::IPlugin
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
SerialPlugin();
|
||||||
|
~SerialPlugin();
|
||||||
|
|
||||||
|
virtual bool initialize(const QStringList &arguments, QString *error_message);
|
||||||
|
virtual void extensionsInitialized();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SERIALPLUGIN_H
|
@ -46,9 +46,7 @@ void UAVTalkPlugin::extensionsInitialized()
|
|||||||
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
||||||
objMngr = pm->getObject<UAVObjectManager>();
|
objMngr = pm->getObject<UAVObjectManager>();
|
||||||
|
|
||||||
// TODO: Initialize serial port and USB libraries, get QIODevice from each
|
// Connect to connection manager so we get notified when the user connect to his device
|
||||||
// ---Julien: Actually I changed a little bit from the initial plan,
|
|
||||||
// now you have to connect to signal emited by the connection manager
|
|
||||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||||
QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)),
|
QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)),
|
||||||
this, SLOT(onDeviceConnect(QIODevice *)));
|
this, SLOT(onDeviceConnect(QIODevice *)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user