2019-05-01 22:02:40 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2019 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 //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// 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 <stdint.h>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMessageBox>
|
2020-04-01 17:17:26 -04:00
|
|
|
#include <QFileDialog>
|
2019-05-01 22:02:40 -04:00
|
|
|
#include <QTime>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QString>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QJsonParseError>
|
|
|
|
#include <QJsonObject>
|
2022-04-21 01:53:36 -04:00
|
|
|
#include <QResizeEvent>
|
2019-05-01 22:02:40 -04:00
|
|
|
|
|
|
|
#include "ui_localinputgui.h"
|
|
|
|
#include "gui/colormapper.h"
|
|
|
|
#include "gui/glspectrum.h"
|
|
|
|
#include "gui/basicdevicesettingsdialog.h"
|
|
|
|
#include "dsp/dspengine.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "util/simpleserializer.h"
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2019-05-01 22:02:40 -04:00
|
|
|
#include "device/deviceuiset.h"
|
|
|
|
#include "localinputgui.h"
|
|
|
|
|
|
|
|
|
|
|
|
LocalInputGui::LocalInputGui(DeviceUISet *deviceUISet, QWidget* parent) :
|
2020-10-05 13:23:13 -04:00
|
|
|
DeviceGUI(parent),
|
2019-05-01 22:02:40 -04:00
|
|
|
ui(new Ui::LocalInputGui),
|
|
|
|
m_settings(),
|
|
|
|
m_sampleSource(0),
|
|
|
|
m_acquisition(false),
|
|
|
|
m_streamSampleRate(0),
|
|
|
|
m_streamCenterFrequency(0),
|
2019-05-08 16:11:53 -04:00
|
|
|
m_lastEngineState(DeviceAPI::StNotStarted),
|
2019-05-01 22:02:40 -04:00
|
|
|
m_framesDecodingStatus(0),
|
|
|
|
m_bufferLengthInSecs(0.0),
|
|
|
|
m_bufferGauge(-50),
|
|
|
|
m_nbOriginalBlocks(128),
|
|
|
|
m_nbFECBlocks(0),
|
|
|
|
m_sampleBits(16), // assume 16 bits to start with
|
|
|
|
m_sampleBytes(2),
|
|
|
|
m_samplesCount(0),
|
|
|
|
m_tickCount(0),
|
|
|
|
m_addressEdited(false),
|
|
|
|
m_dataPortEdited(false),
|
|
|
|
m_countUnrecoverable(0),
|
|
|
|
m_countRecovered(0),
|
|
|
|
m_doApplySettings(true),
|
2021-12-07 02:17:55 -05:00
|
|
|
m_forceSettings(true)
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
2022-05-13 16:24:48 -04:00
|
|
|
m_deviceUISet = deviceUISet;
|
2022-04-07 10:32:03 -04:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
2019-05-01 22:02:40 -04:00
|
|
|
m_paletteGreenText.setColor(QPalette::WindowText, Qt::green);
|
|
|
|
m_paletteWhiteText.setColor(QPalette::WindowText, Qt::white);
|
|
|
|
|
|
|
|
m_startingTimeStampms = 0;
|
2022-04-07 10:32:03 -04:00
|
|
|
ui->setupUi(getContents());
|
2022-04-21 01:53:36 -04:00
|
|
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2022-04-23 20:13:18 -04:00
|
|
|
getContents()->setStyleSheet("#LocalInputGui { background-color: rgb(64, 64, 64); }");
|
2022-04-07 10:32:03 -04:00
|
|
|
m_helpURL = "plugins/samplesource/localinput/readme.md";
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2022-04-16 19:31:50 -04:00
|
|
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
|
2019-05-01 22:02:40 -04:00
|
|
|
|
|
|
|
displaySettings();
|
2022-04-07 10:32:03 -04:00
|
|
|
makeUIConnections();
|
2019-05-01 22:02:40 -04:00
|
|
|
|
|
|
|
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
|
|
|
|
m_statusTimer.start(500);
|
|
|
|
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
m_sampleSource = (LocalInput*) m_deviceUISet->m_deviceAPI->getSampleSource();
|
2019-05-01 22:02:40 -04:00
|
|
|
|
|
|
|
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
|
|
|
|
m_sampleSource->setMessageQueueToGUI(&m_inputMessageQueue);
|
|
|
|
|
|
|
|
m_forceSettings = true;
|
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalInputGui::~LocalInputGui()
|
|
|
|
{
|
2022-10-05 10:40:09 -04:00
|
|
|
m_statusTimer.stop();
|
|
|
|
m_updateTimer.stop();
|
2019-05-01 22:02:40 -04:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::blockApplySettings(bool block)
|
|
|
|
{
|
|
|
|
m_doApplySettings = !block;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::resetToDefaults()
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
displaySettings();
|
|
|
|
m_forceSettings = true;
|
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray LocalInputGui::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LocalInputGui::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
qDebug("LocalInputGui::deserialize");
|
|
|
|
|
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
displaySettings();
|
|
|
|
m_forceSettings = true;
|
|
|
|
sendSettings();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 01:53:36 -04:00
|
|
|
void LocalInputGui::resizeEvent(QResizeEvent* size)
|
|
|
|
{
|
|
|
|
adjustSize();
|
|
|
|
size->accept();
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:02:40 -04:00
|
|
|
bool LocalInputGui::handleMessage(const Message& message)
|
|
|
|
{
|
|
|
|
if (LocalInput::MsgConfigureLocalInput::match(message))
|
|
|
|
{
|
|
|
|
const LocalInput::MsgConfigureLocalInput& cfg = (LocalInput::MsgConfigureLocalInput&) message;
|
|
|
|
m_settings = cfg.getSettings();
|
|
|
|
blockApplySettings(true);
|
|
|
|
displaySettings();
|
|
|
|
blockApplySettings(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (LocalInput::MsgStartStop::match(message))
|
|
|
|
{
|
|
|
|
LocalInput::MsgStartStop& notif = (LocalInput::MsgStartStop&) message;
|
|
|
|
blockApplySettings(true);
|
|
|
|
ui->startStop->setChecked(notif.getStartStop());
|
|
|
|
blockApplySettings(false);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (LocalInput::MsgReportSampleRateAndFrequency::match(message))
|
|
|
|
{
|
|
|
|
LocalInput::MsgReportSampleRateAndFrequency& notif = (LocalInput::MsgReportSampleRateAndFrequency&) message;
|
|
|
|
m_streamSampleRate = notif.getSampleRate();
|
|
|
|
m_streamCenterFrequency = notif.getCenterFrequency();
|
|
|
|
updateSampleRateAndFrequency();
|
|
|
|
|
|
|
|
return true;
|
2020-03-10 00:23:19 -04:00
|
|
|
}
|
2019-05-01 22:02:40 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::handleInputMessages()
|
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = m_inputMessageQueue.pop()) != 0)
|
|
|
|
{
|
|
|
|
//qDebug("LocalInputGui::handleInputMessages: message: %s", message->getIdentifier());
|
|
|
|
|
|
|
|
if (DSPSignalNotification::match(*message))
|
|
|
|
{
|
|
|
|
DSPSignalNotification* notif = (DSPSignalNotification*) message;
|
|
|
|
|
|
|
|
if (notif->getSampleRate() != m_streamSampleRate) {
|
|
|
|
m_streamSampleRate = notif->getSampleRate();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_streamCenterFrequency = notif->getCenterFrequency();
|
|
|
|
|
|
|
|
qDebug("LocalInputGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
|
|
|
|
|
|
|
|
updateSampleRateAndFrequency();
|
|
|
|
DSPSignalNotification *fwd = new DSPSignalNotification(*notif);
|
|
|
|
m_sampleSource->getInputMessageQueue()->push(fwd);
|
|
|
|
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (handleMessage(*message))
|
|
|
|
{
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::updateSampleRateAndFrequency()
|
|
|
|
{
|
|
|
|
m_deviceUISet->getSpectrum()->setSampleRate(m_streamSampleRate);
|
|
|
|
m_deviceUISet->getSpectrum()->setCenterFrequency(m_streamCenterFrequency);
|
|
|
|
ui->deviceRateText->setText(tr("%1k").arg((float)m_streamSampleRate / 1000));
|
|
|
|
blockApplySettings(true);
|
2021-12-15 18:18:11 -05:00
|
|
|
ui->centerFrequency->setText(tr("%L1").arg(m_streamCenterFrequency));
|
2019-05-01 22:02:40 -04:00
|
|
|
blockApplySettings(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::displaySettings()
|
|
|
|
{
|
|
|
|
blockApplySettings(true);
|
|
|
|
|
2021-12-15 18:18:11 -05:00
|
|
|
ui->centerFrequency->setText(tr("%L1").arg(m_streamCenterFrequency));
|
2019-05-01 22:02:40 -04:00
|
|
|
ui->deviceRateText->setText(tr("%1k").arg(m_streamSampleRate / 1000.0));
|
|
|
|
|
|
|
|
ui->dcOffset->setChecked(m_settings.m_dcBlock);
|
|
|
|
ui->iqImbalance->setChecked(m_settings.m_iqCorrection);
|
|
|
|
|
|
|
|
blockApplySettings(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::sendSettings()
|
|
|
|
{
|
|
|
|
if(!m_updateTimer.isActive())
|
|
|
|
m_updateTimer.start(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::on_dcOffset_toggled(bool checked)
|
|
|
|
{
|
|
|
|
m_settings.m_dcBlock = checked;
|
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::on_iqImbalance_toggled(bool checked)
|
|
|
|
{
|
|
|
|
m_settings.m_iqCorrection = checked;
|
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::on_startStop_toggled(bool checked)
|
|
|
|
{
|
|
|
|
if (m_doApplySettings)
|
|
|
|
{
|
|
|
|
LocalInput::MsgStartStop *message = LocalInput::MsgStartStop::create(checked);
|
|
|
|
m_sampleSource->getInputMessageQueue()->push(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::updateHardware()
|
|
|
|
{
|
|
|
|
if (m_doApplySettings)
|
|
|
|
{
|
|
|
|
qDebug() << "LocalInputGui::updateHardware";
|
|
|
|
LocalInput::MsgConfigureLocalInput* message =
|
|
|
|
LocalInput::MsgConfigureLocalInput::create(m_settings, m_forceSettings);
|
|
|
|
m_sampleSource->getInputMessageQueue()->push(message);
|
|
|
|
m_forceSettings = false;
|
|
|
|
m_updateTimer.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::updateStatus()
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
int state = m_deviceUISet->m_deviceAPI->state();
|
2019-05-01 22:02:40 -04:00
|
|
|
|
|
|
|
if(m_lastEngineState != state)
|
|
|
|
{
|
|
|
|
switch(state)
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
case DeviceAPI::StNotStarted:
|
2019-05-01 22:02:40 -04:00
|
|
|
ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
|
|
|
|
break;
|
2019-05-08 16:11:53 -04:00
|
|
|
case DeviceAPI::StIdle:
|
2019-05-01 22:02:40 -04:00
|
|
|
ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
|
|
|
|
break;
|
2019-05-08 16:11:53 -04:00
|
|
|
case DeviceAPI::StRunning:
|
2019-05-01 22:02:40 -04:00
|
|
|
ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
|
|
|
|
break;
|
2019-05-08 16:11:53 -04:00
|
|
|
case DeviceAPI::StError:
|
2019-05-01 22:02:40 -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());
|
2019-05-01 22:02:40 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lastEngineState = state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalInputGui::openDeviceSettingsDialog(const QPoint& p)
|
|
|
|
{
|
2022-04-16 19:31:50 -04:00
|
|
|
if (m_contextMenuType == ContextMenuDeviceSettings)
|
|
|
|
{
|
|
|
|
BasicDeviceSettingsDialog dialog(this);
|
|
|
|
dialog.setUseReverseAPI(m_settings.m_useReverseAPI);
|
|
|
|
dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress);
|
|
|
|
dialog.setReverseAPIPort(m_settings.m_reverseAPIPort);
|
|
|
|
dialog.setReverseAPIDeviceIndex(m_settings.m_reverseAPIDeviceIndex);
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2022-04-16 19:31:50 -04:00
|
|
|
dialog.move(p);
|
|
|
|
dialog.exec();
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2022-04-16 19:31:50 -04:00
|
|
|
m_settings.m_useReverseAPI = dialog.useReverseAPI();
|
|
|
|
m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress();
|
|
|
|
m_settings.m_reverseAPIPort = dialog.getReverseAPIPort();
|
|
|
|
m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex();
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2022-04-16 19:31:50 -04:00
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
resetContextMenuType();
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
2022-04-07 10:32:03 -04:00
|
|
|
|
|
|
|
void LocalInputGui::makeUIConnections()
|
|
|
|
{
|
|
|
|
QObject::connect(ui->dcOffset, &ButtonSwitch::toggled, this, &LocalInputGui::on_dcOffset_toggled);
|
|
|
|
QObject::connect(ui->iqImbalance, &ButtonSwitch::toggled, this, &LocalInputGui::on_iqImbalance_toggled);
|
|
|
|
QObject::connect(ui->startStop, &ButtonSwitch::toggled, this, &LocalInputGui::on_startStop_toggled);
|
|
|
|
}
|