diff options
| author | Christoph Berg <myon@debian.org> | 2025-09-15 23:04:33 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2025-09-15 23:04:33 +0200 |
| commit | e1c678ef00f0159bbeb5571e5ebb0d4697121334 (patch) | |
| tree | 6547edef81a62a812a4d0f64e03fda226b5f0a7e /Network | |
| parent | b9daa22c4c3ad51cd4bc0ef624a19f21d01c9305 (diff) | |
| parent | 0a13f1fdb9928b6d012569dd65f7f6ef18fac2f8 (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 'Network')
| -rwxr-xr-x | Network/Cloudlog.cpp | 174 | ||||
| -rwxr-xr-x | Network/Cloudlog.hpp | 36 | ||||
| -rwxr-xr-x | Network/FileDownload.cpp | 229 | ||||
| -rwxr-xr-x | Network/FileDownload.hpp | 54 | ||||
| -rwxr-xr-x | Network/FoxVerifier.cpp | 125 | ||||
| -rwxr-xr-x | Network/FoxVerifier.hpp | 63 | ||||
| -rwxr-xr-x | Network/LotWUsers.cpp | 179 | ||||
| -rwxr-xr-x | Network/LotWUsers.hpp | 1 | ||||
| -rwxr-xr-x | Network/MessageClient.cpp | 23 | ||||
| -rwxr-xr-x | Network/MessageClient.hpp | 6 | ||||
| -rwxr-xr-x | Network/Network.pri | 21 | ||||
| -rwxr-xr-x | Network/NetworkMessage.hpp | 37 | ||||
| -rwxr-xr-x | Network/PSKReporter.cpp | 148 | ||||
| -rwxr-xr-x | Network/PSKReporter.hpp | 6 |
14 files changed, 948 insertions, 154 deletions
diff --git a/Network/Cloudlog.cpp b/Network/Cloudlog.cpp new file mode 100755 index 00000000..3f642a60 --- /dev/null +++ b/Network/Cloudlog.cpp @@ -0,0 +1,174 @@ +#include "Cloudlog.hpp"
+
+#include <future>
+#include <chrono>
+
+#include <QHash>
+#include <QString>
+#include <QDate>
+#include <QFile>
+#include <QTextStream>
+#include <QDir>
+#include <QFileInfo>
+#include <QPointer>
+#include <QSaveFile>
+#include <QUrl>
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+#include <QDebug>
+#include <QMessageBox>
+#include <QIcon>
+#include <QJsonDocument>
+#include <QJsonObject>
+
+#include "pimpl_impl.hpp"
+
+#include "moc_Cloudlog.cpp"
+
+#include "Configuration.hpp"
+
+namespace
+{
+ // Dictionary mapping call sign to date of last upload to LotW
+ using dictionary = QHash<QString, QDate>;
+}
+
+class Cloudlog::impl final
+ : public QObject
+{
+ Q_OBJECT
+
+public:
+ impl (Cloudlog * self, Configuration const * config, QNetworkAccessManager * network_manager)
+ : self_ {self}
+ , config_ {config}
+ , network_manager_ {network_manager}
+ {
+ }
+
+ void logQso (QByteArray ADIF)
+ {
+ QByteArray data;
+
+ QString str = QString("") +
+ "{" +
+ "\"key\":\""+ config_->cloudlog_api_key() +"\"," +
+ "\"station_profile_id\":\""+ QVariant(config_->cloudlog_api_station_id()).toString() +"\"," +
+ "\"type\":\"adif\"," +
+ "\"string\":\"" + ADIF + "<eor>" + "\"" +
+ "}";
+ data = str.toUtf8();
+
+ QUrl u = QUrl(config_->cloudlog_api_url()+"/index.php/api/qso");
+
+ QNetworkRequest request(u);
+ request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
+ reply_ = network_manager_->post(request, data);
+ connect (reply_.data (), &QNetworkReply::finished, this, &Cloudlog::impl::reply_logqso);
+
+ }
+
+ void testApi (QString const& url, QString const& apiKey)
+ {
+ QString apiUrl = url;
+#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
+ if (QNetworkAccessManager::Accessible != network_manager_->networkAccessible ())
+ {
+ // try and recover network access for QNAM
+ network_manager_->setNetworkAccessible (QNetworkAccessManager::Accessible);
+ }
+#endif
+
+ // Remove trailing slash if given
+ if (apiUrl.endsWith('/')) {
+ apiUrl.remove(-1, 1);
+ }
+ // Remove full path to API if given
+ if (apiUrl.endsWith("/index.php/api/qso")) {
+ apiUrl.remove(-18, 18);
+ }
+
+ QNetworkRequest request {apiUrl+"/index.php/api/auth/"+apiKey};
+ request.setRawHeader ("User-Agent", "WSJT-X Cloudlog API");
+ request.setOriginatingObject (this);
+ reply_ = network_manager_->get (request);
+ connect (reply_.data (), &QNetworkReply::finished, this, &Cloudlog::impl::reply_apitest);
+ }
+
+ void reply_apitest()
+ {
+ QString result;
+ if (reply_ && reply_->isFinished ())
+ {
+ result = reply_->readAll();
+ if (result.contains("<status>Valid</status>"))
+ {
+ if (result.contains("<rights>rw</rights>"))
+ {
+ // fprintf(stderr, "API key OK\n");
+ Q_EMIT self_->apikey_ok ();
+ } else {
+ // fprintf(stderr, "API key not writable!\n");
+ Q_EMIT self_->apikey_ro ();
+ }
+ } else {
+ // fprintf(stderr, "API key invalid!\n");
+ Q_EMIT self_->apikey_invalid ();
+ }
+ }
+ }
+
+ void reply_logqso()
+ {
+ QString result;
+ if (reply_ && reply_->isFinished ())
+ {
+ result = reply_->readAll();
+ QJsonDocument data = QJsonDocument::fromJson(result.toUtf8());
+ QJsonObject obj = data.object();
+ if (obj["status"] == "failed") {
+ QMessageBox msgBox;
+ msgBox.setIcon(QMessageBox::Warning);
+ msgBox.setWindowTitle("Cloudlog Error!");
+ msgBox.setText("QSO could not be sent to Cloudlog!\nPlease check your log.");
+ msgBox.setDetailedText("Reason: "+obj["reason"].toString());
+ msgBox.exec();
+ }
+ }
+ }
+
+ void abort ()
+ {
+ if (reply_ && reply_->isRunning ())
+ {
+ reply_->abort ();
+ }
+ }
+
+ Cloudlog * self_;
+ Configuration const * config_;
+ QNetworkAccessManager * network_manager_;
+ QPointer<QNetworkReply> reply_;
+};
+
+#include "Cloudlog.moc"
+
+Cloudlog::Cloudlog (Configuration const * config, QNetworkAccessManager * network_manager, QObject * parent)
+ : QObject {parent}
+ , m_ {this, config, network_manager}
+{
+}
+
+Cloudlog::~Cloudlog ()
+{
+}
+
+void Cloudlog::testApi (QString const& url, QString const& apiKey)
+{
+ m_->testApi (url, apiKey);
+}
+
+void Cloudlog::logQso (QByteArray ADIF)
+{
+ m_->logQso(ADIF);
+}
diff --git a/Network/Cloudlog.hpp b/Network/Cloudlog.hpp new file mode 100755 index 00000000..c35f7947 --- /dev/null +++ b/Network/Cloudlog.hpp @@ -0,0 +1,36 @@ +#ifndef CLOUDLOG_HPP_
+#define CLOUDLOG_HPP_
+
+#include <boost/core/noncopyable.hpp>
+#include <QObject>
+#include "pimpl_h.hpp"
+
+class QString;
+class QNetworkAccessManager;
+class Configuration;
+
+//
+// Cloudlog
+//
+class Cloudlog final
+ : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit Cloudlog (Configuration const *, QNetworkAccessManager *, QObject * parent = 0);
+ ~Cloudlog ();
+
+ void logQso(QByteArray ADIF);
+ Q_SLOT void testApi (QString const& url, QString const& apiKey);
+
+ Q_SIGNAL void apikey_ok () const;
+ Q_SIGNAL void apikey_ro () const;
+ Q_SIGNAL void apikey_invalid () const;
+
+private:
+ class impl;
+ pimpl<impl> m_;
+};
+
+#endif
diff --git a/Network/FileDownload.cpp b/Network/FileDownload.cpp new file mode 100755 index 00000000..7647dab5 --- /dev/null +++ b/Network/FileDownload.cpp @@ -0,0 +1,229 @@ +
+#include "FileDownload.hpp"
+#include <QCoreApplication>
+#include <QUrl>
+#include <QNetworkRequest>
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+#include <QFileInfo>
+#include <QDir>
+#include <QIODevice>
+#include "qt_helpers.hpp"
+#include "Logger.hpp"
+
+FileDownload::FileDownload() : QObject(nullptr)
+{
+ redirect_count_ = 0;
+ url_valid_ = false;
+}
+
+FileDownload::~FileDownload()
+{
+}
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+void FileDownload::errorOccurred(QNetworkReply::NetworkError code)
+{
+ LOG_INFO(QString{"FileDownload [%1]: errorOccurred %2 -> %3"}.arg(user_agent_).arg(code).arg(reply_->errorString()));
+ Q_EMIT error (reply_->errorString ());
+ destfile_.cancelWriting ();
+ destfile_.commit ();
+}
+#else
+void FileDownload::obsoleteError()
+{
+ LOG_INFO(QString{"FileDownload [%1]: error -> %3"}.arg(user_agent_).arg(reply_->errorString()));
+ Q_EMIT error (reply_->errorString ());
+ destfile_.cancelWriting ();
+ destfile_.commit ();
+}
+#endif
+
+void FileDownload::configure(QNetworkAccessManager *network_manager, const QString &source_url, const QString &destination_path, const QString &user_agent)
+{
+ manager_ = network_manager;
+ source_url_ = source_url;
+ destination_filename_ = destination_path;
+ user_agent_ = user_agent;
+}
+
+void FileDownload::store()
+{
+ if (destfile_.isOpen())
+ destfile_.write (reply_->read (reply_->bytesAvailable ()));
+ else
+ LOG_INFO(QString{ "FileDownload [%1]: file is not open."}.arg(user_agent_));
+}
+
+void FileDownload::replyComplete()
+{
+ QFileInfo destination_file(destination_filename_);
+ QDir tmpdir_(destination_file.absoluteFilePath());
+
+ LOG_DEBUG(QString{ "FileDownload [%1]: replyComplete"}.arg(user_agent_));
+ if (!reply_)
+ {
+ Q_EMIT load_finished ();
+ return; // we probably deleted it in an earlier call
+ }
+
+ QUrl redirect_url {reply_->attribute (QNetworkRequest::RedirectionTargetAttribute).toUrl ()};
+
+ if (reply_->error () == QNetworkReply::NoError && !redirect_url.isEmpty ())
+ {
+ if ("https" == redirect_url.scheme () && !QSslSocket::supportsSsl ())
+ {
+ Q_EMIT download_error (tr ("Network Error - SSL/TLS support not installed, cannot fetch:\n\'%1\'")
+ .arg (redirect_url.toDisplayString ()));
+ url_valid_ = false; // reset
+ Q_EMIT load_finished ();
+ }
+ else if (++redirect_count_ < 10) // maintain sanity
+ {
+ // follow redirect
+ download (reply_->url ().resolved (redirect_url));
+ }
+ else
+ {
+ Q_EMIT download_error (tr ("Network Error - Too many redirects:\n\'%1\'")
+ .arg (redirect_url.toDisplayString ()));
+ url_valid_ = false; // reset
+ Q_EMIT load_finished ();
+ }
+ }
+ else if (reply_->error () != QNetworkReply::NoError)
+ {
+ destfile_.cancelWriting();
+ destfile_.commit();
+ url_valid_ = false; // reset
+ // report errors that are not due to abort
+ if (QNetworkReply::OperationCanceledError != reply_->error ())
+ {
+ Q_EMIT download_error (tr ("Network Error:\n%1")
+ .arg (reply_->errorString ()));
+ }
+ Q_EMIT load_finished ();
+ }
+ else
+ {
+ if (!url_valid_)
+ {
+ // now get the body content
+ url_valid_ = true;
+ download (reply_->url ().resolved (redirect_url));
+ }
+ else // the body has completed. Save it.
+ {
+ url_valid_ = false; // reset
+ // load the database asynchronously
+ // future_load_ = std::async (std::launch::async, &LotWUsers::impl::load_dictionary, this, csv_file_.fileName ());
+ LOG_INFO(QString{ "FileDownload [%1]: complete. File path is %2"}.arg(user_agent_).arg(destfile_.fileName()));
+ destfile_.commit();
+ emit complete(destination_filename_);
+ }
+ }
+
+ if (reply_ && reply_->isFinished ())
+ {
+ reply_->deleteLater ();
+ }
+
+}
+
+void FileDownload::downloadComplete(QNetworkReply *data)
+{
+ // make a temp file in the same place as the file we're downloading. Needs to be on the same
+ // filesystem as where we eventually want to 'mv' it.
+
+ QUrl r = request_.url();
+ LOG_INFO(QString{"FileDownload [%1]: finished %2 of %3 -> %4 (%5)"}.arg(user_agent_).arg(data->operation()).arg(source_url_).arg(destination_filename_).arg(r.url()));
+
+#ifdef DEBUG_FILEDOWNLOAD
+ LOG_INFO("Request Headers:");
+ Q_FOREACH (const QByteArray& hdr, request_.rawHeaderList()) {
+ LOG_INFO(QString{ "%1 -> %2"}.arg(QString(hdr)).arg(QString(request_.rawHeader(hdr))));
+ }
+
+ LOG_INFO("Response Headers:");
+ Q_FOREACH (const QByteArray& hdr, reply_->rawHeaderList()) {
+ LOG_INFO(QString{ "%1 -> %2"}.arg(QString(hdr)).arg(QString(reply_->rawHeader(hdr))));
+ }
+#endif
+ data->deleteLater();
+}
+
+void FileDownload::start_download()
+{
+ url_valid_ = false;
+ download(QUrl(source_url_));
+}
+
+void FileDownload::download(QUrl qurl)
+{
+ request_.setUrl(qurl);
+
+#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
+ if (QNetworkAccessManager::Accessible != manager_->networkAccessible ())
+ {
+ // try and recover network access for QNAM
+ manager_->setNetworkAccessible (QNetworkAccessManager::Accessible);
+ }
+#endif
+
+ LOG_INFO(QString{"FileDownload [%1]: Starting download of %2 to %3"}.arg(user_agent_).arg(source_url_).arg(destination_filename_));
+
+ request_.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
+ request_.setRawHeader("Accept", "*/*");
+ request_.setRawHeader ("User-Agent", user_agent_.toLocal8Bit()); // Must have a UA for some sites, like country-files
+
+ if (!url_valid_)
+ {
+ reply_ = manager_->head(request_);
+ }
+ else
+ {
+ reply_ = manager_->get (request_);
+ }
+
+ QObject::connect(manager_, &QNetworkAccessManager::finished, this, &FileDownload::downloadComplete, Qt::UniqueConnection);
+ QObject::connect(reply_, &QNetworkReply::downloadProgress, this, &FileDownload::downloadProgress, Qt::UniqueConnection);
+ QObject::connect(reply_, &QNetworkReply::finished, this, &FileDownload::replyComplete, Qt::UniqueConnection);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+ QObject::connect(reply_, &QNetworkReply::errorOccurred,this, &FileDownload::errorOccurred, Qt::UniqueConnection);
+#else
+ QObject::connect(reply_, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &FileDownload::obsoleteError, Qt::UniqueConnection);
+#endif
+ QObject::connect(reply_, &QNetworkReply::readyRead, this, &FileDownload::store, Qt::UniqueConnection);
+
+ QFileInfo destination_file(destination_filename_);
+ QString const tmpfile_base = destination_file.fileName();
+ QString const &tmpfile_path = destination_file.absolutePath();
+ QDir tmpdir{};
+ if (!tmpdir.mkpath(tmpfile_path))
+ {
+ LOG_INFO(QString{"FileDownload [%1]: Directory %2 does not exist"}.arg(user_agent_).arg(tmpfile_path).arg(
+ destfile_.errorString()));
+ }
+
+ if (url_valid_) {
+ destfile_.setFileName(destination_file.absoluteFilePath());
+ if (!destfile_.open(QSaveFile::WriteOnly | QIODevice::WriteOnly)) {
+ LOG_INFO(QString{"FileDownload [%1]: Unable to open %2: %3"}.arg(user_agent_).arg(destfile_.fileName()).arg(
+ destfile_.errorString()));
+ return;
+ }
+ }
+}
+
+void FileDownload::downloadProgress(qint64 received, qint64 total)
+{
+ LOG_DEBUG(QString{"FileDownload: [%1] Progress %2 from %3, total %4, so far %5"}.arg(user_agent_).arg(destination_filename_).arg(source_url_).arg(total).arg(received));
+ Q_EMIT progress(QString{"%4 bytes downloaded"}.arg(received));
+}
+
+void FileDownload::abort ()
+{
+ if (reply_ && reply_->isRunning ())
+ {
+ reply_->abort ();
+ }
+}
diff --git a/Network/FileDownload.hpp b/Network/FileDownload.hpp new file mode 100755 index 00000000..140283c3 --- /dev/null +++ b/Network/FileDownload.hpp @@ -0,0 +1,54 @@ +#ifndef WSJTX_FILEDOWNLOAD_H
+#define WSJTX_FILEDOWNLOAD_H
+
+#include <QObject>
+#include <QString>
+#include <QPointer>
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+#include <QTemporaryFile>
+#include <QSaveFile>
+
+class FileDownload : public QObject {
+ Q_OBJECT
+
+public:
+ explicit FileDownload();
+ ~FileDownload();
+
+ void configure(QNetworkAccessManager *network_manager, const QString& source_url, const QString& destination_filename, const QString& user_agent);
+
+private:
+ QNetworkAccessManager *manager_;
+ QString source_url_;
+ QString destination_filename_;
+ QString user_agent_;
+ QPointer<QNetworkReply> reply_;
+ QNetworkRequest request_;
+ QSaveFile destfile_;
+ bool url_valid_;
+ int redirect_count_;
+signals:
+ void complete(QString filename);
+ void progress(QString filename);
+ void load_finished() const;
+ void download_error (QString const& reason) const;
+ void error(QString const& reason) const;
+
+
+public slots:
+ void start_download();
+ void download(QUrl url);
+ void store();
+ void abort();
+ void downloadComplete(QNetworkReply* data);
+ void downloadProgress(qint64 recieved, qint64 total);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+ void errorOccurred(QNetworkReply::NetworkError code);
+#else
+ void obsoleteError();
+#endif
+ void replyComplete();
+};
+
+#endif //WSJTX_FILEDOWNLOAD_H
diff --git a/Network/FoxVerifier.cpp b/Network/FoxVerifier.cpp new file mode 100755 index 00000000..2882f34a --- /dev/null +++ b/Network/FoxVerifier.cpp @@ -0,0 +1,125 @@ +#include "FoxVerifier.hpp"
+#include "Logger.hpp"
+
+FoxVerifier::FoxVerifier(QString user_agent, QNetworkAccessManager *manager,QString base_url, QString callsign, QDateTime timestamp, QString code, unsigned int hz=750) : QObject(nullptr)
+{
+ manager_ = manager;
+ finished_ = false;
+ errored_ = false;
+ callsign_ = callsign;
+ code_ = code;
+ ts_ = timestamp;
+ hz_ = hz;
+
+ // make sure we URLencode the callsign, for things like E51D/MM
+ QString encodedCall = QString::fromUtf8(QUrl::toPercentEncoding(callsign));
+ QString url = QString("%1/check/").arg(base_url) + encodedCall + QString("/%1/%2.text").arg(timestamp.toString(Qt::ISODate)).arg(code);
+ LOG_INFO(QString("FoxVerifier: url %1").arg(url).toStdString());
+ q_url_ = QUrl(url);
+ if (manager_ == nullptr) {
+ LOG_INFO("FoxVerifier: manager is null, creating new one");
+ manager_ = new QNetworkAccessManager(this);
+ manager_->deleteLater();
+ }
+ if (q_url_.isValid()) {
+ request_ = QNetworkRequest(q_url_);
+ request_.setRawHeader( "User-Agent" , user_agent.toUtf8());
+ request_.setRawHeader( "Accept" , "*/*" );
+ request_.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
+
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+ request_.setTransferTimeout(FOXVERIFIER_DEFAULT_TIMEOUT_MSEC);
+#endif
+
+ reply_ = manager_->get(request_);
+ connect(reply_, &QNetworkReply::finished, this, &FoxVerifier::httpFinished);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+ connect(reply_, &QNetworkReply::errorOccurred, this, &FoxVerifier::errorOccurred);
+#endif
+ connect(reply_, &QNetworkReply::redirected, this, &FoxVerifier::httpRedirected);
+ connect(reply_, &QNetworkReply::encrypted, this, &FoxVerifier::httpEncrypted);
+#if QT_CONFIG(ssl)
+ connect(reply_, &QNetworkReply::sslErrors, this, &FoxVerifier::sslErrors);
+#else
+ LOG_INFO("FoxVerifier: ssl not supported");
+#endif
+
+ } else {
+ LOG_INFO(QString("FoxVerifier: url invalid ! %1").arg(url).toStdString());
+ }
+}
+
+FoxVerifier::~FoxVerifier() {
+}
+
+bool FoxVerifier::finished() {
+ return finished_;
+}
+
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+void FoxVerifier::errorOccurred(QNetworkReply::NetworkError code)
+{
+ int status = reply_->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ QString reason = reply_->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
+ errored_ = true;
+ error_reason_ = reply_->errorString();
+ if (reply_->error() != QNetworkReply::NoError) {
+
+ LOG_INFO(QString("FoxVerifier: errorOccurred status %1 error [%2][%3] isFinished %4 isrunning %5 code %6").arg(status).arg(
+ reason).arg(error_reason_).arg(reply_->isFinished()).arg(reply_->isRunning()).arg(code).toStdString());
+ return;
+ }
+ // TODO emit
+}
+#endif
+
+void FoxVerifier::httpFinished()
+{
+ int status = reply_->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ QString reason = reply_->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
+ if (reply_->error() != QNetworkReply::NoError) {
+ LOG_INFO(QString("FoxVerifier: httpFinished error:[%1 - %2] msg:[%3]").arg(status).arg(reason).arg(reply_->errorString()).toStdString());
+ reply_->abort();
+ emit verifyError(status, ts_, callsign_, code_, hz_, reply_->errorString());
+ }
+ return_value = reply_->read(1024); // limit amount we get
+ LOG_INFO(QString("FoxVerifier: httpFinished status:[%1 - %2] body:[%3] ").arg(status).arg(reason).arg(return_value).toStdString());
+ finished_ = true;
+ reply_->deleteLater();
+ if (status >= 200 && status <= 299) {
+ emit verifyComplete(status, ts_, callsign_, code_, hz_, return_value);
+ }
+}
+
+void FoxVerifier::sslErrors(const QList<QSslError> &)
+{
+ LOG_INFO(QString("FoxVerifier: sslErrors").toStdString());
+ reply_->ignoreSslErrors();
+}
+
+void FoxVerifier::httpRedirected(const QUrl &url) {
+ LOG_INFO(QString("FoxVerifier: redirected to %1").arg(url.toString()).toStdString());
+}
+
+void FoxVerifier::httpEncrypted() {
+ LOG_INFO("FoxVerifier: httpEncrypted");
+}
+
+QString FoxVerifier::formatDecodeMessage(QDateTime ts, QString callsign, unsigned int hz_, QString const& verify_message) {
+ //"172100 -00 0.0 750 ~ K8R VERIFIED"
+ QTime rx_time = ts.time();
+ QString hz=QString("%1").arg(hz_, 4, 10 ); // insert Hz
+ if (verify_message.endsWith(" VERIFIED")) {
+ return QString("%1 0 0.0 %2 ~ %3 verified").arg(rx_time.toString("hhmmss")).arg(hz).arg(callsign);
+ } else
+ if (verify_message.endsWith(" INVALID"))
+ {
+ return QString("%1 0 0.0 %2 ~ %3 invalid").arg(rx_time.toString("hhmmss")).arg(hz).arg(callsign);
+ }
+ else
+ return QString{};
+}
+
+QString FoxVerifier::default_url() {
+ return QString(FOXVERIFIER_DEFAULT_BASE_URL);
+}
diff --git a/Network/FoxVerifier.hpp b/Network/FoxVerifier.hpp new file mode 100755 index 00000000..0a645189 --- /dev/null +++ b/Network/FoxVerifier.hpp @@ -0,0 +1,63 @@ +
+#ifndef WSJTX2_FOXVERIFIER_HPP
+#define WSJTX2_FOXVERIFIER_HPP
+
+#include <QObject>
+#include <QString>
+#include <QPointer>
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+#include <QMutex>
+
+#define FOXVERIFIER_DEFAULT_TIMEOUT_MSEC 5000
+#define FOXVERIFIER_DEFAULT_BASE_URL "https://www.9dx.cc"
+
+class FoxVerifier : public QObject {
+ Q_OBJECT
+ QMutex mutex_;
+
+public:
+ explicit FoxVerifier(QString user_agent, QNetworkAccessManager *manager, QString base_url, QString callsign, QDateTime timestamp, QString code, unsigned int);
+ ~FoxVerifier();
+
+ QString return_value;
+ bool finished();
+ static QString formatDecodeMessage(QDateTime ts, QString callsign, unsigned int hz, QString const& verify_message);
+ static QString default_url();
+
+private:
+ QNetworkAccessManager* manager_;
+ QNetworkReply* reply_;
+ QNetworkRequest request_;
+ QUrl q_url_;
+ bool finished_;
+ bool errored_;
+ unsigned int hz_;
+ QString error_reason_;
+ QDateTime ts_;
+ QString callsign_;
+ QString code_;
+
+private slots:
+ void httpFinished();
+ void httpRedirected(const QUrl &url);
+ void httpEncrypted();
+#ifndef QT_NO_SSL
+ void sslErrors(const QList<QSslError> &);
+#endif
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+ void errorOccurred(QNetworkReply::NetworkError code);
+#endif
+//signals:
+ //void results(QString verify_response);
+ //void error(QString const& reason) const;
+
+public slots:
+signals:
+ void verifyComplete(int status, QDateTime ts, QString callsign, QString code, unsigned int hz, QString const& response);
+ void verifyError(int status, QDateTime ts, QString callsign, QString code, unsigned int hz, QString const& response);
+
+};
+
+
+#endif //WSJTX2_FOXVERIFIER_HPP
diff --git a/Network/LotWUsers.cpp b/Network/LotWUsers.cpp index f33b75c1..73480f68 100755 --- a/Network/LotWUsers.cpp +++ b/Network/LotWUsers.cpp @@ -16,7 +16,9 @@ #include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QDebug>
-
+#include "qt_helpers.hpp"
+#include "Logger.hpp"
+#include "FileDownload.hpp"
#include "pimpl_impl.hpp"
#include "moc_LotWUsers.cpp"
@@ -39,6 +41,7 @@ public: , url_valid_ {false}
, redirect_count_ {0}
, age_constraint_ {365}
+ , connected_ {false}
{
}
@@ -48,161 +51,50 @@ public: auto csv_file_name = csv_file_.fileName ();
auto exists = QFileInfo::exists (csv_file_name);
if (fetch && (!exists || forced_fetch))
+ {
+ current_url_.setUrl(url);
+ if (current_url_.isValid() && !QSslSocket::supportsSsl())
{
- current_url_.setUrl (url);
- if (current_url_.isValid () && !QSslSocket::supportsSsl ())
- {
- current_url_.setScheme ("http");
- }
- redirect_count_ = 0;
- download (current_url_);
- }
- else
- {
- if (exists)
- {
- // load the database asynchronously
- future_load_ = std::async (std::launch::async, &LotWUsers::impl::load_dictionary, this, csv_file_name);
- }
- }
- }
-
- void download (QUrl url)
- {
-#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
- if (QNetworkAccessManager::Accessible != network_manager_->networkAccessible ())
- {
- // try and recover network access for QNAM
- network_manager_->setNetworkAccessible (QNetworkAccessManager::Accessible);
- }
-#endif
-
- QNetworkRequest request {url};
- request.setRawHeader ("User-Agent", "WSJT LotW User Downloader");
- request.setOriginatingObject (this);
-
- // this blocks for a second or two the first time it is used on
- // Windows - annoying
- if (!url_valid_)
- {
- reply_ = network_manager_->head (request);
- }
- else
- {
- reply_ = network_manager_->get (request);
+ current_url_.setScheme("http");
}
+ redirect_count_ = 0;
- connect (reply_.data (), &QNetworkReply::finished, this, &LotWUsers::impl::reply_finished);
- connect (reply_.data (), &QNetworkReply::readyRead, this, &LotWUsers::impl::store);
- }
+ Q_EMIT self_->progress (QString("Starting download from %1").arg(url));
- void reply_finished ()
- {
- if (!reply_)
- {
- Q_EMIT self_->load_finished ();
- return; // we probably deleted it in an earlier call
- }
- QUrl redirect_url {reply_->attribute (QNetworkRequest::RedirectionTargetAttribute).toUrl ()};
- if (reply_->error () == QNetworkReply::NoError && !redirect_url.isEmpty ())
+ lotw_downloader_.configure(network_manager_,
+ url,
+ csv_file_name,
+ "WSJT-X LotW User Downloader");
+ if (!connected_)
{
- if ("https" == redirect_url.scheme () && !QSslSocket::supportsSsl ())
- {
- Q_EMIT self_->LotW_users_error (tr ("Network Error - SSL/TLS support not installed, cannot fetch:\n\'%1\'")
- .arg (redirect_url.toDisplayString ()));
- url_valid_ = false; // reset
- Q_EMIT self_->load_finished ();
- }
- else if (++redirect_count_ < 10) // maintain sanity
- {
- // follow redirect
- download (reply_->url ().resolved (redirect_url));
- }
- else
- {
- Q_EMIT self_->LotW_users_error (tr ("Network Error - Too many redirects:\n\'%1\'")
- .arg (redirect_url.toDisplayString ()));
- url_valid_ = false; // reset
- Q_EMIT self_->load_finished ();
- }
+ connect(&lotw_downloader_, &FileDownload::complete, [this, csv_file_name] {
+ LOG_INFO(QString{"LotWUsers: Loading LotW file %1"}.arg(csv_file_name));
+ future_load_ = std::async(std::launch::async, &LotWUsers::impl::load_dictionary, this, csv_file_name);
+ });
+ connect(&lotw_downloader_, &FileDownload::error, [this] (QString const& msg) {
+ LOG_INFO(QString{"LotWUsers: Error downloading LotW file: %1"}.arg(msg));
+ Q_EMIT self_->LotW_users_error (msg);
+ });
+ connect( &lotw_downloader_, &FileDownload::progress, [this] (QString const& msg) {
+ Q_EMIT self_->progress (msg);
+ });
+ connected_ = true;
}
- else if (reply_->error () != QNetworkReply::NoError)
- {
- csv_file_.cancelWriting ();
- csv_file_.commit ();
- url_valid_ = false; // reset
- // report errors that are not due to abort
- if (QNetworkReply::OperationCanceledError != reply_->error ())
- {
- Q_EMIT self_->LotW_users_error (tr ("Network Error:\n%1")
- .arg (reply_->errorString ()));
- }
- Q_EMIT self_->load_finished ();
+ lotw_downloader_.start_download();
}
else
{
- if (url_valid_ && !csv_file_.commit ())
- {
- Q_EMIT self_->LotW_users_error (tr ("File System Error - Cannot commit changes to:\n\"%1\"")
- .arg (csv_file_.fileName ()));
- url_valid_ = false; // reset
- Q_EMIT self_->load_finished ();
- }
- else
- {
- if (!url_valid_)
- {
- // now get the body content
- url_valid_ = true;
- download (reply_->url ().resolved (redirect_url));
- }
- else
- {
- url_valid_ = false; // reset
- // load the database asynchronously
- future_load_ = std::async (std::launch::async, &LotWUsers::impl::load_dictionary, this, csv_file_.fileName ());
- }
- }
- }
- if (reply_ && reply_->isFinished ())
- {
- reply_->deleteLater ();
- }
- }
-
- void store ()
- {
- if (url_valid_)
- {
- if (!csv_file_.isOpen ())
- {
- // create temporary file in the final location
- if (!csv_file_.open (QSaveFile::WriteOnly))
- {
- abort ();
- Q_EMIT self_->LotW_users_error (tr ("File System Error - Cannot open file:\n\"%1\"\nError(%2): %3")
- .arg (csv_file_.fileName ())
- .arg (csv_file_.error ())
- .arg (csv_file_.errorString ()));
- }
- }
- if (csv_file_.write (reply_->read (reply_->bytesAvailable ())) < 0)
+ if (exists)
{
- abort ();
- Q_EMIT self_->LotW_users_error (tr ("File System Error - Cannot write to file:\n\"%1\"\nError(%2): %3")
- .arg (csv_file_.fileName ())
- .arg (csv_file_.error ())
- .arg (csv_file_.errorString ()));
+ // load the database asynchronously
+ future_load_ = std::async (std::launch::async, &LotWUsers::impl::load_dictionary, this, csv_file_name);
}
}
}
void abort ()
{
- if (reply_ && reply_->isRunning ())
- {
- reply_->abort ();
- }
+ lotw_downloader_.abort();
}
// Load the database from the given file name
@@ -222,12 +114,14 @@ public: auto pos = l.indexOf (',');
result[l.left (pos)] = QDate::fromString (l.mid (pos + 1, l.indexOf (',', pos + 1) - pos - 1), "yyyy-MM-dd");
}
-// qDebug () << "LotW User Data Loaded";
}
else
{
throw std::runtime_error {QObject::tr ("Failed to open LotW users CSV file: '%1'").arg (f.fileName ()).toStdString ()};
}
+ LOG_INFO(QString{"LotWUsers: Loaded %1 records from %2"}.arg(result.size()).arg(lotw_csv_file));
+ Q_EMIT self_->progress (QString{"Loaded %1 records from LotW."}.arg(result.size()));
+ Q_EMIT self_->load_finished();
return result;
}
@@ -241,6 +135,8 @@ public: std::future<dictionary> future_load_;
dictionary last_uploaded_;
qint64 age_constraint_; // days
+ FileDownload lotw_downloader_;
+ bool connected_;
};
#include "LotWUsers.moc"
@@ -249,6 +145,7 @@ LotWUsers::LotWUsers (QNetworkAccessManager * network_manager, QObject * parent) : QObject {parent}
, m_ {this, network_manager}
{
+
}
LotWUsers::~LotWUsers ()
diff --git a/Network/LotWUsers.hpp b/Network/LotWUsers.hpp index b3fd6601..cfb9b890 100755 --- a/Network/LotWUsers.hpp +++ b/Network/LotWUsers.hpp @@ -31,6 +31,7 @@ public: bool user (QString const& call) const;
Q_SIGNAL void LotW_users_error (QString const& reason) const;
+ Q_SIGNAL void progress (QString const& reason) const;
Q_SIGNAL void load_finished () const;
private:
diff --git a/Network/MessageClient.cpp b/Network/MessageClient.cpp index aa26fa1f..933bc8a7 100755 --- a/Network/MessageClient.cpp +++ b/Network/MessageClient.cpp @@ -392,6 +392,21 @@ void MessageClient::impl::parse_message (QByteArray const& msg) }
break;
+ case NetworkMessage::AnnotationInfo: {
+ QByteArray dx_call;
+ bool sort_order_provided{false};
+ quint32 sort_order{std::numeric_limits<quint32>::max()};
+ in >> dx_call >> sort_order_provided >> sort_order;
+ TRACE_UDP ("External Callsign Info:" << dx_call << "sort_order_provided:" << sort_order_provided
+ << "sort_order:" << sort_order);
+ if (sort_order > 50000) sort_order = 50000;
+ if (check_status(in) != Fail) {
+ Q_EMIT
+ self_->annotation_info(QString::fromUtf8(dx_call), sort_order_provided, sort_order);
+ }
+ }
+ break;
+
default:
// Ignore
//
@@ -634,7 +649,8 @@ void MessageClient::qso_logged (QDateTime time_off, QString const& dx_call, QStr , QString const& comments, QString const& name, QDateTime time_on
, QString const& operator_call, QString const& my_call
, QString const& my_grid, QString const& exchange_sent
- , QString const& exchange_rcvd, QString const& propmode)
+ , QString const& exchange_rcvd, QString const& propmode
+ , QString const& satellite, QString const& satmode, QString const& freqRx)
{
if (m_->server_port_ && !m_->server_.isNull ())
{
@@ -643,8 +659,9 @@ void MessageClient::qso_logged (QDateTime time_off, QString const& dx_call, QStr out << time_off << dx_call.toUtf8 () << dx_grid.toUtf8 () << dial_frequency << mode.toUtf8 ()
<< report_sent.toUtf8 () << report_received.toUtf8 () << tx_power.toUtf8 () << comments.toUtf8 ()
<< name.toUtf8 () << time_on << operator_call.toUtf8 () << my_call.toUtf8 () << my_grid.toUtf8 ()
- << exchange_sent.toUtf8 () << exchange_rcvd.toUtf8 () << propmode.toUtf8 ();
- TRACE_UDP ("time off:" << time_off << "DX:" << dx_call << "DX grid:" << dx_grid << "dial:" << dial_frequency << "mode:" << mode << "sent:" << report_sent << "rcvd:" << report_received << "pwr:" << tx_power << "comments:" << comments << "name:" << name << "time on:" << time_on << "op:" << operator_call << "DE:" << my_call << "DE grid:" << my_grid << "exch sent:" << exchange_sent << "exch rcvd:" << exchange_rcvd << "prop_mode:" << propmode);
+ << exchange_sent.toUtf8 () << exchange_rcvd.toUtf8 () << propmode.toUtf8 () << satellite.toUtf8 ()
+ << satmode.toUtf8 () << freqRx.toUtf8 ();
+ TRACE_UDP ("time off:" << time_off << "DX:" << dx_call << "DX grid:" << dx_grid << "dial:" << dial_frequency << "mode:" << mode << "sent:" << report_sent << "rcvd:" << report_received << "pwr:" << tx_power << "comments:" << comments << "name:" << name << "time on:" << time_on << "op:" << operator_call << "DE:" << my_call << "DE grid:" << my_grid << "exch sent:" << exchange_sent << "exch rcvd:" << exchange_rcvd << "prop_mode:" << propmode << "sat_name:" << satellite << "sat_mode:" << satmode << "freq_rx:" << freqRx);
m_->send_message (out, message);
}
}
diff --git a/Network/MessageClient.hpp b/Network/MessageClient.hpp index 05348f27..1fffda26 100755 --- a/Network/MessageClient.hpp +++ b/Network/MessageClient.hpp @@ -78,7 +78,8 @@ public: , QString const& name, QDateTime time_on, QString const& operator_call
, QString const& my_call, QString const& my_grid
, QString const& exchange_sent, QString const& exchange_rcvd
- , QString const& propmode);
+ , QString const& propmode, QString const& satellite
+ , QString const& satmode, QString const& freqRx);
// ADIF_record argument should be valid ADIF excluding any <EOR> end
// of record marker
@@ -123,6 +124,9 @@ public: , bool fast_mode, quint32 tr_period, quint32 rx_df, QString const& dx_call
, QString const& dx_grid, bool generate_messages);
+ // this signal is emitted if the server has sent information about a callsign
+ Q_SIGNAL void annotation_info (QString const& dx_call, bool sort_order_provided, quint32 sort_order);
+
// this signal is emitted when network errors occur or if a host
// lookup fails
Q_SIGNAL void error (QString const&) const;
diff --git a/Network/Network.pri b/Network/Network.pri new file mode 100755 index 00000000..ac590793 --- /dev/null +++ b/Network/Network.pri @@ -0,0 +1,21 @@ +SOURCES += \
+Network/FileDownload.cpp \
+Network/FoxVerifier.cpp \
+Network/LotWUsers.cpp \
+Network/MessageClient.cpp \
+Network/NetworkAccessManager.cpp \
+Network/NetworkMessage.cpp \
+Network/NetworkServerLookup.cpp \
+Network/PSKReporter.cpp \
+Network/wsprnet.cpp
+
+HEADERS += \
+Network/FileDownload.hpp \
+Network/FoxVerifier.hpp \
+Network/LotWUsers.hpp \
+Network/MessageClient.hpp \
+Network/NetworkAccessManager.hpp \
+Network/NetworkMessage.hpp \
+Network/NetworkServerLookup.hpp \
+Network/PSKReporter.hpp \
+Network/wsprnet.h
diff --git a/Network/NetworkMessage.hpp b/Network/NetworkMessage.hpp index 728e71e4..c046c3db 100755 --- a/Network/NetworkMessage.hpp +++ b/Network/NetworkMessage.hpp @@ -463,6 +463,14 @@ * limit the number of active highlighting requests to no more
* than 100.
*
+ * Using a callsign of "CLEARALL!" and anything for the
+ * color values will clear the internal highlighting data. It will
+ * NOT remove the highlighting on the screen, however. The exclamation
+ * symbol is used to avoid accidental clearing of all highlighting
+ * data via a decoded callsign, since an exclamation symbol is not
+ * a valid character in a callsign.
+
+ *
* The "Highlight last" field allows the sender to request that
* all instances of "Callsign" in the last period only, instead
* of all instances in all periods, be highlighted.
@@ -494,7 +502,33 @@ * fields an empty value implies no change, for the quint32 Rx DF
* and Frequency Tolerance fields the maximum quint32 value
* implies no change. Invalid or unrecognized values will be
- * silently ignored.
+ * silently ignored. NOTE that if a mode/submode change occurs and
+ * the current frequency is NOT in the frequency table for that
+ * mode, a frequency change (to the default frequency for that band
+ * and mode) may occur.
+ *
+ * AnnotationInfo In 16 quint32
+ * Id (unique key) utf8
+ * DX Call utf8
+ * Sort Order Provided bool
+ * Sort Order quint32
+ *
+ * The server may send this message at any time. Sort orders can be used
+ * for sorting hound callers when in Fox mode. A typical usage is to
+ * "score" callsigns based on number of bands and/or modes worked using
+ * an external logging program during a DXpedition, to be able to give
+ * preference to calls that have not been worked before on any other
+ * band or mode. An external program can watch decodes from wsjt-x,
+ * then use this message to annotate the calls with a sort order. The
+ * hound queue can be displayed by that sort order. *
+ *
+ * If 'sort order provided' is true, the message also specifies a numeric
+ * sort order for the DX call.
+ *
+ * Invalid or unrecognized values will be silently ignored. A sort-order of
+ * ffffffff will remove the sort-order value from the internal table.
+ * Callsigns without a sort order will be valued at zero for sorting purposes
+ * in the hound display.
*/
#include <QDataStream>
@@ -526,6 +560,7 @@ namespace NetworkMessage HighlightCallsign,
SwitchConfiguration,
Configure,
+ AnnotationInfo,
maximum_message_type_ // ONLY add new message types
// immediately before here
};
diff --git a/Network/PSKReporter.cpp b/Network/PSKReporter.cpp index 4db1d756..6e390006 100755 --- a/Network/PSKReporter.cpp +++ b/Network/PSKReporter.cpp @@ -6,6 +6,8 @@ //
// Reports will be sent in batch mode every 5 minutes.
+#include <fstream>
+#include <iostream>
#include <cmath>
#include <QObject>
#include <QString>
@@ -18,6 +20,7 @@ #include <QByteArray>
#include <QDataStream>
#include <QTimer>
+#include <QDir>
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#include <QRandomGenerator>
#endif
@@ -29,19 +32,26 @@ #include "moc_PSKReporter.cpp"
+//#define DEBUGECLIPSE 0
+
namespace
{
QLatin1String HOST {"report.pskreporter.info"};
// QLatin1String HOST {"127.0.0.1"};
quint16 SERVICE_PORT {4739};
// quint16 SERVICE_PORT {14739};
- int MIN_SEND_INTERVAL {15}; // in seconds
- int FLUSH_INTERVAL {4 * 5}; // in send intervals
+ int MIN_SEND_INTERVAL {120}; // in seconds
+ int FLUSH_INTERVAL {MIN_SEND_INTERVAL + 5}; // in send intervals
bool ALIGNMENT_PADDING {true};
int MIN_PAYLOAD_LENGTH {508};
- int MAX_PAYLOAD_LENGTH {1400};
+ int MAX_PAYLOAD_LENGTH {10000};
+ int CACHE_TIMEOUT {300}; // default to 5 minutes for repeating spots
+ QMap<QString, time_t> spot_cache;
}
+static int added;
+static int removed;
+
class PSKReporter::impl final
: public QObject
{
@@ -83,6 +93,7 @@ public: send_receiver_data_ = 3; // three times
}
});
+ eclipse_load(config->data_dir ().absoluteFilePath ("eclipse.txt"));
}
void check_connection ()
@@ -167,7 +178,7 @@ public: if (!report_timer_.isActive ())
{
- report_timer_.start (MIN_SEND_INTERVAL * 1000);
+ report_timer_.start (MIN_SEND_INTERVAL+1 * 1000); // we add 1 to give some more randomization
}
if (!descriptor_timer_.isActive ())
{
@@ -188,6 +199,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 ()
{
@@ -196,6 +209,14 @@ public: return flush;
}
+ QString getStringFromQDateTime(const QString& dateTimeString, const QString& format)
+ {
+ QDateTime dateTime = QDateTime::fromString(dateTimeString, format);
+ return dateTime.toString();
+ }
+
+ QList<QDateTime> eclipseDates;
+
logger_type mutable logger_;
PSKReporter * self_;
Configuration const * config_;
@@ -217,6 +238,7 @@ public: QString rx_call_;
QString rx_grid_;
QString rx_ant_;
+ QString rigInformation_;
QString prog_id_;
QByteArray tx_data_;
QByteArray tx_residue_;
@@ -272,6 +294,70 @@ namespace }
}
+bool PSKReporter::impl::eclipse_active(QDateTime timeutc)
+{
+ qDebug() << timeutc;
+#ifdef DEBUGECLIPSE
+ std::ofstream mylog("/temp/eclipse.log", std::ios_base::app);
+#endif
+ QDateTime dateNow = QDateTime::currentDateTimeUtc();
+ for (int i=0; i< eclipseDates.size(); ++i)
+ {
+ QDateTime check = eclipseDates.at(i); // already in UTC time
+ // +- 6 hour window
+ qint64 secondsDiff = qAbs(check.secsTo(dateNow));
+ if (secondsDiff <= 3600*6) // 6 hour check
+ {
+#ifdef DEBUGECLIPSE
+ mylog << dateNow.toString(Qt::ISODate) << " Eclipse! " << "secondsDiff=" << secondsDiff << std::endl;
+#endif
+ return true;
+ }
+ }
+#ifdef DEBUGECLIPSE
+ mylog << timeutc.toString("yyyy-MM-dd HH:mm:ss") << " no eclipse" << "\n";
+#endif
+ 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("c:/temp/eclipse.log");
+ mylog << "eclipse_file=" << eclipse_file << std::endl;
+#endif
+ if (fs.is_open())
+ {
+ while(!fs.eof())
+ {
+ std::getline(fs, myline);
+ if (myline[0] != '#' && myline.length() > 2) // make sure to skip blank lines
+ {
+ //QString format = "yyyy-MM-dd hh:mm:ss";
+ QDateTime qdate = QDateTime::fromString(QString::fromStdString(myline), Qt::ISODate);
+ QDateTime now = QDateTime::currentDateTimeUtc();
+ // only add the date if we can cover the whole 12 hours
+ //if (now < qdate.toUTC().addSecs(-3600*6))
+ eclipseDates.append(qdate);
+#ifdef DEBUGECLIPSE
+ //else
+ // mylog << "not adding " << myline << std::endl;
+#endif
+
+ }
+#ifdef DEBUGECLIPSE
+ mylog << myline << std::endl;
+#endif
+ }
+ }
+#ifdef DEBUGECLIPSE
+ if (eclipse_active(QDateTime::currentDateTime().toUTC())) mylog << "Eclipse is active" << std::endl;
+ else mylog << "Eclipse is not active" << std::endl;
+#endif
+}
+
void PSKReporter::impl::build_preamble (QDataStream& message)
{
// Message Header
@@ -327,7 +413,7 @@ void PSKReporter::impl::build_preamble (QDataStream& message) << quint16 (3u) // Options Template Set ID
<< quint16 (0u) // Length (place-holder)
<< quint16 (0x50e2) // Link ID
- << quint16 (4u) // Field Count
+ << quint16 (5u) // Field Count
<< quint16 (0u) // Scope Field Count
<< quint16 (0x8000 + 2u) // Option 1 Information Element ID (receiverCallsign)
<< quint16 (0xffff) // Option 1 Field Length (variable)
@@ -340,6 +426,9 @@ void PSKReporter::impl::build_preamble (QDataStream& message) << quint32 (30351u) // Option 3 Enterprise Number
<< quint16 (0x8000 + 9u) // Option 4 Information Element ID (antennaInformation)
<< quint16 (0xffff) // Option 4 Field Length (variable)
+ << quint32 (30351u) // Option 5 Enterprise Number
+ << quint16 (0x8000 + 13u)// Option 5 Information Element ID (rigInformation)
+ << quint16 (0xffff) // Option 5 Field Length (variable)
<< quint32 (30351u); // Option 4 Enterprise Number
// insert Length
set_length (out, descriptor);
@@ -366,6 +455,7 @@ void PSKReporter::impl::build_preamble (QDataStream& message) writeUtfString (out, rx_grid_);
writeUtfString (out, prog_id_);
writeUtfString (out, rx_ant_);
+ writeUtfString (out, rigInformation_);
// insert Length and move to payload
set_length (out, data);
@@ -516,7 +606,12 @@ void PSKReporter::reconnect () m_->reconnect ();
}
-void PSKReporter::setLocalStation (QString const& call, QString const& gridSquare, QString const& antenna)
+bool PSKReporter::eclipse_active(QDateTime now)
+{
+ return m_->eclipse_active(now);
+}
+
+void PSKReporter::setLocalStation (QString const& call, QString const& gridSquare, QString const& antenna, QString const& rigInformation)
{
LOG_LOG_LOCATION (m_->logger_, trace, "call: " << call << " grid: " << gridSquare << " ant: " << antenna);
m_->check_connection ();
@@ -528,6 +623,7 @@ void PSKReporter::setLocalStation (QString const& call, QString const& gridSquar m_->rx_call_ = call;
m_->rx_grid_ = gridSquare;
m_->rx_ant_ = antenna;
+ m_->rigInformation_ = rigInformation;
}
}
@@ -542,7 +638,45 @@ bool PSKReporter::addRemoteStation (QString const& call, QString const& grid, Ra {
reconnect ();
}
- m_->spots_.enqueue ({call, grid, snr, freq, mode, QDateTime::currentDateTimeUtc ()});
+ // remove any earlier spots of this call to reduce pskreporter load
+#ifdef DEBUGPSK
+ static std::fstream fs;
+ if (!fs.is_open()) fs.open("/temp/psk.log", std::fstream::in | std::fstream::out | std::fstream::app);
+#endif
+ added++;
+
+ QDateTime qdateNow = QDateTime::currentDateTime().toUTC();
+ // 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));
+#ifdef DEBUGPSK
+ if (fs.is_open()) fs << "Adding " << call << " freq=" << freq << " " << spot_cache[call] << " count=" << m_->spots_.count() << std::endl;
+#endif
+ }
+ else if (time(NULL) - spot_cache[call] > CACHE_TIMEOUT) // then the cache has expired
+ {
+ m_->spots_.enqueue ({call, grid, snr, freq, mode, QDateTime::currentDateTimeUtc ()});
+#ifdef DEBUGPSK
+ if (fs.is_open()) fs << "Adding # " << call << spot_cache[call] << " count=" << m_->spots_.count() << std::endl;
+#endif
+ spot_cache[call] = time(NULL);
+ }
+ else
+ {
+ removed++;
+#ifdef DEBUGPSK
+ if (fs.is_open()) fs << "Removing " << call << " " << time(NULL) << " reduction=" << removed/(double)added*100 << "%" << std::endl;
+#endif
+ }
+ // remove cached items over 10 minutes old to save a little memory
+ QMapIterator<QString, time_t> i(spot_cache);
+ time_t tmptime = time(NULL);
+ while(i.hasNext()) {
+ i.next();
+ if (tmptime - i.value() > 600) spot_cache.remove(i.key());
+ }
return true;
}
return false;
diff --git a/Network/PSKReporter.hpp b/Network/PSKReporter.hpp index 7bac5421..25006de0 100755 --- a/Network/PSKReporter.hpp +++ b/Network/PSKReporter.hpp @@ -19,7 +19,7 @@ public: void reconnect ();
- void setLocalStation (QString const& call, QString const& grid, QString const& antenna);
+ void setLocalStation (QString const& call, QString const& grid, QString const& antenna, QString const& rigInformation);
//
// Returns false if PSK Reporter connection is not available
@@ -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:
|
