KiwiSDR: implemented report in REST API

This commit is contained in:
f4exb 2019-06-09 00:56:31 +02:00
parent 8ea5606034
commit dc15668469
15 changed files with 284 additions and 3 deletions

View File

@ -26,6 +26,8 @@
#include "SWGDeviceSettings.h"
#include "SWGDeviceState.h"
#include "SWGDeviceReport.h"
#include "SWGKiwiSDRReport.h"
#include "kiwisdrinput.h"
#include "device/deviceapi.h"
@ -251,6 +253,15 @@ bool KiwiSDRInput::handleMessage(const Message& message)
}
}
int KiwiSDRInput::getStatus() const
{
if (m_kiwiSDRWorker) {
return m_kiwiSDRWorker->getStatus();
} else {
return 0;
}
}
bool KiwiSDRInput::applySettings(const KiwiSDRSettings& settings, bool force)
{
QList<QString> reverseAPIKeys;
@ -376,6 +387,17 @@ int KiwiSDRInput::webapiSettingsPutPatch(
return 200;
}
int KiwiSDRInput::webapiReportGet(
SWGSDRangel::SWGDeviceReport& response,
QString& errorMessage)
{
(void) errorMessage;
response.setKiwiSdrReport(new SWGSDRangel::SWGKiwiSDRReport());
response.getKiwiSdrReport()->init();
webapiFormatDeviceReport(response);
return 200;
}
void KiwiSDRInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const KiwiSDRSettings& settings)
{
response.getKiwiSdrSettings()->setGain(settings.m_gain);
@ -389,6 +411,11 @@ void KiwiSDRInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& re
}
}
void KiwiSDRInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
{
response.getKiwiSdrReport()->setStatus(getStatus());
}
void KiwiSDRInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const KiwiSDRSettings& settings, bool force)
{
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();

View File

@ -156,6 +156,10 @@ public:
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage);
virtual int webapiReportGet(
SWGSDRangel::SWGDeviceReport& response,
QString& errorMessage);
private:
DeviceAPI *m_deviceAPI;
FileRecord *m_fileSink; //!< File sink to record device I/Q output
@ -169,8 +173,10 @@ private:
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
int getStatus() const;
bool applySettings(const KiwiSDRSettings& settings, bool force);
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const KiwiSDRSettings& settings);
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const KiwiSDRSettings& settings, bool force);
void webapiReverseSendStartStop(bool start);

View File

@ -25,7 +25,8 @@ KiwiSDRWorker::KiwiSDRWorker(SampleSinkFifo* sampleFifo)
m_samplesBuf(),
m_centerFrequency(1450000),
m_gain(20),
m_useAGC(true)
m_useAGC(true),
m_status(0)
{
connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
@ -48,11 +49,13 @@ void KiwiSDRWorker::onConnected()
void KiwiSDRWorker::onDisconnected()
{
qDebug("KiwiSDRWorker::onDisconnected");
m_status = 4;
emit updateStatus(4);
}
void KiwiSDRWorker::onSocketError(QAbstractSocket::SocketError error)
{
m_status = 3;
emit updateStatus(3);
}
@ -91,6 +94,7 @@ void KiwiSDRWorker::onBinaryMessageReceived(const QByteArray &message)
sendGain();
sendCenterFrequency();
m_timer.start(5000);
m_status = 2;
emit updateStatus(2);
}
}
@ -139,6 +143,7 @@ void KiwiSDRWorker::onServerAddressChanged(QString serverAddress)
return;
m_serverAddress = serverAddress;
m_status = 1;
emit updateStatus(1);
QString url("ws://");

View File

