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

This commit is contained in:
f4exb 2017-12-08 00:56:29 +01:00
parent a041f827b4
commit 34cb4aa89b
3 changed files with 73 additions and 29 deletions

View File

@ -287,10 +287,11 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force)
{
if (rtlsdr_set_agc_mode(m_dev, settings.m_agc ? 1 : 0) < 0)
{
qCritical("could not set AGC mode %s", settings.m_agc ? "on" : "off");
qCritical("RTLSDRInput::applySettings: could not set AGC mode %s", settings.m_agc ? "on" : "off");
}
else
{
qDebug("RTLSDRInput::applySettings: AGC mode %s", settings.m_agc ? "on" : "off");
m_settings.m_agc = settings.m_agc;
}
}
@ -301,9 +302,13 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force)
if(m_dev != 0)
{
if(rtlsdr_set_tuner_gain(m_dev, m_settings.m_gain) != 0)
if (rtlsdr_set_tuner_gain(m_dev, m_settings.m_gain) != 0)
{
qDebug("rtlsdr_set_tuner_gain() failed");
qCritical("RTLSDRInput::applySettings: rtlsdr_set_tuner_gain() failed");
}
else
{
qDebug("RTLSDRInput::applySettings: rtlsdr_set_tuner_gain() to %d", m_settings.m_gain);
}
}
}
@ -491,7 +496,7 @@ int RTLSDRInput::webapiSettingsGet(
int RTLSDRInput::webapiSettingsPutPatch(
bool force,
SWGSDRangel::SWGDeviceSettings& response, // query + response
QString& errorMessage)
QString& errorMessage __attribute__((unused)))
{
RTLSDRSettings settings;
settings.m_agc = response.getRtlSdrSettings()->getAgc() != 0;
@ -508,19 +513,14 @@ int RTLSDRInput::webapiSettingsPutPatch(
settings.m_transverterDeltaFrequency = response.getRtlSdrSettings()->getTransverterDeltaFrequency();
settings.m_transverterMode = response.getRtlSdrSettings()->getTransverterMode() != 0;
if (applySettings(settings, force))
{
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureRTLSDR *msg = MsgConfigureRTLSDR::create(settings, force);
m_guiMessageQueue->push(msg);
}
MsgConfigureRTLSDR *msg = MsgConfigureRTLSDR::create(settings, force);
m_inputMessageQueue.push(msg);
return 200;
}
else
if (m_guiMessageQueue) // forward to GUI if any
{
errorMessage = "RTLSDRInput::webapiSettingsPutPatch: error applying settings";
return 500;
MsgConfigureRTLSDR *msgToGUI = MsgConfigureRTLSDR::create(settings, force);
m_guiMessageQueue->push(msgToGUI);
}
return 200;
}

View File

@ -758,7 +758,7 @@ bool WebAPIRequestMapper::validateDeviceSettings(SWGSDRangel::SWGDeviceSettings&
deviceSettings.setTx(0); // assume Rx
}
if (jsonObject.contains("deviceHwType")) {
if (jsonObject.contains("deviceHwType") && jsonObject["deviceHwType"].isString()) {
deviceSettings.setDeviceHwType(new QString(jsonObject["deviceHwType"].toString()));
} else {
return false;
@ -766,21 +766,65 @@ bool WebAPIRequestMapper::validateDeviceSettings(SWGSDRangel::SWGDeviceSettings&
QString *deviceHwType = deviceSettings.getDeviceHwType();
if (*deviceHwType == "FileSource") {
if (jsonObject.contains("fileSourceSettings")) {
if (*deviceHwType == "FileSource")
{
if (jsonObject.contains("fileSourceSettings") && jsonObject["fileSourceSettings"].isObject())
{
QJsonObject fileSourceSettingsJsonObject = jsonObject["fileSourceSettings"].toObject();
deviceSettings.setFileSourceSettings(new SWGSDRangel::SWGFileSourceSettings());
deviceSettings.getFileSourceSettings()->fromJsonObject(fileSourceSettingsJsonObject);
return true;
} else {
}
else
{
return false;
}
} 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;
}
else if (*deviceHwType == "RTLSDR")
{
if (jsonObject.contains("rtlSdrSettings") && jsonObject["rtlSdrSettings"].isObject())
{
QJsonObject rtlSdrSettingsJsonObject = jsonObject["rtlSdrSettings"].toObject();
deviceSettings.setRtlSdrSettings(new SWGSDRangel::SWGRtlSdrSettings());
deviceSettings.getRtlSdrSettings()->fromJsonObject(rtlSdrSettingsJsonObject);
return true;
}
else
{
return false;
}
}
else if ((*deviceHwType == "LimeSDR") && (deviceSettings.getTx() == 0))
{
if (jsonObject.contains("limeSdrInputSettings") && jsonObject["limeSdrInputSettings"].isObject())
{
QJsonObject limeSdrInputSettingsJsonObject = jsonObject["limeSdrInputSettings"].toObject();
deviceSettings.setLimeSdrInputSettings(new SWGSDRangel::SWGLimeSdrInputSettings());
deviceSettings.getLimeSdrInputSettings()->fromJsonObject(limeSdrInputSettingsJsonObject);
return true;
}
else
{
return false;
}
}
else if ((*deviceHwType == "LimeSDR") && (deviceSettings.getTx() != 0))
{
if (jsonObject.contains("limeSdrOutputSettings") && jsonObject["limeSdrOutputSettings"].isObject())
{
QJsonObject limeSdrOutputSettingsJsonObject = jsonObject["limeSdrOutputSettings"].toObject();
deviceSettings.setLimeSdrOutputSettings(new SWGSDRangel::SWGLimeSdrOutputSettings());
deviceSettings.getLimeSdrOutputSettings()->fromJsonObject(limeSdrOutputSettingsJsonObject);
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
import requests, json
base_url = "http://10.0.2.2:8091/sdrangel"
base_url = "http://127.0.0.1:8888/sdrangel"
requests_methods = {
"GET": requests.get,
@ -66,4 +66,4 @@ def main():
if __name__ == "__main__":
main()
main()