mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-22 08:04:49 -05:00
File source debugging interim state #2. Make file source GUI and input talk together
This commit is contained in:
parent
fb167dad70
commit
75f10a3b63
@ -16,6 +16,9 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QTime>
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include "ui_filesourcegui.h"
|
||||
#include "plugin/pluginapi.h"
|
||||
#include "gui/colormapper.h"
|
||||
@ -28,7 +31,12 @@ FileSourceGui::FileSourceGui(PluginAPI* pluginAPI, QWidget* parent) :
|
||||
ui(new Ui::FileSourceGui),
|
||||
m_pluginAPI(pluginAPI),
|
||||
m_settings(),
|
||||
m_sampleSource(NULL)
|
||||
m_sampleSource(NULL),
|
||||
m_acquisition(false),
|
||||
m_sampleRate(0),
|
||||
m_centerFrequency(0),
|
||||
m_startingTimeStamp(0),
|
||||
m_samplesCount(0)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
|
||||
@ -109,17 +117,53 @@ bool FileSourceGui::deserialize(const QByteArray& data)
|
||||
|
||||
bool FileSourceGui::handleMessage(Message* message)
|
||||
{
|
||||
if(FileSourceInput::MsgReportFileSource::match(message)) {
|
||||
if(FileSourceInput::MsgReportFileSource::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();
|
||||
message->completed();
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void FileSourceGui::displaySettings()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
void FileSourceGui::displayTime()
|
||||
{
|
||||
int t_sec = 0;
|
||||
int t_msec = 0;
|
||||
|
||||
if (m_sampleRate > 0){
|
||||
t_msec = ((m_samplesCount * 1000) / m_sampleRate) % 1000;
|
||||
t_sec = m_samplesCount / m_sampleRate;
|
||||
}
|
||||
|
||||
QTime t(0, 0, 0, 0);
|
||||
t.addSecs(t_sec);
|
||||
t.addMSecs(t_msec);
|
||||
QString s_time = t.toString("hh:mm:ss.zzz");
|
||||
ui->relTimeText->setText(s_time);
|
||||
|
||||
quint64 startingTimeStampMsec = m_startingTimeStamp * 1000;
|
||||
QDateTime dt = QDateTime::fromMSecsSinceEpoch(startingTimeStampMsec);
|
||||
dt.addSecs(t_sec);
|
||||
dt.addMSecs(t_msec);
|
||||
QString s_date = dt.toString("yyyyMMdd hh.mm.ss.zzz");
|
||||
ui->absTimeText->setText(s_date);
|
||||
}
|
||||
|
||||
void FileSourceGui::sendSettings()
|
||||
@ -134,3 +178,8 @@ void FileSourceGui::updateHardware()
|
||||
message->submit(m_pluginAPI->getDSPEngineMessageQueue());
|
||||
m_updateTimer.stop();
|
||||
}
|
||||
|
||||
void FileSourceGui::on_play_toggled(bool checked)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -56,8 +56,14 @@ private:
|
||||
QTimer m_updateTimer;
|
||||
std::vector<int> m_gains;
|
||||
SampleSource* m_sampleSource;
|
||||
bool m_acquisition;
|
||||
int m_sampleRate;
|
||||
quint64 m_centerFrequency;
|
||||
std::time_t m_startingTimeStamp;
|
||||
int m_samplesCount;
|
||||
|
||||
void displaySettings();
|
||||
void displayTime();
|
||||
void sendSettings();
|
||||
void updateHardware();
|
||||
|
||||
|
@ -80,7 +80,7 @@
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Tuner center frequency in kHz</string>
|
||||
<string>Record center frequency in kHz</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -109,14 +109,14 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="rateTimeLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="rateText">
|
||||
<widget class="QLabel" name="sampleRateText">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>8</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Rate</string>
|
||||
<string>Record sample rate</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>0k</string>
|
||||
@ -153,6 +153,9 @@
|
||||
<pointsize>8</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Record absolute time</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>20150101 00:00:00.000</string>
|
||||
</property>
|
||||
@ -171,11 +174,14 @@
|
||||
<layout class="QHBoxLayout" name="playControllLayout">
|
||||
<item>
|
||||
<widget class="ButtonSwitch" name="playLoop">
|
||||
<property name="toolTip">
|
||||
<string>Play in a loop</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="../../../sdrbase/resources/res.qrc">
|
||||
<normaloff>:/playloop.png</normaloff>:/playloop.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
@ -191,12 +197,22 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ButtonSwitch" name="play">
|
||||
<property name="toolTip">
|
||||
<string>Stopped / Play / Pause</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>:/play.png</normaloff>:/play.png</iconset>
|
||||
<iconset resource="../../../sdrbase/resources/res.qrc">
|
||||
<normaloff>:/pause.png</normaloff>
|
||||
<normalon>:/play.png</normalon>
|
||||
<disabledoff>:/stop.png</disabledoff>
|
||||
<disabledon>:/stop.png</disabledon>
|
||||
<activeoff>:/pause.png</activeoff>
|
||||
<activeon>:/play.png</activeon>
|
||||
<selectedoff>:/pause.png</selectedoff>
|
||||
<selectedon>:/play.png</selectedon>:/pause.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
@ -242,6 +258,9 @@
|
||||
<pointsize>8</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Record time from start</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>00:00:00.000</string>
|
||||
</property>
|
||||
@ -264,6 +283,8 @@
|
||||
<header>gui/buttonswitch.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../../../sdrbase/resources/res.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -84,6 +84,10 @@ FileSourceInput::~FileSourceInput()
|
||||
|
||||
void FileSourceInput::openFileStream()
|
||||
{
|
||||
if (m_ifstream.is_open()) {
|
||||
m_ifstream.close();
|
||||
}
|
||||
|
||||
m_ifstream.open(m_settings.m_fileName.toStdString().c_str(), std::ios::binary);
|
||||
FileSink::Header header;
|
||||
FileSink::readHeader(m_ifstream, header);
|
||||
@ -95,6 +99,7 @@ void FileSourceInput::openFileStream()
|
||||
|
||||
bool FileSourceInput::startInput(int device)
|
||||
{
|
||||
std::cerr << "FileSourceInput::startInput" << std::endl;
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
openFileStream();
|
||||
@ -111,8 +116,7 @@ bool FileSourceInput::startInput(int device)
|
||||
mutexLocker.unlock();
|
||||
applySettings(m_generalSettings, m_settings, true);
|
||||
|
||||
qDebug("bladerfInput: start");
|
||||
//MsgReportBladerf::create(m_gains)->submit(m_guiMessageQueue); Pass anything here
|
||||
MsgReportFileSource::create(true, m_sampleRate, m_centerFrequency, m_startingTimeStamp)->submit(m_guiMessageQueue); // acquisition on
|
||||
|
||||
return true;
|
||||
|
||||
@ -123,6 +127,7 @@ failed:
|
||||
|
||||
void FileSourceInput::stopInput()
|
||||
{
|
||||
std::cerr << "FileSourceInput::stopInput()" << std::endl;
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
if(m_fileSourceThread != NULL) {
|
||||
@ -132,6 +137,8 @@ void FileSourceInput::stopInput()
|
||||
}
|
||||
|
||||
m_deviceDescription.clear();
|
||||
|
||||
MsgReportFileSource::create(false, m_sampleRate, m_centerFrequency, m_startingTimeStamp)->submit(m_guiMessageQueue); // acquisition off
|
||||
}
|
||||
|
||||
const QString& FileSourceInput::getDeviceDescription() const
|
||||
|
@ -64,16 +64,29 @@ public:
|
||||
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()
|
||||
static MsgReportFileSource* create(bool acquisition, int sampleRate, quint64 centerFrequency, std::time_t startingTimeStamp)
|
||||
{
|
||||
return new MsgReportFileSource();
|
||||
return new MsgReportFileSource(acquisition, sampleRate, centerFrequency, startingTimeStamp);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool m_acquisition;
|
||||
int m_sampleRate;
|
||||
quint64 m_centerFrequency;
|
||||
std::time_t m_startingTimeStamp;
|
||||
|
||||
MsgReportFileSource() :
|
||||
Message()
|
||||
|
||||
MsgReportFileSource(bool acquisition, int sampleRate, quint64 centerFrequency, std::time_t startingTimeStamp) :
|
||||
Message(),
|
||||
m_acquisition(acquisition),
|
||||
m_sampleRate(sampleRate),
|
||||
m_centerFrequency(centerFrequency),
|
||||
m_startingTimeStamp(startingTimeStamp)
|
||||
{ }
|
||||
};
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include "dsp/samplefifo.h"
|
||||
|
||||
#include "filesourcethread.h"
|
||||
@ -32,6 +33,7 @@ FileSourceThread::FileSourceThread(std::ifstream *samplesStream, SampleFifo* sam
|
||||
m_sampleFifo(sampleFifo),
|
||||
m_samplerate(0)
|
||||
{
|
||||
assert(m_ifstream != 0);
|
||||
}
|
||||
|
||||
FileSourceThread::~FileSourceThread()
|
||||
@ -47,12 +49,21 @@ FileSourceThread::~FileSourceThread()
|
||||
|
||||
void FileSourceThread::startWork()
|
||||
{
|
||||
std::cerr << "FileSourceThread::startWork" << std::endl;
|
||||
m_startWaitMutex.lock();
|
||||
start();
|
||||
while(!m_running)
|
||||
m_startWaiter.wait(&m_startWaitMutex, 100);
|
||||
m_startWaitMutex.unlock();
|
||||
std::cerr << "FileSourceThread::startWork: ";
|
||||
|
||||
if (m_ifstream->is_open())
|
||||
{
|
||||
std::cerr << " file stream open, starting..." << std::endl;
|
||||
m_startWaitMutex.lock();
|
||||
start();
|
||||
while(!m_running)
|
||||
m_startWaiter.wait(&m_startWaitMutex, 100);
|
||||
m_startWaitMutex.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << " file stream closed, not starting." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void FileSourceThread::stopWork()
|
||||
@ -64,19 +75,33 @@ void FileSourceThread::stopWork()
|
||||
|
||||
void FileSourceThread::setSamplerate(int samplerate)
|
||||
{
|
||||
std::cerr << "FileSourceThread::setSamplerate:"
|
||||
<< " new:" << samplerate
|
||||
<< " old:" << m_samplerate;
|
||||
|
||||
if (samplerate != m_samplerate)
|
||||
{
|
||||
if (m_running) {
|
||||
stopWork();
|
||||
}
|
||||
|
||||
m_samplerate = samplerate;
|
||||
m_bufsize = (m_samplerate / m_rateDivider)*4;
|
||||
|
||||
if (m_buf == 0) {
|
||||
std::cerr << " Allocate buffer";
|
||||
m_buf = (quint8*) malloc(m_bufsize);
|
||||
} else {
|
||||
std::cerr << " Re-allocate buffer";
|
||||
m_buf = (quint8*) realloc((void*) m_buf, m_bufsize);
|
||||
}
|
||||
|
||||
std::cerr << " size: " << m_bufsize
|
||||
<< " #samples: " << (m_bufsize/4) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
m_samplerate = samplerate;
|
||||
@ -90,7 +115,7 @@ void FileSourceThread::run()
|
||||
m_running = true;
|
||||
m_startWaiter.wakeAll();
|
||||
|
||||
while(m_running)
|
||||
while(m_running) // actual work is in the tick() function
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
@ -110,7 +135,18 @@ void FileSourceThread::tick()
|
||||
{
|
||||
// read samples directly feeding the SampleFifo (no callback)
|
||||
m_ifstream->read(reinterpret_cast<char*>(m_buf), m_chunksize);
|
||||
m_sampleFifo->write(m_buf, m_chunksize);
|
||||
|
||||
if (m_ifstream->eof())
|
||||
{
|
||||
m_sampleFifo->write(m_buf, m_ifstream->gcount());
|
||||
// TODO: handle loop playback situation
|
||||
stopWork();
|
||||
m_ifstream->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_sampleFifo->write(m_buf, m_chunksize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
BIN
sdrbase/resources/pause.png
Normal file
BIN
sdrbase/resources/pause.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 307 B |
@ -27,5 +27,7 @@
|
||||
<file>clear.png</file>
|
||||
<file>playloop.png</file>
|
||||
<file>play.png</file>
|
||||
<file>pause.png</file>
|
||||
<file>stop.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
sdrbase/resources/stop.png
Normal file
BIN
sdrbase/resources/stop.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 264 B |
Loading…
Reference in New Issue
Block a user