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
|
#include "pskreporter_decode.h"
#include "../validators/LiveCQCallsign.hpp"
#include "../Network/DecodedTime.hpp"
#include <QtGlobal>
namespace
{
bool isReportableMessageType(QString const& messageType)
{
return messageType == "CQ" || messageType == "QRZ"
|| messageType == "CQV" || messageType == "CQH"
|| messageType == "QRT";
}
bool parseSpot(QStringList const& tokens,
QString const& receiverCallsign,
QString const& receiverLocator,
QDateTime const& nowUtc,
PSKReporterIPFIX::Spot& spot)
{
if (tokens.size() < 9 || receiverCallsign.length() < 3
|| receiverLocator.length() < 4
|| !isReportableMessageType(tokens.at(5).trimmed())) {
return false;
}
bool ok = false;
auto const frequencyMHz = tokens.at(0).trimmed().toDouble(&ok);
if (!ok) {
return false;
}
auto const spotTime = DecodedTime::spotTime(tokens.at(3).trimmed(), nowUtc, 60);
if (!spotTime.isValid()) {
return false;
}
QString callsign;
QString locator = "--";
QString mode;
QString modeToken;
if (tokens.at(7).contains('.')) {
callsign = tokens.at(6).trimmed().toUpper();
modeToken = tokens.at(8).trimmed();
} else if (tokens.size() >= 10 && tokens.at(8).contains('.')) {
callsign = tokens.at(6).trimmed().toUpper();
if (Map65PSKReporter::isValidMap65Callsign(callsign)) {
locator = tokens.at(7).trimmed();
} else {
callsign = tokens.at(7).trimmed().toUpper();
}
modeToken = tokens.at(9).trimmed();
} else if (tokens.size() >= 11 && tokens.at(9).contains('.')) {
callsign = tokens.at(7).trimmed().toUpper();
locator = tokens.at(8).trimmed();
modeToken = tokens.at(10).trimmed();
} else {
return false;
}
if (!Map65PSKReporter::isValidMap65Callsign(callsign)) {
return false;
}
if (modeToken.contains('#')) {
mode = "JT65" + modeToken.back();
} else if (modeToken.contains(':')) {
mode = "Q65-60" + modeToken.back();
} else {
return false;
}
spot = {
callsign,
locator,
-10,
static_cast<Radio::Frequency>(qRound64(frequencyMHz * 1000000)),
mode,
spotTime
};
return true;
}
}
namespace Map65PSKReporter
{
bool isValidMap65Callsign(QString const& callsign)
{
return LiveCQ::isValidCallsign(callsign);
}
QList<PSKReporterIPFIX::Spot> parseMap65PSKReporterSpots(
QStringList const& decodeLines,
QString const& receiverCallsign,
QString const& receiverLocator,
QDateTime const& nowUtc,
QStringList& seenDecodes)
{
QList<PSKReporterIPFIX::Spot> spots;
for (auto const& line : decodeLines) {
auto const tokens = line.split(' ', Qt::SkipEmptyParts);
if (tokens.size() < 6
|| !isReportableMessageType(tokens.at(5).trimmed())
|| receiverCallsign.length() < 3
|| receiverLocator.length() < 4
|| !seenDecodes.filter(line.left(53)).isEmpty()) {
continue;
}
seenDecodes.append(line);
PSKReporterIPFIX::Spot spot;
if (parseSpot(tokens, receiverCallsign, receiverLocator, nowUtc, spot)) {
spots.append(spot);
}
}
return spots;
}
}
|