-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotudp.cpp
151 lines (126 loc) · 5.13 KB
/
rotudp.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
** This file is part of the CatRotator project.
** Copyright 2022-2024 Gianfranco Sordetti IZ8EWD <[email protected]>.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
#include "rotudp.h"
#include "rotatordata.h"
//#include "mainwindow.h"
#include <QRegularExpression>
extern catRotatorConfig rotCfg;
extern rotatorUdpEx rotUdpEx;
rotUdp::rotUdp(QObject *parent)
: QObject{parent}
{
}
bool rotUdp::initSocket()
{
udpSocket = new QUdpSocket(this);
bool result = udpSocket->bind(QHostAddress(rotCfg.udpAddress), rotCfg.udpPort);
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readDatagrams()));
return result;
}
void rotUdp::readDatagrams()
{
QHostAddress sender;
quint16 senderPort;
while (udpSocket->hasPendingDatagrams())
{
QByteArray datagrams;
datagrams.resize(udpSocket->pendingDatagramSize());
udpSocket->readDatagram(datagrams.data(), datagrams.size(), &sender, &senderPort);
//qDebug() << "Message from: " << sender.toString();
//qDebug() << "Message port: " << senderPort;
//qDebug() << "Message: " << datagrams;
//N1MM Logger+
QRegularExpression n1mmCmd("<N1MMRotor>");
QRegularExpressionMatch n1mmMatch = n1mmCmd.match(datagrams);
if (n1mmMatch.hasMatch())
{
rotUdpEx.n1mmUdp = true;
QRegularExpression n1mmName("<rotor>(.+)</rotor>");
n1mmMatch = n1mmName.match(datagrams);
if (n1mmMatch.hasMatch())
{
QString n1mmMatchString = n1mmMatch.captured(1);
rotUdpEx.rotName = n1mmMatchString;
}
QRegularExpression n1mmAzCmd("<goazi>(\\d+\\,?\\.?\\d*)</goazi>");
QRegularExpressionMatch n1mmMatch = n1mmAzCmd.match(datagrams);
if (n1mmMatch.hasMatch())
{
QString n1mmMatchString = n1mmMatch.captured(1);
n1mmMatchString.replace(",", ".", Qt::CaseInsensitive);
rotUdpEx.azUdpFlag = true;
rotUdpEx.azUdp = n1mmMatchString.toFloat();
}
QRegularExpression n1mmStopCmd("<stop>");
QRegularExpressionMatch n1mmStop = n1mmStopCmd.match(datagrams);
if (n1mmStop.hasMatch()) rotUdpEx.stopUdpFlag = true;
}
//Previsat
QRegularExpression previSatCmd("<PREVISAT>");
QRegularExpressionMatch previMatch = previSatCmd.match(datagrams);
if (previMatch.hasMatch())
{
rotUdpEx.previSatUdp = true;
QRegularExpression previSatName("<SAT>(.+)</SAT>");
previMatch = previSatName.match(datagrams);
if (previMatch.hasMatch())
{
QString previMatchString = previMatch.captured(1);
rotUdpEx.satName = previMatchString;
}
QRegularExpression previSatAOS("<AOS>(\\d)</AOS>");
previMatch = previSatAOS.match(datagrams);
if (previMatch.hasMatch())
{
QString previMatchString = previMatch.captured(1);
rotUdpEx.satAOS = previMatchString.toUInt();
}
}
QRegularExpression pstAzCmd("<AZIMUTH>(\\d+\\.?\\d*)</AZIMUTH>");
QRegularExpressionMatch pstMatch = pstAzCmd.match(datagrams);
if (pstMatch.hasMatch())
{
QString pstMatchString = pstMatch.captured(1);
rotUdpEx.azUdpFlag = true;
rotUdpEx.azUdp = pstMatchString.toFloat();
//rotUdpEx.elUdp = 0;
}
QRegularExpression pstElCmd("<ELEVATION>(-?\\d+\\.?\\d*)</ELEVATION>");
pstMatch = pstElCmd.match(datagrams);
if (pstMatch.hasMatch())
{
QString pstMatchString = pstMatch.captured(1);
rotUdpEx.elUdpFlag = true;
rotUdpEx.elUdp = pstMatchString.toFloat();
}
QRegularExpression pstStopCmd("<STOP>(\\d)</STOP>");
pstMatch = pstStopCmd.match(datagrams);
if (pstMatch.hasMatch())
{
QString pstMatchString = pstMatch.captured(1);
rotUdpEx.stopUdpFlag = pstMatchString.toInt();
}
QRegularExpression pstParkCmd("<PARK>(\\d)</PARK>");
pstMatch = pstParkCmd.match(datagrams);
if (pstMatch.hasMatch())
{
QString pstMatchString = pstMatch.captured(1);
rotUdpEx.parkUdpFlag = pstMatchString.toInt();
}
}
}