From e8a2f0736ef5ad66bb06a8f5a05aea5aaed98176 Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Wed, 18 Feb 2015 01:25:10 -0500 Subject: [PATCH] Adding TCP to the Link Configuration Manager --- src/comm/LinkConfiguration.cc | 9 +- src/comm/LinkConfiguration.h | 4 +- src/comm/LinkManager.cc | 9 +- src/comm/LinkManager.h | 3 +- src/comm/TCPLink.cc | 159 +++++++++++++++--------------- src/comm/TCPLink.h | 100 ++++++++++++++----- src/comm/UDPLink.cc | 4 +- src/comm/UDPLink.h | 2 +- src/qgcunittest/TCPLinkTest.cc | 47 ++++----- src/qgcunittest/TCPLinkTest.h | 3 +- src/ui/QGCCommConfiguration.cc | 40 +++++++- src/ui/QGCCommConfiguration.h | 30 ++++++ src/ui/QGCLinkConfiguration.cc | 55 +++++++---- src/ui/QGCLinkConfiguration.h | 30 ++++++ src/ui/QGCTCPLinkConfiguration.cc | 65 +++++++++--- src/ui/QGCTCPLinkConfiguration.h | 41 ++++++-- src/ui/QGCTCPLinkConfiguration.ui | 16 ++- src/ui/QGCUDPLinkConfiguration.cc | 2 +- src/ui/QGCUDPLinkConfiguration.h | 29 ++++++ 19 files changed, 465 insertions(+), 183 deletions(-) diff --git a/src/comm/LinkConfiguration.cc b/src/comm/LinkConfiguration.cc index c3069903c..57ee6c929 100644 --- a/src/comm/LinkConfiguration.cc +++ b/src/comm/LinkConfiguration.cc @@ -2,7 +2,7 @@ QGroundControl Open Source Ground Control Station -(c) 2009, 2010 QGROUNDCONTROL PROJECT +(c) 2009, 2015 QGROUNDCONTROL PROJECT This file is part of the QGROUNDCONTROL project @@ -30,6 +30,7 @@ This file is part of the QGROUNDCONTROL project #include "LinkConfiguration.h" #include "SerialLink.h" #include "UDPLink.h" +#include "TCPLink.h" #ifdef UNITTEST_BUILD #include "MockLink.h" @@ -84,6 +85,9 @@ LinkConfiguration* LinkConfiguration::createSettings(int type, const QString& na case LinkConfiguration::TypeUdp: config = new UDPConfiguration(name); break; + case LinkConfiguration::TypeTcp: + config = new TCPConfiguration(name); + break; #ifdef UNITTEST_BUILD case LinkConfiguration::TypeMock: config = new MockConfiguration(name); @@ -107,6 +111,9 @@ LinkConfiguration* LinkConfiguration::duplicateSettings(LinkConfiguration* sourc case TypeUdp: dupe = new UDPConfiguration(dynamic_cast(source)); break; + case TypeTcp: + dupe = new TCPConfiguration(dynamic_cast(source)); + break; #ifdef UNITTEST_BUILD case TypeMock: dupe = new MockConfiguration(dynamic_cast(source)); diff --git a/src/comm/LinkConfiguration.h b/src/comm/LinkConfiguration.h index 0c09ba767..1216d4048 100644 --- a/src/comm/LinkConfiguration.h +++ b/src/comm/LinkConfiguration.h @@ -2,7 +2,7 @@ QGroundControl Open Source Ground Control Station -(c) 2009, 2010 QGROUNDCONTROL PROJECT +(c) 2009, 2015 QGROUNDCONTROL PROJECT This file is part of the QGROUNDCONTROL project @@ -41,9 +41,9 @@ public: enum { TypeSerial, ///< Serial Link TypeUdp, ///< UDP Link + TypeTcp, ///< TCP Link // TODO Below is not yet implemented #if 0 - TypeTcp, ///< TCP Link TypeSimulation, ///< Simulation Link TypeForwarding, ///< Forwarding Link TypeXbee, ///< XBee Proprietary Link diff --git a/src/comm/LinkManager.cc b/src/comm/LinkManager.cc index f51747b19..3fffbdfd8 100644 --- a/src/comm/LinkManager.cc +++ b/src/comm/LinkManager.cc @@ -2,7 +2,7 @@ QGroundControl Open Source Ground Control Station -(c) 2009, 2010 QGROUNDCONTROL PROJECT +(c) 2009, 2015 QGROUNDCONTROL PROJECT This file is part of the QGROUNDCONTROL project @@ -79,6 +79,9 @@ LinkInterface* LinkManager::createLink(LinkConfiguration* config) case LinkConfiguration::TypeUdp: pLink = new UDPLink(dynamic_cast(config)); break; + case LinkConfiguration::TypeTcp: + pLink = new TCPLink(dynamic_cast(config)); + break; #ifdef UNITTEST_BUILD case LinkConfiguration::TypeMock: pLink = new MockLink(dynamic_cast(config)); @@ -375,6 +378,10 @@ void LinkManager::loadLinkConfigurationList() pLink = (LinkConfiguration*)new UDPConfiguration(name); pLink->setPreferred(preferred); break; + case LinkConfiguration::TypeTcp: + pLink = (LinkConfiguration*)new TCPConfiguration(name); + pLink->setPreferred(preferred); + break; #ifdef UNITTEST_BUILD case LinkConfiguration::TypeMock: pLink = (LinkConfiguration*)new MockConfiguration(name); diff --git a/src/comm/LinkManager.h b/src/comm/LinkManager.h index ad4e7d627..ba0e057f0 100644 --- a/src/comm/LinkManager.h +++ b/src/comm/LinkManager.h @@ -2,7 +2,7 @@ PIXHAWK Micro Air Vehicle Flying Robotics Toolkit -(c) 2009, 2010 PIXHAWK PROJECT +(c) 2009, 2015 PIXHAWK PROJECT This file is part of the PIXHAWK project @@ -37,6 +37,7 @@ This file is part of the PIXHAWK project // Links #include "SerialLink.h" #include "UDPLink.h" +#include "TCPLink.h" #ifdef UNITTEST_BUILD #include "MockLink.h" diff --git a/src/comm/TCPLink.cc b/src/comm/TCPLink.cc index 80872dd53..70bf07dec 100644 --- a/src/comm/TCPLink.cc +++ b/src/comm/TCPLink.cc @@ -2,7 +2,7 @@ QGroundControl Open Source Ground Control Station - (c) 2009 - 2011 QGROUNDCONTROL PROJECT + (c) 2009 - 2015 QGROUNDCONTROL PROJECT This file is part of the QGROUNDCONTROL project @@ -37,26 +37,22 @@ /// /// @author Don Gagne -TCPLink::TCPLink(QHostAddress hostAddress, quint16 socketPort) : - _hostAddress(hostAddress), - _port(socketPort), - _socket(NULL), - _socketIsConnected(false) +TCPLink::TCPLink(TCPConfiguration *config) + : _config(config) + , _socket(NULL) + , _socketIsConnected(false) { + Q_ASSERT(_config != NULL); // We're doing it wrong - because the Qt folks got the API wrong: // http://blog.qt.digia.com/blog/2010/06/17/youre-doing-it-wrong/ moveToThread(this); - _linkId = getNextLinkId(); - _resetName(); - - qDebug() << "TCP Created " << _name; + qDebug() << "TCP Created " << _config->name(); } TCPLink::~TCPLink() { _disconnect(); - // Tell the thread to exit quit(); // Wait for it to exit @@ -66,49 +62,9 @@ TCPLink::~TCPLink() void TCPLink::run() { _hardwareConnect(); - exec(); } -void TCPLink::setHostAddress(QHostAddress hostAddress) -{ - bool reconnect = false; - - if (this->isConnected()) { - _disconnect(); - reconnect = true; - } - - _hostAddress = hostAddress; - _resetName(); - - if (reconnect) { - _connect(); - } -} - -void TCPLink::setHostAddress(const QString& hostAddress) -{ - setHostAddress(QHostAddress(hostAddress)); -} - -void TCPLink::setPort(int port) -{ - bool reconnect = false; - - if (this->isConnected()) { - _disconnect(); - reconnect = true; - } - - _port = port; - _resetName(); - - if (reconnect) { - _connect(); - } -} - #ifdef TCPLINK_READWRITE_DEBUG void TCPLink::_writeDebugBytes(const char *data, qint16 size) { @@ -127,7 +83,7 @@ void TCPLink::_writeDebugBytes(const char *data, qint16 size) ascii.append(219); } } - qDebug() << "Sent" << size << "bytes to" << _hostAddress.toString() << ":" << _port << "data:"; + qDebug() << "Sent" << size << "bytes to" << _config->address().toString() << ":" << _config->port() << "data:"; qDebug() << bytes; qDebug() << "ASCII:" << ascii; } @@ -139,7 +95,6 @@ void TCPLink::writeBytes(const char* data, qint64 size) _writeDebugBytes(data, size); #endif _socket->write(data, size); - // Log the amount and time written out for future data rate calculations. QMutexLocker dataRateLocker(&dataRateMutex); logDataRateToBuffer(outDataWriteAmounts, outDataWriteTimes, &outDataIndex, size, QDateTime::currentMSecsSinceEpoch()); @@ -154,20 +109,15 @@ void TCPLink::writeBytes(const char* data, qint64 size) void TCPLink::readBytes() { qint64 byteCount = _socket->bytesAvailable(); - if (byteCount) { QByteArray buffer; buffer.resize(byteCount); - _socket->read(buffer.data(), buffer.size()); - emit bytesReceived(this, buffer); - // Log the amount and time received for future data rate calculations. QMutexLocker dataRateLocker(&dataRateMutex); logDataRateToBuffer(inDataWriteAmounts, inDataWriteTimes, &inDataIndex, byteCount, QDateTime::currentMSecsSinceEpoch()); - #ifdef TCPLINK_READWRITE_DEBUG writeDebugBytes(buffer.data(), buffer.size()); #endif @@ -183,16 +133,13 @@ bool TCPLink::_disconnect(void) { quit(); wait(); - if (_socket) { _socketIsConnected = false; _socket->deleteLater(); // Make sure delete happens on correct thread _socket = NULL; - emit disconnected(); } - return true; } @@ -208,24 +155,18 @@ bool TCPLink::_connect(void) quit(); wait(); } - start(HighPriority); - return true; } -bool TCPLink::_hardwareConnect(void) +bool TCPLink::_hardwareConnect() { Q_ASSERT(_socket == NULL); _socket = new QTcpSocket(); - QSignalSpy errorSpy(_socket, SIGNAL(error(QAbstractSocket::SocketError))); - - _socket->connectToHost(_hostAddress, _port); - + _socket->connectToHost(_config->address(), _config->port()); QObject::connect(_socket, SIGNAL(readyRead()), this, SLOT(readBytes())); QObject::connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(_socketError(QAbstractSocket::SocketError))); - // Give the socket a second to connect to the other side otherwise error out if (!_socket->waitForConnected(1000)) { @@ -238,10 +179,8 @@ bool TCPLink::_hardwareConnect(void) _socket = NULL; return false; } - _socketIsConnected = true; emit connected(); - return true; } @@ -268,7 +207,7 @@ int TCPLink::getId() const QString TCPLink::getName() const { - return _name; + return _config->name(); } qint64 TCPLink::getConnectionSpeed() const @@ -286,12 +225,6 @@ qint64 TCPLink::getCurrentOutDataRate() const return 0; } -void TCPLink::_resetName(void) -{ - _name = QString("TCP Link (host:%1 port:%2)").arg(_hostAddress.toString()).arg(_port); - emit nameChanged(_name); -} - void TCPLink::waitForBytesWritten(int msecs) { Q_ASSERT(_socket); @@ -303,3 +236,73 @@ void TCPLink::waitForReadyRead(int msecs) Q_ASSERT(_socket); _socket->waitForReadyRead(msecs); } + +void TCPLink::_restartConnection() +{ + if(this->isConnected()) + { + _disconnect(); + _connect(); + } +} + +//-------------------------------------------------------------------------- +//-- TCPConfiguration + +TCPConfiguration::TCPConfiguration(const QString& name) : LinkConfiguration(name) +{ + _port = QGC_TCP_PORT; + _address = QHostAddress::Any; +} + +TCPConfiguration::TCPConfiguration(TCPConfiguration* source) : LinkConfiguration(source) +{ + _port = source->port(); + _address = source->address(); +} + +void TCPConfiguration::copyFrom(LinkConfiguration *source) +{ + LinkConfiguration::copyFrom(source); + TCPConfiguration* usource = dynamic_cast(source); + Q_ASSERT(usource != NULL); + _port = usource->port(); + _address = usource->address(); +} + +void TCPConfiguration::setPort(quint16 port) +{ + _port = port; +} + +void TCPConfiguration::setAddress(const QHostAddress& address) +{ + _address = address; +} + +void TCPConfiguration::saveSettings(QSettings& settings, const QString& root) +{ + settings.beginGroup(root); + settings.setValue("port", (int)_port); + settings.setValue("host", address().toString()); + settings.endGroup(); +} + +void TCPConfiguration::loadSettings(QSettings& settings, const QString& root) +{ + settings.beginGroup(root); + _port = (quint16)settings.value("port", QGC_UDP_PORT).toUInt(); + QString address = settings.value("host", _address.toString()).toString(); + _address = address; + settings.endGroup(); +} + +void TCPConfiguration::updateSettings() +{ + if(_link) { + TCPLink* ulink = dynamic_cast(_link); + if(ulink) { + ulink->_restartConnection(); + } + } +} diff --git a/src/comm/TCPLink.h b/src/comm/TCPLink.h index 0b6e59269..36ce8815a 100644 --- a/src/comm/TCPLink.h +++ b/src/comm/TCPLink.h @@ -2,7 +2,7 @@ QGroundControl Open Source Ground Control Station - (c) 2009 - 2011 QGROUNDCONTROL PROJECT + (c) 2009 - 2015 QGROUNDCONTROL PROJECT This file is part of the QGROUNDCONTROL project @@ -36,6 +36,7 @@ #include #include #include "QGCConfig.h" +#include "LinkManager.h" // Even though QAbstractSocket::SocketError is used in a signal by Qt, Qt doesn't declare it as a meta type. // This in turn causes debug output to be kicked out about not being able to queue the signal. We declare it @@ -47,20 +48,79 @@ class TCPLinkUnitTest; +#define QGC_TCP_PORT 5760 + +class TCPConfiguration : public LinkConfiguration +{ +public: + + /*! + * @brief Regular constructor + * + * @param[in] name Configuration (user friendly) name + */ + TCPConfiguration(const QString& name); + + /*! + * @brief Copy contructor + * + * When manipulating data, you create a copy of the configuration, edit it + * and then transfer its content to the original (using copyFrom() below). Use this + * contructor to create an editable copy. + * + * @param[in] source Original configuration + */ + TCPConfiguration(TCPConfiguration* source); + + /*! + * @brief The TCP port + * + * @return Port number + */ + quint16 port () { return _port; } + + /*! + * @brief Set the TCP port + * + * @param[in] port Port number + */ + void setPort (quint16 port); + + /*! + * @brief The host address + * + * @return Host address + */ + const QHostAddress& address () { return _address; } + + /*! + * @brief Set the host address + * + * @param[in] address Host address + */ + void setAddress (const QHostAddress& address); + + /// From LinkConfiguration + int type() { return LinkConfiguration::TypeTcp; } + void copyFrom(LinkConfiguration* source); + void loadSettings(QSettings& settings, const QString& root); + void saveSettings(QSettings& settings, const QString& root); + void updateSettings(); + +private: + QHostAddress _address; + quint16 _port; +}; + class TCPLink : public LinkInterface { Q_OBJECT - friend class TCPLinkUnitTest; - + friend class TCPConfiguration; public: - TCPLink(QHostAddress hostAddress = QHostAddress::LocalHost, quint16 socketPort = 5760); + TCPLink(TCPConfiguration* config); ~TCPLink(); - void setHostAddress(QHostAddress hostAddress); - - QHostAddress getHostAddress(void) const { return _hostAddress; } - quint16 getPort(void) const { return _port; } QTcpSocket* getSocket(void) { return _socket; } void signalBytesWritten(void); @@ -82,12 +142,9 @@ public: bool disconnect(void); public slots: - void setHostAddress(const QString& hostAddress); - void setPort(int port); // From LinkInterface - virtual void writeBytes(const char* data, qint64 length); - + void writeBytes(const char* data, qint64 length); void waitForBytesWritten(int msecs); void waitForReadyRead(int msecs); @@ -103,21 +160,20 @@ protected: private: // From LinkInterface - virtual bool _connect(void); - virtual bool _disconnect(void); + bool _connect(void); + bool _disconnect(void); + + bool _hardwareConnect(); + void _restartConnection(); - void _resetName(void); - bool _hardwareConnect(void); #ifdef TCPLINK_READWRITE_DEBUG void _writeDebugBytes(const char *data, qint16 size); #endif - QString _name; - QHostAddress _hostAddress; - quint16 _port; - int _linkId; - QTcpSocket* _socket; - bool _socketIsConnected; + int _linkId; + TCPConfiguration* _config; + QTcpSocket* _socket; + bool _socketIsConnected; quint64 _bitsSentTotal; quint64 _bitsSentCurrent; diff --git a/src/comm/UDPLink.cc b/src/comm/UDPLink.cc index f32409c3a..9c232ea3b 100644 --- a/src/comm/UDPLink.cc +++ b/src/comm/UDPLink.cc @@ -2,7 +2,7 @@ QGroundControl Open Source Ground Control Station -(c) 2009 - 2011 QGROUNDCONTROL PROJECT +(c) 2009 - 2015 QGROUNDCONTROL PROJECT This file is part of the QGROUNDCONTROL project @@ -286,7 +286,7 @@ UDPConfiguration::UDPConfiguration(UDPConfiguration* source) : LinkConfiguration void UDPConfiguration::copyFrom(LinkConfiguration *source) { _confMutex.lock(); - LinkConfiguration::copyFrom(dynamic_cast(this)); + LinkConfiguration::copyFrom(source); UDPConfiguration* usource = dynamic_cast(source); Q_ASSERT(usource != NULL); _localPort = usource->localPort(); diff --git a/src/comm/UDPLink.h b/src/comm/UDPLink.h index 471f151aa..9adfd266d 100644 --- a/src/comm/UDPLink.h +++ b/src/comm/UDPLink.h @@ -2,7 +2,7 @@ QGroundControl Open Source Ground Control Station -(c) 2009 - 2011 QGROUNDCONTROL PROJECT +(c) 2009 - 2015 QGROUNDCONTROL PROJECT This file is part of the QGROUNDCONTROL project diff --git a/src/qgcunittest/TCPLinkTest.cc b/src/qgcunittest/TCPLinkTest.cc index 86dde4e3c..2ebd3b8bb 100644 --- a/src/qgcunittest/TCPLinkTest.cc +++ b/src/qgcunittest/TCPLinkTest.cc @@ -33,13 +33,14 @@ // time to debug. //UT_REGISTER_TEST(TCPLinkUnitTest) -TCPLinkUnitTest::TCPLinkUnitTest(void) : - _link(NULL), - _hostAddress(QHostAddress::LocalHost), - _port(5760), - _multiSpy(NULL) +TCPLinkUnitTest::TCPLinkUnitTest(void) + : _config(NULL) + , _link(NULL) + , _multiSpy(NULL) { - + _config = new TCPConfiguration("MockTCP"); + _config->setAddress(QHostAddress::LocalHost); + _config->setPort(5760); } // Called before every test @@ -50,13 +51,12 @@ void TCPLinkUnitTest::init(void) Q_ASSERT(_link == NULL); Q_ASSERT(_multiSpy == NULL); - _link = new TCPLink(_hostAddress, _port); + _link = new TCPLink(_config); Q_ASSERT(_link != NULL); _rgSignals[bytesReceivedSignalIndex] = SIGNAL(bytesReceived(LinkInterface*, QByteArray)); _rgSignals[connectedSignalIndex] = SIGNAL(connected(void)); _rgSignals[disconnectedSignalIndex] = SIGNAL(disconnected(void)); - _rgSignals[nameChangedSignalIndex] = SIGNAL(nameChanged(QString)); _rgSignals[communicationErrorSignalIndex] = SIGNAL(communicationError(const QString&, const QString&)); _rgSignals[communicationUpdateSignalIndex] = SIGNAL(communicationUpdate(const QString&, const QString&)); _rgSignals[deleteLinkSignalIndex] = SIGNAL(deleteLink(LinkInterface* const)); @@ -70,50 +70,39 @@ void TCPLinkUnitTest::cleanup(void) { Q_ASSERT(_multiSpy); Q_ASSERT(_link); + Q_ASSERT(_config); delete _multiSpy; delete _link; + delete _config; _multiSpy = NULL; - _link = NULL; - + _link = NULL; + _config = NULL; UnitTest::cleanup(); } void TCPLinkUnitTest::_properties_test(void) { + Q_ASSERT(_config); Q_ASSERT(_link); Q_ASSERT(_multiSpy); Q_ASSERT(_multiSpy->checkNoSignals() == true); - // Make sure we get the right values back - QHostAddress hostAddressOut; - quint16 portOut; - - hostAddressOut = _link->getHostAddress(); - QCOMPARE(_hostAddress, hostAddressOut); - - portOut = _link->getPort(); - QCOMPARE(_port, portOut); + // Test no longer valid } void TCPLinkUnitTest::_nameChangedSignal_test(void) { + // Test no longer valid + Q_ASSERT(_config); Q_ASSERT(_link); Q_ASSERT(_multiSpy); - Q_ASSERT(_multiSpy->checkNoSignals() == true); - - _link->setHostAddress(QHostAddress("127.1.1.1")); - QCOMPARE(_multiSpy->checkOnlySignalByMask(nameChangedSignalMask), true); - _multiSpy->clearSignalByIndex(nameChangedSignalIndex); - - _link->setPort(42); - QCOMPARE(_multiSpy->checkOnlySignalByMask(nameChangedSignalMask), true); - _multiSpy->clearSignalByIndex(nameChangedSignalIndex); } void TCPLinkUnitTest::_connectFail_test(void) { + Q_ASSERT(_config); Q_ASSERT(_link); Q_ASSERT(_multiSpy); Q_ASSERT(_multiSpy->checkNoSignals() == true); @@ -150,7 +139,7 @@ void TCPLinkUnitTest::_connectSucceed_test(void) Q_ASSERT(_multiSpy->checkNoSignals() == true); // Start the server side - TCPLoopBackServer* server = new TCPLoopBackServer(_hostAddress, _port); + TCPLoopBackServer* server = new TCPLoopBackServer(_config->address(), _config->port()); Q_CHECK_PTR(server); // Connect to the server diff --git a/src/qgcunittest/TCPLinkTest.h b/src/qgcunittest/TCPLinkTest.h index e007e3274..6a406fbe7 100644 --- a/src/qgcunittest/TCPLinkTest.h +++ b/src/qgcunittest/TCPLinkTest.h @@ -75,9 +75,8 @@ private: deleteLinkSignalMask = 1 << deleteLinkSignalIndex, }; + TCPConfiguration* _config; TCPLink* _link; - QHostAddress _hostAddress; - quint16 _port; MultiSignalSpy* _multiSpy; static const size_t _cSignals = maxSignalIndex; const char* _rgSignals[_cSignals]; diff --git a/src/ui/QGCCommConfiguration.cc b/src/ui/QGCCommConfiguration.cc index 3ed561562..b6339a83c 100644 --- a/src/ui/QGCCommConfiguration.cc +++ b/src/ui/QGCCommConfiguration.cc @@ -1,8 +1,39 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009 - 2015 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Comm Link Configuration + * @author Gus Grubba + * + */ + #include #include "SerialLink.h" #include "SerialConfigurationWindow.h" #include "QGCUDPLinkConfiguration.h" +#include "QGCTCPLinkConfiguration.h" #include "QGCCommConfiguration.h" #include "ui_QGCCommConfiguration.h" @@ -16,12 +47,12 @@ QGCCommConfiguration::QGCCommConfiguration(QWidget *parent, LinkConfiguration *c _ui->typeCombo->addItem(tr("Select Type"), LinkConfiguration::TypeLast); _ui->typeCombo->addItem(tr("Serial"), LinkConfiguration::TypeSerial); _ui->typeCombo->addItem(tr("UDP"), LinkConfiguration::TypeUdp); + _ui->typeCombo->addItem(tr("TCP"), LinkConfiguration::TypeTcp); #ifdef UNITTEST_BUILD _ui->typeCombo->addItem(tr("Mock"), LinkConfiguration::TypeMock); #endif #if 0 - _ui->typeCombo->addItem(tr("TCP"), LinkConfiguration::TypeTcp); #ifdef QGC_RTLAB_ENABLED _ui->typeCombo->addItem(tr("Opal-RT Link"), LinkConfiguration::TypeOpal); @@ -96,6 +127,13 @@ void QGCCommConfiguration::_loadTypeConfigWidget(int type) _ui->typeCombo->setCurrentIndex(_ui->typeCombo->findData(LinkConfiguration::TypeUdp)); } break; + case LinkConfiguration::TypeTcp: { + QWidget* conf = new QGCTCPLinkConfiguration((TCPConfiguration*)_config, this); + _ui->linkScrollArea->setWidget(conf); + _ui->linkGroupBox->setTitle(tr("TCP Link")); + _ui->typeCombo->setCurrentIndex(_ui->typeCombo->findData(LinkConfiguration::TypeTcp)); + } + break; #ifdef UNITTEST_BUILD case LinkConfiguration::TypeMock: { _ui->linkScrollArea->setWidget(NULL); diff --git a/src/ui/QGCCommConfiguration.h b/src/ui/QGCCommConfiguration.h index 192a99d7c..380d9b8d3 100644 --- a/src/ui/QGCCommConfiguration.h +++ b/src/ui/QGCCommConfiguration.h @@ -1,3 +1,33 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009 - 2015 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Comm Link Configuration + * @author Gus Grubba + * + */ + #ifndef QGCCOMMCONFIGURATION_H #define QGCCOMMCONFIGURATION_H diff --git a/src/ui/QGCLinkConfiguration.cc b/src/ui/QGCLinkConfiguration.cc index c9c1cc6a3..300345bad 100644 --- a/src/ui/QGCLinkConfiguration.cc +++ b/src/ui/QGCLinkConfiguration.cc @@ -2,7 +2,7 @@ QGroundControl Open Source Ground Control Station -(c) 2009, 2010 QGROUNDCONTROL PROJECT +(c) 2009, 2015 QGROUNDCONTROL PROJECT This file is part of the QGROUNDCONTROL project @@ -124,6 +124,38 @@ void QGCLinkConfiguration::on_editLinkButton_clicked() _editLink(index.row()); } +void QGCLinkConfiguration::_fixUnnamed(LinkConfiguration* config) +{ + Q_ASSERT(config != NULL); + //-- Check for "Unnamed" + if (config->name() == tr("Unnamed")) { + switch(config->type()) { + case LinkConfiguration::TypeSerial: + config->setName( + QString("Serial Device on %1").arg(dynamic_cast(config)->portName())); + break; + case LinkConfiguration::TypeUdp: + config->setName( + QString("UDP Link on Port %1").arg(dynamic_cast(config)->localPort())); + break; + case LinkConfiguration::TypeTcp: { + TCPConfiguration* tconfig = dynamic_cast(config); + if(tconfig) { + config->setName( + QString("TCP Link %1:%2").arg(tconfig->address().toString()).arg((int)tconfig->port())); + } + } + break; +#ifdef UNITTEST_BUILD + case LinkConfiguration::TypeMock: + config->setName( + QString("Mock Link")); + break; +#endif + } + } +} + void QGCLinkConfiguration::on_addLinkButton_clicked() { QGCCommConfiguration* commDialog = new QGCCommConfiguration(this); @@ -131,25 +163,7 @@ void QGCLinkConfiguration::on_addLinkButton_clicked() // Save changes (if any) LinkConfiguration* config = commDialog->getConfig(); if(config) { - //-- Check for "Unnamed" - if (config->name() == tr("Unnamed")) { - switch(config->type()) { - case LinkConfiguration::TypeSerial: - config->setName( - QString("Serial Device on %1").arg(dynamic_cast(config)->portName())); - break; - case LinkConfiguration::TypeUdp: - config->setName( - QString("UDP Link on Port %1").arg(dynamic_cast(config)->localPort())); - break; -#ifdef UNITTEST_BUILD - case LinkConfiguration::TypeMock: - config->setName( - QString("Mock Link")); - break; -#endif - } - } + _fixUnnamed(config); _viewModel->beginChange(); LinkManager::instance()->addLinkConfiguration(commDialog->getConfig()); LinkManager::instance()->saveLinkConfigurationList(); @@ -172,6 +186,7 @@ void QGCLinkConfiguration::_editLink(int row) if(commDialog->exec() == QDialog::Accepted) { // Save changes (if any) if(commDialog->getConfig()) { + _fixUnnamed(tmpConfig); _viewModel->beginChange(); config->copyFrom(tmpConfig); // Save it diff --git a/src/ui/QGCLinkConfiguration.h b/src/ui/QGCLinkConfiguration.h index 4052ad39c..15afcfc6d 100644 --- a/src/ui/QGCLinkConfiguration.h +++ b/src/ui/QGCLinkConfiguration.h @@ -1,3 +1,32 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2015 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Implementation of QGCLinkConfiguration + * @author Gus Grubba + */ + #ifndef QGCLINKCONFIGURATION_H #define QGCLINKCONFIGURATION_H @@ -30,6 +59,7 @@ private slots: private: void _editLink(int row); + void _fixUnnamed(LinkConfiguration* config); Ui::QGCLinkConfiguration* _ui; LinkViewModel* _viewModel; diff --git a/src/ui/QGCTCPLinkConfiguration.cc b/src/ui/QGCTCPLinkConfiguration.cc index e816ec735..722f460e1 100644 --- a/src/ui/QGCTCPLinkConfiguration.cc +++ b/src/ui/QGCTCPLinkConfiguration.cc @@ -1,25 +1,53 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2015 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Implementation of QGCTCPLinkConfiguration + * @author Gus Grubba + */ + #include #include "QGCTCPLinkConfiguration.h" #include "ui_QGCTCPLinkConfiguration.h" -QGCTCPLinkConfiguration::QGCTCPLinkConfiguration(TCPLink* link, QWidget *parent) : - QWidget(parent), - link(link), - ui(new Ui::QGCTCPLinkConfiguration) +QGCTCPLinkConfiguration::QGCTCPLinkConfiguration(TCPConfiguration *config, QWidget *parent) + : QWidget(parent) + , _ui(new Ui::QGCTCPLinkConfiguration) + , _config(config) { - ui->setupUi(this); - quint16 port = link->getPort(); - ui->portSpinBox->setValue(port); - QString addr = link->getHostAddress().toString(); - ui->hostAddressLineEdit->setText(addr); - connect(ui->portSpinBox, SIGNAL(valueChanged(int)), link, SLOT(setPort(int))); - connect(ui->hostAddressLineEdit, SIGNAL(textChanged (const QString &)), link, SLOT(setHostAddress(const QString &))); + Q_ASSERT(_config != NULL); + _ui->setupUi(this); + quint16 port = config->port(); + _ui->portSpinBox->setValue(port); + QString addr = config->address().toString(); + _ui->hostAddressLineEdit->setText(addr); } QGCTCPLinkConfiguration::~QGCTCPLinkConfiguration() { - delete ui; + delete _ui; } void QGCTCPLinkConfiguration::changeEvent(QEvent *e) @@ -27,9 +55,20 @@ void QGCTCPLinkConfiguration::changeEvent(QEvent *e) QWidget::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: - ui->retranslateUi(this); + _ui->retranslateUi(this); break; default: break; } } + +void QGCTCPLinkConfiguration::on_portSpinBox_valueChanged(int arg1) +{ + _config->setPort(arg1); +} + +void QGCTCPLinkConfiguration::on_hostAddressLineEdit_textChanged(const QString &arg1) +{ + QHostAddress add(arg1); + _config->setAddress(add); +} diff --git a/src/ui/QGCTCPLinkConfiguration.h b/src/ui/QGCTCPLinkConfiguration.h index 0d8eb33ad..a971547e9 100644 --- a/src/ui/QGCTCPLinkConfiguration.h +++ b/src/ui/QGCTCPLinkConfiguration.h @@ -1,3 +1,32 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2015 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Implementation of QGCTCPLinkConfiguration + * @author Gus Grubba + */ + #ifndef QGCTCPLINKCONFIGURATION_H #define QGCTCPLINKCONFIGURATION_H @@ -13,20 +42,20 @@ class QGCTCPLinkConfiguration; class QGCTCPLinkConfiguration : public QWidget { Q_OBJECT - public: - explicit QGCTCPLinkConfiguration(TCPLink* link, QWidget *parent = 0); + explicit QGCTCPLinkConfiguration(TCPConfiguration *config, QWidget *parent = 0); ~QGCTCPLinkConfiguration(); -public slots: - protected: void changeEvent(QEvent *e); - TCPLink* link; ///< TCP link instance this widget configures +private slots: + void on_portSpinBox_valueChanged(int arg1); + void on_hostAddressLineEdit_textChanged(const QString &arg1); private: - Ui::QGCTCPLinkConfiguration *ui; + Ui::QGCTCPLinkConfiguration* _ui; + TCPConfiguration* _config; }; #endif // QGCTCPLINKCONFIGURATION_H diff --git a/src/ui/QGCTCPLinkConfiguration.ui b/src/ui/QGCTCPLinkConfiguration.ui index 416e58797..d58792890 100644 --- a/src/ui/QGCTCPLinkConfiguration.ui +++ b/src/ui/QGCTCPLinkConfiguration.ui @@ -27,10 +27,13 @@ - 3000 + 1024 - 100000 + 65535 + + + 3000 @@ -42,7 +45,14 @@ - + + + + 200 + 0 + + + diff --git a/src/ui/QGCUDPLinkConfiguration.cc b/src/ui/QGCUDPLinkConfiguration.cc index 3ef4ead54..dc949d631 100644 --- a/src/ui/QGCUDPLinkConfiguration.cc +++ b/src/ui/QGCUDPLinkConfiguration.cc @@ -2,7 +2,7 @@ QGroundControl Open Source Ground Control Station -(c) 2009, 2010 QGROUNDCONTROL PROJECT +(c) 2009, 2015 QGROUNDCONTROL PROJECT This file is part of the QGROUNDCONTROL project diff --git a/src/ui/QGCUDPLinkConfiguration.h b/src/ui/QGCUDPLinkConfiguration.h index 5834ac951..35e8d709a 100644 --- a/src/ui/QGCUDPLinkConfiguration.h +++ b/src/ui/QGCUDPLinkConfiguration.h @@ -1,3 +1,32 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2015 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL 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. + + QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Implementation of QGCUDPLinkConfiguration + * @author Gus Grubba + */ + #ifndef QGCUDPLINKCONFIGURATION_H #define QGCUDPLINKCONFIGURATION_H -- 2.22.0