From d0a9a467204f871e68a6e0e87530f67e63240f80 Mon Sep 17 00:00:00 2001 From: Ladislav Foldyna Date: Thu, 24 Aug 2023 20:03:49 +0200 Subject: [PATCH 1/2] Added Az BeamWidth and Offset to Antenna Profile --- core/Migration.h | 2 +- core/Rotator.cpp | 4 +++ data/AntProfile.cpp | 20 +++++++++---- data/AntProfile.h | 5 +++- res/res.qrc | 1 + res/sql/migration_021.sql | 2 ++ ui/MainWindow.cpp | 1 + ui/OnlineMapWidget.cpp | 7 +++-- ui/SettingsDialog.cpp | 6 ++++ ui/SettingsDialog.ui | 63 +++++++++++++++++++++++++++++++++++++++ 10 files changed, 102 insertions(+), 9 deletions(-) create mode 100644 res/sql/migration_021.sql diff --git a/core/Migration.h b/core/Migration.h index e691a5ef..430d8f96 100644 --- a/core/Migration.h +++ b/core/Migration.h @@ -38,7 +38,7 @@ class Migration : public QObject bool createTriggers(); QString fixIntlField(QSqlQuery &query, const QString &columName, const QString &columnNameIntl); - static const int latestVersion = 20; + static const int latestVersion = 21; }; #endif // MIGRATION_H diff --git a/core/Rotator.cpp b/core/Rotator.cpp index 19b296ac..e9ee209f 100644 --- a/core/Rotator.cpp +++ b/core/Rotator.cpp @@ -2,6 +2,7 @@ #include "Rotator.h" #include "core/debug.h" #include "data/RotProfile.h" +#include "data/AntProfile.h" #ifdef Q_OS_WIN #include @@ -141,6 +142,7 @@ void Rotator::update() int newAzimuth = static_cast(az); int newElevation = static_cast(el); // Azimuth Normalization (-180,180) -> (0,360) - ADIF defined interval is 0-360 + newAzimuth += AntProfilesManager::instance()->getCurProfile1().azimuthOffset; newAzimuth = (newAzimuth < 0 ) ? 360 + newAzimuth : newAzimuth; if ( newAzimuth != this->azimuth @@ -304,6 +306,8 @@ void Rotator::setPositionImpl(int azimuth, int elevation) { if ( !isRotConnected() ) return; + azimuth -= AntProfilesManager::instance()->getCurProfile1().azimuthOffset; + rotLock.lock(); if ( azimuth > 180 ) diff --git a/data/AntProfile.cpp b/data/AntProfile.cpp index f0e4f6eb..61f71e42 100644 --- a/data/AntProfile.cpp +++ b/data/AntProfile.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "AntProfile.h" #include "core/debug.h" @@ -10,7 +11,7 @@ MODULE_IDENTIFICATION("qlog.data.antprofile"); QDataStream& operator<<(QDataStream& out, const AntProfile& v) { - out << v.profileName << v.description; + out << v.profileName << v.description << v.azimuthBeamWidth << v.azimuthOffset; return out; } @@ -18,6 +19,9 @@ QDataStream& operator>>(QDataStream& in, AntProfile& v) { in >> v.profileName; in >> v.description; + in >> v.azimuthBeamWidth; + in >> v.azimuthOffset; + return in; } @@ -29,7 +33,7 @@ AntProfilesManager::AntProfilesManager(QObject *parent) : QSqlQuery profileQuery; - if ( ! profileQuery.prepare("SELECT profile_name, desc FROM ant_profiles") ) + if ( ! profileQuery.prepare("SELECT profile_name, desc, azimuth_beamwidth, azimuth_offset FROM ant_profiles") ) { qWarning()<< "Cannot prepare select"; } @@ -41,6 +45,8 @@ AntProfilesManager::AntProfilesManager(QObject *parent) : AntProfile profileDB; profileDB.profileName = profileQuery.value(0).toString(); profileDB.description = profileQuery.value(1).toString(); + profileDB.azimuthBeamWidth = profileQuery.value(2).toDouble(); + profileDB.azimuthOffset = profileQuery.value(3).toDouble(); addProfile(profileDB.profileName, profileDB); } @@ -73,8 +79,8 @@ void AntProfilesManager::save() return; } - if ( ! insertQuery.prepare("INSERT INTO ant_profiles(profile_name, desc) " - "VALUES (:profile_name, :desc)") ) + if ( ! insertQuery.prepare("INSERT INTO ant_profiles(profile_name, desc, azimuth_beamwidth, azimuth_offset) " + "VALUES (:profile_name, :desc, :azimuth_beamwidth, :azimuth_offset)") ) { qWarning() << "cannot prepare Insert statement"; return; @@ -89,6 +95,8 @@ void AntProfilesManager::save() insertQuery.bindValue(":profile_name", key); insertQuery.bindValue(":desc", antProfile.description); + insertQuery.bindValue(":azimuth_beamwidth", antProfile.azimuthBeamWidth); + insertQuery.bindValue(":azimuth_offset", antProfile.azimuthOffset); if ( ! insertQuery.exec() ) @@ -109,7 +117,9 @@ void AntProfilesManager::save() bool AntProfile::operator==(const AntProfile &profile) { return (profile.profileName == this->profileName - && profile.description == this->description); + && profile.description == this->description + && profile.azimuthBeamWidth == this->azimuthBeamWidth + && profile.azimuthOffset == this->azimuthOffset); } bool AntProfile::operator!=(const AntProfile &profile) diff --git a/data/AntProfile.h b/data/AntProfile.h index 72fa5a0c..735cec2e 100644 --- a/data/AntProfile.h +++ b/data/AntProfile.h @@ -3,6 +3,7 @@ #include #include +#include #include "data/ProfileManager.h" @@ -12,9 +13,11 @@ class AntProfile { public: - AntProfile(){}; + AntProfile() : azimuthBeamWidth(0.0), azimuthOffset(0.0) {}; QString profileName; QString description; + double azimuthBeamWidth; + double azimuthOffset; bool operator== (const AntProfile &profile); bool operator!= (const AntProfile &profile); diff --git a/res/res.qrc b/res/res.qrc index 99c41ee8..d16dc732 100644 --- a/res/res.qrc +++ b/res/res.qrc @@ -33,5 +33,6 @@ sql/migration_018.sql sql/migration_019.sql sql/migration_020.sql + sql/migration_021.sql diff --git a/res/sql/migration_021.sql b/res/sql/migration_021.sql new file mode 100644 index 00000000..64acc8c7 --- /dev/null +++ b/res/sql/migration_021.sql @@ -0,0 +1,2 @@ +ALTER TABLE ant_profiles ADD azimuth_beamwidth DOUBLE DEFAULT 0.0; +ALTER TABLE ant_profiles ADD azimuth_offset DOUBLE DEFAULT 0.0; diff --git a/ui/MainWindow.cpp b/ui/MainWindow.cpp index e0da4d52..2688e777 100644 --- a/ui/MainWindow.cpp +++ b/ui/MainWindow.cpp @@ -171,6 +171,7 @@ MainWindow::MainWindow(QWidget* parent) : connect(ui->newContactWidget, &NewContactWidget::stationProfileChanged, this, &MainWindow::stationProfileChanged); connect(ui->newContactWidget, &NewContactWidget::stationProfileChanged, ui->rotatorWidget, &RotatorWidget::redrawMap); connect(ui->newContactWidget, &NewContactWidget::stationProfileChanged, ui->onlineMapWidget, &OnlineMapWidget::flyToMyQTH); + connect(ui->newContactWidget, &NewContactWidget::antProfileChanged, ui->onlineMapWidget, &OnlineMapWidget::flyToMyQTH); connect(ui->newContactWidget, &NewContactWidget::markQSO, ui->bandmapWidget, &BandmapWidget::addSpot); connect(ui->newContactWidget, &NewContactWidget::rigProfileChanged, ui->rigWidget, &RigWidget::refreshRigProfileCombo); diff --git a/ui/OnlineMapWidget.cpp b/ui/OnlineMapWidget.cpp index 2bdf1be2..a177f2dd 100644 --- a/ui/OnlineMapWidget.cpp +++ b/ui/OnlineMapWidget.cpp @@ -11,6 +11,7 @@ #include "core/debug.h" #include "core/Gridsquare.h" #include "data/StationProfile.h" +#include "data/AntProfile.h" #include "core/debug.h" #include "core/PropConditions.h" #include "data/Band.h" @@ -212,7 +213,7 @@ void OnlineMapWidget::antPositionChanged(int in_azimuth, int in_elevation) my_lon = myGrid.getLongitude(); double beamLen = 3000; // in km - double angle = 20; // in degree + double azimuthBeamWidth = AntProfilesManager::instance()->getCurProfile1().azimuthBeamWidth; if ( contact ) { double newBeamLen = contact->getQSODistance(); @@ -225,7 +226,7 @@ void OnlineMapWidget::antPositionChanged(int in_azimuth, int in_elevation) .arg(my_lon) .arg(beamLen) .arg(in_azimuth) - .arg(angle); + .arg(azimuthBeamWidth); } else { @@ -306,6 +307,8 @@ void OnlineMapWidget::flyToMyQTH() QString js = QString("flyToPoint(%1, 4);").arg(currentProfilePosition); runJavaScript(js); } + // redraw ant path because QSO distance can change + antPositionChanged(lastSeenAzimuth, lastSeenElevation); } OnlineMapWidget::~OnlineMapWidget() diff --git a/ui/SettingsDialog.cpp b/ui/SettingsDialog.cpp index 1334d7d7..145abe46 100644 --- a/ui/SettingsDialog.cpp +++ b/ui/SettingsDialog.cpp @@ -911,6 +911,8 @@ void SettingsDialog::addAntProfile() profile.profileName = ui->antProfileNameEdit->text(); profile.description = ui->antDescEdit->toPlainText(); + profile.azimuthBeamWidth = ui->antAzBeamWidthSpinBox->value(); + profile.azimuthOffset = ui->antAzOffsetSpinBox->value(); antProfManager->addProfile(profile.profileName, profile); @@ -953,6 +955,8 @@ void SettingsDialog::doubleClickAntProfile(QModelIndex i) ui->antProfileNameEdit->setText(profile.profileName); ui->antDescEdit->setPlainText(profile.description); + ui->antAzBeamWidthSpinBox->setValue(profile.azimuthBeamWidth); + ui->antAzOffsetSpinBox->setValue(profile.azimuthOffset); ui->antAddProfileButton->setText(tr("Modify")); @@ -966,6 +970,8 @@ void SettingsDialog::clearAntProfileForm() ui->antProfileNameEdit->clear(); ui->antDescEdit->clear(); + ui->antAzBeamWidthSpinBox->setValue(0.0); + ui->antAzOffsetSpinBox->setValue(0.0); ui->antAddProfileButton->setText(tr("Add")); } diff --git a/ui/SettingsDialog.ui b/ui/SettingsDialog.ui index 09137fd9..b0a7dd9f 100644 --- a/ui/SettingsDialog.ui +++ b/ui/SettingsDialog.ui @@ -370,6 +370,67 @@ + + + + Azimuth Beamwidth + + + + + + + Azimuth Offset + + + + + + + + 0 + 0 + + + + Valid range value is 0° - 100° (0° Unspecified) + + + Unspecified + + + ° + + + 1 + + + 100.000000000000000 + + + + + + + + 0 + 0 + + + + ° + + + 1 + + + -180.000000000000000 + + + 180.000000000000000 + + + @@ -3782,6 +3843,8 @@ stationDelProfileButton antProfileNameEdit antDescEdit + antAzBeamWidthSpinBox + antAzOffsetSpinBox antAddProfileButton antDelProfileButton cwProfileNameEdit From 31d1fa56be2426e9c8eeb8d3eb64e7aa0e5ba220 Mon Sep 17 00:00:00 2001 From: Ladislav Foldyna Date: Mon, 28 Aug 2023 14:52:47 +0200 Subject: [PATCH 2/2] Changed Azimuth from int to double --- core/Rotator.cpp | 29 +++++++++++++++-------------- core/Rotator.h | 14 +++++++------- ui/OnlineMapWidget.cpp | 11 ++++++----- ui/OnlineMapWidget.h | 4 ++-- ui/RotatorWidget.cpp | 19 ++++++++++--------- ui/RotatorWidget.h | 4 ++-- ui/RotatorWidget.ui | 23 +++++++++++++---------- 7 files changed, 55 insertions(+), 49 deletions(-) diff --git a/core/Rotator.cpp b/core/Rotator.cpp index e9ee209f..9d6d5d4b 100644 --- a/core/Rotator.cpp +++ b/core/Rotator.cpp @@ -28,8 +28,8 @@ Rotator::Rotator(QObject *parent) : { FCT_IDENTIFICATION; - azimuth = 0; - elevation = 0; + azimuth = 0.0; + elevation = 0.0; rot = nullptr; rig_set_debug(RIG_DEBUG_ERR); } @@ -46,7 +46,7 @@ Rotator* Rotator::instance() { return &instance; } -int Rotator::getAzimuth() +double Rotator::getAzimuth() { FCT_IDENTIFICATION; @@ -54,7 +54,7 @@ int Rotator::getAzimuth() return azimuth; } -int Rotator::getElevation() +double Rotator::getElevation() { FCT_IDENTIFICATION; @@ -139,11 +139,11 @@ void Rotator::update() int status = rot_get_position(rot, &az, &el); if ( status == RIG_OK ) { - int newAzimuth = static_cast(az); - int newElevation = static_cast(el); + double newAzimuth = az; + double newElevation = el; // Azimuth Normalization (-180,180) -> (0,360) - ADIF defined interval is 0-360 newAzimuth += AntProfilesManager::instance()->getCurProfile1().azimuthOffset; - newAzimuth = (newAzimuth < 0 ) ? 360 + newAzimuth : newAzimuth; + newAzimuth = (newAzimuth < 0.0 ) ? 360.0 + newAzimuth : newAzimuth; if ( newAzimuth != this->azimuth || newElevation != this->elevation @@ -270,8 +270,8 @@ void Rotator::__closeRot() FCT_IDENTIFICATION; connectedRotProfile = RotProfile(); - azimuth = 0; - elevation = 0; + azimuth = 0.0; + elevation = 0.0; if (isRotConnected()) { @@ -299,7 +299,8 @@ void Rotator::closeImpl() rotLock.unlock(); } -void Rotator::setPositionImpl(int azimuth, int elevation) { +void Rotator::setPositionImpl(double azimuth, double elevation) +{ FCT_IDENTIFICATION; qCDebug(function_parameters)< 180 ) + if ( azimuth > 180.0 ) { - azimuth = azimuth - 360; + azimuth = azimuth - 360.0; } int status = rot_set_position(rot, static_cast(azimuth), static_cast(elevation)); @@ -347,10 +348,10 @@ void Rotator::stopTimerImplt() } } -void Rotator::setPosition(int azimuth, int elevation) +void Rotator::setPosition(double azimuth, double elevation) { FCT_IDENTIFICATION; QMetaObject::invokeMethod(this, "setPositionImpl", Qt::QueuedConnection, - Q_ARG(int,azimuth), Q_ARG(int,elevation)); + Q_ARG(double,azimuth), Q_ARG(double,elevation)); } diff --git a/core/Rotator.h b/core/Rotator.h index e3f6946a..5d42c180 100644 --- a/core/Rotator.h +++ b/core/Rotator.h @@ -14,12 +14,12 @@ class Rotator : public SerialPort public: static Rotator* instance(); - int getAzimuth(); - int getElevation(); + double getAzimuth(); + double getElevation(); bool isRotConnected(); signals: - void positionChanged(int azimuth, int elevation); + void positionChanged(double azimuth, double elevation); void rotErrorPresent(QString, QString); void rotDisconnected(); void rotConnected(); @@ -32,10 +32,10 @@ public slots: void stopTimer(); void sendState(); - void setPosition(int azimuth, int elevation); + void setPosition(double azimuth, double elevation); private slots: - void setPositionImpl(int azimuth, int elevation); + void setPositionImpl(double azimuth, double elevation); void stopTimerImplt(); void openImpl(); void closeImpl(); @@ -48,8 +48,8 @@ private slots: void __openRot(); QString hamlibErrorString(int); - int azimuth; - int elevation; + double azimuth; + double elevation; ROT* rot; RotProfile connectedRotProfile; diff --git a/ui/OnlineMapWidget.cpp b/ui/OnlineMapWidget.cpp index a177f2dd..4f525709 100644 --- a/ui/OnlineMapWidget.cpp +++ b/ui/OnlineMapWidget.cpp @@ -27,8 +27,8 @@ OnlineMapWidget::OnlineMapWidget(QWidget *parent): webChannelHandler("onlinemap",parent), prop_cond(nullptr), contact(nullptr), - lastSeenAzimuth(0), - lastSeenElevation(0), + lastSeenAzimuth(0.0), + lastSeenElevation(0.0), isRotConnected(false) { FCT_IDENTIFICATION; @@ -189,7 +189,7 @@ void OnlineMapWidget::setIBPBand(VFOID , double, double ritFreq, double) runJavaScript(targetJavaScript); } -void OnlineMapWidget::antPositionChanged(int in_azimuth, int in_elevation) +void OnlineMapWidget::antPositionChanged(double in_azimuth, double in_elevation) { FCT_IDENTIFICATION; @@ -207,13 +207,14 @@ void OnlineMapWidget::antPositionChanged(int in_azimuth, int in_elevation) if ( myGrid.isValid() ) { - double my_lat=0; - double my_lon=0; + double my_lat=0.0; + double my_lon=0.0; my_lat = myGrid.getLatitude(); my_lon = myGrid.getLongitude(); double beamLen = 3000; // in km double azimuthBeamWidth = AntProfilesManager::instance()->getCurProfile1().azimuthBeamWidth; + if ( contact ) { double newBeamLen = contact->getQSODistance(); diff --git a/ui/OnlineMapWidget.h b/ui/OnlineMapWidget.h index 57d5bc45..d74e91b6 100644 --- a/ui/OnlineMapWidget.h +++ b/ui/OnlineMapWidget.h @@ -31,7 +31,7 @@ public slots: void auroraDataUpdate(); void mufDataUpdate(); void setIBPBand(VFOID, double, double, double); - void antPositionChanged(int in_azimuth, int in_elevation); + void antPositionChanged(double in_azimuth, double in_elevation); void rotConnected(); void rotDisconnected(); void flyToMyQTH(); @@ -48,7 +48,7 @@ protected slots: MapWebChannelHandler webChannelHandler; PropConditions *prop_cond; const NewContactWidget *contact; - int lastSeenAzimuth, lastSeenElevation; + double lastSeenAzimuth, lastSeenElevation; bool isRotConnected; void runJavaScript(QString &); diff --git a/ui/RotatorWidget.cpp b/ui/RotatorWidget.cpp index 3ceadf2c..85c6adf1 100644 --- a/ui/RotatorWidget.cpp +++ b/ui/RotatorWidget.cpp @@ -23,7 +23,7 @@ RotatorWidget::RotatorWidget(QWidget *parent) : ui->setupUi(this); - azimuth = 0; + azimuth = 0.0; redrawMap(); @@ -47,7 +47,7 @@ void RotatorWidget::gotoPosition() { FCT_IDENTIFICATION; - setBearing(ui->gotoSpinBox->value()); + setBearing(ui->gotoDoubleSpinBox->value()); } void RotatorWidget::setBearing(double in_azimuth) @@ -61,20 +61,21 @@ void RotatorWidget::setBearing(double in_azimuth) destinationAzimuthNeedle->setRotation(in_azimuth); } -void RotatorWidget::positionChanged(int in_azimuth, int in_elevation) { +void RotatorWidget::positionChanged(double in_azimuth, double in_elevation) +{ FCT_IDENTIFICATION; qCDebug(function_parameters)<setRotation(azimuth); if ( waitingFirstValue ) { waitingFirstValue = false; destinationAzimuthNeedle->setRotation(in_azimuth); } - ui->gotoSpinBox->blockSignals(true); - ui->gotoSpinBox->setValue(azimuth); - ui->gotoSpinBox->blockSignals(false); + ui->gotoDoubleSpinBox->blockSignals(true); + ui->gotoDoubleSpinBox->setValue(azimuth); + ui->gotoDoubleSpinBox->blockSignals(false); } void RotatorWidget::showEvent(QShowEvent* event) { @@ -346,7 +347,7 @@ void RotatorWidget::rotConnected() FCT_IDENTIFICATION; ui->rotProfileCombo->setStyleSheet("QComboBox {color: green}"); - ui->gotoSpinBox->setEnabled(true); + ui->gotoDoubleSpinBox->setEnabled(true); ui->gotoButton->setEnabled(true); ui->qsoBearingButton->setEnabled(true); ui->userButtonsProfileCombo->setEnabled(true); @@ -359,7 +360,7 @@ void RotatorWidget::rotDisconnected() FCT_IDENTIFICATION; ui->rotProfileCombo->setStyleSheet("QComboBox {color: red}"); - ui->gotoSpinBox->setEnabled(false); + ui->gotoDoubleSpinBox->setEnabled(false); ui->gotoButton->setEnabled(false); ui->qsoBearingButton->setEnabled(false); ui->userButtonsProfileCombo->setEnabled(false); diff --git a/ui/RotatorWidget.h b/ui/RotatorWidget.h index efe7cfb4..0354e9b0 100644 --- a/ui/RotatorWidget.h +++ b/ui/RotatorWidget.h @@ -29,7 +29,7 @@ class RotatorWidget : public QWidget public slots: void gotoPosition(); void setBearing(double); - void positionChanged(int, int); + void positionChanged(double, double); void redrawMap(); void rotProfileComboChanged(QString); void rotUserButtonProfileComboChanged(QString); @@ -60,7 +60,7 @@ private slots: bool waitingFirstValue; QGraphicsScene* compassScene; Ui::RotatorWidget *ui; - int azimuth; + double azimuth; const NewContactWidget *contact; }; diff --git a/ui/RotatorWidget.ui b/ui/RotatorWidget.ui index 0eba9d1a..0df6d057 100644 --- a/ui/RotatorWidget.ui +++ b/ui/RotatorWidget.ui @@ -6,7 +6,7 @@ 0 0 - 355 + 387 257 @@ -66,27 +66,30 @@ - + false - - - 50 - 16777215 - + + + 0 + 0 + Qt::ClickFocus + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + ° - - 0 + + 1 - 359 + 359.000000000000000