2016-01-24 13:21:21 -05: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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include <QTime>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QString>
|
|
|
|
#include <QFileDialog>
|
2016-02-01 02:24:14 -05:00
|
|
|
#include <stdint.h>
|
2016-01-24 13:21:21 -05:00
|
|
|
#include "ui_sdrdaemongui.h"
|
|
|
|
#include "plugin/pluginapi.h"
|
|
|
|
#include "gui/colormapper.h"
|
|
|
|
#include "dsp/dspengine.h"
|
|
|
|
#include "mainwindow.h"
|
2016-02-01 02:24:14 -05:00
|
|
|
#include "util/simpleserializer.h"
|
2016-01-24 13:21:21 -05:00
|
|
|
|
|
|
|
#include "sdrdaemongui.h"
|
|
|
|
|
|
|
|
SDRdaemonGui::SDRdaemonGui(PluginAPI* pluginAPI, QWidget* parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::SDRdaemonGui),
|
|
|
|
m_pluginAPI(pluginAPI),
|
|
|
|
m_sampleSource(NULL),
|
|
|
|
m_acquisition(false),
|
|
|
|
m_sampleRate(0),
|
2016-02-22 09:03:16 -05:00
|
|
|
m_sampleRateStream(0),
|
2016-01-24 13:21:21 -05:00
|
|
|
m_centerFrequency(0),
|
2016-02-23 08:57:40 -05:00
|
|
|
m_syncLocked(false),
|
2016-02-23 13:27:47 -05:00
|
|
|
m_frameSize(0),
|
|
|
|
m_lz4(false),
|
|
|
|
m_compressionRatio(1.0),
|
|
|
|
m_nbLz4DataCRCOK(0),
|
|
|
|
m_nbLz4SuccessfulDecodes(0),
|
2016-01-24 13:21:21 -05:00
|
|
|
m_samplesCount(0),
|
2016-02-17 17:47:03 -05:00
|
|
|
m_tickCount(0),
|
2016-02-17 19:24:58 -05:00
|
|
|
m_address("127.0.0.1"),
|
|
|
|
m_port(9090),
|
2016-02-17 17:47:03 -05:00
|
|
|
m_dcBlock(false),
|
|
|
|
m_iqCorrection(false)
|
2016-01-24 13:21:21 -05:00
|
|
|
{
|
2016-02-14 14:01:46 -05:00
|
|
|
m_startingTimeStamp.tv_sec = 0;
|
|
|
|
m_startingTimeStamp.tv_usec = 0;
|
2016-01-24 13:21:21 -05:00
|
|
|
ui->setupUi(this);
|
|
|
|
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
|
|
|
|
ui->centerFrequency->setValueRange(7, 0, pow(10,7));
|
|
|
|
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
|
|
|
|
connect(&(m_pluginAPI->getMainWindow()->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
|
|
|
|
|
|
|
|
m_sampleSource = new SDRdaemonInput(m_pluginAPI->getMainWindow()->getMasterTimer());
|
|
|
|
connect(m_sampleSource->getOutputMessageQueueToGUI(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages()));
|
|
|
|
DSPEngine::instance()->setSource(m_sampleSource);
|
2016-02-01 02:24:14 -05:00
|
|
|
|
|
|
|
displaySettings();
|
2016-02-24 19:37:47 -05:00
|
|
|
ui->applyButton->setEnabled(false);
|
2016-01-24 13:21:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SDRdaemonGui::~SDRdaemonGui()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::setName(const QString& name)
|
|
|
|
{
|
|
|
|
setObjectName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SDRdaemonGui::getName() const
|
|
|
|
{
|
|
|
|
return objectName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::resetToDefaults()
|
|
|
|
{
|
2016-02-17 19:24:58 -05:00
|
|
|
m_address = "127.0.0.1";
|
|
|
|
m_port = 9090;
|
|
|
|
m_dcBlock = false;
|
|
|
|
m_iqCorrection = false;
|
2016-01-24 13:21:21 -05:00
|
|
|
displaySettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray SDRdaemonGui::serialize() const
|
|
|
|
{
|
2016-02-01 02:24:14 -05:00
|
|
|
bool ok;
|
|
|
|
SimpleSerializer s(1);
|
2016-02-17 19:24:58 -05:00
|
|
|
|
2016-02-01 02:24:14 -05:00
|
|
|
s.writeString(1, ui->address->text());
|
|
|
|
uint32_t uintval = ui->port->text().toInt(&ok);
|
2016-02-17 19:24:58 -05:00
|
|
|
|
2016-02-01 02:24:14 -05:00
|
|
|
if((!ok) || (uintval < 1024) || (uintval > 65535)) {
|
|
|
|
uintval = 9090;
|
|
|
|
}
|
2016-02-17 19:24:58 -05:00
|
|
|
|
2016-02-01 02:24:14 -05:00
|
|
|
s.writeU32(2, uintval);
|
2016-02-17 19:24:58 -05:00
|
|
|
s.writeBool(3, m_dcBlock);
|
|
|
|
s.writeBool(4, m_iqCorrection);
|
|
|
|
|
2016-02-01 02:24:14 -05:00
|
|
|
return s.final();
|
2016-01-24 13:21:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SDRdaemonGui::deserialize(const QByteArray& data)
|
|
|
|
{
|
2016-02-01 02:24:14 -05:00
|
|
|
SimpleDeserializer d(data);
|
|
|
|
QString address;
|
|
|
|
uint32_t uintval;
|
|
|
|
quint16 port;
|
2016-02-20 04:10:11 -05:00
|
|
|
bool dcBlock;
|
|
|
|
bool iqCorrection;
|
2016-02-01 02:24:14 -05:00
|
|
|
|
2016-02-20 04:10:11 -05:00
|
|
|
if (!d.isValid())
|
|
|
|
{
|
2016-02-01 02:24:14 -05:00
|
|
|
resetToDefaults();
|
2016-02-20 04:10:11 -05:00
|
|
|
displaySettings();
|
2016-02-01 02:24:14 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-20 04:10:11 -05:00
|
|
|
if (d.getVersion() == 1)
|
|
|
|
{
|
2016-02-01 02:24:14 -05:00
|
|
|
uint32_t uintval;
|
2016-02-20 04:10:11 -05:00
|
|
|
d.readString(1, &address, "127.0.0.1");
|
2016-02-01 02:24:14 -05:00
|
|
|
d.readU32(2, &uintval, 9090);
|
2016-02-17 19:24:58 -05:00
|
|
|
|
2016-02-01 02:24:14 -05:00
|
|
|
if ((uintval > 1024) && (uintval < 65536)) {
|
2016-02-20 04:10:11 -05:00
|
|
|
port = uintval;
|
2016-02-01 02:24:14 -05:00
|
|
|
} else {
|
2016-02-20 04:10:11 -05:00
|
|
|
port = 9090;
|
2016-02-01 02:24:14 -05:00
|
|
|
}
|
2016-02-17 19:24:58 -05:00
|
|
|
|
2016-02-20 04:10:11 -05:00
|
|
|
d.readBool(3, &dcBlock, false);
|
|
|
|
d.readBool(4, &iqCorrection, false);
|
2016-02-17 19:24:58 -05:00
|
|
|
|
2016-02-20 04:10:11 -05:00
|
|
|
if ((address != m_address) || (port != m_port))
|
|
|
|
{
|
|
|
|
m_address = address;
|
|
|
|
m_port = port;
|
|
|
|
configureUDPLink();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dcBlock != m_dcBlock) || (iqCorrection != m_iqCorrection))
|
|
|
|
{
|
|
|
|
m_dcBlock = dcBlock;
|
|
|
|
m_iqCorrection = iqCorrection;
|
|
|
|
configureAutoCorrections();
|
|
|
|
}
|
|
|
|
|
|
|
|
displaySettings();
|
2016-01-24 13:21:21 -05:00
|
|
|
return true;
|
2016-02-20 04:10:11 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-24 13:21:21 -05:00
|
|
|
resetToDefaults();
|
2016-02-20 04:10:11 -05:00
|
|
|
displaySettings();
|
2016-01-24 13:21:21 -05:00
|
|
|
return false;
|
|
|
|
}
|
2016-02-01 02:24:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
qint64 SDRdaemonGui::getCenterFrequency() const
|
|
|
|
{
|
|
|
|
return m_centerFrequency;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::setCenterFrequency(qint64 centerFrequency)
|
|
|
|
{
|
|
|
|
m_centerFrequency = centerFrequency;
|
|
|
|
displaySettings();
|
2016-01-24 13:21:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SDRdaemonGui::handleMessage(const Message& message)
|
|
|
|
{
|
|
|
|
if (SDRdaemonInput::MsgReportSDRdaemonAcquisition::match(message))
|
|
|
|
{
|
|
|
|
m_acquisition = ((SDRdaemonInput::MsgReportSDRdaemonAcquisition&)message).getAcquisition();
|
|
|
|
updateWithAcquisition();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (SDRdaemonInput::MsgReportSDRdaemonStreamData::match(message))
|
|
|
|
{
|
2016-02-22 09:03:16 -05:00
|
|
|
m_sampleRateStream = ((SDRdaemonInput::MsgReportSDRdaemonStreamData&)message).getSampleRateStream();
|
2016-01-24 13:21:21 -05:00
|
|
|
m_sampleRate = ((SDRdaemonInput::MsgReportSDRdaemonStreamData&)message).getSampleRate();
|
|
|
|
m_centerFrequency = ((SDRdaemonInput::MsgReportSDRdaemonStreamData&)message).getCenterFrequency();
|
2016-02-14 14:01:46 -05:00
|
|
|
m_startingTimeStamp.tv_sec = ((SDRdaemonInput::MsgReportSDRdaemonStreamData&)message).get_tv_sec();
|
|
|
|
m_startingTimeStamp.tv_usec = ((SDRdaemonInput::MsgReportSDRdaemonStreamData&)message).get_tv_usec();
|
2016-01-24 13:21:21 -05:00
|
|
|
updateWithStreamData();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (SDRdaemonInput::MsgReportSDRdaemonStreamTiming::match(message))
|
|
|
|
{
|
2016-02-16 20:22:05 -05:00
|
|
|
m_startingTimeStamp.tv_sec = ((SDRdaemonInput::MsgReportSDRdaemonStreamTiming&)message).get_tv_sec();
|
|
|
|
m_startingTimeStamp.tv_usec = ((SDRdaemonInput::MsgReportSDRdaemonStreamTiming&)message).get_tv_usec();
|
2016-02-23 08:57:40 -05:00
|
|
|
m_syncLocked = ((SDRdaemonInput::MsgReportSDRdaemonStreamTiming&)message).getSyncLock();
|
2016-02-23 12:09:20 -05:00
|
|
|
m_frameSize = ((SDRdaemonInput::MsgReportSDRdaemonStreamTiming&)message).getFrameSize();
|
2016-02-23 12:19:35 -05:00
|
|
|
m_lz4 = ((SDRdaemonInput::MsgReportSDRdaemonStreamTiming&)message).getLz4Compression();
|
2016-02-23 13:27:47 -05:00
|
|
|
|
|
|
|
if (m_lz4) {
|
|
|
|
m_compressionRatio = ((SDRdaemonInput::MsgReportSDRdaemonStreamTiming&)message).getLz4CompressionRatio();
|
|
|
|
} else {
|
|
|
|
m_compressionRatio = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_nbLz4DataCRCOK = ((SDRdaemonInput::MsgReportSDRdaemonStreamTiming&)message).getLz4DataCRCOK();
|
|
|
|
m_nbLz4SuccessfulDecodes = ((SDRdaemonInput::MsgReportSDRdaemonStreamTiming&)message).getLz4SuccessfulDecodes();
|
|
|
|
|
2016-01-24 13:21:21 -05:00
|
|
|
updateWithStreamTime();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::handleSourceMessages()
|
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = m_sampleSource->getOutputMessageQueueToGUI()->pop()) != 0)
|
|
|
|
{
|
2016-02-17 17:47:03 -05:00
|
|
|
//qDebug("SDRdaemonGui::handleSourceMessages: message: %s", message->getIdentifier());
|
2016-01-24 13:21:21 -05:00
|
|
|
|
|
|
|
if (handleMessage(*message))
|
|
|
|
{
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::displaySettings()
|
|
|
|
{
|
2016-02-17 19:24:58 -05:00
|
|
|
ui->address->setText(m_address);
|
|
|
|
ui->port->setText(QString::number(m_port));
|
2016-02-17 17:47:03 -05:00
|
|
|
ui->dcOffset->setChecked(m_dcBlock);
|
|
|
|
ui->iqImbalance->setChecked(m_iqCorrection);
|
2016-01-24 13:21:21 -05:00
|
|
|
}
|
|
|
|
|
2016-02-01 02:24:14 -05:00
|
|
|
void SDRdaemonGui::on_applyButton_clicked(bool checked)
|
2016-01-24 13:21:21 -05:00
|
|
|
{
|
2016-02-23 17:16:05 -05:00
|
|
|
bool ok;
|
|
|
|
QString udpAddress = ui->address->text();
|
|
|
|
int udpPort = ui->port->text().toInt(&ok);
|
|
|
|
|
|
|
|
if((!ok) || (udpPort < 1024) || (udpPort > 65535))
|
|
|
|
{
|
|
|
|
udpPort = 9090;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_address = udpAddress;
|
|
|
|
m_port = udpPort;
|
|
|
|
|
2016-02-01 02:24:14 -05:00
|
|
|
configureUDPLink();
|
2016-02-24 19:37:47 -05:00
|
|
|
|
|
|
|
ui->applyButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::on_address_textEdited(const QString& arg1)
|
|
|
|
{
|
|
|
|
ui->applyButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::on_port_textEdited(const QString& arg1)
|
|
|
|
{
|
|
|
|
ui->applyButton->setEnabled(true);
|
2016-02-01 02:24:14 -05:00
|
|
|
}
|
2016-01-24 13:21:21 -05:00
|
|
|
|
2016-02-17 17:47:03 -05:00
|
|
|
void SDRdaemonGui::on_dcOffset_toggled(bool checked)
|
|
|
|
{
|
|
|
|
if (m_dcBlock != checked)
|
|
|
|
{
|
|
|
|
m_dcBlock = checked;
|
2016-02-17 19:24:58 -05:00
|
|
|
configureAutoCorrections();
|
2016-02-17 17:47:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::on_iqImbalance_toggled(bool checked)
|
|
|
|
{
|
|
|
|
if (m_iqCorrection != checked)
|
|
|
|
{
|
|
|
|
m_iqCorrection = checked;
|
2016-02-17 19:24:58 -05:00
|
|
|
configureAutoCorrections();
|
2016-02-17 17:47:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-01 02:24:14 -05:00
|
|
|
void SDRdaemonGui::configureUDPLink()
|
|
|
|
{
|
2016-02-23 17:16:05 -05:00
|
|
|
qDebug() << "SDRdaemonGui::configureUDPLink: " << m_address.toStdString().c_str()
|
|
|
|
<< " : " << m_port;
|
2016-02-01 02:24:14 -05:00
|
|
|
|
2016-02-23 17:16:05 -05:00
|
|
|
SDRdaemonInput::MsgConfigureSDRdaemonUDPLink* message = SDRdaemonInput::MsgConfigureSDRdaemonUDPLink::create(m_address, m_port);
|
2016-01-24 13:21:21 -05:00
|
|
|
m_sampleSource->getInputMessageQueue()->push(message);
|
|
|
|
}
|
|
|
|
|
2016-02-17 19:24:58 -05:00
|
|
|
void SDRdaemonGui::configureAutoCorrections()
|
|
|
|
{
|
|
|
|
SDRdaemonInput::MsgConfigureSDRdaemonAutoCorr* message = SDRdaemonInput::MsgConfigureSDRdaemonAutoCorr::create(m_dcBlock, m_iqCorrection);
|
|
|
|
m_sampleSource->getInputMessageQueue()->push(message);
|
|
|
|
}
|
|
|
|
|
2016-01-24 13:21:21 -05:00
|
|
|
void SDRdaemonGui::updateWithAcquisition()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::updateWithStreamData()
|
|
|
|
{
|
2016-02-20 04:10:11 -05:00
|
|
|
ui->centerFrequency->setValue(m_centerFrequency / 1000);
|
2016-02-23 15:22:27 -05:00
|
|
|
QString s0 = QString::number(m_sampleRateStream/1000.0, 'f', 2);
|
2016-02-22 09:03:16 -05:00
|
|
|
ui->sampleRateStreamText->setText(tr("%1").arg(s0));
|
|
|
|
QString s1 = QString::number(m_sampleRate/1000.0, 'f', 3);
|
|
|
|
ui->sampleRateText->setText(tr("%1").arg(s1));
|
|
|
|
float skewPerCent = (float) ((m_sampleRate - m_sampleRateStream) * 100) / (float) m_sampleRateStream;
|
|
|
|
QString s2 = QString::number(skewPerCent, 'f', 2);
|
|
|
|
ui->skewRateText->setText(tr("%1").arg(s2));
|
|
|
|
updateWithStreamTime();
|
2016-01-24 13:21:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::updateWithStreamTime()
|
|
|
|
{
|
2016-02-14 14:01:46 -05:00
|
|
|
quint64 startingTimeStampMsec = (m_startingTimeStamp.tv_sec * 1000) + (m_startingTimeStamp.tv_usec / 1000);
|
|
|
|
QDateTime dt = QDateTime::fromMSecsSinceEpoch(startingTimeStampMsec);
|
2016-02-17 17:47:03 -05:00
|
|
|
QString s_date = dt.toString("yyyy-MM-dd hh:mm:ss.zzz");
|
2016-02-14 14:01:46 -05:00
|
|
|
ui->absTimeText->setText(s_date);
|
2016-02-23 08:57:40 -05:00
|
|
|
|
|
|
|
if (m_syncLocked) {
|
|
|
|
ui->streamLocked->setStyleSheet("QToolButton { background-color : green; }");
|
|
|
|
} else {
|
|
|
|
ui->streamLocked->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
|
|
|
|
}
|
2016-02-23 12:09:20 -05:00
|
|
|
|
|
|
|
QString s = QString::number(m_frameSize / 1024.0, 'f', 0);
|
|
|
|
ui->frameSizeText->setText(tr("%1").arg(s));
|
2016-02-23 12:19:35 -05:00
|
|
|
|
|
|
|
if (m_lz4) {
|
|
|
|
ui->lz4Compressed->setStyleSheet("QToolButton { background-color : green; }");
|
|
|
|
} else {
|
|
|
|
ui->lz4Compressed->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
|
|
|
|
}
|
2016-02-23 12:29:08 -05:00
|
|
|
|
|
|
|
s = QString::number(m_compressionRatio, 'f', 2);
|
|
|
|
ui->compressionRatioText->setText(tr("%1").arg(s));
|
2016-02-23 13:27:47 -05:00
|
|
|
|
|
|
|
s = QString::number(m_nbLz4DataCRCOK, 'f', 0);
|
|
|
|
ui->dataCRCOKText->setText(tr("%1").arg(s));
|
|
|
|
|
|
|
|
s = QString::number(m_nbLz4SuccessfulDecodes, 'f', 0);
|
|
|
|
ui->lz4DecodesOKText->setText(tr("%1").arg(s));
|
2016-01-24 13:21:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SDRdaemonGui::tick()
|
|
|
|
{
|
|
|
|
if ((++m_tickCount & 0xf) == 0) {
|
|
|
|
SDRdaemonInput::MsgConfigureSDRdaemonStreamTiming* message = SDRdaemonInput::MsgConfigureSDRdaemonStreamTiming::create();
|
|
|
|
m_sampleSource->getInputMessageQueue()->push(message);
|
|
|
|
}
|
|
|
|
}
|
2016-02-17 19:24:58 -05:00
|
|
|
|