diff --git a/astro.cpp b/astro.cpp index c4af0c4a7..6fffb4853 100644 --- a/astro.cpp +++ b/astro.cpp @@ -13,24 +13,31 @@ #include #include "commons.h" +#include "Configuration.hpp" +#include "SettingsGroup.hpp" #include "qt_helpers.hpp" #include "ui_astro.h" - #include "moc_astro.cpp" -Astro::Astro(QSettings * settings, QWidget * parent) - : QWidget {parent} +Astro::Astro(QSettings * settings, Configuration const * configuration, QWidget * parent) + : QWidget {parent, Qt::Dialog | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint} , settings_ {settings} + , configuration_ {configuration} , ui_ {new Ui::Astro} + , m_bRxAudioTrack {false} + , m_bTxAudioTrack {false} + , m_DopplerMethod {0} + , m_kHz {0} + , m_Hz {0} + , m_stepHz {1} { - ui_->setupUi(this); - setWindowFlags (Qt::Dialog | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint); - setWindowTitle(QApplication::applicationName () + " - " + tr ("Astronomical Data")); + ui_->setupUi (this); + setWindowTitle (QApplication::applicationName () + " - " + tr ("Astronomical Data")); setStyleSheet ("QWidget {background: white;}"); + connect (ui_->cbDopplerTracking, &QAbstractButton::toggled, ui_->doppler_widget, &QWidget::setVisible); read_settings (); - m_Hz=0; - ui_->text_label->clear(); + ui_->text_label->clear (); } Astro::~Astro () @@ -46,10 +53,10 @@ void Astro::closeEvent (QCloseEvent * e) void Astro::read_settings () { - settings_->beginGroup ("Astro"); + SettingsGroup g (settings_, "Astro"); restoreGeometry (settings_->value ("geometry", saveGeometry ()).toByteArray ()); - m_bDopplerTracking=settings_->value("DopplerTracking",false).toBool(); - ui_->cbDopplerTracking->setChecked(m_bDopplerTracking); + ui_->cbDopplerTracking->setChecked (settings_->value ("DopplerTracking",false).toBool ()); + ui_->doppler_widget->setVisible (ui_->cbDopplerTracking->isChecked ()); m_DopplerMethod=settings_->value("DopplerMethod",0).toInt(); if(m_DopplerMethod==0) ui_->rbNoDoppler->setChecked(true); if(m_DopplerMethod==1) ui_->rbFullTrack->setChecked(true); @@ -64,47 +71,48 @@ void Astro::read_settings () m_bTxAudioTrack=settings_->value("TxAudioTrack",false).toBool(); ui_->cbTxAudioTrack->setChecked(m_bTxAudioTrack); move (settings_->value ("window/pos", pos ()).toPoint ()); - settings_->endGroup (); } void Astro::write_settings () { - settings_->beginGroup ("Astro"); + SettingsGroup g (settings_, "Astro"); settings_->setValue ("geometry", saveGeometry ()); - settings_->setValue ("DopplerTracking",m_bDopplerTracking); + settings_->setValue ("DopplerTracking", ui_->cbDopplerTracking->isChecked ()); settings_->setValue ("DopplerMethod",m_DopplerMethod); settings_->setValue ("StepHz",m_stepHz); settings_->setValue ("kHzAdd",m_kHz); settings_->setValue ("RxAudioTrack",m_bRxAudioTrack); settings_->setValue ("TxAudioTrack",m_bTxAudioTrack); settings_->setValue ("window/pos", pos ()); - settings_->endGroup (); } -void Astro::astroUpdate(QDateTime t, QString mygrid, QString hisgrid, qint64 freqMoon, - qint32* ndop, qint32* ndop00, bool bTx, QString jpleph) +auto Astro::astroUpdate(QDateTime const& t, QString const& mygrid, QString const& hisgrid, Frequency freq, + bool dx_is_self, bool bTx) -> FrequencyDelta { + Frequency freq_moon {freq + 1000 * m_kHz + m_Hz}; double azsun,elsun,azmoon,elmoon,azmoondx,elmoondx; double ramoon,decmoon,dgrd,poloffset,xnr,techo,width1,width2; int ntsky; - QString date = t.date().toString("yyyy MMM dd").trimmed (); - QString utc = t.time().toString().trimmed (); - int nyear=t.date().year(); - int month=t.date().month(); - int nday=t.date().day(); - int nhr=t.time().hour(); - int nmin=t.time().minute(); - double sec=t.time().second() + 0.001*t.time().msec(); - double uth=nhr + nmin/60.0 + sec/3600.0; - if(freqMoon < 1) freqMoon=144000000; - int nfreq=freqMoon/1000000; - double freq8=(double)freqMoon; - - QString AzElFileName = QDir::toNativeSeparators(m_azelDir.absoluteFilePath ("azel.dat")); + QString date {t.date().toString("yyyy MMM dd").trimmed ()}; + QString utc {t.time().toString().trimmed ()}; + int nyear {t.date().year()}; + int month {t.date().month()}; + int nday {t.date().day()}; + int nhr {t.time().hour()}; + int nmin {t.time().minute()}; + double sec {t.time().second() + 0.001*t.time().msec()}; + double uth {nhr + nmin/60.0 + sec/3600.0}; + if(freq_moon < 1) freq_moon = 144000000; + int nfreq {static_cast (freq_moon / 1000000u)}; + double freq8 {static_cast (freq_moon)}; + auto const& AzElFileName = QDir::toNativeSeparators (configuration_->azel_directory ().absoluteFilePath ("azel.dat")); + auto const& jpleph = configuration_->data_dir ().absoluteFilePath ("JPLEPH"); + int ndop; + int ndop00; astrosub_(&nyear, &month, &nday, &uth, &freq8, mygrid.toLatin1().constData(), hisgrid.toLatin1().constData(), &azsun, &elsun, &azmoon, &elmoon, - &azmoondx, &elmoondx, &ntsky, ndop, ndop00, &ramoon, &decmoon, + &azmoondx, &elmoondx, &ntsky, &ndop, &ndop00, &ramoon, &decmoon, &dgrd, &poloffset, &xnr, &techo, &width1, &width2, &bTx, AzElFileName.toLatin1().constData(), jpleph.toLatin1().constData(), 6, 6, AzElFileName.length(), jpleph.length()); @@ -120,14 +128,14 @@ void Astro::astroUpdate(QDateTime t, QString mygrid, QString hisgrid, qint64 fre << qSetRealNumberPrecision (1) << "Az: " << azmoon << "\n" "El: " << elmoon << "\n" - "SelfDop:" << *ndop00 << "\n" + "SelfDop:" << ndop00 << "\n" "Width: " << int(width1) << "\n" << qSetRealNumberPrecision (2) << "Delay: " << techo << "\n" << qSetRealNumberPrecision (1) << "DxAz: " << azmoondx << "\n" "DxEl: " << elmoondx << "\n" - "DxDop: " << *ndop << "\n" + "DxDop: " << ndop << "\n" "DxWid: " << int(width2) << "\n" "Dec: " << decmoon << "\n" "SunAz: " << azsun << "\n" @@ -192,18 +200,40 @@ void Astro::astroUpdate(QDateTime t, QString mygrid, QString hisgrid, qint64 fre } f.close(); */ -} -void Astro::on_cbDopplerTracking_toggled(bool b) -{ - QRect g=this->geometry(); - if(b) { - g.setWidth(430); - } else { - g.setWidth(200); + FrequencyDelta astro_correction {0}; + //Apply Doppler corrections only for 50 MHz and above + if (freq_moon >= 50000000) { + if (ui_->cbDopplerTracking->isChecked ()) { + switch (m_DopplerMethod) + { + case 1: + // All Doppler correction done here; DX station stays at nominal dial frequency. + if(dx_is_self) { + astro_correction = m_stepHz*qRound(double(ndop00)/m_stepHz); + } else { + astro_correction = m_stepHz*qRound(double(ndop)/m_stepHz); + } + break; + + case 2: + // Doppler correction to constant frequency on Moon + astro_correction = m_stepHz*qRound(double(ndop00/2.0)/m_stepHz); + break; + } + + if (bTx) { + astro_correction = 1000 * m_kHz + m_Hz - astro_correction; + } else { + if(dx_is_self && m_DopplerMethod==1) { + astro_correction = 1000*m_kHz + m_Hz; + } else { + astro_correction += 1000*m_kHz + m_Hz; + } + } + } } - this->setGeometry(g); - m_bDopplerTracking=b; + return astro_correction; } void Astro::on_rbFullTrack_clicked() @@ -229,7 +259,6 @@ void Astro::on_rb1Hz_clicked() void Astro::on_rb10Hz_clicked() { m_stepHz=10; - } void Astro::on_rb100Hz_clicked() diff --git a/astro.h b/astro.h index 240aae7f5..843566380 100644 --- a/astro.h +++ b/astro.h @@ -3,10 +3,10 @@ #define ASTRO_H #include -#include +#include "Radio.hpp" class QSettings; - +class Configuration; namespace Ui { class Astro; } @@ -16,31 +16,19 @@ class Astro final { Q_OBJECT; -private: - Q_DISABLE_COPY (Astro); + using Frequency = Radio::Frequency; + using FrequencyDelta = Radio::FrequencyDelta; public: - explicit Astro(QSettings * settings, QWidget * parent = nullptr); + explicit Astro(QSettings * settings, Configuration const *, QWidget * parent = nullptr); ~Astro (); - void astroUpdate(QDateTime t, QString mygrid, QString hisgrid, qint64 freqMoon, - qint32* ndop, qint32 *ndop00, bool bTx, QString jpleph); - - bool m_bDopplerTracking; - bool m_bRxAudioTrack; - bool m_bTxAudioTrack; - - qint32 m_DopplerMethod; - qint32 m_kHz; - qint32 m_Hz; - qint32 m_stepHz; - - QDir m_azelDir; + FrequencyDelta astroUpdate(QDateTime const& t, QString const& mygrid, QString const& hisgrid, Frequency frequency, + bool dx_is_self, bool bTx); protected: void closeEvent (QCloseEvent *) override; private slots: - void on_cbDopplerTracking_toggled(bool b); void on_rbConstFreqOnMoon_clicked(); void on_rbFullTrack_clicked(); void on_rbNoDoppler_clicked(); @@ -56,8 +44,15 @@ private: void write_settings (); QSettings * settings_; -// QScopedPointer ui_; - Ui::Astro *ui_; + Configuration const * configuration_; + Ui::Astro * ui_; + bool m_bRxAudioTrack; + bool m_bTxAudioTrack; + + qint32 m_DopplerMethod; + qint32 m_kHz; + qint32 m_Hz; + qint32 m_stepHz; }; extern "C" { diff --git a/astro.ui b/astro.ui index a13cb1b82..110e81588 100644 --- a/astro.ui +++ b/astro.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 445 + 325 + 339 @@ -16,359 +16,240 @@ 0 - - - 200 - 440 - - - - - - - - - 0 - 0 - 201 - 410 - + + + QLayout::SetFixedSize - - - 0 - 0 - - - - - 300 - 16777215 - - - - - Courier - 14 - 75 - false - true - - - - - - - QFrame::Sunken - - - Astro Data - - - Qt::AlignCenter - - - 6 - - - - - - 1 - 410 - 195 - 22 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Doppler tracking - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - 200 - 12 - 198 - 411 - - - - - - - - 196 - 0 - - - - - 16777215 - 60 - - - - Frequency above nominal band edge - - - - - 20 - 20 - 75 - 22 - + + + + + + + 1 + 0 + - - - 75 - 0 - + + + Courier + 12 + 75 + true + + + + * { + font-family: Courier; + font-size: 12pt; + font-weight: bold; +} + + + QFrame::Sunken + + + Astro Data Qt::AlignCenter - - kHz - - - 999 - - - 200 + + 6 - - - - 100 - 20 - 75 - 22 - - - - - 75 - 0 - - - - Qt::AlignCenter - - - Hz - - - -2000 - - - 2000 - - - 100 - - - - - - - - - 196 - 0 - - - - - 16777215 - 100 - - - - Doppler tracking - - - - + + + + + + + + - Full Doppler to DX Grid - - - true - - - - - - - Constant frequency on Moon - - - false - - - - - - - None - - - false + Doppler tracking - - - - - - - 196 - 0 - + + + + + + + * { + font-weight: normal; +} + + + + 7 - - - 16777215 - 90 - + + 0 - - Transceiver step size + + 0 - - - - 10 - 23 - 61 - 17 - - - - 1 Hz - - - true - - - - - - 10 - 46 - 71 - 17 - - - - 10 Hz - - - - - - 10 - 69 - 71 - 17 - - - - 100 Hz - - - - - - - - - 196 - 0 - + + 0 - - - 16777215 - 60 - + + 0 - - Tx audio tracking - - - - false - - - - 20 - 20 - 105 - 17 - - - - Enable - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 44 - - - - - - + + + + Frequency above nominal band edge + + + + + + Qt::AlignCenter + + + kHz + + + 999 + + + 200 + + + + + + + Qt::AlignCenter + + + Hz + + + -2000 + + + 2000 + + + 100 + + + + + + + + + + Doppler tracking + + + + + + Full Doppler to DX Grid + + + true + + + + + + + Constant frequency on Moon + + + false + + + + + + + None + + + false + + + + + + + + + + Transceiver step size + + + + + + 1 Hz + + + true + + + + + + + 10 Hz + + + + + + + 100 Hz + + + + + + + + + + false + + + Tx audio tracking + + + + + + Enable + + + + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index bfbf88783..66330075e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -432,15 +432,11 @@ MainWindow::MainWindow(bool multiple, QSettings * settings, QSharedMemory *shdme m_DTtol=0.5; m_wideGraph->setTol(m_tol); m_bShMsgs=false; - m_bDopplerTracking0=false; m_bTxTime=false; m_rxDone=false; m_bHaveTransmitted=false; m_bEchoTxOK=false; m_bTransmittedEcho=false; - m_nDop=0; - m_nDop00=0; - m_nDopr=0; m_nclearave=1; signalMeter = new SignalMeter(ui->meterFrame); @@ -962,7 +958,6 @@ void MainWindow::on_actionSettings_triggered() //Setup Dialog { Q_EMIT m_config.transceiver_frequency (m_dialFreq); } - if(m_astroWidget) m_astroWidget->m_azelDir=m_config.azel_directory(); } void MainWindow::on_monitorButton_clicked (bool checked) @@ -1223,11 +1218,7 @@ void MainWindow::displayDialFrequency () valid = true; } - ui->labDialFreq->setProperty ("oob", !valid); - // the following sequence is necessary to update the style - ui->labDialFreq->style ()->unpolish (ui->labDialFreq); - ui->labDialFreq->style ()->polish (ui->labDialFreq); - ui->labDialFreq->update (); + update_dynamic_property (ui->labDialFreq, "oob", !valid); ui->labDialFreq->setText (Radio::pretty_frequency_MHz_string (m_dialFreq)); } @@ -1357,13 +1348,12 @@ void MainWindow::on_actionAstronomical_data_triggered() { if (!m_astroWidget) { - m_astroWidget.reset (new Astro {m_settings}); + m_astroWidget.reset (new Astro {m_settings, &m_config}); // hook up termination signal connect (this, &MainWindow::finished, m_astroWidget.data (), &Astro::close); } m_astroWidget->showNormal(); - m_astroWidget->m_azelDir=m_config.azel_directory(); } void MainWindow::on_actionMessage_averaging_triggered() @@ -2137,28 +2127,6 @@ void MainWindow::guiUpdate() on_actionOpen_next_in_directory_triggered(); } - Frequency f; - if(m_astroWidget) { - m_bDopplerTracking = m_astroWidget->m_bDopplerTracking; - m_DopplerMethod = m_astroWidget->m_DopplerMethod; - if((m_bDopplerTracking0 and !m_bDopplerTracking) or - (m_DopplerMethod==0 and m_DopplerMethod0>0)) { -//Doppler tracking has just been turned off. Reset dial frequency to "nominal + kHz" - if(m_transmitting) { - m_dialFreqTx=m_freqNominal + 1000*m_astroWidget->m_kHz + m_astroWidget->m_Hz; - ui->labDialFreq->setText (Radio::pretty_frequency_MHz_string (m_dialFreqTx)); - Q_EMIT m_config.transceiver_tx_frequency (m_dialFreqTx); - } else { - f=m_freqNominal + 1000*m_astroWidget->m_kHz + m_astroWidget->m_Hz; -// m_dialFreq=f; -// ui->labDialFreq->setText (Radio::pretty_frequency_MHz_string (m_dialFreq)); - Q_EMIT m_config.transceiver_frequency(f); - } - } - m_bDopplerTracking0 = m_bDopplerTracking; - m_DopplerMethod0 = m_DopplerMethod; - } - if(m_auto and m_mode=="Echo" and m_bEchoTxOK) progressBar->setValue( int(100*m_s6/6.0)); @@ -2169,53 +2137,17 @@ void MainWindow::guiUpdate() progressBar->setValue(ipct); } QDateTime t = QDateTime::currentDateTimeUtc(); - if(m_astroWidget) { - m_freqMoon=m_dialFreq + 1000*m_astroWidget->m_kHz + m_astroWidget->m_Hz; - m_astroWidget->astroUpdate(t, m_config.my_grid (), m_hisGrid,m_freqMoon, - &m_nDop, &m_nDop00, m_transmitting, - m_config.data_dir().absoluteFilePath("JPLEPH")); - -//Apply Doppler corrections only for 50 MHz and above - if(m_freqNominal>=50000000) { - - if(m_astroWidget->m_bDopplerTracking) { - - m_nDopr=0; - if(m_DopplerMethod==1) { -// All Doppler correction done here; DX station stays at nominal dial frequency. - if(m_mode=="Echo") { - m_nDopr=m_astroWidget->m_stepHz*qRound(double(m_nDop00)/double( - m_astroWidget->m_stepHz)); - } else { - m_nDopr=m_astroWidget->m_stepHz*qRound(double(m_nDop)/double( - m_astroWidget->m_stepHz)); - } - } - if(m_DopplerMethod==2) { - // Doppler correction to constant frequency on Moon - m_nDopr=m_astroWidget->m_stepHz*qRound(double(m_nDop00/2.0)/double( - m_astroWidget->m_stepHz)); - } - - if(m_transmitting) { - m_dialFreqTx=m_freqNominal + 1000*m_astroWidget->m_kHz + - m_astroWidget->m_Hz - m_nDopr; - ui->labDialFreq->setText (Radio::pretty_frequency_MHz_string ( - m_dialFreqTx)); - Q_EMIT m_config.transceiver_tx_frequency (m_dialFreqTx); - } else { - if(m_mode=="Echo" and m_DopplerMethod==1) { - m_dialFreq=m_freqNominal + 1000*m_astroWidget->m_kHz + - m_astroWidget->m_Hz; - } else { - m_dialFreq=m_freqNominal + 1000*m_astroWidget->m_kHz + - m_astroWidget->m_Hz + m_nDopr; - } - ui->labDialFreq->setText (Radio::pretty_frequency_MHz_string ( - m_dialFreq)); - Q_EMIT m_config.transceiver_frequency(m_dialFreq); - } - } + if (m_astroWidget) { + auto astro_correction = m_astroWidget->astroUpdate(t, m_config.my_grid (), m_hisGrid + , m_dialFreq, "Echo" == m_mode, m_transmitting); + if(m_transmitting) { + m_dialFreqTx = m_freqNominal + astro_correction; + ui->labDialFreq->setText (Radio::pretty_frequency_MHz_string (m_dialFreqTx)); + Q_EMIT m_config.transceiver_tx_frequency (m_dialFreqTx); + } else { + m_dialFreq = m_freqNominal + astro_correction; + ui->labDialFreq->setText (Radio::pretty_frequency_MHz_string (m_dialFreq)); + Q_EMIT m_config.transceiver_frequency(m_dialFreq); } } diff --git a/mainwindow.h b/mainwindow.h index a22742820..70533cc9d 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -327,15 +327,10 @@ private: qint32 m_MinW; qint32 m_tol; qint32 m_nclearave; - qint32 m_DopplerMethod; - qint32 m_DopplerMethod0; qint32 m_minSync; qint32 m_dBm; qint32 m_pctx; qint32 m_nseq; - qint32 m_nDop; //Doppler shift of EME DX station - qint32 m_nDop00; //EME self-Doppler - qint32 m_nDopr; //Applied Doppler (rounded to nearest 1, 10 or 100 Hz) bool m_btxok; //True if OK to transmit bool m_diskData; @@ -380,8 +375,6 @@ private: bool m_bAstroData; bool m_bEME; bool m_bShMsgs; - bool m_bDopplerTracking; - bool m_bDopplerTracking0; bool m_uploadSpots; bool m_uploading; bool m_txNext;