From de0a3d60e3515a083a15c9810696f305f10c108a Mon Sep 17 00:00:00 2001 From: Uwe Risse Date: Thu, 9 Mar 2023 18:04:46 +0100 Subject: [PATCH] Preparations for the HamSCI Festivals of Eclipse Ionospheric Science. --- CMakeLists.txt | 1 + Network/PSKReporter.cpp | 71 +++++++++++++++++++++++++++++++++++++++-- Network/PSKReporter.hpp | 4 +++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f641f6445..76c0e836b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1641,6 +1641,7 @@ install (FILES cty.dat cty.dat_copyright.txt contrib/Ephemeris/JPLEPH + eclipse.txt DESTINATION ${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME} #COMPONENT runtime ) diff --git a/Network/PSKReporter.cpp b/Network/PSKReporter.cpp index 8f442eb0f..f3cb2a757 100644 --- a/Network/PSKReporter.cpp +++ b/Network/PSKReporter.cpp @@ -6,9 +6,8 @@ // // Reports will be sent in batch mode every 5 minutes. -#ifdef DEBUGPSK #include -#endif +#include #include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) #include #endif @@ -91,6 +91,7 @@ public: send_receiver_data_ = 3; // three times } }); + eclipse_load(config->data_dir ().absoluteFilePath ("eclipse.txt")); } void check_connection () @@ -196,6 +197,8 @@ public: void send_report (bool send_residue = false); void build_preamble (QDataStream&); + void eclipse_load(QString filename); + bool eclipse_active(QDateTime now = QDateTime::currentDateTime()); bool flushing () { @@ -204,6 +207,14 @@ public: return flush; } + QString getStringFromQDateTime(const QString& dateTimeString, const QString& format) + { + QDateTime dateTime = QDateTime::fromString(dateTimeString, format); + return dateTime.toString(); + } + + QList eclipseDates; + logger_type mutable logger_; PSKReporter * self_; Configuration const * config_; @@ -280,6 +291,52 @@ namespace } } +bool PSKReporter::impl::eclipse_active(QDateTime now) +{ + for (int i=0; i< eclipseDates.size(); ++i) + { + QDateTime check = eclipseDates.at(i); + // +- 6 hour window + QDateTime date1 = check.addSecs(-3600*6); + QDateTime date2 = check.addSecs( 3600*6); + if (now > date1 && now < date2) + { + return true; + } + } + return false; +} + +void PSKReporter::impl::eclipse_load(QString eclipse_file) +{ + std::ifstream fs(qPrintable(eclipse_file)); + std::string mydate,mytime,myline; +#ifdef DEBUGECLIPSE + std::ofstream mylog("eclipse.log"); + mylog << "eclipse_file=" << eclipse_file << std::endl; +#endif + if (fs.is_open()) + { + while(!fs.eof()) + { + std::getline(fs, myline); + if (myline[0] != '#') + { + QString format = "yyyy-MM-dd hh:mm:ss"; + QDateTime qdate = QDateTime::fromString(QString::fromStdString(myline), format); + eclipseDates.append(qdate); + } +#ifdef DEBUGECLIPSE + mylog << myline << std::endl; +#endif + } + } +#ifdef DEBUGECLIPSE + if (eclipse_active(QDateTime::currentDateTime())) mylog << "Eclipse is active" << std::endl; + else mylog << "Eclipse is not active" << std::endl; +#endif +} + void PSKReporter::impl::build_preamble (QDataStream& message) { // Message Header @@ -524,6 +581,11 @@ void PSKReporter::reconnect () m_->reconnect (); } +bool PSKReporter::eclipse_active(QDateTime now) +{ + return m_->eclipse_active(now); +} + void PSKReporter::setLocalStation (QString const& call, QString const& gridSquare, QString const& antenna) { LOG_LOG_LOCATION (m_->logger_, trace, "call: " << call << " grid: " << gridSquare << " ant: " << antenna); @@ -556,7 +618,10 @@ bool PSKReporter::addRemoteStation (QString const& call, QString const& grid, Ra if (!fs.is_open()) fs.open("/temp/psk.log", std::fstream::in | std::fstream::out | std::fstream::app); #endif added++; - if (!spot_cache.contains(call) || freq > 49000000) // then it's a new spot + + QDateTime qdateNow = QDateTime::currentDateTime(); + // we allow all spots through +/- 6 hours around an eclipse for the HamSCI group + if (!spot_cache.contains(call) || freq > 49000000 || eclipse_active(qdateNow)) // then it's a new spot { m_->spots_.enqueue ({call, grid, snr, freq, mode, QDateTime::currentDateTimeUtc ()}); spot_cache.insert(call, time(NULL)); diff --git a/Network/PSKReporter.hpp b/Network/PSKReporter.hpp index 1757e63af..74c08bdb8 100644 --- a/Network/PSKReporter.hpp +++ b/Network/PSKReporter.hpp @@ -31,6 +31,10 @@ public: // void sendReport (bool last = false); + // + // True if current time falls withing a +/- window of a solar eclipse for HamSCI use + bool eclipse_active(QDateTime now); + Q_SIGNAL void errorOccurred (QString const& reason); private: