Skip to content

Commit

Permalink
File Input: REST API: updated with new settings elements
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Oct 14, 2018
1 parent 6852b70 commit b397cd3
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 38 deletions.
6 changes: 3 additions & 3 deletions plugins/samplesource/filesource/filesourcegui.cpp
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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()
Expand Down
64 changes: 47 additions & 17 deletions plugins/samplesource/filesource/filesourceinput.cpp
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
18 changes: 14 additions & 4 deletions plugins/samplesource/filesource/filesourceinput.h
Expand Up @@ -37,18 +37,21 @@ class FileSourceInput : public DeviceSampleSource {

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)
{ }
};

Expand Down Expand Up @@ -290,6 +293,12 @@ class FileSourceInput : public DeviceSampleSource {
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);
Expand Down Expand Up @@ -321,6 +330,7 @@ class FileSourceInput : public DeviceSampleSource {
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);
};

Expand Down
10 changes: 0 additions & 10 deletions plugins/samplesource/filesource/filesourcethread.cpp
Expand Up @@ -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);
}
}
Expand Down
13 changes: 11 additions & 2 deletions sdrbase/resources/webapi/doc/html2/index.html
Expand Up @@ -2297,7 +2297,16 @@
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"
Expand Down Expand Up @@ -23242,7 +23251,7 @@ <h3> Status: 501 - Function not implemented </h3>
</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>
Expand Down
7 changes: 7 additions & 0 deletions sdrbase/resources/webapi/doc/swagger/include/FileSource.yaml
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions swagger/sdrangel/api/swagger/include/FileSource.yaml
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions swagger/sdrangel/code/html2/index.html
Expand Up @@ -2297,7 +2297,16 @@
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"
Expand Down Expand Up @@ -23242,7 +23251,7 @@ <h3> Status: 501 - Function not implemented </h3>
</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>
Expand Down
42 changes: 42 additions & 0 deletions swagger/sdrangel/code/qt5/client/SWGFileSourceSettings.cpp
Expand Up @@ -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() {
Expand All @@ -40,13 +44,19 @@ 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
SWGFileSourceSettings::cleanup() {
if(file_name != nullptr) {
delete file_name;
}


}

SWGFileSourceSettings*
Expand All @@ -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
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit b397cd3

Please sign in to comment.