@ -28,6 +28,7 @@ class KiwiSDRWorker : public QObject {
public:
KiwiSDRWorker(SampleSinkFifo* sampleFifo);
int getStatus() const { return m_status; }
private:
QTimer m_timer;
@ -42,6 +43,8 @@ private:
uint32_t m_gain;
bool m_useAGC;
int m_status; //!< See GUI for status number detail
void sendCenterFrequency();
void sendGain();

View File

@ -2163,6 +2163,9 @@ margin-bottom: 20px;
"limeSdrInputReport" : {
"$ref" : "#/definitions/LimeSdrInputReport"
},
"kiwiSDRReport" : {
"$ref" : "#/definitions/KiwiSDRReport"
},
"limeSdrOutputReport" : {
"$ref" : "#/definitions/LimeSdrOutputReport"
},
@ -3076,6 +3079,15 @@ margin-bottom: 20px;
}
},
"description" : "Summarized information about this SDRangel instance"
};
defs.KiwiSDRReport = {
"properties" : {
"status" : {
"type" : "integer",
"description" : "0 for Idle, 1 for Connecting, 2 for Connected, 3 for Error, 4 for Disconnected"
}
},
"description" : "KiwiSDR"
};
defs.KiwiSDRSettings = {
"properties" : {
@ -25136,7 +25148,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2019-06-08T11:06:14.976+02:00
Generated 2019-06-08T23:46:41.204+02:00
</div>
</div>
</div>

View File

@ -21,3 +21,10 @@ KiwiSDRSettings:
type: integer
reverseAPIDeviceIndex:
type: integer
KiwiSDRReport:
description: KiwiSDR
properties:
status:
description: 0 for Idle, 1 for Connecting, 2 for Connected, 3 for Error, 4 for Disconnected
type: integer

View File

@ -1865,6 +1865,8 @@ definitions:
$ref: "/doc/swagger/include/FileSource.yaml#/FileSourceReport"
limeSdrInputReport:
$ref: "/doc/swagger/include/LimeSdr.yaml#/LimeSdrInputReport"
kiwiSDRReport:
$ref: "/doc/swagger/include/KiwiSDR.yaml#/KiwiSDRReport"
limeSdrOutputReport:
$ref: "/doc/swagger/include/LimeSdr.yaml#/LimeSdrOutputReport"
localInputReport:

View File

@ -21,3 +21,10 @@ KiwiSDRSettings:
type: integer
reverseAPIDeviceIndex:
type: integer
KiwiSDRReport:
description: KiwiSDR
properties:
status:
description: 0 for Idle, 1 for Connecting, 2 for Connected, 3 for Error, 4 for Disconnected
type: integer

View File

@ -1865,6 +1865,8 @@ definitions:
$ref: "http://localhost:8081/api/swagger/include/FileSource.yaml#/FileSourceReport"
limeSdrInputReport:
$ref: "http://localhost:8081/api/swagger/include/LimeSdr.yaml#/LimeSdrInputReport"
kiwiSDRReport:
$ref: "http://localhost:8081/api/swagger/include/KiwiSDR.yaml#/KiwiSDRReport"
limeSdrOutputReport:
$ref: "http://localhost:8081/api/swagger/include/LimeSdr.yaml#/LimeSdrOutputReport"
localInputReport:

View File

@ -2163,6 +2163,9 @@ margin-bottom: 20px;
"limeSdrInputReport" : {
"$ref" : "#/definitions/LimeSdrInputReport"
},
"kiwiSDRReport" : {
"$ref" : "#/definitions/KiwiSDRReport"
},
"limeSdrOutputReport" : {
"$ref" : "#/definitions/LimeSdrOutputReport"
},
@ -3076,6 +3079,15 @@ margin-bottom: 20px;
}
},
"description" : "Summarized information about this SDRangel instance"
};
defs.KiwiSDRReport = {
"properties" : {
"status" : {
"type" : "integer",
"description" : "0 for Idle, 1 for Connecting, 2 for Connected, 3 for Error, 4 for Disconnected"
}
},
"description" : "KiwiSDR"
};
defs.KiwiSDRSettings = {
"properties" : {
@ -25136,7 +25148,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2019-06-08T11:06:14.976+02:00
Generated 2019-06-08T23:46:41.204+02:00
</div>
</div>
</div>

View File

@ -44,6 +44,8 @@ SWGDeviceReport::SWGDeviceReport() {
m_file_source_report_isSet = false;
lime_sdr_input_report = nullptr;
m_lime_sdr_input_report_isSet = false;
kiwi_sdr_report = nullptr;
m_kiwi_sdr_report_isSet = false;
lime_sdr_output_report = nullptr;
m_lime_sdr_output_report_isSet = false;
local_input_report = nullptr;
@ -96,6 +98,8 @@ SWGDeviceReport::init() {
m_file_source_report_isSet = false;
lime_sdr_input_report = new SWGLimeSdrInputReport();
m_lime_sdr_input_report_isSet = false;
kiwi_sdr_report = new SWGKiwiSDRReport();
m_kiwi_sdr_report_isSet = false;
lime_sdr_output_report = new SWGLimeSdrOutputReport();
m_lime_sdr_output_report_isSet = false;
local_input_report = new SWGLocalInputReport();
@ -150,6 +154,9 @@ SWGDeviceReport::cleanup() {
if(lime_sdr_input_report != nullptr) {
delete lime_sdr_input_report;
}
if(kiwi_sdr_report != nullptr) {
delete kiwi_sdr_report;
}
if(lime_sdr_output_report != nullptr) {
delete lime_sdr_output_report;
}
@ -221,6 +228,8 @@ SWGDeviceReport::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&lime_sdr_input_report, pJson["limeSdrInputReport"], "SWGLimeSdrInputReport", "SWGLimeSdrInputReport");
::SWGSDRangel::setValue(&kiwi_sdr_report, pJson["kiwiSDRReport"], "SWGKiwiSDRReport", "SWGKiwiSDRReport");
::SWGSDRangel::setValue(&lime_sdr_output_report, pJson["limeSdrOutputReport"], "SWGLimeSdrOutputReport", "SWGLimeSdrOutputReport");
::SWGSDRangel::setValue(&local_input_report, pJson["localInputReport"], "SWGLocalInputReport", "SWGLocalInputReport");
@ -289,6 +298,9 @@ SWGDeviceReport::asJsonObject() {
if((lime_sdr_input_report != nullptr) && (lime_sdr_input_report->isSet())){
toJsonValue(QString("limeSdrInputReport"), lime_sdr_input_report, obj, QString("SWGLimeSdrInputReport"));
}
if((kiwi_sdr_report != nullptr) && (kiwi_sdr_report->isSet())){
toJsonValue(QString("kiwiSDRReport"), kiwi_sdr_report, obj, QString("SWGKiwiSDRReport"));
}
if((lime_sdr_output_report != nullptr) && (lime_sdr_output_report->isSet())){
toJsonValue(QString("limeSdrOutputReport"), lime_sdr_output_report, obj, QString("SWGLimeSdrOutputReport"));
}
@ -415,6 +427,16 @@ SWGDeviceReport::setLimeSdrInputReport(SWGLimeSdrInputReport* lime_sdr_input_rep
this->m_lime_sdr_input_report_isSet = true;
}
SWGKiwiSDRReport*
SWGDeviceReport::getKiwiSdrReport() {
return kiwi_sdr_report;
}
void
SWGDeviceReport::setKiwiSdrReport(SWGKiwiSDRReport* kiwi_sdr_report) {
this->kiwi_sdr_report = kiwi_sdr_report;
this->m_kiwi_sdr_report_isSet = true;
}
SWGLimeSdrOutputReport*
SWGDeviceReport::getLimeSdrOutputReport() {
return lime_sdr_output_report;
@ -568,6 +590,7 @@ SWGDeviceReport::isSet(){
if(blade_rf2_output_report != nullptr && blade_rf2_output_report->isSet()){ isObjectUpdated = true; break;}
if(file_source_report != nullptr && file_source_report->isSet()){ isObjectUpdated = true; break;}
if(lime_sdr_input_report != nullptr && lime_sdr_input_report->isSet()){ isObjectUpdated = true; break;}
if(kiwi_sdr_report != nullptr && kiwi_sdr_report->isSet()){ isObjectUpdated = true; break;}
if(lime_sdr_output_report != nullptr && lime_sdr_output_report->isSet()){ isObjectUpdated = true; break;}
if(local_input_report != nullptr && local_input_report->isSet()){ isObjectUpdated = true; break;}
if(local_output_report != nullptr && local_output_report->isSet()){ isObjectUpdated = true; break;}

View File

@ -27,6 +27,7 @@
#include "SWGBladeRF2InputReport.h"
#include "SWGBladeRF2OutputReport.h"
#include "SWGFileSourceReport.h"
#include "SWGKiwiSDRReport.h"
#include "SWGLimeSdrInputReport.h"
#include "SWGLimeSdrOutputReport.h"
#include "SWGLocalInputReport.h"
@ -85,6 +86,9 @@ public:
SWGLimeSdrInputReport* getLimeSdrInputReport();
void setLimeSdrInputReport(SWGLimeSdrInputReport* lime_sdr_input_report);
SWGKiwiSDRReport* getKiwiSdrReport();
void setKiwiSdrReport(SWGKiwiSDRReport* kiwi_sdr_report);
SWGLimeSdrOutputReport* getLimeSdrOutputReport();
void setLimeSdrOutputReport(SWGLimeSdrOutputReport* lime_sdr_output_report);
@ -155,6 +159,9 @@ private:
SWGLimeSdrInputReport* lime_sdr_input_report;
bool m_lime_sdr_input_report_isSet;
SWGKiwiSDRReport* kiwi_sdr_report;
bool m_kiwi_sdr_report_isSet;
SWGLimeSdrOutputReport* lime_sdr_output_report;
bool m_lime_sdr_output_report_isSet;

View File

@ -0,0 +1,106 @@
/**
* 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. * 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 and DATV demodulators, Channel Analyzer NG, LoRa demodulator * The device settings and report structures contains only the sub-structure corresponding to the device type. The DeviceSettings and DeviceReport structures documented here shows all of them but only one will be or should be present at a time * The channel settings and report structures contains only the sub-structure corresponding to the channel type. The ChannelSettings and ChannelReport structures documented here shows all of them but only one will be or should be present at a time ---
*
* OpenAPI spec version: 4.8.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 "SWGKiwiSDRReport.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace SWGSDRangel {
SWGKiwiSDRReport::SWGKiwiSDRReport(QString* json) {
init();
this->fromJson(*json);
}
SWGKiwiSDRReport::SWGKiwiSDRReport() {
status = 0;
m_status_isSet = false;
}
SWGKiwiSDRReport::~SWGKiwiSDRReport() {
this->cleanup();
}
void
SWGKiwiSDRReport::init() {
status = 0;
m_status_isSet = false;
}
void
SWGKiwiSDRReport::cleanup() {
}
SWGKiwiSDRReport*
SWGKiwiSDRReport::fromJson(QString &json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGKiwiSDRReport::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&status, pJson["status"], "qint32", "");
}
QString
SWGKiwiSDRReport::asJson ()
{
QJsonObject* obj = this->asJsonObject();
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson();
delete obj;
return QString(bytes);
}
QJsonObject*
SWGKiwiSDRReport::asJsonObject() {
QJsonObject* obj = new QJsonObject();
if(m_status_isSet){
obj->insert("status", QJsonValue(status));
}
return obj;
}
qint32
SWGKiwiSDRReport::getStatus() {
return status;
}
void
SWGKiwiSDRReport::setStatus(qint32 status) {
this->status = status;
this->m_status_isSet = true;
}
bool
SWGKiwiSDRReport::isSet(){
bool isObjectUpdated = false;
do{
if(m_status_isSet){ isObjectUpdated = true; break;}
}while(false);
return isObjectUpdated;
}
}

View File

@ -0,0 +1,58 @@
/**
* 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. * 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 and DATV demodulators, Channel Analyzer NG, LoRa demodulator * The device settings and report structures contains only the sub-structure corresponding to the device type. The DeviceSettings and DeviceReport structures documented here shows all of them but only one will be or should be present at a time * The channel settings and report structures contains only the sub-structure corresponding to the channel type. The ChannelSettings and ChannelReport structures documented here shows all of them but only one will be or should be present at a time ---
*
* OpenAPI spec version: 4.8.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.
*/
/*
* SWGKiwiSDRReport.h
*
* KiwiSDR
*/
#ifndef SWGKiwiSDRReport_H_
#define SWGKiwiSDRReport_H_
#include <QJsonObject>
#include "SWGObject.h"
#include "export.h"
namespace SWGSDRangel {
class SWG_API SWGKiwiSDRReport: public SWGObject {
public:
SWGKiwiSDRReport();
SWGKiwiSDRReport(QString* json);
virtual ~SWGKiwiSDRReport();
void init();
void cleanup();
virtual QString asJson () override;
virtual QJsonObject* asJsonObject() override;
virtual void fromJsonObject(QJsonObject &json) override;
virtual SWGKiwiSDRReport* fromJson(QString &jsonString) override;
qint32 getStatus();
void setStatus(qint32 status);
virtual bool isSet() override;
private:
qint32 status;
bool m_status_isSet;
};
}
#endif /* SWGKiwiSDRReport_H_ */

View File

@ -75,6 +75,7 @@
#include "SWGInstanceChannelsResponse.h"
#include "SWGInstanceDevicesResponse.h"
#include "SWGInstanceSummaryResponse.h"
#include "SWGKiwiSDRReport.h"
#include "SWGKiwiSDRSettings.h"
#include "SWGLimeSdrInputReport.h"
#include "SWGLimeSdrInputSettings.h"
@ -335,6 +336,9 @@ namespace SWGSDRangel {
if(QString("SWGInstanceSummaryResponse").compare(type) == 0) {
return new SWGInstanceSummaryResponse();
}
if(QString("SWGKiwiSDRReport").compare(type) == 0) {
return new SWGKiwiSDRReport();
}
if(QString("SWGKiwiSDRSettings").compare(type) == 0) {
return new SWGKiwiSDRSettings();
}