From 0492c50e55be94046c906a5e43ed0b2fd9990058 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 18 Nov 2015 06:05:13 +0100 Subject: [PATCH] Enhancements to TCP src plugin. Effectively show channel power on TCP src GUI --- plugins/channel/tcpsrc/tcpsrc.cpp | 28 ++++++++++++++++++------- plugins/channel/tcpsrc/tcpsrc.h | 2 ++ plugins/channel/tcpsrc/tcpsrcgui.cpp | 15 ++++++++++++- plugins/channel/tcpsrc/tcpsrcgui.h | 6 +++++- plugins/channel/tcpsrc/tcpsrcplugin.cpp | 16 +++++++------- plugins/channel/tcpsrc/tcpsrcplugin.h | 2 +- 6 files changed, 50 insertions(+), 19 deletions(-) diff --git a/plugins/channel/tcpsrc/tcpsrc.cpp b/plugins/channel/tcpsrc/tcpsrc.cpp index 5e4438d35..093508a7b 100644 --- a/plugins/channel/tcpsrc/tcpsrc.cpp +++ b/plugins/channel/tcpsrc/tcpsrc.cpp @@ -49,6 +49,7 @@ TCPSrc::TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, SampleSink* s m_this = 0; m_scale = 0; m_boost = 0; + m_magsq = 0; m_sampleBufferSSB.resize(tcpFftLen); TCPFilter = new fftfilt(0.3 / 48.0, 16.0 / 48.0, tcpFftLen); // if (!TCPFilter) segfault; @@ -82,32 +83,43 @@ void TCPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector: m_settingsMutex.lock(); // Rtl-Sdr uses full 16-bit scale; FCDPP does not - int rescale = 30000 * (1 << m_boost); + //int rescale = 32768 * (1 << m_boost); + int rescale = (1 << m_boost); for(SampleVector::const_iterator it = begin; it < end; ++it) { - Complex c(it->real() / 32768.0f, it->imag() / 32768.0f); + //Complex c(it->real() / 32768.0f, it->imag() / 32768.0f); + Complex c(it->real(), it->imag()); c *= m_nco.nextIQ(); - if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &ci)) { + if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &ci)) + { + m_magsq = ((ci.real()*ci.real() + ci.imag()*ci.imag())*rescale*rescale) / (1<<30); m_sampleBuffer.push_back(Sample(ci.real() * rescale, ci.imag() * rescale)); m_sampleDistanceRemain += m_inputSampleRate / m_outputSampleRate; } } - if((m_spectrum != NULL) && (m_spectrumEnabled)) + if((m_spectrum != 0) && (m_spectrumEnabled)) + { m_spectrum->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), positiveOnly); + } for(int i = 0; i < m_s16leSockets.count(); i++) + { m_s16leSockets[i].socket->write((const char*)&m_sampleBuffer[0], m_sampleBuffer.size() * 4); + } if((m_sampleFormat == FormatSSB) && (m_ssbSockets.count() > 0)) { for(SampleVector::const_iterator it = m_sampleBuffer.begin(); it != m_sampleBuffer.end(); ++it) { - Complex cj(it->real() / 30000.0, it->imag() / 30000.0); + //Complex cj(it->real() / 30000.0, it->imag() / 30000.0); + Complex cj(it->real(), it->imag()); int n_out = TCPFilter->runSSB(cj, &sideband, true); if (n_out) { for (int i = 0; i < n_out; i+=2) { - l = (sideband[i].real() + sideband[i].imag()) * 0.7 * 32000.0; - r = (sideband[i+1].real() + sideband[i+1].imag()) * 0.7 * 32000.0; + //l = (sideband[i].real() + sideband[i].imag()) * 0.7 * 32000.0; + //r = (sideband[i+1].real() + sideband[i+1].imag()) * 0.7 * 32000.0; + l = (sideband[i].real() + sideband[i].imag()) * 0.7; + r = (sideband[i+1].real() + sideband[i+1].imag()) * 0.7; m_sampleBufferSSB.push_back(Sample(l, r)); } for(int i = 0; i < m_ssbSockets.count(); i++) @@ -119,7 +131,7 @@ void TCPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector: if((m_sampleFormat == FormatNFM) && (m_ssbSockets.count() > 0)) { for(SampleVector::const_iterator it = m_sampleBuffer.begin(); it != m_sampleBuffer.end(); ++it) { - Complex cj(it->real() / 30000.0, it->imag() / 30000.0); + Complex cj(it->real() / 32768.0f, it->imag() / 32768.0f); // An FFT filter here is overkill, but was already set up for SSB int n_out = TCPFilter->runFilt(cj, &sideband); if (n_out) { diff --git a/plugins/channel/tcpsrc/tcpsrc.h b/plugins/channel/tcpsrc/tcpsrc.h index dce83c1d3..7b100b2bd 100644 --- a/plugins/channel/tcpsrc/tcpsrc.h +++ b/plugins/channel/tcpsrc/tcpsrc.h @@ -31,6 +31,7 @@ public: void configure(MessageQueue* messageQueue, SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost); void setSpectrum(MessageQueue* messageQueue, bool enabled); + Real getMagSq() const { return m_magsq; } virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void start(); @@ -128,6 +129,7 @@ protected: Real m_rfBandwidth; int m_tcpPort; int m_boost; + Real m_magsq; Real m_scale; Complex m_last, m_this; diff --git a/plugins/channel/tcpsrc/tcpsrcgui.cpp b/plugins/channel/tcpsrc/tcpsrcgui.cpp index b93d4610b..d46b927a6 100644 --- a/plugins/channel/tcpsrc/tcpsrcgui.cpp +++ b/plugins/channel/tcpsrc/tcpsrcgui.cpp @@ -6,8 +6,10 @@ #include "dsp/spectrumvis.h" #include "dsp/dspengine.h" #include "util/simpleserializer.h" +#include "util/db.h" #include "gui/basicchannelsettingswidget.h" #include "ui_tcpsrcgui.h" +#include "mainwindow.h" TCPSrcGUI* TCPSrcGUI::create(PluginAPI* pluginAPI) { @@ -169,12 +171,20 @@ void TCPSrcGUI::channelMarkerChanged() applySettings(); } +void TCPSrcGUI::tick() +{ + Real powDb = CalcDb::dbPower(m_tcpSrc->getMagSq()); + m_channelPowerDbAvg.feed(powDb); + ui->channelPower->setText(QString::number(m_channelPowerDbAvg.average(), 'f', 1)); +} + TCPSrcGUI::TCPSrcGUI(PluginAPI* pluginAPI, QWidget* parent) : RollupWidget(parent), ui(new Ui::TCPSrcGUI), m_pluginAPI(pluginAPI), - m_tcpSrc(NULL), + m_tcpSrc(0), m_channelMarker(this), + m_channelPowerDbAvg(40,0), m_basicSettingsShown(false), m_doApplySettings(true) { @@ -199,6 +209,9 @@ TCPSrcGUI::TCPSrcGUI(PluginAPI* pluginAPI, QWidget* parent) : ui->glSpectrum->setDisplayMaxHold(true); m_spectrumVis->configure(m_spectrumVis->getInputMessageQueue(), 64, 10, FFTWindow::BlackmanHarris); + ui->glSpectrum->connectTimer(m_pluginAPI->getMainWindow()->getMasterTimer()); + connect(&m_pluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); + //m_channelMarker = new ChannelMarker(this); m_channelMarker.setBandwidth(16000); m_channelMarker.setCenterFrequency(0); diff --git a/plugins/channel/tcpsrc/tcpsrcgui.h b/plugins/channel/tcpsrc/tcpsrcgui.h index 5bc6e4901..4d86158b0 100644 --- a/plugins/channel/tcpsrc/tcpsrcgui.h +++ b/plugins/channel/tcpsrc/tcpsrcgui.h @@ -5,6 +5,7 @@ #include "gui/rollupwidget.h" #include "plugin/plugingui.h" #include "dsp/channelmarker.h" +#include "dsp/movingaverage.h" #include "tcpsrc.h" class PluginAPI; @@ -47,11 +48,14 @@ private slots: void onWidgetRolled(QWidget* widget, bool rollDown); void onMenuDoubleClicked(); void on_boost_valueChanged(int value); + void tick(); + private: Ui::TCPSrcGUI* ui; PluginAPI* m_pluginAPI; TCPSrc* m_tcpSrc; ChannelMarker m_channelMarker; + MovingAverage m_channelPowerDbAvg; // settings TCPSrc::SampleFormat m_sampleFormat; @@ -67,7 +71,7 @@ private: Channelizer* m_channelizer; SpectrumVis* m_spectrumVis; - explicit TCPSrcGUI(PluginAPI* pluginAPI, QWidget* parent = NULL); + explicit TCPSrcGUI(PluginAPI* pluginAPI, QWidget* parent = 0); virtual ~TCPSrcGUI(); void blockApplySettings(bool block); diff --git a/plugins/channel/tcpsrc/tcpsrcplugin.cpp b/plugins/channel/tcpsrc/tcpsrcplugin.cpp index 654186216..e47adb883 100644 --- a/plugins/channel/tcpsrc/tcpsrcplugin.cpp +++ b/plugins/channel/tcpsrc/tcpsrcplugin.cpp @@ -6,11 +6,11 @@ const PluginDescriptor TCPSrcPlugin::m_pluginDescriptor = { QString("TCP Channel Source"), - QString("ssb"), - QString("(c) maintech GmbH (written by Christian Daniel)"), - QString("http://www.maintech.de"), + QString("---"), + QString("(c) Edouard Griffiths, F4EXB"), + QString("https://github.com/f4exb/sdrangel"), true, - QString("github.com/hexameron/rtl-sdrangelove") + QString("https://github.com/f4exb/sdrangel") }; TCPSrcPlugin::TCPSrcPlugin(QObject* parent) : @@ -30,14 +30,14 @@ void TCPSrcPlugin::initPlugin(PluginAPI* pluginAPI) // register TCP Channel Source QAction* action = new QAction(tr("&TCP Source"), this); connect(action, SIGNAL(triggered()), this, SLOT(createInstanceTCPSrc())); - m_pluginAPI->registerChannel("de.maintech.sdrangelove.channel.tcpsrc", this, action); + m_pluginAPI->registerChannel("sdrangel.channel.tcpsrc", this, action); } PluginGUI* TCPSrcPlugin::createChannel(const QString& channelName) { - if(channelName == "de.maintech.sdrangelove.channel.tcpsrc") { + if(channelName == "sdrangel.channel.tcpsrc") { TCPSrcGUI* gui = TCPSrcGUI::create(m_pluginAPI); - m_pluginAPI->registerChannelInstance("de.maintech.sdrangelove.channel.tcpsrc", gui); + m_pluginAPI->registerChannelInstance("sdrangel.channel.tcpsrc", gui); m_pluginAPI->addChannelRollup(gui); return gui; } else { @@ -48,6 +48,6 @@ PluginGUI* TCPSrcPlugin::createChannel(const QString& channelName) void TCPSrcPlugin::createInstanceTCPSrc() { TCPSrcGUI* gui = TCPSrcGUI::create(m_pluginAPI); - m_pluginAPI->registerChannelInstance("de.maintech.sdrangelove.channel.tcpsrc", gui); + m_pluginAPI->registerChannelInstance("sdrangel.channel.tcpsrc", gui); m_pluginAPI->addChannelRollup(gui); } diff --git a/plugins/channel/tcpsrc/tcpsrcplugin.h b/plugins/channel/tcpsrc/tcpsrcplugin.h index 984cd8fb2..4f5d729b4 100644 --- a/plugins/channel/tcpsrc/tcpsrcplugin.h +++ b/plugins/channel/tcpsrc/tcpsrcplugin.h @@ -7,7 +7,7 @@ class TCPSrcPlugin : public QObject, PluginInterface { Q_OBJECT Q_INTERFACES(PluginInterface) - Q_PLUGIN_METADATA(IID "de.maintech.sdrangelove.demod.tcpsrc") + Q_PLUGIN_METADATA(IID "sdrangel.demod.tcpsrc") public: explicit TCPSrcPlugin(QObject* parent = NULL);