1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

Web API: have /sdrangel/deviceset/{deviceSetIndex}/device/settings PUT,PATCH (3)

This commit is contained in:
f4exb 2017-12-07 22:38:39 +01:00
parent 2cf797a0a2
commit a041f827b4

View File

@ -643,10 +643,9 @@ void WebAPIRequestMapper::devicesetDeviceSettingsService(const std::string& inde
if (parseJsonBody(jsonStr, jsonObject, response)) if (parseJsonBody(jsonStr, jsonObject, response))
{ {
SWGSDRangel::SWGDeviceSettings normalResponse; SWGSDRangel::SWGDeviceSettings normalResponse;
//resetDeviceSettings(normalResponse); resetDeviceSettings(normalResponse);
normalResponse.fromJson(jsonStr);
if (validateDeviceSettings(normalResponse)) if (validateDeviceSettings(normalResponse, jsonObject))
{ {
int status = m_adapter->devicesetDeviceSettingsPutPatch( int status = m_adapter->devicesetDeviceSettingsPutPatch(
deviceSetIndex, deviceSetIndex,
@ -753,16 +752,27 @@ bool WebAPIRequestMapper::validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifi
bool WebAPIRequestMapper::validateDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings, QJsonObject& jsonObject) bool WebAPIRequestMapper::validateDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings, QJsonObject& jsonObject)
{ {
QString *deviceHwType = deviceSettings.getDeviceHwType(); if (jsonObject.contains("tx")) {
deviceSettings.setTx(jsonObject["tx"].toInt());
} else {
deviceSettings.setTx(0); // assume Rx
}
if (deviceHwType == 0) if (jsonObject.contains("deviceHwType")) {
{ deviceSettings.setDeviceHwType(new QString(jsonObject["deviceHwType"].toString()));
} else {
return false; return false;
} }
else
{ QString *deviceHwType = deviceSettings.getDeviceHwType();
if (*deviceHwType == "FileSource") { if (*deviceHwType == "FileSource") {
return deviceSettings.getFileSourceSettings() != 0; if (jsonObject.contains("fileSourceSettings")) {
deviceSettings.setFileSourceSettings(new SWGSDRangel::SWGFileSourceSettings());
return true;
} else {
return false;
}
} else if (*deviceHwType == "RTLSDR") { } else if (*deviceHwType == "RTLSDR") {
return deviceSettings.getRtlSdrSettings() != 0; return deviceSettings.getRtlSdrSettings() != 0;
} else if (*deviceHwType == "LimeSDR") { } else if (*deviceHwType == "LimeSDR") {
@ -772,7 +782,6 @@ bool WebAPIRequestMapper::validateDeviceSettings(SWGSDRangel::SWGDeviceSettings&
return deviceSettings.getLimeSdrOutputSettings() != 0; return deviceSettings.getLimeSdrOutputSettings() != 0;
} }
} }
}
} }
void WebAPIRequestMapper::resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings) void WebAPIRequestMapper::resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings)