Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
e8a2f073
Commit
e8a2f073
authored
Feb 18, 2015
by
dogmaphobic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding TCP to the Link Configuration Manager
parent
1a6af465
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
465 additions
and
183 deletions
+465
-183
LinkConfiguration.cc
src/comm/LinkConfiguration.cc
+8
-1
LinkConfiguration.h
src/comm/LinkConfiguration.h
+2
-2
LinkManager.cc
src/comm/LinkManager.cc
+8
-1
LinkManager.h
src/comm/LinkManager.h
+2
-1
TCPLink.cc
src/comm/TCPLink.cc
+81
-78
TCPLink.h
src/comm/TCPLink.h
+78
-22
UDPLink.cc
src/comm/UDPLink.cc
+2
-2
UDPLink.h
src/comm/UDPLink.h
+1
-1
TCPLinkTest.cc
src/qgcunittest/TCPLinkTest.cc
+18
-29
TCPLinkTest.h
src/qgcunittest/TCPLinkTest.h
+1
-2
QGCCommConfiguration.cc
src/ui/QGCCommConfiguration.cc
+39
-1
QGCCommConfiguration.h
src/ui/QGCCommConfiguration.h
+30
-0
QGCLinkConfiguration.cc
src/ui/QGCLinkConfiguration.cc
+35
-20
QGCLinkConfiguration.h
src/ui/QGCLinkConfiguration.h
+30
-0
QGCTCPLinkConfiguration.cc
src/ui/QGCTCPLinkConfiguration.cc
+52
-13
QGCTCPLinkConfiguration.h
src/ui/QGCTCPLinkConfiguration.h
+35
-6
QGCTCPLinkConfiguration.ui
src/ui/QGCTCPLinkConfiguration.ui
+13
-3
QGCUDPLinkConfiguration.cc
src/ui/QGCUDPLinkConfiguration.cc
+1
-1
QGCUDPLinkConfiguration.h
src/ui/QGCUDPLinkConfiguration.h
+29
-0
No files found.
src/comm/LinkConfiguration.cc
View file @
e8a2f073
...
...
@@ -2,7 +2,7 @@
QGroundControl Open Source Ground Control Station
(c) 2009, 201
0
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
(c) 2009, 201
5
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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
<
UDPConfiguration
*>
(
source
));
break
;
case
TypeTcp
:
dupe
=
new
TCPConfiguration
(
dynamic_cast
<
TCPConfiguration
*>
(
source
));
break
;
#ifdef UNITTEST_BUILD
case
TypeMock
:
dupe
=
new
MockConfiguration
(
dynamic_cast
<
MockConfiguration
*>
(
source
));
...
...
src/comm/LinkConfiguration.h
View file @
e8a2f073
...
...
@@ -2,7 +2,7 @@
QGroundControl Open Source Ground Control Station
(c) 2009, 201
0
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
(c) 2009, 201
5
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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
...
...
src/comm/LinkManager.cc
View file @
e8a2f073
...
...
@@ -2,7 +2,7 @@
QGroundControl Open Source Ground Control Station
(c) 2009, 201
0
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
(c) 2009, 201
5
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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
<
UDPConfiguration
*>
(
config
));
break
;
case
LinkConfiguration
:
:
TypeTcp
:
pLink
=
new
TCPLink
(
dynamic_cast
<
TCPConfiguration
*>
(
config
));
break
;
#ifdef UNITTEST_BUILD
case
LinkConfiguration
:
:
TypeMock
:
pLink
=
new
MockLink
(
dynamic_cast
<
MockConfiguration
*>
(
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
);
...
...
src/comm/LinkManager.h
View file @
e8a2f073
...
...
@@ -2,7 +2,7 @@
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
(c) 2009, 201
0
PIXHAWK PROJECT <http://pixhawk.ethz.ch>
(c) 2009, 201
5
PIXHAWK PROJECT <http://pixhawk.ethz.ch>
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"
...
...
src/comm/TCPLink.cc
View file @
e8a2f073
...
...
@@ -2,7 +2,7 @@
QGroundControl Open Source Ground Control Station
(c) 2009 - 201
1
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
(c) 2009 - 201
5
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
...
...
@@ -37,26 +37,22 @@
///
/// @author Don Gagne <don@thegagnes.com>
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
<
TCPConfiguration
*>
(
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
<
TCPLink
*>
(
_link
);
if
(
ulink
)
{
ulink
->
_restartConnection
();
}
}
}
src/comm/TCPLink.h
View file @
e8a2f073
...
...
@@ -2,7 +2,7 @@
QGroundControl Open Source Ground Control Station
(c) 2009 - 201
1
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
(c) 2009 - 201
5
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
...
...
@@ -36,6 +36,7 @@
#include <QHostAddress>
#include <LinkInterface.h>
#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
;
...
...
src/comm/UDPLink.cc
View file @
e8a2f073
...
...
@@ -2,7 +2,7 @@
QGroundControl Open Source Ground Control Station
(c) 2009 - 201
1
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
(c) 2009 - 201
5
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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
<
LinkConfiguration
*>
(
this
)
);
LinkConfiguration
::
copyFrom
(
source
);
UDPConfiguration
*
usource
=
dynamic_cast
<
UDPConfiguration
*>
(
source
);
Q_ASSERT
(
usource
!=
NULL
);
_localPort
=
usource
->
localPort
();
...
...
src/comm/UDPLink.h
View file @
e8a2f073
...
...
@@ -2,7 +2,7 @@
QGroundControl Open Source Ground Control Station
(c) 2009 - 201
1
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
(c) 2009 - 201
5
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
...
...
src/qgcunittest/TCPLinkTest.cc
View file @
e8a2f073
...
...
@@ -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
...
...
src/qgcunittest/TCPLinkTest.h
View file @
e8a2f073
...
...
@@ -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
];
...
...
src/ui/QGCCommConfiguration.cc
View file @
e8a2f073
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Comm Link Configuration
* @author Gus Grubba <mavlink@grubba.com>
*
*/
#include <QPushButton>
#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
);
...
...
src/ui/QGCCommConfiguration.h
View file @
e8a2f073
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Comm Link Configuration
* @author Gus Grubba <mavlink@grubba.com>
*
*/
#ifndef QGCCOMMCONFIGURATION_H
#define QGCCOMMCONFIGURATION_H
...
...
src/ui/QGCLinkConfiguration.cc
View file @
e8a2f073
...
...
@@ -2,7 +2,7 @@
QGroundControl Open Source Ground Control Station
(c) 2009, 201
0
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
(c) 2009, 201
5
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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
<
SerialConfiguration
*>
(
config
)
->
portName
()));
break
;
case
LinkConfiguration
:
:
TypeUdp
:
config
->
setName
(
QString
(
"UDP Link on Port %1"
).
arg
(
dynamic_cast
<
UDPConfiguration
*>
(
config
)
->
localPort
()));
break
;
case
LinkConfiguration
:
:
TypeTcp
:
{
TCPConfiguration
*
tconfig
=
dynamic_cast
<
TCPConfiguration
*>
(
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
<
SerialConfiguration
*>
(
config
)
->
portName
()));
break
;
case
LinkConfiguration
:
:
TypeUdp
:
config
->
setName
(
QString
(
"UDP Link on Port %1"
).
arg
(
dynamic_cast
<
UDPConfiguration
*>
(
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
...
...
src/ui/QGCLinkConfiguration.h
View file @
e8a2f073
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Implementation of QGCLinkConfiguration
* @author Gus Grubba <mavlink@grubba.com>
*/
#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
;
...
...
src/ui/QGCTCPLinkConfiguration.cc
View file @
e8a2f073
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Implementation of QGCTCPLinkConfiguration
* @author Gus Grubba <mavlink@grubba.com>
*/
#include <QInputDialog>
#include "QGCTCPLinkConfiguration.h"
#include "ui_QGCTCPLinkConfiguration.h"
QGCTCPLinkConfiguration
::
QGCTCPLinkConfiguration
(
TCP
Link
*
link
,
QWidget
*
parent
)
:
QWidget
(
parent
),
link
(
link
),
ui
(
new
Ui
::
QGCTCPLinkConfiguration
)
QGCTCPLinkConfiguration
::
QGCTCPLinkConfiguration
(
TCP
Configuration
*
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
);
}
src/ui/QGCTCPLinkConfiguration.h
View file @
e8a2f073
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Implementation of QGCTCPLinkConfiguration
* @author Gus Grubba <mavlink@grubba.com>
*/
#ifndef QGCTCPLINKCONFIGURATION_H
#define QGCTCPLINKCONFIGURATION_H
...
...
@@ -13,20 +42,20 @@ class QGCTCPLinkConfiguration;
class
QGCTCPLinkConfiguration
:
public
QWidget
{
Q_OBJECT
public:
explicit
QGCTCPLinkConfiguration
(
TCP
Link
*
link
,
QWidget
*
parent
=
0
);
explicit
QGCTCPLinkConfiguration
(
TCP
Configuration
*
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
src/ui/QGCTCPLinkConfiguration.ui
View file @
e8a2f073
...
...
@@ -27,10 +27,13 @@
<item
row=
"0"
column=
"1"
>
<widget
class=
"QSpinBox"
name=
"portSpinBox"
>
<property
name=
"minimum"
>
<number>
3000
</number>
<number>
1024
</number>
</property>
<property
name=
"maximum"
>
<number>
100000
</number>
<number>
65535
</number>
</property>
<property
name=
"value"
>
<number>
3000
</number>
</property>
</widget>
</item>
...
...
@@ -42,7 +45,14 @@
</widget>
</item>
<item
row=
"1"
column=
"1"
>
<widget
class=
"QLineEdit"
name=
"hostAddressLineEdit"
/>
<widget
class=
"QLineEdit"
name=
"hostAddressLineEdit"
>
<property
name=
"minimumSize"
>
<size>
<width>
200
</width>
<height>
0
</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
...
...
src/ui/QGCUDPLinkConfiguration.cc
View file @
e8a2f073
...
...
@@ -2,7 +2,7 @@
QGroundControl Open Source Ground Control Station
(c) 2009, 201
0
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
(c) 2009, 201
5
QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
...
...
src/ui/QGCUDPLinkConfiguration.h
View file @
e8a2f073
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* @brief Implementation of QGCUDPLinkConfiguration
* @author Gus Grubba <mavlink@grubba.com>
*/
#ifndef QGCUDPLINKCONFIGURATION_H
#define QGCUDPLINKCONFIGURATION_H
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment