3#include <QtNetwork/QNetworkDatagram>
4#include <QtNetwork/QUdpSocket>
22 _socket =
new QUdpSocket(
this);
23 if (!_socket->bind(QHostAddress::AnyIPv4, _port)) {
24 qCWarning(RTCMUdpInputLog) <<
"Failed to bind UDP socket on port" << _port <<
":" << _socket->errorString();
25 _socket->deleteLater();
29 connect(_socket, &QUdpSocket::readyRead,
this, &RTCMUdpInput::_readDatagrams);
32 _port = _socket->localPort();
38 qCDebug(RTCMUdpInputLog) <<
"Listening for RTCM data on UDP port" << _port;
50 _socket->deleteLater();
55 qCDebug(RTCMUdpInputLog) <<
"Stopped listening on UDP port" << _port;
72void RTCMUdpInput::_readDatagrams()
77 while (_socket->hasPendingDatagrams()) {
78 const QNetworkDatagram datagram = _socket->receiveDatagram();
79 const QByteArray data = datagram.data();
85 qCDebug(RTCMUdpInputLog) <<
"Received RTCM datagram:" << data.size() <<
"bytes";
93 int framesDropped = 0;
94 for (
const char ch : data) {
95 if (!_rtcmParser.
addByte(
static_cast<uint8_t
>(
static_cast<unsigned char>(ch)))) {
109 if (framesDropped > 0) {
110 qCWarning(RTCMUdpInputLog) <<
"Dropped" << framesDropped <<
"RTCM frame(s) - CRC mismatch";
113 qCDebug(RTCMUdpInputLog) <<
"Datagram" << data.size() <<
"bytes -" <<
"framesFound:" << framesFound
114 <<
"framesDropped:" << framesDropped;
116 const quint64 totalFrames = _validFrames + _invalidFrames;
117 if (totalFrames > 0) {
118 const double dropPct = 100.0 * _invalidFrames / totalFrames;
119 qCDebug(RTCMUdpInputLog) << QString(
"RTCM frame stats: %1 valid, %2 invalid, %3% dropped")
122 .arg(dropPct, 0,
'f', 1);
#define QGC_LOGGING_CATEGORY(name, categoryStr)
QByteArray currentFrame() const
bool addByte(uint8_t byte)