File source input: implemeted WEB API for reporting

This commit is contained in:
f4exb 2018-05-26 11:40:37 +02:00
parent 268ad2b33f
commit 4c31da6c17
15 changed files with 510 additions and 6 deletions

View File

@ -714,7 +714,6 @@ int AirspyInput::webapiReportGet(
return 200;
}
void AirspyInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const AirspySettings& settings)
{
response.getAirspySettings()->setCenterFrequency(settings.m_centerFrequency);

View File

@ -337,7 +337,6 @@ void FileSourceGui::updateWithStreamTime()
t = t.addSecs(t_sec);
t = t.addMSecs(t_msec);
QString s_timems = t.toString("HH:mm:ss.zzz");
QString s_time = t.toString("HH:mm:ss");
ui->relTimeText->setText(s_timems);
quint64 startingTimeStampMsec = (quint64) m_startingTimeStamp * 1000LL;

View File

@ -21,6 +21,8 @@
#include "SWGDeviceSettings.h"
#include "SWGFileSourceSettings.h"
#include "SWGDeviceState.h"
#include "SWGDeviceReport.h"
#include "SWGFileSourceSettings.h"
#include "util/simpleserializer.h"
#include "dsp/dspcommands.h"
@ -376,3 +378,50 @@ int FileSourceInput::webapiRun(
return 200;
}
int FileSourceInput::webapiReportGet(
SWGSDRangel::SWGDeviceReport& response,
QString& errorMessage __attribute__((unused)))
{
response.setFileSourceReport(new SWGSDRangel::SWGFileSourceReport());
response.getFileSourceReport()->init();
webapiFormatDeviceReport(response);
return 200;
}
void FileSourceInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
{
int t_sec = 0;
int t_msec = 0;
std::size_t samplesCount = 0;
if (m_fileSourceThread) {
samplesCount = m_fileSourceThread->getSamplesCount();
}
if (m_sampleRate > 0)
{
t_sec = samplesCount / m_sampleRate;
t_msec = (samplesCount - (t_sec * m_sampleRate)) * 1000 / m_sampleRate;
}
QTime t(0, 0, 0, 0);
t = t.addSecs(t_sec);
t = t.addMSecs(t_msec);
response.getFileSourceReport()->setElapsedTime(new QString(t.toString("HH:mm:ss.zzz")));
quint64 startingTimeStampMsec = (quint64) m_startingTimeStamp * 1000LL;
QDateTime dt = QDateTime::fromMSecsSinceEpoch(startingTimeStampMsec);
dt = dt.addSecs((quint64) t_sec);
dt = dt.addMSecs((quint64) t_msec);
response.getFileSourceReport()->setAbsoluteTime(new QString(dt.toString("yyyy-MM-dd HH:mm:ss.zzz")));
QTime recordLength(0, 0, 0, 0);
recordLength = recordLength.addSecs(m_recordLength);
response.getFileSourceReport()->setDurationTime(new QString(recordLength.toString("HH:mm:ss")));
response.getFileSourceReport()->setFileName(new QString(m_fileName));
response.getFileSourceReport()->setSampleRate(m_sampleRate);
response.getFileSourceReport()->setSampleSize(m_sampleSize);
}

View File

@ -261,6 +261,10 @@ public:
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage);
virtual int webapiReportGet(
SWGSDRangel::SWGDeviceReport& response,
QString& errorMessage);
private:
DeviceSourceAPI *m_deviceAPI;
QMutex m_mutex;
@ -279,6 +283,7 @@ public:
void openFileStream();
void seekFileStream(int seekPercentage);
bool applySettings(const FileSourceSettings& settings, bool force = false);
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
};
#endif // INCLUDE_FILESOURCEINPUT_H

View File

