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

Server: Web API: implemented /sdrangel/preset (PUT)

This commit is contained in:
f4exb 2017-12-20 14:31:17 +01:00
parent ffea25fe71
commit 894d926329
8 changed files with 120 additions and 6 deletions

View File

@ -14268,7 +14268,7 @@ $(document).ready(function() {
<div class="pull-right"></div>
<div class="clearfix"></div>
<p></p>
<p class="marked">Update device set settings on an existing preset.</p>
<p class="marked">Update an existing preset with device set settings.</p>
<p></p>
<br />
<pre class="prettyprint language-html prettyprinted" data-type="put"><code><span class="pln">/sdrangel/preset</span></code></pre>
@ -15011,7 +15011,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2017-12-20T00:50:19.499+01:00
Generated 2017-12-20T14:24:11.587+01:00
</div>
</div>
</div>

View File

@ -379,7 +379,7 @@ int WebAPIAdapterGUI::instancePresetPatch(
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
int nbDeviceSets = m_mainWindow.m_deviceUIs.size();
if (deviceSetIndex > nbDeviceSets)
if (deviceSetIndex >= nbDeviceSets)
{
*error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
return 404;

View File

@ -35,6 +35,7 @@
#include "maincore.h"
MESSAGE_CLASS_DEFINITION(MainCore::MsgDeleteInstance, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgLoadPreset, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgAddDeviceSet, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgRemoveLastDeviceSet, Message)
@ -100,6 +101,12 @@ bool MainCore::handleMessage(const Message& cmd)
emit finished();
return true;
}
else if (MsgLoadPreset::match(cmd))
{
MsgLoadPreset& notif = (MsgLoadPreset&) cmd;
loadPresetSettings(notif.getPreset(), notif.getDeviceSetIndex());
return true;
}
else if (MsgAddDeviceSet::match(cmd))
{
MsgAddDeviceSet& notif = (MsgAddDeviceSet&) cmd;
@ -290,6 +297,29 @@ void MainCore::removeLastDevice()
m_deviceSets.pop_back();
}
void MainCore::loadPresetSettings(const Preset* preset, int tabIndex)
{
qDebug("MainCore::loadPresetSettings: preset [%s | %s]",
qPrintable(preset->getGroup()),
qPrintable(preset->getDescription()));
if (tabIndex >= 0)
{
DeviceSet *deviceSet = m_deviceSets[tabIndex];
if (deviceSet->m_deviceSourceEngine) // source device
{
deviceSet->m_deviceSourceAPI->loadSourceSettings(preset);
deviceSet->loadRxChannelSettings(preset, m_pluginManager->getPluginAPI());
}
else if (deviceSet->m_deviceSinkEngine) // sink device
{
deviceSet->m_deviceSinkAPI->loadSinkSettings(preset);
deviceSet->loadTxChannelSettings(preset, m_pluginManager->getPluginAPI());
}
}
}
void MainCore::savePresetSettings(Preset* preset, int tabIndex)
{
qDebug("MainCore::savePresetSettings: preset [%s | %s]",

View File

@ -70,6 +70,29 @@ signals:
void finished();
private:
class MsgLoadPreset : public Message {
MESSAGE_CLASS_DECLARATION
public:
const Preset *getPreset() const { return m_preset; }
int getDeviceSetIndex() const { return m_deviceSetIndex; }
static MsgLoadPreset* create(const Preset *preset, int deviceSetIndex)
{
return new MsgLoadPreset(preset, deviceSetIndex);
}
private:
const Preset *m_preset;
int m_deviceSetIndex;
MsgLoadPreset(const Preset *preset, int deviceSetIndex) :
Message(),
m_preset(preset),
m_deviceSetIndex(deviceSetIndex)
{ }
};
class MsgDeleteInstance : public Message {
MESSAGE_CLASS_DECLARATION
@ -138,6 +161,7 @@ private:
WebAPIAdapterSrv *m_apiAdapter;
void loadSettings();
void loadPresetSettings(const Preset* preset, int tabIndex);
void savePresetSettings(Preset* preset, int tabIndex);
void setLoggingOptions();

View File

@ -33,6 +33,7 @@
#include "SWGPresetImport.h"
#include "SWGPresetExport.h"
#include "SWGPresets.h"
#include "SWGPresetTransfer.h"
#include "SWGSuccessResponse.h"
#include "SWGErrorResponse.h"
@ -484,6 +485,60 @@ int WebAPIAdapterSrv::instancePresetGet(
return 200;
}
int WebAPIAdapterSrv::instancePresetPatch(
SWGSDRangel::SWGPresetTransfer& query,
SWGSDRangel::SWGPresetIdentifier& response,
SWGSDRangel::SWGErrorResponse& error)
{
int deviceSetIndex = query.getDeviceSetIndex();
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
int nbDeviceSets = m_mainCore.m_deviceSets.size();
if (deviceSetIndex >= nbDeviceSets)
{
*error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
return 404;
}
const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(),
presetIdentifier->getCenterFrequency(),
*presetIdentifier->getName());
if (selectedPreset == 0)
{
*error.getMessage() = QString("There is no preset [%1, %2, %3]")
.arg(*presetIdentifier->getGroupName())
.arg(presetIdentifier->getCenterFrequency())
.arg(*presetIdentifier->getName());
return 404;
}
DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
if (deviceSet->m_deviceSourceEngine && !selectedPreset->isSourcePreset())
{
*error.getMessage() = QString("Preset type (T) and device set type (Rx) mismatch");
return 404;
}
if (deviceSet->m_deviceSinkEngine && selectedPreset->isSourcePreset())
{
*error.getMessage() = QString("Preset type (R) and device set type (Tx) mismatch");
return 404;
}
MainCore::MsgLoadPreset *msg = MainCore::MsgLoadPreset::create(selectedPreset, deviceSetIndex);
m_mainCore.m_inputMessageQueue.push(msg);
response.init();
response.setCenterFrequency(selectedPreset->getCenterFrequency());
*response.getGroupName() = selectedPreset->getGroup();
*response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
*response.getName() = selectedPreset->getDescription();
return 200;
}
int WebAPIAdapterSrv::instanceDeviceSetsPost(
bool tx,
SWGSDRangel::SWGSuccessResponse& response,

View File

@ -93,6 +93,11 @@ public:
SWGSDRangel::SWGPresets& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instancePresetPatch(
SWGSDRangel::SWGPresetTransfer& query,
SWGSDRangel::SWGPresetIdentifier& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDeviceSetsPost(
bool tx,
SWGSDRangel::SWGSuccessResponse& response,

View File

@ -337,7 +337,7 @@ paths:
"501":
description: Function not implemented
put:
description: Update device set settings on an existing preset.
description: Update an existing preset with device set settings.
operationId: instancePresetPut
tags:
- Instance

View File

@ -14268,7 +14268,7 @@ $(document).ready(function() {
<div class="pull-right"></div>
<div class="clearfix"></div>
<p></p>
<p class="marked">Update device set settings on an existing preset.</p>
<p class="marked">Update an existing preset with device set settings.</p>
<p></p>
<br />
<pre class="prettyprint language-html prettyprinted" data-type="put"><code><span class="pln">/sdrangel/preset</span></code></pre>
@ -15011,7 +15011,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2017-12-20T00:50:19.499+01:00
Generated 2017-12-20T14:24:11.587+01:00
</div>
</div>
</div>