diff --git a/src/comm/LinkConfiguration.cc b/src/comm/LinkConfiguration.cc index c3069903cfb5e8b72ecce8c4cf2f133692ee8655..57ee6c929496a9ede30825fd3b12c79f185d718c 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 0c09ba7670d88061675a829c2ac13f0e999065ec..1216d40487d8e1d9ca36a04ce184594e59249de8 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 f51747b1967c23e29ca22ce335f6b67bcb922a7a..3fffbdfd807bd4d1040747ccd3224bca99e01ec6 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 ad4e7d62784d3e698133c086f23fc0aa22a3e8d8..ba0e057f0606009c22fa0b17bf1ec168e97c15ba 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/SerialLinkInterface.h b/src/comm/SerialLinkInterface.h deleted file mode 100644 index 985e92a937157722da0b4596fa9969eb8227cf21..0000000000000000000000000000000000000000 --- a/src/comm/SerialLinkInterface.h +++ /dev/null @@ -1,74 +0,0 @@ -/*===================================================================== - -QGroundControl Open Source Ground Control Station - -(c) 2009 - 2011 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 Brief Description - * - * @author Lorenz Meier - * - */ - -#ifndef SERIALLINKINTERFACE_H_ -#define SERIALLINKINTERFACE_H_ - -#include -#include -#include -#include - -/* -class SerialLinkInterface : public LinkInterface -{ - Q_OBJECT - -public: - virtual QString getPortName() const = 0; - virtual int getBaudRate() const = 0; - virtual int getDataBits() const = 0; - virtual int getStopBits() const = 0; - virtual void requestReset() = 0; - virtual int getBaudRateType() const = 0; - virtual int getFlowType() const = 0; - virtual int getParityType() const = 0; - virtual int getDataBitsType() const = 0; - virtual int getStopBitsType() const = 0; - -public slots: - virtual bool setPortName(QString portName) = 0; - virtual bool setBaudRate(int rate) = 0; - virtual bool setBaudRateType(int rateIndex) = 0; - virtual bool setFlowType(int flow) = 0; - virtual bool setParityType(int parity) = 0; - virtual bool setDataBitsType(int dataBits) = 0; - virtual bool setStopBitsType(int stopBits) = 0; - virtual void loadSettings() = 0; - virtual void writeSettings() = 0; - -}; -*/ - -/* Declare C++ interface as Qt interface */ -//Q_DECLARE_INTERFACE(SerialLinkInterface, "org.openground.comm.links.SerialLinkInterface/1.0") - -#endif // SERIALLINKINTERFACE_H_ diff --git a/src/comm/TCPLink.cc b/src/comm/TCPLink.cc index 80872dd53205b512cfc725e376f0c3fd3736b3df..70bf07decd72cdb7c609a8d896511e0d7b977f92 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 0b6e592698ce7bfd63b59d044bc911a80c41d06c..36ce8815addbd509d39518ce7623a487ef439791 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 f32409c3aefddcd3d590b514eb19402b91b9c123..9c232ea3b69dd330e7d88946ed0c70d7a5a5d742 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 471f151aa79df3f99b47f2cc0e70ff7560cd4624..9adfd266d6ec806d579251bffe7704ca7bca086c 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 86dde4e3c4dbff69aa454f51e50270fa65f06d7e..2ebd3b8bb5dc4c8157da4301a212ef891077b6d6 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 e007e32748b4b29630806a61038c4d8aa7f00566..6a406fbe77951a57365b376d2f59b1278d37c86e 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 3ed561562bf0cfed68718d0e07da02f563c24b9d..b6339a83cf34a48c19bdb99b1584ef592b5c6fe4 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 192a99d7c015cb343dfe04a0c869ff2f399cab18..380d9b8d35d46b2549e61cde305ba7103e2300e9 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 c9c1cc6a3c3d98a9b333f498f7ddcafda4ca2109..300345bad3564834d6fe34b1b2bdb189c6a59cee 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 4052ad39cb753ea055dff3a5ca85bd2857fd03d0..15afcfc6db96d5cd9142cd532b4d4822127b0226 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 e816ec73552b5d42b38600f2a2443eb4e7f6b2db..722f460e1e04a8ad2ee9235d21f1a06a020efb15 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 0d8eb33ad7e8d07862dd57400a0ba443f47a9a54..a971547e9028a66c79aba6fde6cf340ac20e1750 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 416e587970589d09aed7aba76722040fce971440..d5879289041693bba48d336748d187da2d49a961 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 3ef4ead5484dc2adec64689b9db5a6adb869c563..dc949d631a77f9dccc2a172f1186186689941718 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 5834ac951605573127368799f48cb41443dfb799..35e8d709aa27f40b2c23960ea4fc8f8ab15a022b 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