1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 01:39:05 -05:00

File Input: REST API: updated with new settings elements

This commit is contained in:
f4exb 2018-10-14 10:38:31 +02:00
parent 6852b70597
commit b397cd3a4b
10 changed files with 154 additions and 38 deletions

View File

@ -249,7 +249,7 @@ void FileSourceGui::on_playLoop_toggled(bool checked)
if (m_doApplySettings)
{
m_settings.m_loop = checked;
FileSourceInput::MsgConfigureFileSource *message = FileSourceInput::MsgConfigureFileSource::create(m_settings);
FileSourceInput::MsgConfigureFileSource *message = FileSourceInput::MsgConfigureFileSource::create(m_settings, false);
m_sampleSource->getInputMessageQueue()->push(message);
}
}
@ -329,7 +329,7 @@ void FileSourceGui::on_acceleration_currentIndexChanged(int index)
if (m_doApplySettings)
{
m_settings.m_accelerationFactor = FileSourceSettings::getAccelerationValue(index);
FileSourceInput::MsgConfigureFileSource *message = FileSourceInput::MsgConfigureFileSource::create(m_settings);
FileSourceInput::MsgConfigureFileSource *message = FileSourceInput::MsgConfigureFileSource::create(m_settings, false);
m_sampleSource->getInputMessageQueue()->push(message);
}
}
@ -358,7 +358,7 @@ void FileSourceGui::updateWithStreamData()
recordLength = recordLength.addSecs(m_recordLength);
QString s_time = recordLength.toString("HH:mm:ss");
ui->recordLengthText->setText(s_time);
updateWithStreamTime(); // TODO: remove when time data is implemented
updateWithStreamTime();
}
void FileSourceGui::updateWithStreamTime()

View File

