mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 01:39:05 -05:00
AFC: REST API: actions and report: implementation
This commit is contained in:
parent
598cefa933
commit
d0081b2af4
@ -46,7 +46,8 @@ const QString AFC::m_featureId = "AFC";
|
|||||||
AFC::AFC(WebAPIAdapterInterface *webAPIAdapterInterface) :
|
AFC::AFC(WebAPIAdapterInterface *webAPIAdapterInterface) :
|
||||||
Feature(m_featureIdURI, webAPIAdapterInterface),
|
Feature(m_featureIdURI, webAPIAdapterInterface),
|
||||||
m_trackerDeviceSet(nullptr),
|
m_trackerDeviceSet(nullptr),
|
||||||
m_trackedDeviceSet(nullptr)
|
m_trackedDeviceSet(nullptr),
|
||||||
|
m_trackerIndexInDeviceSet(-1)
|
||||||
{
|
{
|
||||||
setObjectName(m_featureId);
|
setObjectName(m_featureId);
|
||||||
m_worker = new AFCWorker(webAPIAdapterInterface);
|
m_worker = new AFCWorker(webAPIAdapterInterface);
|
||||||
@ -61,7 +62,8 @@ AFC::~AFC()
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete m_worker;
|
delete m_worker;
|
||||||
removeFeatureReferences();
|
removeTrackerFeatureReferences();
|
||||||
|
removeTrackedFeatureReferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AFC::start()
|
void AFC::start()
|
||||||
@ -217,11 +219,13 @@ void AFC::applySettings(const AFCSettings& settings, bool force)
|
|||||||
reverseAPIKeys.append("trackerAdjustPeriod");
|
reverseAPIKeys.append("trackerAdjustPeriod");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((m_settings.m_trackerDeviceSetIndex != settings.m_trackerDeviceSetIndex) || force) {
|
if ((m_settings.m_trackerDeviceSetIndex != settings.m_trackerDeviceSetIndex) || force)
|
||||||
|
{
|
||||||
trackerDeviceChange(settings.m_trackerDeviceSetIndex);
|
trackerDeviceChange(settings.m_trackerDeviceSetIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((m_settings.m_trackedDeviceSetIndex != settings.m_trackedDeviceSetIndex) || force) {
|
if ((m_settings.m_trackedDeviceSetIndex != settings.m_trackedDeviceSetIndex) || force)
|
||||||
|
{
|
||||||
trackedDeviceChange(settings.m_trackedDeviceSetIndex);
|
trackedDeviceChange(settings.m_trackedDeviceSetIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,6 +313,28 @@ int AFC::webapiActionsPost(
|
|||||||
|
|
||||||
if (swgAFCActions)
|
if (swgAFCActions)
|
||||||
{
|
{
|
||||||
|
if (featureActionsKeys.contains("deviceTrack"))
|
||||||
|
{
|
||||||
|
bool deviceTrack = swgAFCActions->getDeviceTrack() != 0;
|
||||||
|
|
||||||
|
if (deviceTrack)
|
||||||
|
{
|
||||||
|
MsgDeviceTrack *msg = MsgDeviceTrack::create();
|
||||||
|
getInputMessageQueue()->push(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (featureActionsKeys.contains("devicesApply"))
|
||||||
|
{
|
||||||
|
bool devicesApply = swgAFCActions->getDevicesApply() != 0;
|
||||||
|
|
||||||
|
if (devicesApply)
|
||||||
|
{
|
||||||
|
MsgDevicesApply *msg = MsgDevicesApply::create();
|
||||||
|
getInputMessageQueue()->push(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 202;
|
return 202;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -401,6 +427,9 @@ void AFC::webapiUpdateFeatureSettings(
|
|||||||
|
|
||||||
void AFC::webapiFormatFeatureReport(SWGSDRangel::SWGFeatureReport& response)
|
void AFC::webapiFormatFeatureReport(SWGSDRangel::SWGFeatureReport& response)
|
||||||
{
|
{
|
||||||
|
response.getAfcReport()->setTrackerChannelIndex(m_trackerIndexInDeviceSet);
|
||||||
|
response.getAfcReport()->setTrackerDeviceFrequency(m_worker->getTrackerDeviceFrequency());
|
||||||
|
response.getAfcReport()->setTrackerChannelOffset(m_worker->getTrackerChannelOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AFC::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const AFCSettings& settings, bool force)
|
void AFC::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const AFCSettings& settings, bool force)
|
||||||
@ -509,15 +538,18 @@ void AFC::trackedDeviceChange(int deviceIndex)
|
|||||||
{
|
{
|
||||||
ChannelAPI *channel = m_trackedDeviceSet->getChannelAt(i);
|
ChannelAPI *channel = m_trackedDeviceSet->getChannelAt(i);
|
||||||
|
|
||||||
if (channel->getURI() != "sdrangel.channel.freqtracker") {
|
if (channel->getURI() != "sdrangel.channel.freqtracker")
|
||||||
|
{
|
||||||
channel->addFeatureSettingsFeedback(this);
|
channel->addFeatureSettingsFeedback(this);
|
||||||
|
m_trackerIndexInDeviceSet = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AFC::removeFeatureReferences()
|
void AFC::removeTrackerFeatureReferences()
|
||||||
{
|
{
|
||||||
MainCore *mainCore = MainCore::instance();
|
MainCore *mainCore = MainCore::instance();
|
||||||
|
m_trackerIndexInDeviceSet = -1;
|
||||||
|
|
||||||
if ((m_settings.m_trackerDeviceSetIndex >= 0) && (m_settings.m_trackerDeviceSetIndex < mainCore->getDeviceSets().size()))
|
if ((m_settings.m_trackerDeviceSetIndex >= 0) && (m_settings.m_trackerDeviceSetIndex < mainCore->getDeviceSets().size()))
|
||||||
{
|
{
|
||||||
@ -532,6 +564,11 @@ void AFC::removeFeatureReferences()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AFC::removeTrackedFeatureReferences()
|
||||||
|
{
|
||||||
|
MainCore *mainCore = MainCore::instance();
|
||||||
|
|
||||||
if ((m_settings.m_trackedDeviceSetIndex >= 0) && (m_settings.m_trackedDeviceSetIndex < mainCore->getDeviceSets().size()))
|
if ((m_settings.m_trackedDeviceSetIndex >= 0) && (m_settings.m_trackedDeviceSetIndex < mainCore->getDeviceSets().size()))
|
||||||
{
|
{
|
||||||
|
@ -160,6 +160,7 @@ private:
|
|||||||
AFCSettings m_settings;
|
AFCSettings m_settings;
|
||||||
DeviceSet *m_trackerDeviceSet;
|
DeviceSet *m_trackerDeviceSet;
|
||||||
DeviceSet *m_trackedDeviceSet;
|
DeviceSet *m_trackedDeviceSet;
|
||||||
|
int m_trackerIndexInDeviceSet;
|
||||||
|
|
||||||
QNetworkAccessManager *m_networkManager;
|
QNetworkAccessManager *m_networkManager;
|
||||||
QNetworkRequest m_networkRequest;
|
QNetworkRequest m_networkRequest;
|
||||||
@ -171,7 +172,8 @@ private:
|
|||||||
void webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const AFCSettings& settings, bool force);
|
void webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const AFCSettings& settings, bool force);
|
||||||
void trackerDeviceChange(int deviceIndex);
|
void trackerDeviceChange(int deviceIndex);
|
||||||
void trackedDeviceChange(int deviceIndex);
|
void trackedDeviceChange(int deviceIndex);
|
||||||
void removeFeatureReferences();
|
void removeTrackerFeatureReferences();
|
||||||
|
void removeTrackedFeatureReferences();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void networkManagerFinished(QNetworkReply *reply);
|
void networkManagerFinished(QNetworkReply *reply);
|
||||||
|
@ -79,15 +79,19 @@ bool AFCGUI::handleMessage(const Message& message)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (AFCReport::MsgRadioState::match(message))
|
else if (AFCReport::MsgUpdateTarget::match(message))
|
||||||
{
|
{
|
||||||
qDebug("AFCGUI::handleMessage: AFCReport::MsgRadioState");
|
const AFCReport::MsgUpdateTarget& cfg = (AFCReport::MsgUpdateTarget&) message;
|
||||||
const AFCReport::MsgRadioState& cfg = (AFCReport::MsgRadioState&) message;
|
bool frequencyChanged = cfg.getFrequencyChanged();
|
||||||
AFCReport::RadioState state = cfg.getState();
|
|
||||||
ui->statusIndicator->setStyleSheet("QLabel { background-color: " +
|
|
||||||
m_statusColors[(int) state] + "; border-radius: 12px; }");
|
|
||||||
ui->statusIndicator->setToolTip(m_statusTooltips[(int) state]);
|
|
||||||
|
|
||||||
|
if (cfg.getFrequencyChanged()) {
|
||||||
|
ui->statusIndicator->setStyleSheet("QLabel { background-color: rgb(232, 85, 85); border-radius: 8px; }"); // red
|
||||||
|
} else {
|
||||||
|
ui->statusIndicator->setStyleSheet("QLabel { background-color: rgb(85, 232, 85); border-radius: 8px; }"); // green
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->statusIndicator->setToolTip(tr("%1 Hz").arg(cfg.getFrequencyAdjustment()));
|
||||||
|
m_autoTargetStatusTimer.start(500);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,13 +146,9 @@ AFCGUI::AFCGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *featur
|
|||||||
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
|
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
|
||||||
m_statusTimer.start(1000);
|
m_statusTimer.start(1000);
|
||||||
|
|
||||||
m_statusTooltips.push_back("Idle"); // 0 - all off
|
connect(&m_autoTargetStatusTimer, SIGNAL(timeout()), this, SLOT(resetAutoTargetStatus()));
|
||||||
m_statusTooltips.push_back("Rx on"); // 1 - Rx on
|
m_autoTargetStatusTimer.setSingleShot(true);
|
||||||
m_statusTooltips.push_back("Tx on"); // 2 - Tx on
|
ui->statusIndicator->setStyleSheet("QLabel { background-color: gray; border-radius: 8px; }");
|
||||||
|
|
||||||
m_statusColors.push_back("gray"); // All off
|
|
||||||
m_statusColors.push_back("rgb(85, 232, 85)"); // Rx on (green)
|
|
||||||
m_statusColors.push_back("rgb(232, 85, 85)"); // Tx on (red)
|
|
||||||
|
|
||||||
updateDeviceSetLists();
|
updateDeviceSetLists();
|
||||||
displaySettings();
|
displaySettings();
|
||||||
@ -401,6 +401,11 @@ void AFCGUI::updateStatus()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AFCGUI::resetAutoTargetStatus()
|
||||||
|
{
|
||||||
|
ui->statusIndicator->setStyleSheet("QLabel { background-color: gray; border-radius: 8px; }");
|
||||||
|
}
|
||||||
|
|
||||||
void AFCGUI::applySettings(bool force)
|
void AFCGUI::applySettings(bool force)
|
||||||
{
|
{
|
||||||
if (m_doApplySettings)
|
if (m_doApplySettings)
|
||||||
|
@ -53,9 +53,8 @@ private:
|
|||||||
AFC* m_afc;
|
AFC* m_afc;
|
||||||
MessageQueue m_inputMessageQueue;
|
MessageQueue m_inputMessageQueue;
|
||||||
QTimer m_statusTimer;
|
QTimer m_statusTimer;
|
||||||
|
QTimer m_autoTargetStatusTimer;
|
||||||
int m_lastFeatureState;
|
int m_lastFeatureState;
|
||||||
std::vector<QString> m_statusColors;
|
|
||||||
std::vector<QString> m_statusTooltips;
|
|
||||||
|
|
||||||
explicit AFCGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent = nullptr);
|
explicit AFCGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent = nullptr);
|
||||||
virtual ~AFCGUI();
|
virtual ~AFCGUI();
|
||||||
@ -85,6 +84,7 @@ private slots:
|
|||||||
void on_devicesApply_clicked();
|
void on_devicesApply_clicked();
|
||||||
void on_targetPeriod_valueChanged(int value);
|
void on_targetPeriod_valueChanged(int value);
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
|
void resetAutoTargetStatus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#include "afcreport.h"
|
#include "afcreport.h"
|
||||||
|
|
||||||
MESSAGE_CLASS_DEFINITION(AFCReport::MsgRadioState, Message)
|
MESSAGE_CLASS_DEFINITION(AFCReport::MsgUpdateTarget, Message)
|
||||||
|
|
||||||
AFCReport::AFCReport()
|
AFCReport::AFCReport()
|
||||||
{}
|
{}
|
||||||
|
@ -28,23 +28,26 @@ public:
|
|||||||
RadioRx,
|
RadioRx,
|
||||||
RadioTx
|
RadioTx
|
||||||
};
|
};
|
||||||
class MsgRadioState : public Message {
|
class MsgUpdateTarget : public Message {
|
||||||
MESSAGE_CLASS_DECLARATION
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RadioState getState() const { return m_state; }
|
int getFrequencyAdjustment() const { return m_frequencyAdjustment; }
|
||||||
|
bool getFrequencyChanged() const { return m_frequencyChanged; }
|
||||||
|
|
||||||
static MsgRadioState* create(RadioState state)
|
static MsgUpdateTarget* create(int frequencyAdjustment, bool frequencyChanged)
|
||||||
{
|
{
|
||||||
return new MsgRadioState(state);
|
return new MsgUpdateTarget(frequencyAdjustment, frequencyChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RadioState m_state;
|
int m_frequencyAdjustment;
|
||||||
|
bool m_frequencyChanged;
|
||||||
|
|
||||||
MsgRadioState(RadioState state) :
|
MsgUpdateTarget(int frequencyAdjustment, bool frequencyChanged) :
|
||||||
Message(),
|
Message(),
|
||||||
m_state(state)
|
m_frequencyAdjustment(frequencyAdjustment),
|
||||||
|
m_frequencyChanged(frequencyChanged)
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -393,9 +393,10 @@ void AFCWorker::updateTarget()
|
|||||||
int64_t trackerFrequency = m_trackerDeviceFrequency + m_trackerChannelOffset;
|
int64_t trackerFrequency = m_trackerDeviceFrequency + m_trackerChannelOffset;
|
||||||
int64_t correction = m_settings.m_targetFrequency - trackerFrequency;
|
int64_t correction = m_settings.m_targetFrequency - trackerFrequency;
|
||||||
int64_t tolerance = m_settings.m_freqTolerance;
|
int64_t tolerance = m_settings.m_freqTolerance;
|
||||||
qDebug() << "AFCWorker::updateTarget: correction:" << correction << "tolerance:" << tolerance;
|
|
||||||
|
|
||||||
if ((correction > -tolerance) && (correction < tolerance)) {
|
if ((correction > -tolerance) && (correction < tolerance))
|
||||||
|
{
|
||||||
|
reportUpdateTarget(correction, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,6 +421,8 @@ void AFCWorker::updateTarget()
|
|||||||
if (updateChannelOffset(m_freqTracker, 0, m_trackerChannelOffset + correction, 1)) {
|
if (updateChannelOffset(m_freqTracker, 0, m_trackerChannelOffset + correction, 1)) {
|
||||||
m_trackerChannelOffset += correction;
|
m_trackerChannelOffset += correction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportUpdateTarget(correction, true);
|
||||||
}
|
}
|
||||||
else // act on device
|
else // act on device
|
||||||
{
|
{
|
||||||
@ -436,6 +439,8 @@ void AFCWorker::updateTarget()
|
|||||||
qDebug() << "AFCWorker::updateTarget: cannot find device transverter frequency";
|
qDebug() << "AFCWorker::updateTarget: cannot find device transverter frequency";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportUpdateTarget(correction, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,3 +520,12 @@ void AFCWorker::getDeviceSettingsKey(DeviceAPI *deviceAPI, QString& settingsKey)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AFCWorker::reportUpdateTarget(int correction, bool done)
|
||||||
|
{
|
||||||
|
if (m_msgQueueToGUI)
|
||||||
|
{
|
||||||
|
AFCReport::MsgUpdateTarget *msg = AFCReport::MsgUpdateTarget::create(correction, done);
|
||||||
|
m_msgQueueToGUI->push(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -112,6 +112,8 @@ public:
|
|||||||
bool isRunning() const { return m_running; }
|
bool isRunning() const { return m_running; }
|
||||||
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
||||||
void setMessageQueueToGUI(MessageQueue *messageQueue) { m_msgQueueToGUI = messageQueue; }
|
void setMessageQueueToGUI(MessageQueue *messageQueue) { m_msgQueueToGUI = messageQueue; }
|
||||||
|
uint64_t getTrackerDeviceFrequency() const { return m_trackerDeviceFrequency; }
|
||||||
|
int getTrackerChannelOffset() const { return m_trackerChannelOffset; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ChannelTracking
|
struct ChannelTracking
|
||||||
@ -166,6 +168,7 @@ private:
|
|||||||
bool updateDeviceFrequency(DeviceSet *deviceSet, const QString& key, int64_t frequency);
|
bool updateDeviceFrequency(DeviceSet *deviceSet, const QString& key, int64_t frequency);
|
||||||
int getDeviceDirection(DeviceAPI *deviceAPI);
|
int getDeviceDirection(DeviceAPI *deviceAPI);
|
||||||
void getDeviceSettingsKey(DeviceAPI *deviceAPI, QString& settingsKey);
|
void getDeviceSettingsKey(DeviceAPI *deviceAPI, QString& settingsKey);
|
||||||
|
void reportUpdateTarget(int correction, bool done);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateTarget();
|
void updateTarget();
|
||||||
|
Loading…
Reference in New Issue
Block a user