summaryrefslogtreecommitdiff
path: root/decodedtext.cpp
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2018-02-16 15:17:14 +0000
committerhibby <d@vehibberd.com>2018-02-16 15:17:14 +0000
commit37f727ac0746fd85504aa46c1f023c09b3eff33a (patch)
treec8a7ce04545040a8f161ba279528730bd9a3e6ab /decodedtext.cpp
parentd63dd8d081a6fcd0715cd13f26df59fb831769d2 (diff)
New upstream version 1.8.0+repackupstream/1.8.0+repack
Diffstat (limited to 'decodedtext.cpp')
-rw-r--r--decodedtext.cpp201
1 files changed, 126 insertions, 75 deletions
diff --git a/decodedtext.cpp b/decodedtext.cpp
index 0e90440e..54c56e5f 100644
--- a/decodedtext.cpp
+++ b/decodedtext.cpp
@@ -1,57 +1,114 @@
+#include "decodedtext.h"
+
#include <QStringList>
+#include <QRegularExpression>
#include <QDebug>
-#include "decodedtext.h"
-QString DecodedText::CQersCall()
+extern "C" {
+ bool stdmsg_(char const * msg, bool contest_mode, char const * mygrid, int len_msg, int len_grid);
+}
+
+namespace
{
- // extract the CQer's call TODO: does this work with all call formats?
- int s1 {0};
- int position;
- if ((position = _string.indexOf (" CQ DX ")) >= 0)
- {
- s1 = 7 + position;
- }
- else if ((position = _string.indexOf (" CQ ")) >= 0)
- {
- s1 = 4 + position;
- }
- else if ((position = _string.indexOf (" DE ")) >= 0)
+ QRegularExpression words_re {R"(^(?:(?<word1>(?:CQ|DE|QRZ)(?:\s?DX|\s(?:[A-Z]{2}|\d{3}))|[A-Z0-9/]+)\s)(?:(?<word2>[A-Z0-9/]+)(?:\s(?<word3>[-+A-Z0-9]+)(?:\s(?<word4>(?:OOO|(?!RR73)[A-R]{2}[0-9]{2})))?)?)?)"};
+}
+
+DecodedText::DecodedText (QString const& the_string, bool contest_mode, QString const& my_grid)
+ : string_ {the_string.left (the_string.indexOf (QChar::Nbsp))} // discard appended info
+ , padding_ {string_.indexOf (" ") > 4 ? 2 : 0} // allow for
+ // seconds
+ , contest_mode_ {contest_mode}
+ , message_ {string_.mid (column_qsoText + padding_).trimmed ()}
+ , is_standard_ {false}
+{
+ if (message_.length() >= 1)
{
- s1 = 4 + position;
+ message_ = message_.left (21).remove (QRegularExpression {"[<>]"});
+ int i1 = message_.indexOf ('\r');
+ if (i1 > 0)
+ {
+ message_ = message_.left (i1 - 1);
+ }
+ if (message_.contains (QRegularExpression {"^(CQ|QRZ)\\s"}))
+ {
+ // TODO this magic position 16 is guaranteed to be after the
+ // last space in a decoded CQ or QRZ message but before any
+ // appended DXCC entity name or worked before information
+ auto eom_pos = message_.indexOf (' ', 16);
+ // we always want at least the characters to position 16
+ if (eom_pos < 16) eom_pos = message_.size () - 1;
+ // 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 = message_.toLocal8Bit ();
+ message_c_string += QByteArray {22 - message_c_string.size (), ' '};
+ auto grid_c_string = my_grid.toLocal8Bit ();
+ grid_c_string += QByteArray {6 - grid_c_string.size (), ' '};
+ is_standard_ = stdmsg_ (message_c_string.constData ()
+ , contest_mode_
+ , grid_c_string.constData ()
+ , 22, 6);
}
- else if ((position = _string.indexOf (" QRZ ")) >= 0)
+};
+
+QStringList DecodedText::messageWords () const
+{
+ if (is_standard_)
{
- s1 = 5 + position;
+ // extract up to the first four message words
+ return words_re.match (message_).capturedTexts ();
}
- auto s2 = _string.indexOf (" ", s1);
- return _string.mid (s1, s2 - s1);
+ // simple word split for free text messages
+ auto words = message_.split (' ', QString::SkipEmptyParts);
+ // add whole message as item 0 to mimic RE capture list
+ words.prepend (message_);
+ return words;
+}
+
+QString DecodedText::CQersCall() const
+{
+ QRegularExpression callsign_re {R"(^(CQ|DE|QRZ)(\s?DX|\s([A-Z]{2}|\d{3}))?\s(?<callsign>[A-Z0-9/]{2,})(\s[A-R]{2}[0-9]{2})?)"};
+ return callsign_re.match (message_).captured ("callsign");
}
-bool DecodedText::isJT65()
+bool DecodedText::isJT65() const
{
- return _string.indexOf("#") == column_mode;
+ return string_.indexOf("#") == column_mode + padding_;
}
-bool DecodedText::isJT9()
+bool DecodedText::isJT9() const
{
- return _string.indexOf("@") == column_mode;
+ return string_.indexOf("@") == column_mode + padding_;
}
-bool DecodedText::isTX()
+bool DecodedText::isTX() const
{
- int i = _string.indexOf("Tx");
+ int i = string_.indexOf("Tx");
return (i >= 0 && i < 15); // TODO guessing those numbers. Does Tx ever move?
}
-int DecodedText::frequencyOffset()
+bool DecodedText::isLowConfidence () const
+{
+ return QChar {'?'} == string_.mid (padding_ + column_qsoText + 21, 1);
+}
+
+int DecodedText::frequencyOffset() const
{
- return _string.mid(column_freq,4).toInt();
+ return string_.mid(column_freq + padding_,4).toInt();
}
-int DecodedText::snr()
+int DecodedText::snr() const
{
- return _string.mid(column_snr,3).toInt();
+ int i1=string_.indexOf(" ")+1;
+ return string_.mid(i1,3).toInt();
+}
+
+float DecodedText::dt() const
+{
+ return string_.mid(column_dt + padding_,5).toFloat();
}
/*
@@ -64,72 +121,66 @@ int DecodedText::snr()
*/
// find and extract any report. Returns true if this is a standard message
-bool DecodedText::report(QString const& myBaseCall, QString const& dxBaseCall, /*mod*/QString& report)
-{
- QString msg=_string.mid(column_qsoText);
- int i1=msg.indexOf("\r");
- if (i1>0)
- msg=msg.mid(0,i1-1) + " ";
- bool b = stdmsg_(msg.mid(0,22).toLatin1().constData(),22); // stdmsg is a fortran routine that packs the text, unpacks it and compares the result
-
- QStringList w=msg.split(" ",QString::SkipEmptyParts);
- if(b && (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 + "/")))))
+bool DecodedText::report(QString const& myBaseCall, QString const& dxBaseCall, /*mod*/QString& report) const
+{
+ if (message_.size () < 1) return false;
+
+ QStringList const& w = message_.split(" ",QString::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 + "/")))))
{
- QString tt="";
- if(w.size() > 2) tt=w[2];
- bool ok;
- i1=tt.toInt(&ok);
- if (ok and i1>=-50 and i1<50)
+ QString tt="";
+ if(w.size() > 2) tt=w[2];
+ bool ok;
+ auto i1=tt.toInt(&ok);
+ if (ok and i1>=-50 and i1<50)
{
- report = tt;
-// qDebug() << "report for " << _string << "::" << report;
+ report = tt;
}
- else
+ else
{
- if (tt.mid(0,1)=="R")
+ if (tt.mid(0,1)=="R")
{
- i1=tt.mid(1).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.mid(1);
-// qDebug() << "report for " << _string << "::" << report;
+ report = tt.mid(1);
}
}
}
}
- return b;
+ return is_standard_;
}
// get the first text word, usually the call
-QString DecodedText::call()
+QString DecodedText::call() const
{
- auto call = _string;
- call = call.replace (" CQ DX ", " CQ_DX ").mid (column_qsoText);
- int i = call.indexOf(" ");
- return call.mid(0,i);
+ return words_re.match (message_).captured ("word1");
}
// get the second word, most likely the de call and the third word, most likely grid
-void DecodedText::deCallAndGrid(/*out*/QString& call, QString& grid)
+void DecodedText::deCallAndGrid(/*out*/QString& call, QString& grid) const
{
- auto msg = _string;
- msg = msg.replace (" CQ DX ", " CQ_DX ").mid (column_qsoText);
- int i1 = msg.indexOf(" ");
- call = msg.mid(i1+1);
- int i2 = call.indexOf(" ");
- grid = call.mid(i2+1,4);
- call = call.mid(0,i2);
+ auto const& match = words_re.match (message_);
+ call = match.captured ("word2");
+ grid = match.captured ("word3");
+ if (contest_mode_ && "R" == grid)
+ {
+ grid = match.captured ("word4");
+ }
}
-int DecodedText::timeInSeconds()
+unsigned DecodedText::timeInSeconds() const
{
- return 60*_string.mid(column_time,2).toInt() + _string.mid(2,2).toInt();
+ return 3600 * string_.mid (column_time, 2).toUInt ()
+ + 60 * string_.mid (column_time + 2, 2).toUInt()
+ + (padding_ ? string_.mid (column_time + 2 + padding_, 2).toUInt () : 0U);
}
/*
@@ -141,7 +192,7 @@ int DecodedText::timeInSeconds()
0605 Tx 1259 # CQ VK3ACF QF22
*/
-QString DecodedText::report() // returns a string of the SNR field with a leading + or - followed by two digits
+QString DecodedText::report() const // returns a string of the SNR field with a leading + or - followed by two digits
{
int sr = snr();
if (sr<-50)