Skip to content

Commit

Permalink
Notification: Added Rig Notification Message
Browse files Browse the repository at this point in the history
  • Loading branch information
foldynl committed Dec 15, 2024
1 parent 848bd6a commit 4f19690
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 3 deletions.
99 changes: 99 additions & 0 deletions core/NetworkNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ void NetworkNotification::saveNotifSpotAlertAddrs(const QString &addresses)

}

QString NetworkNotification::getNotifRigStateAddrs()
{
FCT_IDENTIFICATION;

QSettings settings;
return settings.value(NetworkNotification::CONFIG_NOTIF_RIGSTATE_ADDRS_KEY).toString();
}

void NetworkNotification::saveNotifRigStateAddrs(const QString &addresses)
{
FCT_IDENTIFICATION;

QSettings settings;
settings.setValue(NetworkNotification::CONFIG_NOTIF_RIGSTATE_ADDRS_KEY, addresses);
}

void NetworkNotification::QSOInserted(const QSqlRecord &record)
{
FCT_IDENTIFICATION;
Expand Down Expand Up @@ -214,6 +230,21 @@ void NetworkNotification::spotAlert(const SpotAlert &spot)
}
}

void NetworkNotification::rigStatus(const Rig::Status &status)
{
FCT_IDENTIFICATION;

qCDebug(function_parameters) << "Rig Status";

HostsPortString destList(getNotifSpotAlertAddrs());

if ( destList.getAddrList().size() > 0 )
{
RigStatusNotificationMsg rigStatusMsg(status);
send(rigStatusMsg.getJson(), destList);
}
}

void NetworkNotification::send(const QByteArray &data, const HostsPortString &dests)
{
FCT_IDENTIFICATION;
Expand All @@ -240,6 +271,7 @@ QString NetworkNotification::CONFIG_NOTIF_QSO_ADI_ADDRS_KEY = "network/notificat
QString NetworkNotification::CONFIG_NOTIF_DXSPOT_ADDRS_KEY = "network/notification/dxspot/addrs";
QString NetworkNotification::CONFIG_NOTIF_WSJTXCQSPOT_ADDRS_KEY = "network/notification/wsjtx/cqspot/addrs";
QString NetworkNotification::CONFIG_NOTIF_SPOTALERT_ADDRS_KEY = "network/notification/alerts/spot/addrs";
QString NetworkNotification::CONFIG_NOTIF_RIGSTATE_ADDRS_KEY = "network/notification/rig/state/addrs";

GenericNotificationMsg::GenericNotificationMsg(QObject *parent) :
QObject(parent)
Expand Down Expand Up @@ -469,3 +501,70 @@ ToAllSpotNotificationMsg::ToAllSpotNotificationMsg(const ToAllSpot &spot, QObjec
msg["msgtype"] = "toallspot";
msg["data"] = spotData;
}

RigStatusNotificationMsg::RigStatusNotificationMsg(const Rig::Status &status, QObject *parent) :
GenericNotificationMsg(parent)
{
FCT_IDENTIFICATION;

QJsonObject vfoState;

auto addIfNoEmpty = [&](const QString &key,
const QString &value,
bool addCond = true)
{
if ( !value.isEmpty() && addCond)
vfoState[key] = value;
};

auto addBoolIfNoEmpty = [&](const QString &key,
const qint8 &value,
bool addCond = true)
{
if ( addCond )
vfoState[key] = ( value != 0 );
};

auto addDoubleIfNoEmpty = [&](const QString &key,
const double &value,
bool addCond = true)
{
if ( value != 0.0 && addCond )
vfoState[key] = value;
};

addIfNoEmpty("vfo", status.vfo);
addIfNoEmpty("freq", QString::number(status.freq, 'f', 5), status.freq != 0.0);
addIfNoEmpty("mode", status.mode);
addIfNoEmpty("submode", status.submode);
addIfNoEmpty("rawmode", status.rawmode);
addBoolIfNoEmpty("ptt", status.ptt, status.ptt != -1);
addDoubleIfNoEmpty("rit", status.rit);
addDoubleIfNoEmpty("xit", status.xit);
addDoubleIfNoEmpty("bandwidth", status.bandwidth);

QJsonArray vfoStates;
vfoStates.append(vfoState);

QJsonObject rigData;
rigData["profile"] = status.profile;
rigData["connected"] = status.isConnected;

if ( !status.vfo.isEmpty() )
{
rigData["txvfo"] = status.vfo;
rigData["rxvfo"] = status.vfo; // split mode is not supported yet
}

if ( status.power > 0.0 )
rigData["txpower"] = status.power;

if ( vfoState.size() > 0 )
rigData["vfostates"] = vfoStates;

if ( status.keySpeed > 0 )
rigData["keyspeed"] = status.keySpeed;

msg["msgtype"] = "rigstatus";
msg["data"] = rigData;
}
13 changes: 13 additions & 0 deletions core/NetworkNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "data/WCYSpot.h"
#include "data/WWVSpot.h"
#include "data/ToAllSpot.h"
#include "rig/Rig.h"

class GenericNotificationMsg : public QObject
{
Expand Down Expand Up @@ -115,6 +116,14 @@ class ToAllSpotNotificationMsg : public GenericNotificationMsg

};

class RigStatusNotificationMsg : public GenericNotificationMsg
{

public:
explicit RigStatusNotificationMsg(const Rig::Status&, QObject *parent = nullptr);

};

class NetworkNotification : public QObject
{
Q_OBJECT
Expand All @@ -129,6 +138,8 @@ class NetworkNotification : public QObject
static void saveNotifWSJTXCQSpotAddrs(const QString &);
static QString getNotifSpotAlertAddrs();
static void saveNotifSpotAlertAddrs(const QString &);
static QString getNotifRigStateAddrs();
static void saveNotifRigStateAddrs(const QString &);

public slots:
void QSOInserted(const QSqlRecord &);
Expand All @@ -140,6 +151,7 @@ public slots:
void toAllSpot(const ToAllSpot&);
void WSJTXCQSpot(const WsjtxEntry&);
void spotAlert(const SpotAlert&);
void rigStatus(const Rig::Status&);

private:

Expand All @@ -149,6 +161,7 @@ public slots:
static QString CONFIG_NOTIF_DXSPOT_ADDRS_KEY;
static QString CONFIG_NOTIF_WSJTXCQSPOT_ADDRS_KEY;
static QString CONFIG_NOTIF_SPOTALERT_ADDRS_KEY;
static QString CONFIG_NOTIF_RIGSTATE_ADDRS_KEY;

};

Expand Down
1 change: 1 addition & 0 deletions core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ int main(int argc, char* argv[])
qRegisterMetaType<DxSpot>();
qRegisterMetaType<BandPlan::BandPlanMode>();
qRegisterMetaType<SpotAlert>();
qRegisterMetaType<Rig::Status>();

set_debug_level(LEVEL_PRODUCTION); // you can set more verbose rules via
// environment variable QT_LOGGING_RULES (project setting/debug)
Expand Down
43 changes: 40 additions & 3 deletions rig/Rig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,45 +200,64 @@ void Rig::__openRig()

connect( rigDriver, &GenericRigDrv::frequencyChanged, this, [this](double a, double b, double c)
{
rigStatus.freq = a;
emit frequencyChanged(VFO1, a, b, c);
emitRigStatusChanged();
});

connect( rigDriver, &GenericRigDrv::pttChanged, this, [this](bool a)
{
rigStatus.ptt = (a) ? 1 : 0;
emit pttChanged(VFO1, a);
emitRigStatusChanged();
});

connect( rigDriver, &GenericRigDrv::modeChanged, this, [this](const QString &a,
const QString &b,
const QString &c,
qint32 d)
const QString &b,
const QString &c,
qint32 d)
{
rigStatus.rawmode = a;
rigStatus.mode = b;
rigStatus.submode = c;
rigStatus.bandwidth = d;
emit modeChanged(VFO1, a, b, c, d);
emitRigStatusChanged();
});

