mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 13:11:20 -05:00 
			
		
		
		
	Web API: /sdrangel/dvserial implementation
This commit is contained in:
		
							parent
							
								
									aa8b02a225
								
							
						
					
					
						commit
						68fbbcf768
					
				@ -832,11 +832,20 @@ margin-bottom: 20px;
 | 
			
		||||
      "type" : "array",
 | 
			
		||||
      "description" : "Device names of DV serial devices",
 | 
			
		||||
      "items" : {
 | 
			
		||||
        "type" : "string"
 | 
			
		||||
        "$ref" : "#/definitions/DVSerialDevice"
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "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 = {
 | 
			
		||||
  "required" : [ "hwType" ],
 | 
			
		||||
@ -7384,7 +7393,7 @@ except ApiException as e:
 | 
			
		||||
          </div>
 | 
			
		||||
          <div id="generator">
 | 
			
		||||
            <div class="content">
 | 
			
		||||
              Generated 2017-11-24T17:11:18.943+01:00
 | 
			
		||||
              Generated 2017-11-25T04:38:54.817+01:00
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
@ -24,3 +24,4 @@ QString WebAPIAdapterInterface::instanceChannelsURL = "/sdrangel/channels";
 | 
			
		||||
QString WebAPIAdapterInterface::instanceLoggingURL = "/sdrangel/logging";
 | 
			
		||||
QString WebAPIAdapterInterface::instanceAudioURL = "/sdrangel/audio";
 | 
			
		||||
QString WebAPIAdapterInterface::instanceLocationURL = "/sdrangel/location";
 | 
			
		||||
QString WebAPIAdapterInterface::instanceDVSerialURL = "/sdrangel/dvserial";
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,7 @@ namespace Swagger
 | 
			
		||||
    class SWGAudioDevices;
 | 
			
		||||
    class SWGAudioDevicesSelect;
 | 
			
		||||
    class SWGLocationInformation;
 | 
			
		||||
    class SWGDVSeralDevices;
 | 
			
		||||
    class SWGErrorResponse;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -121,12 +122,23 @@ public:
 | 
			
		||||
            Swagger::SWGErrorResponse& error __attribute__((unused)))
 | 
			
		||||
    { 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 instanceDevicesURL;
 | 
			
		||||
    static QString instanceChannelsURL;
 | 
			
		||||
    static QString instanceLoggingURL;
 | 
			
		||||
    static QString instanceAudioURL;
 | 
			
		||||
    static QString instanceLocationURL;
 | 
			
		||||
    static QString instanceDVSerialURL;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -28,6 +28,7 @@
 | 
			
		||||
#include "SWGAudioDevices.h"
 | 
			
		||||
#include "SWGAudioDevicesSelect.h"
 | 
			
		||||
#include "SWGLocationInformation.h"
 | 
			
		||||
#include "SWGDVSeralDevices.h"
 | 
			
		||||
#include "SWGErrorResponse.h"
 | 
			
		||||
 | 
			
		||||
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
 | 
			
		||||
@ -67,6 +68,8 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
 | 
			
		||||
            instanceAudioService(request, response);
 | 
			
		||||
        } else if (path == WebAPIAdapterInterface::instanceLocationURL) {
 | 
			
		||||
            instanceLocationService(request, response);
 | 
			
		||||
        } else if (path == WebAPIAdapterInterface::instanceDVSerialURL) {
 | 
			
		||||
            instanceDVSerialService(request, response);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
@ -112,7 +115,11 @@ void WebAPIRequestMapper::instanceDevicesService(qtwebapp::HttpRequest& request,
 | 
			
		||||
    if (request.getMethod() == "GET")
 | 
			
		||||
    {
 | 
			
		||||
        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);
 | 
			
		||||
        response.setStatus(status);
 | 
			
		||||
@ -138,7 +145,11 @@ void WebAPIRequestMapper::instanceChannelsService(qtwebapp::HttpRequest& request
 | 
			
		||||
    if (request.getMethod() == "GET")
 | 
			
		||||
    {
 | 
			
		||||
        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);
 | 
			
		||||
        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)
 | 
			
		||||
{
 | 
			
		||||
    Swagger::SWGErrorResponse errorResponse;
 | 
			
		||||
 | 
			
		||||
@ -45,6 +45,7 @@ private:
 | 
			
		||||
    void instanceLoggingService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response);
 | 
			
		||||
    void instanceAudioService(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);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -40,6 +40,8 @@
 | 
			
		||||
#include "SWGAudioDevices.h"
 | 
			
		||||
#include "SWGAudioDevicesSelect.h"
 | 
			
		||||
#include "SWGLocationInformation.h"
 | 
			
		||||
#include "SWGDVSeralDevices.h"
 | 
			
		||||
#include "SWGDVSerialDevice.h"
 | 
			
		||||
#include "SWGErrorResponse.h"
 | 
			
		||||
 | 
			
		||||
#include "webapiadaptergui.h"
 | 
			
		||||
@ -348,6 +350,39 @@ int WebAPIAdapterGUI::instanceLocationPut(
 | 
			
		||||
    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)
 | 
			
		||||
{
 | 
			
		||||
    if (msgTypeString == "debug") {
 | 
			
		||||
 | 
			
		||||
@ -69,6 +69,11 @@ public:
 | 
			
		||||
            Swagger::SWGLocationInformation& response,
 | 
			
		||||
            Swagger::SWGErrorResponse& error);
 | 
			
		||||
 | 
			
		||||
    virtual int instanceDVSerialPatch(
 | 
			
		||||
            bool dvserial,
 | 
			
		||||
            Swagger::SWGDVSeralDevices& response,
 | 
			
		||||
            Swagger::SWGErrorResponse& error);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    MainWindow& m_mainWindow;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -714,6 +714,12 @@ definitions:
 | 
			
		||||
        description: "Device names of DV serial devices"
 | 
			
		||||
        type: array
 | 
			
		||||
        items:
 | 
			
		||||
          $ref: "#/definitions/DVSerialDevice"
 | 
			
		||||
  DVSerialDevice:
 | 
			
		||||
    description: "DV serial device details"
 | 
			
		||||
    properties:
 | 
			
		||||
      deviceName:
 | 
			
		||||
        description: "Name of the serial device in the system"
 | 
			
		||||
        type: string
 | 
			
		||||
  Presets:
 | 
			
		||||
    description: "Settings presets"
 | 
			
		||||
 | 
			
		||||
@ -832,11 +832,20 @@ margin-bottom: 20px;
 | 
			
		||||
      "type" : "array",
 | 
			
		||||
      "description" : "Device names of DV serial devices",
 | 
			
		||||
      "items" : {
 | 
			
		||||
        "type" : "string"
 | 
			
		||||
        "$ref" : "#/definitions/DVSerialDevice"
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "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 = {
 | 
			
		||||
  "required" : [ "hwType" ],
 | 
			
		||||
@ -7384,7 +7393,7 @@ except ApiException as e:
 | 
			
		||||
          </div>
 | 
			
		||||
          <div id="generator">
 | 
			
		||||
            <div class="content">
 | 
			
		||||
              Generated 2017-11-24T17:11:18.943+01:00
 | 
			
		||||
              Generated 2017-11-25T04:38:54.817+01:00
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
@ -38,7 +38,7 @@ SWGDVSeralDevices::~SWGDVSeralDevices() {
 | 
			
		||||
void
 | 
			
		||||
SWGDVSeralDevices::init() {
 | 
			
		||||
    nb_devices = 0;
 | 
			
		||||
    dv_serial_devices = new QList<QString*>();
 | 
			
		||||
    dv_serial_devices = new QList<SWGDVSerialDevice*>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
@ -46,8 +46,8 @@ SWGDVSeralDevices::cleanup() {
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    if(dv_serial_devices != nullptr) {
 | 
			
		||||
        QList<QString*>* arr = dv_serial_devices;
 | 
			
		||||
        foreach(QString* o, *arr) {
 | 
			
		||||
        QList<SWGDVSerialDevice*>* arr = dv_serial_devices;
 | 
			
		||||
        foreach(SWGDVSerialDevice* o, *arr) {
 | 
			
		||||
            delete o;
 | 
			
		||||
        }
 | 
			
		||||
        delete dv_serial_devices;
 | 
			
		||||
@ -67,7 +67,7 @@ void
 | 
			
		||||
SWGDVSeralDevices::fromJsonObject(QJsonObject &pJson) {
 | 
			
		||||
    ::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));
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
 | 
			
		||||
    return obj;
 | 
			
		||||
@ -103,12 +103,12 @@ SWGDVSeralDevices::setNbDevices(qint32 nb_devices) {
 | 
			
		||||
    this->nb_devices = nb_devices;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QList<QString*>*
 | 
			
		||||
QList<SWGDVSerialDevice*>*
 | 
			
		||||
SWGDVSeralDevices::getDvSerialDevices() {
 | 
			
		||||
    return dv_serial_devices;
 | 
			
		||||
}
 | 
			
		||||
void
 | 
			
		||||
SWGDVSeralDevices::setDvSerialDevices(QList<QString*>* dv_serial_devices) {
 | 
			
		||||
SWGDVSeralDevices::setDvSerialDevices(QList<SWGDVSerialDevice*>* dv_serial_devices) {
 | 
			
		||||
    this->dv_serial_devices = dv_serial_devices;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -22,8 +22,8 @@
 | 
			
		||||
#include <QJsonObject>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "SWGDVSerialDevice.h"
 | 
			
		||||
#include <QList>
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
#include "SWGObject.h"
 | 
			
		||||
 | 
			
		||||
@ -46,13 +46,13 @@ public:
 | 
			
		||||
    qint32 getNbDevices();
 | 
			
		||||
    void setNbDevices(qint32 nb_devices);
 | 
			
		||||
 | 
			
		||||
    QList<QString*>* getDvSerialDevices();
 | 
			
		||||
    void setDvSerialDevices(QList<QString*>* dv_serial_devices);
 | 
			
		||||
    QList<SWGDVSerialDevice*>* getDvSerialDevices();
 | 
			
		||||
    void setDvSerialDevices(QList<SWGDVSerialDevice*>* dv_serial_devices);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    qint32 nb_devices;
 | 
			
		||||
    QList<QString*>* dv_serial_devices;
 | 
			
		||||
    QList<SWGDVSerialDevice*>* dv_serial_devices;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -20,6 +20,7 @@
 | 
			
		||||
#include "SWGChannel.h"
 | 
			
		||||
#include "SWGChannelListItem.h"
 | 
			
		||||
#include "SWGDVSeralDevices.h"
 | 
			
		||||
#include "SWGDVSerialDevice.h"
 | 
			
		||||
#include "SWGDeviceListItem.h"
 | 
			
		||||
#include "SWGDeviceSet.h"
 | 
			
		||||
#include "SWGDeviceSetList.h"
 | 
			
		||||
@ -58,6 +59,9 @@ namespace Swagger {
 | 
			
		||||
    if(QString("SWGDVSeralDevices").compare(type) == 0) {
 | 
			
		||||
      return new SWGDVSeralDevices();
 | 
			
		||||
    }
 | 
			
		||||
    if(QString("SWGDVSerialDevice").compare(type) == 0) {
 | 
			
		||||
      return new SWGDVSerialDevice();
 | 
			
		||||
    }
 | 
			
		||||
    if(QString("SWGDeviceListItem").compare(type) == 0) {
 | 
			
		||||
      return new SWGDeviceListItem();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user