1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Initial code for TCP connection to Flight hardware.

This is heavily based on the serial connection code.
Currently this uses a fixed IP and PORT to connect.
This has only been tested on Windows XP.
This has not been tested with real hardware.

Update to allow config of IP and PORT to come soon.


git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@866 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
andrew 2010-06-23 04:11:01 +00:00 committed by andrew
parent b76ed714c8
commit 76e522f15a
13 changed files with 758 additions and 0 deletions

View File

@ -0,0 +1,10 @@
<plugin name="TCPtelemetry" 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 TCP/IP interface</description>
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
</dependencyList>
</plugin>

View File

@ -0,0 +1,3 @@
include(TCPtelemetry_dependencies.pri)
LIBS *= -l$$qtLibraryTarget(TCPtelemetry)

View File

@ -0,0 +1 @@
include(../../plugins/coreplugin/coreplugin.pri)

View File

@ -0,0 +1,39 @@
/**
******************************************************************************
*
* @file TCPtelemetry_global.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup TCPtelemetry_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 TCPtelemetry_GLOBAL_H
#define TCPtelemetry_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(TCPtelemetry_LIBRARY)
# define TCPtelemetry_EXPORT Q_DECL_EXPORT
#else
# define TCPtelemetry_EXPORT Q_DECL_IMPORT
#endif
#endif // TCPtelemetry_GLOBAL_H

View File

@ -0,0 +1,65 @@
/**
******************************************************************************
*
* @file TCPtelemetryconfiguration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup map
* @{
*
*****************************************************************************/
/*
* 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 "TCPtelemetryconfiguration.h"
#include <QtCore/QDataStream>
TCPtelemetryConfiguration::TCPtelemetryConfiguration(QString classId, const QByteArray &state, QObject *parent) :
IUAVGadgetConfiguration(classId, parent),
m_HostName("127.0.0.1"),
m_Port(1000)
{
if (state.count() > 0) {
QDataStream stream(state);
int Port;
QString HostName;
stream >> Port;
stream >> HostName;
m_Port = Port;
if (HostName != "")
m_HostName = HostName;
}
}
IUAVGadgetConfiguration *TCPtelemetryConfiguration::clone()
{
TCPtelemetryConfiguration *m = new TCPtelemetryConfiguration(this->classId());
m->m_Port = m_Port;
m->m_HostName = m_HostName;
return m;
}
QByteArray TCPtelemetryConfiguration::saveState() const
{
QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly);
stream << m_Port;
stream << m_HostName;
return bytes;
}

View File

@ -0,0 +1,61 @@
/**
******************************************************************************
*
* @file TCPtelemetryconfiguration.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup map
* @{
*
*****************************************************************************/
/*
* 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 TCPtelemetryCONFIGURATION_H
#define TCPtelemetryCONFIGURATION_H
#include <coreplugin/iuavgadgetconfiguration.h>
#include <QtCore/QString>
using namespace Core;
class TCPtelemetryConfiguration : public IUAVGadgetConfiguration
{
Q_OBJECT
Q_PROPERTY(QString HostName READ HostName WRITE setHostName)
Q_PROPERTY(int Port READ Port WRITE setPort)
public:
explicit TCPtelemetryConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
QByteArray saveState() const;
IUAVGadgetConfiguration *clone();
QString HostName() const { return m_HostName; }
int Port() const { return m_Port; }
public slots:
void setHostName(QString HostName) { m_HostName = HostName; }
void setPort(int Port) { m_Port = Port; }
private:
QString m_HostName;
int m_Port;
};
#endif // TCPtelemetryCONFIGURATION_H

View File

@ -0,0 +1,16 @@
TEMPLATE = lib
TARGET = TCPtelemetry
include(../../openpilotgcsplugin.pri)
include(TCPtelemetry_dependencies.pri)
HEADERS += TCPtelemetryplugin.h \
TCPtelemetry_global.h \
TCPtelemetryconfiguration.h \
TCPtelemetryoptionspage.h
SOURCES += TCPtelemetryplugin.cpp \
TCPtelemetryconfiguration.cpp \
TCPtelemetryoptionspage.cpp
FORMS += TCPtelemetryoptionspage.ui
RESOURCES +=
DEFINES += TCPtelemetry_LIBRARY
OTHER_FILES += TCPtelemetry.pluginspec
QT += network

View File

@ -0,0 +1,68 @@
/**
******************************************************************************
*
* @file TCPtelemetryoptionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup map
* @{
*
*****************************************************************************/
/*
* 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 "TCPtelemetryoptionspage.h"
#include "TCPtelemetryconfiguration.h"
#include <QtGui/QLabel>
#include <QtGui/QComboBox>
#include <QtGui/QSpinBox>
#include <QtGui/QDoubleSpinBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include "ui_TCPtelemetryoptionspage.h"
TCPtelemetryOptionsPage::TCPtelemetryOptionsPage(TCPtelemetryConfiguration *config, QObject *parent) :
IOptionsPage(parent),
m_config(config)
{
}
QWidget *TCPtelemetryOptionsPage::createPage(QWidget *parent)
{
m_page = new Ui::TCPtelemetryOptionsPage();
QWidget *w = new QWidget(parent);
m_page->setupUi(w);
m_page->Port->setValue(m_config->Port());
m_page->HostName->setText(m_config->HostName());
return w;
}
void TCPtelemetryOptionsPage::apply()
{
m_config->setPort(m_page->Port->value());
m_config->setHostName(m_page->HostName->text());
}
void TCPtelemetryOptionsPage::finish()
{
delete m_page;
}

View File

@ -0,0 +1,63 @@
/**
******************************************************************************
*
* @file TCPtelemetryoptionspage.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup map
* @{
*
*****************************************************************************/
/*
* 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 TCPtelemetryOPTIONSPAGE_H
#define TCPtelemetryOPTIONSPAGE_H
#include "coreplugin/dialogs/ioptionspage.h"
class TCPtelemetryConfiguration;
namespace Core {
class IUAVGadgetConfiguration;
}
namespace Ui {
class TCPtelemetryOptionsPage;
}
using namespace Core;
class TCPtelemetryOptionsPage : public IOptionsPage
{
Q_OBJECT
public:
explicit TCPtelemetryOptionsPage(TCPtelemetryConfiguration *config, QObject *parent = 0);
QWidget *createPage(QWidget *parent);
void apply();
void finish();
signals:
public slots:
private:
TCPtelemetryConfiguration *m_config;
Ui::TCPtelemetryOptionsPage *m_page;
};
#endif // TCPtelemetryOPTIONSPAGE_H

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TCPtelemetryOptionsPage</class>
<widget class="QWidget" name="TCPtelemetryOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>355</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Host Name/Number</string>
</property>
</widget>
</item>
<item row="2" column="1" rowspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="3" rowspan="5">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="HostName"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="Port"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,178 @@
/**
******************************************************************************
*
* @file TCPtelemetryplugin.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 TCPtelemetry_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
*/
//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 "TCPtelemetryplugin.h"
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
#include <QtCore/QtPlugin>
#include <QtGui/QMainWindow>
#include <QtNetwork/QTcpSocket>
#include <QDebug>
TCPtelemetryConnection::TCPtelemetryConnection()
{//no change from serial plugin
//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()));
}
TCPtelemetryConnection::~TCPtelemetryConnection()
{//no change from serial plugin
}
void TCPtelemetryConnection::onEnumerationChanged()
{//no change from serial plugin
emit availableDevChanged(this);
}
/*bool sortPorts(const QextPortInfo &s1,const QextPortInfo &s2)
{
return s1.portName<s2.portName;
}*/
QStringList TCPtelemetryConnection::availableDevices()
{
QStringList list;
/*QList<QextPortInfo> ports = QextTCPtelemetryEnumerator::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);
}*/
//for the first attempt just hard code the IP and PORT
list.append((const QString )"Test OpenPilot");
return list;
}
QIODevice *TCPtelemetryConnection::openDevice(const QString &deviceName)
{
/*QList<QextPortInfo> ports = QextTCPtelemetryEnumerator::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
return new QextTCPtelemetryPort(port.portName, set);
#else
return new QextTCPtelemetryPort(port.physName, set);
#endif
}
}*/
const int Timeout = 5 * 1000;
tcpSocket = new QTcpSocket(this);
tcpSocket->connectToHost((const QString )"192.168.10.77", 9100);
if (tcpSocket->waitForConnected(Timeout)) {
return tcpSocket;
}
return NULL;
}
void TCPtelemetryConnection::closeDevice(const QString &deviceName)
{//no change from serial plugin
//nothing to do here
}
QString TCPtelemetryConnection::connectionName()
{//updated from serial plugin
return QString("TCPtelemetry port");
}
QString TCPtelemetryConnection::shortName()
{//updated from serial plugin
return QString("TCP");
}
TCPtelemetryPlugin::TCPtelemetryPlugin()
{//no change from serial plugin
}
TCPtelemetryPlugin::~TCPtelemetryPlugin()
{//no change from serial plugin
}
void TCPtelemetryPlugin::extensionsInitialized()
{//updated from serial plugin
addAutoReleasedObject(m_connection);
}
bool TCPtelemetryPlugin::initialize(const QStringList &arguments, QString *errorString)
{//no change from serial plugin
Q_UNUSED(arguments);
Q_UNUSED(errorString);
//m_optionspage = new TCPtelemetryOptionsPage(NULL,this);
//addAutoReleasedObject(m_optionspage);
m_connection = new TCPtelemetryConnection();
//m_factory = new TCPtelemetryFactory(this);
//addAutoReleasedObject(m_factory);
return true;
}
Q_EXPORT_PLUGIN(TCPtelemetryPlugin)

