QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
UdpForwarder.cc
Go to the documentation of this file.
1
#include "
UdpForwarder.h
"
2
3
#include <algorithm>
4
5
#include "
QGCLoggingCategory.h
"
6
7
QGC_LOGGING_CATEGORY
(UdpForwarderLog,
"Utilities.UdpForwarder"
)
8
9
UdpForwarder
::
UdpForwarder
(QObject* parent) : QObject(parent) {}
10
11
bool
UdpForwarder::configure
(
const
QString& address, quint16 port)
12
{
13
stop
();
14
15
const
QHostAddress parsed(
address
);
16
if
(
address
.isEmpty() || parsed.isNull() ||
port
== 0) {
17
qCWarning(UdpForwarderLog) <<
"Invalid UDP forward config:"
<<
address
<<
port
;
18
return
false
;
19
}
20
21
_address = parsed;
22
_port =
port
;
23
24
qCDebug(UdpForwarderLog) <<
"UDP forwarding configured:"
<<
address
<<
":"
<<
port
;
25
return
true
;
26
}
27
28
qint64
UdpForwarder::forward
(
const
QByteArray& data)
29
{
30
if
(!
isEnabled
()) {
31
return
0;
32
}
33
34
// No rate limiting: RTCM runs 5-50 KB/s; writeDatagram()'s return value
35
// surfaces saturation if it ever becomes a real problem.
36
const
qint64 sent = _socket.writeDatagram(data, _address, _port);
37
if
(sent < 0) {
38
qCWarning(UdpForwarderLog) <<
"UDP forward failed:"
<< _socket.errorString();
39
}
40
return
(std::max) (qint64{0}, sent);
41
}
42
43
void
UdpForwarder::stop
()
44
{
45
_socket.close();
46
_port = 0;
47
_address.clear();
48
}
QGCLoggingCategory.h
QGC_LOGGING_CATEGORY
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Definition
QGCLoggingCategory.h:11
UdpForwarder.h
UdpForwarder
Definition
UdpForwarder.h:11
UdpForwarder::isEnabled
bool isEnabled() const
Definition
UdpForwarder.h:21
UdpForwarder::forward
qint64 forward(const QByteArray &data)
Definition
UdpForwarder.cc:28
UdpForwarder::stop
void stop()
Definition
UdpForwarder.cc:43
UdpForwarder::address
QString address() const
Definition
UdpForwarder.h:23
UdpForwarder::configure
bool configure(const QString &address, quint16 port)
Definition
UdpForwarder.cc:11
UdpForwarder::port
quint16 port() const
Definition
UdpForwarder.h:25
src
Utilities
Network
IO
UdpForwarder.cc
Generated by
1.9.8