1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-05-24 11:12:27 -04:00

Web API: /sdrangel/dvserial implementation

This commit is contained in:
f4exb 2017-11-25 04:43:22 +01:00
parent aa8b02a225
commit 68fbbcf768
12 changed files with 1530 additions and 1406 deletions

View File

@ -832,11 +832,20 @@ margin-bottom: 20px;
"type" : "array", "type" : "array",
"description" : "Device names of DV serial devices", "description" : "Device names of DV serial devices",
"items" : { "items" : {
"type" : "string" "$ref" : "#/definitions/DVSerialDevice"
} }
} }
}, },
"description" : "List of DV serial devices available in the system" "description" : "List of DV serial devices available in the system"
};
defs.DVSerialDevice = {
"properties" : {
"deviceName" : {
"type" : "string",
"description" : "Name of the serial device in the system"
}
},
"description" : "DV serial device details"
}; };
defs.DeviceListItem = { defs.DeviceListItem = {
"required" : [ "hwType" ], "required" : [ "hwType" ],
@ -7384,7 +7393,7 @@ except ApiException as e:
</div> </div>
<div id="generator"> <div id="generator">
<div class="content"> <div class="content">
Generated 2017-11-24T17:11:18.943+01:00 Generated 2017-11-25T04:38:54.817+01:00
</div> </div>
</div> </div>
</div> </div>

View File

@ -24,3 +24,4 @@ QString WebAPIAdapterInterface::instanceChannelsURL = "/sdrangel/channels";
QString WebAPIAdapterInterface::instanceLoggingURL = "/sdrangel/logging"; QString WebAPIAdapterInterface::instanceLoggingURL = "/sdrangel/logging";
QString WebAPIAdapterInterface::instanceAudioURL = "/sdrangel/audio"; QString WebAPIAdapterInterface::instanceAudioURL = "/sdrangel/audio";
QString WebAPIAdapterInterface::instanceLocationURL = "/sdrangel/location"; QString WebAPIAdapterInterface::instanceLocationURL = "/sdrangel/location";
QString WebAPIAdapterInterface::instanceDVSerialURL = "/sdrangel/dvserial";

View File

@ -30,6 +30,7 @@ namespace Swagger
class SWGAudioDevices; class SWGAudioDevices;
class SWGAudioDevicesSelect; class SWGAudioDevicesSelect;
class SWGLocationInformation; class SWGLocationInformation;
class SWGDVSeralDevices;
class SWGErrorResponse; class SWGErrorResponse;
} }
@ -121,12 +122,23 @@ public:
Swagger::SWGErrorResponse& error __attribute__((unused))) Swagger::SWGErrorResponse& error __attribute__((unused)))
{ return 501; } { return 501; }
/**
* Handler of /sdrangel/location (PUT) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
* returns the Http status code (default 501: not implemented)
*/
virtual int instanceDVSerialPatch(
bool dvserial __attribute__((unused)),
Swagger::SWGDVSeralDevices& response __attribute__((unused)),
Swagger::SWGErrorResponse& error __attribute__((unused)))
{ return 501; }
static QString instanceSummaryURL; static QString instanceSummaryURL;
static QString instanceDevicesURL; static QString instanceDevicesURL;
static QString instanceChannelsURL; static QString instanceChannelsURL;
static QString instanceLoggingURL; static QString instanceLoggingURL;
static QString instanceAudioURL; static QString instanceAudioURL;
static QString instanceLocationURL; static QString instanceLocationURL;
static QString instanceDVSerialURL;
}; };

View File

