kopia lustrzana https://github.com/f4exb/sdrangel
Web API: RTLSDR run implementation
rodzic
37b1b045ac
commit
9c581107e8
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGRtlSdrSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "rtlsdrinput.h"
|
||||
#include "device/devicesourceapi.h"
|
||||
|
@ -524,3 +525,26 @@ int RTLSDRInput::webapiSettingsPutPatch(
|
|||
|
||||
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
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
const std::vector<int>& getGains() const { return m_gains; }
|
||||
void set_ds_mode(int on);
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
namespace SWGSDRangel
|
||||
{
|
||||
class SWGDeviceSettings;
|
||||
class SWGDeviceState;
|
||||
}
|
||||
|
||||
class SDRANGEL_API DeviceSampleSink : public QObject {
|
||||
|
@ -57,6 +58,11 @@ public:
|
|||
QString& errorMessage)
|
||||
{ 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; }
|
||||
void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
||||
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
namespace SWGSDRangel
|
||||
{
|
||||
class SWGDeviceSettings;
|
||||
class SWGDeviceState;
|
||||
}
|
||||
|
||||
class SDRANGEL_API DeviceSampleSource : public QObject {
|
||||
|
@ -57,6 +58,11 @@ public:
|
|||
QString& errorMessage)
|
||||
{ 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; }
|
||||
virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
||||
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "SWGPresetTransfer.h"
|
||||
#include "SWGPresetIdentifier.h"
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
#include "SWGErrorResponse.h"
|
||||
|
||||
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
|
||||
|
@ -92,6 +93,8 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
|
|||
devicesetDeviceService(std::string(desc_match[1]), request, response);
|
||||
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceSettingsURLRe)) {
|
||||
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
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
SWGSDRangel::SWGErrorResponse errorResponse;
|
||||
|
|
|
@ -58,6 +58,7 @@ private:
|
|||
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 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 validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier);
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "SWGPresetTransfer.h"
|
||||
#include "SWGPresetIdentifier.h"
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
#include "SWGErrorResponse.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)
|
||||
{
|
||||
deviceSetList->init();
|
||||
|
|
|
@ -131,6 +131,16 @@ public:
|
|||
SWGSDRangel::SWGDeviceSettings& response,
|
||||
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:
|
||||
MainWindow& m_mainWindow;
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue