|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 60 KiB |
@ -1,11 +1,18 @@
@@ -1,11 +1,18 @@
|
||||
<RCC> |
||||
<qresource prefix="/map/"> |
||||
<file>icons/groundtracks.png</file> |
||||
<file>icons/clock.png</file> |
||||
<file>icons/ibp.png</file> |
||||
<file>icons/muf.png</file> |
||||
<file>icons/fof2.png</file> |
||||
<file>icons/controltower.png</file> |
||||
<file>icons/vor.png</file> |
||||
</qresource> |
||||
<qresource prefix="/map/"> |
||||
<file>icons/groundtracks.png</file> |
||||
<file>icons/clock.png</file> |
||||
<file>icons/ibp.png</file> |
||||
<file>icons/muf.png</file> |
||||
<file>icons/fof2.png</file> |
||||
<file>icons/controltower.png</file> |
||||
<file>icons/vor.png</file> |
||||
<file>icons/precipitation.png</file> |
||||
<file>icons/anchor.png</file> |
||||
<file>icons/cloud.png</file> |
||||
<file>icons/layers.png</file> |
||||
<file>icons/railway.png</file> |
||||
<file>icons/waypoints.png</file> |
||||
<file>icons/earthsat.png</file> |
||||
</qresource> |
||||
</RCC> |
||||
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 389 B |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 420 B |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2024 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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 "maptileserver.h" |
||||
@ -0,0 +1,436 @@
@@ -0,0 +1,436 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2021, 2023 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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_MAPTILESERVER_H_ |
||||
#define INCLUDE_MAPTILESERVER_H_ |
||||
|
||||
#include <QTcpServer> |
||||
#include <QTcpSocket> |
||||
#include <QRegularExpression> |
||||
#include <QDebug> |
||||
#include <QtNetwork> |
||||
#include <QImage> |
||||
#include <QPainter> |
||||
#include <QHash> |
||||
#include <QMutex> |
||||
#include <QMutexLocker> |
||||
#include <QNetworkDiskCache> |
||||
|
||||
class MapTileServer : public QTcpServer |
||||
{ |
||||
Q_OBJECT |
||||
private: |
||||
QString m_thunderforestAPIKey; |
||||
QString m_maptilerAPIKey; |
||||
QNetworkAccessManager m_manager; |
||||
QMutex m_mutex; |
||||
|
||||
struct TileJob { |
||||
QTcpSocket* m_socket; |
||||
QList<QString> m_urls; |
||||
QHash<QString, QImage> m_images; |
||||
QString m_format; |
||||
}; |
||||
QList<TileJob *> m_tileJobs; |
||||
QHash<QNetworkReply *, TileJob *> m_replies; |
||||
|
||||
QNetworkDiskCache *m_cache; |
||||
|
||||
QString m_radarPath; |
||||
QString m_satellitePath; |
||||
QString m_nasaGlobalImageryPath; |
||||
QString m_nasaGlobalImageryFormat; |
||||
bool m_displayRain; |
||||
bool m_displayClouds; |
||||
bool m_displaySeaMarks; |
||||
bool m_displayRailways; |
||||
bool m_displayNASAGlobalImagery; |
||||
|
||||
public: |
||||
// port - port to listen on / is listening on. Use 0 for any free port.
|
||||
MapTileServer(quint16 &port, QObject* parent = 0) : |
||||
QTcpServer(parent), |
||||
m_thunderforestAPIKey(""), |
||||
m_maptilerAPIKey(""), |
||||
m_radarPath(""), |
||||
m_satellitePath(""), |
||||
m_nasaGlobalImageryPath(""), |
||||
m_nasaGlobalImageryFormat(""), |
||||
m_displayRain(false), |
||||
m_displayClouds(false), |
||||
m_displaySeaMarks(false), |
||||
m_displayRailways(false), |
||||
m_displayNASAGlobalImagery(false) |
||||
{ |
||||
connect(&m_manager, &QNetworkAccessManager::finished, this, &MapTileServer::downloadFinished); |
||||
listen(QHostAddress::Any, port); |
||||
port = serverPort(); |
||||
|
||||
QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); |
||||
QDir writeableDir(locations[0]); |
||||
if (!writeableDir.mkpath(QStringLiteral("cache") + QDir::separator() + QStringLiteral("maptiles"))) { |
||||
qDebug() << "Failed to create cache/maptiles"; |
||||
} |
||||
|
||||
m_cache = new QNetworkDiskCache(); |
||||
m_cache->setCacheDirectory(locations[0] + QDir::separator() + QStringLiteral("cache") + QDir::separator() + QStringLiteral("maptiles")); |
||||
m_cache->setMaximumCacheSize(1000000000); |
||||
m_manager.setCache(m_cache); |
||||
} |
||||
|
||||
~MapTileServer() |
||||
{ |
||||
disconnect(&m_manager, &QNetworkAccessManager::finished, this, &MapTileServer::downloadFinished); |
||||
delete m_cache; |
||||
} |
||||
|
||||
void setThunderforestAPIKey(const QString& thunderforestAPIKey) |
||||
{ |
||||
m_thunderforestAPIKey = thunderforestAPIKey; |
||||
} |
||||
|
||||
void setMaptilerAPIKey(const QString& maptilerAPIKey) |
||||
{ |
||||
m_maptilerAPIKey = maptilerAPIKey; |
||||
} |
||||
|
||||
void setRadarPath(const QString& radarPath) |
||||
{ |
||||
m_radarPath = radarPath; |
||||
} |
||||
|
||||
void setSatellitePath(const QString& satellitePath) |
||||
{ |
||||
m_satellitePath = satellitePath; |
||||
} |
||||
|
||||
void setNASAGlobalImageryPath(const QString& nasaGlobalImageryPath) |
||||
{ |
||||
m_nasaGlobalImageryPath = nasaGlobalImageryPath; |
||||
} |
||||
|
||||
void setNASAGlobalImageryFormat(const QString& nasaGlobalImageryFormat) |
||||
{ |
||||
m_nasaGlobalImageryFormat = nasaGlobalImageryFormat; |
||||
} |
||||
|
||||
void setDisplaySeaMarks(bool displaySeaMarks) |
||||
{ |
||||
m_displaySeaMarks = displaySeaMarks; |
||||
} |
||||
|
||||
void setDisplayRailways(bool displayRailways) |
||||
{ |
||||
m_displayRailways = displayRailways; |
||||
} |
||||
|
||||
void setDisplayRain(bool displayRain) |
||||
{ |
||||
m_displayRain = displayRain; |
||||
} |
||||
|
||||
void setDisplayClouds(bool displayClouds) |
||||
{ |
||||
m_displayClouds = displayClouds; |
||||
} |
||||
|
||||
void setDisplayNASAGlobalImagery(bool displayNASAGlobalImagery) |
||||
{ |
||||
m_displayNASAGlobalImagery = displayNASAGlobalImagery; |
||||
} |
||||
|
||||
void incomingConnection(qintptr socket) override |
||||
{ |
||||
QTcpSocket* s = new QTcpSocket(this); |
||||
connect(s, SIGNAL(readyRead()), this, SLOT(readClient())); |
||||
connect(s, SIGNAL(disconnected()), this, SLOT(discardClient())); |
||||
s->setSocketDescriptor(socket); |
||||
//addPendingConnection(socket);
|
||||
} |
||||
|
||||
bool isHttpRedirect(QNetworkReply *reply) |
||||
{ |
||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); |
||||
// 304 is file not changed, but maybe we did
|
||||
return (status >= 301 && status <= 308); |
||||
} |
||||
|
||||
QNetworkReply *download(const QUrl &url) |
||||
{ |
||||
QNetworkRequest request(url); |
||||
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); |
||||
request.setRawHeader("User-Agent", "SDRangel"); // Required by a.tile.openstreetmap.org
|
||||
|
||||
// Don't cache rainviwer data as it's dynamic
|
||||
if (!url.toString().contains("tilecache.rainviewer")) { |
||||
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); |
||||
} |
||||
|
||||
QNetworkReply *reply = m_manager.get(request); |
||||
connect(reply, &QNetworkReply::sslErrors, this, &MapTileServer::sslErrors); |
||||
//qDebug() << "MapTileServer: Downloading from " << url;
|
||||
return reply; |
||||
} |
||||
|
||||
QImage combine(const TileJob *job) |
||||
{ |
||||
// Don't use job->m_images[job->m_urls[0]].size() as not always valid (E.g. map tiler can return http 204 - no content)
|
||||
// Do we need to support 512x512?
|
||||
QImage image(QSize(256, 256), QImage::Format_ARGB32_Premultiplied); |
||||
image.fill(qPremultiply(QColor(0, 0, 0, 0).rgba())); |
||||
QPainter painter(&image); |
||||
|
||||
for (int i = 0; i < job->m_images.size(); i++) { |
||||
const QImage &img = job->m_images[job->m_urls[i]]; |
||||
//qDebug() << "Image format " << i << " is " << img.format() << img.size();
|
||||
} |
||||
|
||||
for (int i = 0; i < job->m_images.size(); i++) { |
||||
const QImage &img = job->m_images[job->m_urls[i]]; |
||||
//img.save(QString("in%1.png").arg(i), "PNG");
|
||||
if (img.format() != QImage::Format_Invalid) { |
||||
painter.drawImage(image.rect(), img); |
||||
} |
||||
} |
||||
|
||||
return image; |
||||
} |
||||
|
||||
void replyImage(QTcpSocket* socket, const QImage& image, const QString& format) |
||||
{ |
||||
QByteArray ba; |
||||
QBuffer buffer(&ba); |
||||
buffer.open(QIODevice::WriteOnly); |
||||
image.save(&buffer, qPrintable(format)); |
||||
|
||||
//qDebug() << "socket: " << socket << "thread:" << QThread::currentThread();
|
||||
socket->write("HTTP/1.0 200 Ok\r\n" |
||||
"Content-Type: image/png\r\n" |
||||
"\r\n"); |
||||
socket->write(buffer.buffer()); |
||||
socket->close(); |
||||
|
||||
if (socket->state() == QTcpSocket::UnconnectedState) { |
||||
delete socket; |
||||
} |
||||
} |
||||
|
||||
void replyError(QTcpSocket* socket) |
||||
{ |
||||
QTextStream os(socket); |
||||
os.setAutoDetectUnicode(true); |
||||
os << "HTTP/1.0 404 Not Found\r\n" |
||||
"Content-Type: text/html\r\n" |
||||
"\r\n" |
||||
"<html>Not found</html>\r\n"; |
||||
socket->close(); |
||||
|
||||
if (socket->state() == QTcpSocket::UnconnectedState) { |
||||
delete socket; |
||||
} |
||||
} |
||||
|
||||
private slots: |
||||
|
||||
void readClient() |
||||
{ |
||||
QMutexLocker locker(&m_mutex); |
||||
|
||||
QTcpSocket* socket = (QTcpSocket*)sender(); |
||||
if (socket->canReadLine()) |
||||
{ |
||||
QString line = socket->readLine(); |
||||
qDebug() << "HTTP Request: " << line; |
||||
QStringList tokens = QString(line).split(QRegularExpression("[ \r\n][ \r\n]*")); |
||||
if (tokens[0] == "GET") |
||||
{ |
||||
QString xml = ""; |
||||
|
||||
// Create multiple requests for each image
|
||||
// https://wiki.openstreetmap.org/wiki/Raster_tile_providers
|
||||
// rain radar: https://tilecache.rainviewer.com/v2/radar/{timestamp=1705359600}/{size=256}/z/x/y/{color=0}/{options=1_1}.png
|
||||
|
||||
// "GET /street/1/2/3.png HTTP/1.1\r\n"
|
||||
const QRegularExpression re("\\/([A-Za-z0-9\\-_]+)\\/([0-9]+)\\/([0-9]+)\\/([0-9]+).(png|jpg)"); |
||||
QRegularExpressionMatch match = re.match(tokens[1]); |
||||
if (match.hasMatch()) |
||||
{ |
||||
QString map, x, y, z, format; |
||||
|
||||
map = match.captured(1); |
||||
z = match.captured(2); |
||||
x = match.captured(3); |
||||
y = match.captured(4); |
||||
format = match.captured(5); |
||||
|
||||
TileJob *job = new TileJob; |
||||
//qDebug() << "Created job" << job << "socket:" << socket << "thread:" << QThread::currentThread() ;
|
||||
job->m_socket = socket; |
||||
if (format == "png") { |
||||
job->m_format = "PNG"; |
||||
} else { |
||||
job->m_format = "JPG"; |
||||
} |
||||
|
||||
// This should match code in OSMTemplateServer::readClient
|
||||
QString baseMapURL; |
||||
if (map == "street") { |
||||
baseMapURL = QString("https://tile.openstreetmap.org/%3/%1/%2.png").arg(x).arg(y).arg(z); |
||||
} else if (map == "satellite") { |
||||
baseMapURL = QString("https://api.maptiler.com/tiles/satellite-v2/%3/%1/%2.jpg?key=%4").arg(x).arg(y).arg(z).arg(m_maptilerAPIKey); |
||||
} else if ((map == "dark_nolabels") || (map == "light_nolabels")) { |
||||
baseMapURL = QString("http://1.basemaps.cartocdn.com/%4/%3/%1/%2.png").arg(x).arg(y).arg(z).arg(map); |
||||
} else { |
||||
baseMapURL = QString("http://a.tile.thunderforest.com/%4/%3/%1/%2.png?apikey=%5").arg(x).arg(y).arg(z).arg(map).arg(m_thunderforestAPIKey); |
||||
} |
||||
|
||||
job->m_urls.append(baseMapURL); |
||||
if (m_displaySeaMarks) { |
||||
job->m_urls.append(QString("https://tiles.openseamap.org/seamark/%3/%1/%2.png").arg(x).arg(y).arg(z)); |
||||
} |
||||
if (m_displayRailways) { |
||||
job->m_urls.append(QString("https://a.tiles.openrailwaymap.org/standard/%3/%1/%2.png").arg(x).arg(y).arg(z)); |
||||
} |
||||
if (m_displayNASAGlobalImagery && !m_nasaGlobalImageryPath.isEmpty()) { |
||||
job->m_urls.append(QString("https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/%4/%3/%2/%1.%5").arg(x).arg(y).arg(z).arg(m_nasaGlobalImageryPath).arg(m_nasaGlobalImageryFormat)); // x,y reversed compared to others
|
||||
} |
||||
if (m_displayClouds && !m_satellitePath.isEmpty()) { |
||||
job->m_urls.append(QString("https://tilecache.rainviewer.com%4/256/%3/%1/%2/0/0_0.png").arg(x).arg(y).arg(z).arg(m_satellitePath)); |
||||
} |
||||
if (m_displayRain && !m_radarPath.isEmpty()) { |
||||
job->m_urls.append(QString("https://tilecache.rainviewer.com%4/256/%3/%1/%2/4/1_1.png").arg(x).arg(y).arg(z).arg(m_radarPath)); |
||||
} |
||||
m_tileJobs.append(job); |
||||
for (const auto& url : job->m_urls) |
||||
{ |
||||
QNetworkReply *reply = download(QUrl(url)); |
||||
m_replies.insert(reply, job); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
replyError(socket); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void discardClient() |
||||
{ |
||||
QTcpSocket* socket = (QTcpSocket*)sender(); |
||||
//qDebug() << "discardClient socket:" << socket;
|
||||
socket->deleteLater(); |
||||
for (auto job : m_tileJobs) { |
||||
if (job->m_socket == socket) { |
||||
//qDebug() << "Socket closed on active job. job: " << job << "socket" << socket;
|
||||
job->m_socket = nullptr; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void downloadFinished(QNetworkReply *reply) |
||||
{ |
||||
QMutexLocker locker(&m_mutex); |
||||
//QString url = reply->url().toEncoded().constData();
|
||||
QString url = reply->request().url().toEncoded().constData(); // reply->url() may differ if redirection occured, so use requested
|
||||
|
||||
if (!isHttpRedirect(reply)) |
||||
{ |
||||
QByteArray data = reply->readAll(); |
||||
QImage image; |
||||
if (!reply->error()) |
||||
{ |
||||
if (!image.loadFromData(data)) |
||||
{ |
||||
qDebug() << "MapTileServer::downloadFinished: Failed to load image: " << url; |
||||
} |
||||
else |
||||
{ |
||||
bool cached = reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute).toBool(); |
||||
//qDebug() << "Downloaded " << url << "as" << image.size() << "cached:" << cached;
|
||||
} |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "MapTileServer::downloadFinished: Error: " << reply->error() << "for" << url; |
||||
} |
||||
|
||||
bool found = false; |
||||
TileJob *job = m_replies[reply]; |
||||
if (!m_tileJobs.contains(job)) { |
||||
qDebug() << "job has been deleted!"; |
||||
} |
||||
for (const auto& jobURL : job->m_urls) |
||||
{ |
||||
if (jobURL == url) |
||||
{ |
||||
job->m_images.insert(url, image); |
||||
if (job->m_urls.size() == job->m_images.size()) |
||||
{ |
||||
// All images available
|
||||
QImage combinedImage = combine(job); |
||||
if (job->m_socket) |
||||
{ |
||||
replyImage(job->m_socket, combinedImage, job->m_format); |
||||
job->m_socket = nullptr; |
||||
m_tileJobs.removeAll(job); |
||||
delete job; |
||||
//qDebug() << "Delete job" << job;
|
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "Socket was null. URL: " << url << "job:" << job; |
||||
} |
||||
} |
||||
found = true; |
||||
break; |
||||
} |
||||
} |
||||
if (!found) { |
||||
qDebug() << "MapTileServer::downloadFinished: Failed to match URL: " << url; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "MapTileServer::downloadFinished: Redirect"; |
||||
} |
||||
reply->deleteLater(); |
||||
m_replies.remove(reply); |
||||
} |
||||
|
||||
void sslErrors(const QList<QSslError> &sslErrors) |
||||
{ |
||||
for (const QSslError &error : sslErrors) |
||||
{ |
||||
qCritical() << "MapTileServer: SSL error" << (int)error.error() << ": " << error.errorString(); |
||||
#ifdef ANDROID |
||||
// On Android 6 (but not on 12), we always seem to get: "The issuer certificate of a locally looked up certificate could not be found"
|
||||
// which causes downloads to fail, so ignore
|
||||
if (error.error() == QSslError::UnableToGetLocalIssuerCertificate) |
||||
{ |
||||
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender()); |
||||
QList<QSslError> errorsThatCanBeIgnored; |
||||
errorsThatCanBeIgnored << QSslError(QSslError::UnableToGetLocalIssuerCertificate, error.certificate()); |
||||
reply->ignoreSslErrors(errorsThatCanBeIgnored); |
||||
} |
||||
#endif |
||||
} |
||||
} |
||||
|
||||
}; |
||||
|
||||
#endif |
||||
@ -0,0 +1,198 @@
@@ -0,0 +1,198 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2024 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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 "kiwisdrlist.h" |
||||
|
||||
#include <QDebug> |
||||
#include <QUrl> |
||||
#include <QUrlQuery> |
||||
#include <QNetworkReply> |
||||
#include <QXmlStreamReader> |
||||
#include <QNetworkDiskCache> |
||||
#include <QRegularExpression> |
||||
|
||||
KiwiSDRList::KiwiSDRList() |
||||
{ |
||||
m_networkManager = new QNetworkAccessManager(); |
||||
QObject::connect(m_networkManager, &QNetworkAccessManager::finished, this, &KiwiSDRList::handleReply); |
||||
|
||||
QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); |
||||
QDir writeableDir(locations[0]); |
||||
if (!writeableDir.mkpath(QStringLiteral("cache") + QDir::separator() + QStringLiteral("kiwisdr"))) { |
||||
qDebug() << "Failed to create cache/kiwisdr"; |
||||
} |
||||
|
||||
m_cache = new QNetworkDiskCache(); |
||||
m_cache->setCacheDirectory(locations[0] + QDir::separator() + QStringLiteral("cache") + QDir::separator() + QStringLiteral("kiwisdr")); |
||||
m_cache->setMaximumCacheSize(100000000); |
||||
m_networkManager->setCache(m_cache); |
||||
|
||||
connect(&m_timer, &QTimer::timeout, this, &KiwiSDRList::update); |
||||
} |
||||
|
||||
KiwiSDRList::~KiwiSDRList() |
||||
{ |
||||
QObject::disconnect(m_networkManager, &QNetworkAccessManager::finished, this, &KiwiSDRList::handleReply); |
||||
delete m_networkManager; |
||||
} |
||||
|
||||
void KiwiSDRList::getData() |
||||
{ |
||||
QUrl url(QString("http://kiwisdr.com/public/")); |
||||
m_networkManager->get(QNetworkRequest(url)); |
||||
} |
||||
|
||||
void KiwiSDRList::getDataPeriodically(int periodInMins) |
||||
{ |
||||
m_timer.setInterval(periodInMins*60*1000); |
||||
m_timer.start(); |
||||
update(); |
||||
} |
||||
|
||||
void KiwiSDRList::update() |
||||
{ |
||||
getData(); |
||||
} |
||||
|
||||
void KiwiSDRList::handleReply(QNetworkReply* reply) |
||||
{ |
||||
if (reply) |
||||
{ |
||||
if (!reply->error()) |
||||
{ |
||||
QString url = reply->url().toEncoded().constData(); |
||||
QByteArray bytes = reply->readAll(); |
||||
|
||||
handleHTML(url, bytes); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "KiwiSDRList::handleReply: error: " << reply->error(); |
||||
} |
||||
reply->deleteLater(); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "KiwiSDRList::handleReply: reply is null"; |
||||
} |
||||
} |
||||
|
||||
void KiwiSDRList::handleHTML(const QString& url, const QByteArray& bytes) |
||||
{ |
||||
QList<KiwiSDR> sdrs; |
||||
QString html(bytes); |
||||
QRegularExpression div("<div class='cl-info'>(.*?)<\\/div>", QRegularExpression::DotMatchesEverythingOption); |
||||
QRegularExpressionMatchIterator divItr = div.globalMatch(html); |
||||
|
||||
if (divItr.hasNext()) |
||||
{ |
||||
while (divItr.hasNext()) |
||||
{ |
||||
QRegularExpressionMatch divMatch = divItr.next(); |
||||
QString divText = divMatch.captured(1); |
||||
QRegularExpression urlRe("a href='(.*?)'"); |
||||
QRegularExpressionMatch urlMatch = urlRe.match(divText); |
||||
|
||||
if (urlMatch.hasMatch()) |
||||
{ |
||||
KiwiSDR sdr; |
||||
|
||||
sdr.m_url = urlMatch.captured(1); |
||||
|
||||
QRegularExpression element("<!-- (\\w+)=(.*?) -->"); |
||||
QRegularExpressionMatchIterator elementItr = element.globalMatch(divText); |
||||
while(elementItr.hasNext()) |
||||
{ |
||||
QRegularExpressionMatch elementMatch = elementItr.next(); |
||||
QString key = elementMatch.captured(1); |
||||
QString value = elementMatch.captured(2); |
||||
|
||||
if (key == "name") |
||||
{ |
||||
sdr.m_name = value; |
||||
} |
||||
else if (key == "sdr_hw") |
||||
{ |
||||
sdr.m_sdrHW = value; |
||||
} |
||||
else if (key == "bands") |
||||
{ |
||||
QRegularExpression freqRe("([\\d]+)-([\\d]+)"); |
||||
QRegularExpressionMatch freqMatch = freqRe.match(value); |
||||
|
||||
if (freqMatch.hasMatch()) |
||||
{ |
||||
sdr.m_lowFrequency = freqMatch.captured(1).toInt(); |
||||
sdr.m_highFrequency = freqMatch.captured(2).toInt(); |
||||
} |
||||
} |
||||
else if (key == "users") |
||||
{ |
||||
sdr.m_users = value.toInt(); |
||||
} |
||||
else if (key == "users_max") |
||||
{ |
||||
sdr.m_usersMax = value.toInt(); |
||||
} |
||||
else if (key == "gps") |
||||
{ |
||||
QRegularExpression gpsRe("([\\d.+-]+), ([\\d.+-]+)"); |
||||
QRegularExpressionMatch gpsMatch = gpsRe.match(value); |
||||
|
||||
if (gpsMatch.hasMatch()) |
||||
{ |
||||
sdr.m_latitude = gpsMatch.captured(1).toFloat(); |
||||
sdr.m_longitude = gpsMatch.captured(2).toFloat(); |
||||
} |
||||
} |
||||
else if (key == "asl") |
||||
{ |
||||
sdr.m_altitude = value.toInt(); |
||||
} |
||||
else if (key == "loc") |
||||
{ |
||||
sdr.m_location = value.toInt(); |
||||
} |
||||
else if (key == "antenna") |
||||
{ |
||||
sdr.m_antenna = value; |
||||
} |
||||
else if (key == "ant_connected") |
||||
{ |
||||
sdr.m_antennaConnected = value == "1"; |
||||
} |
||||
else if (key == "snr") |
||||
{ |
||||
sdr.m_snr = value; |
||||
} |
||||
} |
||||
|
||||
sdrs.append(sdr); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "KiwiSDRPublic::handleHTML: No URL found in:\n" << divText; |
||||
} |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "KiwiSDRPublic::handleHTML: No cl-info found in:\n" << html; |
||||
} |
||||
|
||||
emit dataUpdated(sdrs); |
||||
} |
||||
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2024 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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_KIWISDRLIST_H |
||||
#define INCLUDE_KIWISDRLIST_H |
||||
|
||||
#include <QtCore> |
||||
#include <QTimer> |
||||
|
||||
#include "export.h" |
||||
|
||||
class QNetworkAccessManager; |
||||
class QNetworkReply; |
||||
class QNetworkDiskCache; |
||||
|
||||
// Gets a list of public Kiwi SDRs from http://kiwisdr.com/public/
|
||||
class SDRBASE_API KiwiSDRList : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
|
||||
struct KiwiSDR { |
||||
QString m_url; |
||||
QString m_status; // Only seems to be 'active'
|
||||
QString m_offline; // Only seems to be 'no'
|
||||
QString m_name; |
||||
QString m_sdrHW; |
||||
qint64 m_lowFrequency; |
||||
qint64 m_highFrequency; |
||||
int m_users; |
||||
int m_usersMax; |
||||
float m_latitude; |
||||
float m_longitude; |
||||
int m_altitude; // Above sea level (Not sure if ft or m)
|
||||
QString m_location; |
||||
QString m_antenna; |
||||
bool m_antennaConnected; |
||||
QString m_snr; |
||||
}; |
||||
|
||||
KiwiSDRList(); |
||||
~KiwiSDRList(); |
||||
|
||||
void getData(); |
||||
void getDataPeriodically(int periodInMins=4); |
||||
|
||||
public slots: |
||||
void handleReply(QNetworkReply* reply); |
||||
void update(); |
||||
|
||||
signals: |
||||
void dataUpdated(const QList<KiwiSDR>& sdrs); // Emitted when data are available.
|
||||
|
||||
private: |
||||
QNetworkAccessManager *m_networkManager; |
||||
QNetworkDiskCache *m_cache; |
||||
QTimer m_timer; // Timer for periodic updates
|
||||
|
||||
void handleHTML(const QString& url, const QByteArray& bytes); |
||||
|
||||
}; |
||||
|
||||
#endif /* INCLUDE_KIWISDRLIST_H */ |
||||
@ -0,0 +1,326 @@
@@ -0,0 +1,326 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2024 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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 "nasaglobalimagery.h" |
||||
|
||||
#include <QDebug> |
||||
#include <QUrl> |
||||
#include <QUrlQuery> |
||||
#include <QNetworkReply> |
||||
#include <QXmlStreamReader> |
||||
#include <QNetworkDiskCache> |
||||
#include <QJsonDocument> |
||||
#include <QJsonObject> |
||||
|
||||
NASAGlobalImagery::NASAGlobalImagery() |
||||
{ |
||||
m_networkManager = new QNetworkAccessManager(); |
||||
QObject::connect(m_networkManager, &QNetworkAccessManager::finished, this, &NASAGlobalImagery::handleReply); |
||||
|
||||
QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); |
||||
QDir writeableDir(locations[0]); |
||||
if (!writeableDir.mkpath(QStringLiteral("cache") + QDir::separator() + QStringLiteral("nasaglobalimagery"))) { |
||||
qDebug() << "Failed to create cache/nasaglobalimagery"; |
||||
} |
||||
|
||||
m_cache = new QNetworkDiskCache(); |
||||
m_cache->setCacheDirectory(locations[0] + QDir::separator() + QStringLiteral("cache") + QDir::separator() + QStringLiteral("nasaglobalimagery")); |
||||
m_cache->setMaximumCacheSize(100000000); |
||||
m_networkManager->setCache(m_cache); |
||||
} |
||||
|
||||
NASAGlobalImagery::~NASAGlobalImagery() |
||||
{ |
||||
QObject::disconnect(m_networkManager, &QNetworkAccessManager::finished, this, &NASAGlobalImagery::handleReply); |
||||
delete m_networkManager; |
||||
} |
||||
|
||||
void NASAGlobalImagery::getData() |
||||
{ |
||||
QUrl url(QString("https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/1.0.0/WMTSCapabilities.xml")); |
||||
m_networkManager->get(QNetworkRequest(url)); |
||||
} |
||||
|
||||
void NASAGlobalImagery::getMetaData() |
||||
{ |
||||
QUrl url(QString("https://worldview.earthdata.nasa.gov/config/wv.json")); |
||||
m_networkManager->get(QNetworkRequest(url)); |
||||
} |
||||
|
||||
void NASAGlobalImagery::handleReply(QNetworkReply* reply) |
||||
{ |
||||
if (reply) |
||||
{ |
||||
if (!reply->error()) |
||||
{ |
||||
QString url = reply->url().toEncoded().constData(); |
||||
QByteArray bytes = reply->readAll(); |
||||
|
||||
if (url.endsWith(".xml")) { |
||||
handleXML(bytes); |
||||
} else if (url.endsWith(".svg")) { |
||||
handleSVG(url, bytes); |
||||
} else if (url.endsWith(".json")) { |
||||
handleJSON(bytes); |
||||
} else if (url.endsWith(".html")) { |
||||
handleHTML(url, bytes); |
||||
} else { |
||||
qDebug() << "NASAGlobalImagery::handleReply: unexpected URL: " << url; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "NASAGlobalImagery::handleReply: error: " << reply->error(); |
||||
} |
||||
reply->deleteLater(); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "NASAGlobalImagery::handleReply: reply is null"; |
||||
} |
||||
} |
||||
|
||||
void NASAGlobalImagery::handleXML(const QByteArray& bytes) |
||||
{ |
||||
QXmlStreamReader xmlReader(bytes); |
||||
QList<DataSet> dataSets; |
||||
|
||||
while (!xmlReader.atEnd() && !xmlReader.hasError()) |
||||
{ |
||||
while (xmlReader.readNextStartElement()) |
||||
{ |
||||
if (xmlReader.name() == QLatin1String("Capabilities")) |
||||
{ |
||||
while(xmlReader.readNextStartElement()) |
||||
{ |
||||
if (xmlReader.name() == QLatin1String("Contents")) |
||||
{ |
||||
while(xmlReader.readNextStartElement()) |
||||
{ |
||||
if (xmlReader.name() == QLatin1String("Layer")) |
||||
{ |
||||
QString identifier; |
||||
QString colorMap; |
||||
QList<Legend> legends; |
||||
QString tileMatrixSet; |
||||
QStringList urls; |
||||
QString format; |
||||
QString defaultDateTime; |
||||
QStringList dates; |
||||
|
||||
while(xmlReader.readNextStartElement()) |
||||
{ |
||||
if (xmlReader.name() == QLatin1String("Identifier")) |
||||
{ |
||||
identifier = xmlReader.readElementText(); |
||||
} |
||||
else if (xmlReader.name() == QLatin1String("TileMatrixSetLink")) |
||||
{ |
||||
while(xmlReader.readNextStartElement()) |
||||
{ |
||||
if (xmlReader.name() == QLatin1String("TileMatrixSet")) |
||||
{ |
||||
tileMatrixSet = xmlReader.readElementText(); |
||||
} |
||||
else |
||||
{ |
||||
xmlReader.skipCurrentElement(); |
||||
} |
||||
} |
||||
} |
||||
else if (xmlReader.name() == QLatin1String("Style")) |
||||
{ |
||||
while(xmlReader.readNextStartElement()) |
||||
{ |
||||
if (xmlReader.name() == QLatin1String("LegendURL")) |
||||
{ |
||||
Legend legend; |
||||
|
||||
legend.m_url = xmlReader.attributes().value("xlink:href").toString(); |
||||
legend.m_width = (int)xmlReader.attributes().value("width").toFloat(); |
||||
legend.m_height = (int)xmlReader.attributes().value("height").toFloat(); |
||||
//qDebug() << legend.m_url << legend.m_width << legend.m_height;
|
||||
legends.append(legend); |
||||
xmlReader.skipCurrentElement(); |
||||
} |
||||
else |
||||
{ |
||||
xmlReader.skipCurrentElement(); |
||||
} |
||||
} |
||||
} |
||||
else if (xmlReader.name() == QLatin1String("Metadata")) |
||||
{ |
||||
colorMap = xmlReader.attributes().value("xlink:href").toString(); |
||||
xmlReader.skipCurrentElement(); |
||||
} |
||||
else if (xmlReader.name() == QLatin1String("Format")) |
||||
{ |
||||
format = xmlReader.readElementText(); |
||||
} |
||||
else if (xmlReader.name() == QLatin1String("ResourceURL")) |
||||
{ |
||||
QString url = xmlReader.attributes().value("template").toString(); |
||||
if (!url.isEmpty()) { |
||||
urls.append(url); |
||||
} |
||||
xmlReader.skipCurrentElement(); |
||||
} |
||||
else if (xmlReader.name() == QLatin1String("Dimension")) |
||||
{ |
||||
while(xmlReader.readNextStartElement()) |
||||
{ |
||||
if (xmlReader.name() == QLatin1String("Default")) |
||||
{ |
||||
defaultDateTime = xmlReader.readElementText(); |
||||
} |
||||
else if (xmlReader.name() == QLatin1String("Value")) |
||||
{ |
||||
dates.append(xmlReader.readElementText()); |
||||
} |
||||
else |
||||
{ |
||||
xmlReader.skipCurrentElement(); |
||||
} |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
xmlReader.skipCurrentElement(); |
||||
} |
||||
} |
||||
|
||||
// Some layers are <Format>application/vnd.mapbox-vector-tile</Format>
|
||||
if (!identifier.isEmpty() && !tileMatrixSet.isEmpty() && ((format == "image/png") || (format == "image/jpeg"))) |
||||
{ |
||||
DataSet dataSet; |
||||
dataSet.m_identifier = identifier; |
||||
dataSet.m_legends = legends; |
||||
dataSet.m_tileMatrixSet = tileMatrixSet; |
||||
dataSet.m_format = format; |
||||
dataSet.m_defaultDateTime = defaultDateTime; |
||||
dataSet.m_dates = dates; |
||||
dataSets.append(dataSet); |
||||
|
||||
//qDebug() << "Adding layer" << identifier << colorMap << legends << tileMatrixSet;
|
||||
} |
||||
|
||||
} |
||||
else |
||||
{ |
||||
xmlReader.skipCurrentElement(); |
||||
} |
||||
} |
||||
} |
||||
else if (xmlReader.name() == QLatin1String("ServiceMetadataURL")) |
||||
{ |
||||
// Empty?
|
||||
} |
||||
else |
||||
{ |
||||
xmlReader.skipCurrentElement(); |
||||
} |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
xmlReader.skipCurrentElement(); |
||||
} |
||||
} |
||||
} |
||||
// Ignore "Premature end of document." here even if ok
|
||||
if (!xmlReader.atEnd() && xmlReader.hasError()) |
||||
{ |
||||
qDebug() << "NASAGlobalImagery::handleReply: Error parsing XML: " << xmlReader.errorString(); |
||||
} |
||||
|
||||
emit dataUpdated(dataSets); |
||||
} |
||||
|
||||
void NASAGlobalImagery::downloadLegend(const Legend& legend) |
||||
{ |
||||
QUrl url(legend.m_url); |
||||
m_networkManager->get(QNetworkRequest(url)); |
||||
} |
||||
|
||||
void NASAGlobalImagery::downloadHTML(const QString& urlString) |
||||
{ |
||||
QUrl url(urlString); |
||||
m_networkManager->get(QNetworkRequest(url)); |
||||
} |
||||
|
||||
void NASAGlobalImagery::handleSVG(const QString& url, const QByteArray& bytes) |
||||
{ |
||||
emit legendAvailable(url, bytes); |
||||
} |
||||
|
||||
void NASAGlobalImagery::handleJSON(const QByteArray& bytes) |
||||
{ |
||||
MetaData metaData; |
||||
|
||||
QJsonDocument document = QJsonDocument::fromJson(bytes); |
||||
if (document.isObject()) |
||||
{ |
||||
QJsonObject obj = document.object(); |
||||
if (obj.contains(QStringLiteral("layers"))) |
||||
{ |
||||
for (const auto& oRef : obj.value(QStringLiteral("layers")).toObject()) |
||||
{ |
||||
Layer layer; |
||||
QJsonObject o = oRef.toObject(); |
||||
|
||||
if (o.contains(QStringLiteral("id"))) { |
||||
layer.m_identifier = o.value(QStringLiteral("id")).toString(); |
||||
} |
||||
if (o.contains(QStringLiteral("title"))) { |
||||
layer.m_title = o.value(QStringLiteral("title")).toString(); |
||||
} |
||||
if (o.contains(QStringLiteral("subtitle"))) { |
||||
layer.m_subtitle = o.value(QStringLiteral("subtitle")).toString(); |
||||
} |
||||
if (o.contains(QStringLiteral("description"))) { |
||||
layer.m_descriptionURL = "https://worldview.earthdata.nasa.gov/config/metadata/layers/" + o.value(QStringLiteral("description")).toString() + ".html"; |
||||
} |
||||
if (o.contains(QStringLiteral("startDate"))) { |
||||
layer.m_startDate = QDateTime::fromString(o.value(QStringLiteral("startDate")).toString(), Qt::ISODate); |
||||
} |
||||
if (o.contains(QStringLiteral("endDate"))) { |
||||
layer.m_endDate = QDateTime::fromString(o.value(QStringLiteral("endDate")).toString(), Qt::ISODate); |
||||
} |
||||
if (o.contains(QStringLiteral("ongoing"))) { |
||||
layer.m_ongoing = o.value(QStringLiteral("ongoing")).toBool(); |
||||
} |
||||
if (o.contains(QStringLiteral("layerPeriod"))) { |
||||
layer.m_layerPeriod = o.value(QStringLiteral("layerPeriod")).toString(); |
||||
} |
||||
if (o.contains(QStringLiteral("layergroup"))) { |
||||
layer.m_layerGroup = o.value(QStringLiteral("layergroup")).toString(); |
||||
} |
||||
if (!layer.m_identifier.isEmpty()) { |
||||
metaData.m_layers.insert(layer.m_identifier, layer); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
emit metaDataUpdated(metaData); |
||||
} |
||||
|
||||
void NASAGlobalImagery::handleHTML(const QString& url, const QByteArray& bytes) |
||||
{ |
||||
emit htmlAvailable(url, bytes); |
||||
} |
||||
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2024 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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_NASAGLOBALIMAGERY_H |
||||
#define INCLUDE_NASAGLOBALIMAGERY_H |
||||
|
||||
#include <QtCore> |
||||
#include <QTimer> |
||||
|
||||
#include "export.h" |
||||
|
||||
class QNetworkAccessManager; |
||||
class QNetworkReply; |
||||
class QNetworkDiskCache; |
||||
|
||||
// NASA GIBS (Global Imagery Browse Server) API (https://nasa-gibs.github.io/gibs-api-docs/)
|
||||
// Gets details of available data sets for use on maps
|
||||
// Also supports cached download of .svg legends
|
||||
class SDRBASE_API NASAGlobalImagery : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
|
||||
struct Legend { |
||||
QString m_url; // Typically to .svg file
|
||||
int m_width; |
||||
int m_height; |
||||
}; |
||||
|
||||
struct DataSet { |
||||
QString m_identifier; |
||||
QList<Legend> m_legends; |
||||
QString m_tileMatrixSet; |
||||
QString m_format; |
||||
QString m_defaultDateTime; |
||||
QStringList m_dates; |
||||
}; |
||||
|
||||
struct Layer { |
||||
QString m_identifier; |
||||
QString m_title; |
||||
QString m_subtitle; |
||||
QString m_descriptionURL; |
||||
QDateTime m_startDate; |
||||
QDateTime m_endDate; |
||||
bool m_ongoing; |
||||
QString m_layerPeriod; |
||||
QString m_layerGroup; |
||||
}; |
||||
|
||||
struct MetaData { |
||||
QHash<QString, Layer> m_layers; |
||||
}; |
||||
|
||||
NASAGlobalImagery(); |
||||
~NASAGlobalImagery(); |
||||
|
||||
void getData(); |
||||
void getMetaData(); |
||||
void downloadLegend(const Legend& legend); |
||||
void downloadHTML(const QString& url); |
||||
|
||||
public slots: |
||||
void handleReply(QNetworkReply* reply); |
||||
|
||||
signals: |
||||
void dataUpdated(const QList<DataSet>& dataSets); // Emitted when paths to new data are available.
|
||||
void metaDataUpdated(const MetaData& metaData); |
||||
void legendAvailable(const QString& url, const QByteArray data); |
||||
void htmlAvailable(const QString& url, const QByteArray data); |
||||
|
||||
private: |
||||
QNetworkAccessManager *m_networkManager; |
||||
QNetworkDiskCache *m_cache; |
||||
|
||||
void handleXML(const QByteArray& bytes); |
||||
void handleSVG(const QString& url, const QByteArray& bytes); |
||||
void handleJSON(const QByteArray& bytes); |
||||
void handleHTML(const QString& url, const QByteArray& bytes); |
||||
|
||||
}; |
||||
|
||||
#endif /* INCLUDE_NASAGLOBALIMAGERY_H */ |
||||
@ -0,0 +1,130 @@
@@ -0,0 +1,130 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2024 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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 "rainviewer.h" |
||||
|
||||
#include <QDebug> |
||||
#include <QUrl> |
||||
#include <QUrlQuery> |
||||
#include <QNetworkReply> |
||||
#include <QJsonDocument> |
||||
#include <QJsonObject> |
||||
|
||||
RainViewer::RainViewer() |
||||
{ |
||||
connect(&m_timer, &QTimer::timeout, this, &RainViewer::update); |
||||
m_networkManager = new QNetworkAccessManager(); |
||||
QObject::connect(m_networkManager, &QNetworkAccessManager::finished, this, &RainViewer::handleReply); |
||||
} |
||||
|
||||
RainViewer::~RainViewer() |
||||
{ |
||||
m_timer.stop(); |
||||
QObject::disconnect(m_networkManager, &QNetworkAccessManager::finished, this, &RainViewer::handleReply); |
||||
delete m_networkManager; |
||||
} |
||||
|
||||
void RainViewer::getPathPeriodically(int periodInMins) |
||||
{ |
||||
// Rain maps updated every 10mins
|
||||
m_timer.setInterval(periodInMins*60*1000); |
||||
m_timer.start(); |
||||
update(); |
||||
} |
||||
|
||||
void RainViewer::update() |
||||
{ |
||||
getPath(); |
||||
} |
||||
|
||||
void RainViewer::getPath() |
||||
{ |
||||
QUrl url(QString("https://api.rainviewer.com/public/weather-maps.json")); |
||||
m_networkManager->get(QNetworkRequest(url)); |
||||
} |
||||
|
||||
void RainViewer::handleReply(QNetworkReply* reply) |
||||
{ |
||||
if (reply) |
||||
{ |
||||
if (!reply->error()) |
||||
{ |
||||
QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); |
||||
if (document.isObject()) |
||||
{ |
||||
QJsonObject obj = document.object(); |
||||
QString radarPath = ""; |
||||
QString satellitePath = ""; |
||||
|
||||
if (obj.contains(QStringLiteral("radar"))) |
||||
{ |
||||
QJsonValue val = obj.value(QStringLiteral("radar")); |
||||
QJsonObject mainObj = val.toObject(); |
||||
if (mainObj.contains(QStringLiteral("past"))) |
||||
{ |
||||
QJsonArray past = mainObj.value(QStringLiteral("past")).toArray(); |
||||
if (past.size() > 0) |
||||
{ |
||||
QJsonObject mostRecent = past.last().toObject(); |
||||
if (mostRecent.contains(QStringLiteral("path"))) { |
||||
radarPath = mostRecent.value(QStringLiteral("path")).toString(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "RainViewer::handleReply: Object doesn't contain a radar: " << obj; |
||||
} |
||||
if (obj.contains(QStringLiteral("satellite"))) |
||||
{ |
||||
QJsonValue val = obj.value(QStringLiteral("satellite")); |
||||
QJsonObject mainObj = val.toObject(); |
||||
if (mainObj.contains(QStringLiteral("infrared"))) |
||||
{ |
||||
QJsonArray ir = mainObj.value(QStringLiteral("infrared")).toArray(); |
||||
if (ir.size() > 0) |
||||
{ |
||||
QJsonObject mostRecent = ir.last().toObject(); |
||||
if (mostRecent.contains(QStringLiteral("path"))) { |
||||
satellitePath = mostRecent.value(QStringLiteral("path")).toString(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "RainViewer::handleReply: Object doesn't contain a satellite: " << obj; |
||||
} |
||||
emit pathUpdated(radarPath, satellitePath); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "RainViewer::handleReply: Document is not an object: " << document; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "RainViewer::handleReply: error: " << reply->error(); |
||||
} |
||||
reply->deleteLater(); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "RainViewer::handleReply: reply is null"; |
||||
} |
||||
} |
||||
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2024 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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_RAINVIEWER_H |
||||
#define INCLUDE_RAINVIEWER_H |
||||
|
||||
#include <QtCore> |
||||
#include <QTimer> |
||||
|
||||
#include "export.h" |
||||
|
||||
class QNetworkAccessManager; |
||||
class QNetworkReply; |
||||
|
||||
// RainViewer API wrapper (https://www.rainviewer.com/)
|
||||
// Gets details of currently available weather radar and satellite IR data
|
||||
class SDRBASE_API RainViewer : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
RainViewer(); |
||||
~RainViewer(); |
||||
|
||||
void getPath(); |
||||
void getPathPeriodically(int periodInMins=15); |
||||
|
||||
public slots: |
||||
void update(); |
||||
void handleReply(QNetworkReply* reply); |
||||
|
||||
signals: |
||||
void pathUpdated(const QString& radarPath, const QString& satellitePath); // Emitted when paths to new data are available.
|
||||
|
||||
private: |
||||
QTimer m_timer; // Timer for periodic updates
|
||||
QNetworkAccessManager *m_networkManager; |
||||
|
||||
}; |
||||
|
||||
#endif /* INCLUDE_RAINVIEWER_H */ |
||||
@ -0,0 +1,164 @@
@@ -0,0 +1,164 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2024 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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 "spyserverlist.h" |
||||
|
||||
#include <QDebug> |
||||
#include <QUrl> |
||||
#include <QUrlQuery> |
||||
#include <QNetworkReply> |
||||
#include <QXmlStreamReader> |
||||
#include <QNetworkDiskCache> |
||||
#include <QRegularExpression> |
||||
|
||||
SpyServerList::SpyServerList() |
||||
{ |
||||
m_networkManager = new QNetworkAccessManager(); |
||||
QObject::connect(m_networkManager, &QNetworkAccessManager::finished, this, &SpyServerList::handleReply); |
||||
|
||||
QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); |
||||
QDir writeableDir(locations[0]); |
||||
if (!writeableDir.mkpath(QStringLiteral("cache") + QDir::separator() + QStringLiteral("spyserver"))) { |
||||
qDebug() << "Failed to create cache/spyserver"; |
||||
} |
||||
|
||||
m_cache = new QNetworkDiskCache(); |
||||
m_cache->setCacheDirectory(locations[0] + QDir::separator() + QStringLiteral("cache") + QDir::separator() + QStringLiteral("spyserver")); |
||||
m_cache->setMaximumCacheSize(100000000); |
||||
m_networkManager->setCache(m_cache); |
||||
|
||||
connect(&m_timer, &QTimer::timeout, this, &SpyServerList::update); |
||||
} |
||||
|
||||
SpyServerList::~SpyServerList() |
||||
{ |
||||
QObject::disconnect(m_networkManager, &QNetworkAccessManager::finished, this, &SpyServerList::handleReply); |
||||
delete m_networkManager; |
||||
} |
||||
|
||||
void SpyServerList::getData() |
||||
{ |
||||
QUrl url(QString("https://airspy.com/directory/status.json")); |
||||
m_networkManager->get(QNetworkRequest(url)); |
||||
} |
||||
|
||||
void SpyServerList::getDataPeriodically(int periodInMins) |
||||
{ |
||||
m_timer.setInterval(periodInMins*60*1000); |
||||
m_timer.start(); |
||||
update(); |
||||
} |
||||
|
||||
void SpyServerList::update() |
||||
{ |
||||
getData(); |
||||
} |
||||
|
||||
void SpyServerList::handleReply(QNetworkReply* reply) |
||||
{ |
||||
if (reply) |
||||
{ |
||||
if (!reply->error()) |
||||
{ |
||||
QString url = reply->url().toEncoded().constData(); |
||||
QByteArray bytes = reply->readAll(); |
||||
|
||||
handleJSON(url, bytes); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "SpyServerList::handleReply: error: " << reply->error(); |
||||
} |
||||
reply->deleteLater(); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "SpyServerList::handleReply: reply is null"; |
||||
} |
||||
} |
||||
|
||||
void SpyServerList::handleJSON(const QString& url, const QByteArray& bytes) |
||||
{ |
||||
QList<SpyServer> sdrs; |
||||
QJsonDocument document = QJsonDocument::fromJson(bytes); |
||||
|
||||
if (document.isObject()) |
||||
{ |
||||
QJsonObject obj = document.object(); |
||||
if (obj.contains(QStringLiteral("servers"))) |
||||
{ |
||||
QJsonArray servers = obj.value(QStringLiteral("servers")).toArray(); |
||||
|
||||
for (auto valRef : servers) |
||||
{ |
||||
if (valRef.isObject()) |
||||
{ |
||||
QJsonObject serverObj = valRef.toObject(); |
||||
SpyServer sdr; |
||||
|
||||
if (serverObj.contains(QStringLiteral("generalDescription"))) { |
||||
sdr.m_generalDescription = serverObj.value(QStringLiteral("generalDescription")).toString(); |
||||
} |
||||
if (serverObj.contains(QStringLiteral("deviceType"))) { |
||||
sdr.m_deviceType = serverObj.value(QStringLiteral("deviceType")).toString(); |
||||
} |
||||
if (serverObj.contains(QStringLiteral("streamingHost"))) { |
||||
sdr.m_streamingHost = serverObj.value(QStringLiteral("streamingHost")).toString(); |
||||
} |
||||
if (serverObj.contains(QStringLiteral("streamingPort"))) { |
||||
sdr.m_streamingPort = serverObj.value(QStringLiteral("streamingPort")).toInt(); |
||||
} |
||||
if (serverObj.contains(QStringLiteral("currentClientCount"))) { |
||||
sdr.m_currentClientCount = serverObj.value(QStringLiteral("currentClientCount")).toInt(); |
||||
} |
||||
if (serverObj.contains(QStringLiteral("maxClients"))) { |
||||
sdr.m_maxClients = serverObj.value(QStringLiteral("maxClients")).toInt(); |
||||
} |
||||
if (serverObj.contains(QStringLiteral("antennaType"))) { |
||||
sdr.m_antennaType = serverObj.value(QStringLiteral("antennaType")).toString(); |
||||
} |
||||
if (serverObj.contains(QStringLiteral("antennaLocation"))) |
||||
{ |
||||
QJsonObject location = serverObj.value(QStringLiteral("antennaLocation")).toObject(); |
||||
sdr.m_latitude = location.value(QStringLiteral("lat")).toDouble(); |
||||
sdr.m_longitude = location.value(QStringLiteral("long")).toDouble(); |
||||
} |
||||
if (serverObj.contains(QStringLiteral("minimumFrequency"))) { |
||||
sdr.m_minimumFrequency = serverObj.value(QStringLiteral("minimumFrequency")).toInt(); |
||||
} |
||||
if (serverObj.contains(QStringLiteral("maximumFrequency"))) { |
||||
sdr.m_maximumFrequency = serverObj.value(QStringLiteral("maximumFrequency")).toInt(); |
||||
} |
||||
if (serverObj.contains(QStringLiteral("fullControlAllowed"))) { |
||||
sdr.m_fullControlAllowed = serverObj.value(QStringLiteral("fullControlAllowed")).toBool(); |
||||
} |
||||
if (serverObj.contains(QStringLiteral("online"))) { |
||||
sdr.m_online = serverObj.value(QStringLiteral("online")).toBool(); |
||||
} |
||||
|
||||
sdrs.append(sdr); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "SpyServerList::handleJSON: Doc doesn't contain an object:\n" << document; |
||||
} |
||||
|
||||
emit dataUpdated(sdrs); |
||||
} |
||||
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2024 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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_SPYSERVERLIST_H |
||||
#define INCLUDE_SPYSERVERLIST_H |
||||
|
||||
#include <QtCore> |
||||
#include <QTimer> |
||||
|
||||
#include "export.h" |
||||
|
||||
class QNetworkAccessManager; |
||||
class QNetworkReply; |
||||
class QNetworkDiskCache; |
||||
|
||||
// Gets a list of public SpyServers from https://airspy.com/directory/status.json
|
||||
class SDRBASE_API SpyServerList : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
|
||||
struct SpyServer { |
||||
QString m_generalDescription; |
||||
QString m_deviceType; |
||||
QString m_streamingHost; // IP addrss
|
||||
int m_streamingPort; // IP port
|
||||
int m_currentClientCount; |
||||
int m_maxClients; |
||||
QString m_antennaType; |
||||
float m_latitude; |
||||
float m_longitude; |
||||
qint64 m_minimumFrequency; |
||||
qint64 m_maximumFrequency; |
||||
bool m_fullControlAllowed; |
||||
bool m_online; |
||||
}; |
||||
|
||||
SpyServerList(); |
||||
~SpyServerList(); |
||||
|
||||
void getData(); |
||||
void getDataPeriodically(int periodInMins=2); |
||||
|
||||
public slots: |
||||
void handleReply(QNetworkReply* reply); |
||||
void update(); |
||||
|
||||
signals: |
||||
void dataUpdated(const QList<SpyServer>& sdrs); // Emitted when data are available.
|
||||
|
||||
private: |
||||
QNetworkAccessManager *m_networkManager; |
||||
QNetworkDiskCache *m_cache; |
||||
QTimer m_timer; // Timer for periodic updates
|
||||
|
||||
void handleJSON(const QString& url, const QByteArray& bytes); |
||||
|
||||
}; |
||||
|
||||
#endif /* INCLUDE_SPYSERVERLIST_H */ |
||||
@ -0,0 +1,141 @@
@@ -0,0 +1,141 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2024 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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 <QDebug> |
||||
|
||||
#include "waypoints.h" |
||||
#include "csv.h" |
||||
|
||||
QHash<QString, Waypoint *> *Waypoint::readCSV(const QString &filename) |
||||
{ |
||||
QHash<QString, Waypoint *> *waypoints = new QHash<QString, Waypoint *>(); |
||||
QFile file(filename); |
||||
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
||||
{ |
||||
QTextStream in(&file); |
||||
QString error; |
||||
|
||||
QStringList cols; |
||||
while(CSV::readRow(in, &cols)) |
||||
{ |
||||
Waypoint *waypoint = new Waypoint(); |
||||
waypoint->m_name = cols[0]; |
||||
waypoint->m_latitude = cols[1].toFloat(); |
||||
waypoint->m_longitude = cols[2].toFloat(); |
||||
waypoints->insert(waypoint->m_name, waypoint); |
||||
} |
||||
|
||||
file.close(); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "Waypoint::readCSV: Could not open " << filename << " for reading."; |
||||
} |
||||
return waypoints; |
||||
} |
||||
|
||||
QSharedPointer<QHash<QString, Waypoint *>> Waypoints::m_waypoints; |
||||
|
||||
QDateTime Waypoints::m_waypointsModifiedDateTime; |
||||
|
||||
Waypoints::Waypoints(QObject *parent) : |
||||
QObject(parent) |
||||
{ |
||||
connect(&m_dlm, &HttpDownloadManager::downloadComplete, this, &Waypoints::downloadFinished); |
||||
} |
||||
|
||||
Waypoints::~Waypoints() |
||||
{ |
||||
disconnect(&m_dlm, &HttpDownloadManager::downloadComplete, this, &Waypoints::downloadFinished); |
||||
} |
||||
|
||||
QString Waypoints::getDataDir() |
||||
{ |
||||
// Get directory to store app data in
|
||||
QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); |
||||
// First dir is writable
|
||||
return locations[0]; |
||||
} |
||||
|
||||
QString Waypoints::getWaypointsFilename() |
||||
{ |
||||
return getDataDir() + "/" + "waypoints.csv"; |
||||
} |
||||
|
||||
void Waypoints::downloadWaypoints() |
||||
{ |
||||
QString filename = getWaypointsFilename(); |
||||
QString urlString = WAYPOINTS_URL; |
||||
QUrl dbURL(urlString); |
||||
qDebug() << "Waypoints::downloadWaypoints: Downloading " << urlString; |
||||
emit downloadingURL(urlString); |
||||
m_dlm.download(dbURL, filename); |
||||
} |
||||
|
||||
void Waypoints::downloadFinished(const QString& filename, bool success) |
||||
{ |
||||
if (!success) { |
||||
qDebug() << "Waypoints::downloadFinished: Failed: " << filename; |
||||
} |
||||
|
||||
if (filename == getWaypointsFilename()) |
||||
{ |
||||
emit downloadWaypointsFinished(); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "Waypoints::downloadFinished: Unexpected filename: " << filename; |
||||
emit downloadError(QString("Unexpected filename: %1").arg(filename)); |
||||
} |
||||
} |
||||
|
||||
// Read waypoints
|
||||
QHash<QString, Waypoint *> *Waypoints::readWaypoints() |
||||
{ |
||||
return Waypoint::readCSV(getWaypointsFilename()); |
||||
} |
||||
|
||||
QSharedPointer<const QHash<QString, Waypoint *>> Waypoints::getWaypoints() |
||||
{ |
||||
QDateTime filesDateTime = getWaypointsModifiedDateTime(); |
||||
|
||||
if (!m_waypoints || (filesDateTime > m_waypointsModifiedDateTime)) |
||||
{ |
||||
// Using shared pointer, so old object, if it exists, will be deleted, when no longer used
|
||||
m_waypoints = QSharedPointer<QHash<QString, Waypoint *>>(readWaypoints()); |
||||
m_waypointsModifiedDateTime = filesDateTime; |
||||
} |
||||
return m_waypoints; |
||||
} |
||||
|
||||
// Gets the date and time the waypoint file was most recently modified
|
||||
QDateTime Waypoints::getWaypointsModifiedDateTime() |
||||
{ |
||||
QFileInfo fileInfo(getWaypointsFilename()); |
||||
return fileInfo.lastModified(); |
||||
} |
||||
|
||||
// Find a waypoint by name
|
||||
const Waypoint *Waypoints::findWayPoint(const QString& name) |
||||
{ |
||||
if (m_waypoints->contains(name)) { |
||||
return m_waypoints->value(name); |
||||
} else { |
||||
return nullptr; |
||||
} |
||||
} |
||||
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2021-2024 Jon Beniston, M7RCE <jon@beniston.com> //
|
||||
// //
|
||||
// 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_WAYPOINTS_H |
||||
#define INCLUDE_WAYPOINTS_H |
||||
|
||||
#include <QString> |
||||
#include <QFile> |
||||
#include <QHash> |
||||
|
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
#include "export.h" |
||||
|
||||
#include "util/units.h" |
||||
#include "util/httpdownloadmanager.h" |
||||
|
||||
#define WAYPOINTS_URL "https://github.com/srcejon/aviationwaypoints/waypoints.csv"
|
||||
|
||||
// Aviation waypoints
|
||||
struct SDRBASE_API Waypoint { |
||||
|
||||
QString m_name; // Typically 5 characters
|
||||
float m_latitude; |
||||
float m_longitude; |
||||
|
||||
static QHash<QString, Waypoint *> *readCSV(const QString &filename); |
||||
}; |
||||
|
||||
class SDRBASE_API Waypoints : public QObject { |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
Waypoints(QObject* parent = nullptr); |
||||
~Waypoints(); |
||||
|
||||
void downloadWaypoints(); |
||||
|
||||
static const Waypoint* findWayPoint(const QString& name); |
||||
static QSharedPointer<const QHash<QString, Waypoint *>> getWaypoints(); |
||||
|
||||
private: |
||||
HttpDownloadManager m_dlm; |
||||
|
||||
static QSharedPointer<QHash<QString, Waypoint *>> m_waypoints; |
||||
|
||||
static QDateTime m_waypointsModifiedDateTime; |
||||
|
||||
static QHash<QString, Waypoint *> *readWaypoints(); |
||||
|
||||
static QString getDataDir(); |
||||
static QString getWaypointsFilename(); |
||||
static QDateTime getWaypointsModifiedDateTime(); |
||||
|
||||
public slots: |
||||
void downloadFinished(const QString& filename, bool success); |
||||
|
||||
signals: |
||||
void downloadingURL(const QString& url); |
||||
void downloadError(const QString& error); |
||||
void downloadWaypointsFinished(); |
||||
|
||||
}; |
||||
|
||||
#endif // INCLUDE_WAYPOINTS_H
|
||||