diff --git a/plugins/feature/startracker/startrackergui.cpp b/plugins/feature/startracker/startrackergui.cpp index 8686cc4c0..f7c66e7c0 100644 --- a/plugins/feature/startracker/startrackergui.cpp +++ b/plugins/feature/startracker/startrackergui.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -147,7 +149,9 @@ StarTrackerGUI::StarTrackerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, m_pluginAPI(pluginAPI), m_featureUISet(featureUISet), m_doApplySettings(true), - m_lastFeatureState(0) + m_lastFeatureState(0), + m_networkManager(nullptr), + m_solarFlux(0.0) { ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose, true); @@ -197,10 +201,19 @@ StarTrackerGUI::StarTrackerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, m_settings.m_temperatureLapseRate)); printf("];\n"); */ + + m_networkManager = new QNetworkAccessManager(); + connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); + + connect(&m_solarFluxTimer, SIGNAL(timeout()), this, SLOT(updateSolarFlux())); + m_solarFluxTimer.start(1000*60*60*24); // Update every 24hours + updateSolarFlux(); } StarTrackerGUI::~StarTrackerGUI() { + disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); + delete m_networkManager; delete ui; } @@ -475,6 +488,7 @@ void StarTrackerGUI::on_displaySettings_clicked() if (dialog.exec() == QDialog::Accepted) { applySettings(); + displaySolarFlux(); } } @@ -582,3 +596,60 @@ void StarTrackerGUI::on_viewOnMap_clicked() QString target = m_settings.m_target == "Sun" || m_settings.m_target == "Moon" ? m_settings.m_target : "Star"; FeatureWebAPIUtils::mapFind(target); } + +void StarTrackerGUI::updateSolarFlux() +{ + qDebug() << "StarTrackerGUI: Updating flux"; + m_networkRequest.setUrl(QUrl("https://www.spaceweather.gc.ca/solarflux/sx-4-en.php")); + m_networkManager->get(m_networkRequest); +} + +void StarTrackerGUI::displaySolarFlux() +{ + if (m_solarFlux <= 0.0) + ui->solarFlux->setText(""); + else + { + switch (m_settings.m_solarFluxUnits) + { + case StarTrackerSettings::SFU: + ui->solarFlux->setText(QString("%1 sfu").arg(m_solarFlux)); + break; + case StarTrackerSettings::JANSKY: + ui->solarFlux->setText(QString("%1 Jy").arg(Units::solarFluxUnitsToJansky(m_solarFlux))); + break; + case StarTrackerSettings::WATTS_M_HZ: + ui->solarFlux->setText(QString("%1 Wm^-2Hz^-1").arg(Units::solarFluxUnitsToWattsPerMetrePerHertz(m_solarFlux))); + break; + } + ui->solarFlux->setCursorPosition(0); + } +} + +void StarTrackerGUI::networkManagerFinished(QNetworkReply *reply) +{ + ui->solarFlux->setText(""); // Don't show obsolete data + QNetworkReply::NetworkError replyError = reply->error(); + + if (replyError) + { + qWarning() << "StarTrackerGUI::networkManagerFinished:" + << " error(" << (int) replyError + << "): " << replyError + << ": " << reply->errorString(); + } + else + { + QString answer = reply->readAll(); + QRegExp re("\\Observed Flux Density\\<\\/th\\>\\([0-9]+(\\.[0-9]+)?)\\<\\/td\\>"); + if (re.indexIn(answer) != -1) + { + m_solarFlux = re.capturedTexts()[1].toDouble(); + displaySolarFlux(); + } + else + qDebug() << "No Solar flux found: " << answer; + } + + reply->deleteLater(); +} diff --git a/plugins/feature/startracker/startrackergui.h b/plugins/feature/startracker/startrackergui.h index ced54e3e2..336874e81 100644 --- a/plugins/feature/startracker/startrackergui.h +++ b/plugins/feature/startracker/startrackergui.h @@ -21,6 +21,7 @@ #include #include +#include #include "feature/featuregui.h" #include "util/messagequeue.h" @@ -29,6 +30,8 @@ class PluginAPI; class FeatureUISet; class StarTracker; +class QNetworkAccessManager; +class QNetworkReply; namespace Ui { class StarTrackerGUI; @@ -57,12 +60,17 @@ private: StarTracker* m_starTracker; MessageQueue m_inputMessageQueue; QTimer m_statusTimer; + QTimer m_solarFluxTimer; int m_lastFeatureState; QChart m_chart; QDateTimeAxis m_chartXAxis; QValueAxis m_chartYAxis; + QNetworkAccessManager *m_networkManager; + QNetworkRequest m_networkRequest; + double m_solarFlux; + explicit StarTrackerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent = nullptr); virtual ~StarTrackerGUI(); @@ -74,6 +82,7 @@ private: bool handleMessage(const Message& message); void updateLST(); void plotChart(); + void displaySolarFlux(); void leaveEvent(QEvent*); void enterEvent(QEvent*); @@ -94,6 +103,8 @@ private slots: void on_dateTime_dateTimeChanged(const QDateTime &datetime); void updateStatus(); void on_viewOnMap_clicked(); + void updateSolarFlux(); + void networkManagerFinished(QNetworkReply *reply); }; diff --git a/plugins/feature/startracker/startrackergui.ui b/plugins/feature/startracker/startrackergui.ui index 9e859b468..c45a56d08 100644 --- a/plugins/feature/startracker/startrackergui.ui +++ b/plugins/feature/startracker/startrackergui.ui @@ -409,6 +409,23 @@ This can be specified as a decimal (E.g. 34.23) or in degrees, minutes and secon + + + + Solar Flux + + + + + + + Displays the solar flux at 10.7cm + + + true + + + @@ -486,15 +503,21 @@ This can be specified as a decimal (E.g. 34.23) or in degrees, minutes and secon startStop + viewOnMap useMyPosition displaySettings latitude longitude + dateTimeSelect + dateTime + lst + solarFlux target rightAscension declination azimuth elevation + elevationChart diff --git a/plugins/feature/startracker/startrackersettings.cpp b/plugins/feature/startracker/startrackersettings.cpp index 2585a4759..39bae71c0 100644 --- a/plugins/feature/startracker/startrackersettings.cpp +++ b/plugins/feature/startracker/startrackersettings.cpp @@ -46,6 +46,7 @@ void StarTrackerSettings::resetToDefaults() m_enableServer = true; m_serverPort = 10001; m_azElUnits = DM; + m_solarFluxUnits = SFU; m_updatePeriod = 1.0; m_jnow = false; m_drawSunOnMap = true; @@ -92,6 +93,7 @@ QByteArray StarTrackerSettings::serialize() const s.writeU32(26, m_reverseAPIPort); s.writeU32(27, m_reverseAPIFeatureSetIndex); s.writeU32(28, m_reverseAPIFeatureIndex); + s.writeU32(29, m_solarFluxUnits); return s.final(); } @@ -156,6 +158,8 @@ bool StarTrackerSettings::deserialize(const QByteArray& data) d.readU32(28, &utmp, 0); m_reverseAPIFeatureIndex = utmp > 99 ? 99 : utmp; + d.readS32(29, (qint32 *)&m_solarFluxUnits, SFU); + return true; } else diff --git a/plugins/feature/startracker/startrackersettings.h b/plugins/feature/startracker/startrackersettings.h index 17290f603..3fec6fd6c 100644 --- a/plugins/feature/startracker/startrackersettings.h +++ b/plugins/feature/startracker/startrackersettings.h @@ -44,6 +44,7 @@ struct StarTrackerSettings uint16_t m_serverPort; bool m_enableServer; // Enable Stellarium server enum AzElUnits {DMS, DM, D, Decimal} m_azElUnits; + enum SolarFluxUnits {SFU, JANSKY, WATTS_M_HZ} m_solarFluxUnits; float m_updatePeriod; bool m_jnow; // Use JNOW epoch rather than J2000 bool m_drawSunOnMap; diff --git a/plugins/feature/startracker/startrackersettingsdialog.cpp b/plugins/feature/startracker/startrackersettingsdialog.cpp index f5dd6cbcd..c21abcf36 100644 --- a/plugins/feature/startracker/startrackersettingsdialog.cpp +++ b/plugins/feature/startracker/startrackersettingsdialog.cpp @@ -37,6 +37,7 @@ StarTrackerSettingsDialog::StarTrackerSettingsDialog(StarTrackerSettings *settin ui->height->setValue(settings->m_heightAboveSeaLevel); ui->temperatureLapseRate->setValue(settings->m_temperatureLapseRate); ui->frequency->setValue(settings->m_frequency/1000000.0); + ui->solarFluxUnits->setCurrentIndex((int)settings->m_solarFluxUnits); ui->drawSunOnMap->setChecked(settings->m_drawSunOnMap); ui->drawMoonOnMap->setChecked(settings->m_drawMoonOnMap); ui->drawStarOnMap->setChecked(settings->m_drawStarOnMap); @@ -61,6 +62,7 @@ void StarTrackerSettingsDialog::accept() m_settings->m_heightAboveSeaLevel = ui->height->value(); m_settings->m_temperatureLapseRate = ui->temperatureLapseRate->value(); m_settings->m_frequency = ui->frequency->value() * 1000000.0; + m_settings->m_solarFluxUnits = (StarTrackerSettings::SolarFluxUnits)ui->solarFluxUnits->currentIndex(); m_settings->m_drawSunOnMap = ui->drawSunOnMap->isChecked(); m_settings->m_drawMoonOnMap = ui->drawMoonOnMap->isChecked(); m_settings->m_drawStarOnMap = ui->drawStarOnMap->isChecked(); diff --git a/plugins/feature/startracker/startrackersettingsdialog.ui b/plugins/feature/startracker/startrackersettingsdialog.ui index 8c1c15a72..bd40dbfba 100644 --- a/plugins/feature/startracker/startrackersettingsdialog.ui +++ b/plugins/feature/startracker/startrackersettingsdialog.ui @@ -6,8 +6,8 @@ 0 0 - 351 - 468 + 393 + 485 @@ -23,73 +23,10 @@ - - + + - Height above sea level (m) - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Draw target star on map - - - - - - - Air temperature (C) - - - - - - - Refraction correction - - - - - - - Stellarium telescope server IP port number - - - 1024 - - - 65535 - - - 10001 - - - - - - - Radio frequency being observed - - - 1000000000 - - - 435 + Update period (s) @@ -100,113 +37,17 @@ - - - - Air pressure in millibars, for use in atmospheric refraction correction - - - 2000.000000000000000 - - - 1.000000000000000 - - - 1010.000000000000000 - - - - - + + - Epoch for RA & Dec + Azimuth and elevation units - - - - Air temperature in degrees Celsius, for use in atmospheric refraction correction - - - -100 - - - 100 - - - 10 - - - - - + + - Draw Sun on map - - - - - - - Draw Moon on map - - - - - - - Relative humidity in % - - - 100 - - - 80 - - - - - - - Stellarium server port - - - - - - - Update period (s) - - - - - - - Humidity (%) - - - - - - - Enter the time in seconds between each calculation of the target's position - - - 1.000000000000000 - - - - - - - Height of observation/antenna location above sea level in metres - - - -1000 - - - 20000 + Refraction correction @@ -217,30 +58,6 @@ - - - - Epoch for custom right ascension and declination - - - - J2000 - - - - - JNOW - - - - - - - - Azimuth and elevation units - - - @@ -266,7 +83,7 @@ - + Enable Stellarium server which allows RA and Dec to be sent to and from Stellarium @@ -276,6 +93,46 @@ + + + + Height of observation/antenna location above sea level in metres + + + -1000 + + + 20000 + + + + + + + Radio frequency being observed + + + 1000000000 + + + 435 + + + + + + + Epoch for RA & Dec + + + + + + + Air temperature (C) + + + @@ -306,13 +163,41 @@ - - - - Temperature lapse rate (K/m) - + + - Temperature lapse rate (K/km) + Draw Sun on map + + + + + + + Height above sea level (m) + + + + + + + Epoch for custom right ascension and declination + + + + J2000 + + + + + JNOW + + + + + + + + Humidity (%) @@ -329,6 +214,150 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Draw Moon on map + + + + + + + Air pressure in millibars, for use in atmospheric refraction correction + + + 2000.000000000000000 + + + 1.000000000000000 + + + 1010.000000000000000 + + + + + + + Temperature lapse rate (K/m) + + + Temperature lapse rate (K/km) + + + + + + + Relative humidity in % + + + 100 + + + 80 + + + + + + + Stellarium telescope server IP port number + + + 1024 + + + 65535 + + + 10001 + + + + + + + Air temperature in degrees Celsius, for use in atmospheric refraction correction + + + -100 + + + 100 + + + 10 + + + + + + + Enter the time in seconds between each calculation of the target's position + + + 1.000000000000000 + + + + + + + Stellarium server port + + + + + + + Draw target star on map + + + + + + + Solar flux units + + + + + + + Units to use for the display of the Solar flux + + + + Solar flux units (sfu) + + + + + Jansky (Jy) + + + + + Watts per square metre per hertz (W m^-2 Hz-1) + + + + @@ -344,6 +373,24 @@ + + epoch + azElUnits + refraction + pressure + temperature + humidity + height + temperatureLapseRate + frequency + solarFluxUnits + updatePeriod + serverPort + enableServer + drawSunOnMap + drawMoonOnMap + drawStarOnMap +