2020-10-16 13:20:55 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
|
|
|
|
|
|
|
#include "SWGFeatureSettings.h"
|
|
|
|
#include "SWGFeatureReport.h"
|
|
|
|
#include "SWGFeatureActions.h"
|
|
|
|
#include "SWGAFCReport.h"
|
|
|
|
#include "SWGDeviceState.h"
|
2020-10-22 02:38:43 -04:00
|
|
|
#include "SWGChannelSettings.h"
|
2020-10-16 13:20:55 -04:00
|
|
|
|
|
|
|
#include "dsp/dspengine.h"
|
2020-10-22 02:38:43 -04:00
|
|
|
#include "device/deviceset.h"
|
|
|
|
#include "channel/channelapi.h"
|
|
|
|
#include "maincore.h"
|
2020-10-16 13:20:55 -04:00
|
|
|
|
|
|
|
#include "afcworker.h"
|
|
|
|
#include "afc.h"
|
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(AFC::MsgConfigureAFC, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(AFC::MsgStartStop, Message)
|
2020-10-24 04:35:07 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(AFC::MsgDeviceTrack, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(AFC::MsgDevicesApply, Message)
|
2020-10-16 13:20:55 -04:00
|
|
|
|
2020-11-21 14:24:18 -05:00
|
|
|
const char* const AFC::m_featureIdURI = "sdrangel.feature.afc";
|
|
|
|
const char* const AFC::m_featureId = "AFC";
|
2020-10-16 13:20:55 -04:00
|
|
|
|
|
|
|
AFC::AFC(WebAPIAdapterInterface *webAPIAdapterInterface) :
|
|
|
|
Feature(m_featureIdURI, webAPIAdapterInterface),
|
2020-10-22 02:38:43 -04:00
|
|
|
m_trackerDeviceSet(nullptr),
|
2020-10-26 08:48:19 -04:00
|
|
|
m_trackedDeviceSet(nullptr),
|
2020-10-26 16:39:34 -04:00
|
|
|
m_trackerIndexInDeviceSet(-1),
|
|
|
|
m_trackerChannelAPI(nullptr)
|
2020-10-16 13:20:55 -04:00
|
|
|
{
|
|
|
|
setObjectName(m_featureId);
|
|
|
|
m_worker = new AFCWorker(webAPIAdapterInterface);
|
|
|
|
m_state = StIdle;
|
|
|
|
m_errorMessage = "AFC error";
|
2021-01-15 06:24:21 -05:00
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
AFC::~AFC()
|
|
|
|
{
|
2021-01-15 06:24:21 -05:00
|
|
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
delete m_networkManager;
|
2020-10-16 13:20:55 -04:00
|
|
|
if (m_worker->isRunning()) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete m_worker;
|
2020-10-26 16:39:34 -04:00
|
|
|
removeTrackerFeatureReference();
|
2020-10-26 08:48:19 -04:00
|
|
|
removeTrackedFeatureReferences();
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AFC::start()
|
|
|
|
{
|
|
|
|
qDebug("AFC::start");
|
|
|
|
|
|
|
|
m_worker->reset();
|
|
|
|
m_worker->setMessageQueueToGUI(getMessageQueueToGUI());
|
|
|
|
bool ok = m_worker->startWork();
|
|
|
|
m_state = ok ? StRunning : StError;
|
|
|
|
m_thread.start();
|
|
|
|
|
|
|
|
AFCWorker::MsgConfigureAFCWorker *msg = AFCWorker::MsgConfigureAFCWorker::create(m_settings, true);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AFC::stop()
|
|
|
|
{
|
|
|
|
qDebug("AFC::stop");
|
|
|
|
m_worker->stopWork();
|
|
|
|
m_state = StIdle;
|
|
|
|
m_thread.quit();
|
|
|
|
m_thread.wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AFC::handleMessage(const Message& cmd)
|
|
|
|
{
|
|
|
|
if (MsgConfigureAFC::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureAFC& cfg = (MsgConfigureAFC&) cmd;
|
|
|
|
qDebug() << "AFC::handleMessage: MsgConfigureAFC";
|
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgStartStop::match(cmd))
|
|
|
|
{
|
|
|
|
MsgStartStop& cfg = (MsgStartStop&) cmd;
|
|
|
|
qDebug() << "AFC::handleMessage: MsgStartStop: start:" << cfg.getStartStop();
|
|
|
|
|
|
|
|
if (cfg.getStartStop()) {
|
|
|
|
start();
|
|
|
|
} else {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-12-13 07:04:36 -05:00
|
|
|
else if (MainCore::MsgChannelSettings::match(cmd))
|
2020-10-22 02:38:43 -04:00
|
|
|
{
|
2020-12-13 07:04:36 -05:00
|
|
|
MainCore::MsgChannelSettings& cfg = (MainCore::MsgChannelSettings&) cmd;
|
2020-10-22 02:38:43 -04:00
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings = cfg.getSWGSettings();
|
|
|
|
QString *channelType = swgChannelSettings->getChannelType();
|
2020-12-13 07:04:36 -05:00
|
|
|
qDebug() << "AFC::handleMessage: MainCore::MsgChannelSettings: " << *channelType;
|
2020-10-22 02:38:43 -04:00
|
|
|
|
|
|
|
if (m_worker->isRunning())
|
|
|
|
{
|
|
|
|
m_worker->getInputMessageQueue()->push(&cfg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete swgChannelSettings;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-12-13 07:04:36 -05:00
|
|
|
else if (MessagePipesCommon::MsgReportChannelDeleted::match(cmd))
|
|
|
|
{
|
|
|
|
qDebug() << "AFC::handleMessage: MessagePipesCommon::MsgReportChannelDeleted";
|
|
|
|
MessagePipesCommon::MsgReportChannelDeleted& report = (MessagePipesCommon::MsgReportChannelDeleted&) cmd;
|
|
|
|
const MessagePipesCommon::ChannelRegistrationKey& channelKey = report.getChannelRegistrationKey();
|
2021-01-13 15:53:10 -05:00
|
|
|
MainCore::instance()->getMessagePipes().unregisterChannelToFeature(channelKey.m_key, this, "settings");
|
2020-12-13 07:04:36 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-10-24 04:35:07 -04:00
|
|
|
else if (MsgDeviceTrack::match(cmd))
|
|
|
|
{
|
|
|
|
if (m_worker->isRunning())
|
|
|
|
{
|
|
|
|
AFCWorker::MsgDeviceTrack *msg = AFCWorker::MsgDeviceTrack::create();
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgDevicesApply::match(cmd))
|
|
|
|
{
|
2020-10-26 16:39:34 -04:00
|
|
|
removeTrackerFeatureReference();
|
|
|
|
trackerDeviceChange(m_settings.m_trackerDeviceSetIndex);
|
|
|
|
removeTrackedFeatureReferences();
|
|
|
|
trackedDeviceChange(m_settings.m_trackedDeviceSetIndex);
|
|
|
|
|
2020-10-24 04:35:07 -04:00
|
|
|
if (m_worker->isRunning())
|
|
|
|
{
|
|
|
|
AFCWorker::MsgDevicesApply *msg = AFCWorker::MsgDevicesApply::create();
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-10-22 02:38:43 -04:00
|
|
|
|
|
|
|
return false;
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray AFC::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AFC::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
MsgConfigureAFC *msg = MsgConfigureAFC::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
MsgConfigureAFC *msg = MsgConfigureAFC::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AFC::applySettings(const AFCSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
qDebug() << "AFC::applySettings:"
|
|
|
|
<< " m_title: " << settings.m_title
|
|
|
|
<< " m_rgbColor: " << settings.m_rgbColor
|
2020-10-17 17:43:20 -04:00
|
|
|
<< " m_trackerDeviceSetIndex: " << settings.m_trackerDeviceSetIndex
|
|
|
|
<< " m_trackedDeviceSetIndex: " << settings.m_trackedDeviceSetIndex
|
|
|
|
<< " m_hasTargetFrequency: " << settings.m_hasTargetFrequency
|
|
|
|
<< " m_transverterTarget: " << settings.m_transverterTarget
|
|
|
|
<< " m_targetFrequency: " << settings.m_targetFrequency
|
|
|
|
<< " m_freqTolerance: " << settings.m_freqTolerance
|
2020-10-25 06:34:47 -04:00
|
|
|
<< " m_trackerAdjustPeriod:" << settings.m_trackerAdjustPeriod
|
2020-10-16 13:20:55 -04:00
|
|
|
<< " force: " << force;
|
|
|
|
|
|
|
|
QList<QString> reverseAPIKeys;
|
|
|
|
|
|
|
|
if ((m_settings.m_title != settings.m_title) || force) {
|
|
|
|
reverseAPIKeys.append("title");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_rgbColor != settings.m_rgbColor) || force) {
|
|
|
|
reverseAPIKeys.append("rgbColor");
|
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if ((m_settings.m_trackerDeviceSetIndex != settings.m_trackerDeviceSetIndex) || force) {
|
|
|
|
reverseAPIKeys.append("trackerDeviceSetIndex");
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if ((m_settings.m_trackedDeviceSetIndex != settings.m_trackedDeviceSetIndex) || force) {
|
|
|
|
reverseAPIKeys.append("trackedDeviceSetIndex");
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if ((m_settings.m_hasTargetFrequency != settings.m_hasTargetFrequency) || force) {
|
|
|
|
reverseAPIKeys.append("hasTargetFrequency");
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if ((m_settings.m_transverterTarget != settings.m_transverterTarget) || force) {
|
|
|
|
reverseAPIKeys.append("transverterTarget");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_targetFrequency != settings.m_targetFrequency) || force) {
|
|
|
|
reverseAPIKeys.append("targetFrequency");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_freqTolerance != settings.m_freqTolerance) || force) {
|
|
|
|
reverseAPIKeys.append("freqTolerance");
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-25 06:34:47 -04:00
|
|
|
if ((m_settings.m_trackerAdjustPeriod != settings.m_trackerAdjustPeriod) || force) {
|
|
|
|
reverseAPIKeys.append("trackerAdjustPeriod");
|
|
|
|
}
|
2020-10-16 13:20:55 -04:00
|
|
|
|
2020-10-26 08:48:19 -04:00
|
|
|
if ((m_settings.m_trackerDeviceSetIndex != settings.m_trackerDeviceSetIndex) || force)
|
|
|
|
{
|
2020-10-26 16:39:34 -04:00
|
|
|
removeTrackerFeatureReference();
|
2020-10-22 02:38:43 -04:00
|
|
|
trackerDeviceChange(settings.m_trackerDeviceSetIndex);
|
|
|
|
}
|
|
|
|
|
2020-10-26 08:48:19 -04:00
|
|
|
if ((m_settings.m_trackedDeviceSetIndex != settings.m_trackedDeviceSetIndex) || force)
|
|
|
|
{
|
2020-10-26 16:39:34 -04:00
|
|
|
removeTrackedFeatureReferences();
|
2020-10-22 02:38:43 -04:00
|
|
|
trackedDeviceChange(settings.m_trackedDeviceSetIndex);
|
|
|
|
}
|
|
|
|
|
2020-10-16 13:20:55 -04:00
|
|
|
AFCWorker::MsgConfigureAFCWorker *msg = AFCWorker::MsgConfigureAFCWorker::create(
|
|
|
|
settings, force
|
|
|
|
);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
|
|
|
|
if (settings.m_useReverseAPI)
|
|
|
|
{
|
|
|
|
bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
|
|
|
|
(m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
|
|
|
|
(m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
|
|
|
|
(m_settings.m_reverseAPIFeatureSetIndex != settings.m_reverseAPIFeatureSetIndex) ||
|
|
|
|
(m_settings.m_reverseAPIFeatureIndex != settings.m_reverseAPIFeatureIndex);
|
|
|
|
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_settings = settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AFC::webapiRun(bool run,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
2020-11-14 05:13:32 -05:00
|
|
|
(void) errorMessage;
|
2020-10-16 13:20:55 -04:00
|
|
|
getFeatureStateStr(*response.getState());
|
|
|
|
MsgStartStop *msg = MsgStartStop::create(run);
|
|
|
|
getInputMessageQueue()->push(msg);
|
|
|
|
return 202;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AFC::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
response.setAfcSettings(new SWGSDRangel::SWGAFCSettings());
|
|
|
|
response.getAfcSettings()->init();
|
|
|
|
webapiFormatFeatureSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AFC::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& featureSettingsKeys,
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
AFCSettings settings = m_settings;
|
|
|
|
webapiUpdateFeatureSettings(settings, featureSettingsKeys, response);
|
|
|
|
|
|
|
|
MsgConfigureAFC *msg = MsgConfigureAFC::create(settings, force);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
qDebug("AFC::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureAFC *msgToGUI = MsgConfigureAFC::create(settings, force);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatFeatureSettings(response, settings);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AFC::webapiReportGet(
|
|
|
|
SWGSDRangel::SWGFeatureReport& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
response.setAfcReport(new SWGSDRangel::SWGAFCReport());
|
|
|
|
response.getAfcReport()->init();
|
|
|
|
webapiFormatFeatureReport(response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AFC::webapiActionsPost(
|
|
|
|
const QStringList& featureActionsKeys,
|
|
|
|
SWGSDRangel::SWGFeatureActions& query,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGAFCActions *swgAFCActions = query.getAfcActions();
|
|
|
|
|
|
|
|
if (swgAFCActions)
|
|
|
|
{
|
2021-10-21 20:01:33 -04:00
|
|
|
bool unknownAction = true;
|
|
|
|
|
|
|
|
if (featureActionsKeys.contains("run"))
|
|
|
|
{
|
|
|
|
bool featureRun = swgAFCActions->getRun() != 0;
|
|
|
|
unknownAction = false;
|
|
|
|
MsgStartStop *msg = MsgStartStop::create(featureRun);
|
|
|
|
getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
|
2020-10-26 08:48:19 -04:00
|
|
|
if (featureActionsKeys.contains("deviceTrack"))
|
|
|
|
{
|
|
|
|
bool deviceTrack = swgAFCActions->getDeviceTrack() != 0;
|
2021-10-21 20:01:33 -04:00
|
|
|
unknownAction = false;
|
2020-10-26 08:48:19 -04:00
|
|
|
|
|
|
|
if (deviceTrack)
|
|
|
|
{
|
|
|
|
MsgDeviceTrack *msg = MsgDeviceTrack::create();
|
|
|
|
getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (featureActionsKeys.contains("devicesApply"))
|
|
|
|
{
|
|
|
|
bool devicesApply = swgAFCActions->getDevicesApply() != 0;
|
2021-10-21 20:01:33 -04:00
|
|
|
unknownAction = false;
|
2020-10-26 08:48:19 -04:00
|
|
|
|
|
|
|
if (devicesApply)
|
|
|
|
{
|
|
|
|
MsgDevicesApply *msg = MsgDevicesApply::create();
|
|
|
|
getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:01:33 -04:00
|
|
|
if (unknownAction)
|
|
|
|
{
|
|
|
|
errorMessage = "Unknown action";
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 202;
|
|
|
|
}
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
errorMessage = "Missing AFCActions in query";
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AFC::webapiFormatFeatureSettings(
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response,
|
|
|
|
const AFCSettings& settings)
|
|
|
|
{
|
|
|
|
if (response.getAfcSettings()->getTitle()) {
|
|
|
|
*response.getAfcSettings()->getTitle() = settings.m_title;
|
|
|
|
} else {
|
|
|
|
response.getAfcSettings()->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getAfcSettings()->setRgbColor(settings.m_rgbColor);
|
2020-10-17 17:43:20 -04:00
|
|
|
response.getAfcSettings()->setTrackerDeviceSetIndex(settings.m_trackerDeviceSetIndex);
|
|
|
|
response.getAfcSettings()->setTrackedDeviceSetIndex(settings.m_trackedDeviceSetIndex);
|
|
|
|
response.getAfcSettings()->setHasTargetFrequency(settings.m_hasTargetFrequency);
|
|
|
|
response.getAfcSettings()->setTransverterTarget(settings.m_transverterTarget);
|
|
|
|
response.getAfcSettings()->setTargetFrequency(settings.m_targetFrequency);
|
|
|
|
response.getAfcSettings()->setFreqTolerance(settings.m_freqTolerance);
|
2020-10-25 06:34:47 -04:00
|
|
|
response.getAfcSettings()->setTrackerAdjustPeriod(settings.m_trackerAdjustPeriod);
|
2020-10-16 13:20:55 -04:00
|
|
|
|
|
|
|
response.getAfcSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getAfcSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getAfcSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
|
|
|
} else {
|
|
|
|
response.getAfcSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getAfcSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
2021-09-16 18:52:08 -04:00
|
|
|
response.getAfcSettings()->setReverseApiFeatureSetIndex(settings.m_reverseAPIFeatureSetIndex);
|
|
|
|
response.getAfcSettings()->setReverseApiFeatureIndex(settings.m_reverseAPIFeatureIndex);
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AFC::webapiUpdateFeatureSettings(
|
|
|
|
AFCSettings& settings,
|
|
|
|
const QStringList& featureSettingsKeys,
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response)
|
|
|
|
{
|
|
|
|
if (featureSettingsKeys.contains("title")) {
|
|
|
|
settings.m_title = *response.getAfcSettings()->getTitle();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("rgbColor")) {
|
|
|
|
settings.m_rgbColor = response.getAfcSettings()->getRgbColor();
|
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if (featureSettingsKeys.contains("trackerDeviceSetIndex")) {
|
|
|
|
settings.m_trackerDeviceSetIndex = response.getAfcSettings()->getTrackerDeviceSetIndex();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("trackedDeviceSetIndex")) {
|
|
|
|
settings.m_trackedDeviceSetIndex = response.getAfcSettings()->getTrackedDeviceSetIndex();
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if (featureSettingsKeys.contains("hasTargetFrequency")) {
|
|
|
|
settings.m_hasTargetFrequency = response.getAfcSettings()->getHasTargetFrequency() != 0;
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if (featureSettingsKeys.contains("hasTargetFrequency")) {
|
|
|
|
settings.m_hasTargetFrequency = response.getAfcSettings()->getHasTargetFrequency() != 0;
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if (featureSettingsKeys.contains("targetFrequency")) {
|
|
|
|
settings.m_targetFrequency = response.getAfcSettings()->getTargetFrequency();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("freqTolerance")) {
|
|
|
|
settings.m_freqTolerance = response.getAfcSettings()->getFreqTolerance();
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-25 06:34:47 -04:00
|
|
|
if (featureSettingsKeys.contains("trackerAdjustPeriod")) {
|
|
|
|
settings.m_trackerAdjustPeriod = response.getAfcSettings()->getTrackerAdjustPeriod();
|
|
|
|
}
|
2020-10-16 13:20:55 -04:00
|
|
|
if (featureSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getAfcSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("reverseAPIAddress")) {
|
|
|
|
settings.m_reverseAPIAddress = *response.getAfcSettings()->getReverseApiAddress();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getAfcSettings()->getReverseApiPort();
|
|
|
|
}
|
2021-09-16 18:52:08 -04:00
|
|
|
if (featureSettingsKeys.contains("reverseAPIFeatureSetIndex")) {
|
|
|
|
settings.m_reverseAPIFeatureSetIndex = response.getAfcSettings()->getReverseApiFeatureSetIndex();
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2021-09-16 18:52:08 -04:00
|
|
|
if (featureSettingsKeys.contains("reverseAPIFeatureIndex")) {
|
|
|
|
settings.m_reverseAPIFeatureIndex = response.getAfcSettings()->getReverseApiFeatureIndex();
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AFC::webapiFormatFeatureReport(SWGSDRangel::SWGFeatureReport& response)
|
|
|
|
{
|
2020-10-26 08:48:19 -04:00
|
|
|
response.getAfcReport()->setTrackerChannelIndex(m_trackerIndexInDeviceSet);
|
|
|
|
response.getAfcReport()->setTrackerDeviceFrequency(m_worker->getTrackerDeviceFrequency());
|
|
|
|
response.getAfcReport()->setTrackerChannelOffset(m_worker->getTrackerChannelOffset());
|
2021-10-23 15:24:25 -04:00
|
|
|
response.getAfcReport()->setRunningState(getState());
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AFC::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const AFCSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGFeatureSettings *swgFeatureSettings = new SWGSDRangel::SWGFeatureSettings();
|
|
|
|
// swgFeatureSettings->setOriginatorFeatureIndex(getIndexInDeviceSet());
|
|
|
|
// swgFeatureSettings->setOriginatorFeatureSetIndex(getDeviceSetIndex());
|
|
|
|
swgFeatureSettings->setFeatureType(new QString("AFC"));
|
|
|
|
swgFeatureSettings->setAfcSettings(new SWGSDRangel::SWGAFCSettings());
|
|
|
|
SWGSDRangel::SWGAFCSettings *swgAFCSettings = swgFeatureSettings->getAfcSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("title") || force) {
|
|
|
|
swgAFCSettings->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor") || force) {
|
|
|
|
swgAFCSettings->setRgbColor(settings.m_rgbColor);
|
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if (channelSettingsKeys.contains("trackerDeviceSetIndex") || force) {
|
|
|
|
swgAFCSettings->setTrackerDeviceSetIndex(settings.m_trackerDeviceSetIndex);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("trackedDeviceSetIndex") || force) {
|
|
|
|
swgAFCSettings->setTrackedDeviceSetIndex(settings.m_trackedDeviceSetIndex);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("hasTargetFrequency") || force) {
|
|
|
|
swgAFCSettings->setHasTargetFrequency(settings.m_hasTargetFrequency ? 1 : 0);
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if (channelSettingsKeys.contains("targetFrequency") || force) {
|
|
|
|
swgAFCSettings->setTargetFrequency(settings.m_targetFrequency ? 1 : 0);
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if (channelSettingsKeys.contains("targetFrequency") || force) {
|
|
|
|
swgAFCSettings->setTargetFrequency(settings.m_targetFrequency);
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-17 17:43:20 -04:00
|
|
|
if (channelSettingsKeys.contains("freqTolerance") || force) {
|
|
|
|
swgAFCSettings->setFreqTolerance(settings.m_freqTolerance);
|
2020-10-16 13:20:55 -04:00
|
|
|
}
|
2020-10-25 06:34:47 -04:00
|
|
|
if (channelSettingsKeys.contains("trackerAdjustPeriod") || force) {
|
|
|
|
swgAFCSettings->setTrackerAdjustPeriod(settings.m_trackerAdjustPeriod);
|
|
|
|
}
|
2020-10-16 13:20:55 -04:00
|
|
|
|
|
|
|
QString channelSettingsURL = QString("http://%1:%2/sdrangel/featureset/%3/feature/%4/settings")
|
|
|
|
.arg(settings.m_reverseAPIAddress)
|
|
|
|
.arg(settings.m_reverseAPIPort)
|
|
|
|
.arg(settings.m_reverseAPIFeatureSetIndex)
|
|
|
|
.arg(settings.m_reverseAPIFeatureIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
|
|
|
QBuffer *buffer = new QBuffer();
|
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgFeatureSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
|
|
|
|
|
|
|
// Always use PATCH to avoid passing reverse API settings
|
|
|
|
QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
buffer->setParent(reply);
|
|
|
|
|
|
|
|
delete swgFeatureSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AFC::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
|
|
|
qWarning() << "AFC::networkManagerFinished:"
|
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("AFC::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
reply->deleteLater();
|
|
|
|
}
|
2020-10-22 02:38:43 -04:00
|
|
|
|
|
|
|
void AFC::trackerDeviceChange(int deviceIndex)
|
|
|
|
{
|
|
|
|
MainCore *mainCore = MainCore::instance();
|
|
|
|
m_trackerDeviceSet = mainCore->getDeviceSets()[deviceIndex];
|
|
|
|
|
|
|
|
for (int i = 0; i < m_trackerDeviceSet->getNumberOfChannels(); i++)
|
|
|
|
{
|
|
|
|
ChannelAPI *channel = m_trackerDeviceSet->getChannelAt(i);
|
|
|
|
|
|
|
|
if (channel->getURI() == "sdrangel.channel.freqtracker")
|
|
|
|
{
|
2020-12-13 07:04:36 -05:00
|
|
|
MessageQueue *messageQueue = mainCore->getMessagePipes().registerChannelToFeature(channel, this, "settings");
|
|
|
|
QObject::connect(
|
|
|
|
messageQueue,
|
|
|
|
&MessageQueue::messageEnqueued,
|
|
|
|
this,
|
|
|
|
[=](){ this->handleChannelMessageQueue(messageQueue); },
|
|
|
|
Qt::QueuedConnection
|
|
|
|
);
|
2020-10-26 16:39:34 -04:00
|
|
|
m_trackerChannelAPI = channel;
|
2020-10-22 02:38:43 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AFC::trackedDeviceChange(int deviceIndex)
|
|
|
|
{
|
|
|
|
MainCore *mainCore = MainCore::instance();
|
|
|
|
m_trackedDeviceSet = mainCore->getDeviceSets()[deviceIndex];
|
|
|
|
|
|
|
|
for (int i = 0; i < m_trackedDeviceSet->getNumberOfChannels(); i++)
|
|
|
|
{
|
|
|
|
ChannelAPI *channel = m_trackedDeviceSet->getChannelAt(i);
|
|
|
|
|
2020-10-26 08:48:19 -04:00
|
|
|
if (channel->getURI() != "sdrangel.channel.freqtracker")
|
|
|
|
{
|
2020-12-13 07:04:36 -05:00
|
|
|
MessageQueue *messageQueue = mainCore->getMessagePipes().registerChannelToFeature(channel, this, "settings");
|
|
|
|
QObject::connect(
|
|
|
|
messageQueue,
|
|
|
|
&MessageQueue::messageEnqueued,
|
|
|
|
this,
|
|
|
|
[=](){ this->handleChannelMessageQueue(messageQueue); },
|
|
|
|
Qt::QueuedConnection
|
|
|
|
);
|
2020-10-26 08:48:19 -04:00
|
|
|
m_trackerIndexInDeviceSet = i;
|
2020-10-22 02:38:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 16:39:34 -04:00
|
|
|
void AFC::removeTrackerFeatureReference()
|
2020-10-22 02:38:43 -04:00
|
|
|
{
|
2020-10-26 16:39:34 -04:00
|
|
|
if (m_trackerChannelAPI)
|
2020-10-22 02:38:43 -04:00
|
|
|
{
|
2020-12-19 19:53:03 -05:00
|
|
|
if (MainCore::instance()->existsChannel(m_trackerChannelAPI))
|
|
|
|
{
|
|
|
|
MessageQueue *messageQueue
|
|
|
|
= MainCore::instance()->getMessagePipes().unregisterChannelToFeature(m_trackerChannelAPI, this, "settings");
|
|
|
|
disconnect(messageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleChannelMessageQueue(MessageQueue*)));
|
2020-10-22 02:38:43 -04:00
|
|
|
}
|
|
|
|
}
|
2020-10-26 08:48:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AFC::removeTrackedFeatureReferences()
|
|
|
|
{
|
2020-10-26 16:39:34 -04:00
|
|
|
for (QList<ChannelAPI*>::iterator it = m_trackedChannelAPIs.begin(); it != m_trackedChannelAPIs.end(); ++it)
|
2020-10-22 02:38:43 -04:00
|
|
|
{
|
2020-10-26 16:39:34 -04:00
|
|
|
ChannelAPI *channel = *it;
|
2020-10-22 02:38:43 -04:00
|
|
|
|
2020-10-26 16:39:34 -04:00
|
|
|
if (MainCore::instance()->existsChannel(channel)) {
|
2020-12-13 07:04:36 -05:00
|
|
|
MainCore::instance()->getMessagePipes().unregisterChannelToFeature(channel, this, "settings");
|
2020-10-22 02:38:43 -04:00
|
|
|
}
|
|
|
|
}
|
2020-10-26 16:39:34 -04:00
|
|
|
|
|
|
|
m_trackedChannelAPIs.clear();
|
2020-10-22 02:38:43 -04:00
|
|
|
}
|
2020-12-13 07:04:36 -05:00
|
|
|
|
|
|
|
void AFC::handleChannelMessageQueue(MessageQueue* messageQueue)
|
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = messageQueue->pop()) != nullptr)
|
|
|
|
{
|
|
|
|
if (handleMessage(*message)) {
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|