1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-20 20:06:57 -04:00

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) 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 else
{ {
qDebug("RTLSDRInput::applySettings: AGC mode %s", settings.m_agc ? "on" : "off");
m_settings.m_agc = settings.m_agc; m_settings.m_agc = settings.m_agc;
} }
} }
@ -303,7 +304,11 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force)
{ {
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( int RTLSDRInput::webapiSettingsPutPatch(
bool force, bool force,
SWGSDRangel::SWGDeviceSettings& response, // query + response SWGSDRangel::SWGDeviceSettings& response, // query + response
QString& errorMessage) QString& errorMessage __attribute__((unused)))
{ {
RTLSDRSettings settings; RTLSDRSettings settings;
settings.m_agc = response.getRtlSdrSettings()->getAgc() != 0; settings.m_agc = response.getRtlSdrSettings()->getAgc() != 0;
@ -508,19 +513,14 @@ int RTLSDRInput::webapiSettingsPutPatch(
settings.m_transverterDeltaFrequency = response.getRtlSdrSettings()->getTransverterDeltaFrequency(); settings.m_transverterDeltaFrequency = response.getRtlSdrSettings()->getTransverterDeltaFrequency();
settings.m_transverterMode = response.getRtlSdrSettings()->getTransverterMode() != 0; settings.m_transverterMode = response.getRtlSdrSettings()->getTransverterMode() != 0;
if (applySettings(settings, force)) MsgConfigureRTLSDR *msg = MsgConfigureRTLSDR::create(settings, force);
{ m_inputMessageQueue.push(msg);
if (m_guiMessageQueue) // forward to GUI if any if (m_guiMessageQueue) // forward to GUI if any
{ {
MsgConfigureRTLSDR *msg = MsgConfigureRTLSDR::create(settings, force); MsgConfigureRTLSDR *msgToGUI = MsgConfigureRTLSDR::create(settings, force);
m_guiMessageQueue->push(msg); m_guiMessageQueue->push(msgToGUI);
} }
return 200; return 200;
} }
else
{
errorMessage = "RTLSDRInput::webapiSettingsPutPatch: error applying settings";
return 500;
}
}

View File

@ -758,7 +758,7 @@ bool WebAPIRequestMapper::validateDeviceSettings(SWGSDRangel::SWGDeviceSettings&
deviceSettings.setTx(0); // assume Rx deviceSettings.setTx(0); // assume Rx
} }
if (jsonObject.contains("deviceHwType")) { if (jsonObject.contains("deviceHwType") && jsonObject["deviceHwType"].isString()) {
deviceSettings.setDeviceHwType(new QString(jsonObject["deviceHwType"].toString())); deviceSettings.setDeviceHwType(new QString(jsonObject["deviceHwType"].toString()));
} else { } else {
return false; return false;
@ -766,21 +766,65 @@ bool WebAPIRequestMapper::validateDeviceSettings(SWGSDRangel::SWGDeviceSettings&
QString *deviceHwType = deviceSettings.getDeviceHwType(); QString *deviceHwType = deviceSettings.getDeviceHwType();
if (*deviceHwType == "FileSource") { if (*deviceHwType == "FileSource")
if (jsonObject.contains("fileSourceSettings")) { {
if (jsonObject.contains("fileSourceSettings") && jsonObject["fileSourceSettings"].isObject())
{
QJsonObject fileSourceSettingsJsonObject = jsonObject["fileSourceSettings"].toObject();
deviceSettings.setFileSourceSettings(new SWGSDRangel::SWGFileSourceSettings()); deviceSettings.setFileSourceSettings(new SWGSDRangel::SWGFileSourceSettings());
deviceSettings.getFileSourceSettings()->fromJsonObject(fileSourceSettingsJsonObject);
return true; return true;
} else { }
else
{
return false; 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 #!/usr/bin/env python
import requests, json import requests, json
base_url = "http://10.0.2.2:8091/sdrangel" base_url = "http://127.0.0.1:8888/sdrangel"
requests_methods = { requests_methods = {
"GET": requests.get, "GET": requests.get,