summaryrefslogtreecommitdiff
path: root/logbook/AD1CCty.cpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2025-09-15 23:04:33 +0200
committerChristoph Berg <myon@debian.org>2025-09-15 23:04:33 +0200
commite1c678ef00f0159bbeb5571e5ebb0d4697121334 (patch)
tree6547edef81a62a812a4d0f64e03fda226b5f0a7e /logbook/AD1CCty.cpp
parentb9daa22c4c3ad51cd4bc0ef624a19f21d01c9305 (diff)
parent0a13f1fdb9928b6d012569dd65f7f6ef18fac2f8 (diff)
Update upstream source from tag 'upstream/3.0.0_rc1+repack'
Update to upstream version '3.0.0~rc1+repack' with Debian dir 68c212e23136fecf9ebc6f12ff355579224d27ee
Diffstat (limited to 'logbook/AD1CCty.cpp')
-rwxr-xr-xlogbook/AD1CCty.cpp252
1 files changed, 197 insertions, 55 deletions
diff --git a/logbook/AD1CCty.cpp b/logbook/AD1CCty.cpp
index 222a4b5a..dc1a4701 100755
--- a/logbook/AD1CCty.cpp
+++ b/logbook/AD1CCty.cpp
@@ -16,9 +16,11 @@
#include <QTextStream>
#include <QDebug>
#include <QDebugStateSaver>
+#include <QRegularExpression>
#include "Configuration.hpp"
#include "Radio.hpp"
#include "pimpl_impl.hpp"
+#include "Logger.hpp"
#include "moc_AD1CCty.cpp"
@@ -27,6 +29,8 @@ using namespace boost::multi_index;
namespace
{
auto const file_name = "cty.dat";
+ auto const grid_file_name = "grid.dat"; // NJ0A
+// auto const logFileName = "wsjtx_log.adi"; // NJ0A
}
struct entity
@@ -68,6 +72,13 @@ struct entity
QString primary_prefix_;
};
+#define maxPrefix 25 //NJ0A
+#define maxIndex 100 //NJ0A
+
+QString gridPrefix [maxPrefix]; //NJ0A
+QString gridState [maxPrefix] [maxIndex]; //NJ0A
+int gridNumPrefix; //NJ0A
+
#if !defined (QT_NO_DEBUG_STREAM)
QDebug operator << (QDebug dbg, entity const& e)
{
@@ -163,6 +174,9 @@ public:
{
}
+ QString get_cty_path(const Configuration *configuration);
+ void load_cty(QFile &file);
+
entity_by_id::iterator lookup_entity (QString call, prefix const& p) const
{
call = call.toUpper ();
@@ -228,6 +242,9 @@ public:
Configuration const * configuration_;
QString path_;
+ QString cty_version_;
+ QString cty_version_date_;
+
entities_type entities_;
prefixes_type prefixes_;
};
@@ -314,6 +331,80 @@ char const * AD1CCty::continent (Continent c)
}
}
+QString AD1CCty::impl::get_cty_path(Configuration const * configuration)
+{
+ QDir dataPath {QStandardPaths::writableLocation (QStandardPaths::DataLocation)};
+ auto path = dataPath.exists (file_name)
+ ? dataPath.absoluteFilePath (file_name) // user override
+ : configuration->data_dir ().absoluteFilePath (file_name); // or original
+ return path;
+}
+
+void AD1CCty::impl::load_cty(QFile &file)
+{
+ QRegularExpression version_pattern{R"(VER\d{8})"};
+ int entity_id = 0;
+ int line_number{0};
+
+ entities_.clear();
+ prefixes_.clear();
+ cty_version_ = QString{};
+ cty_version_date_ = QString{};
+
+ QTextStream in{&file};
+ while (!in.atEnd())
+ {
+ auto const &entity_line = in.readLine();
+ ++line_number;
+ if (!in.atEnd())
+ {
+ auto const &entity_parts = entity_line.split(':');
+ if (entity_parts.size() >= 8)
+ {
+ auto primary_prefix = entity_parts[7].trimmed();
+ bool WAE_only{false};
+ if (primary_prefix.startsWith('*'))
+ {
+ primary_prefix = primary_prefix.mid(1);
+ WAE_only = true;
+ }
+ bool ok1, ok2, ok3, ok4, ok5;
+ entities_.emplace(++entity_id, entity_parts[0].trimmed(), WAE_only, entity_parts[1].trimmed().toInt(&ok1),
+ entity_parts[2].trimmed().toInt(&ok2), continent(entity_parts[3].trimmed()),
+ entity_parts[4].trimmed().toFloat(&ok3), entity_parts[5].trimmed().toFloat(&ok4),
+ static_cast<int> (entity_parts[6].trimmed().toFloat(&ok5) * 60 * 60), primary_prefix);
+ if (!(ok1 && ok2 && ok3 && ok4 && ok5))
+ {
+ throw std::domain_error{"Invalid number in cty.dat line " + boost::lexical_cast<std::string>(line_number)};
+ }
+ QString line;
+ QString detail;
+ do
+ {
+ in.readLineInto(&line);
+ ++line_number;
+ } while (detail += line, !detail.endsWith(';'));
+ for (auto prefix: detail.left(detail.size() - 1).split(','))
+ {
+ prefix = prefix.trimmed();
+ bool exact{false};
+ if (prefix.startsWith('='))
+ {
+ prefix = prefix.mid(1);
+ exact = true;
+ // match version pattern to prefix
+ if (version_pattern.match(prefix).hasMatch())
+ {
+ cty_version_date_ = prefix;
+ }
+ }
+ prefixes_.emplace(prefix, exact, entity_id);
+ }
+ }
+ }
+ }
+}
+
AD1CCty::AD1CCty (Configuration const * configuration)
: m_ {configuration}
{
@@ -321,69 +412,92 @@ AD1CCty::AD1CCty (Configuration const * configuration)
// TODO: G4WJS - consider doing the following asynchronously to
// speed up startup. Not urgent as it takes less than 0.5s on a Core
// i7 reading BIG CTY.DAT.
+ AD1CCty::reload (configuration);
+
+ //NJ0A
+ gridNumPrefix = 0;
+
+ for (int i = 0; i < maxPrefix ; i ++) {
+ for (int j = 0; j < maxIndex; j ++) {
+ gridState[i] [j] = "**";
+ }
+ }
+
QDir dataPath {QStandardPaths::writableLocation (QStandardPaths::DataLocation)};
m_->path_ = dataPath.exists (file_name)
? dataPath.absoluteFilePath (file_name) // user override
: configuration->data_dir ().absoluteFilePath (file_name); // or original
- QFile file {m_->path_};
- if (file.open (QFile::ReadOnly))
+
+ QString path = dataPath.exists (grid_file_name)
+ ? dataPath.absoluteFilePath (grid_file_name) // user override
+ : configuration->data_dir ().absoluteFilePath (grid_file_name); // or original in the resources FS
+
+
+ QFile file1 {path};
+
+ if (file1.open (QFile::ReadOnly))
{
- int entity_id = 0;
- int line_number {0};
- QTextStream in {&file};
- while (!in.atEnd ())
- {
+ int line_number [[maybe_unused]] {0};
+ QTextStream in {&file1};
+ while (!in.atEnd ())
+ {
auto const& entity_line = in.readLine ();
++line_number;
- if (!in.atEnd ())
- {
- auto const& entity_parts = entity_line.split (':');
- if (entity_parts.size () >= 8)
- {
- auto primary_prefix = entity_parts[7].trimmed ();
- bool WAE_only {false};
- if (primary_prefix.startsWith ('*'))
- {
- primary_prefix = primary_prefix.mid (1);
- WAE_only = true;
- }
- bool ok1, ok2, ok3, ok4, ok5;
- m_->entities_.emplace (++entity_id
- , entity_parts[0].trimmed ()
- , WAE_only
- , entity_parts[1].trimmed ().toInt (&ok1)
- , entity_parts[2].trimmed ().toInt (&ok2)
- , continent (entity_parts[3].trimmed ())
- , entity_parts[4].trimmed ().toFloat (&ok3)
- , entity_parts[5].trimmed ().toFloat (&ok4)
- , static_cast<int> (entity_parts[6].trimmed ().toFloat (&ok5) * 60 * 60)
- , primary_prefix);
- if (!(ok1 && ok2 && ok3 && ok4 && ok5))
- {
- throw std::domain_error {"Invalid number in cty.dat line " + boost::lexical_cast<std::string> (line_number)};
- }
- QString line;
- QString detail;
- do
- {
- in.readLineInto (&line);
- ++line_number;
- } while (detail += line, !detail.endsWith (';'));
- for (auto prefix : detail.left (detail.size () - 1).split (','))
- {
- prefix = prefix.trimmed ();
- bool exact {false};
- if (prefix.startsWith ('='))
- {
- prefix = prefix.mid (1);
- exact = true;
- }
- m_->prefixes_.emplace (prefix, exact, entity_id);
+ if (!in.atEnd () && entity_line.length() > 0 && entity_line.contains("<"))
+ {
+ //std::cout << entity_line.toStdString() << '\n';
+ if (entity_line.contains("<")) {
+ auto const& entity_parts = entity_line.split ('<');
+ //std::cout << "Grid prefix: " << entity_parts[0].toStdString() << '\n';
+ gridPrefix[gridNumPrefix] = entity_parts[0];
+ gridNumPrefix++;
+ while (!in.atEnd()) {
+ auto const& entity_grid_line = in.readLine();
+ if (entity_grid_line.length() > 1 &&
+ entity_grid_line.contains(":") &&
+ entity_grid_line.contains(",")) {
+ auto const& entity_parts = entity_grid_line.split(":");
+ //std::cout << "Grid Indxes: " << entity_parts[0].trimmed().toStdString() << " " ;
+
+ auto const& entity_temp = entity_parts[1].split(",");
+ auto const & entity_state = entity_temp[0];
+ //std::cout << "State: " << entity_state.toStdString() << '\n';
+ gridState[gridNumPrefix - 1] [entity_parts[0].toInt()] = entity_state;
+
+ } else if (entity_grid_line.length() > 1 &&
+ entity_grid_line.contains(":") &&
+ entity_grid_line.contains(">")) {
+ auto const& entity_parts = entity_grid_line.split(":");
+ //std::cout << "Grid Indxes: " << entity_parts[0].trimmed().toStdString() << " ";
+
+ auto const& entity_temp = entity_parts[1].split(">");
+ auto const & entity_state = entity_temp[0];
+ //std::cout << "State: " << entity_state.toStdString() << '\n';
+ gridState[gridNumPrefix - 1] [entity_parts[0].toInt()] = entity_state;
+
+ break;
}
}
- }
- }
+ }
+ }
+ }
}
+ }
+
+void AD1CCty::reload(Configuration const * configuration)
+{
+ m_->path_ = m_->impl::get_cty_path(configuration);
+ QFile file {m_->path_};
+
+ LOG_INFO(QString{"Loading CTY.DAT from %1"}.arg (m_->path_));
+
+ if (file.open (QFile::ReadOnly))
+ {
+ m_->impl::load_cty(file);
+ m_->cty_version_ = AD1CCty::lookup("VERSION").entity_name;
+ Q_EMIT cty_loaded(m_->cty_version_);
+ LOG_INFO(QString{"Loaded CTY.DAT version %1, %2"}.arg (m_->cty_version_date_).arg (m_->cty_version_));
+ }
}
AD1CCty::~AD1CCty ()
@@ -410,8 +524,8 @@ auto AD1CCty::lookup (QString const& call) const -> Record
if (p != m_->prefixes_.end ())
{
impl::entity_by_id::iterator e = m_->lookup_entity (call, *p);
- if ((m_->configuration_->include_WAE_entities () || !e->WAE_only_)
- && (!p->exact_ || call.size () == search_prefix.size ()))
+ // always lookup WAE entities, we substitute them later in displaytext.cpp if "Include extra WAE entites" is not selected
+ if (!p->exact_ || call.size () == search_prefix.size ())
{
return m_->fixup (*p, *e);
}
@@ -421,3 +535,31 @@ auto AD1CCty::lookup (QString const& call) const -> Record
}
return Record {};
}
+
+auto AD1CCty::version () const -> QString
+{
+ return m_->cty_version_date_;
+}
+
+// NJ0A
+auto AD1CCty::findState ( QString const& grid) const -> QString
+{
+
+
+ auto const& prefix = grid.left(2);
+ int gridIndex = grid.mid(2,2).toInt();
+ //if (gridIndex < 0 || gridIndex > maxIndex) {
+ //std::cout << "Prefix: " << prefix.toStdString() << " Index " << gridIndex << '\n';
+ //}
+ for (int i = 0; i < gridNumPrefix + 1; i ++) {
+ if (gridPrefix[i] == prefix) {
+ QString state = gridState[i] [gridIndex];
+ //if (state.length() < 2 ) {
+ // std::cout << "Prefix: " << prefix.toStdString() << " Index " << gridIndex << '\n';
+ //}
+ return state;
+ }
+ }
+
+ return "**";
+} // NJ0A