1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 08:28:36 -05:00
sdrangel/plugins/channeltx/daemonsource/daemonsourcegui.cpp

381 lines
12 KiB
C++
Raw Normal View History

2018-08-31 17:29:53 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 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 "device/devicesinkapi.h"
#include "device/deviceuiset.h"
2018-08-31 18:18:35 -04:00
#include "gui/basicchannelsettingsdialog.h"
#include "mainwindow.h"
2018-08-31 17:29:53 -04:00
2018-09-11 10:50:55 -04:00
#include "daemonsource.h"
#include "ui_daemonsourcegui.h"
#include "daemonsourcegui.h"
2018-08-31 17:29:53 -04:00
2018-09-11 10:32:14 -04:00
DaemonSourceGUI* DaemonSourceGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx)
2018-08-31 17:29:53 -04:00
{
2018-09-11 10:32:14 -04:00
DaemonSourceGUI* gui = new DaemonSourceGUI(pluginAPI, deviceUISet, channelTx);
2018-08-31 17:29:53 -04:00
return gui;
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::destroy()
2018-08-31 17:29:53 -04:00
{
delete this;
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::setName(const QString& name)
2018-08-31 17:29:53 -04:00
{
setObjectName(name);
}
2018-09-11 10:32:14 -04:00
QString DaemonSourceGUI::getName() const
2018-08-31 17:29:53 -04:00
{
return objectName();
}
2018-09-11 10:32:14 -04:00
qint64 DaemonSourceGUI::getCenterFrequency() const {
2018-08-31 17:29:53 -04:00
return 0;
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::setCenterFrequency(qint64 centerFrequency __attribute__((unused)))
2018-08-31 17:29:53 -04:00
{
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::resetToDefaults()
2018-08-31 17:29:53 -04:00
{
m_settings.resetToDefaults();
displaySettings();
applySettings(true);
}
2018-09-11 10:32:14 -04:00
QByteArray DaemonSourceGUI::serialize() const
2018-08-31 17:29:53 -04:00
{
return m_settings.serialize();
}
2018-09-11 10:32:14 -04:00
bool DaemonSourceGUI::deserialize(const QByteArray& data)
2018-08-31 17:29:53 -04:00
{
if(m_settings.deserialize(data)) {
displaySettings();
applySettings(true);
return true;
} else {
resetToDefaults();
return false;
}
}
2018-09-11 10:32:14 -04:00
bool DaemonSourceGUI::handleMessage(const Message& message)
2018-08-31 17:29:53 -04:00
{
2018-09-11 10:32:14 -04:00
if (DaemonSource::MsgSampleRateNotification::match(message))
2018-08-31 18:18:35 -04:00
{
2018-09-11 10:32:14 -04:00
DaemonSource::MsgSampleRateNotification& notif = (DaemonSource::MsgSampleRateNotification&) message;
2018-08-31 18:18:35 -04:00
m_channelMarker.setBandwidth(notif.getSampleRate());
2018-09-01 03:53:16 -04:00
return true;
}
2018-09-11 10:32:14 -04:00
else if (DaemonSource::MsgConfigureDaemonSource::match(message))
2018-09-01 03:53:16 -04:00
{
2018-09-11 10:32:14 -04:00
const DaemonSource::MsgConfigureDaemonSource& cfg = (DaemonSource::MsgConfigureDaemonSource&) message;
2018-09-01 03:53:16 -04:00
m_settings = cfg.getSettings();
blockApplySettings(true);
displaySettings();
blockApplySettings(false);
return true;
}
2018-09-11 10:32:14 -04:00
else if (DaemonSource::MsgReportStreamData::match(message))
{
2018-09-11 10:32:14 -04:00
const DaemonSource::MsgReportStreamData& report = (DaemonSource::MsgReportStreamData&) message;
ui->sampleRate->setText(QString("%1").arg(report.get_sampleRate()));
QString nominalNbBlocksText = QString("%1/%2")
.arg(report.get_nbOriginalBlocks() + report.get_nbFECBlocks())
.arg(report.get_nbFECBlocks());
ui->nominalNbBlocksText->setText(nominalNbBlocksText);
QString queueLengthText = QString("%1/%2").arg(report.get_queueLength()).arg(report.get_queueSize());
ui->queueLengthText->setText(queueLengthText);
int queueLengthPercent = (report.get_queueLength()*100)/report.get_queueSize();
ui->queueLengthGauge->setValue(queueLengthPercent);
int unrecoverableCount = report.get_nbUncorrectableErrors();
int recoverableCount = report.get_nbCorrectableErrors();
uint64_t timestampUs = report.get_tv_sec()*1000000ULL + report.get_tv_usec();
if (!m_resetCounts)
{
int recoverableCountDelta = recoverableCount - m_lastCountRecovered;
int unrecoverableCountDelta = unrecoverableCount - m_lastCountUnrecoverable;
displayEventStatus(recoverableCountDelta, unrecoverableCountDelta);
m_countRecovered += recoverableCountDelta;
m_countUnrecoverable += unrecoverableCountDelta;
displayEventCounts();
}
uint32_t sampleCountDelta, sampleCount;
sampleCount = report.get_readSamplesCount();
if (sampleCount < m_lastSampleCount) {
sampleCountDelta = (0xFFFFFFFFU - sampleCount) + m_lastSampleCount + 1;
} else {
sampleCountDelta = sampleCount - m_lastSampleCount;
}
if (sampleCountDelta == 0) {
ui->allFramesDecoded->setStyleSheet("QToolButton { background-color : blue; }");
}
double remoteStreamRate = sampleCountDelta*1e6 / (double) (timestampUs - m_lastTimestampUs);
if (remoteStreamRate != 0) {
ui->streamRateText->setText(QString("%1").arg(remoteStreamRate, 0, 'f', 0));
}
m_resetCounts = false;
m_lastCountRecovered = recoverableCount;
m_lastCountUnrecoverable = unrecoverableCount;
m_lastSampleCount = sampleCount;
m_lastTimestampUs = timestampUs;
return true;
}
2018-09-01 03:53:16 -04:00
else
{
return false;
2018-08-31 18:18:35 -04:00
}
2018-08-31 17:29:53 -04:00
}
2018-09-11 10:32:14 -04:00
DaemonSourceGUI::DaemonSourceGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx __attribute__((unused)), QWidget* parent) :
2018-08-31 17:29:53 -04:00
RollupWidget(parent),
2018-09-11 10:32:14 -04:00
ui(new Ui::DaemonSourceGUI),
2018-08-31 17:29:53 -04:00
m_pluginAPI(pluginAPI),
m_deviceUISet(deviceUISet),
m_countUnrecoverable(0),
m_countRecovered(0),
m_lastCountUnrecoverable(0),
m_lastCountRecovered(0),
m_lastSampleCount(0),
m_lastTimestampUs(0),
m_resetCounts(true),
m_tickCount(0)
2018-08-31 17:29:53 -04:00
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true);
connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
2018-08-31 18:18:35 -04:00
2018-09-11 10:32:14 -04:00
m_daemonSrc = (DaemonSource*) channelTx;
2018-08-31 18:18:35 -04:00
m_daemonSrc->setMessageQueueToGUI(getInputMessageQueue());
connect(&(m_deviceUISet->m_deviceSinkAPI->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
2018-08-31 18:18:35 -04:00
m_channelMarker.blockSignals(true);
m_channelMarker.setColor(m_settings.m_rgbColor);
m_channelMarker.setCenterFrequency(0);
m_channelMarker.setTitle("Daemon source");
m_channelMarker.blockSignals(false);
m_channelMarker.setVisible(true); // activate signal on the last setting only
m_settings.setChannelMarker(&m_channelMarker);
2018-09-11 10:32:14 -04:00
m_deviceUISet->registerTxChannelInstance(DaemonSource::m_channelIdURI, this);
2018-08-31 18:18:35 -04:00
m_deviceUISet->addChannelMarker(&m_channelMarker);
m_deviceUISet->addRollupWidget(this);
connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor()));
2018-08-31 18:18:35 -04:00
connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages()));
m_time.start();
2018-08-31 18:18:35 -04:00
displaySettings();
applySettings(true);
2018-08-31 17:29:53 -04:00
}
2018-09-11 10:32:14 -04:00
DaemonSourceGUI::~DaemonSourceGUI()
2018-08-31 17:29:53 -04:00
{
m_deviceUISet->removeTxChannelInstance(this);
delete m_daemonSrc;
2018-08-31 17:29:53 -04:00
delete ui;
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::blockApplySettings(bool block)
2018-08-31 17:29:53 -04:00
{
m_doApplySettings = !block;
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::applySettings(bool force)
2018-08-31 17:29:53 -04:00
{
2018-08-31 22:37:23 -04:00
if (m_doApplySettings)
{
setTitleColor(m_channelMarker.getColor());
2018-09-11 10:32:14 -04:00
DaemonSource::MsgConfigureDaemonSource* message = DaemonSource::MsgConfigureDaemonSource::create(m_settings, force);
2018-08-31 22:37:23 -04:00
m_daemonSrc->getInputMessageQueue()->push(message);
}
2018-08-31 17:29:53 -04:00
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::displaySettings()
2018-08-31 17:29:53 -04:00
{
2018-08-31 18:18:35 -04:00
m_channelMarker.blockSignals(true);
m_channelMarker.setCenterFrequency(0);
m_channelMarker.setTitle(m_settings.m_title);
m_channelMarker.setBandwidth(5000); // TODO
m_channelMarker.blockSignals(false);
m_channelMarker.setColor(m_settings.m_rgbColor); // activate signal on the last setting only
setTitleColor(m_settings.m_rgbColor);
setWindowTitle(m_channelMarker.getTitle());
blockApplySettings(true);
ui->dataAddress->setText(m_settings.m_dataAddress);
ui->dataPort->setText(tr("%1").arg(m_settings.m_dataPort));
blockApplySettings(false);
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::leaveEvent(QEvent*)
2018-08-31 18:18:35 -04:00
{
m_channelMarker.setHighlighted(false);
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::enterEvent(QEvent*)
2018-08-31 18:18:35 -04:00
{
m_channelMarker.setHighlighted(true);
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::handleSourceMessages()
2018-08-31 18:18:35 -04:00
{
Message* message;
while ((message = getInputMessageQueue()->pop()) != 0)
{
if (handleMessage(*message))
{
delete message;
}
}
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::onWidgetRolled(QWidget* widget __attribute__((unused)), bool rollDown __attribute__((unused)))
2018-08-31 18:18:35 -04:00
{
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::onMenuDialogCalled(const QPoint &p)
2018-08-31 18:18:35 -04:00
{
BasicChannelSettingsDialog dialog(&m_channelMarker, this);
dialog.move(p);
dialog.exec();
m_settings.m_rgbColor = m_channelMarker.getColor().rgb();
m_settings.m_title = m_channelMarker.getTitle();
setWindowTitle(m_settings.m_title);
setTitleColor(m_settings.m_rgbColor);
applySettings();
2018-08-31 17:29:53 -04:00
}
2018-08-31 22:37:23 -04:00
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::on_dataAddress_returnPressed()
2018-08-31 22:37:23 -04:00
{
m_settings.m_dataAddress = ui->dataAddress->text();
applySettings();
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::on_dataPort_returnPressed()
2018-08-31 22:37:23 -04:00
{
bool dataOk;
int dataPort = ui->dataPort->text().toInt(&dataOk);
if((!dataOk) || (dataPort < 1024) || (dataPort > 65535))
{
return;
}
else
{
m_settings.m_dataPort = dataPort;
}
applySettings();
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::on_dataApplyButton_clicked(bool checked __attribute__((unused)))
2018-08-31 22:37:23 -04:00
{
m_settings.m_dataAddress = ui->dataAddress->text();
bool dataOk;
int udpDataPort = ui->dataPort->text().toInt(&dataOk);
if((dataOk) && (udpDataPort >= 1024) && (udpDataPort < 65535))
{
m_settings.m_dataPort = udpDataPort;
}
applySettings();
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::on_eventCountsReset_clicked(bool checked __attribute__((unused)))
{
m_countUnrecoverable = 0;
m_countRecovered = 0;
m_time.start();
displayEventCounts();
displayEventTimer();
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::displayEventCounts()
{
QString nstr = QString("%1").arg(m_countUnrecoverable, 3, 10, QChar('0'));
ui->eventUnrecText->setText(nstr);
nstr = QString("%1").arg(m_countRecovered, 3, 10, QChar('0'));
ui->eventRecText->setText(nstr);
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::displayEventStatus(int recoverableCount, int unrecoverableCount)
{
if (unrecoverableCount == 0)
{
if (recoverableCount == 0) {
ui->allFramesDecoded->setStyleSheet("QToolButton { background-color : green; }");
} else {
ui->allFramesDecoded->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
}
}
else
{
ui->allFramesDecoded->setStyleSheet("QToolButton { background-color : red; }");
}
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::displayEventTimer()
{
int elapsedTimeMillis = m_time.elapsed();
QTime recordLength(0, 0, 0, 0);
recordLength = recordLength.addSecs(elapsedTimeMillis/1000);
QString s_time = recordLength.toString("HH:mm:ss");
ui->eventCountsTimeText->setText(s_time);
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::tick()
{
if (++m_tickCount == 20) // once per second
{
2018-09-11 10:32:14 -04:00
DaemonSource::MsgQueryStreamData *msg = DaemonSource::MsgQueryStreamData::create();
m_daemonSrc->getInputMessageQueue()->push(msg);
displayEventTimer();
m_tickCount = 0;
}
}
2018-09-11 10:32:14 -04:00
void DaemonSourceGUI::channelMarkerChangedByCursor()
{
}