@ -28,6 +28,7 @@
#include "SWGAudioDevices.h" #include "SWGAudioDevices.h"
#include "SWGAudioDevicesSelect.h" #include "SWGAudioDevicesSelect.h"
#include "SWGLocationInformation.h" #include "SWGLocationInformation.h"
#include "SWGDVSeralDevices.h"
#include "SWGErrorResponse.h" #include "SWGErrorResponse.h"
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) : WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
@ -67,6 +68,8 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
instanceAudioService(request, response); instanceAudioService(request, response);
} else if (path == WebAPIAdapterInterface::instanceLocationURL) { } else if (path == WebAPIAdapterInterface::instanceLocationURL) {
instanceLocationService(request, response); instanceLocationService(request, response);
} else if (path == WebAPIAdapterInterface::instanceDVSerialURL) {
instanceDVSerialService(request, response);
} }
else else
{ {
@ -112,7 +115,11 @@ void WebAPIRequestMapper::instanceDevicesService(qtwebapp::HttpRequest& request,
if (request.getMethod() == "GET") if (request.getMethod() == "GET")
{ {
QByteArray txStr = request.getParameter("tx"); QByteArray txStr = request.getParameter("tx");
bool tx = (txStr == "1"); bool tx = false;
if (txStr.length() != 0) {
tx = !(txStr == "0");
}
int status = m_adapter->instanceDevices(tx, normalResponse, errorResponse); int status = m_adapter->instanceDevices(tx, normalResponse, errorResponse);
response.setStatus(status); response.setStatus(status);
@ -138,7 +145,11 @@ void WebAPIRequestMapper::instanceChannelsService(qtwebapp::HttpRequest& request
if (request.getMethod() == "GET") if (request.getMethod() == "GET")
{ {
QByteArray txStr = request.getParameter("tx"); QByteArray txStr = request.getParameter("tx");
bool tx = (txStr == "1"); bool tx = false;
if (txStr.length() != 0) {
tx = !(txStr == "0");
}
int status = m_adapter->instanceChannels(tx, normalResponse, errorResponse); int status = m_adapter->instanceChannels(tx, normalResponse, errorResponse);
response.setStatus(status); response.setStatus(status);
@ -280,6 +291,37 @@ void WebAPIRequestMapper::instanceLocationService(qtwebapp::HttpRequest& request
} }
} }
void WebAPIRequestMapper::instanceDVSerialService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
{
Swagger::SWGErrorResponse errorResponse;
if (request.getMethod() == "PATCH")
{
QByteArray dvserialStr = request.getParameter("dvserial");
bool dvserial = false;
if (dvserialStr.length() != 0) {
dvserial = !(dvserialStr == "0");
}
Swagger::SWGDVSeralDevices normalResponse;
int status = m_adapter->instanceDVSerialPatch(dvserial, 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");
}
}
bool WebAPIRequestMapper::parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response) bool WebAPIRequestMapper::parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response)
{ {
Swagger::SWGErrorResponse errorResponse; Swagger::SWGErrorResponse errorResponse;

View File

@ -45,6 +45,7 @@ private:
void instanceLoggingService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); void instanceLoggingService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
void instanceAudioService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); void instanceAudioService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
void instanceLocationService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); void instanceLocationService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
void instanceDVSerialService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
bool parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response); bool parseJsonBody(QString& jsonStr, qtwebapp::HttpResponse& response);
}; };

View File