connect( rigDriver, &GenericRigDrv::vfoChanged, this, [this](const QString &a)
{
rigStatus.vfo = a;
emit vfoChanged(VFO1, a);
emitRigStatusChanged();
});

connect( rigDriver, &GenericRigDrv::powerChanged, this, [this](double a)
{
rigStatus.power = a;
emit powerChanged(VFO1, a);
emitRigStatusChanged();
});

connect( rigDriver, &GenericRigDrv::ritChanged, this, [this](double a)
{
rigStatus.rit = a;
emit ritChanged(VFO1, a);
emitRigStatusChanged();
});

connect( rigDriver, &GenericRigDrv::xitChanged, this, [this](double a)
{
rigStatus.xit = a;
emit xitChanged(VFO1, a);
emitRigStatusChanged();
});

connect( rigDriver, &GenericRigDrv::keySpeedChanged, this, [this](unsigned int a)
{
rigStatus.keySpeed = a;
emit keySpeedChanged(VFO1, a);
emitRigStatusChanged();
});

connect( rigDriver, &GenericRigDrv::errorOccured, this, [this](const QString &a,
Expand All @@ -259,6 +278,8 @@ void Rig::__openRig()
emit rigCWKeyOpenRequest(newRigProfile.assignedCWKey);
}

rigStatus.profile = newRigProfile.profileName;
rigStatus.isConnected = true;
emit rigConnected();

sendState();
Expand Down Expand Up @@ -308,6 +329,10 @@ void Rig::__closeRig()
emit rigCWKeyCloseRequest(connectedRigProfile.assignedCWKey);
}

rigStatus.isConnected = false;
emitRigStatusChanged();
rigStatus.clear();

