1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-02 06:04:39 -04:00

API: added GET /sdrangel/featurepresets and DELETE /sdrangel/featurepreset

This commit is contained in:
f4exb
2021-09-04 05:58:06 +02:00
parent bd47ba524f
commit e1c3726a27
22 changed files with 3115 additions and 2 deletions
+73
View File
@@ -71,6 +71,10 @@
#include "SWGLimeRFEDevices.h"
#include "SWGLimeRFESettings.h"
#include "SWGLimeRFEPower.h"
#include "SWGFeaturePresets.h"
#include "SWGFeaturePresetGroup.h"
#include "SWGFeaturePresetItem.h"
#include "SWGFeaturePresetIdentifier.h"
#include "SWGFeatureSetList.h"
#include "SWGFeatureSettings.h"
#include "SWGFeatureReport.h"
@@ -1406,6 +1410,75 @@ int WebAPIAdapter::instancePresetDelete(
return 202;
}
int WebAPIAdapter::instanceFeaturePresetsGet(
SWGSDRangel::SWGFeaturePresets& response,
SWGSDRangel::SWGErrorResponse& error)
{
(void) error;
int nbPresets = m_mainCore->m_settings.getFeatureSetPresetCount();
int nbGroups = 0;
int nbPresetsThisGroup = 0;
QString groupName;
response.init();
QList<SWGSDRangel::SWGFeaturePresetGroup*> *groups = response.getGroups();
QList<SWGSDRangel::SWGFeaturePresetItem*> *swgPresets = 0;
int i = 0;
// Presets are sorted by group first
for (; i < nbPresets; i++)
{
const FeatureSetPreset *preset = m_mainCore->m_settings.getFeatureSetPreset(i);
if ((i == 0) || (groupName != preset->getGroup())) // new group
{
if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); }
groups->append(new SWGSDRangel::SWGFeaturePresetGroup);
groups->back()->init();
groupName = preset->getGroup();
*groups->back()->getGroupName() = groupName;
swgPresets = groups->back()->getPresets();
nbGroups++;
nbPresetsThisGroup = 0;
}
swgPresets->append(new SWGSDRangel::SWGFeaturePresetItem);
swgPresets->back()->init();
*swgPresets->back()->getDescription() = preset->getDescription();
nbPresetsThisGroup++;
}
if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); }
response.setNbGroups(nbGroups);
return 200;
}
int WebAPIAdapter::instanceFeaturePresetDelete(
SWGSDRangel::SWGFeaturePresetIdentifier& response,
SWGSDRangel::SWGErrorResponse& error)
{
const FeatureSetPreset *selectedPreset = m_mainCore->m_settings.getFeatureSetPreset(*response.getGroupName(),
*response.getDescription());
if (selectedPreset == nullptr)
{
error.init();
*error.getMessage() = QString("There is no feature preset [%1, %2]")
.arg(*response.getGroupName())
.arg(*response.getDescription());
return 404;
}
*response.getGroupName() = selectedPreset->getGroup();
*response.getDescription() = selectedPreset->getDescription();
MainCore::MsgDeleteFeatureSetPreset *msg = MainCore::MsgDeleteFeatureSetPreset::create(const_cast<FeatureSetPreset*>(selectedPreset));
m_mainCore->m_mainMessageQueue->push(msg);
return 202;
}
int WebAPIAdapter::instanceDeviceSetsGet(
SWGSDRangel::SWGDeviceSetList& response,
SWGSDRangel::SWGErrorResponse& error)