summaryrefslogtreecommitdiff
path: root/Decoder/decodedtext.cpp
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
committerhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
commitc25cbdf6fb6d946175f4335fab77bfea601b56db (patch)
tree6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /Decoder/decodedtext.cpp
parent71f5689252c9f13e70e1c24856904475b2307809 (diff)
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'Decoder/decodedtext.cpp')
-rw-r--r--Decoder/decodedtext.cpp55
1 files changed, 46 insertions, 9 deletions
diff --git a/Decoder/decodedtext.cpp b/Decoder/decodedtext.cpp
index 3c684f82..52780e02 100644
--- a/Decoder/decodedtext.cpp
+++ b/Decoder/decodedtext.cpp
@@ -7,6 +7,7 @@
extern "C" {
bool stdmsg_(char const * msg, fortran_charlen_t);
+ bool stdmsg72_(char const * msg, bool * is_jt65, fortran_charlen_t);
}
namespace
@@ -44,6 +45,32 @@ namespace
)?
)"
, QRegularExpression::ExtendedPatternSyntaxOption};
+ QRegularExpression const ap_suffix_re {R"(^(.*?)(?:\?\s)?[aq][0-9].*$)"};
+ QRegularExpression const angle_bracket_re {"[<>]"};
+ QRegularExpression const cq_qrz_re {"^(CQ|QRZ)\\s"};
+ QRegularExpression const grid_re {R"(^(?!RR73$)[A-R]{2}[0-9]{2}(?:[A-X]{2})?$)"};
+}
+
+DecodedMessageFields parseDecodedMessage (QString message)
+{
+ message = message.trimmed ().remove (angle_bracket_re);
+ if (message.startsWith ("TU; ")) message.remove (0, 4);
+ auto const match = tokens_re.match (message);
+ if (!match.hasMatch ()) return {};
+
+ DecodedMessageFields fields;
+ fields.destination = match.captured ("word1");
+ fields.sender = match.captured ("word2");
+ fields.cq = fields.destination == "CQ" || fields.destination == "CQDX"
+ || fields.destination.startsWith ("CQ ");
+ for (auto const& name : {"word3", "word4", "word5"}) {
+ auto const candidate = match.captured (name);
+ if (grid_re.match (candidate).hasMatch ()) {
+ fields.grid = candidate;
+ break;
+ }
+ }
+ return fields;
}
DecodedText::DecodedText (QString const& the_string)
@@ -55,7 +82,7 @@ DecodedText::DecodedText (QString const& the_string)
, is_standard_ {false}
{
// discard appended AP info
- clean_string_.replace (QRegularExpression {R"(^(.*?)(?:\?\s)?[aq][0-9].*$)"}, "\\1");
+ clean_string_.replace (ap_suffix_re, "\\1");
// qDebug () << "DecodedText: the_string:" << the_string << "Nbsp pos:" << the_string.indexOf (QChar::Nbsp);
if (message_.length() >= 1)
@@ -63,13 +90,13 @@ DecodedText::DecodedText (QString const& the_string)
// remove appended confidence (?) and ap designators before truncating the message
message_ = clean_string_.mid (column_qsoText + padding_).trimmed ();
message0_ = message_.left(37);
- message_ = message_.left(37).remove (QRegularExpression {"[<>]"});
+ message_ = message_.left(37).remove (angle_bracket_re);
int i1 = message_.indexOf ('\r');
if (i1 > 0)
{
message_ = message_.left (i1 - 1);
}
- if (message_.contains (QRegularExpression {"^(CQ|QRZ)\\s"}))
+ if (message_.contains (cq_qrz_re))
{
// TODO this magic position 16 is guaranteed to be after the
// last space in a decoded CQ or QRZ message but before any
@@ -80,11 +107,18 @@ DecodedText::DecodedText (QString const& the_string)
// remove DXCC entity and worked B4 status. TODO need a better way to do this
message_ = message_.left (eom_pos + 1);
}
- // stdmsg is a Fortran routine that packs the text, unpacks it
- // and compares the result
auto message_c_string = message0_.toLocal8Bit ();
message_c_string += QByteArray {37 - message_c_string.size (), ' '};
- is_standard_ = stdmsg_(message_c_string.constData(),37);
+ auto const mode = string_.mid (column_mode + padding_, 1);
+ if (mode == "$" || mode == "@" || mode == "#")
+ {
+ bool is_jt65 = mode == "#";
+ is_standard_ = stdmsg72_(message_c_string.constData(), &is_jt65, 37);
+ }
+ else
+ {
+ is_standard_ = stdmsg_(message_c_string.constData(), 37);
+ }
}
};
@@ -107,8 +141,10 @@ QStringList DecodedText::messageWords () const
QString DecodedText::CQersCall() const
{
- QRegularExpression callsign_re {R"(^(CQ|DE|QRZ)(\s?DX|\s([A-Z]{1,4}|\d{3}))?\s(?<callsign>[A-Z0-9/]{2,})(\s[A-R]{2}[0-9]{2})?)"};
- return callsign_re.match (message_).captured ("callsign");
+ auto const fields = parseDecodedMessage (message_);
+ auto const callType = fields.destination.section (' ', 0, 0);
+ return callType == "CQ" || callType == "CQDX" || callType == "DE" || callType == "QRZ"
+ ? fields.sender : QString {};
}
@@ -171,6 +207,7 @@ bool DecodedText::report(QString const& myBaseCall, QString const& dxBaseCall, /
{
offset = 2;
}
+ if (w.size () <= offset + 2) return false;
if (is_standard_ && (w[offset] == myBaseCall
|| w[offset].endsWith ("/" + myBaseCall)
|| w[offset].startsWith (myBaseCall + "/")
@@ -205,7 +242,7 @@ bool DecodedText::report(QString const& myBaseCall, QString const& dxBaseCall, /
// get the first text word, usually the call
QString DecodedText::call() const
{
- return tokens_re.match (message_).captured ("word1");
+ return parseDecodedMessage (message_).destination;
}
// get the second word, most likely the de call and the third word, most likely grid