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

Server: Web API: implemented /sdrangel/deviceset/{deviceSetIndex}/device/settings GET, PUT, PATCH

This commit is contained in:
f4exb 2017-12-22 16:41:37 +01:00
parent 78aa24014e
commit 3d5269dcd9
2 changed files with 111 additions and 0 deletions

View File

@ -34,6 +34,7 @@
#include "SWGPresetExport.h" #include "SWGPresetExport.h"
#include "SWGPresets.h" #include "SWGPresets.h"
#include "SWGPresetTransfer.h" #include "SWGPresetTransfer.h"
#include "SWGDeviceSettings.h"
#include "SWGSuccessResponse.h" #include "SWGSuccessResponse.h"
#include "SWGErrorResponse.h" #include "SWGErrorResponse.h"
@ -823,6 +824,105 @@ int WebAPIAdapterSrv::devicesetDevicePut(
} }
} }
int WebAPIAdapterSrv::devicesetDeviceSettingsGet(
int deviceSetIndex,
SWGSDRangel::SWGDeviceSettings& response,
SWGSDRangel::SWGErrorResponse& error)
{
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
{
DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
if (deviceSet->m_deviceSourceEngine) // Rx
{
response.setDeviceHwType(new QString(deviceSet->m_deviceSourceAPI->getHardwareId()));
response.setTx(0);
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
return source->webapiSettingsGet(response, *error.getMessage());
}
else if (deviceSet->m_deviceSinkEngine) // Tx
{
response.setDeviceHwType(new QString(deviceSet->m_deviceSinkAPI->getHardwareId()));
response.setTx(1);
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
return sink->webapiSettingsGet(response, *error.getMessage());
}
else
{
*error.getMessage() = QString("DeviceSet error");
return 500;
}
}
else
{
error.init();
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
return 404;
}
}
int WebAPIAdapterSrv::devicesetDeviceSettingsPutPatch(
int deviceSetIndex,
bool force,
SWGSDRangel::SWGDeviceSettings& response,
SWGSDRangel::SWGErrorResponse& error)
{
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
{
DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
if (deviceSet->m_deviceSourceEngine) // Rx
{
if (response.getTx() != 0)
{
*error.getMessage() = QString("Rx device found but Tx device requested");
return 400;
}
if (deviceSet->m_deviceSourceAPI->getHardwareId() != *response.getDeviceHwType())
{
*error.getMessage() = QString("Device mismatch. Found %1 input").arg(deviceSet->m_deviceSourceAPI->getHardwareId());
return 400;
}
else
{
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
return source->webapiSettingsPutPatch(force, response, *error.getMessage());
}
}
else if (deviceSet->m_deviceSinkEngine) // Tx
{
if (response.getTx() == 0)
{
*error.getMessage() = QString("Tx device found but Rx device requested");
return 400;
}
else if (deviceSet->m_deviceSinkAPI->getHardwareId() != *response.getDeviceHwType())
{
*error.getMessage() = QString("Device mismatch. Found %1 output").arg(deviceSet->m_deviceSinkAPI->getHardwareId());
return 400;
}
else
{
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
return sink->webapiSettingsPutPatch(force, response, *error.getMessage());
}
}
else
{
*error.getMessage() = QString("DeviceSet error");
return 500;
}
}
else
{
error.init();
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
return 404;
}
}
void WebAPIAdapterSrv::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList) void WebAPIAdapterSrv::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList)
{ {
deviceSetList->init(); deviceSetList->init();

View File

@ -135,6 +135,17 @@ public:
SWGSDRangel::SWGDeviceListItem& response, SWGSDRangel::SWGDeviceListItem& response,
SWGSDRangel::SWGErrorResponse& error); SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceSettingsGet(
int deviceSetIndex,
SWGSDRangel::SWGDeviceSettings& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceSettingsPutPatch(
int deviceSetIndex,
bool force,
SWGSDRangel::SWGDeviceSettings& response,
SWGSDRangel::SWGErrorResponse& error);
private: private:
MainCore& m_mainCore; MainCore& m_mainCore;