1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

Add Solar flux measurement to Star Tracker GUI

This commit is contained in:
Jon Beniston 2021-01-22 16:58:24 +00:00
parent ecdffc4780
commit f7845dfe05
7 changed files with 361 additions and 202 deletions

View File

@ -20,6 +20,8 @@
#include <QMessageBox>
#include <QLineEdit>
#include <QRegExp>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
@ -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("\\<th\\>Observed Flux Density\\<\\/th\\>\\<td\\>([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();
}

View File

@ -21,6 +21,7 @@
#include <QTimer>
#include <QtCharts>
#include <QNetworkRequest>
#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);
};

View File

@ -409,6 +409,23 @@ This can be specified as a decimal (E.g. 34.23) or in degrees, minutes and secon
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="solarFluxLabel">
<property name="text">
<string>Solar Flux</string>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QLineEdit" name="solarFlux">
<property name="toolTip">
<string>Displays the solar flux at 10.7cm</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@ -486,15 +503,21 @@ This can be specified as a decimal (E.g. 34.23) or in degrees, minutes and secon
</customwidgets>
<tabstops>
<tabstop>startStop</tabstop>
<tabstop>viewOnMap</tabstop>
<tabstop>useMyPosition</tabstop>
<tabstop>displaySettings</tabstop>
<tabstop>latitude</tabstop>
<tabstop>longitude</tabstop>
<tabstop>dateTimeSelect</tabstop>
<tabstop>dateTime</tabstop>
<tabstop>lst</tabstop>
<tabstop>solarFlux</tabstop>
<tabstop>target</tabstop>
<tabstop>rightAscension</tabstop>
<tabstop>declination</tabstop>
<tabstop>azimuth</tabstop>
<tabstop>elevation</tabstop>
<tabstop>elevationChart</tabstop>
</tabstops>
<resources>
<include location="../../../sdrgui/resources/res.qrc"/>

View File

@ -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

View File

@ -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;

View File