@ -1711,6 +1711,9 @@ margin-bottom: 20px;
},
"airspyHFReport" : {
"$ref" : "#/definitions/AirspyHFReport"
},
"fileSourceReport" : {
"$ref" : "#/definitions/FileSourceReport"
}
},
"description" : "Base device report. The specific device report present depeds on deviceHwType"
@ -1953,6 +1956,34 @@ margin-bottom: 20px;
}
},
"description" : "FCDPro"
};
defs.FileSourceReport = {
"properties" : {
"fileName" : {
"type" : "string"
},
"sampleRate" : {
"type" : "integer",
"description" : "Record sample rate in S/s"
},
"sampleSize" : {
"type" : "integer",
"description" : "Record sample size in number of bits"
},
"absoluteTime" : {
"type" : "string",
"description" : "Absolute record time string representation"
},
"elapsedTime" : {
"type" : "string",
"description" : "Elapsed time since beginning string representation"
},
"durationTime" : {
"type" : "string",
"description" : "Duration time string representation"
}
},
"description" : "FileSource"
};
defs.FileSourceSettings = {
"properties" : {
@ -21830,7 +21861,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2018-05-26T10:50:36.916+02:00
Generated 2018-05-26T11:35:33.686+02:00
</div>
</div>
</div>

View File

@ -2,4 +2,26 @@ FileSourceSettings:
description: FileSource
properties:
fileName:
type: string
type: string
FileSourceReport:
description: FileSource
properties:
fileName:
type: string
sampleRate:
description: Record sample rate in S/s
type: integer
sampleSize:
description: Record sample size in number of bits
type: integer
absoluteTime:
description: Absolute record time string representation
type: string
elapsedTime:
description: Elapsed time since beginning string representation
type: string
durationTime:
description: Duration time string representation
type: string

View File

@ -1787,6 +1787,8 @@ definitions:
$ref: "/doc/swagger/include/Airspy.yaml#/AirspyReport"
airspyHFReport:
$ref: "/doc/swagger/include/AirspyHF.yaml#/AirspyHFReport"
fileSourceReport:
$ref: "/doc/swagger/include/FileSource.yaml#/FileSourceReport"
ChannelSettings:
description: Base channel settings. The specific channel settings present depends on channelType.

View File

@ -2,4 +2,26 @@ FileSourceSettings:
description: FileSource
properties:
fileName:
type: string
type: string
FileSourceReport:
description: FileSource
properties:
fileName:
type: string
sampleRate:
description: Record sample rate in S/s
type: integer
sampleSize:
description: Record sample size in number of bits
type: integer
absoluteTime:
description: Absolute record time string representation
type: string
elapsedTime:
description: Elapsed time since beginning string representation
type: string
durationTime:
description: Duration time string representation
type: string

View File

@ -1787,6 +1787,8 @@ definitions:
$ref: "http://localhost:8081/api/swagger/include/Airspy.yaml#/AirspyReport"
airspyHFReport:
$ref: "http://localhost:8081/api/swagger/include/AirspyHF.yaml#/AirspyHFReport"
fileSourceReport:
$ref: "http://localhost:8081/api/swagger/include/FileSource.yaml#/FileSourceReport"
ChannelSettings:
description: Base channel settings. The specific channel settings present depends on channelType.

View File

@ -1711,6 +1711,9 @@ margin-bottom: 20px;
},
"airspyHFReport" : {
"$ref" : "#/definitions/AirspyHFReport"
},
"fileSourceReport" : {
"$ref" : "#/definitions/FileSourceReport"
}
},
"description" : "Base device report. The specific device report present depeds on deviceHwType"
@ -1953,6 +1956,34 @@ margin-bottom: 20px;
}
},
"description" : "FCDPro"
};
defs.FileSourceReport = {
"properties" : {
"fileName" : {
"type" : "string"
},
"sampleRate" : {
"type" : "integer",
"description" : "Record sample rate in S/s"
},
"sampleSize" : {
"type" : "integer",
"description" : "Record sample size in number of bits"
},
"absoluteTime" : {
"type" : "string",
"description" : "Absolute record time string representation"
},
"elapsedTime" : {
"type" : "string",
"description" : "Elapsed time since beginning string representation"
},
"durationTime" : {
"type" : "string",
"description" : "Duration time string representation"
}
},
"description" : "FileSource"
};
defs.FileSourceSettings = {
"properties" : {
@ -21830,7 +21861,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2018-05-26T10:50:36.916+02:00
Generated 2018-05-26T11:35:33.686+02:00
</div>
</div>
</div>

View File

@ -36,6 +36,8 @@ SWGDeviceReport::SWGDeviceReport() {
m_airspy_report_isSet = false;
airspy_hf_report = nullptr;
m_airspy_hf_report_isSet = false;
file_source_report = nullptr;
m_file_source_report_isSet = false;
}
SWGDeviceReport::~SWGDeviceReport() {
@ -52,6 +54,8 @@ SWGDeviceReport::init() {
m_airspy_report_isSet = false;
airspy_hf_report = new SWGAirspyHFReport();
m_airspy_hf_report_isSet = false;
file_source_report = new SWGFileSourceReport();
m_file_source_report_isSet = false;
}
void
@ -66,6 +70,9 @@ SWGDeviceReport::cleanup() {
if(airspy_hf_report != nullptr) {
delete airspy_hf_report;
}
if(file_source_report != nullptr) {
delete file_source_report;
}
}
SWGDeviceReport*
@ -87,6 +94,8 @@ SWGDeviceReport::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&airspy_hf_report, pJson["airspyHFReport"], "SWGAirspyHFReport", "SWGAirspyHFReport");
::SWGSDRangel::setValue(&file_source_report, pJson["fileSourceReport"], "SWGFileSourceReport", "SWGFileSourceReport");
}
QString
@ -115,6 +124,9 @@ SWGDeviceReport::asJsonObject() {
if((airspy_hf_report != nullptr) && (airspy_hf_report->isSet())){
toJsonValue(QString("airspyHFReport"), airspy_hf_report, obj, QString("SWGAirspyHFReport"));
}
if((file_source_report != nullptr) && (file_source_report->isSet())){
toJsonValue(QString("fileSourceReport"), file_source_report, obj, QString("SWGFileSourceReport"));
}
return obj;
}
@ -159,6 +171,16 @@ SWGDeviceReport::setAirspyHfReport(SWGAirspyHFReport* airspy_hf_report) {
this->m_airspy_hf_report_isSet = true;
}
SWGFileSourceReport*
SWGDeviceReport::getFileSourceReport() {
return file_source_report;
}
void
SWGDeviceReport::setFileSourceReport(SWGFileSourceReport* file_source_report) {
this->file_source_report = file_source_report;
this->m_file_source_report_isSet = true;
}
bool
SWGDeviceReport::isSet(){
@ -168,6 +190,7 @@ SWGDeviceReport::isSet(){
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;}
if(file_source_report != nullptr && file_source_report->isSet()){ isObjectUpdated = true; break;}
}while(false);
return isObjectUpdated;
}

