mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-04 06:54:39 -04:00
Web API: have /sdrangel/deviceset/{deviceSetIndex}/device/settings PUT,PATCH (1)
This commit is contained in:
@@ -626,11 +626,39 @@ void WebAPIRequestMapper::devicesetDeviceSettingsService(const std::string& inde
|
||||
{
|
||||
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
|
||||
|
||||
if (request.getMethod() == "PUT")
|
||||
{
|
||||
}
|
||||
else if (request.getMethod() == "PATCH")
|
||||
if ((request.getMethod() == "PUT") || (request.getMethod() == "PATCH"))
|
||||
{
|
||||
QString jsonStr = request.getBody();
|
||||
|
||||
if (parseJsonBody(jsonStr, response))
|
||||
{
|
||||
SWGSDRangel::SWGDeviceSettings normalResponse;
|
||||
resetDeviceSettings(normalResponse);
|
||||
normalResponse.fromJson(jsonStr);
|
||||
|
||||
if (validateDeviceSettings(normalResponse))
|
||||
{
|
||||
int status = m_adapter->devicesetDeviceSettingsPutPatch(
|
||||
deviceSetIndex,
|
||||
(request.getMethod() == "PUT"), // force settings on PUT
|
||||
normalResponse,
|
||||
errorResponse);
|
||||
response.setStatus(status);
|
||||
|
||||
if (status == 200) {
|
||||
response.write(normalResponse.asJson().toUtf8());
|
||||
} else {
|
||||
response.write(errorResponse.asJson().toUtf8());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(400,"Invalid JSON request");
|
||||
errorResponse.init();
|
||||
*errorResponse.getMessage() = "Invalid JSON request";
|
||||
response.write(errorResponse.asJson().toUtf8());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (request.getMethod() == "GET")
|
||||
{
|
||||
@@ -709,6 +737,30 @@ bool WebAPIRequestMapper::validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifi
|
||||
return (presetIdentifier.getGroupName() && presetIdentifier.getName() && presetIdentifier.getType());
|
||||
}
|
||||
|
||||
bool WebAPIRequestMapper::validateDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings)
|
||||
{
|
||||
QString *deviceHwType = deviceSettings.getDeviceHwType();
|
||||
|
||||
if (deviceHwType == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*deviceHwType == "FileSource") {
|
||||
return deviceSettings.getFileSourceSettings() != 0;
|
||||
} else if (*deviceHwType == "RTLSDR") {
|
||||
return deviceSettings.getRtlSdrSettings() != 0;
|
||||
} else if (*deviceHwType == "LimeSDR") {
|
||||
if (deviceSettings.getTx() == 0) {
|
||||
return deviceSettings.getLimeSdrInputSettings() != 0;
|
||||
} else {
|
||||
return deviceSettings.getLimeSdrOutputSettings() != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebAPIRequestMapper::resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings)
|
||||
{
|
||||
deviceSettings.cleanup();
|
||||
|
||||
Reference in New Issue
Block a user