View File

@ -0,0 +1,89 @@
/**
******************************************************************************
*
* @file TCPtelemetryplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup TCPtelemetry_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 TCPtelemetryPLUGIN_H
#define TCPtelemetryPLUGIN_H
#include "TCPtelemetry_global.h"
#include "TCPtelemetryoptionspage.h"
#include "TCPtelemetryconfiguration.h"
#include "TCPtelemetryfactory.h"
#include "coreplugin/iconnection.h"
#include <extensionsystem/iplugin.h>
class QTcpSocket;
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 TCPtelemetry_EXPORT TCPtelemetryConnection
: public Core::IConnection
{
Q_OBJECT
public:
TCPtelemetryConnection();
virtual ~TCPtelemetryConnection();
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();
private:
QTcpSocket *tcpSocket;
};
class TCPtelemetry_EXPORT TCPtelemetryPlugin
: public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
TCPtelemetryPlugin();
~TCPtelemetryPlugin();
virtual bool initialize(const QStringList &arguments, QString *error_message);
virtual void extensionsInitialized();
private:
//TCPtelemetryConfiguration *m_config;
//TCPtelemetryOptionsPage *m_optionspage;
TCPtelemetryFactory *m_factory;
TCPtelemetryConnection *m_connection;
};
#endif // TCPtelemetryPLUGIN_H

View File

@ -0,0 +1,95 @@
/********************************************************************************
** Form generated from reading UI file 'TCPtelemetryoptionspage.ui'
**
** Created: Tue 22. Jun 21:46:31 2010
** by: Qt User Interface Compiler version 4.6.3
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_TCPTELEMETRYOPTIONSPAGE_H
#define UI_TCPTELEMETRYOPTIONSPAGE_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QGridLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QSpacerItem>
#include <QtGui/QSpinBox>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_TCPtelemetryOptionsPage
{
public:
QGridLayout *gridLayout;
QLabel *label_2;
QSpacerItem *verticalSpacer;
QSpacerItem *horizontalSpacer;
QLineEdit *HostName;
QSpinBox *Port;
QLabel *label_3;
void setupUi(QWidget *TCPtelemetryOptionsPage)
{
if (TCPtelemetryOptionsPage->objectName().isEmpty())
TCPtelemetryOptionsPage->setObjectName(QString::fromUtf8("TCPtelemetryOptionsPage"));
TCPtelemetryOptionsPage->resize(355, 300);
gridLayout = new QGridLayout(TCPtelemetryOptionsPage);
gridLayout->setContentsMargins(0, 0, 0, 0);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
label_2 = new QLabel(TCPtelemetryOptionsPage);
label_2->setObjectName(QString::fromUtf8("label_2"));
gridLayout->addWidget(label_2, 0, 0, 1, 1);
verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
gridLayout->addItem(verticalSpacer, 2, 1, 3, 1);
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(horizontalSpacer, 0, 3, 5, 1);
HostName = new QLineEdit(TCPtelemetryOptionsPage);
HostName->setObjectName(QString::fromUtf8("HostName"));
gridLayout->addWidget(HostName, 0, 1, 1, 1);
Port = new QSpinBox(TCPtelemetryOptionsPage);
Port->setObjectName(QString::fromUtf8("Port"));
gridLayout->addWidget(Port, 1, 1, 1, 1);
label_3 = new QLabel(TCPtelemetryOptionsPage);
label_3->setObjectName(QString::fromUtf8("label_3"));
gridLayout->addWidget(label_3, 1, 0, 1, 1);
retranslateUi(TCPtelemetryOptionsPage);
QMetaObject::connectSlotsByName(TCPtelemetryOptionsPage);
} // setupUi
void retranslateUi(QWidget *TCPtelemetryOptionsPage)
{
TCPtelemetryOptionsPage->setWindowTitle(QApplication::translate("TCPtelemetryOptionsPage", "Form", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("TCPtelemetryOptionsPage", "Host Name/Number", 0, QApplication::UnicodeUTF8));
label_3->setText(QApplication::translate("TCPtelemetryOptionsPage", "Port", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class TCPtelemetryOptionsPage: public Ui_TCPtelemetryOptionsPage {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_TCPTELEMETRYOPTIONSPAGE_H