From 30cca075547b90a9da1ee2722fc76828bd59ef98 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 26 May 2018 02:33:35 +0200 Subject: [PATCH] Web API: AirspyHF device report --- plugins/samplesource/airspy/airspyinput.cpp | 1 - .../samplesource/airspyhf/airspyhfinput.cpp | 23 ++++ plugins/samplesource/airspyhf/airspyhfinput.h | 5 + sdrbase/resources/webapi/doc/html2/index.html | 16 ++- .../webapi/doc/swagger/include/AirspyHF.yaml | 14 ++- .../resources/webapi/doc/swagger/swagger.yaml | 2 + .../api/swagger/include/AirspyHF.yaml | 14 ++- swagger/sdrangel/api/swagger/swagger.yaml | 2 + swagger/sdrangel/code/html2/index.html | 16 ++- .../code/qt5/client/SWGAirspyHFReport.cpp | 112 ++++++++++++++++++ .../code/qt5/client/SWGAirspyHFReport.h | 60 ++++++++++ .../code/qt5/client/SWGDeviceReport.cpp | 23 ++++ .../code/qt5/client/SWGDeviceReport.h | 7 ++ .../code/qt5/client/SWGModelFactory.h | 4 + 14 files changed, 294 insertions(+), 5 deletions(-) create mode 100644 swagger/sdrangel/code/qt5/client/SWGAirspyHFReport.cpp create mode 100644 swagger/sdrangel/code/qt5/client/SWGAirspyHFReport.h diff --git a/plugins/samplesource/airspy/airspyinput.cpp b/plugins/samplesource/airspy/airspyinput.cpp index da89e98a0..0beea475e 100644 --- a/plugins/samplesource/airspy/airspyinput.cpp +++ b/plugins/samplesource/airspy/airspyinput.cpp @@ -742,7 +742,6 @@ void AirspyInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& res void AirspyInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response) { - response.setAirspyReport(new SWGSDRangel::SWGAirspyReport()); response.getAirspyReport()->setSampleRates(new QList); for (std::vector::const_iterator it = getSampleRates().begin(); it != getSampleRates().end(); ++it) diff --git a/plugins/samplesource/airspyhf/airspyhfinput.cpp b/plugins/samplesource/airspyhf/airspyhfinput.cpp index b076ed10c..0009ddc8f 100644 --- a/plugins/samplesource/airspyhf/airspyhfinput.cpp +++ b/plugins/samplesource/airspyhf/airspyhfinput.cpp @@ -20,6 +20,8 @@ #include "SWGDeviceSettings.h" #include "SWGDeviceState.h" +#include "SWGDeviceReport.h" +#include "SWGAirspyHFReport.h" #include #include @@ -561,6 +563,27 @@ void AirspyHFInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& r } } +void AirspyHFInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response) +{ + response.getAirspyHfReport()->setSampleRates(new QList); + + for (std::vector::const_iterator it = getSampleRates().begin(); it != getSampleRates().end(); ++it) + { + response.getAirspyHfReport()->getSampleRates()->append(new SWGSDRangel::SWGAirspyReport_sampleRates); + response.getAirspyHfReport()->getSampleRates()->back()->setSampleRate(*it); + } +} + +int AirspyHFInput::webapiReportGet( + SWGSDRangel::SWGDeviceReport& response, + QString& errorMessage __attribute__((unused))) +{ + response.setAirspyHfReport(new SWGSDRangel::SWGAirspyHFReport()); + response.getAirspyHfReport()->init(); + webapiFormatDeviceReport(response); + return 200; +} + int AirspyHFInput::webapiRunGet( SWGSDRangel::SWGDeviceState& response, QString& errorMessage __attribute__((unused))) diff --git a/plugins/samplesource/airspyhf/airspyhfinput.h b/plugins/samplesource/airspyhf/airspyhfinput.h index 4392841c0..bb5e5e213 100644 --- a/plugins/samplesource/airspyhf/airspyhfinput.h +++ b/plugins/samplesource/airspyhf/airspyhfinput.h @@ -122,6 +122,10 @@ public: SWGSDRangel::SWGDeviceSettings& response, // query + response QString& errorMessage); + virtual int webapiReportGet( + SWGSDRangel::SWGDeviceReport& response, + QString& errorMessage); + virtual int webapiRunGet( SWGSDRangel::SWGDeviceState& response, QString& errorMessage); @@ -143,6 +147,7 @@ private: airspyhf_device_t *open_airspyhf_from_serial(const QString& serialStr); void setDeviceCenterFrequency(quint64 freq, const AirspyHFSettings& settings); void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const AirspyHFSettings& settings); + void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response); DeviceSourceAPI *m_deviceAPI; QMutex m_mutex; diff --git a/sdrbase/resources/webapi/doc/html2/index.html b/sdrbase/resources/webapi/doc/html2/index.html index 78e660702..5a04f8ddb 100644 --- a/sdrbase/resources/webapi/doc/html2/index.html +++ b/sdrbase/resources/webapi/doc/html2/index.html @@ -911,6 +911,17 @@ margin-bottom: 20px; } }, "description" : "ATVMod" +}; + defs.AirspyHFReport = { + "properties" : { + "sampleRates" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/AirspyReport_sampleRates" + } + } + }, + "description" : "AirspyHF" }; defs.AirspyHFSettings = { "properties" : { @@ -1697,6 +1708,9 @@ margin-bottom: 20px; }, "airspyReport" : { "$ref" : "#/definitions/AirspyReport" + }, + "airspyHFReport" : { + "$ref" : "#/definitions/AirspyHFReport" } }, "description" : "Base device report. The specific device report present depeds on deviceHwType" @@ -21681,7 +21695,7 @@ except ApiException as e:
- Generated 2018-05-26T00:44:20.967+02:00 + Generated 2018-05-26T02:22:55.108+02:00
diff --git a/sdrbase/resources/webapi/doc/swagger/include/AirspyHF.yaml b/sdrbase/resources/webapi/doc/swagger/include/AirspyHF.yaml index 0ec9d4f93..e0317e414 100644 --- a/sdrbase/resources/webapi/doc/swagger/include/AirspyHF.yaml +++ b/sdrbase/resources/webapi/doc/swagger/include/AirspyHF.yaml @@ -19,4 +19,16 @@ AirspyHFSettings: type: integer fileRecordName: type: string - \ No newline at end of file + +AirspyHFReport: + description: AirspyHF + properties: + sampleRates: + type: array + items: + properties: + sampleRate: + description: sample rate in S/s + type: integer + + \ No newline at end of file diff --git a/sdrbase/resources/webapi/doc/swagger/swagger.yaml b/sdrbase/resources/webapi/doc/swagger/swagger.yaml index 746cffbe1..62f07987c 100644 --- a/sdrbase/resources/webapi/doc/swagger/swagger.yaml +++ b/sdrbase/resources/webapi/doc/swagger/swagger.yaml @@ -1781,6 +1781,8 @@ definitions: type: integer airspyReport: $ref: "/doc/swagger/include/Airspy.yaml#/AirspyReport" + airspyHFReport: + $ref: "/doc/swagger/include/AirspyHF.yaml#/AirspyHFReport" ChannelSettings: description: Base channel settings. The specific channel settings present depends on channelType. diff --git a/swagger/sdrangel/api/swagger/include/AirspyHF.yaml b/swagger/sdrangel/api/swagger/include/AirspyHF.yaml index 0ec9d4f93..e0317e414 100644 --- a/swagger/sdrangel/api/swagger/include/AirspyHF.yaml +++ b/swagger/sdrangel/api/swagger/include/AirspyHF.yaml @@ -19,4 +19,16 @@ AirspyHFSettings: type: integer fileRecordName: type: string - \ No newline at end of file + +AirspyHFReport: + description: AirspyHF + properties: + sampleRates: + type: array + items: + properties: + sampleRate: + description: sample rate in S/s + type: integer + + \ No newline at end of file diff --git a/swagger/sdrangel/api/swagger/swagger.yaml b/swagger/sdrangel/api/swagger/swagger.yaml index 9408a65c8..1c6fb1704 100644 --- a/swagger/sdrangel/api/swagger/swagger.yaml +++ b/swagger/sdrangel/api/swagger/swagger.yaml @@ -1781,6 +1781,8 @@ definitions: type: integer airspyReport: $ref: "http://localhost:8081/api/swagger/include/Airspy.yaml#/AirspyReport" + airspyHFReport: + $ref: "http://localhost:8081/api/swagger/include/AirspyHF.yaml#/AirspyHFReport" ChannelSettings: description: Base channel settings. The specific channel settings present depends on channelType. diff --git a/swagger/sdrangel/code/html2/index.html b/swagger/sdrangel/code/html2/index.html index 78e660702..5a04f8ddb 100644 --- a/swagger/sdrangel/code/html2/index.html +++ b/swagger/sdrangel/code/html2/index.html @@ -911,6 +911,17 @@ margin-bottom: 20px; } }, "description" : "ATVMod" +}; + defs.AirspyHFReport = { + "properties" : { + "sampleRates" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/AirspyReport_sampleRates" + } + } + }, + "description" : "AirspyHF" }; defs.AirspyHFSettings = { "properties" : { @@ -1697,6 +1708,9 @@ margin-bottom: 20px; }, "airspyReport" : { "$ref" : "#/definitions/AirspyReport" + }, + "airspyHFReport" : { + "$ref" : "#/definitions/AirspyHFReport" } }, "description" : "Base device report. The specific device report present depeds on deviceHwType" @@ -21681,7 +21695,7 @@ except ApiException as e:
- Generated 2018-05-26T00:44:20.967+02:00 + Generated 2018-05-26T02:22:55.108+02:00
diff --git a/swagger/sdrangel/code/qt5/client/SWGAirspyHFReport.cpp b/swagger/sdrangel/code/qt5/client/SWGAirspyHFReport.cpp new file mode 100644 index 000000000..e7e1da594 --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGAirspyHFReport.cpp @@ -0,0 +1,112 @@ +/** + * SDRangel + * This is the web REST/JSON API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ (4.3+ in Windows) GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube --- Limitations and specifcities: * In SDRangel GUI the first Rx device set cannot be deleted. Conversely the server starts with no device sets and its number of device sets can be reduced to zero by as many calls as necessary to /sdrangel/deviceset with DELETE method. * Stopping instance i.e. /sdrangel with DELETE method is a server only feature. It allows stopping the instance nicely. * Preset import and export from/to file is a server only feature. * Device set focus is a GUI only feature. * The following channels are not implemented (status 501 is returned): ATV demodulator, Channel Analyzer, Channel Analyzer NG, LoRa demodulator, TCP source * The content type returned is always application/json except in the following cases: * An incorrect URL was specified: this document is returned as text/html with a status 400 --- + * + * OpenAPI spec version: 4.0.0 + * Contact: f4exb06@gmail.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +#include "SWGAirspyHFReport.h" + +#include "SWGHelpers.h" + +#include +#include +#include +#include + +namespace SWGSDRangel { + +SWGAirspyHFReport::SWGAirspyHFReport(QString* json) { + init(); + this->fromJson(*json); +} + +SWGAirspyHFReport::SWGAirspyHFReport() { + sample_rates = nullptr; + m_sample_rates_isSet = false; +} + +SWGAirspyHFReport::~SWGAirspyHFReport() { + this->cleanup(); +} + +void +SWGAirspyHFReport::init() { + sample_rates = new QList(); + m_sample_rates_isSet = false; +} + +void +SWGAirspyHFReport::cleanup() { + if(sample_rates != nullptr) { + auto arr = sample_rates; + for(auto o: *arr) { + delete o; + } + delete sample_rates; + } +} + +SWGAirspyHFReport* +SWGAirspyHFReport::fromJson(QString &json) { + QByteArray array (json.toStdString().c_str()); + QJsonDocument doc = QJsonDocument::fromJson(array); + QJsonObject jsonObject = doc.object(); + this->fromJsonObject(jsonObject); + return this; +} + +void +SWGAirspyHFReport::fromJsonObject(QJsonObject &pJson) { + + ::SWGSDRangel::setValue(&sample_rates, pJson["sampleRates"], "QList", "SWGAirspyReport_sampleRates"); +} + +QString +SWGAirspyHFReport::asJson () +{ + QJsonObject* obj = this->asJsonObject(); + + QJsonDocument doc(*obj); + QByteArray bytes = doc.toJson(); + delete obj; + return QString(bytes); +} + +QJsonObject* +SWGAirspyHFReport::asJsonObject() { + QJsonObject* obj = new QJsonObject(); + if(sample_rates->size() > 0){ + toJsonArray((QList*)sample_rates, obj, "sampleRates", "SWGAirspyReport_sampleRates"); + } + + return obj; +} + +QList* +SWGAirspyHFReport::getSampleRates() { + return sample_rates; +} +void +SWGAirspyHFReport::setSampleRates(QList* sample_rates) { + this->sample_rates = sample_rates; + this->m_sample_rates_isSet = true; +} + + +bool +SWGAirspyHFReport::isSet(){ + bool isObjectUpdated = false; + do{ + if(sample_rates->size() > 0){ isObjectUpdated = true; break;} + }while(false); + return isObjectUpdated; +} +} + diff --git a/swagger/sdrangel/code/qt5/client/SWGAirspyHFReport.h b/swagger/sdrangel/code/qt5/client/SWGAirspyHFReport.h new file mode 100644 index 000000000..668dd2c50 --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGAirspyHFReport.h @@ -0,0 +1,60 @@ +/** + * SDRangel + * This is the web REST/JSON API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ (4.3+ in Windows) GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube --- Limitations and specifcities: * In SDRangel GUI the first Rx device set cannot be deleted. Conversely the server starts with no device sets and its number of device sets can be reduced to zero by as many calls as necessary to /sdrangel/deviceset with DELETE method. * Stopping instance i.e. /sdrangel with DELETE method is a server only feature. It allows stopping the instance nicely. * Preset import and export from/to file is a server only feature. * Device set focus is a GUI only feature. * The following channels are not implemented (status 501 is returned): ATV demodulator, Channel Analyzer, Channel Analyzer NG, LoRa demodulator, TCP source * The content type returned is always application/json except in the following cases: * An incorrect URL was specified: this document is returned as text/html with a status 400 --- + * + * OpenAPI spec version: 4.0.0 + * Contact: f4exb06@gmail.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * SWGAirspyHFReport.h + * + * AirspyHF + */ + +#ifndef SWGAirspyHFReport_H_ +#define SWGAirspyHFReport_H_ + +#include + + +#include "SWGAirspyReport_sampleRates.h" +#include + +#include "SWGObject.h" +#include "export.h" + +namespace SWGSDRangel { + +class SWG_API SWGAirspyHFReport: public SWGObject { +public: + SWGAirspyHFReport(); + SWGAirspyHFReport(QString* json); + virtual ~SWGAirspyHFReport(); + void init(); + void cleanup(); + + virtual QString asJson () override; + virtual QJsonObject* asJsonObject() override; + virtual void fromJsonObject(QJsonObject &json) override; + virtual SWGAirspyHFReport* fromJson(QString &jsonString) override; + + QList* getSampleRates(); + void setSampleRates(QList* sample_rates); + + + virtual bool isSet() override; + +private: + QList* sample_rates; + bool m_sample_rates_isSet; + +}; + +} + +#endif /* SWGAirspyHFReport_H_ */ diff --git a/swagger/sdrangel/code/qt5/client/SWGDeviceReport.cpp b/swagger/sdrangel/code/qt5/client/SWGDeviceReport.cpp index f1212ae30..8eead58ba 100644 --- a/swagger/sdrangel/code/qt5/client/SWGDeviceReport.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGDeviceReport.cpp @@ -34,6 +34,8 @@ SWGDeviceReport::SWGDeviceReport() { m_tx_isSet = false; airspy_report = nullptr; m_airspy_report_isSet = false; + airspy_hf_report = nullptr; + m_airspy_hf_report_isSet = false; } SWGDeviceReport::~SWGDeviceReport() { @@ -48,6 +50,8 @@ SWGDeviceReport::init() { m_tx_isSet = false; airspy_report = new SWGAirspyReport(); m_airspy_report_isSet = false; + airspy_hf_report = new SWGAirspyHFReport(); + m_airspy_hf_report_isSet = false; } void @@ -59,6 +63,9 @@ SWGDeviceReport::cleanup() { if(airspy_report != nullptr) { delete airspy_report; } + if(airspy_hf_report != nullptr) { + delete airspy_hf_report; + } } SWGDeviceReport* @@ -78,6 +85,8 @@ SWGDeviceReport::fromJsonObject(QJsonObject &pJson) { ::SWGSDRangel::setValue(&airspy_report, pJson["airspyReport"], "SWGAirspyReport", "SWGAirspyReport"); + ::SWGSDRangel::setValue(&airspy_hf_report, pJson["airspyHFReport"], "SWGAirspyHFReport", "SWGAirspyHFReport"); + } QString @@ -103,6 +112,9 @@ SWGDeviceReport::asJsonObject() { if((airspy_report != nullptr) && (airspy_report->isSet())){ toJsonValue(QString("airspyReport"), airspy_report, obj, QString("SWGAirspyReport")); } + if((airspy_hf_report != nullptr) && (airspy_hf_report->isSet())){ + toJsonValue(QString("airspyHFReport"), airspy_hf_report, obj, QString("SWGAirspyHFReport")); + } return obj; } @@ -137,6 +149,16 @@ SWGDeviceReport::setAirspyReport(SWGAirspyReport* airspy_report) { this->m_airspy_report_isSet = true; } +SWGAirspyHFReport* +SWGDeviceReport::getAirspyHfReport() { + return airspy_hf_report; +} +void +SWGDeviceReport::setAirspyHfReport(SWGAirspyHFReport* airspy_hf_report) { + this->airspy_hf_report = airspy_hf_report; + this->m_airspy_hf_report_isSet = true; +} + bool SWGDeviceReport::isSet(){ @@ -145,6 +167,7 @@ SWGDeviceReport::isSet(){ if(device_hw_type != nullptr && *device_hw_type != QString("")){ isObjectUpdated = true; break;} if(m_tx_isSet){ isObjectUpdated = true; break;} if(airspy_report != nullptr && airspy_report->isSet()){ isObjectUpdated = true; break;} + if(airspy_hf_report != nullptr && airspy_hf_report->isSet()){ isObjectUpdated = true; break;} }while(false); return isObjectUpdated; } diff --git a/swagger/sdrangel/code/qt5/client/SWGDeviceReport.h b/swagger/sdrangel/code/qt5/client/SWGDeviceReport.h index 7f9bb02f0..8b7b0f1b3 100644 --- a/swagger/sdrangel/code/qt5/client/SWGDeviceReport.h +++ b/swagger/sdrangel/code/qt5/client/SWGDeviceReport.h @@ -22,6 +22,7 @@ #include +#include "SWGAirspyHFReport.h" #include "SWGAirspyReport.h" #include @@ -52,6 +53,9 @@ public: SWGAirspyReport* getAirspyReport(); void setAirspyReport(SWGAirspyReport* airspy_report); + SWGAirspyHFReport* getAirspyHfReport(); + void setAirspyHfReport(SWGAirspyHFReport* airspy_hf_report); + virtual bool isSet() override; @@ -65,6 +69,9 @@ private: SWGAirspyReport* airspy_report; bool m_airspy_report_isSet; + SWGAirspyHFReport* airspy_hf_report; + bool m_airspy_hf_report_isSet; + }; } diff --git a/swagger/sdrangel/code/qt5/client/SWGModelFactory.h b/swagger/sdrangel/code/qt5/client/SWGModelFactory.h index 6aae27271..0e413ef74 100644 --- a/swagger/sdrangel/code/qt5/client/SWGModelFactory.h +++ b/swagger/sdrangel/code/qt5/client/SWGModelFactory.h @@ -20,6 +20,7 @@ #include "SWGAMModSettings.h" #include "SWGATVModReport.h" #include "SWGATVModSettings.h" +#include "SWGAirspyHFReport.h" #include "SWGAirspyHFSettings.h" #include "SWGAirspyReport.h" #include "SWGAirspyReport_sampleRates.h" @@ -106,6 +107,9 @@ namespace SWGSDRangel { if(QString("SWGATVModSettings").compare(type) == 0) { return new SWGATVModSettings(); } + if(QString("SWGAirspyHFReport").compare(type) == 0) { + return new SWGAirspyHFReport(); + } if(QString("SWGAirspyHFSettings").compare(type) == 0) { return new SWGAirspyHFSettings(); }