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 //
|
2019-04-11 00:39:30 -04:00
|
|
|
// (at your option) any later version. //
|
2016-10-19 12:42:57 -04:00
|
|
|
// //
|
|
|
|
// 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>
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
#include "ui_fileoutputgui.h"
|
2016-10-19 12:42:57 -04:00
|
|
|
#include "plugin/pluginapi.h"
|
|
|
|
#include "gui/colormapper.h"
|
|
|
|
#include "gui/glspectrum.h"
|
|
|
|
#include "dsp/dspengine.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2017-10-29 20:11:35 -04:00
|
|
|
#include "device/deviceuiset.h"
|
2020-08-03 18:29:15 -04:00
|
|
|
#include "fileoutputgui.h"
|
2016-10-19 12:42:57 -04:00
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
FileOutputGui::FileOutputGui(DeviceUISet *deviceUISet, QWidget* parent) :
|
2016-10-19 12:42:57 -04:00
|
|
|
QWidget(parent),
|
2020-08-03 18:29:15 -04:00
|
|
|
ui(new Ui::FileOutputGui),
|
2017-10-29 20:11:35 -04:00
|
|
|
m_deviceUISet(deviceUISet),
|
2017-12-13 18:38:22 -05:00
|
|
|
m_doApplySettings(true),
|
2017-10-14 01:28:57 -04:00
|
|
|
m_forceSettings(true),
|
2016-10-19 12:42:57 -04:00
|
|
|
m_settings(),
|
2016-10-20 19:21:17 -04:00
|
|
|
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),
|
2019-05-08 16:11:53 -04:00
|
|
|
m_lastEngineState(DeviceAPI::StNotStarted)
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2017-04-06 13:19:32 -04:00
|
|
|
|
2017-05-16 10:21:59 -04:00
|
|
|
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
|
2016-10-19 12:42:57 -04:00
|
|
|
ui->centerFrequency->setValueRange(7, 0, pow(10,7));
|
|
|
|
|
2017-05-16 10:21:59 -04:00
|
|
|
ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow));
|
2020-09-28 04:48:20 -04:00
|
|
|
ui->sampleRate->setValueRange(8, 32000U, 90000000U);
|
2017-04-06 13:19:32 -04:00
|
|
|
|
|
|
|
ui->fileNameText->setText(m_fileName);
|
2016-10-19 12:42:57 -04:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
connect(&(m_deviceUISet->m_deviceAPI->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
|
2016-10-22 20:22:00 -04:00
|
|
|
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();
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
m_deviceSampleSink = (FileOutput*) m_deviceUISet->m_deviceAPI->getSampleSink();
|
2017-09-17 11:35:03 -04:00
|
|
|
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
|
2016-10-19 12:42:57 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
FileOutputGui::~FileOutputGui()
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::destroy()
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::setName(const QString& name)
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
|
|
|
setObjectName(name);
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
QString FileOutputGui::getName() const
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
|
|
|
return objectName();
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::resetToDefaults()
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
displaySettings();
|
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
qint64 FileOutputGui::getCenterFrequency() const
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2016-10-20 19:21:17 -04:00
|
|
|
return m_settings.m_centerFrequency;
|
2016-10-19 12:42:57 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::setCenterFrequency(qint64 centerFrequency)
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2016-10-20 19:21:17 -04:00
|
|
|
m_settings.m_centerFrequency = centerFrequency;
|
2016-10-19 12:42:57 -04:00
|
|
|
displaySettings();
|
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
QByteArray FileOutputGui::serialize() const
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
bool FileOutputGui::deserialize(const QByteArray& data)
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
|
|
|
if(m_settings.deserialize(data)) {
|
|
|
|
displaySettings();
|
2017-10-14 01:28:57 -04:00
|
|
|
m_forceSettings = true;
|
2016-10-19 12:42:57 -04:00
|
|
|
sendSettings();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
resetToDefaults();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
bool FileOutputGui::handleMessage(const Message& message)
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2020-08-03 18:29:15 -04:00
|
|
|
if (FileOutput::MsgConfigureFileOutput::match(message))
|
2017-12-27 22:04:50 -05:00
|
|
|
{
|
2020-08-03 18:29:15 -04:00
|
|
|
qDebug("FileOutputGui::handleMessage: message: MsgConfigureFileOutput");
|
|
|
|
const FileOutput::MsgConfigureFileOutput& cfg = (FileOutput::MsgConfigureFileOutput&) message;
|
2017-12-27 22:04:50 -05:00
|
|
|
m_settings = cfg.getSettings();
|
|
|
|
blockApplySettings(true);
|
|
|
|
displaySettings();
|
|
|
|
blockApplySettings(false);
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-03 18:29:15 -04:00
|
|
|
else if (FileOutput::MsgReportFileOutputGeneration::match(message))
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2020-08-03 18:29:15 -04:00
|
|
|
m_generation = ((FileOutput::MsgReportFileOutputGeneration&)message).getAcquisition();
|
|
|
|
qDebug("FileOutputGui::handleMessage: message: MsgReportFileOutputGeneration: %s", m_generation ? "start" : "stop");
|
2016-10-19 12:42:57 -04:00
|
|
|
updateWithGeneration();
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-03 18:29:15 -04:00
|
|
|
else if (FileOutput::MsgReportFileOutputStreamTiming::match(message))
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2020-08-03 18:29:15 -04:00
|
|
|
m_samplesCount = ((FileOutput::MsgReportFileOutputStreamTiming&)message).getSamplesCount();
|
2016-10-19 12:42:57 -04:00
|
|
|
updateWithStreamTime();
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-03 18:29:15 -04:00
|
|
|
else if (FileOutput::MsgStartStop::match(message))
|
2017-12-13 18:38:22 -05:00
|
|
|
{
|
2020-08-03 18:29:15 -04:00
|
|
|
FileOutput::MsgStartStop& notif = (FileOutput::MsgStartStop&) message;
|
|
|
|
qDebug("FileOutputGui::handleMessage: message: MsgStartStop: %s", notif.getStartStop() ? "start" : "stop");
|
2017-12-13 18:38:22 -05:00
|
|
|
blockApplySettings(true);
|
|
|
|
ui->startStop->setChecked(notif.getStartStop());
|
|
|
|
blockApplySettings(false);
|
|
|
|
return true;
|
|
|
|
}
|
2016-10-19 12:42:57 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::handleInputMessages()
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2016-10-22 20:22:00 -04:00
|
|
|
Message* message;
|
2016-10-19 12:42:57 -04:00
|
|
|
|
2017-09-17 11:35:03 -04:00
|
|
|
while ((message = m_inputMessageQueue.pop()) != 0)
|
2016-10-22 20:22:00 -04:00
|
|
|
{
|
2016-10-19 12:42:57 -04:00
|
|
|
|
2016-10-22 20:22:00 -04:00
|
|
|
if (DSPSignalNotification::match(*message))
|
|
|
|
{
|
|
|
|
DSPSignalNotification* notif = (DSPSignalNotification*) message;
|
2020-08-03 18:29:15 -04:00
|
|
|
qDebug("FileOutputGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
|
2016-10-22 20:22:00 -04:00
|
|
|
m_sampleRate = notif->getSampleRate();
|
|
|
|
m_deviceCenterFrequency = notif->getCenterFrequency();
|
|
|
|
updateSampleRateAndFrequency();
|
|
|
|
|
|
|
|
delete message;
|
|
|
|
}
|
2017-09-17 11:35:03 -04:00
|
|
|
else
|
2016-10-23 06:22:52 -04:00
|
|
|
{
|
2017-09-17 11:35:03 -04:00
|
|
|
if (handleMessage(*message))
|
|
|
|
{
|
|
|
|
delete message;
|
|
|
|
}
|
2016-10-23 06:22:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::updateSampleRateAndFrequency()
|
2016-10-22 20:22:00 -04:00
|
|
|
{
|
2017-10-29 20:11:35 -04:00
|
|
|
m_deviceUISet->getSpectrum()->setSampleRate(m_sampleRate);
|
|
|
|
m_deviceUISet->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency);
|
2017-01-01 21:14:46 -05:00
|
|
|
ui->deviceRateText->setText(tr("%1k").arg((float)(m_sampleRate*(1<<m_settings.m_log2Interp)) / 1000));
|
2016-10-19 12:42:57 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::displaySettings()
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2016-10-20 19:21:17 -04:00
|
|
|
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
|
2017-04-06 13:19:32 -04:00
|
|
|
ui->sampleRate->setValue(m_settings.m_sampleRate);
|
2016-10-19 12:42:57 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::sendSettings()
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2016-10-22 20:22:00 -04:00
|
|
|
if(!m_updateTimer.isActive())
|
|
|
|
m_updateTimer.start(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::updateHardware()
|
2016-10-22 20:22:00 -04:00
|
|
|
{
|
2020-08-03 18:29:15 -04:00
|
|
|
qDebug() << "FileOutputGui::updateHardware";
|
|
|
|
FileOutput::MsgConfigureFileOutput* message = FileOutput::MsgConfigureFileOutput::create(m_settings, m_forceSettings);
|
2016-10-20 19:21:17 -04:00
|
|
|
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
2017-10-14 01:28:57 -04:00
|
|
|
m_forceSettings = false;
|
2016-10-22 20:22:00 -04:00
|
|
|
m_updateTimer.stop();
|
2016-10-19 12:42:57 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::updateStatus()
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
int state = m_deviceUISet->m_deviceAPI->state();
|
2016-10-19 12:42:57 -04:00
|
|
|
|
|
|
|
if(m_lastEngineState != state)
|
|
|
|
{
|
|
|
|
switch(state)
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
case DeviceAPI::StNotStarted:
|
2016-10-19 12:42:57 -04:00
|
|
|
ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
|
|
|
|
break;
|
2019-05-08 16:11:53 -04:00
|
|
|
case DeviceAPI::StIdle:
|
2016-10-19 12:42:57 -04:00
|
|
|
ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
|
|
|
|
break;
|
2019-05-08 16:11:53 -04:00
|
|
|
case DeviceAPI::StRunning:
|
2017-06-05 17:00:28 -04:00
|
|
|
ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
|
2016-10-19 12:42:57 -04:00
|
|
|
break;
|
2019-05-08 16:11:53 -04:00
|
|
|
case DeviceAPI::StError:
|
2017-06-05 17:00:28 -04:00
|
|
|
ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
|
2019-05-08 16:11:53 -04:00
|
|
|
QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
|
2016-10-19 12:42:57 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lastEngineState = state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::on_centerFrequency_changed(quint64 value)
|
2016-10-20 19:21:17 -04:00
|
|
|
{
|
|
|
|
m_settings.m_centerFrequency = value * 1000;
|
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::on_sampleRate_changed(quint64 value)
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2017-04-06 13:19:32 -04:00
|
|
|
m_settings.m_sampleRate = value;
|
2016-10-20 19:21:17 -04:00
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::on_interp_currentIndexChanged(int index)
|
2017-01-01 21:14:46 -05:00
|
|
|
{
|
|
|
|
if (index < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_settings.m_log2Interp = index;
|
|
|
|
updateSampleRateAndFrequency();
|
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::on_startStop_toggled(bool checked)
|
2016-10-20 19:21:17 -04:00
|
|
|
{
|
2017-12-13 18:38:22 -05:00
|
|
|
if (m_doApplySettings)
|
2016-10-20 19:21:17 -04:00
|
|
|
{
|
2020-08-03 18:29:15 -04:00
|
|
|
FileOutput::MsgStartStop *message = FileOutput::MsgStartStop::create(checked);
|
2017-12-13 18:38:22 -05:00
|
|
|
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
2016-10-20 19:21:17 -04:00
|
|
|
}
|
2016-10-19 12:42:57 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::on_showFileDialog_clicked(bool checked)
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) checked;
|
2016-10-20 19:21:17 -04:00
|
|
|
QString fileName = QFileDialog::getSaveFileName(this,
|
2018-05-10 18:00:15 -04:00
|
|
|
tr("Save I/Q record file"), ".", tr("SDR I/Q Files (*.sdriq)"), 0, QFileDialog::DontUseNativeDialog);
|
2016-10-19 12:42:57 -04:00
|
|
|
|
|
|
|
if (fileName != "")
|
|
|
|
{
|
|
|
|
m_fileName = fileName;
|
|
|
|
ui->fileNameText->setText(m_fileName);
|
|
|
|
configureFileName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::configureFileName()
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2020-08-03 18:29:15 -04:00
|
|
|
qDebug() << "FileOutputGui::configureFileName: " << m_fileName.toStdString().c_str();
|
|
|
|
FileOutput::MsgConfigureFileOutputName* message = FileOutput::MsgConfigureFileOutputName::create(m_fileName);
|
2016-10-20 19:21:17 -04:00
|
|
|
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
2016-10-19 12:42:57 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::updateWithGeneration()
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
|
|
|
ui->showFileDialog->setEnabled(!m_generation);
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::updateWithStreamTime()
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
|
|
|
int t_sec = 0;
|
|
|
|
int t_msec = 0;
|
|
|
|
|
2016-10-20 19:21:17 -04:00
|
|
|
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);
|
2018-05-11 05:00:08 -04:00
|
|
|
QString s_timems = t.toString("HH:mm:ss.zzz");
|
2016-10-19 12:42:57 -04:00
|
|
|
ui->relTimeText->setText(s_timems);
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:29:15 -04:00
|
|
|
void FileOutputGui::tick()
|
2016-10-19 12:42:57 -04:00
|
|
|
{
|
2016-10-23 06:22:52 -04:00
|
|
|
if ((++m_tickCount & 0xf) == 0)
|
|
|
|
{
|
2020-08-03 18:29:15 -04:00
|
|
|
FileOutput::MsgConfigureFileOutputStreamTiming* message = FileOutput::MsgConfigureFileOutputStreamTiming::create();
|
2016-10-20 19:21:17 -04:00
|
|
|
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
2016-10-19 12:42:57 -04:00
|
|
|
}
|
|
|
|
}
|