1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-14 04:11:48 -05:00

File source: effective file selection. Better definition of open, start and stop actions

This commit is contained in:
f4exb 2015-08-05 03:25:06 +02:00
parent 5b0cc63c72
commit 196cf51089
5 changed files with 149 additions and 57 deletions

View File

@ -34,6 +34,7 @@ FileSourceGui::FileSourceGui(PluginAPI* pluginAPI, QWidget* parent) :
m_settings(),
m_sampleSource(NULL),
m_acquisition(false),
m_fileName("..."),
m_sampleRate(0),
m_centerFrequency(0),
m_startingTimeStamp(0),
@ -42,6 +43,7 @@ FileSourceGui::FileSourceGui(PluginAPI* pluginAPI, QWidget* parent) :
ui->setupUi(this);
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
ui->centerFrequency->setValueRange(7, 0, pow(10,7));
ui->fileNameText->setText(m_fileName);
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
displaySettings();
@ -118,13 +120,20 @@ bool FileSourceGui::deserialize(const QByteArray& data)
bool FileSourceGui::handleMessage(Message* message)
{
if(FileSourceInput::MsgReportFileSource::match(message))
if(FileSourceInput::MsgReportFileSourceAcquisition::match(message))
{
m_acquisition = ((FileSourceInput::MsgReportFileSource*)message)->getAcquisition();
m_sampleRate = ((FileSourceInput::MsgReportFileSource*)message)->getSampleRate();
m_centerFrequency = ((FileSourceInput::MsgReportFileSource*)message)->getCenterFrequency();
m_startingTimeStamp = ((FileSourceInput::MsgReportFileSource*)message)->getStartingTimeStamp();
displaySettings();
m_acquisition = ((FileSourceInput::MsgReportFileSourceAcquisition*)message)->getAcquisition();
updateWithAcquisition();
message->completed();
return true;
}
else if(FileSourceInput::MsgReportFileSourceStreamData::match(message))
{
std::cerr << "FileSourceGui::handleMessage: MsgReportFileSourceStreamData" << std::endl;
m_sampleRate = ((FileSourceInput::MsgReportFileSourceStreamData*)message)->getSampleRate();
m_centerFrequency = ((FileSourceInput::MsgReportFileSourceStreamData*)message)->getCenterFrequency();
m_startingTimeStamp = ((FileSourceInput::MsgReportFileSourceStreamData*)message)->getStartingTimeStamp();
updateWithStreamData();
message->completed();
return true;
}
@ -135,15 +144,64 @@ bool FileSourceGui::handleMessage(Message* message)
}
void FileSourceGui::displaySettings()
{
}
void FileSourceGui::sendSettings()
{
/*
if(!m_updateTimer.isActive())
m_updateTimer.start(100);
*/
}
void FileSourceGui::updateHardware()
{
/*
FileSourceInput::MsgConfigureFileSource* message = FileSourceInput::MsgConfigureFileSource::create(m_generalSettings, m_settings);
message->submit(m_pluginAPI->getDSPEngineMessageQueue());
m_updateTimer.stop();*/
}
void FileSourceGui::on_play_toggled(bool checked)
{
}
void FileSourceGui::on_showFileDialog_clicked(bool checked)
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open I/Q record file"), ".", tr("SDR I/Q Files (*.sdriq)"));
if (fileName != "") {
m_fileName = fileName;
ui->fileNameText->setText(m_fileName);
configureFileName();
}
}
void FileSourceGui::configureFileName()
{
std::cerr << "FileSourceGui::configureFileName: " << m_fileName.toStdString() << std::endl;
FileSourceInput::MsgConfigureFileName* message = FileSourceInput::MsgConfigureFileName::create(m_fileName);
message->submit(m_pluginAPI->getDSPEngineMessageQueue());
}
void FileSourceGui::updateWithAcquisition()
{
ui->play->setEnabled(m_acquisition);
ui->play->setChecked(m_acquisition);
ui->showFileDialog->setEnabled(!m_acquisition);
}
void FileSourceGui::updateWithStreamData()
{
ui->centerFrequency->setValue(m_centerFrequency/1000);
QString s = QString::number(m_sampleRate/1000.0, 'f', 0);
ui->sampleRateText->setText(tr("%1k").arg(s));
ui->play->setEnabled(m_acquisition);
displayTime();
updateWithStreamTime(); // TODO: remove when time data is implemented
}
void FileSourceGui::displayTime()
void FileSourceGui::updateWithStreamTime()
{
int t_sec = 0;
int t_msec = 0;
@ -166,31 +224,3 @@ void FileSourceGui::displayTime()
QString s_date = dt.toString("yyyyMMdd hh.mm.ss.zzz");
ui->absTimeText->setText(s_date);
}
void FileSourceGui::sendSettings()
{
if(!m_updateTimer.isActive())
m_updateTimer.start(100);
}
void FileSourceGui::updateHardware()
{
FileSourceInput::MsgConfigureFileSource* message = FileSourceInput::MsgConfigureFileSource::create(m_generalSettings, m_settings);
message->submit(m_pluginAPI->getDSPEngineMessageQueue());
m_updateTimer.stop();
}
void FileSourceGui::on_play_toggled(bool checked)
{
}
void FileSourceGui::on_showFileDialog_clicked(bool checked)
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open I/Q record file"), ".", tr("SDR I/Q Files (*.sdriq)"));
if (fileName != "") {
m_settings.m_fileName = fileName;
ui->fileNameText->setText(m_settings.m_fileName);
sendSettings();
}
}

View File

@ -57,6 +57,7 @@ private:
std::vector<int> m_gains;
SampleSource* m_sampleSource;
bool m_acquisition;
QString m_fileName;
int m_sampleRate;
quint64 m_centerFrequency;
std::time_t m_startingTimeStamp;
@ -66,6 +67,10 @@ private:
void displayTime();
void sendSettings();
void updateHardware();
void configureFileName();
void updateWithAcquisition();
void updateWithStreamData();
void updateWithStreamTime();
private slots:
void on_playLoop_toggled(bool checked);

View File

@ -27,7 +27,9 @@
#include "filesourcethread.h"
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSource, Message)
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSource, Message)
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileName, Message)
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceAcquisition, Message)
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceStreamData, Message)
FileSourceInput::Settings::Settings() :
m_fileName("./test.sdriq")
@ -70,6 +72,7 @@ FileSourceInput::FileSourceInput(MessageQueue* msgQueueToGUI, const QTimer& mast
m_settings(),
m_fileSourceThread(NULL),
m_deviceDescription(),
m_fileName("..."),
m_sampleRate(0),
m_centerFrequency(0),
m_startingTimeStamp(0),
@ -84,30 +87,46 @@ FileSourceInput::~FileSourceInput()
void FileSourceInput::openFileStream()
{
std::cerr << "FileSourceInput::openFileStream: " << m_fileName.toStdString() << std::endl;
//stopInput();
if (m_ifstream.is_open()) {
m_ifstream.close();
}
m_ifstream.open(m_settings.m_fileName.toStdString().c_str(), std::ios::binary);
m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary);
FileSink::Header header;
FileSink::readHeader(m_ifstream, header);
m_sampleRate = header.sampleRate;
m_centerFrequency = header.centerFrequency;
m_startingTimeStamp = header.startTimeStamp;
MsgReportFileSourceStreamData::create(m_sampleRate, m_centerFrequency, m_startingTimeStamp)->submit(m_guiMessageQueue); // file stream data
}
bool FileSourceInput::startInput(int device)
{
std::cerr << "FileSourceInput::startInput" << std::endl;
QMutexLocker mutexLocker(&m_mutex);
std::cerr << "FileSourceInput::startInput" << std::endl;
/*
if (!m_ifstream.is_open()) {
openFileStream();
}*/
if (m_ifstream.tellg() != 0) {
m_ifstream.clear();
m_ifstream.seekg(0, std::ios::beg);
}
if(!m_sampleFifo.setSize(96000 * 4)) {
qCritical("Could not allocate SampleFifo");
return false;
}
openFileStream();
//openFileStream();
if((m_fileSourceThread = new FileSourceThread(&m_ifstream, &m_sampleFifo)) == NULL) {
qFatal("out of memory");
@ -119,9 +138,9 @@ bool FileSourceInput::startInput(int device)
m_fileSourceThread->startWork();
mutexLocker.unlock();
applySettings(m_generalSettings, m_settings, true);
//applySettings(m_generalSettings, m_settings, true);
MsgReportFileSource::create(true, m_sampleRate, m_centerFrequency, m_startingTimeStamp)->submit(m_guiMessageQueue); // acquisition on
MsgReportFileSourceAcquisition::create(true)->submit(m_guiMessageQueue); // acquisition on
return true;
@ -143,7 +162,7 @@ void FileSourceInput::stopInput()
m_deviceDescription.clear();
MsgReportFileSource::create(false, m_sampleRate, m_centerFrequency, m_startingTimeStamp)->submit(m_guiMessageQueue); // acquisition off
MsgReportFileSourceAcquisition::create(false)->submit(m_guiMessageQueue); // acquisition off
}
const QString& FileSourceInput::getDeviceDescription() const
@ -168,10 +187,11 @@ std::time_t FileSourceInput::getStartingTimeStamp() const
bool FileSourceInput::handleMessage(Message* message)
{
if(MsgConfigureFileSource::match(message)) {
MsgConfigureFileSource* conf = (MsgConfigureFileSource*)message;
if(!applySettings(conf->getGeneralSettings(), conf->getSettings(), false))
qDebug("File Source config error");
if(MsgConfigureFileName::match(message)) {
std::cerr << "FileSourceInput::handleMessage: MsgConfigureFileName" << std::endl;
MsgConfigureFileName* conf = (MsgConfigureFileName*) message;
m_fileName = conf->getFileName();
openFileStream();
message->completed();
return true;
} else {

View File

@ -60,30 +60,66 @@ public:
{ }
};
class MsgReportFileSource : public Message {
class MsgConfigureFileName : public Message {
MESSAGE_CLASS_DECLARATION
public:
const QString& getFileName() const { return m_fileName; }
static MsgConfigureFileName* create(const QString& fileName)
{
return new MsgConfigureFileName(fileName);
}
private:
QString m_fileName;
MsgConfigureFileName(const QString& fileName) :
Message(),
m_fileName(fileName)
{ }
};
class MsgReportFileSourceAcquisition : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getAcquisition() const { return m_acquisition; }
int getSampleRate() const { return m_sampleRate; }
quint64 getCenterFrequency() const { return m_centerFrequency; }
std::time_t getStartingTimeStamp() const { return m_startingTimeStamp; }
static MsgReportFileSource* create(bool acquisition, int sampleRate, quint64 centerFrequency, std::time_t startingTimeStamp)
static MsgReportFileSourceAcquisition* create(bool acquisition)
{
return new MsgReportFileSource(acquisition, sampleRate, centerFrequency, startingTimeStamp);
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; }
static MsgReportFileSourceStreamData* create(int sampleRate, quint64 centerFrequency, std::time_t startingTimeStamp)
{
return new MsgReportFileSourceStreamData(sampleRate, centerFrequency, startingTimeStamp);
}
protected:
int m_sampleRate;
quint64 m_centerFrequency;
std::time_t m_startingTimeStamp;
MsgReportFileSource(bool acquisition, int sampleRate, quint64 centerFrequency, std::time_t startingTimeStamp) :
MsgReportFileSourceStreamData(int sampleRate, quint64 centerFrequency, std::time_t startingTimeStamp) :
Message(),
m_acquisition(acquisition),
m_sampleRate(sampleRate),
m_centerFrequency(centerFrequency),
m_startingTimeStamp(startingTimeStamp)
@ -109,6 +145,7 @@ private:
std::ifstream m_ifstream;
FileSourceThread* m_fileSourceThread;
QString m_deviceDescription;
QString m_fileName;
int m_sampleRate;
quint64 m_centerFrequency;
std::time_t m_startingTimeStamp;

View File

@ -141,7 +141,7 @@ void FileSourceThread::tick()
m_sampleFifo->write(m_buf, m_ifstream->gcount());
// TODO: handle loop playback situation
stopWork();
m_ifstream->close();
//m_ifstream->close();
}
else
{