Skip to content

Commit

Permalink
Demod Analyzer plugin: channel selection via api
Browse files Browse the repository at this point in the history
Problem: It's not possible to select channel in Demod Analyzer feature
via api.

Solution:
Add new "action" into
POST /sdrangel/featureset/feature/{featureIndex}/actions
endpoint
  • Loading branch information
anton-kotenko committed Jan 21, 2024
1 parent 9bfeddf commit ed800f5
Show file tree
Hide file tree
Showing 17 changed files with 342 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ option(ENABLE_CHANNELRX_RADIOCLOCK "Enable channelrx radioclock plugin" ON)
option(ENABLE_CHANNELRX_RADIOASTRONOMY "Enable channelrx radioastronomy plugin" ON)
option(ENABLE_CHANNELRX_DEMODRADIOSONDE "Enable channelrx demodradiosonde plugin" ON)
option(ENABLE_CHANNELRX_FREQTRACKER "Enable channelrx freqtracker plugin" ON)
option(ENABLE_CHANNELRX_DEMODATV "Enable channelrx demodatv plugin" ON)
option(ENABLE_CHANNELRX_DEMODATV "Enable channelrx demodatv plugin" OFF)
option(ENABLE_CHANNELRX_DEMODPAGER "Enable channelrx demodpager plugin" ON)
option(ENABLE_CHANNELRX_DEMODDAB "Enable channelrx demoddab plugin" ON)
option(ENABLE_CHANNELRX_UDPSINK "Enable channelrx udpsink plugin" ON)
Expand Down Expand Up @@ -108,7 +108,7 @@ option(ENABLE_CHANNELTX_MODSSB "Enable channeltx modssb plugin" ON)
option(ENABLE_CHANNELTX_UDPSOURCE "Enable channeltx udpsource plugin" ON)
option(ENABLE_CHANNELTX_MODCHIRPCHAT "Enable channeltx modchirpchat plugin" ON)
option(ENABLE_CHANNELTX_MODWFM "Enable channeltx modwfm plugin" ON)
option(ENABLE_CHANNELTX_MODATV "Enable channeltx modatv plugin" ON)
option(ENABLE_CHANNELTX_MODATV "Enable channeltx modatv plugin" OFF)
option(ENABLE_CHANNELTX_MOD802.15.4 "Enable channeltx mod802.15.4 plugin" ON)
option(ENABLE_CHANNELTX_REMOTESOURCE "Enable channeltx remotesource plugin" ON)
option(ENABLE_CHANNELTX_FILESOURCE "Enable channeltx filesource plugin" ON)
Expand Down
31 changes: 31 additions & 0 deletions plugins/feature/demodanalyzer/demodanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,3 +708,34 @@ void DemodAnalyzer::handleDataPipeToBeDeleted(int reason, QObject *object)
}
}
}

int DemodAnalyzer::webapiActionsPost(
const QStringList& featureActionsKeys,
SWGSDRangel::SWGFeatureActions& query,
QString& errorMessage) {

MainCore* m_core = MainCore::instance();
auto action = query.getDemodAnalyzerActions();
if (action == nullptr) {
errorMessage = QString("missing DemodAnalyzerActions in request");
return 404;
}

auto deviceId = action->getDeviceId();
auto chanId = action->getChannelId();

ChannelAPI * chan = m_core->getChannel(deviceId, chanId);
if (chan == nullptr) {
errorMessage = QString("device(%1) or channel (%2) on the device does not exist").arg(deviceId).arg(chanId);
return 404;
}

MsgRefreshChannels *m1 = MsgRefreshChannels::create();
getInputMessageQueue()->push(m1);
MsgSelectChannel *msg = MsgSelectChannel::create(chan);
getInputMessageQueue()->push(msg);
return 200;
}



5 changes: 5 additions & 0 deletions plugins/feature/demodanalyzer/demodanalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ class DemodAnalyzer : public Feature
SWGSDRangel::SWGFeatureSettings& response,
QString& errorMessage);

virtual int webapiActionsPost(
const QStringList& featureActionsKeys,
SWGSDRangel::SWGFeatureActions& query,
QString& errorMessage);

