1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 01:18:38 -05:00

API: simplify handling of ChannelAnalyzer and SoapySDR

This commit is contained in:
f4exb 2021-12-01 21:03:40 +01:00
parent f9155575d3
commit 9fb5a8f9bb
4 changed files with 13 additions and 411 deletions

View File

@ -18,13 +18,11 @@
#include <QString>
#include "SWGChannelSettings.h"
#include "chanalyzer.h"
#include "chanalyzerwebapiadapter.h"
ChannelAnalyzerWebAPIAdapter::ChannelAnalyzerWebAPIAdapter()
{
m_settings.setScopeGUI(&m_glScopeSettings);
m_settings.setSpectrumGUI(&m_SpectrumSettings);
}
{}
ChannelAnalyzerWebAPIAdapter::~ChannelAnalyzerWebAPIAdapter()
{}
@ -34,133 +32,21 @@ int ChannelAnalyzerWebAPIAdapter::webapiSettingsGet(
QString& errorMessage)
{
(void) errorMessage;
response.setChannelAnalyzerSettings(new SWGSDRangel::SWGChannelAnalyzerSettings());
response.getChannelAnalyzerSettings()->init();
webapiFormatChannelSettings(response, m_settings, m_glScopeSettings, m_SpectrumSettings);
ChannelAnalyzer::webapiFormatChannelSettings(response, m_settings);
return 200;
}
void ChannelAnalyzerWebAPIAdapter::webapiFormatChannelSettings(
SWGSDRangel::SWGChannelSettings& response,
const ChannelAnalyzerSettings& settings,
const GLScopeSettings& scopeSettings,
const SpectrumSettings& spectrumSettings)
{
response.getChannelAnalyzerSettings()->setFrequency(settings.m_inputFrequencyOffset);
response.getChannelAnalyzerSettings()->setDownSample(settings.m_rationalDownSample ? 1 : 0);
response.getChannelAnalyzerSettings()->setDownSampleRate(settings.m_rationalDownSamplerRate);
response.getChannelAnalyzerSettings()->setBandwidth(settings.m_bandwidth);
response.getChannelAnalyzerSettings()->setLowCutoff(settings.m_lowCutoff);
response.getChannelAnalyzerSettings()->setSpanLog2(settings.m_log2Decim);
response.getChannelAnalyzerSettings()->setSsb(settings.m_ssb ? 1 : 0);
response.getChannelAnalyzerSettings()->setPll(settings.m_pll ? 1 : 0);
response.getChannelAnalyzerSettings()->setFll(settings.m_fll ? 1 : 0);
response.getChannelAnalyzerSettings()->setCostasLoop(settings.m_costasLoop ? 1 : 0);
response.getChannelAnalyzerSettings()->setRrc(settings.m_rrc ? 1 : 0);
response.getChannelAnalyzerSettings()->setRrcRolloff(settings.m_rrcRolloff);
response.getChannelAnalyzerSettings()->setPllPskOrder(settings.m_pllPskOrder);
response.getChannelAnalyzerSettings()->setPllBandwidth(settings.m_pllBandwidth);
response.getChannelAnalyzerSettings()->setPllDampingFactor(settings.m_pllBandwidth);
response.getChannelAnalyzerSettings()->setPllLoopGain(settings.m_pllLoopGain);
response.getChannelAnalyzerSettings()->setInputType((int) settings.m_inputType);
response.getChannelAnalyzerSettings()->setRgbColor(settings.m_rgbColor);
response.getChannelAnalyzerSettings()->setTitle(new QString(settings.m_title));
// scope
SWGSDRangel::SWGGLScope *swgScope = new SWGSDRangel::SWGGLScope();
swgScope->init();
response.getChannelAnalyzerSettings()->setScopeConfig(swgScope);
scopeSettings.formatTo(swgScope);
// spectrum
SWGSDRangel::SWGGLSpectrum *swgSpectrum = new SWGSDRangel::SWGGLSpectrum();
swgSpectrum->init();
response.getChannelAnalyzerSettings()->setSpectrumConfig(swgSpectrum);
spectrumSettings.formatTo(swgSpectrum);
}
int ChannelAnalyzerWebAPIAdapter::webapiSettingsPutPatch(
bool force,
const QStringList& channelSettingsKeys,
SWGSDRangel::SWGChannelSettings& response,
QString& errorMessage)
{
(void) force;
(void) force; // no action
(void) errorMessage;
webapiUpdateChannelSettings(m_settings, m_glScopeSettings, m_SpectrumSettings, channelSettingsKeys, response);
ChannelAnalyzer::webapiUpdateChannelSettings(m_settings, channelSettingsKeys, response);
return 200;
}
void ChannelAnalyzerWebAPIAdapter::webapiUpdateChannelSettings(
ChannelAnalyzerSettings& settings,
GLScopeSettings& scopeSettings,
SpectrumSettings& spectrumSettings,
const QStringList& channelSettingsKeys,
SWGSDRangel::SWGChannelSettings& response)
{
if (channelSettingsKeys.contains("bandwidth")) {
settings.m_bandwidth = response.getChannelAnalyzerSettings()->getBandwidth();
}
if (channelSettingsKeys.contains("downSample")) {
settings.m_rationalDownSample = response.getChannelAnalyzerSettings()->getDownSample() != 0;
}
if (channelSettingsKeys.contains("downSampleRate")) {
settings.m_rationalDownSamplerRate = response.getChannelAnalyzerSettings()->getDownSampleRate();
}
if (channelSettingsKeys.contains("fll")) {
settings.m_fll = response.getChannelAnalyzerSettings()->getFll() != 0;
}
if (channelSettingsKeys.contains("frequency")) {
settings.m_inputFrequencyOffset = response.getChannelAnalyzerSettings()->getFrequency();
}
if (channelSettingsKeys.contains("inputType")) {
settings.m_inputType = (ChannelAnalyzerSettings::InputType) response.getChannelAnalyzerSettings()->getInputType();
}
if (channelSettingsKeys.contains("lowCutoff")) {
settings.m_lowCutoff = response.getChannelAnalyzerSettings()->getLowCutoff();
}
if (channelSettingsKeys.contains("pll")) {
settings.m_pll = response.getChannelAnalyzerSettings()->getPll() != 0;
}
if (channelSettingsKeys.contains("costasLoop")) {
settings.m_costasLoop = response.getChannelAnalyzerSettings()->getCostasLoop() != 0;
}
if (channelSettingsKeys.contains("pllPskOrder")) {
settings.m_pllPskOrder = response.getChannelAnalyzerSettings()->getPllPskOrder();
}
if (channelSettingsKeys.contains("pllBandwidth")) {
settings.m_pllBandwidth = response.getChannelAnalyzerSettings()->getPllBandwidth();
}
if (channelSettingsKeys.contains("pllDampingFactor")) {
settings.m_pllDampingFactor = response.getChannelAnalyzerSettings()->getPllDampingFactor();
}
if (channelSettingsKeys.contains("pllLoopGain")) {
settings.m_pllLoopGain = response.getChannelAnalyzerSettings()->getPllLoopGain();
}
if (channelSettingsKeys.contains("rgbColor")) {
settings.m_rgbColor = response.getChannelAnalyzerSettings()->getRgbColor();
}
if (channelSettingsKeys.contains("rrc")) {
settings.m_rrc = response.getChannelAnalyzerSettings()->getRrc() != 0;
}
if (channelSettingsKeys.contains("rrcRolloff")) {
settings.m_rrcRolloff = response.getChannelAnalyzerSettings()->getRrcRolloff();
}
if (channelSettingsKeys.contains("spanLog2")) {
settings.m_log2Decim = response.getChannelAnalyzerSettings()->getSpanLog2();
}
if (channelSettingsKeys.contains("ssb")) {
settings.m_ssb = response.getChannelAnalyzerSettings()->getSsb() != 0;
}
if (channelSettingsKeys.contains("title")) {
settings.m_title = *response.getChannelAnalyzerSettings()->getTitle();
}
// scope
if (channelSettingsKeys.contains("scopeConfig")) {
scopeSettings.updateFrom(channelSettingsKeys, response.getChannelAnalyzerSettings()->getScopeConfig());
}
// spectrum
if (channelSettingsKeys.contains("spectrumConfig")) {
spectrumSettings.updateFrom(channelSettingsKeys, response.getChannelAnalyzerSettings()->getSpectrumConfig());
}
}

View File

@ -43,24 +43,8 @@ public:
const QStringList& channelSettingsKeys,
SWGSDRangel::SWGChannelSettings& response,
QString& errorMessage);
static void webapiFormatChannelSettings(
SWGSDRangel::SWGChannelSettings& response,
const ChannelAnalyzerSettings& settings,
const GLScopeSettings& scopeSettings,
const SpectrumSettings& spectrumSettings);
static void webapiUpdateChannelSettings(
ChannelAnalyzerSettings& settings,
GLScopeSettings& scopeSettings,
SpectrumSettings& spectrumSettings,
const QStringList& channelSettingsKeys,
SWGSDRangel::SWGChannelSettings& response);
private:
ChannelAnalyzerSettings m_settings;
GLScopeSettings m_glScopeSettings;
SpectrumSettings m_SpectrumSettings;
};
#endif // INCLUDE_CHANALYZER_WEBAPIADAPTER_H

View File

@ -4642,17 +4642,15 @@ bool WebAPIRequestMapper::getDeviceSettings(
}
else if (deviceSettingsKey == "soapySDRInputSettings")
{
processSoapySDRSettings(deviceSettings, settingsJsonObject, deviceSettingsKeys, true);
// deviceSettings->setSoapySdrInputSettings(new SWGSDRangel::SWGSoapySDRInputSettings());
// deviceSettings->getSoapySdrInputSettings()->init(); // contains complex objects
// deviceSettings->getSoapySdrInputSettings()->fromJsonObject(settingsJsonObject);
deviceSettings->setSoapySdrInputSettings(new SWGSDRangel::SWGSoapySDRInputSettings());
deviceSettings->getSoapySdrInputSettings()->init(); // contains complex objects
deviceSettings->getSoapySdrInputSettings()->fromJsonObject(settingsJsonObject);
}
else if (deviceSettingsKey == "soapySDROutputSettings")
{
processSoapySDRSettings(deviceSettings, settingsJsonObject, deviceSettingsKeys, false);
// deviceSettings->setSoapySdrOutputSettings(new SWGSDRangel::SWGSoapySDROutputSettings());
// deviceSettings->getSoapySdrOutputSettings()->init(); // contains complex objects
// deviceSettings->getSoapySdrOutputSettings()->fromJsonObject(settingsJsonObject);
deviceSettings->setSoapySdrOutputSettings(new SWGSDRangel::SWGSoapySDROutputSettings());
deviceSettings->getSoapySdrOutputSettings()->init(); // contains complex objects
deviceSettings->getSoapySdrOutputSettings()->fromJsonObject(settingsJsonObject);
}
else if (deviceSettingsKey == "testSourceSettings")
{
@ -5140,262 +5138,3 @@ void WebAPIRequestMapper::resetFeatureActions(SWGSDRangel::SWGFeatureActions& fe
featureActions.setSimplePttActions(nullptr);
}
void WebAPIRequestMapper::processSoapySDRSettings(
SWGSDRangel::SWGDeviceSettings *deviceSettings,
QJsonObject& deviceSettingsJson,
QStringList& deviceSettingsKeys,
bool inputElseOutput
)
{
if (inputElseOutput)
{
SWGSDRangel::SWGSoapySDRInputSettings *swgSoapySDRInputSettings = new SWGSDRangel::SWGSoapySDRInputSettings();
deviceSettings->setSoapySdrInputSettings(swgSoapySDRInputSettings);
swgSoapySDRInputSettings->init();
if (deviceSettingsJson.contains("centerFrequency")) {
swgSoapySDRInputSettings->setCenterFrequency(deviceSettingsJson["centerFrequency"].toInt());
}
if (deviceSettingsJson.contains("LOppmTenths")) {
swgSoapySDRInputSettings->setLOppmTenths(deviceSettingsJson["LOppmTenths"].toInt());
}
if (deviceSettingsJson.contains("devSampleRate")) {
swgSoapySDRInputSettings->setDevSampleRate(deviceSettingsJson["devSampleRate"].toInt());
}
if (deviceSettingsJson.contains("log2Decim")) {
swgSoapySDRInputSettings->setLog2Decim(deviceSettingsJson["log2Decim"].toInt());
}
if (deviceSettingsJson.contains("fcPos")) {
swgSoapySDRInputSettings->setFcPos(deviceSettingsJson["fcPos"].toInt());
}
if (deviceSettingsJson.contains("softDCCorrection")) {
swgSoapySDRInputSettings->setSoftDcCorrection(deviceSettingsJson["softDCCorrection"].toInt());
}
if (deviceSettingsJson.contains("softIQCorrection")) {
swgSoapySDRInputSettings->setSoftIqCorrection(deviceSettingsJson["softIQCorrection"].toInt());
}
if (deviceSettingsJson.contains("transverterMode")) {
swgSoapySDRInputSettings->setTransverterMode(deviceSettingsJson["transverterMode"].toInt());
}
if (deviceSettingsJson.contains("transverterDeltaFrequency")) {
swgSoapySDRInputSettings->setTransverterDeltaFrequency(deviceSettingsJson["transverterDeltaFrequency"].toInt());
}
if (deviceSettingsJson.contains("antenna")) {
swgSoapySDRInputSettings->setAntenna(new QString(deviceSettingsJson["antenna"].toString()));
}
if (deviceSettingsJson.contains("bandwidth")) {
swgSoapySDRInputSettings->setBandwidth(deviceSettingsJson["bandwidth"].toInt());
}
if (deviceSettingsJson.contains("globalGain")) {
swgSoapySDRInputSettings->setGlobalGain(deviceSettingsJson["globalGain"].toInt());
}
if (deviceSettingsJson.contains("autoGain")) {
swgSoapySDRInputSettings->setAutoGain(deviceSettingsJson["autoGain"].toInt());
}
if (deviceSettingsJson.contains("autoDCCorrection")) {
swgSoapySDRInputSettings->setAutoDcCorrection(deviceSettingsJson["autoDCCorrection"].toInt());
}
if (deviceSettingsJson.contains("autoIQCorrection")) {
swgSoapySDRInputSettings->setAutoIqCorrection(deviceSettingsJson["autoIQCorrection"].toInt());
}
if (deviceSettingsJson.contains("dcCorrection"))
{
SWGSDRangel::SWGComplex *swgComplex = new SWGSDRangel::SWGComplex;
swgSoapySDRInputSettings->setDcCorrection(swgComplex);
QJsonObject complexJson = deviceSettingsJson["dcCorrection"].toObject();
if (complexJson.contains("real")) {
swgComplex->setReal(complexJson["real"].toDouble());
}
if (complexJson.contains("imag")) {
swgComplex->setImag(complexJson["imag"].toDouble());
}
}
if (deviceSettingsJson.contains("iqCorrection"))
{
SWGSDRangel::SWGComplex *swgComplex = new SWGSDRangel::SWGComplex;
swgSoapySDRInputSettings->setIqCorrection(swgComplex);
QJsonObject complexJson = deviceSettingsJson["iqCorrection"].toObject();
if (complexJson.contains("real")) {
swgComplex->setReal(complexJson["real"].toDouble());
}
if (complexJson.contains("imag")) {
swgComplex->setImag(complexJson["imag"].toDouble());
}
}
if (deviceSettingsJson.contains("useReverseAPI")) {
swgSoapySDRInputSettings->setUseReverseApi(deviceSettingsJson["useReverseAPI"].toInt());
}
if (deviceSettingsJson.contains("reverseAPIAddress")) {
swgSoapySDRInputSettings->setReverseApiAddress(new QString(deviceSettingsJson["reverseAPIAddress"].toString()));
}
if (deviceSettingsJson.contains("reverseAPIPort")) {
swgSoapySDRInputSettings->setReverseApiPort(deviceSettingsJson["reverseAPIPort"].toInt());
}
if (deviceSettingsJson.contains("reverseAPIDeviceIndex")) {
swgSoapySDRInputSettings->setReverseApiDeviceIndex(deviceSettingsJson["reverseAPIDeviceIndex"].toInt());
}
}
else
{
SWGSDRangel::SWGSoapySDROutputSettings *swgSoapySDROutputSettings = new SWGSDRangel::SWGSoapySDROutputSettings();
deviceSettings->setSoapySdrOutputSettings(swgSoapySDROutputSettings);
swgSoapySDROutputSettings->init();
if (deviceSettingsJson.contains("centerFrequency")) {
swgSoapySDROutputSettings->setCenterFrequency(deviceSettingsJson["centerFrequency"].toInt());
}
if (deviceSettingsJson.contains("LOppmTenths")) {
swgSoapySDROutputSettings->setLOppmTenths(deviceSettingsJson["LOppmTenths"].toInt());
}
if (deviceSettingsJson.contains("devSampleRate")) {
swgSoapySDROutputSettings->setDevSampleRate(deviceSettingsJson["devSampleRate"].toInt());
}
if (deviceSettingsJson.contains("log2Interp")) {
swgSoapySDROutputSettings->setLog2Interp(deviceSettingsJson["log2Interp"].toInt());
}
if (deviceSettingsJson.contains("transverterMode")) {
swgSoapySDROutputSettings->setTransverterMode(deviceSettingsJson["transverterMode"].toInt());
}
if (deviceSettingsJson.contains("transverterDeltaFrequency")) {
swgSoapySDROutputSettings->setTransverterDeltaFrequency(deviceSettingsJson["transverterDeltaFrequency"].toInt());
}
if (deviceSettingsJson.contains("antenna")) {
swgSoapySDROutputSettings->setAntenna(new QString(deviceSettingsJson["antenna"].toString()));
}
if (deviceSettingsJson.contains("bandwidth")) {
swgSoapySDROutputSettings->setBandwidth(deviceSettingsJson["bandwidth"].toInt());
}
if (deviceSettingsJson.contains("globalGain")) {
swgSoapySDROutputSettings->setGlobalGain(deviceSettingsJson["globalGain"].toInt());
}
if (deviceSettingsJson.contains("autoGain")) {
swgSoapySDROutputSettings->setAutoGain(deviceSettingsJson["autoGain"].toInt());
}
if (deviceSettingsJson.contains("autoDCCorrection")) {
swgSoapySDROutputSettings->setAutoDcCorrection(deviceSettingsJson["autoDCCorrection"].toInt());
}
if (deviceSettingsJson.contains("autoIQCorrection")) {
swgSoapySDROutputSettings->setAutoIqCorrection(deviceSettingsJson["autoIQCorrection"].toInt());
}
if (deviceSettingsJson.contains("dcCorrection"))
{
SWGSDRangel::SWGComplex *swgComplex = new SWGSDRangel::SWGComplex;
swgSoapySDROutputSettings->setDcCorrection(swgComplex);
QJsonObject complexJson = deviceSettingsJson["dcCorrection"].toObject();
if (complexJson.contains("real")) {
swgComplex->setReal(complexJson["real"].toDouble());
}
if (complexJson.contains("imag")) {
swgComplex->setImag(complexJson["imag"].toDouble());
}
}
if (deviceSettingsJson.contains("iqCorrection"))
{
SWGSDRangel::SWGComplex *swgComplex = new SWGSDRangel::SWGComplex;
swgSoapySDROutputSettings->setIqCorrection(swgComplex);
QJsonObject complexJson = deviceSettingsJson["iqCorrection"].toObject();
if (complexJson.contains("real")) {
swgComplex->setReal(complexJson["real"].toDouble());
}
if (complexJson.contains("imag")) {
swgComplex->setImag(complexJson["imag"].toDouble());
}
}
if (deviceSettingsJson.contains("useReverseAPI")) {
swgSoapySDROutputSettings->setUseReverseApi(deviceSettingsJson["useReverseAPI"].toInt());
}
if (deviceSettingsJson.contains("reverseAPIAddress")) {
swgSoapySDROutputSettings->setReverseApiAddress(new QString(deviceSettingsJson["reverseAPIAddress"].toString()));
}
if (deviceSettingsJson.contains("reverseAPIPort")) {
swgSoapySDROutputSettings->setReverseApiPort(deviceSettingsJson["reverseAPIPort"].toInt());
}
if (deviceSettingsJson.contains("reverseAPIDeviceIndex")) {
swgSoapySDROutputSettings->setReverseApiDeviceIndex(deviceSettingsJson["reverseAPIDeviceIndex"].toInt());
}
}
if (deviceSettingsKeys.contains("deviceArgSettings"))
{
QList<SWGSDRangel::SWGArgValue *> *swgArgSettings = new QList<SWGSDRangel::SWGArgValue *>;
QJsonArray argsJson = deviceSettingsJson["deviceArgSettings"].toArray();
if (inputElseOutput) {
deviceSettings->getSoapySdrInputSettings()->setDeviceArgSettings(swgArgSettings);
} else {
deviceSettings->getSoapySdrOutputSettings()->setDeviceArgSettings(swgArgSettings);
}
for (int i = 0; i < argsJson.count(); i++)
{
SWGSDRangel::SWGArgValue *argValue = new SWGSDRangel::SWGArgValue();
swgArgSettings->append(argValue);
QJsonObject argValueJson = argsJson.at(i).toObject();
argValue->fromJsonObject(argValueJson);
}
}
if (deviceSettingsKeys.contains("individualGains"))
{
QList<SWGSDRangel::SWGArgValue *> *swgIndividualGains = new QList<SWGSDRangel::SWGArgValue *>;
QJsonArray argsJson = deviceSettingsJson["individualGains"].toArray();
if (inputElseOutput) {
deviceSettings->getSoapySdrInputSettings()->setIndividualGains(swgIndividualGains);
} else {
deviceSettings->getSoapySdrOutputSettings()->setIndividualGains(swgIndividualGains);
}
for (int i = 0; i < argsJson.count(); i++)
{
SWGSDRangel::SWGArgValue *argValue = new SWGSDRangel::SWGArgValue();
swgIndividualGains->append(argValue);
QJsonObject argValueJson = argsJson.at(i).toObject();
argValue->fromJsonObject(argValueJson);
}
}
if (deviceSettingsKeys.contains("streamArgSettings"))
{
QList<SWGSDRangel::SWGArgValue *> *swgStreamArgSettings = new QList<SWGSDRangel::SWGArgValue *>;
QJsonArray argsJson = deviceSettingsJson["streamArgSettings"].toArray();
if (inputElseOutput) {
deviceSettings->getSoapySdrInputSettings()->setStreamArgSettings(swgStreamArgSettings);
} else {
deviceSettings->getSoapySdrOutputSettings()->setStreamArgSettings(swgStreamArgSettings);
}
for (int i = 0; i < argsJson.count(); i++)
{
SWGSDRangel::SWGArgValue *argValue = new SWGSDRangel::SWGArgValue();
swgStreamArgSettings->append(argValue);
QJsonObject argValueJson = argsJson.at(i).toObject();
argValue->fromJsonObject(argValueJson);
}
}
if (deviceSettingsKeys.contains("tunableElements"))
{
QList<SWGSDRangel::SWGArgValue *> *swgTunableElements = new QList<SWGSDRangel::SWGArgValue *>;
QJsonArray argsJson = deviceSettingsJson["tunableElements"].toArray();
if (inputElseOutput) {
deviceSettings->getSoapySdrInputSettings()->setTunableElements(swgTunableElements);
} else {
deviceSettings->getSoapySdrOutputSettings()->setTunableElements(swgTunableElements);
}
for (int i = 0; i < argsJson.count(); i++)
{
SWGSDRangel::SWGArgValue *argValue = new SWGSDRangel::SWGArgValue();
swgTunableElements->append(argValue);
QJsonObject argValueJson = argsJson.at(i).toObject();
argValue->fromJsonObject(argValueJson);
}
}
}

View File

@ -219,13 +219,6 @@ private:
void resetFeatureReport(SWGSDRangel::SWGFeatureReport& featureReport);
void resetFeatureActions(SWGSDRangel::SWGFeatureActions& featureActions);
void processSoapySDRSettings(
SWGSDRangel::SWGDeviceSettings *deviceSettings,
QJsonObject& deviceSettingsJson,
QStringList& deviceSettingsKeys,
bool inputElseOutput
);
static const QMap<QString, QString> m_channelURIToSettingsKey;
static const QMap<QString, QString> m_deviceIdToSettingsKey;
static const QMap<QString, QString> m_channelTypeToSettingsKey;