mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-12-23 10:05:46 -05:00
Web API: implemented /sdrange/devices: Get a list of sampling devices that can be used to take part in a device set
This commit is contained in:
parent
09dc5913c7
commit
2ac9a82b02
@ -39,6 +39,8 @@ public:
|
||||
void changeTxSelection(int tabIndex, int deviceIndex);
|
||||
void removeRxSelection(int tabIndex);
|
||||
void removeTxSelection(int tabIndex);
|
||||
int getNbRxSamplingDevices() const { return m_rxEnumeration.size(); }
|
||||
int getNbTxSamplingDevices() const { return m_txEnumeration.size(); }
|
||||
PluginInterface::SamplingDevice getRxSamplingDevice(int deviceIndex) const { return m_rxEnumeration[deviceIndex].m_samplingDevice; }
|
||||
PluginInterface::SamplingDevice getTxSamplingDevice(int deviceIndex) const { return m_txEnumeration[deviceIndex].m_samplingDevice; }
|
||||
PluginInterface *getRxPluginInterface(int deviceIndex) { return m_rxEnumeration[deviceIndex].m_pluginInterface; }
|
||||
|
@ -19,4 +19,5 @@
|
||||
#include "webapiadapterinterface.h"
|
||||
|
||||
QString WebAPIAdapterInterface::instanceSummaryURL = "/sdrangel";
|
||||
QString WebAPIAdapterInterface::instanceDevicesURL = "/sdrangel/devices";
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
namespace Swagger
|
||||
{
|
||||
class SWGInstanceSummaryResponse;
|
||||
class SWGInstanceDevicesResponse;
|
||||
class SWGErrorResponse;
|
||||
}
|
||||
|
||||
@ -41,7 +42,18 @@ public:
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
/**
|
||||
* Handler of /sdrangel/devices (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceDevices
|
||||
* returns the Http status code (default 501: not implemented)
|
||||
*/
|
||||
virtual int instanceDevices(
|
||||
bool tx __attribute__((unused)),
|
||||
Swagger::SWGInstanceDevicesResponse& response __attribute__((unused)),
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
static QString instanceSummaryURL;
|
||||
static QString instanceDevicesURL;
|
||||
};
|
||||
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "httpdocrootsettings.h"
|
||||
#include "webapirequestmapper.h"
|
||||
#include "SWGInstanceSummaryResponse.h"
|
||||
#include "SWGInstanceDevicesResponse.h"
|
||||
#include "SWGErrorResponse.h"
|
||||
|
||||
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
|
||||
@ -71,6 +72,32 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
|
||||
response.setStatus(405,"Invalid HTTP method");
|
||||
}
|
||||
}
|
||||
else if (path == WebAPIAdapterInterface::instanceDevicesURL)
|
||||
{
|
||||
Swagger::SWGInstanceDevicesResponse normalResponse;
|
||||
Swagger::SWGErrorResponse errorResponse;
|
||||
|
||||
if (request.getMethod() == "GET")
|
||||
{
|
||||
QByteArray txStr = request.getParameter("tx");
|
||||
bool tx = (txStr == "true");
|
||||
|
||||
int status = m_adapter->instanceDevices(tx, normalResponse, errorResponse);
|
||||
|
||||
if (status == 200) {
|
||||
response.write(normalResponse.asJson().toUtf8());
|
||||
} else {
|
||||
response.write(errorResponse.asJson().toUtf8());
|
||||
}
|
||||
|
||||
response.setStatus(status);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.write("Invalid HTTP method");
|
||||
response.setStatus(405,"Invalid HTTP method");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// QDirIterator it(":", QDirIterator::Subdirectories);
|
||||
|
@ -17,18 +17,22 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QApplication>
|
||||
#include <QList>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "loggerwithfile.h"
|
||||
#include "device/devicesourceapi.h"
|
||||
#include "device/devicesinkapi.h"
|
||||
#include "device/deviceuiset.h"
|
||||
#include "device/deviceenumerator.h"
|
||||
#include "dsp/devicesamplesource.h"
|
||||
#include "dsp/devicesamplesink.h"
|
||||
#include "channel/channelsinkapi.h"
|
||||
#include "channel/channelsourceapi.h"
|
||||
|
||||
#include "SWGInstanceSummaryResponse.h"
|
||||
#include "SWGInstanceDevicesResponse.h"
|
||||
#include "SWGDeviceListItem.h"
|
||||
#include "SWGErrorResponse.h"
|
||||
|
||||
#include "webapiadaptergui.h"
|
||||
@ -137,4 +141,27 @@ int WebAPIAdapterGUI::instanceSummary(
|
||||
return 200;
|
||||
}
|
||||
|
||||
int WebAPIAdapterGUI::instanceDevices(
|
||||
bool tx,
|
||||
Swagger::SWGInstanceDevicesResponse& response,
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{
|
||||
int nbSamplingDevices = tx ? DeviceEnumerator::instance()->getNbTxSamplingDevices() : DeviceEnumerator::instance()->getNbRxSamplingDevices();
|
||||
response.setDevicecount(nbSamplingDevices);
|
||||
QList<Swagger::SWGDeviceListItem*> *devices = response.getDevices();
|
||||
|
||||
for (int i = 0; i < nbSamplingDevices; i++)
|
||||
{
|
||||
PluginInterface::SamplingDevice samplingDevice = tx ? DeviceEnumerator::instance()->getTxSamplingDevice(i) : DeviceEnumerator::instance()->getRxSamplingDevice(i);
|
||||
devices->append(new Swagger::SWGDeviceListItem);
|
||||
*devices->back()->getDisplayedName() = samplingDevice.displayedName;
|
||||
*devices->back()->getHwType() = samplingDevice.hardwareId;
|
||||
*devices->back()->getSerial() = samplingDevice.serial;
|
||||
devices->back()->setSequence(samplingDevice.sequence);
|
||||
devices->back()->setTx(!samplingDevice.rxElseTx);
|
||||
devices->back()->setNbStreams(samplingDevice.deviceNbItems);
|
||||
devices->back()->setDeviceSetIndex(samplingDevice.claimed);
|
||||
}
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
@ -33,6 +33,11 @@ public:
|
||||
Swagger::SWGInstanceSummaryResponse& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
virtual int instanceDevices(
|
||||
bool tx,
|
||||
Swagger::SWGInstanceDevicesResponse& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
private:
|
||||
MainWindow& m_mainWindow;
|
||||
};
|
||||
|
@ -482,13 +482,20 @@ definitions:
|
||||
description: "Summarized information about attached hardware device"
|
||||
required:
|
||||
- hwType
|
||||
- streamIndex
|
||||
- sequence
|
||||
- serial
|
||||
|
||||
properties:
|
||||
displayedName:
|
||||
description: "Displayable name that uniquely identifies this device instance"
|
||||
type: string
|
||||
hwType:
|
||||
description: "Key to identify the type of hardware device"
|
||||
type: string
|
||||
serial:
|
||||
description: "Serial number of the hardware device"
|
||||
type: string
|
||||
sequence:
|
||||
description: "Sequence in the enumeration of same device types"
|
||||
type: integer
|
||||
tx:
|
||||
description: "Set to true if this is a Tx device"
|
||||
type: boolean
|
||||
@ -498,12 +505,9 @@ definitions:
|
||||
streamIndex:
|
||||
description: "Index of the channel in the device"
|
||||
type: integer
|
||||
sequence:
|
||||
description: "Sequence in the enumeration of same device types"
|
||||
deviceSetIndex:
|
||||
description: "Index of the device set that claimed this device (-1 if not claimed)"
|
||||
type: integer
|
||||
serial:
|
||||
description: "Serial number of the hardware device"
|
||||
type: string
|
||||
ChannelListItem:
|
||||
description: "Summarized information about channel plugin"
|
||||
required:
|
||||
|
@ -37,28 +37,35 @@ SWGDeviceListItem::~SWGDeviceListItem() {
|
||||
|
||||
void
|
||||
SWGDeviceListItem::init() {
|
||||
displayed_name = new QString("");
|
||||
hw_type = new QString("");
|
||||
serial = new QString("");
|
||||
sequence = 0;
|
||||
tx = false;
|
||||
nb_streams = 0;
|
||||
stream_index = 0;
|
||||
sequence = 0;
|
||||
serial = new QString("");
|
||||
device_set_index = 0;
|
||||
}
|
||||
|
||||
void
|
||||
SWGDeviceListItem::cleanup() {
|
||||
|
||||
if(displayed_name != nullptr) {
|
||||
delete displayed_name;
|
||||
}
|
||||
|
||||
if(hw_type != nullptr) {
|
||||
delete hw_type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(serial != nullptr) {
|
||||
delete serial;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
SWGDeviceListItem*
|
||||
@ -72,12 +79,14 @@ SWGDeviceListItem::fromJson(QString &json) {
|
||||
|
||||
void
|
||||
SWGDeviceListItem::fromJsonObject(QJsonObject &pJson) {
|
||||
::Swagger::setValue(&displayed_name, pJson["displayedName"], "QString", "QString");
|
||||
::Swagger::setValue(&hw_type, pJson["hwType"], "QString", "QString");
|
||||
::Swagger::setValue(&serial, pJson["serial"], "QString", "QString");
|
||||
::Swagger::setValue(&sequence, pJson["sequence"], "qint32", "");
|
||||
::Swagger::setValue(&tx, pJson["tx"], "bool", "");
|
||||
::Swagger::setValue(&nb_streams, pJson["nbStreams"], "qint32", "");
|
||||
::Swagger::setValue(&stream_index, pJson["streamIndex"], "qint32", "");
|
||||
::Swagger::setValue(&sequence, pJson["sequence"], "qint32", "");
|
||||
::Swagger::setValue(&serial, pJson["serial"], "QString", "QString");
|
||||
::Swagger::setValue(&device_set_index, pJson["deviceSetIndex"], "qint32", "");
|
||||
}
|
||||
|
||||
QString
|
||||
@ -94,21 +103,34 @@ QJsonObject*
|
||||
SWGDeviceListItem::asJsonObject() {
|
||||
QJsonObject* obj = new QJsonObject();
|
||||
|
||||
toJsonValue(QString("displayedName"), displayed_name, obj, QString("QString"));
|
||||
|
||||
toJsonValue(QString("hwType"), hw_type, obj, QString("QString"));
|
||||
|
||||
toJsonValue(QString("serial"), serial, obj, QString("QString"));
|
||||
|
||||
obj->insert("sequence", QJsonValue(sequence));
|
||||
|
||||
obj->insert("tx", QJsonValue(tx));
|
||||
|
||||
obj->insert("nbStreams", QJsonValue(nb_streams));
|
||||
|
||||
obj->insert("streamIndex", QJsonValue(stream_index));
|
||||
|
||||
obj->insert("sequence", QJsonValue(sequence));
|
||||
|
||||
toJsonValue(QString("serial"), serial, obj, QString("QString"));
|
||||
obj->insert("deviceSetIndex", QJsonValue(device_set_index));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
QString*
|
||||
SWGDeviceListItem::getDisplayedName() {
|
||||
return displayed_name;
|
||||
}
|
||||
void
|
||||
SWGDeviceListItem::setDisplayedName(QString* displayed_name) {
|
||||
this->displayed_name = displayed_name;
|
||||
}
|
||||
|
||||
QString*
|
||||
SWGDeviceListItem::getHwType() {
|
||||
return hw_type;
|
||||
@ -118,6 +140,24 @@ SWGDeviceListItem::setHwType(QString* hw_type) {
|
||||
this->hw_type = hw_type;
|
||||
}
|
||||
|
||||
QString*
|
||||
SWGDeviceListItem::getSerial() {
|
||||
return serial;
|
||||
}
|
||||
void
|
||||
SWGDeviceListItem::setSerial(QString* serial) {
|
||||
this->serial = serial;
|
||||
}
|
||||
|
||||
qint32
|
||||
SWGDeviceListItem::getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
void
|
||||
SWGDeviceListItem::setSequence(qint32 sequence) {
|
||||
this->sequence = sequence;
|
||||
}
|
||||
|
||||
bool
|
||||
SWGDeviceListItem::getTx() {
|
||||
return tx;
|
||||
@ -146,21 +186,12 @@ SWGDeviceListItem::setStreamIndex(qint32 stream_index) {
|
||||
}
|
||||
|
||||
qint32
|
||||
SWGDeviceListItem::getSequence() {
|
||||
return sequence;
|
||||
SWGDeviceListItem::getDeviceSetIndex() {
|
||||
return device_set_index;
|
||||
}
|
||||
void
|
||||
SWGDeviceListItem::setSequence(qint32 sequence) {
|
||||
this->sequence = sequence;
|
||||
}
|
||||
|
||||
QString*
|
||||
SWGDeviceListItem::getSerial() {
|
||||
return serial;
|
||||
}
|
||||
void
|
||||
SWGDeviceListItem::setSerial(QString* serial) {
|
||||
this->serial = serial;
|
||||
SWGDeviceListItem::setDeviceSetIndex(qint32 device_set_index) {
|
||||
this->device_set_index = device_set_index;
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,9 +42,18 @@ public:
|
||||
void fromJsonObject(QJsonObject &json);
|
||||
SWGDeviceListItem* fromJson(QString &jsonString);
|
||||
|
||||
QString* getDisplayedName();
|
||||
void setDisplayedName(QString* displayed_name);
|
||||
|
||||
QString* getHwType();
|
||||
void setHwType(QString* hw_type);
|
||||
|
||||
QString* getSerial();
|
||||
void setSerial(QString* serial);
|
||||
|
||||
qint32 getSequence();
|
||||
void setSequence(qint32 sequence);
|
||||
|
||||
bool getTx();
|
||||
void setTx(bool tx);
|
||||
|
||||
@ -54,20 +63,19 @@ public:
|
||||
qint32 getStreamIndex();
|
||||
void setStreamIndex(qint32 stream_index);
|
||||
|
||||
qint32 getSequence();
|
||||
void setSequence(qint32 sequence);
|
||||
|
||||
QString* getSerial();
|
||||
void setSerial(QString* serial);
|
||||
qint32 getDeviceSetIndex();
|
||||
void setDeviceSetIndex(qint32 device_set_index);
|
||||
|
||||
|
||||
private:
|
||||
QString* displayed_name;
|
||||
QString* hw_type;
|
||||
QString* serial;
|
||||
qint32 sequence;
|
||||
bool tx;
|
||||
qint32 nb_streams;
|
||||
qint32 stream_index;
|
||||
qint32 sequence;
|
||||
QString* serial;
|
||||
qint32 device_set_index;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user