static void webapiFormatFeatureSettings(
SWGSDRangel::SWGFeatureSettings& response,
const DemodAnalyzerSettings& settings);
Expand Down
18 changes: 17 additions & 1 deletion sdrbase/resources/webapi/doc/html2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5403,6 +5403,19 @@
}
},
"description" : "List of DV serial devices available in the system"
};
defs.DemodAnalyzerActions = {
"properties" : {
"deviceId" : {
"type" : "integer",
"description" : "Device Id/Number that channel belongs to"
},
"channelId" : {
"type" : "integer",
"description" : "Channel Id/Number of the channel within the device"
}
},
"description" : "Demod Analyzer actions"
};
defs.DemodAnalyzerSettings = {
"properties" : {
Expand Down Expand Up @@ -6241,6 +6254,9 @@
},
"VORLocalizerActions" : {
"$ref" : "#/definitions/VORLocalizerActions"
},
"DemodAnalyzerActions" : {
"$ref" : "#/definitions/DemodAnalyzerActions"
}
},
"description" : "Base feature actions. Only the feature actions corresponding to the feature specified in the featureType field is or should be present."
Expand Down Expand Up @@ -58413,7 +58429,7 @@ <h3> Status: 501 - Function not implemented </h3>
</div>
<div id="generator">
<div class="content">
Generated 2023-11-30T13:04:24.913+01:00
Generated 2024-01-21T13:22:02.160+01:00
</div>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions sdrbase/resources/webapi/doc/swagger/include/DemodAnalyzer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,15 @@ DemodAnalyzerSettings:
$ref: "/doc/swagger/include/GLScope.yaml#/GLScope"
rollupState:
$ref: "/doc/swagger/include/RollupState.yaml#/RollupState"

DemodAnalyzerActions:
description: "Demod Analyzer actions"
properties:
deviceId:
type: integer
required: true
description: "Device Id/Number that channel belongs to"
channelId:
type: integer
required: true
description: "Channel Id/Number of the channel within the device"
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ FeatureActions:
$ref: "/doc/swagger/include/StarTracker.yaml#/StarTrackerActions"
VORLocalizerActions:
$ref: "/doc/swagger/include/VORLocalizer.yaml#/VORLocalizerActions"
DemodAnalyzerActions:
$ref: "/doc/swagger/include/DemodAnalyzer.yaml#/DemodAnalyzerActions"
6 changes: 6 additions & 0 deletions sdrbase/webapi/webapirequestmapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <boost/lexical_cast.hpp>

#include "SWGDemodAnalyzerActions.h"
#include "httpdocrootsettings.h"
#include "webapirequestmapper.h"
#include "webapiutils.h"
Expand Down Expand Up @@ -5375,6 +5376,11 @@ bool WebAPIRequestMapper::getFeatureActions(
featureActions->setVorLocalizerActions(new SWGSDRangel::SWGVORLocalizerActions());
featureActions->getVorLocalizerActions()->fromJsonObject(actionsJsonObject);
}
else if (featureActionsKey == "DemodAnalyzerActions")
{
featureActions->setDemodAnalyzerActions(new SWGSDRangel::SWGDemodAnalyzerActions());
featureActions->getDemodAnalyzerActions()->fromJsonObject(actionsJsonObject);
}
else
{
return false;
Expand Down
3 changes: 2 additions & 1 deletion sdrbase/webapi/webapiutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ const QMap<QString, QString> WebAPIUtils::m_featureTypeToActionsKey = {
{"SatelliteTracker", "SatelliteTrackerActions"},
{"SimplePTT", "SimplePTTActions"},
{"StarTracker", "StarTrackerActions"},
{"VORLocalizer", "VORLocalizerActions"}
{"VORLocalizer", "VORLocalizerActions"},
{"DemodAnalyzer", "DemodAnalyzerActions"}
};

const QMap<QString, QString> WebAPIUtils::m_featureURIToSettingsKey = {
Expand Down
2 changes: 1 addition & 1 deletion swagger/docker/compose/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ EOF

image_tag_codegen="latest"
image_tag_server="latest"
sdrangel_codebase="/opt/build/sdrangel"
sdrangel_codebase="/Users/anton/sdrangel"
stack_name="-p sdrangelswg"
action="up -d"

Expand Down
12 changes: 12 additions & 0 deletions swagger/sdrangel/api/swagger/include/DemodAnalyzer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,15 @@ DemodAnalyzerSettings:
$ref: "http://swgserver:8081/api/swagger/include/GLScope.yaml#/GLScope"
rollupState:
$ref: "http://swgserver:8081/api/swagger/include/RollupState.yaml#/RollupState"

DemodAnalyzerActions:
description: "Demod Analyzer actions"
properties:
deviceId:
type: integer
required: true
description: "Device Id/Number that channel belongs to"
channelId:
type: integer
required: true
description: "Channel Id/Number of the channel within the device"
2 changes: 2 additions & 0 deletions swagger/sdrangel/api/swagger/include/FeatureActions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ FeatureActions:
$ref: "http://swgserver:8081/api/swagger/include/StarTracker.yaml#/StarTrackerActions"
VORLocalizerActions:
$ref: "http://swgserver:8081/api/swagger/include/VORLocalizer.yaml#/VORLocalizerActions"
DemodAnalyzerActions:
$ref: "http://swgserver:8081/api/swagger/include/DemodAnalyzer.yaml#/DemodAnalyzerActions"
18 changes: 17 additions & 1 deletion swagger/sdrangel/code/html2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5403,6 +5403,19 @@
}
},
"description" : "List of DV serial devices available in the system"
};
defs.DemodAnalyzerActions = {
"properties" : {
"deviceId" : {
"type" : "integer",
"description" : "Device Id/Number that channel belongs to"
},
"channelId" : {
"type" : "integer",
"description" : "Channel Id/Number of the channel within the device"
}
},
"description" : "Demod Analyzer actions"
};
defs.DemodAnalyzerSettings = {
"properties" : {
Expand Down Expand Up @@ -6241,6 +6254,9 @@
},
"VORLocalizerActions" : {
"$ref" : "#/definitions/VORLocalizerActions"
},
"DemodAnalyzerActions" : {
"$ref" : "#/definitions/DemodAnalyzerActions"
}
},
"description" : "Base feature actions. Only the feature actions corresponding to the feature specified in the featureType field is or should be present."
Expand Down Expand Up @@ -58413,7 +58429,7 @@ <h3> Status: 501 - Function not implemented </h3>
</div>
<div id="generator">
<div class="content">
Generated 2023-11-30T13:04:24.913+01:00
Generated 2024-01-21T13:22:02.160+01:00
</div>
</div>
</div>
Expand Down
131 changes: 131 additions & 0 deletions swagger/sdrangel/code/qt5/client/SWGDemodAnalyzerActions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* SDRangel
* This is the web REST/JSON API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ (4.3+ in Windows) GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube --- Limitations and specifcities: * In SDRangel GUI the first Rx device set cannot be deleted. Conversely the server starts with no device sets and its number of device sets can be reduced to zero by as many calls as necessary to /sdrangel/deviceset with DELETE method. * Preset import and export from/to file is a server only feature. * Device set focus is a GUI only feature. * The following channels are not implemented (status 501 is returned): ATV and DATV demodulators, Channel Analyzer NG, LoRa demodulator * The device settings and report structures contains only the sub-structure corresponding to the device type. The DeviceSettings and DeviceReport structures documented here shows all of them but only one will be or should be present at a time * The channel settings and report structures contains only the sub-structure corresponding to the channel type. The ChannelSettings and ChannelReport structures documented here shows all of them but only one will be or should be present at a time ---
*
* OpenAPI spec version: 7.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/


#include "SWGDemodAnalyzerActions.h"

#include "SWGHelpers.h"

#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>

namespace SWGSDRangel {

SWGDemodAnalyzerActions::SWGDemodAnalyzerActions(QString* json) {
init();
this->fromJson(*json);
}

SWGDemodAnalyzerActions::SWGDemodAnalyzerActions() {
device_id = 0;
m_device_id_isSet = false;
channel_id = 0;
m_channel_id_isSet = false;
}

SWGDemodAnalyzerActions::~SWGDemodAnalyzerActions() {
this->cleanup();
}

void
SWGDemodAnalyzerActions::init() {
device_id = 0;
m_device_id_isSet = false;
channel_id = 0;
m_channel_id_isSet = false;
}

void
SWGDemodAnalyzerActions::cleanup() {


}

SWGDemodAnalyzerActions*
SWGDemodAnalyzerActions::fromJson(QString &json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}

void
SWGDemodAnalyzerActions::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&device_id, pJson["deviceId"], "qint32", "");

::SWGSDRangel::setValue(&channel_id, pJson["channelId"], "qint32", "");

}

QString
SWGDemodAnalyzerActions::asJson ()
{
QJsonObject* obj = this->asJsonObject();

QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson();
delete obj;
return QString(bytes);
}

QJsonObject*
SWGDemodAnalyzerActions::asJsonObject() {
QJsonObject* obj = new QJsonObject();
if(m_device_id_isSet){
obj->insert("deviceId", QJsonValue(device_id));
}
if(m_channel_id_isSet){
obj->insert("channelId", QJsonValue(channel_id));
}

return obj;
}

qint32
SWGDemodAnalyzerActions::getDeviceId() {
return device_id;
}
void
SWGDemodAnalyzerActions::setDeviceId(qint32 device_id) {
this->device_id = device_id;
this->m_device_id_isSet = true;
}

qint32
SWGDemodAnalyzerActions::getChannelId() {
return channel_id;
}
void
SWGDemodAnalyzerActions::setChannelId(qint32 channel_id) {
this->channel_id = channel_id;
this->m_channel_id_isSet = true;
}


bool
SWGDemodAnalyzerActions::isSet(){
bool isObjectUpdated = false;
do{
if(m_device_id_isSet){
isObjectUpdated = true; break;
}
if(m_channel_id_isSet){
isObjectUpdated = true; break;
}
}while(false);
return isObjectUpdated;
}
}

Loading

0 comments on commit ed800f5

Please sign in to comment.