2020-10-27 12:22:10 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2020 Jon Beniston, M7RCE //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-10-12 07:10:12 -04:00
|
|
|
#include <cmath>
|
|
|
|
|
2020-10-27 12:22:10 -04:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2021-10-03 20:11:27 -04:00
|
|
|
#include <QSerialPortInfo>
|
2020-10-27 12:22:10 -04:00
|
|
|
|
|
|
|
#include "SWGFeatureSettings.h"
|
|
|
|
#include "SWGFeatureReport.h"
|
|
|
|
#include "SWGFeatureActions.h"
|
|
|
|
#include "SWGDeviceState.h"
|
2021-01-13 14:44:53 -05:00
|
|
|
#include "SWGTargetAzimuthElevation.h"
|
2020-10-27 12:22:10 -04:00
|
|
|
|
|
|
|
#include "dsp/dspengine.h"
|
2021-01-13 14:44:53 -05:00
|
|
|
#include "device/deviceset.h"
|
|
|
|
#include "feature/featureset.h"
|
2022-01-08 23:27:12 -05:00
|
|
|
#include "settings/serializable.h"
|
2021-01-13 14:44:53 -05:00
|
|
|
#include "maincore.h"
|
2020-10-27 12:22:10 -04:00
|
|
|
|
|
|
|
#include "gs232controller.h"
|
2021-01-13 14:44:53 -05:00
|
|
|
#include "gs232controllerworker.h"
|
|
|
|
#include "gs232controllerreport.h"
|
2020-10-27 12:22:10 -04:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(GS232Controller::MsgConfigureGS232Controller, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(GS232Controller::MsgStartStop, Message)
|
2021-01-13 14:44:53 -05:00
|
|
|
MESSAGE_CLASS_DEFINITION(GS232Controller::MsgReportWorker, Message)
|
2022-03-28 14:12:25 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(GS232Controller::MsgReportAvailableChannelOrFeatures, Message)
|
2022-10-27 14:15:46 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(GS232Controller::MsgScanAvailableChannelOrFeatures, Message)
|
2020-10-27 12:22:10 -04:00
|
|
|
|
2020-11-21 14:24:18 -05:00
|
|
|
const char* const GS232Controller::m_featureIdURI = "sdrangel.feature.gs232controller";
|
|
|
|
const char* const GS232Controller::m_featureId = "GS232Controller";
|
2020-10-27 12:22:10 -04:00
|
|
|
|
|
|
|
GS232Controller::GS232Controller(WebAPIAdapterInterface *webAPIAdapterInterface) :
|
2022-09-18 11:47:06 -04:00
|
|
|
Feature(m_featureIdURI, webAPIAdapterInterface),
|
|
|
|
m_thread(nullptr),
|
|
|
|
m_worker(nullptr)
|
2020-10-27 12:22:10 -04:00
|
|
|
{
|
|
|
|
qDebug("GS232Controller::GS232Controller: webAPIAdapterInterface: %p", webAPIAdapterInterface);
|
|
|
|
setObjectName(m_featureId);
|
|
|
|
m_state = StIdle;
|
|
|
|
m_errorMessage = "GS232Controller error";
|
2021-01-13 14:44:53 -05:00
|
|
|
m_selectedPipe = nullptr;
|
2021-01-15 06:24:21 -05:00
|
|
|
m_networkManager = new QNetworkAccessManager();
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::connect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&GS232Controller::networkManagerFinished
|
|
|
|
);
|
2022-03-28 14:12:25 -04:00
|
|
|
QObject::connect(
|
|
|
|
MainCore::instance(),
|
|
|
|
&MainCore::featureAdded,
|
|
|
|
this,
|
|
|
|
&GS232Controller::handleFeatureAdded
|
|
|
|
);
|
|
|
|
QObject::connect(
|
|
|
|
MainCore::instance(),
|
|
|
|
&MainCore::channelAdded,
|
|
|
|
this,
|
|
|
|
&GS232Controller::handleChannelAdded
|
|
|
|
);
|
|
|
|
QObject::connect(
|
|
|
|
MainCore::instance(),
|
|
|
|
&MainCore::featureRemoved,
|
|
|
|
this,
|
|
|
|
&GS232Controller::handleFeatureRemoved
|
|
|
|
);
|
|
|
|
QObject::connect(
|
|
|
|
MainCore::instance(),
|
|
|
|
&MainCore::channelRemoved,
|
|
|
|
this,
|
|
|
|
&GS232Controller::handleChannelRemoved
|
|
|
|
);
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
GS232Controller::~GS232Controller()
|
|
|
|
{
|
2022-03-28 14:12:25 -04:00
|
|
|
QObject::disconnect(
|
|
|
|
MainCore::instance(),
|
|
|
|
&MainCore::channelRemoved,
|
|
|
|
this,
|
|
|
|
&GS232Controller::handleChannelRemoved
|
|
|
|
);
|
|
|
|
QObject::disconnect(
|
|
|
|
MainCore::instance(),
|
|
|
|
&MainCore::featureRemoved,
|
|
|
|
this,
|
|
|
|
&GS232Controller::handleFeatureRemoved
|
|
|
|
);
|
|
|
|
QObject::disconnect(
|
|
|
|
MainCore::instance(),
|
|
|
|
&MainCore::channelAdded,
|
|
|
|
this,
|
|
|
|
&GS232Controller::handleChannelAdded
|
|
|
|
);
|
|
|
|
QObject::disconnect(
|
|
|
|
MainCore::instance(),
|
|
|
|
&MainCore::featureAdded,
|
|
|
|
this,
|
|
|
|
&GS232Controller::handleFeatureAdded
|
|
|
|
);
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::disconnect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&GS232Controller::networkManagerFinished
|
|
|
|
);
|
2021-01-15 06:24:21 -05:00
|
|
|
delete m_networkManager;
|
2022-09-18 11:47:06 -04:00
|
|
|
stop();
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GS232Controller::start()
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::start");
|
|
|
|
|
2022-09-20 16:13:12 -04:00
|
|
|
m_thread = new QThread();
|
2022-09-18 11:47:06 -04:00
|
|
|
m_worker = new GS232ControllerWorker();
|
|
|
|
m_worker->moveToThread(m_thread);
|
|
|
|
QObject::connect(m_thread, &QThread::started, m_worker, &GS232ControllerWorker::startWork);
|
|
|
|
QObject::connect(m_thread, &QThread::finished, m_worker, &QObject::deleteLater);
|
|
|
|
QObject::connect(m_thread, &QThread::finished, m_thread, &QThread::deleteLater);
|
2020-10-27 12:22:10 -04:00
|
|
|
m_worker->setMessageQueueToFeature(getInputMessageQueue());
|
2022-09-18 11:47:06 -04:00
|
|
|
m_thread->start();
|
|
|
|
m_state = StRunning;
|
2020-10-27 12:22:10 -04:00
|
|
|
|
2022-11-24 10:40:36 -05:00
|
|
|
GS232ControllerWorker::MsgConfigureGS232ControllerWorker *msg =
|
|
|
|
GS232ControllerWorker::MsgConfigureGS232ControllerWorker::create(m_settings, QList<QString>(), true);
|
2020-10-27 12:22:10 -04:00
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
2022-03-28 14:12:25 -04:00
|
|
|
|
|
|
|
scanAvailableChannelsAndFeatures();
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GS232Controller::stop()
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::stop");
|
|
|
|
m_state = StIdle;
|
2022-09-18 11:47:06 -04:00
|
|
|
if (m_thread)
|
|
|
|
{
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
m_thread = nullptr;
|
|
|
|
m_worker = nullptr;
|
|
|
|
}
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GS232Controller::handleMessage(const Message& cmd)
|
|
|
|
{
|
|
|
|
if (MsgConfigureGS232Controller::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureGS232Controller& cfg = (MsgConfigureGS232Controller&) cmd;
|
|
|
|
qDebug() << "GS232Controller::handleMessage: MsgConfigureGS232Controller";
|
2022-11-24 10:40:36 -05:00
|
|
|
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce());
|
2020-10-27 12:22:10 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgStartStop::match(cmd))
|
|
|
|
{
|
|
|
|
MsgStartStop& cfg = (MsgStartStop&) cmd;
|
|
|
|
qDebug() << "GS232Controller::handleMessage: MsgStartStop: start:" << cfg.getStartStop();
|
|
|
|
|
|
|
|
if (cfg.getStartStop()) {
|
|
|
|
start();
|
|
|
|
} else {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-13 14:44:53 -05:00
|
|
|
else if (MsgReportWorker::match(cmd))
|
2020-10-27 12:22:10 -04:00
|
|
|
{
|
2021-01-13 14:44:53 -05:00
|
|
|
MsgReportWorker& report = (MsgReportWorker&) cmd;
|
|
|
|
if (report.getMessage() == "Connected")
|
|
|
|
m_state = StRunning;
|
|
|
|
else if (report.getMessage() == "Disconnected")
|
|
|
|
m_state = StIdle;
|
|
|
|
else
|
2020-10-27 12:22:10 -04:00
|
|
|
{
|
2021-01-13 14:44:53 -05:00
|
|
|
m_state = StError;
|
|
|
|
m_errorMessage = report.getMessage();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-27 14:15:46 -04:00
|
|
|
else if (MsgScanAvailableChannelOrFeatures::match(cmd))
|
|
|
|
{
|
|
|
|
scanAvailableChannelsAndFeatures();
|
|
|
|
return true;
|
|
|
|
}
|
2021-10-05 09:03:31 -04:00
|
|
|
else if (GS232ControllerReport::MsgReportAzAl::match(cmd))
|
|
|
|
{
|
|
|
|
GS232ControllerReport::MsgReportAzAl& report = (GS232ControllerReport::MsgReportAzAl&) cmd;
|
|
|
|
// Save state for Web report/getOnTarget
|
|
|
|
m_currentAzimuth = report.getAzimuth();
|
|
|
|
m_currentElevation = report.getElevation();
|
|
|
|
// Forward to GUI
|
|
|
|
if (getMessageQueueToGUI()) {
|
|
|
|
getMessageQueueToGUI()->push(new GS232ControllerReport::MsgReportAzAl(report));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-13 14:44:53 -05:00
|
|
|
else if (MainCore::MsgTargetAzimuthElevation::match(cmd))
|
|
|
|
{
|
2021-10-03 17:15:15 -04:00
|
|
|
// New source from another plugin
|
2021-01-13 14:44:53 -05:00
|
|
|
if ((m_state == StRunning) && m_settings.m_track)
|
|
|
|
{
|
|
|
|
MainCore::MsgTargetAzimuthElevation& msg = (MainCore::MsgTargetAzimuthElevation&) cmd;
|
|
|
|
// Is it from the selected pipe?
|
|
|
|
if (msg.getPipeSource() == m_selectedPipe)
|
|
|
|
{
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
// Forward to GUI - which will then send us updated settings
|
|
|
|
getMessageQueueToGUI()->push(new MainCore::MsgTargetAzimuthElevation(msg));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-03 17:15:15 -04:00
|
|
|
// No GUI, so save source - applySettings will propagate to worker
|
2021-01-13 14:44:53 -05:00
|
|
|
SWGSDRangel::SWGTargetAzimuthElevation *swgTarget = msg.getSWGTargetAzimuthElevation();
|
|
|
|
m_settings.m_azimuth = swgTarget->getAzimuth();
|
|
|
|
m_settings.m_elevation = swgTarget->getElevation();
|
2022-11-24 10:40:36 -05:00
|
|
|
applySettings(m_settings, QList<QString>{"azimuth", "elevation"});
|
2021-01-13 14:44:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
qDebug() << "GS232Controller::handleMessage: No match " << msg.getPipeSource() << " " << m_selectedPipe;
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-05 09:03:31 -04:00
|
|
|
// Calculate whether last received az/el was on target
|
|
|
|
bool GS232Controller::getOnTarget() const
|
|
|
|
{
|
|
|
|
float targetAziumth, targetElevation;
|
|
|
|
m_settings.calcTargetAzEl(targetAziumth, targetElevation);
|
2021-10-12 07:10:12 -04:00
|
|
|
float readTolerance = m_settings.m_tolerance + 0.0f;
|
|
|
|
bool onTarget = (std::fabs(m_currentAzimuth - targetAziumth) < readTolerance)
|
|
|
|
&& (std::fabs(m_currentElevation - targetElevation) < readTolerance);
|
2021-10-05 09:03:31 -04:00
|
|
|
return onTarget;
|
|
|
|
}
|
|
|
|
|
2020-10-27 12:22:10 -04:00
|
|
|
QByteArray GS232Controller::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GS232Controller::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
2022-11-24 10:40:36 -05:00
|
|
|
MsgConfigureGS232Controller *msg = MsgConfigureGS232Controller::create(m_settings, QList<QString>(), true);
|
2020-10-27 12:22:10 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
2022-11-24 10:40:36 -05:00
|
|
|
MsgConfigureGS232Controller *msg = MsgConfigureGS232Controller::create(m_settings, QList<QString>(), true);
|
2020-10-27 12:22:10 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-24 10:40:36 -05:00
|
|
|
void GS232Controller::applySettings(const GS232ControllerSettings& settings, const QList<QString>& settingsKeys, bool force)
|
2020-10-27 12:22:10 -04:00
|
|
|
{
|
2022-11-24 10:40:36 -05:00
|
|
|
qDebug() << "GS232Controller::applySettings:" << settings.getDebugString(settingsKeys, force) << " force: " << force;
|
|
|
|
|
|
|
|
// if ((m_settings.m_source != settings.m_source)
|
|
|
|
// || (!settings.m_source.isEmpty() && (m_selectedPipe == nullptr)) // Change in available pipes
|
|
|
|
// || force)
|
|
|
|
|
|
|
|
if (settingsKeys.contains("source")
|
2021-10-03 17:15:15 -04:00
|
|
|
|| (!settings.m_source.isEmpty() && (m_selectedPipe == nullptr)) // Change in available pipes
|
2021-01-13 14:44:53 -05:00
|
|
|
|| force)
|
|
|
|
{
|
2022-03-28 14:12:25 -04:00
|
|
|
MainCore *mainCore = MainCore::instance();
|
|
|
|
MessagePipes& messagePipes = mainCore->getMessagePipes();
|
|
|
|
|
|
|
|
if (m_selectedPipe)
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::applySettings: unregister %s (%p)", qPrintable(m_selectedPipe->objectName()), m_selectedPipe);
|
|
|
|
messagePipes.unregisterProducerToConsumer(m_selectedPipe, this, "target");
|
|
|
|
}
|
|
|
|
|
2021-10-03 17:15:15 -04:00
|
|
|
if (!settings.m_source.isEmpty())
|
2021-01-13 14:44:53 -05:00
|
|
|
{
|
2022-03-28 14:12:25 -04:00
|
|
|
QObject *object = nullptr;
|
|
|
|
|
|
|
|
for (const auto& oval : m_availableChannelOrFeatures)
|
|
|
|
{
|
|
|
|
QString itemText = tr("%1%2:%3 %4")
|
|
|
|
.arg(oval.m_kind)
|
|
|
|
.arg(oval.m_superIndex)
|
|
|
|
.arg(oval.m_index)
|
|
|
|
.arg(oval.m_type);
|
|
|
|
|
|
|
|
if (settings.m_source == itemText)
|
|
|
|
{
|
|
|
|
object = m_availableChannelOrFeatures.key(oval);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-10-03 17:15:15 -04:00
|
|
|
|
2022-03-28 14:12:25 -04:00
|
|
|
if (object)
|
|
|
|
{
|
|
|
|
registerPipe(object);
|
|
|
|
m_selectedPipe = object;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_selectedPipe = nullptr;
|
2021-10-03 17:15:15 -04:00
|
|
|
qDebug() << "GS232Controller::applySettings: No plugin corresponding to source " << settings.m_source;
|
|
|
|
}
|
2021-01-13 14:44:53 -05:00
|
|
|
}
|
2022-03-28 14:12:25 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_selectedPipe = nullptr;
|
|
|
|
}
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
GS232ControllerWorker::MsgConfigureGS232ControllerWorker *msg = GS232ControllerWorker::MsgConfigureGS232ControllerWorker::create(
|
2022-11-24 10:40:36 -05:00
|
|
|
settings, settingsKeys, force
|
2020-10-27 12:22:10 -04:00
|
|
|
);
|
2022-11-24 10:40:36 -05:00
|
|
|
|
2022-09-18 11:47:06 -04:00
|
|
|
if (m_worker) {
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
2020-10-27 12:22:10 -04:00
|
|
|
|
2022-11-24 10:40:36 -05:00
|
|
|
if (settingsKeys.contains("useReverseAPI"))
|
2020-10-27 12:22:10 -04:00
|
|
|
{
|
2022-11-24 10:40:36 -05:00
|
|
|
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
|
|
|
|
settingsKeys.contains("reverseAPIAddress") ||
|
|
|
|
settingsKeys.contains("reverseAPIPort") ||
|
|
|
|
settingsKeys.contains("reverseAPIFeatureSetIndex") ||
|
|
|
|
settingsKeys.contains("m_reverseAPIFeatureIndex");
|
|
|
|
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
|
|
|
|
2022-11-24 10:40:36 -05:00
|
|
|
if (force) {
|
|
|
|
m_settings = settings;
|
|
|
|
} else {
|
|
|
|
m_settings.applySettings(settingsKeys, settings);
|
|
|
|
}
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int GS232Controller::webapiRun(bool run,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
2020-11-14 05:13:32 -05:00
|
|
|
(void) errorMessage;
|
2020-10-27 12:22:10 -04:00
|
|
|
getFeatureStateStr(*response.getState());
|
|
|
|
MsgStartStop *msg = MsgStartStop::create(run);
|
|
|
|
getInputMessageQueue()->push(msg);
|
|
|
|
return 202;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GS232Controller::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
response.setGs232ControllerSettings(new SWGSDRangel::SWGGS232ControllerSettings());
|
|
|
|
response.getGs232ControllerSettings()->init();
|
|
|
|
webapiFormatFeatureSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GS232Controller::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& featureSettingsKeys,
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
GS232ControllerSettings settings = m_settings;
|
|
|
|
webapiUpdateFeatureSettings(settings, featureSettingsKeys, response);
|
|
|
|
|
2022-11-24 10:40:36 -05:00
|
|
|
MsgConfigureGS232Controller *msg = MsgConfigureGS232Controller::create(settings, featureSettingsKeys, force);
|
2020-10-27 12:22:10 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
2022-11-24 10:40:36 -05:00
|
|
|
MsgConfigureGS232Controller *msgToGUI = MsgConfigureGS232Controller::create(settings, featureSettingsKeys, force);
|
2020-10-27 12:22:10 -04:00
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatFeatureSettings(response, settings);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2021-10-03 17:15:15 -04:00
|
|
|
int GS232Controller::webapiReportGet(
|
|
|
|
SWGSDRangel::SWGFeatureReport& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
response.setGs232ControllerReport(new SWGSDRangel::SWGGS232ControllerReport());
|
|
|
|
response.getGs232ControllerReport()->init();
|
|
|
|
webapiFormatFeatureReport(response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:01:33 -04:00
|
|
|
int GS232Controller::webapiActionsPost(
|
|
|
|
const QStringList& featureActionsKeys,
|
|
|
|
SWGSDRangel::SWGFeatureActions& query,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGGS232ControllerActions *swgGS232ControllerActions = query.getGs232ControllerActions();
|
|
|
|
|
|
|
|
if (swgGS232ControllerActions)
|
|
|
|
{
|
|
|
|
if (featureActionsKeys.contains("run"))
|
|
|
|
{
|
|
|
|
bool featureRun = swgGS232ControllerActions->getRun() != 0;
|
|
|
|
MsgStartStop *msg = MsgStartStop::create(featureRun);
|
|
|
|
getInputMessageQueue()->push(msg);
|
|
|
|
return 202;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
errorMessage = "Unknown action";
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
errorMessage = "Missing GS232ControllerActions in query";
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-27 12:22:10 -04:00
|
|
|
void GS232Controller::webapiFormatFeatureSettings(
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response,
|
|
|
|
const GS232ControllerSettings& settings)
|
|
|
|
{
|
|
|
|
response.getGs232ControllerSettings()->setAzimuth(settings.m_azimuth);
|
|
|
|
response.getGs232ControllerSettings()->setElevation(settings.m_elevation);
|
|
|
|
response.getGs232ControllerSettings()->setSerialPort(new QString(settings.m_serialPort));
|
|
|
|
response.getGs232ControllerSettings()->setBaudRate(settings.m_baudRate);
|
2021-11-23 07:28:06 -05:00
|
|
|
response.getGs232ControllerSettings()->setHost(new QString(settings.m_host));
|
|
|
|
response.getGs232ControllerSettings()->setPort(settings.m_port);
|
2020-10-27 12:22:10 -04:00
|
|
|
response.getGs232ControllerSettings()->setTrack(settings.m_track);
|
2021-10-03 17:15:15 -04:00
|
|
|
response.getGs232ControllerSettings()->setSource(new QString(settings.m_source));
|
2021-01-13 14:44:53 -05:00
|
|
|
response.getGs232ControllerSettings()->setAzimuthOffset(settings.m_azimuthOffset);
|
|
|
|
response.getGs232ControllerSettings()->setElevationOffset(settings.m_elevationOffset);
|
2021-02-26 15:27:35 -05:00
|
|
|
response.getGs232ControllerSettings()->setAzimuthMin(settings.m_azimuthMin);
|
|
|
|
response.getGs232ControllerSettings()->setAzimuthMax(settings.m_azimuthMax);
|
|
|
|
response.getGs232ControllerSettings()->setElevationMin(settings.m_elevationMin);
|
|
|
|
response.getGs232ControllerSettings()->setElevationMax(settings.m_elevationMax);
|
2021-05-30 07:38:07 -04:00
|
|
|
response.getGs232ControllerSettings()->setTolerance(settings.m_tolerance);
|
|
|
|
response.getGs232ControllerSettings()->setProtocol(settings.m_protocol);
|
2020-10-27 12:22:10 -04:00
|
|
|
|
|
|
|
if (response.getGs232ControllerSettings()->getTitle()) {
|
|
|
|
*response.getGs232ControllerSettings()->getTitle() = settings.m_title;
|
|
|
|
} else {
|
|
|
|
response.getGs232ControllerSettings()->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getGs232ControllerSettings()->setRgbColor(settings.m_rgbColor);
|
|
|
|
response.getGs232ControllerSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getGs232ControllerSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getGs232ControllerSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
|
|
|
} else {
|
|
|
|
response.getGs232ControllerSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getGs232ControllerSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
2021-10-03 20:11:27 -04:00
|
|
|
response.getGs232ControllerSettings()->setReverseApiFeatureSetIndex(settings.m_reverseAPIFeatureSetIndex);
|
|
|
|
response.getGs232ControllerSettings()->setReverseApiFeatureIndex(settings.m_reverseAPIFeatureIndex);
|
2022-01-08 23:27:12 -05:00
|
|
|
|
|
|
|
if (settings.m_rollupState)
|
|
|
|
{
|
|
|
|
if (response.getGs232ControllerSettings()->getRollupState())
|
|
|
|
{
|
|
|
|
settings.m_rollupState->formatTo(response.getGs232ControllerSettings()->getRollupState());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState();
|
|
|
|
settings.m_rollupState->formatTo(swgRollupState);
|
|
|
|
response.getGs232ControllerSettings()->setRollupState(swgRollupState);
|
|
|
|
}
|
|
|
|
}
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GS232Controller::webapiUpdateFeatureSettings(
|
|
|
|
GS232ControllerSettings& settings,
|
|
|
|
const QStringList& featureSettingsKeys,
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response)
|
|
|
|
{
|
|
|
|
if (featureSettingsKeys.contains("azimuth")) {
|
|
|
|
settings.m_azimuth = response.getGs232ControllerSettings()->getAzimuth();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("elevation")) {
|
|
|
|
settings.m_elevation = response.getGs232ControllerSettings()->getElevation();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("serialPort")) {
|
|
|
|
settings.m_serialPort = *response.getGs232ControllerSettings()->getSerialPort();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("baudRate")) {
|
2021-10-03 20:11:27 -04:00
|
|
|
settings.m_baudRate = response.getGs232ControllerSettings()->getBaudRate();
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
2021-11-23 07:28:06 -05:00
|
|
|
if (featureSettingsKeys.contains("host")) {
|
|
|
|
settings.m_host = *response.getGs232ControllerSettings()->getHost();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("port")) {
|
|
|
|
settings.m_port = response.getGs232ControllerSettings()->getPort();
|
|
|
|
}
|
2020-10-27 12:22:10 -04:00
|
|
|
if (featureSettingsKeys.contains("track")) {
|
|
|
|
settings.m_track = response.getGs232ControllerSettings()->getTrack() != 0;
|
|
|
|
}
|
2021-10-03 17:15:15 -04:00
|
|
|
if (featureSettingsKeys.contains("source")) {
|
|
|
|
settings.m_source = *response.getGs232ControllerSettings()->getSource();
|
2021-01-13 14:44:53 -05:00
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("azimuthOffset")) {
|
|
|
|
settings.m_azimuthOffset = response.getGs232ControllerSettings()->getAzimuthOffset();
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
2021-01-13 14:44:53 -05:00
|
|
|
if (featureSettingsKeys.contains("elevationOffset")) {
|
|
|
|
settings.m_elevationOffset = response.getGs232ControllerSettings()->getElevationOffset();
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
2021-02-26 15:27:35 -05:00
|
|
|
if (featureSettingsKeys.contains("azimuthMin")) {
|
|
|
|
settings.m_azimuthMin = response.getGs232ControllerSettings()->getAzimuthMin();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("azimuthMax")) {
|
|
|
|
settings.m_azimuthMax = response.getGs232ControllerSettings()->getAzimuthMax();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("elevationMin")) {
|
|
|
|
settings.m_elevationMin = response.getGs232ControllerSettings()->getElevationMin();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("elevationMax")) {
|
|
|
|
settings.m_elevationMax = response.getGs232ControllerSettings()->getElevationMax();
|
|
|
|
}
|
2021-05-30 07:38:07 -04:00
|
|
|
if (featureSettingsKeys.contains("tolerance")) {
|
|
|
|
settings.m_tolerance = response.getGs232ControllerSettings()->getTolerance();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("protocol")) {
|
|
|
|
settings.m_protocol = (GS232ControllerSettings::Protocol)response.getGs232ControllerSettings()->getProtocol();
|
|
|
|
}
|
2020-10-27 12:22:10 -04:00
|
|
|
if (featureSettingsKeys.contains("title")) {
|
|
|
|
settings.m_title = *response.getGs232ControllerSettings()->getTitle();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("rgbColor")) {
|
|
|
|
settings.m_rgbColor = response.getGs232ControllerSettings()->getRgbColor();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getGs232ControllerSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("reverseAPIAddress")) {
|
|
|
|
settings.m_reverseAPIAddress = *response.getGs232ControllerSettings()->getReverseApiAddress();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getGs232ControllerSettings()->getReverseApiPort();
|
|
|
|
}
|
2021-10-03 20:11:27 -04:00
|
|
|
if (featureSettingsKeys.contains("reverseAPIFeatureSetIndex")) {
|
|
|
|
settings.m_reverseAPIFeatureSetIndex = response.getGs232ControllerSettings()->getReverseApiFeatureSetIndex();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("reverseAPIFeatureIndex")) {
|
|
|
|
settings.m_reverseAPIFeatureIndex = response.getGs232ControllerSettings()->getReverseApiFeatureIndex();
|
|
|
|
}
|
2022-01-08 23:27:12 -05:00
|
|
|
if (settings.m_rollupState && featureSettingsKeys.contains("rollupState")) {
|
|
|
|
settings.m_rollupState->updateFrom(featureSettingsKeys, response.getGs232ControllerSettings()->getRollupState());
|
|
|
|
}
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
|
|
|
|
2022-11-24 10:40:36 -05:00
|
|
|
void GS232Controller::webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const GS232ControllerSettings& settings, bool force)
|
2020-10-27 12:22:10 -04:00
|
|
|
{
|
|
|
|
SWGSDRangel::SWGFeatureSettings *swgFeatureSettings = new SWGSDRangel::SWGFeatureSettings();
|
|
|
|
// swgFeatureSettings->setOriginatorFeatureIndex(getIndexInDeviceSet());
|
|
|
|
// swgFeatureSettings->setOriginatorFeatureSetIndex(getDeviceSetIndex());
|
|
|
|
swgFeatureSettings->setFeatureType(new QString("GS232Controller"));
|
|
|
|
swgFeatureSettings->setGs232ControllerSettings(new SWGSDRangel::SWGGS232ControllerSettings());
|
|
|
|
SWGSDRangel::SWGGS232ControllerSettings *swgGS232ControllerSettings = swgFeatureSettings->getGs232ControllerSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (featureSettingsKeys.contains("azimuth") || force) {
|
|
|
|
swgGS232ControllerSettings->setAzimuth(settings.m_azimuth);
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("elevation") || force) {
|
|
|
|
swgGS232ControllerSettings->setElevation(settings.m_elevation);
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("serialPort") || force) {
|
|
|
|
swgGS232ControllerSettings->setSerialPort(new QString(settings.m_serialPort));
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("baudRate") || force) {
|
|
|
|
swgGS232ControllerSettings->setBaudRate(settings.m_baudRate);
|
|
|
|
}
|
2021-11-23 07:28:06 -05:00
|
|
|
if (featureSettingsKeys.contains("host") || force) {
|
|
|
|
swgGS232ControllerSettings->setHost(new QString(settings.m_host));
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("port") || force) {
|
|
|
|
swgGS232ControllerSettings->setPort(settings.m_port);
|
|
|
|
}
|
2020-10-27 12:22:10 -04:00
|
|
|
if (featureSettingsKeys.contains("track") || force) {
|
|
|
|
swgGS232ControllerSettings->setTrack(settings.m_track);
|
|
|
|
}
|
2021-10-03 17:15:15 -04:00
|
|
|
if (featureSettingsKeys.contains("source") || force) {
|
|
|
|
swgGS232ControllerSettings->setSource(new QString(settings.m_source));
|
2021-01-13 14:44:53 -05:00
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("azimuthOffset") || force) {
|
|
|
|
swgGS232ControllerSettings->setAzimuthOffset(settings.m_azimuthOffset);
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
2021-01-13 14:44:53 -05:00
|
|
|
if (featureSettingsKeys.contains("elevationOffset") || force) {
|
|
|
|
swgGS232ControllerSettings->setElevationOffset(settings.m_elevationOffset);
|
2020-10-27 12:22:10 -04:00
|
|
|
}
|
2021-02-26 15:27:35 -05:00
|
|
|
if (featureSettingsKeys.contains("azimuthMin") || force) {
|
|
|
|
swgGS232ControllerSettings->setAzimuthMin(settings.m_azimuthMin);
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("azimuthMax") || force) {
|
|
|
|
swgGS232ControllerSettings->setAzimuthMax(settings.m_azimuthMax);
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("elevationMin") || force) {
|
|
|
|
swgGS232ControllerSettings->setElevationMin(settings.m_elevationMin);
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("elevationMax") || force) {
|
|
|
|
swgGS232ControllerSettings->setElevationMax(settings.m_elevationMax);
|
|
|
|
}
|
2021-05-30 07:38:07 -04:00
|
|
|
if (featureSettingsKeys.contains("tolerance") || force) {
|
|
|
|
swgGS232ControllerSettings->setTolerance(settings.m_tolerance);
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("protocol") || force) {
|
|
|
|
swgGS232ControllerSettings->setProtocol((int)settings.m_protocol);
|
|
|
|
}
|
2020-10-27 12:22:10 -04:00
|
|
|
if (featureSettingsKeys.contains("title") || force) {
|
|
|
|
swgGS232ControllerSettings->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("rgbColor") || force) {
|
|
|
|
swgGS232ControllerSettings->setRgbColor(settings.m_rgbColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-10-03 17:15:15 -04:00
|
|
|
void GS232Controller::webapiFormatFeatureReport(SWGSDRangel::SWGFeatureReport& response)
|
|
|
|
{
|
|
|
|
response.getGs232ControllerReport()->setSources(new QList<QString*>());
|
|
|
|
|
2022-03-28 14:12:25 -04:00
|
|
|
for (const auto& item : m_availableChannelOrFeatures)
|
|
|
|
{
|
|
|
|
QString itemText = tr("%1%2:%3 %4")
|
|
|
|
.arg(item.m_kind)
|
|
|
|
.arg(item.m_superIndex)
|
|
|
|
.arg(item.m_index)
|
|
|
|
.arg(item.m_type);
|
|
|
|
|
|
|
|
response.getGs232ControllerReport()->getSources()->append(new QString(itemText));
|
2021-10-03 17:15:15 -04:00
|
|
|
}
|
2021-10-03 20:11:27 -04:00
|
|
|
|
|
|
|
QList<QSerialPortInfo> serialPorts = QSerialPortInfo::availablePorts();
|
|
|
|
QListIterator<QSerialPortInfo> i(serialPorts);
|
|
|
|
response.getGs232ControllerReport()->setSerialPorts(new QList<QString*>());
|
|
|
|
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
QSerialPortInfo info = i.next();
|
|
|
|
response.getGs232ControllerReport()->getSerialPorts()->append(new QString(info.portName()));
|
|
|
|
}
|
2021-10-05 09:03:31 -04:00
|
|
|
|
|
|
|
float azimuth, elevation;
|
|
|
|
m_settings.calcTargetAzEl(azimuth, elevation);
|
|
|
|
response.getGs232ControllerReport()->setTargetAzimuth(azimuth);
|
|
|
|
response.getGs232ControllerReport()->setTargetElevation(elevation);
|
|
|
|
response.getGs232ControllerReport()->setCurrentAzimuth(m_currentAzimuth);
|
|
|
|
response.getGs232ControllerReport()->setCurrentElevation(m_currentElevation);
|
|
|
|
response.getGs232ControllerReport()->setOnTarget(getOnTarget());
|
2021-10-23 15:24:25 -04:00
|
|
|
response.getGs232ControllerReport()->setRunningState(getState());
|
2021-10-03 17:15:15 -04:00
|
|
|
}
|
|
|
|
|
2020-10-27 12:22:10 -04:00
|
|
|
void GS232Controller::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
|
|
|
qWarning() << "GS232Controller::networkManagerFinished:"
|
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("GS232Controller::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
reply->deleteLater();
|
|
|
|
}
|
2022-03-28 14:12:25 -04:00
|
|
|
|
|
|
|
void GS232Controller::scanAvailableChannelsAndFeatures()
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::scanAvailableChannelsAndFeatures");
|
|
|
|
MainCore *mainCore = MainCore::instance();
|
|
|
|
std::vector<FeatureSet*>& featureSets = mainCore->getFeatureeSets();
|
|
|
|
m_availableChannelOrFeatures.clear();
|
|
|
|
|
|
|
|
for (const auto& featureSet : featureSets)
|
|
|
|
{
|
|
|
|
for (int fei = 0; fei < featureSet->getNumberOfFeatures(); fei++)
|
|
|
|
{
|
|
|
|
Feature *feature = featureSet->getFeatureAt(fei);
|
|
|
|
|
|
|
|
if (GS232ControllerSettings::m_pipeURIs.contains(feature->getURI()) && !m_availableChannelOrFeatures.contains(feature))
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::scanAvailableChannelsAndFeatures: store feature %d:%d %s (%p)",
|
|
|
|
featureSet->getIndex(), fei, qPrintable(feature->getURI()), feature);
|
|
|
|
GS232ControllerSettings::AvailableChannelOrFeature availableItem =
|
|
|
|
GS232ControllerSettings::AvailableChannelOrFeature{"F", featureSet->getIndex(), fei, feature->getIdentifier()};
|
|
|
|
m_availableChannelOrFeatures[feature] = availableItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<DeviceSet*>& deviceSets = mainCore->getDeviceSets();
|
|
|
|
|
|
|
|
for (const auto& deviceSet : deviceSets)
|
|
|
|
{
|
|
|
|
DSPDeviceSourceEngine *deviceSourceEngine = deviceSet->m_deviceSourceEngine;
|
|
|
|
|
|
|
|
if (deviceSourceEngine)
|
|
|
|
{
|
|
|
|
for (int chi = 0; chi < deviceSet->getNumberOfChannels(); chi++)
|
|
|
|
{
|
|
|
|
ChannelAPI *channel = deviceSet->getChannelAt(chi);
|
|
|
|
|
|
|
|
if (GS232ControllerSettings::m_pipeURIs.contains(channel->getURI()) && !m_availableChannelOrFeatures.contains(channel))
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::scanAvailableChannelsAndFeatures: store channel %d:%d %s (%p)",
|
|
|
|
deviceSet->getIndex(), chi, qPrintable(channel->getURI()), channel);
|
|
|
|
GS232ControllerSettings::AvailableChannelOrFeature availableItem =
|
|
|
|
GS232ControllerSettings::AvailableChannelOrFeature{"R", deviceSet->getIndex(), chi, channel->getIdentifier()};
|
|
|
|
m_availableChannelOrFeatures[channel] = availableItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
notifyUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GS232Controller::notifyUpdate()
|
|
|
|
{
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
MsgReportAvailableChannelOrFeatures *msg = MsgReportAvailableChannelOrFeatures::create();
|
|
|
|
msg->getItems() = m_availableChannelOrFeatures.values();
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GS232Controller::handleFeatureAdded(int featureSetIndex, Feature *feature)
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::handleFeatureAdded: featureSetIndex: %d:%d feature: %s (%p)",
|
|
|
|
featureSetIndex, feature->getIndexInFeatureSet(), qPrintable(feature->getURI()), feature);
|
|
|
|
FeatureSet *featureSet = MainCore::instance()->getFeatureeSets()[featureSetIndex];
|
|
|
|
|
|
|
|
if (GS232ControllerSettings::m_pipeURIs.contains(feature->getURI()))
|
|
|
|
{
|
|
|
|
GS232ControllerSettings::AvailableChannelOrFeature availableItem =
|
|
|
|
GS232ControllerSettings::AvailableChannelOrFeature{
|
|
|
|
"F",
|
|
|
|
featureSet->getIndex(),
|
|
|
|
feature->getIndexInFeatureSet(),
|
|
|
|
feature->getIdentifier()
|
|
|
|
};
|
|
|
|
m_availableChannelOrFeatures[feature] = availableItem;
|
|
|
|
|
|
|
|
notifyUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GS232Controller::handleFeatureRemoved(int featureSetIndex, Feature *feature)
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::handleFeatureRemoved: featureSetIndex: %d (%p)", featureSetIndex, feature);
|
|
|
|
|
|
|
|
if (m_availableChannelOrFeatures.contains(feature))
|
|
|
|
{
|
|
|
|
m_availableChannelOrFeatures.remove(feature);
|
|
|
|
notifyUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GS232Controller::handleChannelAdded(int deviceSetIndex, ChannelAPI *channel)
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::handleChannelAdded: deviceSetIndex: %d:%d channel: %s (%p)",
|
|
|
|
deviceSetIndex, channel->getIndexInDeviceSet(), qPrintable(channel->getURI()), channel);
|
|
|
|
DeviceSet *deviceSet = MainCore::instance()->getDeviceSets()[deviceSetIndex];
|
|
|
|
DSPDeviceSourceEngine *deviceSourceEngine = deviceSet->m_deviceSourceEngine;
|
|
|
|
|
|
|
|
if (deviceSourceEngine && GS232ControllerSettings::m_pipeURIs.contains(channel->getURI()))
|
|
|
|
{
|
|
|
|
GS232ControllerSettings::AvailableChannelOrFeature availableItem =
|
|
|
|
GS232ControllerSettings::AvailableChannelOrFeature{
|
|
|
|
"R",
|
|
|
|
deviceSet->getIndex(),
|
|
|
|
channel->getIndexInDeviceSet(),
|
|
|
|
channel->getIdentifier()
|
|
|
|
};
|
|
|
|
m_availableChannelOrFeatures[channel] = availableItem;
|
|
|
|
|
|
|
|
notifyUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GS232Controller::handleChannelRemoved(int deviceSetIndex, ChannelAPI *channel)
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::handleChannelRemoved: deviceSetIndex: %d (%p)", deviceSetIndex, channel);
|
|
|
|
|
|
|
|
if (m_availableChannelOrFeatures.contains(channel))
|
|
|
|
{
|
|
|
|
m_availableChannelOrFeatures.remove(channel);
|
|
|
|
notifyUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GS232Controller::registerPipe(QObject *object)
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::registerPipe: register %s (%p)", qPrintable(object->objectName()), object);
|
|
|
|
MessagePipes& messagePipes = MainCore::instance()->getMessagePipes();
|
|
|
|
ObjectPipe *pipe = messagePipes.registerProducerToConsumer(object, this, "target");
|
|
|
|
MessageQueue *messageQueue = qobject_cast<MessageQueue*>(pipe->m_element);
|
|
|
|
QObject::connect(
|
|
|
|
messageQueue,
|
|
|
|
&MessageQueue::messageEnqueued,
|
|
|
|
this,
|
|
|
|
[=](){ this->handlePipeMessageQueue(messageQueue); },
|
|
|
|
Qt::QueuedConnection
|
|
|
|
);
|
|
|
|
QObject::connect(
|
|
|
|
pipe,
|
|
|
|
&ObjectPipe::toBeDeleted,
|
|
|
|
this,
|
|
|
|
&GS232Controller::handleMessagePipeToBeDeleted
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GS232Controller::handleMessagePipeToBeDeleted(int reason, QObject* object)
|
|
|
|
{
|
|
|
|
if ((reason == 0) && m_availableChannelOrFeatures.contains(object)) // producer
|
|
|
|
{
|
|
|
|
qDebug("GS232Controller::handleMessagePipeToBeDeleted: removing channel or feature at (%p)", object);
|
|
|
|
m_availableChannelOrFeatures.remove(object);
|
|
|
|
notifyUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GS232Controller::handlePipeMessageQueue(MessageQueue* messageQueue)
|
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = messageQueue->pop()) != nullptr)
|
|
|
|
{
|
|
|
|
if (handleMessage(*message)) {
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|