21 changed files with 725 additions and 47 deletions
|
After Width: | Height: | Size: 368 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 71 KiB |
@ -0,0 +1,227 @@
@@ -0,0 +1,227 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2022 Jon Beniston, M7RCE //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "giro.h" |
||||
|
||||
#include <QDebug> |
||||
#include <QUrl> |
||||
#include <QUrlQuery> |
||||
#include <QNetworkReply> |
||||
#include <QJsonObject> |
||||
|
||||
GIRO::GIRO() |
||||
{ |
||||
connect(&m_dataTimer, &QTimer::timeout, this, &GIRO::getData); |
||||
connect(&m_mufTimer, &QTimer::timeout, this, &GIRO::getMUF); |
||||
connect(&m_foF2Timer, &QTimer::timeout, this, &GIRO::getfoF2); |
||||
m_networkManager = new QNetworkAccessManager(); |
||||
connect(m_networkManager, &QNetworkAccessManager::finished, this, &GIRO::handleReply); |
||||
} |
||||
|
||||
GIRO::~GIRO() |
||||
{ |
||||
disconnect(&m_dataTimer, &QTimer::timeout, this, &GIRO::getData); |
||||
disconnect(&m_mufTimer, &QTimer::timeout, this, &GIRO::getMUF); |
||||
disconnect(&m_foF2Timer, &QTimer::timeout, this, &GIRO::getfoF2); |
||||
disconnect(m_networkManager, &QNetworkAccessManager::finished, this, &GIRO::handleReply); |
||||
delete m_networkManager; |
||||
} |
||||
|
||||
GIRO* GIRO::create(const QString& service) |
||||
{ |
||||
if (service == "prop.kc2g.com") |
||||
{ |
||||
return new GIRO(); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "GIRO::create: Unsupported service: " << service; |
||||
return nullptr; |
||||
} |
||||
} |
||||
|
||||
void GIRO::getDataPeriodically(int periodInMins) |
||||
{ |
||||
if (periodInMins > 0) |
||||
{ |
||||
m_dataTimer.setInterval(periodInMins*60*1000); |
||||
m_dataTimer.start(); |
||||
getData(); |
||||
} |
||||
else |
||||
{ |
||||
m_dataTimer.stop(); |
||||
} |
||||
} |
||||
|
||||
void GIRO::getMUFPeriodically(int periodInMins) |
||||
{ |
||||
if (periodInMins > 0) |
||||
{ |
||||
m_mufTimer.setInterval(periodInMins*60*1000); |
||||
m_mufTimer.start(); |
||||
getMUF(); |
||||
} |
||||
else |
||||
{ |
||||
m_mufTimer.stop(); |
||||
} |
||||
} |
||||
|
||||
void GIRO::getfoF2Periodically(int periodInMins) |
||||
{ |
||||
if (periodInMins > 0) |
||||
{ |
||||
m_foF2Timer.setInterval(periodInMins*60*1000); |
||||
m_foF2Timer.start(); |
||||
getfoF2(); |
||||
} |
||||
else |
||||
{ |
||||
m_foF2Timer.stop(); |
||||
} |
||||
} |
||||
|
||||
void GIRO::getData() |
||||
{ |
||||
QUrl url(QString("https://prop.kc2g.com/api/stations.json")); |
||||
m_networkManager->get(QNetworkRequest(url)); |
||||
} |
||||
|
||||
void GIRO::getMUF() |
||||
{ |
||||
QUrl url(QString("https://prop.kc2g.com/renders/current/mufd-normal-now.geojson")); |
||||
m_networkManager->get(QNetworkRequest(url)); |
||||
} |
||||
|
||||
void GIRO::getfoF2() |
||||
{ |
||||
QUrl url(QString("https://prop.kc2g.com/renders/current/fof2-normal-now.geojson")); |
||||
m_networkManager->get(QNetworkRequest(url)); |
||||
} |
||||
|
||||
bool GIRO::containsNonNull(const QJsonObject& obj, const QString &key) const |
||||
{ |
||||
if (obj.contains(key)) |
||||
{ |
||||
QJsonValue val = obj.value(key); |
||||
return !val.isNull(); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
void GIRO::handleReply(QNetworkReply* reply) |
||||
{ |
||||
if (reply) |
||||
{ |
||||
if (!reply->error()) |
||||
{ |
||||
QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); |
||||
|
||||
if (reply->url().fileName() == "stations.json") |
||||
{ |
||||
if (document.isArray()) |
||||
{ |
||||
QJsonArray array = document.array(); |
||||
for (auto valRef : array) |
||||
{ |
||||
if (valRef.isObject()) |
||||
{ |
||||
QJsonObject obj = valRef.toObject(); |
||||
|
||||
GIROStationData data; |
||||
|
||||
if (obj.contains(QStringLiteral("station"))) |
||||
{ |
||||
QJsonObject stationObj = obj.value(QStringLiteral("station")).toObject(); |
||||
|
||||
if (stationObj.contains(QStringLiteral("name"))) { |
||||
data.m_station = stationObj.value(QStringLiteral("name")).toString(); |
||||
} |
||||
if (stationObj.contains(QStringLiteral("latitude"))) { |
||||
data.m_latitude = (float)stationObj.value(QStringLiteral("latitude")).toString().toFloat(); |
||||
} |
||||
if (stationObj.contains(QStringLiteral("longitude"))) { |
||||
data.m_longitude = (float)stationObj.value(QStringLiteral("longitude")).toString().toFloat(); |
||||
if (data.m_longitude >= 180.0f) { |
||||
data.m_longitude -= 360.0f; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (containsNonNull(obj, QStringLiteral("time"))) { |
||||
data.m_dateTime = QDateTime::fromString(obj.value(QStringLiteral("time")).toString(), Qt::ISODateWithMs); |
||||
} |
||||
if (containsNonNull(obj, QStringLiteral("mufd"))) { |
||||
data.m_mufd = (float)obj.value(QStringLiteral("mufd")).toDouble(); |
||||
} |
||||
if (containsNonNull(obj, QStringLiteral("md"))) { |
||||
data.m_md = obj.value(QStringLiteral("md")).toString().toFloat(); |
||||
} |
||||
if (containsNonNull(obj, QStringLiteral("tec"))) { |
||||
data.m_tec = (float)obj.value(QStringLiteral("tec")).toDouble(); |
||||
} |
||||
if (containsNonNull(obj, QStringLiteral("fof2"))) { |
||||
data.m_foF2 = (float)obj.value(QStringLiteral("fof2")).toDouble(); |
||||
} |
||||
if (containsNonNull(obj, QStringLiteral("hmf2"))) { |
||||
data.m_hmF2 = (float)obj.value(QStringLiteral("hmf2")).toDouble(); |
||||
} |
||||
if (containsNonNull(obj, QStringLiteral("foe"))) { |
||||
data.m_foE = (float)obj.value(QStringLiteral("foe")).toDouble(); |
||||
} |
||||
if (containsNonNull(obj, QStringLiteral("cs"))) { |
||||
data.m_confidence = (int)obj.value(QStringLiteral("cs")).toDouble(); |
||||
} |
||||
|
||||
emit dataUpdated(data); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "GIRO::handleReply: Array element is not an object: " << valRef; |
||||
} |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "GIRO::handleReply: Document is not an array: " << document; |
||||
} |
||||
} |
||||
else if (reply->url().fileName() == "mufd-normal-now.geojson") |
||||
{ |
||||
emit mufUpdated(document); |
||||
} |
||||
else if (reply->url().fileName() == "fof2-normal-now.geojson") |
||||
{ |
||||
emit foF2Updated(document); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "GIRO::handleReply: unexpected filename: " << reply->url().fileName(); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "GIRO::handleReply: error: " << reply->error(); |
||||
} |
||||
reply->deleteLater(); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "GIRO::handleReply: reply is null"; |
||||
} |
||||
} |
||||
@ -0,0 +1,99 @@
@@ -0,0 +1,99 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2022 Jon Beniston, M7RCE //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_GIRO_H |
||||
#define INCLUDE_GIRO_H |
||||
|
||||
#include <QtCore> |
||||
#include <QTimer> |
||||
#include <QJsonDocument> |
||||
|
||||
#include "export.h" |
||||
|
||||
class QNetworkAccessManager; |
||||
class QNetworkReply; |
||||
|
||||
// GIRO - Global Ionosphere Radio Observatory
|
||||
// Gets MUFD, TEC, foF2 and other data for various stations around the world
|
||||
// Also gets MUF and foF2 contours as GeoJSON
|
||||
// Data from https://prop.kc2g.com/stations/
|
||||
class SDRBASE_API GIRO : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
protected: |
||||
GIRO(); |
||||
|
||||
public: |
||||
// See the following paper for an explanation of some of these variables
|
||||
// https://sbgf.org.br/mysbgf/eventos/expanded_abstracts/13th_CISBGf/A%20Simple%20Method%20to%20Calculate%20the%20Maximum%20Usable%20Frequency.pdf
|
||||
struct GIROStationData { |
||||
QString m_station; |
||||
float m_latitude; |
||||
float m_longitude; |
||||
QDateTime m_dateTime; |
||||
float m_mufd; // Maximum usable frequency
|
||||
float m_md; // Propagation coefficient? D=3000km?
|
||||
float m_tec; // Total electron content
|
||||
float m_foF2; // Critical frequency of F2 layer in ionosphere (highest frequency to be reflected)
|
||||
float m_hmF2; // F2 layer height of peak electron density (km?)
|
||||
float m_foE; // Critical frequency of E layer
|
||||
int m_confidence; |
||||
GIROStationData() : |
||||
m_latitude(NAN), |
||||
m_longitude(NAN), |
||||
m_mufd(NAN), |
||||
m_md(NAN), |
||||
m_tec(NAN), |
||||
m_foF2(NAN), |
||||
m_hmF2(NAN), |
||||
m_foE(NAN), |
||||
m_confidence(-1) |
||||
{ |
||||
} |
||||
}; |
||||
|
||||
static GIRO* create(const QString& service="prop.kc2g.com"); |
||||
|
||||
~GIRO(); |
||||
void getDataPeriodically(int periodInMins); |
||||
void getMUFPeriodically(int periodInMins); |
||||
void getfoF2Periodically(int periodInMins); |
||||
|
||||
private slots: |
||||
void getData(); |
||||
void getMUF(); |
||||
void getfoF2(); |
||||
|
||||
private slots: |
||||
void handleReply(QNetworkReply* reply); |
||||
|
||||
signals: |
||||
void dataUpdated(const GIROStationData& data); // Called when new data available.
|
||||
void mufUpdated(const QJsonDocument& doc); |
||||
void foF2Updated(const QJsonDocument& doc); |
||||
|
||||
private: |
||||
bool GIRO::containsNonNull(const QJsonObject& obj, const QString &key) const; |
||||
|
||||
QTimer m_dataTimer; // Timer for periodic updates
|
||||
QTimer m_mufTimer; |
||||
QTimer m_foF2Timer; |
||||
QNetworkAccessManager *m_networkManager; |
||||
|
||||
}; |
||||
|
||||
#endif /* INCLUDE_GIRO_H */ |
||||
Loading…
Reference in new issue