@ -179,15 +179,12 @@ bool FileSourceInput::start()
return false;
}
//openFileStream();
m_fileSourceThread = new FileSourceThread(&m_ifstream, &m_sampleFifo, m_masterTimer, &m_inputMessageQueue);
m_fileSourceThread->setSampleRateAndSize(m_settings.m_accelerationFactor * m_sampleRate, m_sampleSize); // Fast Forward: 1 corresponds to live. 1/2 is half speed, 2 is double speed
m_fileSourceThread->startWork();
m_deviceDescription = "FileSource";
mutexLocker.unlock();
//applySettings(m_generalSettings, m_settings, true);
qDebug("FileSourceInput::startInput: started");
if (getMessageQueueToGUI()) {
@ -233,12 +230,12 @@ bool FileSourceInput::deserialize(const QByteArray& data)
success = false;
}
MsgConfigureFileSource* message = MsgConfigureFileSource::create(m_settings);
MsgConfigureFileSource* message = MsgConfigureFileSource::create(m_settings, true);
m_inputMessageQueue.push(message);
if (getMessageQueueToGUI())
{
MsgConfigureFileSource* messageToGUI = MsgConfigureFileSource::create(m_settings);
MsgConfigureFileSource* messageToGUI = MsgConfigureFileSource::create(m_settings, true);
getMessageQueueToGUI()->push(messageToGUI);
}
@ -265,12 +262,12 @@ void FileSourceInput::setCenterFrequency(qint64 centerFrequency)
FileSourceSettings settings = m_settings;
settings.m_centerFrequency = centerFrequency;
MsgConfigureFileSource* message = MsgConfigureFileSource::create(m_settings);
MsgConfigureFileSource* message = MsgConfigureFileSource::create(m_settings, false);
m_inputMessageQueue.push(message);
if (getMessageQueueToGUI())
{
MsgConfigureFileSource* messageToGUI = MsgConfigureFileSource::create(m_settings);
MsgConfigureFileSource* messageToGUI = MsgConfigureFileSource::create(m_settings, false);
getMessageQueueToGUI()->push(messageToGUI);
}
}
@ -303,16 +300,9 @@ bool FileSourceInput::handleMessage(const Message& message)
if (m_fileSourceThread != 0)
{
if (working)
{
if (working) {
m_fileSourceThread->startWork();
/*
MsgReportFileSourceStreamTiming *report =
MsgReportFileSourceStreamTiming::create(m_fileSourceThread->getSamplesCount());
getOutputMessageQueueToGUI()->push(report);*/
}
else
{
} else {
m_fileSourceThread->stopWork();
}
}
@ -422,7 +412,39 @@ int FileSourceInput::webapiSettingsGet(
QString& errorMessage __attribute__((unused)))
{
response.setFileSourceSettings(new SWGSDRangel::SWGFileSourceSettings());
response.getFileSourceSettings()->setFileName(new QString(m_settings.m_fileName));
response.getFileSourceSettings()->init();
webapiFormatDeviceSettings(response, m_settings);
return 200;
}
int FileSourceInput::webapiSettingsPutPatch(
bool force,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response, // query + response
QString& errorMessage __attribute__((unused)))
{
FileSourceSettings settings = m_settings;
if (deviceSettingsKeys.contains("fileName")) {
settings.m_fileName = *response.getFileSourceSettings()->getFileName();
}
if (deviceSettingsKeys.contains("accelerationFactor")) {
settings.m_accelerationFactor = response.getFileSourceSettings()->getAccelerationFactor();
}
if (deviceSettingsKeys.contains("loop")) {
settings.m_loop = response.getFileSourceSettings()->getLoop() != 0;
}
MsgConfigureFileSource *msg = MsgConfigureFileSource::create(settings, force);
m_inputMessageQueue.push(msg);
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureFileSource *msgToGUI = MsgConfigureFileSource::create(settings, force);
m_guiMessageQueue->push(msgToGUI);
}
webapiFormatDeviceSettings(response, settings);
return 200;
}
@ -462,6 +484,14 @@ int FileSourceInput::webapiReportGet(
return 200;
}
void FileSourceInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const FileSourceSettings& settings)
{
response.getFileSourceSettings()->setFileName(new QString(settings.m_fileName));
response.getFileSourceSettings()->setAccelerationFactor(settings.m_accelerationFactor);
response.getFileSourceSettings()->setLoop(settings.m_loop ? 1 : 0);
}
void FileSourceInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
{
qint64 t_sec = 0;

View File

@ -37,18 +37,21 @@ public:
public:
const FileSourceSettings& getSettings() const { return m_settings; }
bool getForce() const { return m_force; }
static MsgConfigureFileSource* create(const FileSourceSettings& settings)
static MsgConfigureFileSource* create(const FileSourceSettings& settings, bool force)
{
return new MsgConfigureFileSource(settings);
return new MsgConfigureFileSource(settings, force);
}
private:
FileSourceSettings m_settings;
bool m_force;
MsgConfigureFileSource(const FileSourceSettings& settings) :
MsgConfigureFileSource(const FileSourceSettings& settings, bool force) :
Message(),
m_settings(settings)
m_settings(settings),
m_force(force)
{ }
};
@ -290,6 +293,12 @@ public:
SWGSDRangel::SWGDeviceSettings& response,
QString& errorMessage);
virtual int webapiSettingsPutPatch(
bool force,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response, // query + response
QString& errorMessage);
virtual int webapiRunGet(
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage);
@ -321,6 +330,7 @@ public:
void openFileStream();
void seekFileStream(int seekMillis);
bool applySettings(const FileSourceSettings& settings, bool force = false);
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const FileSourceSettings& settings);
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
};

View File

@ -193,20 +193,10 @@ void FileSourceThread::tick()
writeToSampleFifo(m_fileBuf, (qint32) m_ifstream->gcount());
MsgReportEOF *message = MsgReportEOF::create();
m_fileInputMessageQueue->push(message);
//m_sampleFifo->write(m_buf, m_ifstream->gcount());
// TODO: handle loop playback situation
// m_ifstream->clear();
// m_ifstream->seekg(sizeof(FileRecord::Header), std::ios::beg);
// m_samplesCount = 0;
//stopWork();
//m_ifstream->close();
}
else
{
writeToSampleFifo(m_fileBuf, (qint32) m_chunksize);
//m_sampleFifo->write(m_buf, m_chunksize);
m_samplesCount += m_chunksize / (2 * m_samplebytes);
}
}

View File

