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
6d13ae3a
Unverified
Commit
6d13ae3a
authored
Apr 18, 2018
by
Gus Grubba
Committed by
GitHub
Apr 18, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6366 from mavlink/udpFixes
UDP Fixes
parents
83030ca6
50f7674b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
30 deletions
+41
-30
UDPLink.cc
src/comm/UDPLink.cc
+34
-25
UDPLink.h
src/comm/UDPLink.h
+7
-5
No files found.
src/comm/UDPLink.cc
View file @
6d13ae3a
...
...
@@ -68,27 +68,6 @@ static QString get_ip_address(const QString& address)
return
QString
(
""
);
}
static
bool
is_ip_local
(
const
QHostAddress
&
add
)
{
// In simulation and testing setups the vehicle and the GCS can be
// running on the same host. This leads to packets arriving through
// the local network or the loopback adapter, which makes it look
// like the vehicle is connected through two different links,
// complicating routing.
//
// We detect this case and force all traffic to a simulated instance
// onto the local loopback interface.
// Run through all IPv4 interfaces and check if their canonical
// IP address in string representation matches the source IP address
foreach
(
const
QHostAddress
&
address
,
QNetworkInterface
::
allAddresses
())
{
if
(
address
==
add
)
{
// This is a local address of the same host
return
true
;
}
}
return
false
;
}
static
bool
contains_target
(
const
QList
<
UDPCLient
*>
list
,
const
QHostAddress
&
address
,
quint16
port
)
{
foreach
(
UDPCLient
*
target
,
list
)
{
...
...
@@ -112,6 +91,9 @@ UDPLink::UDPLink(SharedLinkConfigurationPointer& config)
if
(
!
_udpConfig
)
{
qWarning
()
<<
"Internal error"
;
}
foreach
(
const
QHostAddress
&
address
,
QNetworkInterface
::
allAddresses
())
{
_localAddress
.
append
(
QHostAddress
(
address
));
}
moveToThread
(
this
);
}
...
...
@@ -158,10 +140,36 @@ QString UDPLink::getName() const
return
_udpConfig
->
name
();
}
bool
UDPLink
::
_isIpLocal
(
const
QHostAddress
&
add
)
{
// In simulation and testing setups the vehicle and the GCS can be
// running on the same host. This leads to packets arriving through
// the local network or the loopback adapter, which makes it look
// like the vehicle is connected through two different links,
// complicating routing.
//
// We detect this case and force all traffic to a simulated instance
// onto the local loopback interface.
// Run through all IPv4 interfaces and check if their canonical
// IP address in string representation matches the source IP address
//
// On Windows, this is a very expensive call only Redmond would know
// why. As such, we make it once and keep the list locally. If a new
// interface shows up after we start, it won't be on this list.
foreach
(
const
QHostAddress
&
address
,
_localAddress
)
{
if
(
address
==
add
)
{
// This is a local address of the same host
return
true
;
}
}
return
false
;
}
void
UDPLink
::
_writeBytes
(
const
QByteArray
data
)
{
if
(
!
_socket
)
if
(
!
_socket
)
{
return
;
}
// Send to all manually targeted systems
foreach
(
UDPCLient
*
target
,
_udpConfig
->
targetHosts
())
{
// Skip it if it's part of the session clients below
...
...
@@ -177,6 +185,7 @@ void UDPLink::_writeBytes(const QByteArray data)
void
UDPLink
::
_writeDataGram
(
const
QByteArray
data
,
const
UDPCLient
*
target
)
{
//qDebug() << "UDP Out" << target->address << target->port;
if
(
_socket
->
writeDatagram
(
data
,
target
->
address
,
target
->
port
)
<
0
)
{
qWarning
()
<<
"Error writing to"
<<
target
->
address
<<
target
->
port
;
}
else
{
...
...
@@ -193,10 +202,9 @@ void UDPLink::_writeDataGram(const QByteArray data, const UDPCLient* target)
**/
void
UDPLink
::
readBytes
()
{
if
(
_socket
)
{
if
(
!
_socket
)
{
return
;
}
QByteArray
databuffer
;
while
(
_socket
->
hasPendingDatagrams
())
{
...
...
@@ -204,6 +212,7 @@ void UDPLink::readBytes()
datagram
.
resize
(
_socket
->
pendingDatagramSize
());
QHostAddress
sender
;
quint16
senderPort
;
//-- Note: This call is broken in Qt 5.9.3 on Windows. It always returns a blank sender and 0 for the port.
_socket
->
readDatagram
(
datagram
.
data
(),
datagram
.
size
(),
&
sender
,
&
senderPort
);
databuffer
.
append
(
datagram
);
//-- Wait a bit before sending it over
...
...
@@ -217,7 +226,7 @@ void UDPLink::readBytes()
// would trigger this.
// Add host to broadcast list if not yet present, or update its port
QHostAddress
asender
=
sender
;
if
(
is_ip_l
ocal
(
sender
))
{
if
(
_isIpL
ocal
(
sender
))
{
asender
=
QHostAddress
(
QString
(
"127.0.0.1"
));
}
if
(
!
contains_target
(
_sessionTargets
,
asender
,
senderPort
))
{
...
...
src/comm/UDPLink.h
View file @
6d13ae3a
...
...
@@ -184,6 +184,7 @@ private:
bool
_connect
(
void
)
override
;
void
_disconnect
(
void
)
override
;
bool
_isIpLocal
(
const
QHostAddress
&
add
);
bool
_hardwareConnect
();
void
_restartConnection
();
void
_registerZeroconf
(
uint16_t
port
,
const
std
::
string
&
regType
);
...
...
@@ -194,11 +195,12 @@ private:
DNSServiceRef
_dnssServiceRef
;
#endif
bool
_running
;
QUdpSocket
*
_socket
;
UDPConfiguration
*
_udpConfig
;
bool
_connectState
;
QList
<
UDPCLient
*>
_sessionTargets
;
bool
_running
;
QUdpSocket
*
_socket
;
UDPConfiguration
*
_udpConfig
;
bool
_connectState
;
QList
<
UDPCLient
*>
_sessionTargets
;
QList
<
QHostAddress
>
_localAddress
;
};
...
...
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