mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-04-04 18:48:34 -04:00
Web API: /sdrangel/devicesets (POST, DELETE) implementation
This commit is contained in:
parent
c91918840e
commit
3086c4772b
@ -7638,7 +7638,7 @@ except ApiException as e:
|
||||
</div>
|
||||
<div id="generator">
|
||||
<div class="content">
|
||||
Generated 2017-11-25T20:11:05.104+01:00
|
||||
Generated 2017-11-25T22:31:12.548+01:00
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -35,6 +35,7 @@ namespace Swagger
|
||||
class SWGPresetTransfer;
|
||||
class SWGPresetIdentifier;
|
||||
class SWGDeviceSetList;
|
||||
class SWGDeviceSet;
|
||||
class SWGErrorResponse;
|
||||
}
|
||||
|
||||
@ -185,7 +186,7 @@ public:
|
||||
{ return 501; }
|
||||
|
||||
/**
|
||||
* Handler of /sdrangel/preset (DELETE) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* Handler of /sdrangel/devicesets (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* returns the Http status code (default 501: not implemented)
|
||||
*/
|
||||
virtual int instanceDeviceSetsGet(
|
||||
@ -193,6 +194,26 @@ public:
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
/**
|
||||
* Handler of /sdrangel/devicesets (POST) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* returns the Http status code (default 501: not implemented)
|
||||
*/
|
||||
virtual int instanceDeviceSetsPost(
|
||||
bool tx __attribute__((unused)),
|
||||
Swagger::SWGDeviceSet& response __attribute__((unused)),
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
|
||||
/**
|
||||
* Handler of /sdrangel/devicesets (DELETE) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* returns the Http status code (default 501: not implemented)
|
||||
*/
|
||||
virtual int instanceDeviceSetsDelete(
|
||||
Swagger::SWGDeviceSetList& response __attribute__((unused)),
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
static QString instanceSummaryURL;
|
||||
static QString instanceDevicesURL;
|
||||
static QString instanceChannelsURL;
|
||||
|
@ -487,6 +487,37 @@ void WebAPIRequestMapper::instanceDeviceSetsService(qtwebapp::HttpRequest& reque
|
||||
response.write(errorResponse.asJson().toUtf8());
|
||||
}
|
||||
}
|
||||
else if (request.getMethod() == "POST")
|
||||
{
|
||||
Swagger::SWGDeviceSet normalResponse;
|
||||
QByteArray txStr = request.getParameter("tx");
|
||||
bool tx = false;
|
||||
|
||||
if (txStr.length() != 0) {
|
||||
tx = !(txStr == "0");
|
||||
}
|
||||
|
||||
int status = m_adapter->instanceDeviceSetsPost(tx, normalResponse, errorResponse);
|
||||
response.setStatus(status);
|
||||
|
||||
if (status == 200) {
|
||||
response.write(normalResponse.asJson().toUtf8());
|
||||
} else {
|
||||
response.write(errorResponse.asJson().toUtf8());
|
||||
}
|
||||
}
|
||||
else if (request.getMethod() == "DELETE")
|
||||
{
|
||||
Swagger::SWGDeviceSetList normalResponse;
|
||||
int status = m_adapter->instanceDeviceSetsDelete(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");
|
||||
|
@ -65,6 +65,8 @@
|
||||
MESSAGE_CLASS_DEFINITION(MainWindow::MsgLoadPreset, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainWindow::MsgSavePreset, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainWindow::MsgDeletePreset, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainWindow::MsgAddDeviceSet, Message)
|
||||
MESSAGE_CLASS_DEFINITION(MainWindow::MsgRemoveLastDeviceSet, Message)
|
||||
|
||||
MainWindow *MainWindow::m_instance = 0;
|
||||
|
||||
@ -706,6 +708,26 @@ bool MainWindow::handleMessage(const Message& cmd)
|
||||
m_settings.deletePreset(presetToDelete);
|
||||
return true;
|
||||
}
|
||||
else if (MsgAddDeviceSet::match(cmd))
|
||||
{
|
||||
MsgAddDeviceSet& notif = (MsgAddDeviceSet&) cmd;
|
||||
|
||||
if (notif.isTx()) {
|
||||
addSinkDevice();
|
||||
} else {
|
||||
addSourceDevice();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgRemoveLastDeviceSet::match(cmd))
|
||||
{
|
||||
if (m_deviceUIs.size() > 1) {
|
||||
removeLastDevice();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -153,6 +153,41 @@ private:
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgAddDeviceSet : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
bool isTx() const { return m_tx; }
|
||||
|
||||
static MsgAddDeviceSet* create(bool tx)
|
||||
{
|
||||
return new MsgAddDeviceSet(tx);
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_tx;
|
||||
|
||||
MsgAddDeviceSet(bool tx) :
|
||||
Message(),
|
||||
m_tx(tx)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgRemoveLastDeviceSet : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
static MsgRemoveLastDeviceSet* create()
|
||||
{
|
||||
return new MsgRemoveLastDeviceSet();
|
||||
}
|
||||
|
||||
private:
|
||||
MsgRemoveLastDeviceSet() :
|
||||
Message()
|
||||
{ }
|
||||
};
|
||||
|
||||
enum {
|
||||
PGroup,
|
||||
PItem
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <QApplication>
|
||||
#include <QList>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "loggerwithfile.h"
|
||||
#include "device/devicesourceapi.h"
|
||||
@ -551,6 +553,46 @@ int WebAPIAdapterGUI::instanceDeviceSetsGet(
|
||||
return 200;
|
||||
}
|
||||
|
||||
int WebAPIAdapterGUI::instanceDeviceSetsPost(
|
||||
bool tx,
|
||||
Swagger::SWGDeviceSet& response,
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{
|
||||
MainWindow::MsgAddDeviceSet *msg = MainWindow::MsgAddDeviceSet::create(tx);
|
||||
m_mainWindow.m_inputMessageQueue.push(msg);
|
||||
|
||||
usleep(100000);
|
||||
|
||||
const DeviceUISet *lastDeviceSet = m_mainWindow.m_deviceUIs.back();
|
||||
getDeviceSet(&response,lastDeviceSet, (int) m_mainWindow.m_deviceUIs.size() - 1);
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
int WebAPIAdapterGUI::instanceDeviceSetsDelete(
|
||||
Swagger::SWGDeviceSetList& response,
|
||||
Swagger::SWGErrorResponse& error)
|
||||
{
|
||||
if (m_mainWindow.m_deviceUIs.size() > 1)
|
||||
{
|
||||
MainWindow::MsgRemoveLastDeviceSet *msg = MainWindow::MsgRemoveLastDeviceSet::create();
|
||||
m_mainWindow.m_inputMessageQueue.push(msg);
|
||||
|
||||
usleep(100000);
|
||||
|
||||
getDeviceSetList(&response);
|
||||
|
||||
return 200;
|
||||
}
|
||||
else
|
||||
{
|
||||
error.init();
|
||||
*error.getMessage() = "No more device sets to be removed";
|
||||
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
|
||||
void WebAPIAdapterGUI::getDeviceSetList(Swagger::SWGDeviceSetList* deviceSetList)
|
||||
{
|
||||
deviceSetList->init();
|
||||
@ -560,71 +602,77 @@ void WebAPIAdapterGUI::getDeviceSetList(Swagger::SWGDeviceSetList* deviceSetList
|
||||
|
||||
for (int i = 0; it != m_mainWindow.m_deviceUIs.end(); ++it, i++)
|
||||
{
|
||||
QList<Swagger::SWGDeviceSet*> *deviceSet = deviceSetList->getDeviceSets();
|
||||
deviceSet->append(new Swagger::SWGDeviceSet());
|
||||
Swagger::SWGSamplingDevice *samplingDevice = deviceSet->back()->getSamplingDevice();
|
||||
samplingDevice->init();
|
||||
samplingDevice->setIndex(i);
|
||||
samplingDevice->setTx((*it)->m_deviceSinkEngine != 0);
|
||||
QList<Swagger::SWGDeviceSet*> *deviceSets = deviceSetList->getDeviceSets();
|
||||
deviceSets->append(new Swagger::SWGDeviceSet());
|
||||
|
||||
if ((*it)->m_deviceSinkEngine) // Tx data
|
||||
{
|
||||
*samplingDevice->getHwType() = (*it)->m_deviceSinkAPI->getHardwareId();
|
||||
*samplingDevice->getSerial() = (*it)->m_deviceSinkAPI->getSampleSinkSerial();
|
||||
samplingDevice->setSequence((*it)->m_deviceSinkAPI->getSampleSinkSequence());
|
||||
samplingDevice->setNbStreams((*it)->m_deviceSinkAPI->getNbItems());
|
||||
samplingDevice->setStreamIndex((*it)->m_deviceSinkAPI->getItemIndex());
|
||||
(*it)->m_deviceSinkAPI->getDeviceEngineStateStr(*samplingDevice->getState());
|
||||
DeviceSampleSink *sampleSink = (*it)->m_deviceSinkEngine->getSink();
|
||||
getDeviceSet(deviceSets->back(), *it, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (sampleSink) {
|
||||
samplingDevice->setCenterFrequency(sampleSink->getCenterFrequency());
|
||||
samplingDevice->setBandwidth(sampleSink->getSampleRate());
|
||||
}
|
||||
void WebAPIAdapterGUI::getDeviceSet(Swagger::SWGDeviceSet *deviceSet, const DeviceUISet* deviceUISet, int deviceUISetIndex)
|
||||
{
|
||||
Swagger::SWGSamplingDevice *samplingDevice = deviceSet->getSamplingDevice();
|
||||
samplingDevice->init();
|
||||
samplingDevice->setIndex(deviceUISetIndex);
|
||||
samplingDevice->setTx(deviceUISet->m_deviceSinkEngine != 0);
|
||||
|
||||
deviceSet->back()->setChannelcount((*it)->m_deviceSinkAPI->getNbChannels());
|
||||
QList<Swagger::SWGChannel*> *channels = deviceSet->back()->getChannels();
|
||||
if (deviceUISet->m_deviceSinkEngine) // Tx data
|
||||
{
|
||||
*samplingDevice->getHwType() = deviceUISet->m_deviceSinkAPI->getHardwareId();
|
||||
*samplingDevice->getSerial() = deviceUISet->m_deviceSinkAPI->getSampleSinkSerial();
|
||||
samplingDevice->setSequence(deviceUISet->m_deviceSinkAPI->getSampleSinkSequence());
|
||||
samplingDevice->setNbStreams(deviceUISet->m_deviceSinkAPI->getNbItems());
|
||||
samplingDevice->setStreamIndex(deviceUISet->m_deviceSinkAPI->getItemIndex());
|
||||
deviceUISet->m_deviceSinkAPI->getDeviceEngineStateStr(*samplingDevice->getState());
|
||||
DeviceSampleSink *sampleSink = deviceUISet->m_deviceSinkEngine->getSink();
|
||||
|
||||
for (int i = 0; i < deviceSet->back()->getChannelcount(); i++)
|
||||
{
|
||||
channels->append(new Swagger::SWGChannel);
|
||||
ChannelSourceAPI *channel = (*it)->m_deviceSinkAPI->getChanelAPIAt(i);
|
||||
channels->back()->setDeltaFrequency(channel->getDeltaFrequency());
|
||||
channels->back()->setIndex(channel->getIndexInDeviceSet());
|
||||
channels->back()->setUid(channel->getUID());
|
||||
channel->getIdentifier(*channels->back()->getId());
|
||||
channel->getTitle(*channels->back()->getTitle());
|
||||
}
|
||||
if (sampleSink) {
|
||||
samplingDevice->setCenterFrequency(sampleSink->getCenterFrequency());
|
||||
samplingDevice->setBandwidth(sampleSink->getSampleRate());
|
||||
}
|
||||
|
||||
if ((*it)->m_deviceSourceEngine) // Rx data
|
||||
deviceSet->setChannelcount(deviceUISet->m_deviceSinkAPI->getNbChannels());
|
||||
QList<Swagger::SWGChannel*> *channels = deviceSet->getChannels();
|
||||
|
||||
for (int i = 0; i < deviceSet->getChannelcount(); i++)
|
||||
{
|
||||
*samplingDevice->getHwType() = (*it)->m_deviceSourceAPI->getHardwareId();
|
||||
*samplingDevice->getSerial() = (*it)->m_deviceSourceAPI->getSampleSourceSerial();
|
||||
samplingDevice->setSequence((*it)->m_deviceSourceAPI->getSampleSourceSequence());
|
||||
samplingDevice->setNbStreams((*it)->m_deviceSourceAPI->getNbItems());
|
||||
samplingDevice->setStreamIndex((*it)->m_deviceSourceAPI->getItemIndex());
|
||||
(*it)->m_deviceSourceAPI->getDeviceEngineStateStr(*samplingDevice->getState());
|
||||
DeviceSampleSource *sampleSource = (*it)->m_deviceSourceEngine->getSource();
|
||||
channels->append(new Swagger::SWGChannel);
|
||||
ChannelSourceAPI *channel = deviceUISet->m_deviceSinkAPI->getChanelAPIAt(i);
|
||||
channels->back()->setDeltaFrequency(channel->getDeltaFrequency());
|
||||
channels->back()->setIndex(channel->getIndexInDeviceSet());
|
||||
channels->back()->setUid(channel->getUID());
|
||||
channel->getIdentifier(*channels->back()->getId());
|
||||
channel->getTitle(*channels->back()->getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
if (sampleSource) {
|
||||
samplingDevice->setCenterFrequency(sampleSource->getCenterFrequency());
|
||||
samplingDevice->setBandwidth(sampleSource->getSampleRate());
|
||||
}
|
||||
if (deviceUISet->m_deviceSourceEngine) // Rx data
|
||||
{
|
||||
*samplingDevice->getHwType() = deviceUISet->m_deviceSourceAPI->getHardwareId();
|
||||
*samplingDevice->getSerial() = deviceUISet->m_deviceSourceAPI->getSampleSourceSerial();
|
||||
samplingDevice->setSequence(deviceUISet->m_deviceSourceAPI->getSampleSourceSequence());
|
||||
samplingDevice->setNbStreams(deviceUISet->m_deviceSourceAPI->getNbItems());
|
||||
samplingDevice->setStreamIndex(deviceUISet->m_deviceSourceAPI->getItemIndex());
|
||||
deviceUISet->m_deviceSourceAPI->getDeviceEngineStateStr(*samplingDevice->getState());
|
||||
DeviceSampleSource *sampleSource = deviceUISet->m_deviceSourceEngine->getSource();
|
||||
|
||||
deviceSet->back()->setChannelcount((*it)->m_deviceSourceAPI->getNbChannels());
|
||||
QList<Swagger::SWGChannel*> *channels = deviceSet->back()->getChannels();
|
||||
if (sampleSource) {
|
||||
samplingDevice->setCenterFrequency(sampleSource->getCenterFrequency());
|
||||
samplingDevice->setBandwidth(sampleSource->getSampleRate());
|
||||
}
|
||||
|
||||
for (int i = 0; i < deviceSet->back()->getChannelcount(); i++)
|
||||
{
|
||||
channels->append(new Swagger::SWGChannel);
|
||||
ChannelSinkAPI *channel = (*it)->m_deviceSourceAPI->getChanelAPIAt(i);
|
||||
channels->back()->setDeltaFrequency(channel->getDeltaFrequency());
|
||||
channels->back()->setIndex(channel->getIndexInDeviceSet());
|
||||
channels->back()->setUid(channel->getUID());
|
||||
channel->getIdentifier(*channels->back()->getId());
|
||||
channel->getTitle(*channels->back()->getTitle());
|
||||
}
|
||||
deviceSet->setChannelcount(deviceUISet->m_deviceSourceAPI->getNbChannels());
|
||||
QList<Swagger::SWGChannel*> *channels = deviceSet->getChannels();
|
||||
|
||||
for (int i = 0; i < deviceSet->getChannelcount(); i++)
|
||||
{
|
||||
channels->append(new Swagger::SWGChannel);
|
||||
ChannelSinkAPI *channel = deviceUISet->m_deviceSourceAPI->getChanelAPIAt(i);
|
||||
channels->back()->setDeltaFrequency(channel->getDeltaFrequency());
|
||||
channels->back()->setIndex(channel->getIndexInDeviceSet());
|
||||
channels->back()->setUid(channel->getUID());
|
||||
channel->getIdentifier(*channels->back()->getId());
|
||||
channel->getTitle(*channels->back()->getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,10 +101,20 @@ public:
|
||||
Swagger::SWGDeviceSetList& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
virtual int instanceDeviceSetsPost(
|
||||
bool tx,
|
||||
Swagger::SWGDeviceSet& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
virtual int instanceDeviceSetsDelete(
|
||||
Swagger::SWGDeviceSetList& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
private:
|
||||
MainWindow& m_mainWindow;
|
||||
|
||||
void getDeviceSetList(Swagger::SWGDeviceSetList* deviceSetList);
|
||||
void getDeviceSet(Swagger::SWGDeviceSet *deviceSet, const DeviceUISet* deviceUISet, int deviceUISetIndex);
|
||||
static QtMsgType getMsgTypeFromString(const QString& msgTypeString);
|
||||
static void getMsgTypeString(const QtMsgType& msgType, QString& level);
|
||||
};
|
||||
|
@ -421,6 +421,8 @@ paths:
|
||||
$ref: "#/definitions/DeviceSetList"
|
||||
"404":
|
||||
description: "No more device sets to be deleted"
|
||||
schema:
|
||||
$ref: "#/definitions/ErrorResponse"
|
||||
"500":
|
||||
description: Error
|
||||
schema:
|
||||
|
@ -7638,7 +7638,7 @@ except ApiException as e:
|
||||
</div>
|
||||
<div id="generator">
|
||||
<div class="content">
|
||||
Generated 2017-11-25T20:11:05.104+01:00
|
||||
Generated 2017-11-25T22:31:12.548+01:00
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user