mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
iOP-87: Enabled TCP module to also support UDP connections.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@904 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
1641e0c4fc
commit
f42260570f
@ -32,7 +32,8 @@
|
||||
TCPtelemetryConfiguration::TCPtelemetryConfiguration(QString classId, const QByteArray &state, QObject *parent) :
|
||||
IUAVGadgetConfiguration(classId, parent),
|
||||
m_HostName("127.0.0.1"),
|
||||
m_Port(1000)
|
||||
m_Port(1000),
|
||||
m_UseTCP(1)
|
||||
{
|
||||
settings = Core::ICore::instance()->settings();
|
||||
}
|
||||
@ -44,6 +45,7 @@ IUAVGadgetConfiguration *TCPtelemetryConfiguration::clone()
|
||||
TCPtelemetryConfiguration *m = new TCPtelemetryConfiguration(this->classId());
|
||||
m->m_Port = m_Port;
|
||||
m->m_HostName = m_HostName;
|
||||
m->m_UseTCP = m_UseTCP;
|
||||
return m;
|
||||
}
|
||||
|
||||
@ -53,6 +55,7 @@ QByteArray TCPtelemetryConfiguration::saveState() const
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
stream << m_Port;
|
||||
stream << m_HostName;
|
||||
stream << m_UseTCP;
|
||||
return bytes;
|
||||
|
||||
}
|
||||
@ -66,6 +69,7 @@ void TCPtelemetryConfiguration::savesettings() const
|
||||
settings->setArrayIndex(0);
|
||||
settings->setValue(QLatin1String("HostName"), m_HostName);
|
||||
settings->setValue(QLatin1String("Port"), m_Port);
|
||||
settings->setValue(QLatin1String("UseTCP"), m_UseTCP);
|
||||
settings->endArray();
|
||||
settings->endGroup();
|
||||
}
|
||||
@ -79,6 +83,7 @@ void TCPtelemetryConfiguration::restoresettings()
|
||||
settings->setArrayIndex(0);
|
||||
m_HostName = (settings->value(QLatin1String("HostName"), tr("")).toString());
|
||||
m_Port = (settings->value(QLatin1String("Port"), tr("")).toInt());
|
||||
m_UseTCP = (settings->value(QLatin1String("UseTCP"), tr("")).toInt());
|
||||
settings->endArray();
|
||||
settings->endGroup();
|
||||
|
||||
|
@ -39,6 +39,7 @@ class TCPtelemetryConfiguration : public IUAVGadgetConfiguration
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString HostName READ HostName WRITE setHostName)
|
||||
Q_PROPERTY(int Port READ Port WRITE setPort)
|
||||
Q_PROPERTY(int UseTCP READ UseTCP WRITE setUseTCP)
|
||||
|
||||
public:
|
||||
explicit TCPtelemetryConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
|
||||
@ -52,15 +53,18 @@ public:
|
||||
|
||||
QString HostName() const { return m_HostName; }
|
||||
int Port() const { return m_Port; }
|
||||
int UseTCP() const { return m_UseTCP; }
|
||||
|
||||
|
||||
public slots:
|
||||
void setHostName(QString HostName) { m_HostName = HostName; }
|
||||
void setPort(int Port) { m_Port = Port; }
|
||||
void setUseTCP(int UseTCP) { m_UseTCP = UseTCP; }
|
||||
|
||||
private:
|
||||
QString m_HostName;
|
||||
int m_Port;
|
||||
int m_UseTCP;
|
||||
QSettings* settings;
|
||||
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <QtGui/QComboBox>
|
||||
#include <QtGui/QSpinBox>
|
||||
#include <QtGui/QDoubleSpinBox>
|
||||
#include <QtGui/QRadioButton>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
|
||||
@ -55,6 +56,8 @@ QWidget *TCPtelemetryOptionsPage::createPage(QWidget *parent)
|
||||
|
||||
m_page->Port->setValue(m_config->Port());
|
||||
m_page->HostName->setText(m_config->HostName());
|
||||
m_page->UseTCP->setChecked(m_config->UseTCP()?true:false);
|
||||
m_page->UseUDP->setChecked(m_config->UseTCP()?false:true);
|
||||
|
||||
return w;
|
||||
}
|
||||
@ -63,6 +66,7 @@ void TCPtelemetryOptionsPage::apply()
|
||||
{
|
||||
m_config->setPort(m_page->Port->value());
|
||||
m_config->setHostName(m_page->HostName->text());
|
||||
m_config->setUseTCP(m_page->UseTCP->isChecked()?1:0);
|
||||
m_config->savesettings();
|
||||
|
||||
emit availableDevChanged();
|
||||
|
@ -52,8 +52,8 @@ public:
|
||||
|
||||
QString id() const { return QLatin1String("settings"); }
|
||||
QString trName() const { return tr("settings"); }
|
||||
QString category() const { return "TCP Connection"; };
|
||||
QString trCategory() const { return "TCP Connection"; };
|
||||
QString category() const { return "IP Network Telemetry"; };
|
||||
QString trCategory() const { return "IP Network Telemetry"; };
|
||||
|
||||
QWidget *createPage(QWidget *parent);
|
||||
void apply();
|
||||
|
@ -30,6 +30,20 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QRadioButton" name="UseTCP">
|
||||
<property name="text">
|
||||
<string>TCP connection</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QRadioButton" name="UseUDP">
|
||||
<property name="text">
|
||||
<string>UDP connection</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QSpinBox" name="Port">
|
||||
<property name="minimum">
|
||||
|
@ -36,14 +36,16 @@
|
||||
#include <QtCore/QtPlugin>
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtNetwork/QAbstractSocket>
|
||||
#include <QtNetwork/QTcpSocket>
|
||||
#include <QtNetwork/QUdpSocket>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
TCPtelemetryConnection::TCPtelemetryConnection()
|
||||
{
|
||||
//create all our objects
|
||||
m_config = new TCPtelemetryConfiguration("TCP Connection", NULL, this);
|
||||
m_config = new TCPtelemetryConfiguration("IP Network Telemetry", NULL, this);
|
||||
m_config->restoresettings();
|
||||
|
||||
m_optionspage = new TCPtelemetryOptionsPage(m_config,this);
|
||||
@ -87,7 +89,11 @@ QIODevice *TCPtelemetryConnection::openDevice(const QString &deviceName)
|
||||
int Port;
|
||||
QMessageBox msgBox;
|
||||
|
||||
tcpSocket = new QTcpSocket(this);
|
||||
if (m_config->UseTCP()) {
|
||||
tcpSocket = new QTcpSocket(this);
|
||||
} else {
|
||||
tcpSocket = new QUdpSocket(this);
|
||||
}
|
||||
|
||||
//get the configuration info
|
||||
HostName = m_config->HostName();
|
||||
@ -111,7 +117,10 @@ QIODevice *TCPtelemetryConnection::openDevice(const QString &deviceName)
|
||||
msgBox.setText((const QString )tcpSocket->errorString ());
|
||||
msgBox.exec();
|
||||
}
|
||||
return NULL;
|
||||
/* 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.*/
|
||||
//return NULL;
|
||||
return tcpSocket;
|
||||
}
|
||||
|
||||
void TCPtelemetryConnection::closeDevice(const QString &deviceName)
|
||||
@ -119,18 +128,24 @@ void TCPtelemetryConnection::closeDevice(const QString &deviceName)
|
||||
//still having problems with the app crashing when we reference the tcpsocket outside the openDevice function...
|
||||
//tcpSocket->close ();
|
||||
//delete(tcpSocket);
|
||||
// Note: CorvusCorax thinks its because the socket got deleted by the caller before this close() is even called
|
||||
// so we end up with a dangling reference! Is this a bug?
|
||||
|
||||
}
|
||||
|
||||
|
||||
QString TCPtelemetryConnection::connectionName()
|
||||
{//updated from serial plugin
|
||||
return QString("TCP telemetry port");
|
||||
return QString("Network telemetry port");
|
||||
}
|
||||
|
||||
QString TCPtelemetryConnection::shortName()
|
||||
{//updated from serial plugin
|
||||
return QString("TCP");
|
||||
if (m_config->UseTCP()) {
|
||||
return QString("TCP");
|
||||
} else {
|
||||
return QString("UDP");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,7 +37,9 @@
|
||||
//#include <QtCore/QSettings>
|
||||
|
||||
|
||||
class QAbstractSocket;
|
||||
class QTcpSocket;
|
||||
class QUdpSocket;
|
||||
|
||||
class IConnection;
|
||||
/**
|
||||
@ -68,7 +70,7 @@ public:
|
||||
protected slots:
|
||||
void onEnumerationChanged();
|
||||
private:
|
||||
QTcpSocket *tcpSocket;
|
||||
QAbstractSocket *tcpSocket;
|
||||
TCPtelemetryConfiguration *m_config;
|
||||
TCPtelemetryOptionsPage *m_optionspage;
|
||||
//QSettings* settings;
|
||||
|
@ -1,8 +1,8 @@
|
||||
/********************************************************************************
|
||||
** Form generated from reading UI file 'TCPtelemetryoptionspage.ui'
|
||||
**
|
||||
** Created: Wed 23. Jun 00:36:03 2010
|
||||
** by: Qt User Interface Compiler version 4.6.3
|
||||
** Created: Sun Jun 27 12:45:24 2010
|
||||
** by: Qt User Interface Compiler version 4.6.2
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||
********************************************************************************/
|
||||
@ -18,6 +18,7 @@
|
||||
#include <QtGui/QHeaderView>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QRadioButton>
|
||||
#include <QtGui/QSpacerItem>
|
||||
#include <QtGui/QSpinBox>
|
||||
#include <QtGui/QWidget>
|
||||
@ -29,6 +30,8 @@ class Ui_TCPtelemetryOptionsPage
|
||||
public:
|
||||
QGridLayout *gridLayout;
|
||||
QSpacerItem *horizontalSpacer;
|
||||
QRadioButton *UseTCP;
|
||||
QRadioButton *UseUDP;
|
||||
QSpinBox *Port;
|
||||
QLabel *label_3;
|
||||
QLineEdit *HostName;
|
||||
@ -46,6 +49,16 @@ public:
|
||||
|
||||
gridLayout->addItem(horizontalSpacer, 0, 3, 1, 1);
|
||||
|
||||
UseTCP = new QRadioButton(TCPtelemetryOptionsPage);
|
||||
UseTCP->setObjectName(QString::fromUtf8("UseTCP"));
|
||||
|
||||
gridLayout->addWidget(UseTCP, 2, 2, 1, 1);
|
||||
|
||||
UseUDP = new QRadioButton(TCPtelemetryOptionsPage);
|
||||
UseUDP->setObjectName(QString::fromUtf8("UseUDP"));
|
||||
|
||||
gridLayout->addWidget(UseUDP, 3, 2, 1, 1);
|
||||
|
||||
Port = new QSpinBox(TCPtelemetryOptionsPage);
|
||||
Port->setObjectName(QString::fromUtf8("Port"));
|
||||
Port->setMinimum(1);
|
||||
@ -77,6 +90,8 @@ public:
|
||||
void retranslateUi(QWidget *TCPtelemetryOptionsPage)
|
||||
{
|
||||
TCPtelemetryOptionsPage->setWindowTitle(QApplication::translate("TCPtelemetryOptionsPage", "Form", 0, QApplication::UnicodeUTF8));
|
||||
UseTCP->setText(QApplication::translate("TCPtelemetryOptionsPage", "TCP connection", 0, QApplication::UnicodeUTF8));
|
||||
UseUDP->setText(QApplication::translate("TCPtelemetryOptionsPage", "UDP connection", 0, QApplication::UnicodeUTF8));
|
||||
label_3->setText(QApplication::translate("TCPtelemetryOptionsPage", "Port", 0, QApplication::UnicodeUTF8));
|
||||
label_2->setText(QApplication::translate("TCPtelemetryOptionsPage", "Host Name/Number", 0, QApplication::UnicodeUTF8));
|
||||
} // retranslateUi
|
||||
|
Loading…
Reference in New Issue
Block a user