From cc8edc9e754178a26232358ef01ecf2aafdc4b76 Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 18 Mar 2019 02:26:03 +0100 Subject: [PATCH] DATV demod: refactored using the settings scheme --- plugins/channelrx/demoddatv/datvdemod.cpp | 340 +++++++----------- plugins/channelrx/demoddatv/datvdemod.h | 179 ++------- plugins/channelrx/demoddatv/datvdemodgui.cpp | 259 +++++-------- plugins/channelrx/demoddatv/datvdemodgui.h | 7 +- .../channelrx/demoddatv/datvdemodsettings.cpp | 46 ++- .../channelrx/demoddatv/datvdemodsettings.h | 6 +- 6 files changed, 294 insertions(+), 543 deletions(-) diff --git a/plugins/channelrx/demoddatv/datvdemod.cpp b/plugins/channelrx/demoddatv/datvdemod.cpp index 9c455a6b4..9ae1cc040 100644 --- a/plugins/channelrx/demoddatv/datvdemod.cpp +++ b/plugins/channelrx/demoddatv/datvdemod.cpp @@ -45,7 +45,7 @@ DATVDemod::DATVDemod(DeviceSourceAPI *deviceAPI) : m_objRenderThread(nullptr), m_blnRenderingVideo(false), m_blnStartStopVideo(false), - m_enmModulation(BPSK /*DATV_FM1*/), + m_enmModulation(DATVDemodSettings::BPSK /*DATV_FM1*/), m_objSettingsMutex(QMutex::NonRecursive) { setObjectName("DATVDemod"); @@ -153,97 +153,6 @@ bool DATVDemod::PlayVideo(bool blnStartStop) return true; } -void DATVDemod::configure(MessageQueue* objMessageQueue, - int intRFBandwidth, - int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, - leansdr::code_rate enmFEC, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - dvb_sampler enmFilter, - bool blnHardMetric, - float fltRollOff, - bool blnViterbi, - int intExcursion) -{ - Message* msgCmd = MsgConfigureDATVDemod::create( - intRFBandwidth, - intCenterFrequency, - enmStandard, - enmModulation, - enmFEC, - intSymbolRate, - intNotchFilters, - blnAllowDrift, - blnFastLock, - enmFilter, - blnHardMetric, - fltRollOff, - blnViterbi, - intExcursion); - objMessageQueue->push(msgCmd); -} - -void DATVDemod::InitDATVParameters(int intMsps, - int intRFBandwidth, - int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, - leansdr::code_rate enmFEC, - int intSampleRate, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - dvb_sampler enmFilter, - bool blnHardMetric, - float fltRollOff, - bool blnViterbi, - int intExcursion) -{ - Real fltLowCut; - Real fltHiCut; - - m_objSettingsMutex.lock(); - - m_blnInitialized=false; - - //Bandpass filter shaping - - fltLowCut = -((float)intRFBandwidth / 2.0) / (float)intMsps; - fltHiCut = ((float)intRFBandwidth / 2.0) / (float)intMsps; - m_objRFFilter->create_filter(fltLowCut, fltHiCut); - m_objNCO.setFreq(-(float)intCenterFrequency,(float)intMsps); - - //Config update - - m_objRunning.intMsps = intMsps; - m_objRunning.intCenterFrequency = intCenterFrequency; - m_objRunning.intRFBandwidth = intRFBandwidth; - m_objRunning.enmStandard = enmStandard; - m_objRunning.enmModulation = enmModulation; - m_objRunning.enmFEC = enmFEC; - m_objRunning.intSampleRate = intSampleRate; - m_objRunning.intSymbolRate = intSymbolRate; - m_objRunning.intNotchFilters = intNotchFilters; - m_objRunning.blnAllowDrift = blnAllowDrift; - m_objRunning.blnFastLock = blnFastLock; - m_objRunning.enmFilter = enmFilter; - m_objRunning.blnHardMetric = blnHardMetric; - m_objRunning.fltRollOff = fltRollOff; - m_objRunning.blnViterbi = blnViterbi; - m_objRunning.intExcursion = intExcursion; - - m_blnInitialized=true; - - m_objSettingsMutex.unlock(); - - m_blnNeedConfigUpdate=true; -} - void DATVDemod::CleanUpDATVFramework(bool blnRelease) { if (blnRelease == true) @@ -516,59 +425,59 @@ void DATVDemod::InitDATVFramework() m_lngReadIQ = 0; CleanUpDATVFramework(false); - qDebug() << "DATVDemod::InitDATVParameters:" - << " Msps: " << m_objRunning.intMsps - << " Sample Rate: " << m_objRunning.intSampleRate - << " Symbol Rate: " << m_objRunning.intSymbolRate - << " Modulation: " << m_objRunning.enmModulation - << " Notch Filters: " << m_objRunning.intNotchFilters - << " Allow Drift: " << m_objRunning.blnAllowDrift - << " Fast Lock: " << m_objRunning.blnFastLock - << " Filter: " << m_objRunning.enmFilter - << " HARD METRIC: " << m_objRunning.blnHardMetric - << " RollOff: " << m_objRunning.fltRollOff - << " Viterbi: " << m_objRunning.blnViterbi - << " Excursion: " << m_objRunning.intExcursion; + qDebug() << "DATVDemod::InitDATVFramework:" + << " Msps: " << m_settings.m_msps + << " Sample Rate: " << m_settings.m_sampleRate + << " Symbol Rate: " << m_settings.m_symbolRate + << " Modulation: " << m_settings.m_modulation + << " Notch Filters: " << m_settings.m_notchFilters + << " Allow Drift: " << m_settings.m_allowDrift + << " Fast Lock: " << m_settings.m_fastLock + << " Filter: " << m_settings.m_filter + << " HARD METRIC: " << m_settings.m_hardMetric + << " RollOff: " << m_settings.m_rollOff + << " Viterbi: " << m_settings.m_viterbi + << " Excursion: " << m_settings.m_excursion; - m_objCfg.standard = m_objRunning.enmStandard; + m_objCfg.standard = m_settings.m_standard; - m_objCfg.fec = m_objRunning.enmFEC; - m_objCfg.Fs = (float) m_objRunning.intSampleRate; - m_objCfg.Fm = (float) m_objRunning.intSymbolRate; - m_objCfg.fastlock = m_objRunning.blnFastLock; + m_objCfg.fec = m_settings.m_fec; + m_objCfg.Fs = (float) m_settings.m_sampleRate; + m_objCfg.Fm = (float) m_settings.m_symbolRate; + m_objCfg.fastlock = m_settings.m_fastLock; - m_objCfg.sampler = m_objRunning.enmFilter; - m_objCfg.rolloff = m_objRunning.fltRollOff; //0...1 - m_objCfg.rrc_rej = (float) m_objRunning.intExcursion; //dB + m_objCfg.sampler = m_settings.m_filter; + m_objCfg.rolloff = m_settings.m_rollOff; //0...1 + m_objCfg.rrc_rej = (float) m_settings.m_excursion; //dB m_objCfg.rrc_steps = 0; //auto - switch(m_objRunning.enmModulation) + switch(m_settings.m_modulation) { - case BPSK: + case DATVDemodSettings::BPSK: m_objCfg.constellation = leansdr::cstln_lut::BPSK; break; - case QPSK: + case DATVDemodSettings::QPSK: m_objCfg.constellation = leansdr::cstln_lut::QPSK; break; - case PSK8: + case DATVDemodSettings::PSK8: m_objCfg.constellation = leansdr::cstln_lut::PSK8; break; - case APSK16: + case DATVDemodSettings::APSK16: m_objCfg.constellation = leansdr::cstln_lut::APSK16; break; - case APSK32: + case DATVDemodSettings::APSK32: m_objCfg.constellation = leansdr::cstln_lut::APSK32; break; - case APSK64E: + case DATVDemodSettings::APSK64E: m_objCfg.constellation = leansdr::cstln_lut::APSK64E; break; - case QAM16: + case DATVDemodSettings::QAM16: m_objCfg.constellation = leansdr::cstln_lut::QAM16; break; - case QAM64: + case DATVDemodSettings::QAM64: m_objCfg.constellation = leansdr::cstln_lut::QAM64; break; - case QAM256: + case DATVDemodSettings::QAM256: m_objCfg.constellation = leansdr::cstln_lut::QAM256; break; default: @@ -576,12 +485,11 @@ void DATVDemod::InitDATVFramework() break; } - m_objCfg.allow_drift = m_objRunning.blnAllowDrift; - m_objCfg.anf = m_objRunning.intNotchFilters; - m_objCfg.hard_metric = m_objRunning.blnHardMetric; - m_objCfg.sampler = m_objRunning.enmFilter; - m_objCfg.viterbi = m_objRunning.blnViterbi; - + m_objCfg.allow_drift = m_settings.m_allowDrift; + m_objCfg.anf = m_settings.m_notchFilters; + m_objCfg.hard_metric = m_settings.m_hardMetric; + m_objCfg.sampler = m_settings.m_filter; + m_objCfg.viterbi = m_settings.m_viterbi; // Min buffer size for baseband data // scopes: 1024 @@ -670,13 +578,13 @@ void DATVDemod::InitDATVFramework() switch (m_objCfg.sampler) { - case SAMP_NEAREST: + case DATVDemodSettings::SAMP_NEAREST: sampler = new leansdr::nearest_sampler(); break; - case SAMP_LINEAR: + case DATVDemodSettings::SAMP_LINEAR: sampler = new leansdr::linear_sampler(); break; - case SAMP_RRC: + case DATVDemodSettings::SAMP_RRC: { if (m_objCfg.rrc_steps == 0) { @@ -706,7 +614,7 @@ void DATVDemod::InitDATVFramework() p_mer, p_sampled); - if (m_objCfg.standard == DVB_S) + if (m_objCfg.standard == DATVDemodSettings::DVB_S) { if ( m_objCfg.constellation != leansdr::cstln_lut::QPSK && m_objCfg.constellation != leansdr::cstln_lut::BPSK ) @@ -715,7 +623,7 @@ void DATVDemod::InitDATVFramework() } } - if (m_objCfg.standard == DVB_S2) + if (m_objCfg.standard == DATVDemodSettings::DVB_S2) { // For DVB-S2 testing only. // Constellation should be determined from PL signalling. @@ -947,14 +855,7 @@ bool DATVDemod::handleMessage(const Message& cmd) qDebug() << "DATVDemod::handleMessage: MsgChannelizerNotification:" << " m_intSampleRate: " << objNotif.getSampleRate() << " m_intFrequencyOffset: " << objNotif.getFrequencyOffset(); - - if (m_objRunning.intMsps != objNotif.getSampleRate()) - { - m_objRunning.intMsps = objNotif.getSampleRate(); - m_objRunning.intSampleRate = m_objRunning.intMsps; - - ApplySettings(); - } + applyChannelSettings(objNotif.getSampleRate(), objNotif.getFrequencyOffset()); return true; } @@ -974,57 +875,8 @@ bool DATVDemod::handleMessage(const Message& cmd) else if (MsgConfigureDATVDemod::match(cmd)) { MsgConfigureDATVDemod& objCfg = (MsgConfigureDATVDemod&) cmd; - - - if ((objCfg.m_objMsgConfig.blnAllowDrift != m_objRunning.blnAllowDrift) - || (objCfg.m_objMsgConfig.intRFBandwidth != m_objRunning.intRFBandwidth) - || (objCfg.m_objMsgConfig.intCenterFrequency != m_objRunning.intCenterFrequency) - || (objCfg.m_objMsgConfig.blnFastLock != m_objRunning.blnFastLock) - || (objCfg.m_objMsgConfig.blnHardMetric != m_objRunning.blnHardMetric) - || (objCfg.m_objMsgConfig.enmFilter != m_objRunning.enmFilter) - || (objCfg.m_objMsgConfig.fltRollOff != m_objRunning.fltRollOff) - || (objCfg.m_objMsgConfig.blnViterbi != m_objRunning.blnViterbi) - || (objCfg.m_objMsgConfig.enmFEC != m_objRunning.enmFEC) - || (objCfg.m_objMsgConfig.enmModulation != m_objRunning.enmModulation) - || (objCfg.m_objMsgConfig.enmStandard != m_objRunning.enmStandard) - || (objCfg.m_objMsgConfig.intNotchFilters != m_objRunning.intNotchFilters) - || (objCfg.m_objMsgConfig.intSymbolRate != m_objRunning.intSymbolRate) - || (objCfg.m_objMsgConfig.intExcursion != m_objRunning.intExcursion)) - { - m_objRunning.blnAllowDrift = objCfg.m_objMsgConfig.blnAllowDrift; - m_objRunning.blnFastLock = objCfg.m_objMsgConfig.blnFastLock; - m_objRunning.blnHardMetric = objCfg.m_objMsgConfig.blnHardMetric; - m_objRunning.enmFilter = objCfg.m_objMsgConfig.enmFilter; - m_objRunning.fltRollOff = objCfg.m_objMsgConfig.fltRollOff; - m_objRunning.blnViterbi = objCfg.m_objMsgConfig.blnViterbi; - m_objRunning.enmFEC = objCfg.m_objMsgConfig.enmFEC; - m_objRunning.enmModulation = objCfg.m_objMsgConfig.enmModulation; - m_objRunning.enmStandard = objCfg.m_objMsgConfig.enmStandard; - m_objRunning.intNotchFilters = objCfg.m_objMsgConfig.intNotchFilters; - m_objRunning.intSymbolRate = objCfg.m_objMsgConfig.intSymbolRate; - m_objRunning.intRFBandwidth = objCfg.m_objMsgConfig.intRFBandwidth; - m_objRunning.intCenterFrequency = objCfg.m_objMsgConfig.intCenterFrequency; - m_objRunning.intExcursion = objCfg.m_objMsgConfig.intExcursion; - - qDebug() << "ATVDemod::handleMessage: MsgConfigureDATVDemod:" - << " blnAllowDrift: " << objCfg.m_objMsgConfig.blnAllowDrift - << " intRFBandwidth: " << objCfg.m_objMsgConfig.intRFBandwidth - << " intCenterFrequency: " << objCfg.m_objMsgConfig.intCenterFrequency - << " blnFastLock: " << objCfg.m_objMsgConfig.blnFastLock - << " enmFilter: " << objCfg.m_objMsgConfig.enmFilter - << " fltRollOff: " << objCfg.m_objMsgConfig.fltRollOff - << " blnViterbi: " << objCfg.m_objMsgConfig.blnViterbi - << " enmFEC: " << objCfg.m_objMsgConfig.enmFEC - << " enmModulation: " << objCfg.m_objMsgConfig.enmModulation - << " enmStandard: " << objCfg.m_objMsgConfig.enmStandard - << " intNotchFilters: " << objCfg.m_objMsgConfig.intNotchFilters - << " intSymbolRate: " << objCfg.m_objMsgConfig.intSymbolRate - << " intRFBandwidth: " << objCfg.m_objMsgConfig.intRFBandwidth - << " intCenterFrequency: " << objCfg.m_objMsgConfig.intCenterFrequency - << " intExcursion: " << objCfg.m_objMsgConfig.intExcursion; - - ApplySettings(); - } + qDebug() << "DATVDemod::handleMessage: MsgConfigureDATVDemod"; + applySettings(objCfg.getSettings(), objCfg.getForce()); return true; } @@ -1034,31 +886,95 @@ bool DATVDemod::handleMessage(const Message& cmd) } } -void DATVDemod::ApplySettings() +void DATVDemod::applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force) { - if (m_objRunning.intMsps == 0) { + qDebug() << "DATVDemod::applyChannelSettings:" + << " inputSampleRate: " << inputSampleRate + << " inputFrequencyOffset: " << inputFrequencyOffset; + + if ((m_settings.m_centerFrequency != inputFrequencyOffset) || + (m_settings.m_msps != inputSampleRate) || force) + { + m_objNCO.setFreq(-(float) inputFrequencyOffset, (float) inputSampleRate); + } + + if ((m_settings.m_msps != inputSampleRate) || force) + { + m_objSettingsMutex.lock(); + //Bandpass filter shaping + Real fltLowCut = -((float) m_settings.m_rfBandwidth / 2.0) / (float) inputSampleRate; + Real fltHiCut = ((float) m_settings.m_rfBandwidth / 2.0) / (float) inputSampleRate; + m_objRFFilter->create_filter(fltLowCut, fltHiCut); + m_blnNeedConfigUpdate = true; + m_objSettingsMutex.unlock(); + } + + m_settings.m_msps = inputSampleRate; + m_settings.m_sampleRate = m_settings.m_msps; + m_settings.m_centerFrequency = inputFrequencyOffset; +} + +void DATVDemod::applySettings(const DATVDemodSettings& settings, bool force) +{ + QString msg = tr("DATVDemod::applySettings: force: %1").arg(force); + settings.debug(msg); + + if (m_settings.m_msps == 0) { return; } - InitDATVParameters(m_objRunning.intMsps, - m_objRunning.intRFBandwidth, - m_objRunning.intCenterFrequency, - m_objRunning.enmStandard, - m_objRunning.enmModulation, - m_objRunning.enmFEC, - m_objRunning.intSampleRate, - m_objRunning.intSymbolRate, - m_objRunning.intNotchFilters, - m_objRunning.blnAllowDrift, - m_objRunning.blnFastLock, - m_objRunning.enmFilter, - m_objRunning.blnHardMetric, - m_objRunning.fltRollOff, - m_objRunning.blnViterbi, - m_objRunning.intExcursion); + if (m_settings.isDifferent(settings) || force) + { + m_objSettingsMutex.lock(); + + if ((m_settings.m_rfBandwidth != settings.m_rfBandwidth) + || force) + { + + //Bandpass filter shaping + Real fltLowCut = -((float) settings.m_rfBandwidth / 2.0) / (float) m_settings.m_msps; + Real fltHiCut = ((float) settings.m_rfBandwidth / 2.0) / (float) m_settings.m_msps; + m_objRFFilter->create_filter(fltLowCut, fltHiCut); + } + + if ((m_settings.m_centerFrequency != settings.m_centerFrequency) + || force) + { + m_objNCO.setFreq(-(float) settings.m_centerFrequency, (float) m_settings.m_msps); + } + + m_objSettingsMutex.unlock(); + m_blnNeedConfigUpdate = true; + } + + m_settings = settings; } +// void DATVDemod::ApplySettings() +// { +// if (m_objRunning.intMsps == 0) { +// return; +// } + +// InitDATVParameters(m_objRunning.intMsps, +// m_objRunning.intRFBandwidth, +// m_objRunning.intCenterFrequency, +// m_objRunning.enmStandard, +// m_objRunning.enmModulation, +// m_objRunning.enmFEC, +// m_objRunning.intSampleRate, +// m_objRunning.intSymbolRate, +// m_objRunning.intNotchFilters, +// m_objRunning.blnAllowDrift, +// m_objRunning.blnFastLock, +// m_objRunning.enmFilter, +// m_objRunning.blnHardMetric, +// m_objRunning.fltRollOff, +// m_objRunning.blnViterbi, +// m_objRunning.intExcursion); +// } + int DATVDemod::GetSampleRate() { - return m_objRunning.intMsps; + return m_settings.m_msps; } diff --git a/plugins/channelrx/demoddatv/datvdemod.h b/plugins/channelrx/demoddatv/datvdemod.h index c957b648d..24e4431f5 100644 --- a/plugins/channelrx/demoddatv/datvdemod.h +++ b/plugins/channelrx/demoddatv/datvdemod.h @@ -41,6 +41,7 @@ class DownChannelizer; #include "datvvideoplayer.h" #include "datvideostream.h" #include "datvideorender.h" +#include "datvdemodsettings.h" #include "channel/channelsinkapi.h" #include "dsp/basebandsamplesink.h" @@ -58,16 +59,16 @@ class DownChannelizer; #include -enum DATVModulation { BPSK, QPSK, PSK8, APSK16, APSK32, APSK64E, QAM16, QAM64, QAM256 }; -enum dvb_version { DVB_S, DVB_S2 }; -enum dvb_sampler { SAMP_NEAREST, SAMP_LINEAR, SAMP_RRC }; +// enum DATVModulation { BPSK, QPSK, PSK8, APSK16, APSK32, APSK64E, QAM16, QAM64, QAM256 }; +// enum dvb_version { DVB_S, DVB_S2 }; +// enum dvb_sampler { SAMP_NEAREST, SAMP_LINEAR, SAMP_RRC }; inline int decimation(float Fin, float Fout) { int d = Fin / Fout; return std::max(d, 1); } struct config { - dvb_version standard; - dvb_sampler sampler; + DATVDemodSettings::dvb_version standard; + DATVDemodSettings::dvb_sampler sampler; int buf_factor; // Buffer sizing float Fs; // Sampling frequency (Hz) @@ -93,8 +94,8 @@ struct config float Finfo; // Desired refresh rate on fd_info (Hz) config() : - standard(DVB_S), - sampler(SAMP_LINEAR), + standard(DATVDemodSettings::DVB_S), + sampler(DATVDemodSettings::SAMP_LINEAR), buf_factor(4), Fs(2.4e6), Fderot(0), @@ -121,48 +122,6 @@ struct config } }; - -struct DATVConfig -{ - int intMsps; - int intRFBandwidth; - int intCenterFrequency; - dvb_version enmStandard; - DATVModulation enmModulation; - leansdr::code_rate enmFEC; - int intSampleRate; - int intSymbolRate; - int intNotchFilters; - bool blnAllowDrift; - bool blnFastLock; - dvb_sampler enmFilter; - bool blnHardMetric; - float fltRollOff; - bool blnViterbi; - int intExcursion; - - DATVConfig() : - intMsps(1024000), - intRFBandwidth(1024000), - intCenterFrequency(0), - enmStandard(DVB_S), - enmModulation(BPSK), - enmFEC(leansdr::FEC12), - intSampleRate(1024000), - intSymbolRate(250000), - intNotchFilters(1), - blnAllowDrift(false), - blnFastLock(false), - enmFilter(SAMP_LINEAR), - blnHardMetric(false), - fltRollOff(0.35), - blnViterbi(false), - intExcursion(10) - { - } -}; - - class DATVDemod : public BasebandSampleSink, public ChannelSinkAPI { Q_OBJECT @@ -175,28 +134,11 @@ public: virtual void destroy() { delete this; } virtual void getIdentifier(QString& id) { id = objectName(); } virtual void getTitle(QString& title) { title = objectName(); } - virtual qint64 getCenterFrequency() const { return m_objRunning.intCenterFrequency; } + virtual qint64 getCenterFrequency() const { return m_settings.m_centerFrequency; } virtual QByteArray serialize() const { return QByteArray(); } virtual bool deserialize(const QByteArray& data) { (void) data; return false; } - void configure( - MessageQueue* objMessageQueue, - int intRFBandwidth, - int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, - leansdr::code_rate enmFEC, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - dvb_sampler enmFilter, - bool blnHardMetric, - float fltRollOff, - bool blnViterbi, - int intfltExcursion); - virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po); virtual void start(); virtual void stop(); @@ -211,15 +153,15 @@ public: int intMsps, int intRFBandwidth, int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, + DATVDemodSettings::dvb_version enmStandard, + DATVDemodSettings::DATVModulation enmModulation, leansdr::code_rate enmFEC, int intSampleRate, int intSymbolRate, int intNotchFilters, bool blnAllowDrift, bool blnFastLock, - dvb_sampler enmFilter, + DATVDemodSettings::dvb_sampler enmFilter, bool blnHardMetric, float fltRollOff, bool blnViterbi, @@ -253,82 +195,30 @@ public: {} }; -private: - class MsgConfigureDATVDemod : public Message - { + class MsgConfigureDATVDemod : public Message { MESSAGE_CLASS_DECLARATION - public: - static MsgConfigureDATVDemod* create( - int intRFBandwidth, - int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, - leansdr::code_rate enmFEC, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - dvb_sampler enmFilter, - bool blnHardMetric, - float fltRollOff, - bool blnViterbi, - int intExcursion) - { - return new MsgConfigureDATVDemod( - intRFBandwidth, - intCenterFrequency, - enmStandard, - enmModulation, - enmFEC, - intSymbolRate, - intNotchFilters, - blnAllowDrift, - blnFastLock, - enmFilter, - blnHardMetric, - fltRollOff, - blnViterbi, - intExcursion); - } + public: + const DATVDemodSettings& getSettings() const { return m_settings; } + bool getForce() const { return m_force; } - DATVConfig m_objMsgConfig; + static MsgConfigureDATVDemod* create(const DATVDemodSettings& settings, bool force) + { + return new MsgConfigureDATVDemod(settings, force); + } - private: - MsgConfigureDATVDemod( - int intRFBandwidth, - int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, - leansdr::code_rate enmFEC, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - dvb_sampler enmFilter, - bool blnHardMetric, - float fltRollOff, - bool blnViterbi, - int intExcursion) : - Message() - { - m_objMsgConfig.intRFBandwidth = intRFBandwidth; - m_objMsgConfig.intCenterFrequency = intCenterFrequency; - m_objMsgConfig.enmStandard = enmStandard; - m_objMsgConfig.enmModulation = enmModulation; - m_objMsgConfig.enmFEC = enmFEC; - m_objMsgConfig.intSymbolRate = intSymbolRate; - m_objMsgConfig.intNotchFilters = intNotchFilters; - m_objMsgConfig.blnAllowDrift = blnAllowDrift; - m_objMsgConfig.blnFastLock = blnFastLock; - m_objMsgConfig.enmFilter= enmFilter; - m_objMsgConfig.blnHardMetric = blnHardMetric; - m_objMsgConfig.fltRollOff = fltRollOff; - m_objMsgConfig.blnViterbi = blnViterbi; - m_objMsgConfig.intExcursion = intExcursion; - } + private: + DATVDemodSettings m_settings; + bool m_force; + + MsgConfigureDATVDemod(const DATVDemodSettings& settings, bool force) : + Message(), + m_settings(settings), + m_force(force) + { } }; +private: unsigned long m_lngExpectedReadIQ; long m_lngReadIQ; @@ -455,14 +345,17 @@ private: bool m_blnRenderingVideo; bool m_blnStartStopVideo; - DATVModulation m_enmModulation; + DATVDemodSettings::DATVModulation m_enmModulation; - DATVConfig m_objRunning; + //DATVConfig m_objRunning; + DATVDemodSettings m_settings; MovingAverageUtil m_objMagSqAverage; QMutex m_objSettingsMutex; - void ApplySettings(); + //void ApplySettings(); + void applySettings(const DATVDemodSettings& settings, bool force = false); + void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force = false); }; #endif // INCLUDE_DATVDEMOD_H diff --git a/plugins/channelrx/demoddatv/datvdemodgui.cpp b/plugins/channelrx/demoddatv/datvdemodgui.cpp index 9a332e719..64906efa8 100644 --- a/plugins/channelrx/demoddatv/datvdemodgui.cpp +++ b/plugins/channelrx/demoddatv/datvdemodgui.cpp @@ -21,7 +21,6 @@ #include #include "datvdemodgui.h" -//#include "datvideostream.h" #include "device/devicesourceapi.h" #include "device/deviceuiset.h" @@ -74,142 +73,22 @@ void DATVDemodGUI::setCenterFrequency(qint64 intCenterFrequency) void DATVDemodGUI::resetToDefaults() { - blockApplySettings(true); - - ui->chkAllowDrift->setChecked(false); - ui->chkFastlock->setChecked(true); - ui->chkHardMetric->setChecked(false); - ui->chkViterbi->setChecked(false); - - ui->cmbFEC->setCurrentIndex(0); - ui->cmbModulation->setCurrentIndex(0); - ui->cmbStandard->setCurrentIndex(0); - ui->cmbFilter->setCurrentIndex(0); - displayRRCParameters(false); - - ui->spiNotchFilters->setValue(0); - ui->prgSynchro->setValue(0); - - ui->lblStatus->setText(""); - - ui->rfBandwidth->setValue(512000); - ui->spiSymbolRate->setValue(250000); - ui->spiRollOff->setValue(35); - ui->spiExcursion->setValue(10); - - - blockApplySettings(false); - - applySettings(); + m_settings.resetToDefaults(); + displaySettings(); + applySettings(true); } QByteArray DATVDemodGUI::serialize() const { - SimpleSerializer s(1); - - s.writeS32(1, m_objChannelMarker.getCenterFrequency()); - s.writeU32(2, m_objChannelMarker.getColor().rgb()); - - s.writeBool(3, ui->chkAllowDrift->isChecked()); - s.writeBool(4, ui->chkFastlock->isChecked()); - s.writeS32(5, ui->cmbFilter->currentIndex()); - s.writeBool(6, ui->chkHardMetric->isChecked()); - s.writeS32(7, ui->spiRollOff->value()); - s.writeBool(8, ui->chkViterbi->isChecked()); - - s.writeS32(9, ui->cmbFEC->currentIndex()); - s.writeS32(10, ui->cmbModulation->currentIndex()); - s.writeS32(11, ui->cmbStandard->currentIndex()); - - s.writeS32(12, ui->spiNotchFilters->value()); - s.writeS64(13, ui->rfBandwidth->getValue()); - s.writeS32(14, ui->spiSymbolRate->value()); - s.writeS32(15, ui->spiExcursion->value()); - - return s.final(); + return m_settings.serialize(); } bool DATVDemodGUI::deserialize(const QByteArray& arrData) { - SimpleDeserializer d(arrData); - - if (!d.isValid()) + if (m_settings.deserialize(arrData)) { - resetToDefaults(); - return false; - } - - if (d.getVersion() == 1) - { - QByteArray bytetmp; - uint32_t u32tmp; - qint64 i64tmp; - int tmp; - bool booltmp; - - blockApplySettings(true); - m_objChannelMarker.blockSignals(true); - - d.readS32(1, &tmp, 0); - m_objChannelMarker.setCenterFrequency(tmp); - ui->deltaFrequency->setValue(tmp); - - if (d.readU32(2, &u32tmp)) - { - m_objChannelMarker.setColor(u32tmp); - } - else - { - m_objChannelMarker.setColor(Qt::magenta); - } - - d.readBool(3, &booltmp, false); - ui->chkAllowDrift->setChecked(booltmp); - - d.readBool(4, &booltmp, false); - ui->chkFastlock->setChecked(booltmp); - - d.readS32(5, &tmp, false); - ui->cmbFilter->setCurrentIndex(tmp); - - displayRRCParameters((tmp==2)); - - d.readBool(6, &booltmp, false); - ui->chkHardMetric->setChecked(booltmp); - - d.readS32(7, &tmp, false); - ui->spiRollOff->setValue(tmp); - - d.readBool(8, &booltmp, false); - ui->chkViterbi->setChecked(booltmp); - - - d.readS32(9, &tmp, 0); - ui->cmbFEC->setCurrentIndex(tmp); - - d.readS32(10, &tmp, 0); - ui->cmbModulation->setCurrentIndex(tmp); - - d.readS32(11, &tmp, 0); - ui->cmbStandard->setCurrentIndex(tmp); - - d.readS32(12, &tmp, 0); - ui->spiNotchFilters->setValue(tmp); - - d.readS64(13, &i64tmp, 5120000); - ui->rfBandwidth->setValue(i64tmp); - - d.readS32(14, &tmp, 250000); - ui->spiSymbolRate->setValue(tmp); - - d.readS32(15, &tmp, false); - ui->spiExcursion->setValue(tmp); - - - blockApplySettings(false); - m_objChannelMarker.blockSignals(false); - - applySettings(); + displaySettings(); + applySettings(true); return true; } else @@ -323,17 +202,41 @@ void DATVDemodGUI::blockApplySettings(bool blnBlock) m_blnDoApplySettings = !blnBlock; } -void DATVDemodGUI::applySettings() +void DATVDemodGUI::displaySettings() +{ + m_objChannelMarker.blockSignals(true); + blockApplySettings(true); + + m_objChannelMarker.setCenterFrequency(m_settings.m_centerFrequency); + ui->deltaFrequency->setValue(m_settings.m_centerFrequency); + m_objChannelMarker.setColor(m_settings.m_rgbColor); + ui->chkAllowDrift->setChecked(m_settings.m_allowDrift); + ui->chkFastlock->setChecked(m_settings.m_fastLock); + ui->cmbFilter->setCurrentIndex((int) m_settings.m_filter); + + displayRRCParameters(((int) m_settings.m_filter == 2)); + + ui->chkHardMetric->setChecked(m_settings.m_hardMetric); + ui->spiRollOff->setValue((int) (m_settings.m_rollOff * 100.0f)); + ui->chkViterbi->setChecked(m_settings.m_viterbi); + ui->cmbFEC->setCurrentIndex((int) m_settings.m_fec); + ui->cmbModulation->setCurrentIndex((int) m_settings.m_modulation); + ui->cmbStandard->setCurrentIndex((int) m_settings.m_standard); + ui->spiNotchFilters->setValue(m_settings.m_notchFilters); + ui->rfBandwidth->setValue(m_settings.m_rfBandwidth); + ui->spiSymbolRate->setValue(m_settings.m_symbolRate); + ui->spiExcursion->setValue(m_settings.m_excursion); + + blockApplySettings(false); + m_objChannelMarker.blockSignals(false); +} + +void DATVDemodGUI::applySettings(bool force) { QString strStandard; QString strModulation; QString strFEC; - DATVModulation enmSelectedModulation; - dvb_version enmVersion; - leansdr::code_rate enmFEC; - dvb_sampler enmSampler; - if (m_blnDoApplySettings) { //Bandwidth and center frequency @@ -348,11 +251,11 @@ void DATVDemodGUI::applySettings() strStandard = ui->cmbStandard->currentText(); if(strStandard=="DVB-S") { - enmVersion=DVB_S; + m_settings.m_standard = DATVDemodSettings::DVB_S; } else if (strStandard=="DVB-S2") { - enmVersion=DVB_S2; + m_settings.m_standard = DATVDemodSettings::DVB_S2; } else { - enmVersion=DVB_S; + m_settings.m_standard = DATVDemodSettings::DVB_S; } //BPSK, QPSK, PSK8, APSK16, APSK32, APSK64E, QAM16, QAM64, QAM256 @@ -360,90 +263,88 @@ void DATVDemodGUI::applySettings() strModulation = ui->cmbModulation->currentText(); if(strModulation=="BPSK") { - enmSelectedModulation=BPSK; + m_settings.m_modulation = DATVDemodSettings::BPSK; } else if(strModulation=="QPSK") { - enmSelectedModulation=QPSK; + m_settings.m_modulation = DATVDemodSettings::QPSK; } else if(strModulation=="8PSK") { - enmSelectedModulation=PSK8; + m_settings.m_modulation = DATVDemodSettings::PSK8; } else if(strModulation=="16APSK") { - enmSelectedModulation=APSK16; + m_settings.m_modulation = DATVDemodSettings::APSK16; } else if(strModulation=="32APSK") { - enmSelectedModulation=APSK32; + m_settings.m_modulation = DATVDemodSettings::APSK32; } else if(strModulation=="64APSKE") { - enmSelectedModulation=APSK64E; + m_settings.m_modulation = DATVDemodSettings::APSK64E; } else if(strModulation=="16QAM") { - enmSelectedModulation=QAM16; + m_settings.m_modulation = DATVDemodSettings::QAM16; } else if(strModulation=="64QAM") { - enmSelectedModulation=QAM64; + m_settings.m_modulation = DATVDemodSettings::QAM64; } else if(strModulation=="256QAM") { - enmSelectedModulation=QAM256; + m_settings.m_modulation = DATVDemodSettings::QAM256; } else { - enmSelectedModulation=BPSK; + m_settings.m_modulation = DATVDemodSettings::BPSK; } //Viterbi only for BPSK et QPSK - if ((enmSelectedModulation!=BPSK) && (enmSelectedModulation!=QPSK)) { + if ((m_settings.m_modulation != DATVDemodSettings::BPSK) + && (m_settings.m_modulation != DATVDemodSettings::QPSK)) + { ui->chkViterbi->setChecked(false); } strFEC = ui->cmbFEC->currentText(); if (strFEC == "1/2") { - enmFEC = leansdr::FEC12; + m_settings.m_fec = leansdr::FEC12; } else if (strFEC == "2/3") { - enmFEC = leansdr::FEC23; + m_settings.m_fec = leansdr::FEC23; } else if (strFEC == "3/4") { - enmFEC = leansdr::FEC34; + m_settings.m_fec = leansdr::FEC34; } else if (strFEC == "5/6") { - enmFEC = leansdr::FEC56; + m_settings.m_fec = leansdr::FEC56; } else if (strFEC == "7/8") { - enmFEC = leansdr::FEC78; + m_settings.m_fec = leansdr::FEC78; } else if (strFEC == "4/5") { - enmFEC = leansdr::FEC45; + m_settings.m_fec = leansdr::FEC45; } else if (strFEC == "8/9") { - enmFEC = leansdr::FEC89; + m_settings.m_fec = leansdr::FEC89; } else if (strFEC == "9/10") { - enmFEC = leansdr::FEC910; + m_settings.m_fec = leansdr::FEC910; } else { - enmFEC = leansdr::FEC12; + m_settings.m_fec = leansdr::FEC12; } if (ui->cmbFilter->currentIndex() == 0) { - enmSampler = SAMP_LINEAR; + m_settings.m_filter = DATVDemodSettings::SAMP_LINEAR; } else if (ui->cmbFilter->currentIndex() == 1) { - enmSampler = SAMP_NEAREST; + m_settings.m_filter = DATVDemodSettings::SAMP_NEAREST; } else { - enmSampler = SAMP_RRC; + m_settings.m_filter = DATVDemodSettings::SAMP_RRC; } - m_objDATVDemod->configure( - m_objDATVDemod->getInputMessageQueue(), - m_objChannelMarker.getBandwidth(), - m_objChannelMarker.getCenterFrequency(), - enmVersion, - enmSelectedModulation, - enmFEC, - ui->spiSymbolRate->value(), - ui->spiNotchFilters->value(), - ui->chkAllowDrift->isChecked(), - ui->chkFastlock->isChecked(), - enmSampler, - ui->chkHardMetric->isChecked(), - ((float)ui->spiRollOff->value())/100.0f, - ui->chkViterbi->isChecked(), - ui->spiExcursion->value()); + m_settings.m_rfBandwidth = m_objChannelMarker.getBandwidth(); + m_settings.m_centerFrequency = m_objChannelMarker.getCenterFrequency(); + m_settings.m_symbolRate = ui->spiSymbolRate->value(); + m_settings.m_notchFilters = ui->spiNotchFilters->value(); + m_settings.m_allowDrift = ui->chkAllowDrift->isChecked(); + m_settings.m_fastLock = ui->chkFastlock->isChecked(); + m_settings.m_hardMetric = ui->chkHardMetric->isChecked(); + m_settings.m_rollOff = ((float)ui->spiRollOff->value()) / 100.0f; + m_settings.m_viterbi = ui->chkViterbi->isChecked(); + m_settings.m_excursion = ui->spiExcursion->value(); - qDebug() << "DATVDemodGUI::applySettings:" - << " m_objDATVDemod->getCenterFrequency: " << m_objDATVDemod->getCenterFrequency() - << " m_objDATVDemod->GetSampleRate: " << m_objDATVDemod->GetSampleRate(); + QString msg = tr("DATVDemodGUI::applySettings: force: %1").arg(force); + m_settings.debug(msg); + + DATVDemod::MsgConfigureDATVDemod* message = DATVDemod::MsgConfigureDATVDemod::create(m_settings, force); + m_objDATVDemod->getInputMessageQueue()->push(message); } } diff --git a/plugins/channelrx/demoddatv/datvdemodgui.h b/plugins/channelrx/demoddatv/datvdemodgui.h index 4af8300ac..9845be534 100644 --- a/plugins/channelrx/demoddatv/datvdemodgui.h +++ b/plugins/channelrx/demoddatv/datvdemodgui.h @@ -32,10 +32,7 @@ class PluginAPI; class DeviceUISet; class BasebandSampleSink; -//class DeviceSourceAPI; -//class ThreadedBasebandSampleSink; class DownChannelizer; -//class DATVDemod; namespace Ui { @@ -106,6 +103,7 @@ private: DATVDemod* m_objDATVDemod; MessageQueue m_inputMessageQueue; int m_intCenterFrequency; + DATVDemodSettings m_settings; QTimer m_objTimer; qint64 m_intPreviousDecodedData; @@ -123,7 +121,8 @@ private: virtual ~DATVDemodGUI(); void blockApplySettings(bool blnBlock); - void applySettings(); + void applySettings(bool force = false); + void displaySettings(); QString formatBytes(qint64 intBytes); void displayRRCParameters(bool blnVisible); diff --git a/plugins/channelrx/demoddatv/datvdemodsettings.cpp b/plugins/channelrx/demoddatv/datvdemodsettings.cpp index 22cbcdc74..c7e48553a 100644 --- a/plugins/channelrx/demoddatv/datvdemodsettings.cpp +++ b/plugins/channelrx/demoddatv/datvdemodsettings.cpp @@ -15,6 +15,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #include "util/simpleserializer.h" #include "settings/serializable.h" @@ -32,7 +33,7 @@ void DATVDemodSettings::resetToDefaults() m_rgbColor = QColor(Qt::magenta).rgb(); m_title = "DATV Demodulator"; m_msps = 1024000; - m_rfBandwidth = 1024000; + m_rfBandwidth = 512000; m_centerFrequency = 0; m_standard = DVB_S; m_modulation = BPSK; @@ -96,7 +97,7 @@ bool DATVDemodSettings::deserialize(const QByteArray& data) QString strtmp; d.readS32(1, &m_msps, 1024000); - d.readS32(2, &m_rfBandwidth, 1024000); + d.readS32(2, &m_rfBandwidth, 512000); d.readS32(3, &m_centerFrequency, 0); d.readS32(4, &tmp, (int) DVB_S); @@ -113,7 +114,7 @@ bool DATVDemodSettings::deserialize(const QByteArray& data) m_channelMarker->deserialize(bytetmp); } - d.readU32(7, &m_rgbColor); + d.readU32(7, &m_rgbColor, QColor(Qt::magenta).rgb()); d.readString(8, &m_title, "DATV Demodulator"); d.readS32(9, &tmp, (int) leansdr::code_rate::FEC12); @@ -143,3 +144,42 @@ bool DATVDemodSettings::deserialize(const QByteArray& data) return false; } } + +void DATVDemodSettings::debug(const QString& msg) const +{ + qDebug() << msg + << " m_msps: " << m_msps + << " m_sampleRate: " << m_sampleRate + << " m_allowDrift: " << m_allowDrift + << " m_rfBandwidth: " << m_rfBandwidth + << " m_centerFrequency: " << m_centerFrequency + << " m_fastLock: " << m_fastLock + << " m_hardMetric: " << m_hardMetric + << " m_filter: " << m_filter + << " m_rollOff: " << m_rollOff + << " m_viterbi: " << m_viterbi + << " m_fec: " << m_fec + << " m_modulation: " << m_modulation + << " m_standard: " << m_standard + << " m_notchFilters: " << m_notchFilters + << " m_symbolRate: " << m_symbolRate + << " m_excursion: " << m_excursion; +} + +bool DATVDemodSettings::isDifferent(const DATVDemodSettings& other) +{ + return ((m_allowDrift != other.m_allowDrift) + || (m_rfBandwidth != other.m_rfBandwidth) + || (m_centerFrequency != other.m_centerFrequency) + || (m_fastLock != other.m_fastLock) + || (m_hardMetric != other.m_hardMetric) + || (m_filter != other.m_filter) + || (m_rollOff != other.m_rollOff) + || (m_viterbi != other.m_viterbi) + || (m_fec != other.m_fec) + || (m_modulation != other.m_modulation) + || (m_standard != other.m_standard) + || (m_notchFilters != other.m_notchFilters) + || (m_symbolRate != other.m_symbolRate) + || (m_excursion != other.m_excursion)); +} \ No newline at end of file diff --git a/plugins/channelrx/demoddatv/datvdemodsettings.h b/plugins/channelrx/demoddatv/datvdemodsettings.h index d2d3aa252..6ad288081 100644 --- a/plugins/channelrx/demoddatv/datvdemodsettings.h +++ b/plugins/channelrx/demoddatv/datvdemodsettings.h @@ -56,13 +56,13 @@ struct DATVDemodSettings quint32 m_rgbColor; QString m_title; Serializable *m_channelMarker; - int m_msps; + int m_msps; //!< FIXME: ineffective int m_rfBandwidth; int m_centerFrequency; dvb_version m_standard; DATVModulation m_modulation; leansdr::code_rate m_fec; - int m_sampleRate; + int m_sampleRate; //!< FIXME: innefective int m_symbolRate; int m_notchFilters; bool m_allowDrift; @@ -78,6 +78,8 @@ struct DATVDemodSettings void setChannelMarker(Serializable *channelMarker) { m_channelMarker = channelMarker; } QByteArray serialize() const; bool deserialize(const QByteArray& data); + void debug(const QString& msg) const; + bool isDifferent(const DATVDemodSettings& other); }; #endif // PLUGINS_CHANNELRX_DEMODATV_DATVDEMODSETTINGS_H_ \ No newline at end of file