Skip to content

Commit

Permalink
Merge branch 'AntennaParams' into testing_0.28
Browse files Browse the repository at this point in the history
  • Loading branch information
foldynl committed Sep 10, 2023
2 parents 33ff680 + 31d1fa5 commit eede539
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 57 deletions.
33 changes: 19 additions & 14 deletions core/Rotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Rotator.h"
#include "core/debug.h"
#include "data/RotProfile.h"
#include "data/AntProfile.h"

#ifdef Q_OS_WIN
#include <windows.h>
Expand All @@ -27,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);
}
Expand All @@ -45,15 +46,15 @@ Rotator* Rotator::instance() {
return &instance;
}

int Rotator::getAzimuth()
double Rotator::getAzimuth()
{
FCT_IDENTIFICATION;

QMutexLocker locker(&rotLock);
return azimuth;
}

int Rotator::getElevation()
double Rotator::getElevation()
{
FCT_IDENTIFICATION;

Expand Down Expand Up @@ -138,10 +139,11 @@ void Rotator::update()
int status = rot_get_position(rot, &az, &el);
if ( status == RIG_OK )
{
int newAzimuth = static_cast<int>(az);
int newElevation = static_cast<int>(el);
double newAzimuth = az;
double newElevation = el;
// Azimuth Normalization (-180,180) -> (0,360) - ADIF defined interval is 0-360
newAzimuth = (newAzimuth < 0 ) ? 360 + newAzimuth : newAzimuth;
newAzimuth += AntProfilesManager::instance()->getCurProfile1().azimuthOffset;
newAzimuth = (newAzimuth < 0.0 ) ? 360.0 + newAzimuth : newAzimuth;

if ( newAzimuth != this->azimuth
|| newElevation != this->elevation
Expand Down Expand Up @@ -268,8 +270,8 @@ void Rotator::__closeRot()
FCT_IDENTIFICATION;

connectedRotProfile = RotProfile();
azimuth = 0;
elevation = 0;
azimuth = 0.0;
elevation = 0.0;

if (isRotConnected())
{
Expand Down Expand Up @@ -297,18 +299,21 @@ void Rotator::closeImpl()
rotLock.unlock();
}

void Rotator::setPositionImpl(int azimuth, int elevation) {
void Rotator::setPositionImpl(double azimuth, double elevation)
{
FCT_IDENTIFICATION;

qCDebug(function_parameters)<<azimuth<< " " << elevation;

if ( !isRotConnected() ) return;

azimuth -= AntProfilesManager::instance()->getCurProfile1().azimuthOffset;

rotLock.lock();

if ( azimuth > 180 )
if ( azimuth > 180.0 )
{
azimuth = azimuth - 360;
azimuth = azimuth - 360.0;
}

int status = rot_set_position(rot, static_cast<azimuth_t>(azimuth), static_cast<elevation_t>(elevation));
Expand Down Expand Up @@ -343,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));
}
14 changes: 7 additions & 7 deletions core/Rotator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -48,8 +48,8 @@ private slots:
void __openRot();
QString hamlibErrorString(int);

int azimuth;
int elevation;
double azimuth;
double elevation;

ROT* rot;
RotProfile connectedRotProfile;
Expand Down
20 changes: 15 additions & 5 deletions data/AntProfile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <QSettings>
#include <QSqlQuery>
#include <QSqlError>
#include <QVariant>

#include "AntProfile.h"
#include "core/debug.h"
Expand All @@ -10,14 +11,17 @@ 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;
}

QDataStream& operator>>(QDataStream& in, AntProfile& v)
{
in >> v.profileName;
in >> v.description;
in >> v.azimuthBeamWidth;
in >> v.azimuthOffset;

return in;
}

Expand All @@ -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";
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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() )
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion data/AntProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <QString>
#include <QObject>
#include <QDataStream>

#include "data/ProfileManager.h"

Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions res/sql/migration_021.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ CREATE TABLE IF NOT EXISTS chat_highlight_rules(
enabled INTEGER,
rule_definition TEXT
);

ALTER TABLE ant_profiles ADD azimuth_beamwidth DOUBLE DEFAULT 0.0;
ALTER TABLE ant_profiles ADD azimuth_offset DOUBLE DEFAULT 0.0;
1 change: 1 addition & 0 deletions ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,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);

Expand Down
18 changes: 11 additions & 7 deletions ui/OnlineMapWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,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;
Expand Down Expand Up @@ -189,7 +190,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;

Expand All @@ -207,13 +208,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 angle = 20; // in degree
double azimuthBeamWidth = AntProfilesManager::instance()->getCurProfile1().azimuthBeamWidth;

if ( contact )
{
double newBeamLen = contact->getQSODistance();
Expand All @@ -226,7 +228,7 @@ void OnlineMapWidget::antPositionChanged(int in_azimuth, int in_elevation)
.arg(my_lon)
.arg(beamLen)
.arg(in_azimuth)
.arg(angle);
.arg(azimuthBeamWidth);
}
else
{
Expand Down Expand Up @@ -316,6 +318,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);
}

void OnlineMapWidget::drawChatUsers(QList<KSTUsersInfo> list)
Expand Down
4 changes: 2 additions & 2 deletions ui/OnlineMapWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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();
Expand All @@ -54,7 +54,7 @@ protected slots:
MapWebChannelHandler webChannelHandler;
PropConditions *prop_cond;
const NewContactWidget *contact;
int lastSeenAzimuth, lastSeenElevation;
double lastSeenAzimuth, lastSeenElevation;
bool isRotConnected;

void runJavaScript(QString &);
Expand Down
19 changes: 10 additions & 9 deletions ui/RotatorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RotatorWidget::RotatorWidget(QWidget *parent) :

ui->setupUi(this);

azimuth = 0;
azimuth = 0.0;

redrawMap();

Expand All @@ -47,7 +47,7 @@ void RotatorWidget::gotoPosition()
{
FCT_IDENTIFICATION;

setBearing(ui->gotoSpinBox->value());
setBearing(ui->gotoDoubleSpinBox->value());
}

void RotatorWidget::setBearing(double in_azimuth)
Expand All @@ -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)<<in_azimuth<<" "<<in_elevation;
azimuth = (in_azimuth < 0 ) ? 360 + in_azimuth : in_azimuth;
azimuth = (in_azimuth < 0.0 ) ? 360.0 + in_azimuth : in_azimuth;
compassNeedle->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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit eede539

Please sign in to comment.