@ -40,6 +40,8 @@
#include "SWGAudioDevices.h" #include "SWGAudioDevices.h"
#include "SWGAudioDevicesSelect.h" #include "SWGAudioDevicesSelect.h"
#include "SWGLocationInformation.h" #include "SWGLocationInformation.h"
#include "SWGDVSeralDevices.h"
#include "SWGDVSerialDevice.h"
#include "SWGErrorResponse.h" #include "SWGErrorResponse.h"
#include "webapiadaptergui.h" #include "webapiadaptergui.h"
@ -348,6 +350,39 @@ int WebAPIAdapterGUI::instanceLocationPut(
return 200; return 200;
} }
int WebAPIAdapterGUI::instanceDVSerialPatch(
bool dvserial,
Swagger::SWGDVSeralDevices& response,
Swagger::SWGErrorResponse& error __attribute__((unused)))
{
m_mainWindow.m_dspEngine->setDVSerialSupport(dvserial);
response.init();
if (dvserial)
{
std::vector<std::string> deviceNames;
m_mainWindow.m_dspEngine->getDVSerialNames(deviceNames);
response.setNbDevices((int) deviceNames.size());
QList<Swagger::SWGDVSerialDevice*> *deviceNamesList = response.getDvSerialDevices();
std::vector<std::string>::iterator it = deviceNames.begin();
std::string deviceNamesStr = "DV Serial devices found: ";
while (it != deviceNames.end())
{
deviceNamesList->append(new Swagger::SWGDVSerialDevice);
*deviceNamesList->back()->getDeviceName() = QString::fromStdString(*it);
++it;
}
}
else
{
response.setNbDevices(0);
}
return 200;
}
QtMsgType WebAPIAdapterGUI::getMsgTypeFromString(const QString& msgTypeString) QtMsgType WebAPIAdapterGUI::getMsgTypeFromString(const QString& msgTypeString)
{ {
if (msgTypeString == "debug") { if (msgTypeString == "debug") {

View File

@ -69,6 +69,11 @@ public:
Swagger::SWGLocationInformation& response, Swagger::SWGLocationInformation& response,
Swagger::SWGErrorResponse& error); Swagger::SWGErrorResponse& error);
virtual int instanceDVSerialPatch(
bool dvserial,
Swagger::SWGDVSeralDevices& response,
Swagger::SWGErrorResponse& error);
private: private:
MainWindow& m_mainWindow; MainWindow& m_mainWindow;

View File

@ -714,6 +714,12 @@ definitions:
description: "Device names of DV serial devices" description: "Device names of DV serial devices"
type: array type: array
items: items:
$ref: "#/definitions/DVSerialDevice"
DVSerialDevice:
description: "DV serial device details"
properties:
deviceName:
description: "Name of the serial device in the system"
type: string type: string
Presets: Presets:
description: "Settings presets" description: "Settings presets"

View File

@ -832,11 +832,20 @@ margin-bottom: 20px;
"type" : "array", "type" : "array",
"description" : "Device names of DV serial devices", "description" : "Device names of DV serial devices",
"items" : { "items" : {
"type" : "string" "$ref" : "#/definitions/DVSerialDevice"
} }
} }
}, },
"description" : "List of DV serial devices available in the system" "description" : "List of DV serial devices available in the system"
};
defs.DVSerialDevice = {
"properties" : {
"deviceName" : {
"type" : "string",
"description" : "Name of the serial device in the system"
}
},
"description" : "DV serial device details"
}; };
defs.DeviceListItem = { defs.DeviceListItem = {
"required" : [ "hwType" ], "required" : [ "hwType" ],
@ -7384,7 +7393,7 @@ except ApiException as e:
</div> </div>
<div id="generator"> <div id="generator">
<div class="content"> <div class="content">
Generated 2017-11-24T17:11:18.943+01:00 Generated 2017-11-25T04:38:54.817+01:00
</div> </div>
</div> </div>
</div> </div>

View File

@ -38,7 +38,7 @@ SWGDVSeralDevices::~SWGDVSeralDevices() {
void void
SWGDVSeralDevices::init() { SWGDVSeralDevices::init() {
nb_devices = 0; nb_devices = 0;
dv_serial_devices = new QList<QString*>(); dv_serial_devices = new QList<SWGDVSerialDevice*>();
} }
void void
@ -46,8 +46,8 @@ SWGDVSeralDevices::cleanup() {
if(dv_serial_devices != nullptr) { if(dv_serial_devices != nullptr) {
QList<QString*>* arr = dv_serial_devices; QList<SWGDVSerialDevice*>* arr = dv_serial_devices;
foreach(QString* o, *arr) { foreach(SWGDVSerialDevice* o, *arr) {
delete o; delete o;
} }
delete dv_serial_devices; delete dv_serial_devices;
@ -67,7 +67,7 @@ void
SWGDVSeralDevices::fromJsonObject(QJsonObject &pJson) { SWGDVSeralDevices::fromJsonObject(QJsonObject &pJson) {
::Swagger::setValue(&nb_devices, pJson["nbDevices"], "qint32", ""); ::Swagger::setValue(&nb_devices, pJson["nbDevices"], "qint32", "");
::Swagger::setValue(&dv_serial_devices, pJson["dvSerialDevices"], "QList", "QString"); ::Swagger::setValue(&dv_serial_devices, pJson["dvSerialDevices"], "QList", "SWGDVSerialDevice");
} }
@ -88,7 +88,7 @@ SWGDVSeralDevices::asJsonObject() {
obj->insert("nbDevices", QJsonValue(nb_devices)); obj->insert("nbDevices", QJsonValue(nb_devices));
QJsonArray dv_serial_devicesJsonArray; QJsonArray dv_serial_devicesJsonArray;
toJsonArray((QList<void*>*)dv_serial_devices, &dv_serial_devicesJsonArray, "dv_serial_devices", "QString"); toJsonArray((QList<void*>*)dv_serial_devices, &dv_serial_devicesJsonArray, "dv_serial_devices", "SWGDVSerialDevice");
obj->insert("dvSerialDevices", dv_serial_devicesJsonArray); obj->insert("dvSerialDevices", dv_serial_devicesJsonArray);
return obj; return obj;
@ -103,12 +103,12 @@ SWGDVSeralDevices::setNbDevices(qint32 nb_devices) {
this->nb_devices = nb_devices; this->nb_devices = nb_devices;
} }
QList<QString*>* QList<SWGDVSerialDevice*>*
SWGDVSeralDevices::getDvSerialDevices() { SWGDVSeralDevices::getDvSerialDevices() {
return dv_serial_devices; return dv_serial_devices;
} }
void void
SWGDVSeralDevices::setDvSerialDevices(QList<QString*>* dv_serial_devices) { SWGDVSeralDevices::setDvSerialDevices(QList<SWGDVSerialDevice*>* dv_serial_devices) {
this->dv_serial_devices = dv_serial_devices; this->dv_serial_devices = dv_serial_devices;
} }

View File

@ -22,8 +22,8 @@
#include <QJsonObject> #include <QJsonObject>
#include "SWGDVSerialDevice.h"
#include <QList> #include <QList>
#include <QString>
#include "SWGObject.h" #include "SWGObject.h"
@ -46,13 +46,13 @@ public:
qint32 getNbDevices(); qint32 getNbDevices();
void setNbDevices(qint32 nb_devices); void setNbDevices(qint32 nb_devices);
QList<QString*>* getDvSerialDevices(); QList<SWGDVSerialDevice*>* getDvSerialDevices();
void setDvSerialDevices(QList<QString*>* dv_serial_devices); void setDvSerialDevices(QList<SWGDVSerialDevice*>* dv_serial_devices);
private: private:
qint32 nb_devices; qint32 nb_devices;
QList<QString*>* dv_serial_devices; QList<SWGDVSerialDevice*>* dv_serial_devices;
}; };
} }

View File

@ -20,6 +20,7 @@
#include "SWGChannel.h" #include "SWGChannel.h"
#include "SWGChannelListItem.h" #include "SWGChannelListItem.h"
#include "SWGDVSeralDevices.h" #include "SWGDVSeralDevices.h"
#include "SWGDVSerialDevice.h"
#include "SWGDeviceListItem.h" #include "SWGDeviceListItem.h"
#include "SWGDeviceSet.h" #include "SWGDeviceSet.h"
#include "SWGDeviceSetList.h" #include "SWGDeviceSetList.h"
@ -58,6 +59,9 @@ namespace Swagger {
if(QString("SWGDVSeralDevices").compare(type) == 0) { if(QString("SWGDVSeralDevices").compare(type) == 0) {
return new SWGDVSeralDevices(); return new SWGDVSeralDevices();
} }
if(QString("SWGDVSerialDevice").compare(type) == 0) {
return new SWGDVSerialDevice();
}
if(QString("SWGDeviceListItem").compare(type) == 0) { if(QString("SWGDeviceListItem").compare(type) == 0) {
return new SWGDeviceListItem(); return new SWGDeviceListItem();
} }