kopia lustrzana https://github.com/f4exb/sdrangel
Web API: implement devicesetDeviceGet (1)
rodzic
a3fb30107b
commit
7dafae3fa1
|
@ -41,6 +41,11 @@ public:
|
|||
|
||||
virtual bool handleMessage(const Message& message) = 0;
|
||||
|
||||
virtual int webapiSettingsGet(
|
||||
SWGSDRangel::SWGObject *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; }
|
||||
|
|
|
@ -1,58 +1,63 @@
|
|||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2015 F4EXB //
|
||||
// written by Edouard Griffiths //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_SAMPLESOURCE_H
|
||||
#define INCLUDE_SAMPLESOURCE_H
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "samplesinkfifo.h"
|
||||
#include "util/message.h"
|
||||
#include "util/messagequeue.h"
|
||||
#include "util/export.h"
|
||||
|
||||
class SDRANGEL_API DeviceSampleSource : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DeviceSampleSource();
|
||||
virtual ~DeviceSampleSource();
|
||||
virtual void destroy() = 0;
|
||||
|
||||
virtual bool start() = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
virtual const QString& getDeviceDescription() const = 0;
|
||||
virtual int getSampleRate() const = 0; //!< Sample rate exposed by the source
|
||||
virtual quint64 getCenterFrequency() const = 0; //!< Center frequency exposed by the source
|
||||
|
||||
virtual bool handleMessage(const Message& message) = 0;
|
||||
|
||||
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
||||
virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
||||
MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; }
|
||||
SampleSinkFifo* getSampleFifo() { return &m_sampleFifo; }
|
||||
|
||||
protected slots:
|
||||
void handleInputMessages();
|
||||
|
||||
protected:
|
||||
SampleSinkFifo m_sampleFifo;
|
||||
MessageQueue m_inputMessageQueue; //!< Input queue to the source
|
||||
MessageQueue *m_guiMessageQueue; //!< Input message queue to the GUI
|
||||
};
|
||||
|
||||
#endif // INCLUDE_SAMPLESOURCE_H
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2015 F4EXB //
|
||||
// written by Edouard Griffiths //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_SAMPLESOURCE_H
|
||||
#define INCLUDE_SAMPLESOURCE_H
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "samplesinkfifo.h"
|
||||
#include "util/message.h"
|
||||
#include "util/messagequeue.h"
|
||||
#include "util/export.h"
|
||||
|
||||
class SDRANGEL_API DeviceSampleSource : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DeviceSampleSource();
|
||||
virtual ~DeviceSampleSource();
|
||||
virtual void destroy() = 0;
|
||||
|
||||
virtual bool start() = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
virtual const QString& getDeviceDescription() const = 0;
|
||||
virtual int getSampleRate() const = 0; //!< Sample rate exposed by the source
|
||||
virtual quint64 getCenterFrequency() const = 0; //!< Center frequency exposed by the source
|
||||
|
||||
virtual bool handleMessage(const Message& message) = 0;
|
||||
|
||||
virtual int webapiSettingsGet(
|
||||
SWGSDRangel::SWGObject *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; }
|
||||
SampleSinkFifo* getSampleFifo() { return &m_sampleFifo; }
|
||||
|
||||
protected slots:
|
||||
void handleInputMessages();
|
||||
|
||||
protected:
|
||||
SampleSinkFifo m_sampleFifo;
|
||||
MessageQueue m_inputMessageQueue; //!< Input queue to the source
|
||||
MessageQueue *m_guiMessageQueue; //!< Input message queue to the GUI
|
||||
};
|
||||
|
||||
#endif // INCLUDE_SAMPLESOURCE_H
|
||||
|
|
|
@ -226,7 +226,7 @@ public:
|
|||
{ return 501; }
|
||||
|
||||
/**
|
||||
* Handler of /sdrangel/devicesets (DELETE) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* Handler of /sdrangel/deviceset/{devicesetIndex}/device (PUT) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* returns the Http status code (default 501: not implemented)
|
||||
*/
|
||||
virtual int devicesetDevicePut(
|
||||
|
@ -235,6 +235,16 @@ public:
|
|||
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
/**
|
||||
* Handler of /sdrangel/deviceset/{devicesetIndex}/device (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* returns the Http status code (default 501: not implemented)
|
||||
*/
|
||||
virtual int devicesetDeviceGet(
|
||||
int deviceSetIndex __attribute__((unused)),
|
||||
SWGSDRangel::SWGDeviceSettings& response __attribute__((unused)),
|
||||
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
static QString instanceSummaryURL;
|
||||
static QString instanceDevicesURL;
|
||||
static QString instanceChannelsURL;
|
||||
|
|
|
@ -86,9 +86,9 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
|
|||
std::string pathStr(path.constData(), path.length());
|
||||
|
||||
if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetURLRe)) {
|
||||
deviceset(std::string(desc_match[1]), request, response);
|
||||
devicesetService(std::string(desc_match[1]), request, response);
|
||||
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceURLRe)) {
|
||||
devicesetDevice(std::string(desc_match[1]), request, response);
|
||||
devicesetDeviceService(std::string(desc_match[1]), request, response);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -539,7 +539,7 @@ void WebAPIRequestMapper::instanceDeviceSetsService(qtwebapp::HttpRequest& reque
|
|||
}
|
||||
}
|
||||
|
||||
void WebAPIRequestMapper::deviceset(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
||||
void WebAPIRequestMapper::devicesetService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
||||
{
|
||||
SWGSDRangel::SWGErrorResponse errorResponse;
|
||||
|
||||
|
@ -573,7 +573,7 @@ void WebAPIRequestMapper::deviceset(const std::string& indexStr, qtwebapp::HttpR
|
|||
}
|
||||
}
|
||||
|
||||
void WebAPIRequestMapper::devicesetDevice(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
||||
void WebAPIRequestMapper::devicesetDeviceService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
||||
{
|
||||
SWGSDRangel::SWGErrorResponse errorResponse;
|
||||
|
||||
|
@ -600,6 +600,18 @@ void WebAPIRequestMapper::devicesetDevice(const std::string& indexStr, qtwebapp:
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (request.getMethod() == "GET")
|
||||
{
|
||||
SWGSDRangel::SWGDeviceSettings normalResponse;
|
||||
int status = m_adapter->devicesetDeviceGet(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");
|
||||
|
|
|
@ -55,8 +55,8 @@ private:
|
|||
void instancePresetService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
void instanceDeviceSetsService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
|
||||
void deviceset(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
|
||||
void devicesetDevice(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);
|
||||
|
||||
bool validatePresetTransfer(SWGSDRangel::SWGPresetTransfer& presetTransfer);
|
||||
bool validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier);
|
||||
|
|
|
@ -693,6 +693,48 @@ int WebAPIAdapterGUI::devicesetDevicePut(
|
|||
}
|
||||
}
|
||||
|
||||
int WebAPIAdapterGUI::devicesetDeviceGet(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGDeviceSettings& response,
|
||||
SWGSDRangel::SWGErrorResponse& error)
|
||||
{
|
||||
if ((deviceSetIndex >= 0) && (m_mainWindow.m_deviceUIs < (int) m_mainWindow.m_deviceUIs.size()))
|
||||
{
|
||||
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
||||
int tx = response.getTx();
|
||||
|
||||
if ((tx == 0) && (deviceSet->m_deviceSinkEngine))
|
||||
{
|
||||
*error.getMessage() = QString("Device type (Rx) and device set type (Tx) mismatch");
|
||||
return 404;
|
||||
}
|
||||
|
||||
if ((tx != 0) && (deviceSet->m_deviceSourceEngine))
|
||||
{
|
||||
*error.getMessage() = QString("Device type (Tx) and device set type (Rx) mismatch");
|
||||
return 404;
|
||||
}
|
||||
|
||||
if (tx == 0) // Rx
|
||||
{
|
||||
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
|
||||
return source->webapiSettingsGet(response.getData(), *error.getMessage());
|
||||
}
|
||||
else // Tx
|
||||
{
|
||||
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
|
||||
return sink->webapiSettingsGet(response.getData(), *error.getMessage());
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
|
|
@ -120,6 +120,11 @@ public:
|
|||
SWGSDRangel::SWGDeviceListItem& response,
|
||||
SWGSDRangel::SWGErrorResponse& error);
|
||||
|
||||
virtual int devicesetDeviceGet(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGDeviceSettings& response,
|
||||
SWGSDRangel::SWGErrorResponse& error);
|
||||
|
||||
private:
|
||||
MainWindow& m_mainWindow;
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue