-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
udpreceiver.cpp
52 lines (42 loc) · 1.9 KB
/
udpreceiver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "udpreceiver.h"
UdpReceiver::UdpReceiver(QObject *parent)
: QObject{parent}
{
}
bool UdpReceiver::start(uint16_t port) {
this->port = port;
socket = new QUdpSocket(this);
if (!socket->bind(QHostAddress::Any, port)) {
return false;
}
connect(socket, &QUdpSocket::readyRead, this, &UdpReceiver::onReadyRead);
return true;
}
void UdpReceiver::onReadyRead() {
while (socket->hasPendingDatagrams()) {
QByteArray data;
int datagramSize = socket->pendingDatagramSize();
data.resize(datagramSize);
qint64 readLen = socket->readDatagram(data.data(), data.size());
if (readLen == -1) return;
process(data);
}
}
void UdpReceiver::process(QByteArray data) {
QDataStream in(data);
in.setVersion(16);
in.setByteOrder(QDataStream::BigEndian);
in >> magic >> schema >> message_type;
switch (message_type) {
case Heartbeat:
in >> id >> max_schema_number >> version >> revision;
emit heartbeat();
break;
case QSOLogged:
qDebug() << "Received UDP message. Type: LOGGED, Payload size (bytes):" << data.size();
in >> id >> time_off >> dx_call >> dx_grid >> tx_frequency_hz >> mode >> report_sent >> report_received >> tx_power >> comments >> name >> time_on >> operator_call >> my_call >> my_grid >> exchange_sent >> exchange_rcvd >> propmode;
qDebug() << "Structed data [id, time_off, dx_call, dx_grid, tx_frequency_hz, mode, report_sent, report_received, tx_power, comments, name, time_on, operator_call, my_call, my_grid, exchange_sent, exchange_rcvd, propmode]:" << id << time_off << dx_call << dx_grid << tx_frequency_hz << mode << report_sent << report_received << tx_power << comments << name << time_on << operator_call << my_call << my_grid << exchange_sent << exchange_rcvd << propmode;
emit logged();
break;
}
}