mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-04 23:14:47 -04:00
Web API: file source settings getter (1)
This commit is contained in:
@@ -21,6 +21,7 @@ set(filesource_FORMS
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
)
|
||||
|
||||
#include(${QT_USE_FILE})
|
||||
@@ -41,6 +42,7 @@ target_link_libraries(inputfilesource
|
||||
${QT_LIBRARIES}
|
||||
sdrbase
|
||||
sdrgui
|
||||
swagger
|
||||
)
|
||||
|
||||
qt5_use_modules(inputfilesource Core Widgets)
|
||||
|
||||
@@ -20,6 +20,7 @@ QMAKE_CXXFLAGS += -std=c++11
|
||||
INCLUDEPATH += $$PWD
|
||||
INCLUDEPATH += ../../../sdrbase
|
||||
INCLUDEPATH += ../../../sdrgui
|
||||
INCLUDEPATH += ../../../swagger/sdrangel/code/qt5/client
|
||||
|
||||
CONFIG(Release):build_subdir = release
|
||||
CONFIG(Debug):build_subdir = debug
|
||||
@@ -38,5 +39,6 @@ FORMS += filesourcegui.ui
|
||||
|
||||
LIBS += -L../../../sdrbase/$${build_subdir} -lsdrbase
|
||||
LIBS += -L../../../sdrgui/$${build_subdir} -lsdrgui
|
||||
LIBS += -L../../../swagger/$${build_subdir} -lswagger
|
||||
|
||||
RESOURCES = ../../../sdrgui/resources/res.qrc
|
||||
|
||||
@@ -1,292 +1,304 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <QDebug>
|
||||
|
||||
#include "util/simpleserializer.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "dsp/filerecord.h"
|
||||
#include "device/devicesourceapi.h"
|
||||
|
||||
#include "filesourcegui.h"
|
||||
#include "filesourceinput.h"
|
||||
#include "filesourcethread.h"
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSource, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceName, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceWork, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceSeek, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceStreamTiming, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceAcquisition, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceStreamData, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceStreamTiming, Message)
|
||||
|
||||
FileSourceInput::Settings::Settings() :
|
||||
m_fileName("./test.sdriq")
|
||||
{
|
||||
}
|
||||
|
||||
void FileSourceInput::Settings::resetToDefaults()
|
||||
{
|
||||
m_fileName = "./test.sdriq";
|
||||
}
|
||||
|
||||
QByteArray FileSourceInput::Settings::serialize() const
|
||||
{
|
||||
SimpleSerializer s(1);
|
||||
s.writeString(1, m_fileName);
|
||||
return s.final();
|
||||
}
|
||||
|
||||
bool FileSourceInput::Settings::deserialize(const QByteArray& data)
|
||||
{
|
||||
SimpleDeserializer d(data);
|
||||
|
||||
if(!d.isValid()) {
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(d.getVersion() == 1) {
|
||||
d.readString(1, &m_fileName, "./test.sdriq");
|
||||
return true;
|
||||
} else {
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
FileSourceInput::FileSourceInput(DeviceSourceAPI *deviceAPI) :
|
||||
m_deviceAPI(deviceAPI),
|
||||
m_settings(),
|
||||
m_fileSourceThread(NULL),
|
||||
m_deviceDescription(),
|
||||
m_fileName("..."),
|
||||
m_sampleRate(0),
|
||||
m_centerFrequency(0),
|
||||
m_recordLength(0),
|
||||
m_startingTimeStamp(0),
|
||||
m_masterTimer(deviceAPI->getMasterTimer())
|
||||
{
|
||||
}
|
||||
|
||||
FileSourceInput::~FileSourceInput()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
void FileSourceInput::destroy()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void FileSourceInput::openFileStream()
|
||||
{
|
||||
//stopInput();
|
||||
|
||||
if (m_ifstream.is_open()) {
|
||||
m_ifstream.close();
|
||||
}
|
||||
|
||||
m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary | std::ios::ate);
|
||||
quint64 fileSize = m_ifstream.tellg();
|
||||
m_ifstream.seekg(0,std::ios_base::beg);
|
||||
FileRecord::Header header;
|
||||
FileRecord::readHeader(m_ifstream, header);
|
||||
|
||||
m_sampleRate = header.sampleRate;
|
||||
m_centerFrequency = header.centerFrequency;
|
||||
m_startingTimeStamp = header.startTimeStamp;
|
||||
|
||||
if (fileSize > sizeof(FileRecord::Header)) {
|
||||
m_recordLength = (fileSize - sizeof(FileRecord::Header)) / (4 * m_sampleRate);
|
||||
} else {
|
||||
m_recordLength = 0;
|
||||
}
|
||||
|
||||
qDebug() << "FileSourceInput::openFileStream: " << m_fileName.toStdString().c_str()
|
||||
<< " fileSize: " << fileSize << "bytes"
|
||||
<< " length: " << m_recordLength << " seconds";
|
||||
|
||||
MsgReportFileSourceStreamData *report = MsgReportFileSourceStreamData::create(m_sampleRate,
|
||||
m_centerFrequency,
|
||||
m_startingTimeStamp,
|
||||
m_recordLength); // file stream data
|
||||
|
||||
if (getMessageQueueToGUI()) {
|
||||
getMessageQueueToGUI()->push(report);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSourceInput::seekFileStream(int seekPercentage)
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
if ((m_ifstream.is_open()) && !m_fileSourceThread->isRunning())
|
||||
{
|
||||
int seekPoint = ((m_recordLength * seekPercentage) / 100) * m_sampleRate;
|
||||
m_fileSourceThread->setSamplesCount(seekPoint);
|
||||
seekPoint *= 4; // + sizeof(FileSink::Header)
|
||||
m_ifstream.clear();
|
||||
m_ifstream.seekg(seekPoint + sizeof(FileRecord::Header), std::ios::beg);
|
||||
}
|
||||
}
|
||||
|
||||
bool FileSourceInput::start()
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
qDebug() << "FileSourceInput::start";
|
||||
|
||||
if (m_ifstream.tellg() != 0) {
|
||||
m_ifstream.clear();
|
||||
m_ifstream.seekg(sizeof(FileRecord::Header), std::ios::beg);
|
||||
}
|
||||
|
||||
if(!m_sampleFifo.setSize(m_sampleRate * 4)) {
|
||||
qCritical("Could not allocate SampleFifo");
|
||||
return false;
|
||||
}
|
||||
|
||||
//openFileStream();
|
||||
|
||||
if((m_fileSourceThread = new FileSourceThread(&m_ifstream, &m_sampleFifo)) == NULL) {
|
||||
qFatal("out of memory");
|
||||
stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_fileSourceThread->setSamplerate(m_sampleRate);
|
||||
m_fileSourceThread->connectTimer(m_masterTimer);
|
||||
m_fileSourceThread->startWork();
|
||||
m_deviceDescription = "FileSource";
|
||||
|
||||
mutexLocker.unlock();
|
||||
//applySettings(m_generalSettings, m_settings, true);
|
||||
qDebug("FileSourceInput::startInput: started");
|
||||
|
||||
MsgReportFileSourceAcquisition *report = MsgReportFileSourceAcquisition::create(true); // acquisition on
|
||||
|
||||
if (getMessageQueueToGUI()) {
|
||||
getMessageQueueToGUI()->push(report);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileSourceInput::stop()
|
||||
{
|
||||
qDebug() << "FileSourceInput::stop";
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
if(m_fileSourceThread != 0)
|
||||
{
|
||||
m_fileSourceThread->stopWork();
|
||||
delete m_fileSourceThread;
|
||||
m_fileSourceThread = 0;
|
||||
}
|
||||
|
||||
m_deviceDescription.clear();
|
||||
|
||||
MsgReportFileSourceAcquisition *report = MsgReportFileSourceAcquisition::create(false); // acquisition off
|
||||
|
||||
if (getMessageQueueToGUI()) {
|
||||
getMessageQueueToGUI()->push(report);
|
||||
}
|
||||
}
|
||||
|
||||
const QString& FileSourceInput::getDeviceDescription() const
|
||||
{
|
||||
return m_deviceDescription;
|
||||
}
|
||||
|
||||
int FileSourceInput::getSampleRate() const
|
||||
{
|
||||
return m_sampleRate;
|
||||
}
|
||||
|
||||
quint64 FileSourceInput::getCenterFrequency() const
|
||||
{
|
||||
return m_centerFrequency;
|
||||
}
|
||||
|
||||
std::time_t FileSourceInput::getStartingTimeStamp() const
|
||||
{
|
||||
return m_startingTimeStamp;
|
||||
}
|
||||
|
||||
bool FileSourceInput::handleMessage(const Message& message)
|
||||
{
|
||||
if (MsgConfigureFileSourceName::match(message))
|
||||
{
|
||||
MsgConfigureFileSourceName& conf = (MsgConfigureFileSourceName&) message;
|
||||
m_fileName = conf.getFileName();
|
||||
openFileStream();
|
||||
return true;
|
||||
}
|
||||
else if (MsgConfigureFileSourceWork::match(message))
|
||||
{
|
||||
MsgConfigureFileSourceWork& conf = (MsgConfigureFileSourceWork&) message;
|
||||
bool working = conf.isWorking();
|
||||
|
||||
if (m_fileSourceThread != 0)
|
||||
{
|
||||
if (working)
|
||||
{
|
||||
m_fileSourceThread->startWork();
|
||||
/*
|
||||
MsgReportFileSourceStreamTiming *report =
|
||||
MsgReportFileSourceStreamTiming::create(m_fileSourceThread->getSamplesCount());
|
||||
getOutputMessageQueueToGUI()->push(report);*/
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fileSourceThread->stopWork();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgConfigureFileSourceSeek::match(message))
|
||||
{
|
||||
MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) message;
|
||||
int seekPercentage = conf.getPercentage();
|
||||
seekFileStream(seekPercentage);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgConfigureFileSourceStreamTiming::match(message))
|
||||
{
|
||||
MsgReportFileSourceStreamTiming *report;
|
||||
|
||||
if (m_fileSourceThread != 0)
|
||||
{
|
||||
report = MsgReportFileSourceStreamTiming::create(m_fileSourceThread->getSamplesCount());
|
||||
|
||||
if (getMessageQueueToGUI()) {
|
||||
getMessageQueueToGUI()->push(report);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <QDebug>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGFileSourceSettings.h"
|
||||
|
||||
#include "util/simpleserializer.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "dsp/filerecord.h"
|
||||
#include "device/devicesourceapi.h"
|
||||
|
||||
#include "filesourcegui.h"
|
||||
#include "filesourceinput.h"
|
||||
#include "filesourcethread.h"
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSource, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceName, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceWork, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceSeek, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceStreamTiming, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceAcquisition, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceStreamData, Message)
|
||||
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceStreamTiming, Message)
|
||||
|
||||
FileSourceInput::Settings::Settings() :
|
||||
m_fileName("./test.sdriq")
|
||||
{
|
||||
}
|
||||
|
||||
void FileSourceInput::Settings::resetToDefaults()
|
||||
{
|
||||
m_fileName = "./test.sdriq";
|
||||
}
|
||||
|
||||
QByteArray FileSourceInput::Settings::serialize() const
|
||||
{
|
||||
SimpleSerializer s(1);
|
||||
s.writeString(1, m_fileName);
|
||||
return s.final();
|
||||
}
|
||||
|
||||
bool FileSourceInput::Settings::deserialize(const QByteArray& data)
|
||||
{
|
||||
SimpleDeserializer d(data);
|
||||
|
||||
if(!d.isValid()) {
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(d.getVersion() == 1) {
|
||||
d.readString(1, &m_fileName, "./test.sdriq");
|
||||
return true;
|
||||
} else {
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
FileSourceInput::FileSourceInput(DeviceSourceAPI *deviceAPI) :
|
||||
m_deviceAPI(deviceAPI),
|
||||
m_settings(),
|
||||
m_fileSourceThread(NULL),
|
||||
m_deviceDescription(),
|
||||
m_fileName("..."),
|
||||
m_sampleRate(0),
|
||||
m_centerFrequency(0),
|
||||
m_recordLength(0),
|
||||
m_startingTimeStamp(0),
|
||||
m_masterTimer(deviceAPI->getMasterTimer())
|
||||
{
|
||||
}
|
||||
|
||||
FileSourceInput::~FileSourceInput()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
void FileSourceInput::destroy()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void FileSourceInput::openFileStream()
|
||||
{
|
||||
//stopInput();
|
||||
|
||||
if (m_ifstream.is_open()) {
|
||||
m_ifstream.close();
|
||||
}
|
||||
|
||||
m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary | std::ios::ate);
|
||||
quint64 fileSize = m_ifstream.tellg();
|
||||
m_ifstream.seekg(0,std::ios_base::beg);
|
||||
FileRecord::Header header;
|
||||
FileRecord::readHeader(m_ifstream, header);
|
||||
|
||||
m_sampleRate = header.sampleRate;
|
||||
m_centerFrequency = header.centerFrequency;
|
||||
m_startingTimeStamp = header.startTimeStamp;
|
||||
|
||||
if (fileSize > sizeof(FileRecord::Header)) {
|
||||
m_recordLength = (fileSize - sizeof(FileRecord::Header)) / (4 * m_sampleRate);
|
||||
} else {
|
||||
m_recordLength = 0;
|
||||
}
|
||||
|
||||
qDebug() << "FileSourceInput::openFileStream: " << m_fileName.toStdString().c_str()
|
||||
<< " fileSize: " << fileSize << "bytes"
|
||||
<< " length: " << m_recordLength << " seconds";
|
||||
|
||||
MsgReportFileSourceStreamData *report = MsgReportFileSourceStreamData::create(m_sampleRate,
|
||||
m_centerFrequency,
|
||||
m_startingTimeStamp,
|
||||
m_recordLength); // file stream data
|
||||
|
||||
if (getMessageQueueToGUI()) {
|
||||
getMessageQueueToGUI()->push(report);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSourceInput::seekFileStream(int seekPercentage)
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
if ((m_ifstream.is_open()) && !m_fileSourceThread->isRunning())
|
||||
{
|
||||
int seekPoint = ((m_recordLength * seekPercentage) / 100) * m_sampleRate;
|
||||
m_fileSourceThread->setSamplesCount(seekPoint);
|
||||
seekPoint *= 4; // + sizeof(FileSink::Header)
|
||||
m_ifstream.clear();
|
||||
m_ifstream.seekg(seekPoint + sizeof(FileRecord::Header), std::ios::beg);
|
||||
}
|
||||
}
|
||||
|
||||
bool FileSourceInput::start()
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
qDebug() << "FileSourceInput::start";
|
||||
|
||||
if (m_ifstream.tellg() != 0) {
|
||||
m_ifstream.clear();
|
||||
m_ifstream.seekg(sizeof(FileRecord::Header), std::ios::beg);
|
||||
}
|
||||
|
||||
if(!m_sampleFifo.setSize(m_sampleRate * 4)) {
|
||||
qCritical("Could not allocate SampleFifo");
|
||||
return false;
|
||||
}
|
||||
|
||||
//openFileStream();
|
||||
|
||||
if((m_fileSourceThread = new FileSourceThread(&m_ifstream, &m_sampleFifo)) == NULL) {
|
||||
qFatal("out of memory");
|
||||
stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_fileSourceThread->setSamplerate(m_sampleRate);
|
||||
m_fileSourceThread->connectTimer(m_masterTimer);
|
||||
m_fileSourceThread->startWork();
|
||||
m_deviceDescription = "FileSource";
|
||||
|
||||
mutexLocker.unlock();
|
||||
//applySettings(m_generalSettings, m_settings, true);
|
||||
qDebug("FileSourceInput::startInput: started");
|
||||
|
||||
MsgReportFileSourceAcquisition *report = MsgReportFileSourceAcquisition::create(true); // acquisition on
|
||||
|
||||
if (getMessageQueueToGUI()) {
|
||||
getMessageQueueToGUI()->push(report);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileSourceInput::stop()
|
||||
{
|
||||
qDebug() << "FileSourceInput::stop";
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
if(m_fileSourceThread != 0)
|
||||
{
|
||||
m_fileSourceThread->stopWork();
|
||||
delete m_fileSourceThread;
|
||||
m_fileSourceThread = 0;
|
||||
}
|
||||
|
||||
m_deviceDescription.clear();
|
||||
|
||||
MsgReportFileSourceAcquisition *report = MsgReportFileSourceAcquisition::create(false); // acquisition off
|
||||
|
||||
if (getMessageQueueToGUI()) {
|
||||
getMessageQueueToGUI()->push(report);
|
||||
}
|
||||
}
|
||||
|
||||
const QString& FileSourceInput::getDeviceDescription() const
|
||||
{
|
||||
return m_deviceDescription;
|
||||
}
|
||||
|
||||
int FileSourceInput::getSampleRate() const
|
||||
{
|
||||
return m_sampleRate;
|
||||
}
|
||||
|
||||
quint64 FileSourceInput::getCenterFrequency() const
|
||||
{
|
||||
return m_centerFrequency;
|
||||
}
|
||||
|
||||
std::time_t FileSourceInput::getStartingTimeStamp() const
|
||||
{
|
||||
return m_startingTimeStamp;
|
||||
}
|
||||
|
||||
bool FileSourceInput::handleMessage(const Message& message)
|
||||
{
|
||||
if (MsgConfigureFileSourceName::match(message))
|
||||
{
|
||||
MsgConfigureFileSourceName& conf = (MsgConfigureFileSourceName&) message;
|
||||
m_fileName = conf.getFileName();
|
||||
openFileStream();
|
||||
return true;
|
||||
}
|
||||
else if (MsgConfigureFileSourceWork::match(message))
|
||||
{
|
||||
MsgConfigureFileSourceWork& conf = (MsgConfigureFileSourceWork&) message;
|
||||
bool working = conf.isWorking();
|
||||
|
||||
if (m_fileSourceThread != 0)
|
||||
{
|
||||
if (working)
|
||||
{
|
||||
m_fileSourceThread->startWork();
|
||||
/*
|
||||
MsgReportFileSourceStreamTiming *report =
|
||||
MsgReportFileSourceStreamTiming::create(m_fileSourceThread->getSamplesCount());
|
||||
getOutputMessageQueueToGUI()->push(report);*/
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fileSourceThread->stopWork();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgConfigureFileSourceSeek::match(message))
|
||||
{
|
||||
MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) message;
|
||||
int seekPercentage = conf.getPercentage();
|
||||
seekFileStream(seekPercentage);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgConfigureFileSourceStreamTiming::match(message))
|
||||
{
|
||||
MsgReportFileSourceStreamTiming *report;
|
||||
|
||||
if (m_fileSourceThread != 0)
|
||||
{
|
||||
report = MsgReportFileSourceStreamTiming::create(m_fileSourceThread->getSamplesCount());
|
||||
|
||||
if (getMessageQueueToGUI()) {
|
||||
getMessageQueueToGUI()->push(report);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int FileSourceInput::webapiSettingsGet(
|
||||
SWGSDRangel::SWGDeviceSettings& response,
|
||||
QString& errorMessage __attribute__((unused)))
|
||||
{
|
||||
response.setFileSourceSettings(new SWGSDRangel::SWGFileSourceSettings());
|
||||
*response.getFileSourceSettings()->getFileName() = m_settings.m_fileName;
|
||||
return 200;
|
||||
}
|
||||
|
||||
@@ -1,245 +1,249 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_FILESOURCEINPUT_H
|
||||
#define INCLUDE_FILESOURCEINPUT_H
|
||||
|
||||
#include <dsp/devicesamplesource.h>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
class FileSourceThread;
|
||||
class DeviceSourceAPI;
|
||||
|
||||
class FileSourceInput : public DeviceSampleSource {
|
||||
public:
|
||||
struct Settings {
|
||||
QString m_fileName;
|
||||
|
||||
Settings();
|
||||
void resetToDefaults();
|
||||
QByteArray serialize() const;
|
||||
bool deserialize(const QByteArray& data);
|
||||
};
|
||||
|
||||
class MsgConfigureFileSource : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
const Settings& getSettings() const { return m_settings; }
|
||||
|
||||
static MsgConfigureFileSource* create(const Settings& settings)
|
||||
{
|
||||
return new MsgConfigureFileSource(settings);
|
||||
}
|
||||
|
||||
private:
|
||||
Settings m_settings;
|
||||
|
||||
MsgConfigureFileSource(const Settings& settings) :
|
||||
Message(),
|
||||
m_settings(settings)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgConfigureFileSourceName : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
const QString& getFileName() const { return m_fileName; }
|
||||
|
||||
static MsgConfigureFileSourceName* create(const QString& fileName)
|
||||
{
|
||||
return new MsgConfigureFileSourceName(fileName);
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
|
||||
MsgConfigureFileSourceName(const QString& fileName) :
|
||||
Message(),
|
||||
m_fileName(fileName)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgConfigureFileSourceWork : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
bool isWorking() const { return m_working; }
|
||||
|
||||
static MsgConfigureFileSourceWork* create(bool working)
|
||||
{
|
||||
return new MsgConfigureFileSourceWork(working);
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_working;
|
||||
|
||||
MsgConfigureFileSourceWork(bool working) :
|
||||
Message(),
|
||||
m_working(working)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgConfigureFileSourceStreamTiming : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
|
||||
static MsgConfigureFileSourceStreamTiming* create()
|
||||
{
|
||||
return new MsgConfigureFileSourceStreamTiming();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
MsgConfigureFileSourceStreamTiming() :
|
||||
Message()
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgConfigureFileSourceSeek : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
int getPercentage() const { return m_seekPercentage; }
|
||||
|
||||
static MsgConfigureFileSourceSeek* create(int seekPercentage)
|
||||
{
|
||||
return new MsgConfigureFileSourceSeek(seekPercentage);
|
||||
}
|
||||
|
||||
protected:
|
||||
int m_seekPercentage; //!< percentage of seek position from the beginning 0..100
|
||||
|
||||
MsgConfigureFileSourceSeek(int seekPercentage) :
|
||||
Message(),
|
||||
m_seekPercentage(seekPercentage)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgReportFileSourceAcquisition : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
bool getAcquisition() const { return m_acquisition; }
|
||||
|
||||
static MsgReportFileSourceAcquisition* create(bool acquisition)
|
||||
{
|
||||
return new MsgReportFileSourceAcquisition(acquisition);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool m_acquisition;
|
||||
|
||||
MsgReportFileSourceAcquisition(bool acquisition) :
|
||||
Message(),
|
||||
m_acquisition(acquisition)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgReportFileSourceStreamData : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
int getSampleRate() const { return m_sampleRate; }
|
||||
quint64 getCenterFrequency() const { return m_centerFrequency; }
|
||||
std::time_t getStartingTimeStamp() const { return m_startingTimeStamp; }
|
||||
quint32 getRecordLength() const { return m_recordLength; }
|
||||
|
||||
static MsgReportFileSourceStreamData* create(int sampleRate,
|
||||
quint64 centerFrequency,
|
||||
std::time_t startingTimeStamp,
|
||||
quint32 recordLength)
|
||||
{
|
||||
return new MsgReportFileSourceStreamData(sampleRate, centerFrequency, startingTimeStamp, recordLength);
|
||||
}
|
||||
|
||||
protected:
|
||||
int m_sampleRate;
|
||||
quint64 m_centerFrequency;
|
||||
std::time_t m_startingTimeStamp;
|
||||
quint32 m_recordLength;
|
||||
|
||||
MsgReportFileSourceStreamData(int sampleRate,
|
||||
quint64 centerFrequency,
|
||||
std::time_t startingTimeStamp,
|
||||
quint32 recordLength) :
|
||||
Message(),
|
||||
m_sampleRate(sampleRate),
|
||||
m_centerFrequency(centerFrequency),
|
||||
m_startingTimeStamp(startingTimeStamp),
|
||||
m_recordLength(recordLength)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgReportFileSourceStreamTiming : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
std::size_t getSamplesCount() const { return m_samplesCount; }
|
||||
|
||||
static MsgReportFileSourceStreamTiming* create(std::size_t samplesCount)
|
||||
{
|
||||
return new MsgReportFileSourceStreamTiming(samplesCount);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::size_t m_samplesCount;
|
||||
|
||||
MsgReportFileSourceStreamTiming(std::size_t samplesCount) :
|
||||
Message(),
|
||||
m_samplesCount(samplesCount)
|
||||
{ }
|
||||
};
|
||||
|
||||
FileSourceInput(DeviceSourceAPI *deviceAPI);
|
||||
virtual ~FileSourceInput();
|
||||
virtual void destroy();
|
||||
|
||||
virtual bool start();
|
||||
virtual void stop();
|
||||
|
||||
virtual const QString& getDeviceDescription() const;
|
||||
virtual int getSampleRate() const;
|
||||
virtual quint64 getCenterFrequency() const;
|
||||
std::time_t getStartingTimeStamp() const;
|
||||
|
||||
virtual bool handleMessage(const Message& message);
|
||||
|
||||
private:
|
||||
DeviceSourceAPI *m_deviceAPI;
|
||||
QMutex m_mutex;
|
||||
Settings m_settings;
|
||||
std::ifstream m_ifstream;
|
||||
FileSourceThread* m_fileSourceThread;
|
||||
QString m_deviceDescription;
|
||||
QString m_fileName;
|
||||
int m_sampleRate;
|
||||
quint64 m_centerFrequency;
|
||||
quint32 m_recordLength; //!< record length in seconds computed from file size
|
||||
std::time_t m_startingTimeStamp;
|
||||
const QTimer& m_masterTimer;
|
||||
|
||||
void openFileStream();
|
||||
void seekFileStream(int seekPercentage);
|
||||
};
|
||||
|
||||
#endif // INCLUDE_FILESOURCEINPUT_H
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_FILESOURCEINPUT_H
|
||||
#define INCLUDE_FILESOURCEINPUT_H
|
||||
|
||||
#include <dsp/devicesamplesource.h>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
class FileSourceThread;
|
||||
class DeviceSourceAPI;
|
||||
|
||||
class FileSourceInput : public DeviceSampleSource {
|
||||
public:
|
||||
struct Settings {
|
||||
QString m_fileName;
|
||||
|
||||
Settings();
|
||||
void resetToDefaults();
|
||||
QByteArray serialize() const;
|
||||
bool deserialize(const QByteArray& data);
|
||||
};
|
||||
|
||||
class MsgConfigureFileSource : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
const Settings& getSettings() const { return m_settings; }
|
||||
|
||||
static MsgConfigureFileSource* create(const Settings& settings)
|
||||
{
|
||||
return new MsgConfigureFileSource(settings);
|
||||
}
|
||||
|
||||
private:
|
||||
Settings m_settings;
|
||||
|
||||
MsgConfigureFileSource(const Settings& settings) :
|
||||
Message(),
|
||||
m_settings(settings)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgConfigureFileSourceName : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
const QString& getFileName() const { return m_fileName; }
|
||||
|
||||
static MsgConfigureFileSourceName* create(const QString& fileName)
|
||||
{
|
||||
return new MsgConfigureFileSourceName(fileName);
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
|
||||
MsgConfigureFileSourceName(const QString& fileName) :
|
||||
Message(),
|
||||
m_fileName(fileName)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgConfigureFileSourceWork : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
bool isWorking() const { return m_working; }
|
||||
|
||||
static MsgConfigureFileSourceWork* create(bool working)
|
||||
{
|
||||
return new MsgConfigureFileSourceWork(working);
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_working;
|
||||
|
||||
MsgConfigureFileSourceWork(bool working) :
|
||||
Message(),
|
||||
m_working(working)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgConfigureFileSourceStreamTiming : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
|
||||
static MsgConfigureFileSourceStreamTiming* create()
|
||||
{
|
||||
return new MsgConfigureFileSourceStreamTiming();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
MsgConfigureFileSourceStreamTiming() :
|
||||
Message()
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgConfigureFileSourceSeek : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
int getPercentage() const { return m_seekPercentage; }
|
||||
|
||||
static MsgConfigureFileSourceSeek* create(int seekPercentage)
|
||||
{
|
||||
return new MsgConfigureFileSourceSeek(seekPercentage);
|
||||
}
|
||||
|
||||
protected:
|
||||
int m_seekPercentage; //!< percentage of seek position from the beginning 0..100
|
||||
|
||||
MsgConfigureFileSourceSeek(int seekPercentage) :
|
||||
Message(),
|
||||
m_seekPercentage(seekPercentage)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgReportFileSourceAcquisition : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
bool getAcquisition() const { return m_acquisition; }
|
||||
|
||||
static MsgReportFileSourceAcquisition* create(bool acquisition)
|
||||
{
|
||||
return new MsgReportFileSourceAcquisition(acquisition);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool m_acquisition;
|
||||
|
||||
MsgReportFileSourceAcquisition(bool acquisition) :
|
||||
Message(),
|
||||
m_acquisition(acquisition)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgReportFileSourceStreamData : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
int getSampleRate() const { return m_sampleRate; }
|
||||
quint64 getCenterFrequency() const { return m_centerFrequency; }
|
||||
std::time_t getStartingTimeStamp() const { return m_startingTimeStamp; }
|
||||
quint32 getRecordLength() const { return m_recordLength; }
|
||||
|
||||
static MsgReportFileSourceStreamData* create(int sampleRate,
|
||||
quint64 centerFrequency,
|
||||
std::time_t startingTimeStamp,
|
||||
quint32 recordLength)
|
||||
{
|
||||
return new MsgReportFileSourceStreamData(sampleRate, centerFrequency, startingTimeStamp, recordLength);
|
||||
}
|
||||
|
||||
protected:
|
||||
int m_sampleRate;
|
||||
quint64 m_centerFrequency;
|
||||
std::time_t m_startingTimeStamp;
|
||||
quint32 m_recordLength;
|
||||
|
||||
MsgReportFileSourceStreamData(int sampleRate,
|
||||
quint64 centerFrequency,
|
||||
std::time_t startingTimeStamp,
|
||||
quint32 recordLength) :
|
||||
Message(),
|
||||
m_sampleRate(sampleRate),
|
||||
m_centerFrequency(centerFrequency),
|
||||
m_startingTimeStamp(startingTimeStamp),
|
||||
m_recordLength(recordLength)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgReportFileSourceStreamTiming : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
std::size_t getSamplesCount() const { return m_samplesCount; }
|
||||
|
||||
static MsgReportFileSourceStreamTiming* create(std::size_t samplesCount)
|
||||
{
|
||||
return new MsgReportFileSourceStreamTiming(samplesCount);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::size_t m_samplesCount;
|
||||
|
||||
MsgReportFileSourceStreamTiming(std::size_t samplesCount) :
|
||||
Message(),
|
||||
m_samplesCount(samplesCount)
|
||||
{ }
|
||||
};
|
||||
|
||||
FileSourceInput(DeviceSourceAPI *deviceAPI);
|
||||
virtual ~FileSourceInput();
|
||||
virtual void destroy();
|
||||
|
||||
virtual bool start();
|
||||
virtual void stop();
|
||||
|
||||
virtual const QString& getDeviceDescription() const;
|
||||
virtual int getSampleRate() const;
|
||||
virtual quint64 getCenterFrequency() const;
|
||||
std::time_t getStartingTimeStamp() const;
|
||||
|
||||
virtual bool handleMessage(const Message& message);
|
||||
|
||||
virtual int webapiSettingsGet(
|
||||
SWGSDRangel::SWGDeviceSettings& response __attribute__((unused)),
|
||||
QString& errorMessage);
|
||||
|
||||
private:
|
||||
DeviceSourceAPI *m_deviceAPI;
|
||||
QMutex m_mutex;
|
||||
Settings m_settings;
|
||||
std::ifstream m_ifstream;
|
||||
FileSourceThread* m_fileSourceThread;
|
||||
QString m_deviceDescription;
|
||||
QString m_fileName;
|
||||
int m_sampleRate;
|
||||
quint64 m_centerFrequency;
|
||||
quint32 m_recordLength; //!< record length in seconds computed from file size
|
||||
std::time_t m_startingTimeStamp;
|
||||
const QTimer& m_masterTimer;
|
||||
|
||||
void openFileStream();
|
||||
void seekFileStream(int seekPercentage);
|
||||
};
|
||||
|
||||
#endif // INCLUDE_FILESOURCEINPUT_H
|
||||
|
||||
Reference in New Issue
Block a user