From 0b05fcc2504732c8eeebc935014a3cd3d549bcc9 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Sat, 27 Mar 2021 10:07:23 +0000 Subject: [PATCH] Add support for Packet demodulator to Demod Analyzer feature. Use RF bandwidth setting for interpolator --- plugins/channelrx/demodpacket/packetdemod.cpp | 1 + .../demodpacket/packetdemodbaseband.cpp | 5 +++ .../demodpacket/packetdemodbaseband.h | 2 + .../channelrx/demodpacket/packetdemodsink.cpp | 42 ++++++++++++++++--- .../channelrx/demodpacket/packetdemodsink.h | 8 ++++ .../demodanalyzer/demodanalyzersettings.cpp | 2 + 6 files changed, 54 insertions(+), 6 deletions(-) diff --git a/plugins/channelrx/demodpacket/packetdemod.cpp b/plugins/channelrx/demodpacket/packetdemod.cpp index 2df2698af..b3b4c256f 100644 --- a/plugins/channelrx/demodpacket/packetdemod.cpp +++ b/plugins/channelrx/demodpacket/packetdemod.cpp @@ -54,6 +54,7 @@ PacketDemod::PacketDemod(DeviceAPI *deviceAPI) : m_basebandSink = new PacketDemodBaseband(this); m_basebandSink->setMessageQueueToChannel(getInputMessageQueue()); + m_basebandSink->setChannel(this); m_basebandSink->moveToThread(&m_thread); applySettings(m_settings, true); diff --git a/plugins/channelrx/demodpacket/packetdemodbaseband.cpp b/plugins/channelrx/demodpacket/packetdemodbaseband.cpp index 61b729f0d..6975b1396 100644 --- a/plugins/channelrx/demodpacket/packetdemodbaseband.cpp +++ b/plugins/channelrx/demodpacket/packetdemodbaseband.cpp @@ -78,6 +78,11 @@ void PacketDemodBaseband::stopWork() m_running = false; } +void PacketDemodBaseband::setChannel(ChannelAPI *channel) +{ + m_sink.setChannel(channel); +} + void PacketDemodBaseband::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end) { m_sampleFifo.write(begin, end); diff --git a/plugins/channelrx/demodpacket/packetdemodbaseband.h b/plugins/channelrx/demodpacket/packetdemodbaseband.h index cee2cd39a..14df864d7 100644 --- a/plugins/channelrx/demodpacket/packetdemodbaseband.h +++ b/plugins/channelrx/demodpacket/packetdemodbaseband.h @@ -29,6 +29,7 @@ #include "packetdemodsink.h" class DownChannelizer; +class ChannelAPI; class PacketDemod; class PacketDemodBaseband : public QObject @@ -70,6 +71,7 @@ public: } void setMessageQueueToChannel(MessageQueue *messageQueue) { m_sink.setMessageQueueToChannel(messageQueue); } void setBasebandSampleRate(int sampleRate); + void setChannel(ChannelAPI *channel); double getMagSq() const { return m_sink.getMagSq(); } bool isRunning() const { return m_running; } diff --git a/plugins/channelrx/demodpacket/packetdemodsink.cpp b/plugins/channelrx/demodpacket/packetdemodsink.cpp index ce3930b6c..3cb9f0b6a 100644 --- a/plugins/channelrx/demodpacket/packetdemodsink.cpp +++ b/plugins/channelrx/demodpacket/packetdemodsink.cpp @@ -21,7 +21,7 @@ #include #include "dsp/dspengine.h" -#include "dsp/dspengine.h" +#include "dsp/datafifo.h" #include "util/db.h" #include "util/stepfunctions.h" #include "pipes/pipeendpoint.h" @@ -46,6 +46,9 @@ PacketDemodSink::PacketDemodSink(PacketDemod *packetDemod) : { m_magsq = 0.0; + m_demodBuffer.resize(1<<12); + m_demodBufferFill = 0; + applySettings(m_settings, true); applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); } @@ -236,6 +239,24 @@ void PacketDemodSink::processOneSample(Complex &ci) } m_corrIdx = (m_corrIdx + 1) % m_correlationLength; m_corrCnt++; + + m_demodBuffer[m_demodBufferFill++] = fmDemod * std::numeric_limits::max(); + + if (m_demodBufferFill >= m_demodBuffer.size()) + { + QList *dataFifos = MainCore::instance()->getDataPipes().getFifos(m_channel, "demod"); + + if (dataFifos) + { + QList::iterator it = dataFifos->begin(); + + for (; it != dataFifos->end(); ++it) { + (*it)->write((quint8*) &m_demodBuffer[0], m_demodBuffer.size() * sizeof(qint16)); + } + } + + m_demodBufferFill = 0; + } } void PacketDemodSink::applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force) @@ -252,9 +273,9 @@ void PacketDemodSink::applyChannelSettings(int channelSampleRate, int channelFre if ((m_channelSampleRate != channelSampleRate) || force) { - m_interpolator.create(16, channelSampleRate, PACKETDEMOD_CHANNEL_BANDWIDTH); - m_interpolatorDistanceRemain = 0; + m_interpolator.create(16, channelSampleRate, m_settings.m_rfBandwidth / 2.2); m_interpolatorDistance = (Real) channelSampleRate / (Real) PACKETDEMOD_CHANNEL_SAMPLE_RATE; + m_interpolatorDistanceRemain = m_interpolatorDistance; } m_channelSampleRate = channelSampleRate; @@ -266,11 +287,20 @@ void PacketDemodSink::applySettings(const PacketDemodSettings& settings, bool fo qDebug() << "PacketDemodSink::applySettings:" << " force: " << force; + if ((settings.m_rfBandwidth != m_settings.m_rfBandwidth) || force) + { + m_interpolator.create(16, m_channelSampleRate, settings.m_rfBandwidth / 2.2); + m_interpolatorDistance = (Real) m_channelSampleRate / (Real) PACKETDEMOD_CHANNEL_SAMPLE_RATE; + m_interpolatorDistanceRemain = m_interpolatorDistance; + m_lowpass.create(301, PACKETDEMOD_CHANNEL_SAMPLE_RATE, settings.m_rfBandwidth / 2.0f); + } + if ((settings.m_fmDeviation != m_settings.m_fmDeviation) || force) + { + m_phaseDiscri.setFMScaling(PACKETDEMOD_CHANNEL_SAMPLE_RATE / (2.0f * settings.m_fmDeviation)); + } + if (force) { - m_lowpass.create(301, PACKETDEMOD_CHANNEL_SAMPLE_RATE, settings.m_rfBandwidth / 2.0f); - m_phaseDiscri.setFMScaling(PACKETDEMOD_CHANNEL_SAMPLE_RATE / (2.0f * settings.m_fmDeviation)); - delete m_f1; delete m_f0; delete m_corrBuf; diff --git a/plugins/channelrx/demodpacket/packetdemodsink.h b/plugins/channelrx/demodpacket/packetdemodsink.h index 45ebb8de7..c207f838f 100644 --- a/plugins/channelrx/demodpacket/packetdemodsink.h +++ b/plugins/channelrx/demodpacket/packetdemodsink.h @@ -19,6 +19,8 @@ #ifndef INCLUDE_PACKETDEMODSINK_H #define INCLUDE_PACKETDEMODSINK_H +#include + #include "dsp/channelsamplesink.h" #include "dsp/phasediscri.h" #include "dsp/nco.h" @@ -39,6 +41,7 @@ // Must be integer multiple of m_baud=1200 #define PACKETDEMOD_CHANNEL_SAMPLE_RATE 38400 +class ChannelAPI; class PacketDemod; class PacketDemodSink : public ChannelSampleSink { @@ -51,6 +54,7 @@ public: void applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force = false); void applySettings(const PacketDemodSettings& settings, bool force = false); void setMessageQueueToChannel(MessageQueue *messageQueue) { m_messageQueueToChannel = messageQueue; } + void setChannel(ChannelAPI *channel) { m_channel = channel; } double getMagSq() const { return m_magsq; } @@ -86,6 +90,7 @@ private: PacketDemod *m_packetDemod; PacketDemodSettings m_settings; + ChannelAPI *m_channel; int m_channelSampleRate; int m_channelFrequencyOffset; @@ -128,6 +133,9 @@ private: int m_byteCount; crc16x25 m_crc; + QVector m_demodBuffer; + int m_demodBufferFill; + void processOneSample(Complex &ci); MessageQueue *getMessageQueueToChannel() { return m_messageQueueToChannel; } }; diff --git a/plugins/feature/demodanalyzer/demodanalyzersettings.cpp b/plugins/feature/demodanalyzer/demodanalyzersettings.cpp index 6004ab2b3..260c7c85c 100644 --- a/plugins/feature/demodanalyzer/demodanalyzersettings.cpp +++ b/plugins/feature/demodanalyzer/demodanalyzersettings.cpp @@ -28,6 +28,7 @@ const QStringList DemodAnalyzerSettings::m_channelTypes = { QStringLiteral("DSDDemod"), QStringLiteral("NFMDemod"), QStringLiteral("NFMMod"), + QStringLiteral("PacketDemod"), QStringLiteral("PacketMod"), QStringLiteral("SSBDemod"), QStringLiteral("SSBMod"), @@ -41,6 +42,7 @@ const QStringList DemodAnalyzerSettings::m_channelURIs = { QStringLiteral("sdrangel.channel.dsddemod"), QStringLiteral("sdrangel.channel.nfmdemod"), QStringLiteral("sdrangel.channeltx.modnfm"), + QStringLiteral("sdrangel.channel.packetdemod"), QStringLiteral("sdrangel.channeltx.modpacket"), QStringLiteral("sdrangel.channel.ssbdemod"), QStringLiteral("sdrangel.channeltx.modssb"),