mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-08-03 06:22:25 -04:00
Web API: RTLSDR run implementation
This commit is contained in:
parent
37b1b045ac
commit
9c581107e8
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "SWGDeviceSettings.h"
|
#include "SWGDeviceSettings.h"
|
||||||
#include "SWGRtlSdrSettings.h"
|
#include "SWGRtlSdrSettings.h"
|
||||||
|
#include "SWGDeviceState.h"
|
||||||
|
|
||||||
#include "rtlsdrinput.h"
|
#include "rtlsdrinput.h"
|
||||||
#include "device/devicesourceapi.h"
|
#include "device/devicesourceapi.h"
|
||||||
@ -524,3 +525,26 @@ int RTLSDRInput::webapiSettingsPutPatch(
|
|||||||
|
|
||||||
return 200;
|
return 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int RTLSDRInput::webapiRun(
|
||||||
|
bool run,
|
||||||
|
SWGSDRangel::SWGDeviceState& response,
|
||||||
|
QString& errorMessage __attribute__((unused)))
|
||||||
|
{
|
||||||
|
if (run)
|
||||||
|
{
|
||||||
|
if (m_deviceAPI->initAcquisition())
|
||||||
|
{
|
||||||
|
m_deviceAPI->startAcquisition();
|
||||||
|
DSPEngine::instance()->startAudioOutput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_deviceAPI->stopAcquisition();
|
||||||
|
DSPEngine::instance()->stopAudioOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
@ -115,6 +115,11 @@ public:
|
|||||||
SWGSDRangel::SWGDeviceSettings& response, // query + response
|
SWGSDRangel::SWGDeviceSettings& response, // query + response
|
||||||
QString& errorMessage);
|
QString& errorMessage);
|
||||||
|
|
||||||
|
virtual int webapiRun(
|
||||||
|
bool run,
|
||||||
|
SWGSDRangel::SWGDeviceState& response,
|
||||||
|
QString& errorMessage);
|
||||||
|
|
||||||
const std::vector<int>& getGains() const { return m_gains; }
|
const std::vector<int>& getGains() const { return m_gains; }
|
||||||
void set_ds_mode(int on);
|
void set_ds_mode(int on);
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
namespace SWGSDRangel
|
namespace SWGSDRangel
|
||||||
{
|
{
|
||||||
class SWGDeviceSettings;
|
class SWGDeviceSettings;
|
||||||
|
class SWGDeviceState;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SDRANGEL_API DeviceSampleSink : public QObject {
|
class SDRANGEL_API DeviceSampleSink : public QObject {
|
||||||
@ -57,6 +58,11 @@ public:
|
|||||||
QString& errorMessage)
|
QString& errorMessage)
|
||||||
{ errorMessage = "Not implemented"; return 501; }
|
{ errorMessage = "Not implemented"; return 501; }
|
||||||
|
|
||||||
|
virtual int webapiRun(bool run __attribute__((unused)),
|
||||||
|
SWGSDRangel::SWGDeviceState& response __attribute__((unused)),
|
||||||
|
QString& errorMessage)
|
||||||
|
{ errorMessage = "Not implemented"; return 501; }
|
||||||
|
|
||||||
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
||||||
void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
||||||
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
namespace SWGSDRangel
|
namespace SWGSDRangel
|
||||||
{
|
{
|
||||||
class SWGDeviceSettings;
|
class SWGDeviceSettings;
|
||||||
|
class SWGDeviceState;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SDRANGEL_API DeviceSampleSource : public QObject {
|
class SDRANGEL_API DeviceSampleSource : public QObject {
|
||||||
@ -57,6 +58,11 @@ public:
|
|||||||
QString& errorMessage)
|
QString& errorMessage)
|
||||||
{ errorMessage = "Not implemented"; return 501; }
|
{ errorMessage = "Not implemented"; return 501; }
|
||||||
|
|
||||||
|
virtual int webapiRun(bool run __attribute__((unused)),
|
||||||
|
SWGSDRangel::SWGDeviceState& response __attribute__((unused)),
|
||||||
|
QString& errorMessage)
|
||||||
|
{ errorMessage = "Not implemented"; return 501; }
|
||||||
|
|
||||||
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
||||||
virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
||||||
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "SWGPresetTransfer.h"
|
#include "SWGPresetTransfer.h"
|
||||||
#include "SWGPresetIdentifier.h"
|
#include "SWGPresetIdentifier.h"
|
||||||
#include "SWGDeviceSettings.h"
|
#include "SWGDeviceSettings.h"
|
||||||
|
#include "SWGDeviceState.h"
|
||||||
#include "SWGErrorResponse.h"
|
#include "SWGErrorResponse.h"
|
||||||
|
|
||||||
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
|
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
|
||||||
@ -92,6 +93,8 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
|
|||||||
devicesetDeviceService(std::string(desc_match[1]), request, response);
|
devicesetDeviceService(std::string(desc_match[1]), request, response);
|
||||||
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceSettingsURLRe)) {
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceSettingsURLRe)) {
|
||||||
devicesetDeviceSettingsService(std::string(desc_match[1]), request, response);
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -697,6 +700,55 @@ void WebAPIRequestMapper::devicesetDeviceSettingsService(const std::string& inde
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebAPIRequestMapper::devicesetDeviceRunService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
||||||
|
{
|
||||||
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
|
||||||
|
|
||||||
|
if (request.getMethod() == "POST")
|
||||||
|
{
|
||||||
|
SWGSDRangel::SWGDeviceState normalResponse;
|
||||||
|
int status = m_adapter->devicesetDeviceRunPost(deviceSetIndex, normalResponse, errorResponse);
|
||||||
|
|
||||||
|
response.setStatus(status);
|
||||||
|
|
||||||
|
if (status == 200) {
|
||||||
|
response.write(normalResponse.asJson().toUtf8());
|
||||||
|
} else {
|
||||||
|
response.write(errorResponse.asJson().toUtf8());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (request.getMethod() == "DELETE")
|
||||||
|
{
|
||||||
|
SWGSDRangel::SWGDeviceState normalResponse;
|
||||||
|
int status = m_adapter->devicesetDeviceRunDelete(deviceSetIndex, 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 device set index";
|
||||||
|
response.setStatus(400,"Invalid data");
|
||||||
|
response.write(errorResponse.asJson().toUtf8());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool WebAPIRequestMapper::parseJsonBody(QString& jsonStr, QJsonObject& jsonObject, qtwebapp::HttpResponse& response)
|
bool WebAPIRequestMapper::parseJsonBody(QString& jsonStr, QJsonObject& jsonObject, qtwebapp::HttpResponse& response)
|
||||||
{
|
{
|
||||||
SWGSDRangel::SWGErrorResponse errorResponse;
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
||||||
|
@ -58,6 +58,7 @@ private:
|
|||||||
void devicesetService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
void devicesetService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||||
void devicesetDeviceService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
void devicesetDeviceService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||||
void devicesetDeviceSettingsService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
void devicesetDeviceSettingsService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||||
|
void devicesetDeviceRunService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||||
|
|
||||||
bool validatePresetTransfer(SWGSDRangel::SWGPresetTransfer& presetTransfer);
|
bool validatePresetTransfer(SWGSDRangel::SWGPresetTransfer& presetTransfer);
|
||||||
bool validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier);
|
bool validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier);
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
#include "SWGPresetTransfer.h"
|
#include "SWGPresetTransfer.h"
|
||||||
#include "SWGPresetIdentifier.h"
|
#include "SWGPresetIdentifier.h"
|
||||||
#include "SWGDeviceSettings.h"
|
#include "SWGDeviceSettings.h"
|
||||||
|
#include "SWGDeviceState.h"
|
||||||
#include "SWGErrorResponse.h"
|
#include "SWGErrorResponse.h"
|
||||||
|
|
||||||
#include "webapiadaptergui.h"
|
#include "webapiadaptergui.h"
|
||||||
@ -783,6 +784,75 @@ int WebAPIAdapterGUI::devicesetDeviceSettingsPutPatch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WebAPIAdapterGUI::devicesetDeviceRunPost(
|
||||||
|
int deviceSetIndex,
|
||||||
|
SWGSDRangel::SWGDeviceState& response,
|
||||||
|
SWGSDRangel::SWGErrorResponse& error)
|
||||||
|
{
|
||||||
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
||||||
|
{
|
||||||
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
||||||
|
|
||||||
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
||||||
|
{
|
||||||
|
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
|
||||||
|
return source->webapiRun(true, response, *error.getMessage());
|
||||||
|
}
|
||||||
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
||||||
|
{
|
||||||
|
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
|
||||||
|
return sink->webapiRun(true, response, *error.getMessage());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*error.getMessage() = QString("DeviceSet error");
|
||||||
|
return 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error.init();
|
||||||
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
||||||
|
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int WebAPIAdapterGUI::devicesetDeviceRunDelete(
|
||||||
|
int deviceSetIndex,
|
||||||
|
SWGSDRangel::SWGDeviceState& response,
|
||||||
|
SWGSDRangel::SWGErrorResponse& error)
|
||||||
|
{
|
||||||
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
||||||
|
{
|
||||||
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
||||||
|
|
||||||
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
||||||
|
{
|
||||||
|
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
|
||||||
|
return source->webapiRun(false, response, *error.getMessage());
|
||||||
|
}
|
||||||
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
||||||
|
{
|
||||||
|
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
|
||||||
|
return sink->webapiRun(false, response, *error.getMessage());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*error.getMessage() = QString("DeviceSet error");
|
||||||
|
return 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error.init();
|
||||||
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
||||||
|
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void WebAPIAdapterGUI::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList)
|
void WebAPIAdapterGUI::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList)
|
||||||
{
|
{
|
||||||
deviceSetList->init();
|
deviceSetList->init();
|
||||||
|
@ -131,6 +131,16 @@ public:
|
|||||||
SWGSDRangel::SWGDeviceSettings& response,
|
SWGSDRangel::SWGDeviceSettings& response,
|
||||||
SWGSDRangel::SWGErrorResponse& error);
|
SWGSDRangel::SWGErrorResponse& error);
|
||||||
|
|
||||||
|
virtual int devicesetDeviceRunPost(
|
||||||
|
int deviceSetIndex,
|
||||||
|
SWGSDRangel::SWGDeviceState& response,
|
||||||
|
SWGSDRangel::SWGErrorResponse& error);
|
||||||
|
|
||||||
|
virtual int devicesetDeviceRunDelete(
|
||||||
|
int deviceSetIndex,
|
||||||
|
SWGSDRangel::SWGDeviceState& response,
|
||||||
|
SWGSDRangel::SWGErrorResponse& error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MainWindow& m_mainWindow;
|
MainWindow& m_mainWindow;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user