2015-08-02 19:04:20 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-09 04:33:04 -04:00
|
|
|
#include <QDebug>
|
2015-08-02 19:04:20 -04:00
|
|
|
|
2015-08-03 22:17:24 -04:00
|
|
|
#include <QTime>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QString>
|
2015-08-04 19:43:30 -04:00
|
|
|
#include <QFileDialog>
|
2015-08-02 19:04:20 -04:00
|
|
|
#include "ui_filesourcegui.h"
|
|
|
|
#include "plugin/pluginapi.h"
|
|
|
|
#include "gui/colormapper.h"
|
2015-08-17 02:29:34 -04:00
|
|
|
#include "dsp/dspengine.h"
|
2015-08-02 19:04:20 -04:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
|
|
#include "filesourcegui.h"
|
|
|
|
|
|
|
|
FileSourceGui::FileSourceGui(PluginAPI* pluginAPI, QWidget* parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::FileSourceGui),
|
|
|
|
m_pluginAPI(pluginAPI),
|
|
|
|
m_settings(),
|
2015-08-03 22:17:24 -04:00
|
|
|
m_sampleSource(NULL),
|
|
|
|
m_acquisition(false),
|
2015-08-04 21:25:06 -04:00
|
|
|
m_fileName("..."),
|
2015-08-03 22:17:24 -04:00
|
|
|
m_sampleRate(0),
|
|
|
|
m_centerFrequency(0),
|
|
|
|
m_startingTimeStamp(0),
|
2015-08-05 19:43:35 -04:00
|
|
|
m_samplesCount(0),
|
|
|
|
m_tickCount(0)
|
2015-08-02 19:04:20 -04:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
|
|
|
|
ui->centerFrequency->setValueRange(7, 0, pow(10,7));
|
2015-08-04 21:25:06 -04:00
|
|
|
ui->fileNameText->setText(m_fileName);
|
2015-08-02 19:04:20 -04:00
|
|
|
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
|
2015-08-05 19:43:35 -04:00
|
|
|
connect(&(m_pluginAPI->getMainWindow()->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
|
2015-08-02 19:04:20 -04:00
|
|
|
displaySettings();
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
m_sampleSource = new FileSourceInput(m_pluginAPI->getMainWindow()->getMasterTimer());
|
|
|
|
DSPEngine::instance()->setSource(m_sampleSource);
|
2015-08-02 19:04:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
FileSourceGui::~FileSourceGui()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSourceGui::destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSourceGui::setName(const QString& name)
|
|
|
|
{
|
|
|
|
setObjectName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FileSourceGui::getName() const
|
|
|
|
{
|
|
|
|
return objectName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSourceGui::resetToDefaults()
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
displaySettings();
|
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 FileSourceGui::getCenterFrequency() const
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
return m_centerFrequency;
|
2015-08-02 19:04:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray FileSourceGui::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileSourceGui::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
if(m_settings.deserialize(data)) {
|
|
|
|
displaySettings();
|
|
|
|
sendSettings();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
resetToDefaults();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
bool FileSourceGui::handleMessage(const Message& message)
|
2015-08-02 19:04:20 -04:00
|
|
|
{
|
2015-08-04 21:25:06 -04:00
|
|
|
if(FileSourceInput::MsgReportFileSourceAcquisition::match(message))
|
2015-08-03 22:17:24 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
m_acquisition = ((FileSourceInput::MsgReportFileSourceAcquisition&)message).getAcquisition();
|
2015-08-04 21:25:06 -04:00
|
|
|
updateWithAcquisition();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(FileSourceInput::MsgReportFileSourceStreamData::match(message))
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
m_sampleRate = ((FileSourceInput::MsgReportFileSourceStreamData&)message).getSampleRate();
|
|
|
|
m_centerFrequency = ((FileSourceInput::MsgReportFileSourceStreamData&)message).getCenterFrequency();
|
|
|
|
m_startingTimeStamp = ((FileSourceInput::MsgReportFileSourceStreamData&)message).getStartingTimeStamp();
|
2015-08-05 19:43:35 -04:00
|
|
|
updateWithStreamData();
|
2015-08-02 19:04:20 -04:00
|
|
|
return true;
|
2015-08-03 22:17:24 -04:00
|
|
|
}
|
2015-08-05 19:14:44 -04:00
|
|
|
else if(FileSourceInput::MsgReportFileSourceStreamTiming::match(message))
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
m_samplesCount = ((FileSourceInput::MsgReportFileSourceStreamTiming&)message).getSamplesCount();
|
2015-08-05 19:14:44 -04:00
|
|
|
updateWithStreamTime();
|
2015-08-05 19:43:35 -04:00
|
|
|
return true;
|
2015-08-05 19:14:44 -04:00
|
|
|
}
|
2015-08-03 22:17:24 -04:00
|
|
|
else
|
|
|
|
{
|
2015-08-02 19:04:20 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSourceGui::displaySettings()
|
2015-08-04 21:25:06 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSourceGui::sendSettings()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSourceGui::updateHardware()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSourceGui::on_play_toggled(bool checked)
|
|
|
|
{
|
2015-08-05 19:14:44 -04:00
|
|
|
FileSourceInput::MsgConfigureFileSourceWork* message = FileSourceInput::MsgConfigureFileSourceWork::create(checked);
|
2015-08-17 02:29:34 -04:00
|
|
|
m_sampleSource->getInputMessageQueue()->push(message);
|
2015-08-04 21:25:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileSourceGui::on_showFileDialog_clicked(bool checked)
|
|
|
|
{
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this,
|
|
|
|
tr("Open I/Q record file"), ".", tr("SDR I/Q Files (*.sdriq)"));
|
2015-08-17 02:29:34 -04:00
|
|
|
|
|
|
|
if (fileName != "")
|
|
|
|
{
|
2015-08-04 21:25:06 -04:00
|
|
|
m_fileName = fileName;
|
|
|
|
ui->fileNameText->setText(m_fileName);
|
|
|
|
configureFileName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSourceGui::configureFileName()
|
|
|
|
{
|
2015-08-09 05:11:28 -04:00
|
|
|
qDebug() << "FileSourceGui::configureFileName: " << m_fileName.toStdString().c_str();
|
2015-08-05 18:10:46 -04:00
|
|
|
FileSourceInput::MsgConfigureFileSourceName* message = FileSourceInput::MsgConfigureFileSourceName::create(m_fileName);
|
2015-08-17 02:29:34 -04:00
|
|
|
m_sampleSource->getInputMessageQueue()->push(message);
|
2015-08-04 21:25:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileSourceGui::updateWithAcquisition()
|
|
|
|
{
|
|
|
|
ui->play->setEnabled(m_acquisition);
|
|
|
|
ui->play->setChecked(m_acquisition);
|
|
|
|
ui->showFileDialog->setEnabled(!m_acquisition);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSourceGui::updateWithStreamData()
|
2015-08-02 19:04:20 -04:00
|
|
|
{
|
2015-08-03 22:17:24 -04:00
|
|
|
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);
|
2015-08-04 21:25:06 -04:00
|
|
|
updateWithStreamTime(); // TODO: remove when time data is implemented
|
2015-08-03 22:17:24 -04:00
|
|
|
}
|
|
|
|
|
2015-08-04 21:25:06 -04:00
|
|
|
void FileSourceGui::updateWithStreamTime()
|
2015-08-03 22:17:24 -04:00
|
|
|
{
|
|
|
|
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);
|
2015-08-05 19:14:44 -04:00
|
|
|
t = t.addSecs(t_sec);
|
|
|
|
t = t.addMSecs(t_msec);
|
2015-08-03 22:17:24 -04:00
|
|
|
QString s_time = t.toString("hh:mm:ss.zzz");
|
|
|
|
ui->relTimeText->setText(s_time);
|
|
|
|
|
|
|
|
quint64 startingTimeStampMsec = m_startingTimeStamp * 1000;
|
|
|
|
QDateTime dt = QDateTime::fromMSecsSinceEpoch(startingTimeStampMsec);
|
2015-08-05 19:14:44 -04:00
|
|
|
dt = dt.addSecs(t_sec);
|
|
|
|
dt = dt.addMSecs(t_msec);
|
2015-08-03 22:17:24 -04:00
|
|
|
QString s_date = dt.toString("yyyyMMdd hh.mm.ss.zzz");
|
|
|
|
ui->absTimeText->setText(s_date);
|
2015-08-02 19:04:20 -04:00
|
|
|
}
|
2015-08-05 19:43:35 -04:00
|
|
|
|
|
|
|
void FileSourceGui::tick()
|
|
|
|
{
|
|
|
|
if ((++m_tickCount & 0xf) == 0) {
|
|
|
|
FileSourceInput::MsgConfigureFileSourceStreamTiming* message = FileSourceInput::MsgConfigureFileSourceStreamTiming::create();
|
2015-08-17 02:29:34 -04:00
|
|
|
m_sampleSource->getInputMessageQueue()->push(message);
|
2015-08-05 19:43:35 -04:00
|
|
|
}
|
|
|
|
}
|