Parse "dx-call-1 RR73; dx-call-2 <de-call> +nn" messages in regular modes

This commit is contained in:
Bill Somerville
2021-10-29 22:27:32 +01:00
parent c0a5bad58a
commit 488c42b8a2
2 changed files with 105 additions and 58 deletions
+56 -23
View File
@@ -11,7 +11,32 @@ extern "C" {
namespace
{
QRegularExpression words_re {R"(^(?:(?<word1>(?:CQ|DE|QRZ)(?:\s?DX|\s(?:[A-Z]{1,4}|\d{3}))|[A-Z0-9/]+|\.{3})\s)(?:(?<word2>[A-Z0-9/]+)(?:\s(?<word3>[-+A-Z0-9]+)(?:\s(?<word4>(?:OOO|(?!RR73)[A-R]{2}[0-9]{2})))?)?)?)"};
QRegularExpression tokens_re {R"(
^
(?:(?<dual>[A-Z0-9/]+)\sRR73;\s)?
(?:
(?<word1>
(?:CQ|DE|QRZ)
(?:\s?DX|\s
(?:[A-Z]{1,4}|\d{3})
)
| [A-Z0-9/]+
|\.{3}
)\s
)
(?:
(?<word2>[A-Z0-9/]+)
(?:\s
(?<word3>[-+A-Z0-9]+)
(?:\s
(?<word4>
(?:OOO | (?!RR73)[A-R]{2}[0-9]{2})
)
)?
)?
)?
)"
, QRegularExpression::ExtendedPatternSyntaxOption};
}
DecodedText::DecodedText (QString const& the_string)
@@ -60,7 +85,9 @@ QStringList DecodedText::messageWords () const
// extract up to the first four message words
QString t=message_;
if(t.left(4)=="TU; ") t=message_.mid(4,-1);
return words_re.match(t).capturedTexts();
auto res = tokens_re.match(t).capturedTexts();
qDebug () << "captured texts:" << res;
return res;
}
// simple word split for free text messages
auto words = message_.split (' ', SkipEmptyParts);
@@ -128,31 +155,37 @@ bool DecodedText::report(QString const& myBaseCall, QString const& dxBaseCall, /
if (message_.size () < 1) return false;
QStringList const& w = message_.split(" ", SkipEmptyParts);
if (w.size ()
&& is_standard_ && (w[0] == myBaseCall
|| w[0].endsWith ("/" + myBaseCall)
|| w[0].startsWith (myBaseCall + "/")
|| (w.size () > 1 && !dxBaseCall.isEmpty ()
&& (w[1] == dxBaseCall
|| w[1].endsWith ("/" + dxBaseCall)
|| w[1].startsWith (dxBaseCall + "/")))))
int offset {0};
if (w.size () > 2)
{
QString tt="";
if(w.size() > 2) tt=w[2];
bool ok;
auto i1=tt.toInt(&ok);
if (ok and i1>=-50 and i1<50)
if ("RR73;" == w[1] && w.size () > 3)
{
report = tt;
offset = 2;
}
else
if (is_standard_ && (w[offset] == myBaseCall
|| w[offset].endsWith ("/" + myBaseCall)
|| w[offset].startsWith (myBaseCall + "/")
|| (w.size () > offset + 1 && !dxBaseCall.isEmpty ()
&& (w[offset + 1] == dxBaseCall
|| w[offset + 1].endsWith ("/" + dxBaseCall)
|| w[offset + 1].startsWith (dxBaseCall + "/")))))
{
if (tt.mid(0,1)=="R")
bool ok;
auto tt = w[offset + 2];
auto i1=tt.toInt(&ok);
if (ok and i1>=-50 and i1<50)
{
i1=tt.mid(1).toInt(&ok);
if(ok and i1>=-50 and i1<50)
report = tt;
}
else
{
if (tt.mid(0,1)=="R")
{
report = tt.mid(1);
i1=tt.mid(1).toInt(&ok);
if(ok and i1>=-50 and i1<50)
{
report = tt.mid(1);
}
}
}
}
@@ -163,7 +196,7 @@ bool DecodedText::report(QString const& myBaseCall, QString const& dxBaseCall, /
// get the first text word, usually the call
QString DecodedText::call() const
{
return words_re.match (message_).captured ("word1");
return tokens_re.match (message_).captured ("word1");
}
// get the second word, most likely the de call and the third word, most likely grid
@@ -175,7 +208,7 @@ void DecodedText::deCallAndGrid(/*out*/QString& call, QString& grid) const
{
msg = msg.mid (p + 2);
}
auto const& match = words_re.match (msg);
auto const& match = tokens_re.match (msg);
call = match.captured ("word2");
grid = match.captured ("word3");
if ("R" == grid) grid = match.captured ("word4");