delete rigDriver;
rigDriver = nullptr;
connected = false;
Expand Down Expand Up @@ -599,6 +624,18 @@ GenericRigDrv *Rig::getDriver( const RigProfile &profile )
#endif
}

void Rig::emitRigStatusChanged()
{
FCT_IDENTIFICATION;

// it can happen especially with TCI that Rig received information,
// emit signals but rig is not connected.
if ( rigStatus.profile.isEmpty() )
return;

emit rigStatusChanged(rigStatus);
}

const QStringList Rig::getAvailableRawModes()
{
FCT_IDENTIFICATION;
Expand Down
39 changes: 39 additions & 0 deletions rig/Rig.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,40 @@ class Rig : public QObject
TCI_DRIVER = 4
};

struct Status
{
QString profile;
double freq = 0.0;
QString mode;
QString submode;
QString rawmode;
qint8 ptt = -1;
double power = -1.0;
int keySpeed = -1;
QString vfo = "Curr";
double rit = 0.0;
double xit = 0.0;
qint32 bandwidth = 0;
bool isConnected = false;

void clear()
{
profile.clear();
freq = 0.0;
mode.clear();
submode.clear();
rawmode.clear();
ptt = -1;
power = -1.0;
keySpeed = -1;
vfo.clear();
rit = 0.0;
xit = 0.0;
bandwidth = 0;
isConnected = false;
};
};

static Rig* instance()
{
static Rig instance;
Expand Down Expand Up @@ -82,6 +116,7 @@ public slots:
void rigDisconnected();
void rigConnected();
void rigErrorPresent(QString, QString);
void rigStatusChanged(Rig::Status);

private slots:
void stopTimerImplt();
Expand Down Expand Up @@ -132,11 +167,15 @@ private slots:
void __closeRig();
void __openRig();
GenericRigDrv *getDriver(const RigProfile &profile);
void emitRigStatusChanged();

private:
GenericRigDrv *rigDriver;
QMutex rigLock;
Rig::Status rigStatus;
bool connected;
};

Q_DECLARE_METATYPE(Rig::Status);

#endif // RIG_RIG_H
1 change: 1 addition & 0 deletions ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ MainWindow::MainWindow(QWidget* parent) :
connect(Rig::instance(), &Rig::xitChanged, ui->rigWidget, &RigWidget::updateXIT);
connect(Rig::instance(), &Rig::ritChanged, ui->rigWidget, &RigWidget::updateRIT);
connect(Rig::instance(), &Rig::pttChanged, ui->rigWidget, &RigWidget::updatePTT);
connect(Rig::instance(), &Rig::rigStatusChanged, &networknotification, &NetworkNotification::rigStatus);

connect(Rotator::instance(), &Rotator::rotErrorPresent, this, &MainWindow::rotErrorHandler);
connect(Rotator::instance(), &Rotator::positionChanged, ui->onlineMapWidget, &OnlineMapWidget::antPositionChanged);
Expand Down
3 changes: 3 additions & 0 deletions ui/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ SettingsDialog::SettingsDialog(MainWindow *parent) :
ui->notifDXSpotsEdit->setValidator(new QRegularExpressionValidator(HostsPortString::hostsPortRegEx(), this));
ui->notifWSJTXCQSpotsEdit->setValidator(new QRegularExpressionValidator(HostsPortString::hostsPortRegEx(), this));
ui->notifSpotAlertEdit->setValidator(new QRegularExpressionValidator(HostsPortString::hostsPortRegEx(), this));
ui->notifRigEdit->setValidator(new QRegularExpressionValidator(HostsPortString::hostsPortRegEx(), this));

iotaCompleter = new QCompleter(Data::instance()->iotaIDList(), this);
iotaCompleter->setCaseSensitivity(Qt::CaseInsensitive);
Expand Down Expand Up @@ -2342,6 +2343,7 @@ void SettingsDialog::readSettings() {
ui->notifDXSpotsEdit->setText(NetworkNotification::getNotifDXSpotAddrs());
ui->notifWSJTXCQSpotsEdit->setText(NetworkNotification::getNotifWSJTXCQSpotAddrs());
ui->notifSpotAlertEdit->setText(NetworkNotification::getNotifSpotAlertAddrs());
ui->notifRigEdit->setText(NetworkNotification::getNotifRigStateAddrs());

/******************/
/* END OF Reading */
Expand Down Expand Up @@ -2453,6 +2455,7 @@ void SettingsDialog::writeSettings() {
NetworkNotification::saveNotifDXSpotAddrs(ui->notifDXSpotsEdit->text());
NetworkNotification::saveNotifWSJTXCQSpotAddrs(ui->notifWSJTXCQSpotsEdit->text());
NetworkNotification::saveNotifSpotAlertAddrs(ui->notifSpotAlertEdit->text());
NetworkNotification::saveNotifRigStateAddrs(ui->notifSpotAlertEdit->text());
}

/* this function is called when user modify rig progile
Expand Down
Loading

0 comments on commit 4f19690

Please sign in to comment.