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 <QtNetwork/QUdpSocket>
4
5
#include "
QGCLoggingCategory.h
"
6
7
QGC_LOGGING_CATEGORY
(UdpForwarderLog,
"GPS.UdpForwarder"
)
8
9
UdpForwarder
::
UdpForwarder
(QObject* parent) : QObject(parent) {}
10
11
UdpForwarder::~UdpForwarder
()
12
{
13
stop
();
14
}
15
16
bool
UdpForwarder::configure
(
const
QString& address, quint16 port)
17
{
18
stop
();
19
20
const
QHostAddress parsed(
address
);
21
if
(
address
.isEmpty() || parsed.isNull() ||
port
== 0) {
22
qCWarning(UdpForwarderLog) <<
"Invalid UDP forward config:"
<<
address
<<
port
;
23
return
false
;
24
}
25
26
_address = parsed;
27
_port =
port
;
28
_socket =
new
QUdpSocket(
this
);
29
_enabled =
true
;
30
31
qCDebug(UdpForwarderLog) <<
"UDP forwarding configured:"
<<
address
<<
":"
<<
port
;
32
return
true
;
33
}
34
35
void
UdpForwarder::forward
(
const
QByteArray& data)
36
{
37
if
(!_enabled || !_socket || _port == 0) {
38
return
;
39
}
40
41
// No rate limiting: RTCM runs 5-50 KB/s; writeDatagram()'s return value
42
// surfaces saturation if it ever becomes a real problem.
43
const
qint64 sent = _socket->writeDatagram(data, _address, _port);
44
if
(sent < 0) {
45
qCWarning(UdpForwarderLog) <<
"UDP forward failed:"
<< _socket->errorString();
46
}
47
}
48
49
void
UdpForwarder::stop
()
50
{
51
if
(_socket) {
52
_socket->close();
53
_socket->deleteLater();
54
_socket =
nullptr
;
55
}
56
_enabled =
false
;
57
_port = 0;
58
_address.clear();
59
}
QGCLoggingCategory.h
QGC_LOGGING_CATEGORY
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Definition
QGCLoggingCategory.h:7
UdpForwarder.h
UdpForwarder
Definition
UdpForwarder.h:12
UdpForwarder::~UdpForwarder
~UdpForwarder() override
Definition
UdpForwarder.cc:11
UdpForwarder::stop
void stop()
Definition
UdpForwarder.cc:49
UdpForwarder::address
QString address() const
Definition
UdpForwarder.h:25
UdpForwarder::configure
bool configure(const QString &address, quint16 port)
Definition
UdpForwarder.cc:16
UdpForwarder::port
quint16 port() const
Definition
UdpForwarder.h:27
UdpForwarder::forward
void forward(const QByteArray &data)
Definition
UdpForwarder.cc:35
src
Utilities
Network
UdpForwarder.cc
Generated by
1.9.8