mirror of https://github.com/f4exb/sdrangel.git
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 changeTxSelection(int tabIndex, int deviceIndex);
|
||||||
void removeRxSelection(int tabIndex);
|
void removeRxSelection(int tabIndex);
|
||||||
void removeTxSelection(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 getRxSamplingDevice(int deviceIndex) const { return m_rxEnumeration[deviceIndex].m_samplingDevice; }
|
||||||
PluginInterface::SamplingDevice getTxSamplingDevice(int deviceIndex) const { return m_txEnumeration[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; }
|
PluginInterface *getRxPluginInterface(int deviceIndex) { return m_rxEnumeration[deviceIndex].m_pluginInterface; }
|
||||||
|
|
|
@ -19,4 +19,5 @@
|
||||||
#include "webapiadapterinterface.h"
|
#include "webapiadapterinterface.h"
|
||||||
|
|
||||||
QString WebAPIAdapterInterface::instanceSummaryURL = "/sdrangel";
|
QString WebAPIAdapterInterface::instanceSummaryURL = "/sdrangel";
|
||||||
|
QString WebAPIAdapterInterface::instanceDevicesURL = "/sdrangel/devices";
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
namespace Swagger
|
namespace Swagger
|
||||||
{
|
{
|
||||||
class SWGInstanceSummaryResponse;
|
class SWGInstanceSummaryResponse;
|
||||||
|
class SWGInstanceDevicesResponse;
|
||||||
class SWGErrorResponse;
|
class SWGErrorResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +42,18 @@ public:
|
||||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||||
{ return 501; }
|
{ 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 instanceSummaryURL;
|
||||||
|
static QString instanceDevicesURL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "httpdocrootsettings.h"
|
#include "httpdocrootsettings.h"
|
||||||
#include "webapirequestmapper.h"
|
#include "webapirequestmapper.h"
|
||||||
#include "SWGInstanceSummaryResponse.h"
|
#include "SWGInstanceSummaryResponse.h"
|
||||||
|
#include "SWGInstanceDevicesResponse.h"
|
||||||
#include "SWGErrorResponse.h"
|
#include "SWGErrorResponse.h"
|
||||||
|
|
||||||
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
|
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
|
||||||
|
@ -71,6 +72,32 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
|
||||||
response.setStatus(405,"Invalid HTTP method");
|
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
|
else
|
||||||
{
|
{
|
||||||
// QDirIterator it(":", QDirIterator::Subdirectories);
|
// QDirIterator it(":", QDirIterator::Subdirectories);
|
||||||
|
|
|
@ -17,18 +17,22 @@
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "loggerwithfile.h"
|
#include "loggerwithfile.h"
|
||||||
#include "device/devicesourceapi.h"
|
#include "device/devicesourceapi.h"
|
||||||
#include "device/devicesinkapi.h"
|
#include "device/devicesinkapi.h"
|
||||||
#include "device/deviceuiset.h"
|
#include "device/deviceuiset.h"
|
||||||
|
#include "device/deviceenumerator.h"
|
||||||
#include "dsp/devicesamplesource.h"
|
#include "dsp/devicesamplesource.h"
|
||||||
#include "dsp/devicesamplesink.h"
|
#include "dsp/devicesamplesink.h"
|
||||||
#include "channel/channelsinkapi.h"
|
#include "channel/channelsinkapi.h"
|
||||||
#include "channel/channelsourceapi.h"
|
#include "channel/channelsourceapi.h"
|
||||||
|
|
||||||
#include "SWGInstanceSummaryResponse.h"
|
#include "SWGInstanceSummaryResponse.h"
|
||||||
|
#include "SWGInstanceDevicesResponse.h"
|
||||||
|
#include "SWGDeviceListItem.h"
|
||||||
#include "SWGErrorResponse.h"
|
#include "SWGErrorResponse.h"
|
||||||
|
|
||||||
#include "webapiadaptergui.h"
|
#include "webapiadaptergui.h"
|
||||||
|
@ -137,4 +141,27 @@ int WebAPIAdapterGUI::instanceSummary(
|
||||||
return 200;
|
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::SWGInstanceSummaryResponse& response,
|
||||||
Swagger::SWGErrorResponse& error);
|
Swagger::SWGErrorResponse& error);
|
||||||
|
|
||||||
|
virtual int instanceDevices(
|
||||||
|
bool tx,
|
||||||
|
Swagger::SWGInstanceDevicesResponse& response,
|
||||||
|
Swagger::SWGErrorResponse& error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MainWindow& m_mainWindow;
|
MainWindow& m_mainWindow;
|
||||||
};
|
};
|
||||||
|
|
|
@ -482,13 +482,20 @@ definitions:
|
||||||
description: "Summarized information about attached hardware device"
|
description: "Summarized information about attached hardware device"
|
||||||
required:
|
required:
|
||||||
- hwType
|
- hwType
|
||||||
- streamIndex
|
|
||||||
- sequence
|
|
||||||
- serial
|
|
||||||
properties:
|
properties:
|
||||||
|
displayedName:
|
||||||
|
description: "Displayable name that uniquely identifies this device instance"
|
||||||
|
type: string
|
||||||
hwType:
|
hwType:
|
||||||
description: "Key to identify the type of hardware device"
|
description: "Key to identify the type of hardware device"
|
||||||
type: string
|
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:
|
tx:
|
||||||
description: "Set to true if this is a Tx device"
|
description: "Set to true if this is a Tx device"
|
||||||
type: boolean
|
type: boolean
|
||||||
|
@ -498,12 +505,9 @@ definitions:
|
||||||
streamIndex:
|
streamIndex:
|
||||||
description: "Index of the channel in the device"
|
description: "Index of the channel in the device"
|
||||||
type: integer
|
type: integer
|
||||||
sequence:
|
deviceSetIndex:
|
||||||
description: "Sequence in the enumeration of same device types"
|
description: "Index of the device set that claimed this device (-1 if not claimed)"
|
||||||
type: integer
|
type: integer
|
||||||
serial:
|
|
||||||
description: "Serial number of the hardware device"
|
|
||||||
type: string
|
|
||||||
ChannelListItem:
|
ChannelListItem:
|
||||||
description: "Summarized information about channel plugin"
|
description: "Summarized information about channel plugin"
|
||||||
required:
|
required:
|
||||||
|
|
|
@ -37,28 +37,35 @@ SWGDeviceListItem::~SWGDeviceListItem() {
|
||||||
|
|
||||||
void
|
void
|
||||||
SWGDeviceListItem::init() {
|
SWGDeviceListItem::init() {
|
||||||
|
displayed_name = new QString("");
|
||||||
hw_type = new QString("");
|
hw_type = new QString("");
|
||||||
|
serial = new QString("");
|
||||||
|
sequence = 0;
|
||||||
tx = false;
|
tx = false;
|
||||||
nb_streams = 0;
|
nb_streams = 0;
|
||||||
stream_index = 0;
|
stream_index = 0;
|
||||||
sequence = 0;
|
device_set_index = 0;
|
||||||
serial = new QString("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SWGDeviceListItem::cleanup() {
|
SWGDeviceListItem::cleanup() {
|
||||||
|
|
||||||
|
if(displayed_name != nullptr) {
|
||||||
|
delete displayed_name;
|
||||||
|
}
|
||||||
|
|
||||||
if(hw_type != nullptr) {
|
if(hw_type != nullptr) {
|
||||||
delete hw_type;
|
delete hw_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(serial != nullptr) {
|
if(serial != nullptr) {
|
||||||
delete serial;
|
delete serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SWGDeviceListItem*
|
SWGDeviceListItem*
|
||||||
|
@ -72,12 +79,14 @@ SWGDeviceListItem::fromJson(QString &json) {
|
||||||
|
|
||||||
void
|
void
|
||||||
SWGDeviceListItem::fromJsonObject(QJsonObject &pJson) {
|
SWGDeviceListItem::fromJsonObject(QJsonObject &pJson) {
|
||||||
|
::Swagger::setValue(&displayed_name, pJson["displayedName"], "QString", "QString");
|
||||||
::Swagger::setValue(&hw_type, pJson["hwType"], "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(&tx, pJson["tx"], "bool", "");
|
||||||
::Swagger::setValue(&nb_streams, pJson["nbStreams"], "qint32", "");
|
::Swagger::setValue(&nb_streams, pJson["nbStreams"], "qint32", "");
|
||||||
::Swagger::setValue(&stream_index, pJson["streamIndex"], "qint32", "");
|
::Swagger::setValue(&stream_index, pJson["streamIndex"], "qint32", "");
|
||||||
::Swagger::setValue(&sequence, pJson["sequence"], "qint32", "");
|
::Swagger::setValue(&device_set_index, pJson["deviceSetIndex"], "qint32", "");
|
||||||
::Swagger::setValue(&serial, pJson["serial"], "QString", "QString");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
|
@ -94,21 +103,34 @@ QJsonObject*
|
||||||
SWGDeviceListItem::asJsonObject() {
|
SWGDeviceListItem::asJsonObject() {
|
||||||
QJsonObject* obj = new QJsonObject();
|
QJsonObject* obj = new QJsonObject();
|
||||||
|
|
||||||
|
toJsonValue(QString("displayedName"), displayed_name, obj, QString("QString"));
|
||||||
|
|
||||||
toJsonValue(QString("hwType"), hw_type, 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("tx", QJsonValue(tx));
|
||||||
|
|
||||||
obj->insert("nbStreams", QJsonValue(nb_streams));
|
obj->insert("nbStreams", QJsonValue(nb_streams));
|
||||||
|
|
||||||
obj->insert("streamIndex", QJsonValue(stream_index));
|
obj->insert("streamIndex", QJsonValue(stream_index));
|
||||||
|
|
||||||
obj->insert("sequence", QJsonValue(sequence));
|
obj->insert("deviceSetIndex", QJsonValue(device_set_index));
|
||||||
|
|
||||||
toJsonValue(QString("serial"), serial, obj, QString("QString"));
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString*
|
||||||
|
SWGDeviceListItem::getDisplayedName() {
|
||||||
|
return displayed_name;
|
||||||
|
}
|
||||||
|
void
|
||||||
|
SWGDeviceListItem::setDisplayedName(QString* displayed_name) {
|
||||||
|
this->displayed_name = displayed_name;
|
||||||
|
}
|
||||||
|
|
||||||
QString*
|
QString*
|
||||||
SWGDeviceListItem::getHwType() {
|
SWGDeviceListItem::getHwType() {
|
||||||
return hw_type;
|
return hw_type;
|
||||||
|
@ -118,6 +140,24 @@ SWGDeviceListItem::setHwType(QString* hw_type) {
|
||||||
this->hw_type = 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
|
bool
|
||||||
SWGDeviceListItem::getTx() {
|
SWGDeviceListItem::getTx() {
|
||||||
return tx;
|
return tx;
|
||||||
|
@ -146,21 +186,12 @@ SWGDeviceListItem::setStreamIndex(qint32 stream_index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
qint32
|
qint32
|
||||||
SWGDeviceListItem::getSequence() {
|
SWGDeviceListItem::getDeviceSetIndex() {
|
||||||
return sequence;
|
return device_set_index;
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
SWGDeviceListItem::setSequence(qint32 sequence) {
|
SWGDeviceListItem::setDeviceSetIndex(qint32 device_set_index) {
|
||||||
this->sequence = sequence;
|
this->device_set_index = device_set_index;
|
||||||
}
|
|
||||||
|
|
||||||
QString*
|
|
||||||
SWGDeviceListItem::getSerial() {
|
|
||||||
return serial;
|
|
||||||
}
|
|
||||||
void
|
|
||||||
SWGDeviceListItem::setSerial(QString* serial) {
|
|
||||||
this->serial = serial;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,9 +42,18 @@ public:
|
||||||
void fromJsonObject(QJsonObject &json);
|
void fromJsonObject(QJsonObject &json);
|
||||||
SWGDeviceListItem* fromJson(QString &jsonString);
|
SWGDeviceListItem* fromJson(QString &jsonString);
|
||||||
|
|
||||||
|
QString* getDisplayedName();
|
||||||
|
void setDisplayedName(QString* displayed_name);
|
||||||
|
|
||||||
QString* getHwType();
|
QString* getHwType();
|
||||||
void setHwType(QString* hw_type);
|
void setHwType(QString* hw_type);
|
||||||
|
|
||||||
|
QString* getSerial();
|
||||||
|
void setSerial(QString* serial);
|
||||||
|
|
||||||
|
qint32 getSequence();
|
||||||
|
void setSequence(qint32 sequence);
|
||||||
|
|
||||||
bool getTx();
|
bool getTx();
|
||||||
void setTx(bool tx);
|
void setTx(bool tx);
|
||||||
|
|
||||||
|
@ -54,20 +63,19 @@ public:
|
||||||
qint32 getStreamIndex();
|
qint32 getStreamIndex();
|
||||||
void setStreamIndex(qint32 stream_index);
|
void setStreamIndex(qint32 stream_index);
|
||||||
|
|
||||||
qint32 getSequence();
|
qint32 getDeviceSetIndex();
|
||||||
void setSequence(qint32 sequence);
|
void setDeviceSetIndex(qint32 device_set_index);
|
||||||
|
|
||||||
QString* getSerial();
|
|
||||||
void setSerial(QString* serial);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString* displayed_name;
|
||||||
QString* hw_type;
|
QString* hw_type;
|
||||||
|
QString* serial;
|
||||||
|
qint32 sequence;
|
||||||
bool tx;
|
bool tx;
|
||||||
qint32 nb_streams;
|
qint32 nb_streams;
|
||||||
qint32 stream_index;
|
qint32 stream_index;
|
||||||
qint32 sequence;
|
qint32 device_set_index;
|
||||||
QString* serial;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue