1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-13 20:01:46 -05:00
sdrangel/plugins/samplesink/filesink/filesinkgui.cpp

337 lines
9.6 KiB
C++
Raw Normal View History

2016-10-19 12:42:57 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 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 <QDebug>
#include <QTime>
#include <QDateTime>
#include <QString>
#include <QFileDialog>
#include <QMessageBox>
#include "ui_filesinkgui.h"
#include "plugin/pluginapi.h"
#include "gui/colormapper.h"
#include "gui/glspectrum.h"
#include "dsp/dspengine.h"
#include "dsp/dspcommands.h"
#include "mainwindow.h"
#include "device/devicesinkapi.h"
#include "device/deviceuiset.h"
2016-10-19 12:42:57 -04:00
#include "filesinkgui.h"
FileSinkGui::FileSinkGui(DeviceUISet *deviceUISet, QWidget* parent) :
2016-10-19 12:42:57 -04:00
QWidget(parent),
ui(new Ui::FileSinkGui),
m_deviceUISet(deviceUISet),
m_doApplySettings(true),
m_forceSettings(true),
2016-10-19 12:42:57 -04:00
m_settings(),
m_fileName("./test.sdriq"),
2017-05-25 14:13:34 -04:00
m_deviceSampleSink(0),
m_sampleRate(0),
m_generation(false),
2016-10-19 12:42:57 -04:00
m_startingTimeStamp(0),
m_samplesCount(0),
m_tickCount(0),
m_lastEngineState((DSPDeviceSinkEngine::State)-1)
{
ui->setupUi(this);
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
2016-10-19 12:42:57 -04:00
ui->centerFrequency->setValueRange(7, 0, pow(10,7));
ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow));
ui->sampleRate->setValueRange(7, 32000U, 9000000U);
ui->fileNameText->setText(m_fileName);
2016-10-19 12:42:57 -04:00
connect(&(m_deviceUISet->m_deviceSinkAPI->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
2016-10-19 12:42:57 -04:00
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(500);
displaySettings();
m_deviceSampleSink = (FileSinkOutput*) m_deviceUISet->m_deviceSinkAPI->getSampleSink();
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
2016-10-19 12:42:57 -04:00
}
FileSinkGui::~FileSinkGui()
{
delete ui;
}
void FileSinkGui::destroy()
{
delete this;
}
void FileSinkGui::setName(const QString& name)
{
setObjectName(name);
}
QString FileSinkGui::getName() const
{
return objectName();
}
void FileSinkGui::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
sendSettings();
}
qint64 FileSinkGui::getCenterFrequency() const
{
return m_settings.m_centerFrequency;
2016-10-19 12:42:57 -04:00
}
void FileSinkGui::setCenterFrequency(qint64 centerFrequency)
{
m_settings.m_centerFrequency = centerFrequency;
2016-10-19 12:42:57 -04:00
displaySettings();
sendSettings();
}
QByteArray FileSinkGui::serialize() const
{
return m_settings.serialize();
}
bool FileSinkGui::deserialize(const QByteArray& data)
{
if(m_settings.deserialize(data)) {
displaySettings();
m_forceSettings = true;
2016-10-19 12:42:57 -04:00
sendSettings();
return true;
} else {
resetToDefaults();
return false;
}
}
bool FileSinkGui::handleMessage(const Message& message)
{
if (FileSinkOutput::MsgConfigureFileSink::match(message))
{
const FileSinkOutput::MsgConfigureFileSink& cfg = (FileSinkOutput::MsgConfigureFileSink&) message;
m_settings = cfg.getSettings();
blockApplySettings(true);
displaySettings();
blockApplySettings(false);
return true;
}
else if (FileSinkOutput::MsgReportFileSinkGeneration::match(message))
2016-10-19 12:42:57 -04:00
{
m_generation = ((FileSinkOutput::MsgReportFileSinkGeneration&)message).getAcquisition();
updateWithGeneration();
return true;
}
else if (FileSinkOutput::MsgReportFileSinkStreamTiming::match(message))
{
m_samplesCount = ((FileSinkOutput::MsgReportFileSinkStreamTiming&)message).getSamplesCount();
updateWithStreamTime();
return true;
}
else if (FileSinkOutput::MsgStartStop::match(message))
{
FileSinkOutput::MsgStartStop& notif = (FileSinkOutput::MsgStartStop&) message;
blockApplySettings(true);
ui->startStop->setChecked(notif.getStartStop());
blockApplySettings(false);
return true;
}
2016-10-19 12:42:57 -04:00
else
{
return false;
}
}
void FileSinkGui::handleInputMessages()
2016-10-19 12:42:57 -04:00
{
Message* message;
2016-10-19 12:42:57 -04:00
while ((message = m_inputMessageQueue.pop()) != 0)
{
qDebug("FileSinkGui::handleInputMessages: message: %s", message->getIdentifier());
2016-10-19 12:42:57 -04:00
if (DSPSignalNotification::match(*message))
{
DSPSignalNotification* notif = (DSPSignalNotification*) message;
qDebug("FileSinkGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
m_sampleRate = notif->getSampleRate();
m_deviceCenterFrequency = notif->getCenterFrequency();
updateSampleRateAndFrequency();
delete message;
}
else
{
if (handleMessage(*message))
{
delete message;
}
}
}
}
void FileSinkGui::updateSampleRateAndFrequency()
{
m_deviceUISet->getSpectrum()->setSampleRate(m_sampleRate);
m_deviceUISet->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency);
ui->deviceRateText->setText(tr("%1k").arg((float)(m_sampleRate*(1<<m_settings.m_log2Interp)) / 1000));
2016-10-19 12:42:57 -04:00
}
void FileSinkGui::displaySettings()
{
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
ui->sampleRate->setValue(m_settings.m_sampleRate);
2016-10-19 12:42:57 -04:00
}
void FileSinkGui::sendSettings()
{
if(!m_updateTimer.isActive())
m_updateTimer.start(100);
}
void FileSinkGui::updateHardware()
{
qDebug() << "FileSinkGui::updateHardware";
FileSinkOutput::MsgConfigureFileSink* message = FileSinkOutput::MsgConfigureFileSink::create(m_settings, m_forceSettings);
m_deviceSampleSink->getInputMessageQueue()->push(message);
m_forceSettings = false;
m_updateTimer.stop();
2016-10-19 12:42:57 -04:00
}
void FileSinkGui::updateStatus()
{
int state = m_deviceUISet->m_deviceSinkAPI->state();
2016-10-19 12:42:57 -04:00
if(m_lastEngineState != state)
{
switch(state)
{
case DSPDeviceSinkEngine::StNotStarted:
2016-10-19 12:42:57 -04:00
ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
break;
case DSPDeviceSinkEngine::StIdle:
2016-10-19 12:42:57 -04:00
ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
break;
case DSPDeviceSinkEngine::StRunning:
ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
2016-10-19 12:42:57 -04:00
break;
case DSPDeviceSinkEngine::StError:
ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceSinkAPI->errorMessage());
2016-10-19 12:42:57 -04:00
break;
default:
break;
}
m_lastEngineState = state;
}
}
void FileSinkGui::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
sendSettings();
}
void FileSinkGui::on_sampleRate_changed(quint64 value)
2016-10-19 12:42:57 -04:00
{
m_settings.m_sampleRate = value;
sendSettings();
}
void FileSinkGui::on_interp_currentIndexChanged(int index)
{
if (index < 0) {
return;
}
m_settings.m_log2Interp = index;
updateSampleRateAndFrequency();
sendSettings();
}
void FileSinkGui::on_startStop_toggled(bool checked)
{
if (m_doApplySettings)
{
FileSinkOutput::MsgStartStop *message = FileSinkOutput::MsgStartStop::create(checked);
m_deviceSampleSink->getInputMessageQueue()->push(message);
}
2016-10-19 12:42:57 -04:00
}
2017-05-25 14:13:34 -04:00
void FileSinkGui::on_showFileDialog_clicked(bool checked __attribute__((unused)))
2016-10-19 12:42:57 -04:00
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save I/Q record file"), ".", tr("SDR I/Q Files (*.sdriq)"));
2016-10-19 12:42:57 -04:00
if (fileName != "")
{
m_fileName = fileName;
ui->fileNameText->setText(m_fileName);
configureFileName();
}
}
void FileSinkGui::configureFileName()
{
qDebug() << "FileSinkGui::configureFileName: " << m_fileName.toStdString().c_str();
FileSinkOutput::MsgConfigureFileSinkName* message = FileSinkOutput::MsgConfigureFileSinkName::create(m_fileName);
m_deviceSampleSink->getInputMessageQueue()->push(message);
2016-10-19 12:42:57 -04:00
}
void FileSinkGui::updateWithGeneration()
{
ui->showFileDialog->setEnabled(!m_generation);
}
void FileSinkGui::updateWithStreamTime()
{
int t_sec = 0;
int t_msec = 0;
if (m_settings.m_sampleRate > 0){
t_msec = ((m_samplesCount * 1000) / m_settings.m_sampleRate) % 1000;
t_sec = m_samplesCount / m_settings.m_sampleRate;
2016-10-19 12:42:57 -04:00
}
QTime t(0, 0, 0, 0);
t = t.addSecs(t_sec);
t = t.addMSecs(t_msec);
QString s_timems = t.toString("hh:mm:ss.zzz");
ui->relTimeText->setText(s_timems);
}
void FileSinkGui::tick()
{
if ((++m_tickCount & 0xf) == 0)
{
2016-10-19 12:42:57 -04:00
FileSinkOutput::MsgConfigureFileSinkStreamTiming* message = FileSinkOutput::MsgConfigureFileSinkStreamTiming::create();
m_deviceSampleSink->getInputMessageQueue()->push(message);
2016-10-19 12:42:57 -04:00
}
}