View File

@ -24,6 +24,7 @@
#include "SWGAirspyHFReport.h"
#include "SWGAirspyReport.h"
#include "SWGFileSourceReport.h"
#include <QString>
#include "SWGObject.h"
@ -56,6 +57,9 @@ public:
SWGAirspyHFReport* getAirspyHfReport();
void setAirspyHfReport(SWGAirspyHFReport* airspy_hf_report);
SWGFileSourceReport* getFileSourceReport();
void setFileSourceReport(SWGFileSourceReport* file_source_report);
virtual bool isSet() override;
@ -72,6 +76,9 @@ private:
SWGAirspyHFReport* airspy_hf_report;
bool m_airspy_hf_report_isSet;
SWGFileSourceReport* file_source_report;
bool m_file_source_report_isSet;
};
}

View File

@ -0,0 +1,219 @@
/**
* 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 "SWGFileSourceReport.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace SWGSDRangel {
SWGFileSourceReport::SWGFileSourceReport(QString* json) {
init();
this->fromJson(*json);
}
SWGFileSourceReport::SWGFileSourceReport() {
file_name = nullptr;
m_file_name_isSet = false;
sample_rate = 0;
m_sample_rate_isSet = false;
sample_size = 0;
m_sample_size_isSet = false;
absolute_time = nullptr;
m_absolute_time_isSet = false;
elapsed_time = nullptr;
m_elapsed_time_isSet = false;
duration_time = nullptr;
m_duration_time_isSet = false;
}
SWGFileSourceReport::~SWGFileSourceReport() {
this->cleanup();
}
void
SWGFileSourceReport::init() {
file_name = new QString("");
m_file_name_isSet = false;
sample_rate = 0;
m_sample_rate_isSet = false;
sample_size = 0;
m_sample_size_isSet = false;
absolute_time = new QString("");
m_absolute_time_isSet = false;
elapsed_time = new QString("");
m_elapsed_time_isSet = false;
duration_time = new QString("");
m_duration_time_isSet = false;
}
void
SWGFileSourceReport::cleanup() {
if(file_name != nullptr) {
delete file_name;
}
if(absolute_time != nullptr) {
delete absolute_time;
}
if(elapsed_time != nullptr) {
delete elapsed_time;
}
if(duration_time != nullptr) {
delete duration_time;
}
}
SWGFileSourceReport*
SWGFileSourceReport::fromJson(QString &json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGFileSourceReport::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&file_name, pJson["fileName"], "QString", "QString");
::SWGSDRangel::setValue(&sample_rate, pJson["sampleRate"], "qint32", "");
::SWGSDRangel::setValue(&sample_size, pJson["sampleSize"], "qint32", "");
::SWGSDRangel::setValue(&absolute_time, pJson["absoluteTime"], "QString", "QString");
::SWGSDRangel::setValue(&elapsed_time, pJson["elapsedTime"], "QString", "QString");
::SWGSDRangel::setValue(&duration_time, pJson["durationTime"], "QString", "QString");
}
QString
SWGFileSourceReport::asJson ()
{
QJsonObject* obj = this->asJsonObject();
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson();
delete obj;
return QString(bytes);
}
QJsonObject*
SWGFileSourceReport::asJsonObject() {
QJsonObject* obj = new QJsonObject();
if(file_name != nullptr && *file_name != QString("")){
toJsonValue(QString("fileName"), file_name, obj, QString("QString"));
}
if(m_sample_rate_isSet){
obj->insert("sampleRate", QJsonValue(sample_rate));
}
if(m_sample_size_isSet){
obj->insert("sampleSize", QJsonValue(sample_size));
}
if(absolute_time != nullptr && *absolute_time != QString("")){
toJsonValue(QString("absoluteTime"), absolute_time, obj, QString("QString"));
}
if(elapsed_time != nullptr && *elapsed_time != QString("")){
toJsonValue(QString("elapsedTime"), elapsed_time, obj, QString("QString"));
}
if(duration_time != nullptr && *duration_time != QString("")){
toJsonValue(QString("durationTime"), duration_time, obj, QString("QString"));
}
return obj;
}
QString*
SWGFileSourceReport::getFileName() {
return file_name;
}
void
SWGFileSourceReport::setFileName(QString* file_name) {
this->file_name = file_name;
this->m_file_name_isSet = true;
}
qint32
SWGFileSourceReport::getSampleRate() {
return sample_rate;
}
void
SWGFileSourceReport::setSampleRate(qint32 sample_rate) {
this->sample_rate = sample_rate;
this->m_sample_rate_isSet = true;
}
qint32
SWGFileSourceReport::getSampleSize() {
return sample_size;
}
void
SWGFileSourceReport::setSampleSize(qint32 sample_size) {
this->sample_size = sample_size;
this->m_sample_size_isSet = true;
}
QString*
SWGFileSourceReport::getAbsoluteTime() {
return absolute_time;
}
void
SWGFileSourceReport::setAbsoluteTime(QString* absolute_time) {
this->absolute_time = absolute_time;
this->m_absolute_time_isSet = true;
}
QString*
SWGFileSourceReport::getElapsedTime() {
return elapsed_time;
}
void
SWGFileSourceReport::setElapsedTime(QString* elapsed_time) {
this->elapsed_time = elapsed_time;
this->m_elapsed_time_isSet = true;
}
QString*
SWGFileSourceReport::getDurationTime() {
return duration_time;
}
void
SWGFileSourceReport::setDurationTime(QString* duration_time) {
this->duration_time = duration_time;
this->m_duration_time_isSet = true;
}
bool
SWGFileSourceReport::isSet(){
bool isObjectUpdated = false;
do{
if(file_name != nullptr && *file_name != QString("")){ isObjectUpdated = true; break;}
if(m_sample_rate_isSet){ isObjectUpdated = true; break;}
if(m_sample_size_isSet){ isObjectUpdated = true; break;}
if(absolute_time != nullptr && *absolute_time != QString("")){ isObjectUpdated = true; break;}
if(elapsed_time != nullptr && *elapsed_time != QString("")){ isObjectUpdated = true; break;}
if(duration_time != nullptr && *duration_time != QString("")){ isObjectUpdated = true; break;}
}while(false);
return isObjectUpdated;
}
}

View File

@ -0,0 +1,89 @@
/**
* 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.
*/
/*
* SWGFileSourceReport.h
*
* FileSource
*/
#ifndef SWGFileSourceReport_H_
#define SWGFileSourceReport_H_
#include <QJsonObject>
#include <QString>
#include "SWGObject.h"
#include "export.h"
namespace SWGSDRangel {
class SWG_API SWGFileSourceReport: public SWGObject {
public:
SWGFileSourceReport();
SWGFileSourceReport(QString* json);
virtual ~SWGFileSourceReport();
void init();
void cleanup();
virtual QString asJson () override;
virtual QJsonObject* asJsonObject() override;
virtual void fromJsonObject(QJsonObject &json) override;
virtual SWGFileSourceReport* fromJson(QString &jsonString) override;
QString* getFileName();
void setFileName(QString* file_name);
qint32 getSampleRate();
void setSampleRate(qint32 sample_rate);
qint32 getSampleSize();
void setSampleSize(qint32 sample_size);
QString* getAbsoluteTime();
void setAbsoluteTime(QString* absolute_time);
QString* getElapsedTime();
void setElapsedTime(QString* elapsed_time);
QString* getDurationTime();
void setDurationTime(QString* duration_time);
virtual bool isSet() override;
private:
QString* file_name;
bool m_file_name_isSet;
qint32 sample_rate;
bool m_sample_rate_isSet;
qint32 sample_size;
bool m_sample_size_isSet;
QString* absolute_time;
bool m_absolute_time_isSet;
QString* elapsed_time;
bool m_elapsed_time_isSet;
QString* duration_time;
bool m_duration_time_isSet;
};
}
#endif /* SWGFileSourceReport_H_ */

View File

@ -51,6 +51,7 @@
#include "SWGErrorResponse.h"
#include "SWGFCDProPlusSettings.h"
#include "SWGFCDProSettings.h"
#include "SWGFileSourceReport.h"
#include "SWGFileSourceSettings.h"
#include "SWGHackRFInputSettings.h"
#include "SWGHackRFOutputSettings.h"
@ -202,6 +203,9 @@ namespace SWGSDRangel {
if(QString("SWGFCDProSettings").compare(type) == 0) {
return new SWGFCDProSettings();
}
if(QString("SWGFileSourceReport").compare(type) == 0) {
return new SWGFileSourceReport();
}
if(QString("SWGFileSourceSettings").compare(type) == 0) {
return new SWGFileSourceSettings();
}