mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-06 15:17:48 -04:00
Server: Web API: implemented /sdrangel/preset POST
This commit is contained in:
parent
9dd707896d
commit
15453b7528
@ -433,7 +433,7 @@ int WebAPIAdapterGUI::instancePresetPut(
|
|||||||
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
|
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
|
||||||
int nbDeviceSets = m_mainWindow.m_deviceUIs.size();
|
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);
|
*error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
|
||||||
return 404;
|
return 404;
|
||||||
@ -489,7 +489,7 @@ int WebAPIAdapterGUI::instancePresetPost(
|
|||||||
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
|
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
|
||||||
int nbDeviceSets = m_mainWindow.m_deviceUIs.size();
|
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);
|
*error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
|
||||||
return 404;
|
return 404;
|
||||||
|
@ -548,7 +548,7 @@ int WebAPIAdapterSrv::instancePresetPut(
|
|||||||
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
|
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
|
||||||
int nbDeviceSets = m_mainCore.m_deviceSets.size();
|
int nbDeviceSets = m_mainCore.m_deviceSets.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);
|
*error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
|
||||||
return 404;
|
return 404;
|
||||||
@ -595,6 +595,62 @@ int WebAPIAdapterSrv::instancePresetPut(
|
|||||||
return 200;
|
return 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WebAPIAdapterSrv::instancePresetPost(
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
|
||||||
|
int deviceCenterFrequency = 0;
|
||||||
|
|
||||||
|
if (deviceSet->m_deviceSourceEngine) { // Rx
|
||||||
|
deviceCenterFrequency = deviceSet->m_deviceSourceEngine->getSource()->getCenterFrequency();
|
||||||
|
} else if (deviceSet->m_deviceSinkEngine) { // Tx
|
||||||
|
deviceCenterFrequency = deviceSet->m_deviceSinkEngine->getSink()->getCenterFrequency();
|
||||||
|
} else {
|
||||||
|
*error.getMessage() = QString("Unknown device in device set (not Rx nor Tx)");
|
||||||
|
return 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*presetIdentifier->getGroupName(),
|
||||||
|
deviceCenterFrequency,
|
||||||
|
*presetIdentifier->getName());
|
||||||
|
|
||||||
|
if (selectedPreset == 0) // save on a new preset
|
||||||
|
{
|
||||||
|
selectedPreset = m_mainCore.m_settings.newPreset(*presetIdentifier->getGroupName(), *presetIdentifier->getName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*error.getMessage() = QString("Preset already exists [%1, %2, %3]")
|
||||||
|
.arg(*presetIdentifier->getGroupName())
|
||||||
|
.arg(deviceCenterFrequency)
|
||||||
|
.arg(*presetIdentifier->getName());
|
||||||
|
return 409;
|
||||||
|
}
|
||||||
|
|
||||||
|
MainCore::MsgSavePreset *msg = MainCore::MsgSavePreset::create(const_cast<Preset*>(selectedPreset), deviceSetIndex, true);
|
||||||
|
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(
|
int WebAPIAdapterSrv::instanceDeviceSetsPost(
|
||||||
bool tx,
|
bool tx,
|
||||||
SWGSDRangel::SWGSuccessResponse& response,
|
SWGSDRangel::SWGSuccessResponse& response,
|
||||||
|
@ -103,6 +103,11 @@ public:
|
|||||||
SWGSDRangel::SWGPresetIdentifier& response,
|
SWGSDRangel::SWGPresetIdentifier& response,
|
||||||
SWGSDRangel::SWGErrorResponse& error);
|
SWGSDRangel::SWGErrorResponse& error);
|
||||||
|
|
||||||
|
virtual int instancePresetPost(
|
||||||
|
SWGSDRangel::SWGPresetTransfer& query,
|
||||||
|
SWGSDRangel::SWGPresetIdentifier& response,
|
||||||
|
SWGSDRangel::SWGErrorResponse& error);
|
||||||
|
|
||||||
virtual int instanceDeviceSetsPost(
|
virtual int instanceDeviceSetsPost(
|
||||||
bool tx,
|
bool tx,
|
||||||
SWGSDRangel::SWGSuccessResponse& response,
|
SWGSDRangel::SWGSuccessResponse& response,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user