@ -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();

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>351</width>
<height>468</height>
<width>393</width>
<height>485</height>
</rect>
</property>
<property name="font">
@ -23,73 +23,10 @@
<item>
<widget class="QGroupBox" name="groupBox">
<layout class="QGridLayout" name="gridLayout">
<item row="6" column="0">
<widget class="QLabel" name="heightLabel">
<item row="10" column="0">
<widget class="QLabel" name="updatePeriodLabel">
<property name="text">
<string>Height above sea level (m)</string>
</property>
</widget>
</item>
<item row="16" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="15" column="0">
<widget class="QCheckBox" name="drawStarOnMap">
<property name="text">
<string>Draw target star on map</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="temperatureLabel">
<property name="text">
<string>Air temperature (C)</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="refractionLabel">
<property name="text">
<string>Refraction correction</string>
</property>
</widget>
</item>
<item row="11" column="1">
<widget class="QSpinBox" name="serverPort">
<property name="toolTip">
<string>Stellarium telescope server IP port number</string>
</property>
<property name="minimum">
<number>1024</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>10001</number>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QSpinBox" name="frequency">
<property name="toolTip">
<string>Radio frequency being observed</string>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
<property name="value">
<number>435</number>
<string>Update period (s)</string>
</property>
</widget>
</item>
@ -100,113 +37,17 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="pressure">
<property name="toolTip">
<string>Air pressure in millibars, for use in atmospheric refraction correction</string>
</property>
<property name="maximum">
<double>2000.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="value">
<double>1010.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="epochLabel">
<item row="1" column="0">
<widget class="QLabel" name="azElUnitsLabel">
<property name="text">
<string>Epoch for RA &amp; Dec</string>
<string>Azimuth and elevation units</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="temperature">
<property name="toolTip">
<string>Air temperature in degrees Celsius, for use in atmospheric refraction correction</string>
</property>
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QCheckBox" name="drawSunOnMap">
<item row="2" column="0">
<widget class="QLabel" name="refractionLabel">
<property name="text">
<string>Draw Sun on map</string>
</property>
</widget>
</item>
<item row="14" column="0">
<widget class="QCheckBox" name="drawMoonOnMap">
<property name="text">
<string>Draw Moon on map</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="humidity">
<property name="toolTip">
<string>Relative humidity in %</string>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>80</number>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="serverPortLabel">
<property name="text">
<string>Stellarium server port</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="updatePeriodLabel">
<property name="text">
<string>Update period (s)</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="humidityLabel">
<property name="text">
<string>Humidity (%)</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QDoubleSpinBox" name="updatePeriod">
<property name="toolTip">
<string>Enter the time in seconds between each calculation of the target's position</string>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="height">
<property name="toolTip">
<string>Height of observation/antenna location above sea level in metres</string>
</property>
<property name="minimum">
<number>-1000</number>
</property>
<property name="maximum">
<number>20000</number>
<string>Refraction correction</string>
</property>
</widget>
</item>
@ -217,30 +58,6 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="epoch">
<property name="toolTip">
<string>Epoch for custom right ascension and declination</string>
</property>
<item>
<property name="text">
<string>J2000</string>
</property>
</item>
<item>
<property name="text">
<string>JNOW</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="azElUnitsLabel">
<property name="text">
<string>Azimuth and elevation units</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="refraction">
<property name="toolTip">
@ -266,7 +83,7 @@
</item>
</widget>
</item>
<item row="12" column="0">
<item row="13" column="0">
<widget class="QCheckBox" name="enableServer">
<property name="toolTip">
<string>Enable Stellarium server which allows RA and Dec to be sent to and from Stellarium</string>
@ -276,6 +93,46 @@
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="height">
<property name="toolTip">
<string>Height of observation/antenna location above sea level in metres</string>
</property>
<property name="minimum">
<number>-1000</number>
</property>
<property name="maximum">
<number>20000</number>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QSpinBox" name="frequency">
<property name="toolTip">
<string>Radio frequency being observed</string>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
<property name="value">
<number>435</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="epochLabel">
<property name="text">
<string>Epoch for RA &amp; Dec</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="temperatureLabel">
<property name="text">
<string>Air temperature (C)</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="azElUnits">
<property name="toolTip">
@ -306,13 +163,41 @@
</item>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="temperatureLapseRateLabel">
<property name="toolTip">
<string>Temperature lapse rate (K/m)</string>
</property>
<item row="14" column="0">
<widget class="QCheckBox" name="drawSunOnMap">
<property name="text">
<string>Temperature lapse rate (K/km)</string>
<string>Draw Sun on map</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="heightLabel">
<property name="text">
<string>Height above sea level (m)</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="epoch">
<property name="toolTip">
<string>Epoch for custom right ascension and declination</string>
</property>
<item>
<property name="text">
<string>J2000</string>
</property>
</item>
<item>
<property name="text">
<string>JNOW</string>
</property>
</item>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="humidityLabel">
<property name="text">
<string>Humidity (%)</string>
</property>
</widget>
</item>
@ -329,6 +214,150 @@
</property>
</widget>
</item>
<item row="17" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="15" column="0">
<widget class="QCheckBox" name="drawMoonOnMap">
<property name="text">
<string>Draw Moon on map</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="pressure">
<property name="toolTip">
<string>Air pressure in millibars, for use in atmospheric refraction correction</string>
</property>
<property name="maximum">
<double>2000.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="value">
<double>1010.000000000000000</double>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="temperatureLapseRateLabel">
<property name="toolTip">
<string>Temperature lapse rate (K/m)</string>
</property>
<property name="text">
<string>Temperature lapse rate (K/km)</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="humidity">
<property name="toolTip">
<string>Relative humidity in %</string>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>80</number>
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QSpinBox" name="serverPort">
<property name="toolTip">
<string>Stellarium telescope server IP port number</string>
</property>
<property name="minimum">
<number>1024</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>10001</number>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="temperature">
<property name="toolTip">
<string>Air temperature in degrees Celsius, for use in atmospheric refraction correction</string>
</property>
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QDoubleSpinBox" name="updatePeriod">
<property name="toolTip">
<string>Enter the time in seconds between each calculation of the target's position</string>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="serverPortLabel">
<property name="text">
<string>Stellarium server port</string>
</property>
</widget>
</item>
<item row="16" column="0">
<widget class="QCheckBox" name="drawStarOnMap">
<property name="text">
<string>Draw target star on map</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="solarFluxUnitsLabel">
<property name="text">
<string>Solar flux units</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QComboBox" name="solarFluxUnits">
<property name="toolTip">
<string>Units to use for the display of the Solar flux</string>
</property>
<item>
<property name="text">
<string>Solar flux units (sfu)</string>
</property>
</item>
<item>
<property name="text">
<string>Jansky (Jy)</string>
</property>
</item>
<item>
<property name="text">
<string>Watts per square metre per hertz (W m^-2 Hz-1)</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
@ -344,6 +373,24 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>epoch</tabstop>
<tabstop>azElUnits</tabstop>
<tabstop>refraction</tabstop>
<tabstop>pressure</tabstop>
<tabstop>temperature</tabstop>
<tabstop>humidity</tabstop>
<tabstop>height</tabstop>
<tabstop>temperatureLapseRate</tabstop>
<tabstop>frequency</tabstop>
<tabstop>solarFluxUnits</tabstop>
<tabstop>updatePeriod</tabstop>
<tabstop>serverPort</tabstop>
<tabstop>enableServer</tabstop>
<tabstop>drawSunOnMap</tabstop>
<tabstop>drawMoonOnMap</tabstop>
<tabstop>drawStarOnMap</tabstop>
</tabstops>
<resources/>
<connections>
<connection>