1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

AFC: REST API: actions and report: implementation

This commit is contained in:
f4exb 2020-10-26 13:48:19 +01:00
parent 598cefa933
commit d0081b2af4
8 changed files with 97 additions and 33 deletions

View File

@ -46,7 +46,8 @@ const QString AFC::m_featureId = "AFC";
AFC::AFC(WebAPIAdapterInterface *webAPIAdapterInterface) :
Feature(m_featureIdURI, webAPIAdapterInterface),
m_trackerDeviceSet(nullptr),
m_trackedDeviceSet(nullptr)
m_trackedDeviceSet(nullptr),
m_trackerIndexInDeviceSet(-1)
{
setObjectName(m_featureId);
m_worker = new AFCWorker(webAPIAdapterInterface);
@ -61,7 +62,8 @@ AFC::~AFC()
}
delete m_worker;
removeFeatureReferences();
removeTrackerFeatureReferences();
removeTrackedFeatureReferences();
}
void AFC::start()
@ -217,11 +219,13 @@ void AFC::applySettings(const AFCSettings& settings, bool force)
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);
}
if ((m_settings.m_trackedDeviceSetIndex != settings.m_trackedDeviceSetIndex) || force) {
if ((m_settings.m_trackedDeviceSetIndex != settings.m_trackedDeviceSetIndex) || force)
{
trackedDeviceChange(settings.m_trackedDeviceSetIndex);
}
@ -309,6 +313,28 @@ int AFC::webapiActionsPost(
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;
}
else
@ -401,6 +427,9 @@ void AFC::webapiUpdateFeatureSettings(
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)
@ -509,15 +538,18 @@ void AFC::trackedDeviceChange(int deviceIndex)
{
ChannelAPI *channel = m_trackedDeviceSet->getChannelAt(i);
if (channel->getURI() != "sdrangel.channel.freqtracker") {
if (channel->getURI() != "sdrangel.channel.freqtracker")
{
channel->addFeatureSettingsFeedback(this);
m_trackerIndexInDeviceSet = i;
}
}
}
void AFC::removeFeatureReferences()
void AFC::removeTrackerFeatureReferences()
{
MainCore *mainCore = MainCore::instance();
m_trackerIndexInDeviceSet = -1;
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()))
{

View File

@ -160,6 +160,7 @@ private:
AFCSettings m_settings;
DeviceSet *m_trackerDeviceSet;
DeviceSet *m_trackedDeviceSet;
int m_trackerIndexInDeviceSet;
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
@ -171,7 +172,8 @@ private:
void webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const AFCSettings& settings, bool force);
void trackerDeviceChange(int deviceIndex);
void trackedDeviceChange(int deviceIndex);
void removeFeatureReferences();
void removeTrackerFeatureReferences();
void removeTrackedFeatureReferences();
private slots:
void networkManagerFinished(QNetworkReply *reply);

View File

@ -79,15 +79,19 @@ bool AFCGUI::handleMessage(const Message& message)
return true;
}
else if (AFCReport::MsgRadioState::match(message))
else if (AFCReport::MsgUpdateTarget::match(message))
{
qDebug("AFCGUI::handleMessage: AFCReport::MsgRadioState");
const AFCReport::MsgRadioState& cfg = (AFCReport::MsgRadioState&) message;
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]);
const AFCReport::MsgUpdateTarget& cfg = (AFCReport::MsgUpdateTarget&) message;
bool frequencyChanged = cfg.getFrequencyChanged();
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;
}
@ -142,13 +146,9 @@ AFCGUI::AFCGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *featur
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(1000);
m_statusTooltips.push_back("Idle"); // 0 - all off
m_statusTooltips.push_back("Rx on"); // 1 - Rx on
m_statusTooltips.push_back("Tx on"); // 2 - Tx on
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)
connect(&m_autoTargetStatusTimer, SIGNAL(timeout()), this, SLOT(resetAutoTargetStatus()));
m_autoTargetStatusTimer.setSingleShot(true);
ui->statusIndicator->setStyleSheet("QLabel { background-color: gray; border-radius: 8px; }");
updateDeviceSetLists();
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)
{
if (m_doApplySettings)

View File

@ -53,9 +53,8 @@ private:
AFC* m_afc;
MessageQueue m_inputMessageQueue;
QTimer m_statusTimer;
QTimer m_autoTargetStatusTimer;
int m_lastFeatureState;
std::vector<QString> m_statusColors;
std::vector<QString> m_statusTooltips;
explicit AFCGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent = nullptr);
virtual ~AFCGUI();
@ -85,6 +84,7 @@ private slots:
void on_devicesApply_clicked();
void on_targetPeriod_valueChanged(int value);
void updateStatus();
void resetAutoTargetStatus();
};

View File

@ -17,7 +17,7 @@
#include "afcreport.h"
MESSAGE_CLASS_DEFINITION(AFCReport::MsgRadioState, Message)
MESSAGE_CLASS_DEFINITION(AFCReport::MsgUpdateTarget, Message)
AFCReport::AFCReport()
{}

View File

@ -28,23 +28,26 @@ public:
RadioRx,
RadioTx
};
class MsgRadioState : public Message {
class MsgUpdateTarget : public Message {
MESSAGE_CLASS_DECLARATION
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:
RadioState m_state;
int m_frequencyAdjustment;
bool m_frequencyChanged;
MsgRadioState(RadioState state) :
MsgUpdateTarget(int frequencyAdjustment, bool frequencyChanged) :
Message(),
m_state(state)
m_frequencyAdjustment(frequencyAdjustment),
m_frequencyChanged(frequencyChanged)
{ }
};

View File

@ -393,9 +393,10 @@ void AFCWorker::updateTarget()
int64_t trackerFrequency = m_trackerDeviceFrequency + m_trackerChannelOffset;
int64_t correction = m_settings.m_targetFrequency - trackerFrequency;
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;
}
@ -420,6 +421,8 @@ void AFCWorker::updateTarget()
if (updateChannelOffset(m_freqTracker, 0, m_trackerChannelOffset + correction, 1)) {
m_trackerChannelOffset += correction;
}
reportUpdateTarget(correction, true);
}
else // act on device
{
@ -436,6 +439,8 @@ void AFCWorker::updateTarget()
qDebug() << "AFCWorker::updateTarget: cannot find device transverter frequency";
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);
}
}

View File

@ -112,6 +112,8 @@ public:
bool isRunning() const { return m_running; }
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
void setMessageQueueToGUI(MessageQueue *messageQueue) { m_msgQueueToGUI = messageQueue; }
uint64_t getTrackerDeviceFrequency() const { return m_trackerDeviceFrequency; }
int getTrackerChannelOffset() const { return m_trackerChannelOffset; }
private:
struct ChannelTracking
@ -166,6 +168,7 @@ private:
bool updateDeviceFrequency(DeviceSet *deviceSet, const QString& key, int64_t frequency);
int getDeviceDirection(DeviceAPI *deviceAPI);
void getDeviceSettingsKey(DeviceAPI *deviceAPI, QString& settingsKey);
void reportUpdateTarget(int correction, bool done);
private slots:
void updateTarget();