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
ca6dc480
Commit
ca6dc480
authored
Mar 18, 2015
by
dogmaphobic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UPD Link Fix
parent
42040794
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
16 deletions
+26
-16
UDPLink.cc
src/comm/UDPLink.cc
+26
-16
No files found.
src/comm/UDPLink.cc
View file @
ca6dc480
...
...
@@ -94,7 +94,6 @@ QString UDPLink::getName() const
void
UDPLink
::
addHost
(
const
QString
&
host
)
{
qDebug
()
<<
"UDP:"
<<
"ADDING HOST:"
<<
host
;
_config
->
addHost
(
host
);
}
...
...
@@ -176,8 +175,7 @@ void UDPLink::readBytes()
// added to the list and will start receiving datagrams from here. Even a port scanner
// would trigger this.
// Add host to broadcast list if not yet present, or update its port
QString
host
(
sender
.
toString
()
+
":"
+
QString
(
"%1"
).
arg
((
int
)
senderPort
));
_config
->
addHost
(
host
);
_config
->
addHost
(
sender
.
toString
(),
(
int
)
senderPort
);
}
}
...
...
@@ -285,7 +283,6 @@ UDPConfiguration::UDPConfiguration(UDPConfiguration* source) : LinkConfiguration
void
UDPConfiguration
::
copyFrom
(
LinkConfiguration
*
source
)
{
_confMutex
.
lock
();
LinkConfiguration
::
copyFrom
(
source
);
UDPConfiguration
*
usource
=
dynamic_cast
<
UDPConfiguration
*>
(
source
);
Q_ASSERT
(
usource
!=
NULL
);
...
...
@@ -297,7 +294,6 @@ void UDPConfiguration::copyFrom(LinkConfiguration *source)
addHost
(
host
,
port
);
}
while
(
usource
->
nextHost
(
host
,
port
));
}
_confMutex
.
unlock
();
}
/**
...
...
@@ -305,7 +301,6 @@ void UDPConfiguration::copyFrom(LinkConfiguration *source)
*/
void
UDPConfiguration
::
addHost
(
const
QString
&
host
)
{
qDebug
()
<<
"UDP:"
<<
"ADDING HOST:"
<<
host
;
if
(
host
.
contains
(
":"
))
{
QHostInfo
info
=
QHostInfo
::
fromName
(
host
.
split
(
":"
).
first
());
...
...
@@ -317,32 +312,43 @@ void UDPConfiguration::addHost(const QString& host)
for
(
int
i
=
0
;
i
<
hostAddresses
.
size
();
i
++
)
{
// Exclude loopback IPv4 and all IPv6 addresses
if
(
!
hostAddresses
.
at
(
i
).
toString
().
contains
(
":"
))
if
(
!
hostAddresses
.
at
(
i
).
toString
().
contains
(
":"
)
&&
!!
hostAddresses
.
at
(
i
).
toString
().
startsWith
(
"127"
)
)
{
address
=
hostAddresses
.
at
(
i
);
}
}
_confMutex
.
lock
();
_hosts
[
address
.
toString
()]
=
host
.
split
(
":"
).
last
().
toInt
();
_confMutex
.
unlock
();
qDebug
()
<<
"UDP:"
<<
"ADDING HOST:"
<<
address
.
toString
()
<<
":"
<<
host
.
split
(
":"
).
last
();
}
}
else
{
QHostInfo
info
=
QHostInfo
::
fromName
(
host
);
if
(
info
.
error
()
==
QHostInfo
::
NoError
)
{
// Set port according to default (same as local port)
_hosts
[
info
.
addresses
().
first
().
toString
()]
=
(
int
)
_localPort
;
}
addHost
(
host
,
(
int
)
_localPort
);
}
}
void
UDPConfiguration
::
addHost
(
const
QString
&
host
,
int
port
)
{
_hosts
[
host
.
trimmed
()]
=
port
;
QMutexLocker
locker
(
&
_confMutex
);
if
(
_hosts
.
contains
(
host
))
{
if
(
_hosts
[
host
]
!=
port
)
{
_hosts
[
host
]
=
port
;
}
}
else
{
QHostInfo
info
=
QHostInfo
::
fromName
(
host
);
if
(
info
.
error
()
==
QHostInfo
::
NoError
)
{
_hosts
[
info
.
addresses
().
first
().
toString
()]
=
port
;
qDebug
()
<<
"UDP:"
<<
"ADDING HOST:"
<<
info
.
addresses
().
first
().
toString
()
<<
":"
<<
port
;
}
}
}
void
UDPConfiguration
::
removeHost
(
const
QString
&
host
)
{
QMutexLocker
locker
(
&
_confMutex
);
QString
tHost
=
host
;
if
(
tHost
.
contains
(
":"
))
{
tHost
=
tHost
.
split
(
":"
).
first
();
...
...
@@ -356,15 +362,19 @@ void UDPConfiguration::removeHost(const QString& host)
bool
UDPConfiguration
::
firstHost
(
QString
&
host
,
int
&
port
)
{
_confMutex
.
lock
();
_it
=
_hosts
.
begin
();
if
(
_it
==
_hosts
.
end
())
{
_confMutex
.
unlock
();
return
false
;
}
_confMutex
.
unlock
();
return
nextHost
(
host
,
port
);
}
bool
UDPConfiguration
::
nextHost
(
QString
&
host
,
int
&
port
)
{
QMutexLocker
locker
(
&
_confMutex
);
if
(
_it
!=
_hosts
.
end
())
{
host
=
_it
.
key
();
port
=
_it
.
value
();
...
...
@@ -402,8 +412,9 @@ void UDPConfiguration::saveSettings(QSettings& settings, const QString& root)
void
UDPConfiguration
::
loadSettings
(
QSettings
&
settings
,
const
QString
&
root
)
{
_confMutex
.
lock
();
settings
.
beginGroup
(
root
);
_hosts
.
clear
();
_confMutex
.
unlock
();
settings
.
beginGroup
(
root
);
_localPort
=
(
quint16
)
settings
.
value
(
"port"
,
QGC_UDP_LOCAL_PORT
).
toUInt
();
int
hostCount
=
settings
.
value
(
"hostCount"
,
0
).
toInt
();
for
(
int
i
=
0
;
i
<
hostCount
;
i
++
)
{
...
...
@@ -414,7 +425,6 @@ void UDPConfiguration::loadSettings(QSettings& settings, const QString& root)
}
}
settings
.
endGroup
();
_confMutex
.
unlock
();
}
void
UDPConfiguration
::
updateSettings
()
...
...
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