1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-01 13:47:01 -04:00

Web API: /sdrangel/deviceset/{deviceSetIndex}/channel/{channelIndex}/settings GET for NFM demod and mod

This commit is contained in:
f4exb
2017-12-10 20:27:08 +01:00
parent 0667c5b479
commit 2dd82e9eca
46 changed files with 7400 additions and 44 deletions
+51
View File
@@ -36,6 +36,7 @@
#include "SWGPresetIdentifier.h"
#include "SWGDeviceSettings.h"
#include "SWGDeviceState.h"
#include "SWGChannelSettings.h"
#include "SWGErrorResponse.h"
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
@@ -95,6 +96,8 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
devicesetDeviceSettingsService(std::string(desc_match[1]), request, response);
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceRunURLRe)) {
devicesetDeviceRunService(std::string(desc_match[1]), request, response);
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetChannelSettingsURLRe)) {
devicesetChannelSettingsService(std::string(desc_match[1]), std::string(desc_match[2]), request, response);
}
else
{
@@ -762,6 +765,47 @@ void WebAPIRequestMapper::devicesetDeviceRunService(const std::string& indexStr,
}
}
void WebAPIRequestMapper::devicesetChannelSettingsService(
const std::string& deviceSetIndexStr,
const std::string& channelIndexStr,
qtwebapp::HttpRequest& request,
qtwebapp::HttpResponse& response)
{
SWGSDRangel::SWGErrorResponse errorResponse;
try
{
int deviceSetIndex = boost::lexical_cast<int>(deviceSetIndexStr);
int channelIndex = boost::lexical_cast<int>(channelIndexStr);
if (request.getMethod() == "GET")
{
SWGSDRangel::SWGChannelSettings normalResponse;
resetChannelSettings(normalResponse);
int status = m_adapter->devicesetChannelSettingsGet(deviceSetIndex, channelIndex, normalResponse, errorResponse);
response.setStatus(status);
if (status == 200) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else
{
response.setStatus(405,"Invalid HTTP method");
response.write("Invalid HTTP method");
}
}
catch (const boost::bad_lexical_cast &e)
{
errorResponse.init();
*errorResponse.getMessage() = "Wrong integer conversion on index";
response.setStatus(400,"Invalid data");
response.write(errorResponse.asJson().toUtf8());
}
}
bool WebAPIRequestMapper::parseJsonBody(QString& jsonStr, QJsonObject& jsonObject, qtwebapp::HttpResponse& response)
{
SWGSDRangel::SWGErrorResponse errorResponse;
@@ -902,3 +946,10 @@ void WebAPIRequestMapper::resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& de
deviceSettings.setLimeSdrOutputSettings(0);
}
void WebAPIRequestMapper::resetChannelSettings(SWGSDRangel::SWGChannelSettings& channelSettings)
{
channelSettings.cleanup();
channelSettings.setNfmDemodSettings(0);
channelSettings.setNfmModSettings(0);
}