@ -2297,7 +2297,16 @@ margin-bottom: 20px;
defs.FileSourceSettings = {
"properties" : {
"fileName" : {
"type" : "string"
"type" : "string",
"description" : "The name (path) of the file being read"
},
"accelerationFactor" : {
"type" : "integer",
"description" : "Playback acceleration (1 if normal speed)"
},
"loop" : {
"type" : "integer",
"description" : "1 if playing in a loop else 0"
}
},
"description" : "FileSource"
@ -23242,7 +23251,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2018-10-11T08:49:05.249+02:00
Generated 2018-10-14T10:07:16.959+02:00
</div>
</div>
</div>

View File

@ -2,7 +2,14 @@ FileSourceSettings:
description: FileSource
properties:
fileName:
description: The name (path) of the file being read
type: string
accelerationFactor:
description: Playback acceleration (1 if normal speed)
type: integer
loop:
description: 1 if playing in a loop else 0
type: integer
FileSourceReport:
description: FileSource

View File

@ -2,7 +2,14 @@ FileSourceSettings:
description: FileSource
properties:
fileName:
description: The name (path) of the file being read
type: string
accelerationFactor:
description: Playback acceleration (1 if normal speed)
type: integer
loop:
description: 1 if playing in a loop else 0
type: integer
FileSourceReport:
description: FileSource

View File

@ -2297,7 +2297,16 @@ margin-bottom: 20px;
defs.FileSourceSettings = {
"properties" : {
"fileName" : {
"type" : "string"
"type" : "string",
"description" : "The name (path) of the file being read"
},
"accelerationFactor" : {
"type" : "integer",
"description" : "Playback acceleration (1 if normal speed)"
},
"loop" : {
"type" : "integer",
"description" : "1 if playing in a loop else 0"
}
},
"description" : "FileSource"
@ -23242,7 +23251,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2018-10-11T08:49:05.249+02:00
Generated 2018-10-14T10:07:16.959+02:00
</div>
</div>
</div>

View File

@ -30,6 +30,10 @@ SWGFileSourceSettings::SWGFileSourceSettings(QString* json) {
SWGFileSourceSettings::SWGFileSourceSettings() {
file_name = nullptr;
m_file_name_isSet = false;
acceleration_factor = 0;
m_acceleration_factor_isSet = false;
loop = 0;
m_loop_isSet = false;
}
SWGFileSourceSettings::~SWGFileSourceSettings() {
@ -40,6 +44,10 @@ void
SWGFileSourceSettings::init() {
file_name = new QString("");
m_file_name_isSet = false;
acceleration_factor = 0;
m_acceleration_factor_isSet = false;
loop = 0;
m_loop_isSet = false;
}
void
@ -47,6 +55,8 @@ SWGFileSourceSettings::cleanup() {
if(file_name != nullptr) {
delete file_name;
}
}
SWGFileSourceSettings*
@ -62,6 +72,10 @@ void
SWGFileSourceSettings::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&file_name, pJson["fileName"], "QString", "QString");
::SWGSDRangel::setValue(&acceleration_factor, pJson["accelerationFactor"], "qint32", "");
::SWGSDRangel::setValue(&loop, pJson["loop"], "qint32", "");
}
QString
@ -81,6 +95,12 @@ SWGFileSourceSettings::asJsonObject() {
if(file_name != nullptr && *file_name != QString("")){
toJsonValue(QString("fileName"), file_name, obj, QString("QString"));
}
if(m_acceleration_factor_isSet){
obj->insert("accelerationFactor", QJsonValue(acceleration_factor));
}
if(m_loop_isSet){
obj->insert("loop", QJsonValue(loop));
}
return obj;
}
@ -95,12 +115,34 @@ SWGFileSourceSettings::setFileName(QString* file_name) {
this->m_file_name_isSet = true;
}
qint32
SWGFileSourceSettings::getAccelerationFactor() {
return acceleration_factor;
}
void
SWGFileSourceSettings::setAccelerationFactor(qint32 acceleration_factor) {
this->acceleration_factor = acceleration_factor;
this->m_acceleration_factor_isSet = true;
}
qint32
SWGFileSourceSettings::getLoop() {
return loop;
}
void
SWGFileSourceSettings::setLoop(qint32 loop) {
this->loop = loop;
this->m_loop_isSet = true;
}
bool
SWGFileSourceSettings::isSet(){
bool isObjectUpdated = false;
do{
if(file_name != nullptr && *file_name != QString("")){ isObjectUpdated = true; break;}
if(m_acceleration_factor_isSet){ isObjectUpdated = true; break;}
if(m_loop_isSet){ isObjectUpdated = true; break;}
}while(false);
return isObjectUpdated;
}

View File

@ -45,6 +45,12 @@ public:
QString* getFileName();
void setFileName(QString* file_name);
qint32 getAccelerationFactor();
void setAccelerationFactor(qint32 acceleration_factor);
qint32 getLoop();
void setLoop(qint32 loop);
virtual bool isSet() override;
@ -52,6 +58,12 @@ private:
QString* file_name;
bool m_file_name_isSet;
qint32 acceleration_factor;
bool m_acceleration_factor_isSet;
qint32 loop;
bool m_loop_isSet;
};
}