From 629fc9ce79d3a270a19c9e3ce0575e3161ab87c2 Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 11 Sep 2017 23:51:58 +0200 Subject: [PATCH] PlutoSDR input: restore full range of FIR Rx gain --- devices/plutosdr/deviceplutosdrbox.cpp | 30 ++++++++++++++----- devices/plutosdr/deviceplutosdrbox.h | 7 +++-- .../plutosdrinput/plutosdrinput.cpp | 2 +- .../plutosdrinput/plutosdrinputgui.cpp | 4 +-- .../plutosdrinput/plutosdrinputgui.ui | 16 ++++++---- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/devices/plutosdr/deviceplutosdrbox.cpp b/devices/plutosdr/deviceplutosdrbox.cpp index 3538fe33b..7532bab57 100644 --- a/devices/plutosdr/deviceplutosdrbox.cpp +++ b/devices/plutosdr/deviceplutosdrbox.cpp @@ -27,6 +27,8 @@ #include "deviceplutosdrbox.h" DevicePlutoSDRBox::DevicePlutoSDRBox(const std::string& uri) : + m_lpfFIRRxGain(0), + m_lpfFIRTxGain(0), m_chnRx0(0), m_chnTx0(0), m_rxBuf(0), @@ -470,7 +472,14 @@ void DevicePlutoSDRBox::setSampleRate(uint32_t sampleRate) m_devSampleRate = sampleRate; } -void DevicePlutoSDRBox::setFIR(uint32_t sampleRate, uint32_t log2IntDec, uint32_t bw, int gain) +/** + * @param sampleRate baseband sample rate (S/s) + * @param log2IntDec FIR interpolation or decimation factor + * @param use Rx or Tx. Applies to the rest of the parameters + * @param bw FIR filter bandwidth at approximately -6 dB cutoff (Hz) + * @param gain FIR filter gain (dB) + */ +void DevicePlutoSDRBox::setFIR(uint32_t sampleRate, uint32_t log2IntDec, DeviceUse use, uint32_t bw, int gain) { SampleRates sampleRates; std::ostringstream ostr; @@ -479,11 +488,19 @@ void DevicePlutoSDRBox::setFIR(uint32_t sampleRate, uint32_t log2IntDec, uint32_ double normalizedBW; uint32_t intdec = 1<<(log2IntDec > 2 ? 2 : log2IntDec); + // update gain parameter + + if (use == USE_RX) { + m_lpfFIRRxGain = gain; + } else { + m_lpfFIRTxGain = gain; + } + // set a dummy minimal filter first to get the sample rates right setFIREnable(false); // disable first - formatFIRHeader(ostr, intdec, gain); + formatFIRHeader(ostr, intdec); formatFIRCoefficients(ostr, 16, 0.5); setFilter(ostr.str()); ostr.str(""); // reset string stream @@ -515,13 +532,12 @@ void DevicePlutoSDRBox::setFIR(uint32_t sampleRate, uint32_t log2IntDec, uint32_ // set the right filter - formatFIRHeader(ostr, intdec, gain); + formatFIRHeader(ostr, intdec); formatFIRCoefficients(ostr, nbTaps, normalizedBW); setFilter(ostr.str()); m_lpfFIRlog2Decim = log2IntDec; m_lpfFIRBW = bw; - m_lpfFIRGain = gain; // enable and set sample rate will be done by the caller } @@ -547,10 +563,10 @@ void DevicePlutoSDRBox::setLOPPMTenths(int ppmTenths) m_LOppmTenths = ppmTenths; } -void DevicePlutoSDRBox::formatFIRHeader(std::ostringstream& ostr,uint32_t intdec, int32_t gain) +void DevicePlutoSDRBox::formatFIRHeader(std::ostringstream& ostr,uint32_t intdec) { - ostr << "RX 3 GAIN " << gain << " DEC " << intdec << std::endl; - ostr << "TX 3 GAIN " << gain << " INT " << intdec << std::endl; + ostr << "RX 3 GAIN " << m_lpfFIRRxGain << " DEC " << intdec << std::endl; + ostr << "TX 3 GAIN " << m_lpfFIRTxGain << " INT " << intdec << std::endl; } void DevicePlutoSDRBox::formatFIRCoefficients(std::ostringstream& ostr, uint32_t nbTaps, double normalizedBW) diff --git a/devices/plutosdr/deviceplutosdrbox.h b/devices/plutosdr/deviceplutosdrbox.h index 8990ceb46..caeaab99a 100644 --- a/devices/plutosdr/deviceplutosdrbox.h +++ b/devices/plutosdr/deviceplutosdrbox.h @@ -57,7 +57,8 @@ public: bool m_lpfFIREnable; //!< enable digital lowpass FIR filter float m_lpfFIRBW; //!< digital lowpass FIR filter bandwidth (Hz) uint32_t m_lpfFIRlog2Decim; //!< digital lowpass FIR filter log2 of decimation factor (0..2) - int m_lpfFIRGain; //!< digital lowpass FIR filter gain (dB) + int m_lpfFIRRxGain; //!< digital lowpass FIR filter gain Rx side (dB) + int m_lpfFIRTxGain; //!< digital lowpass FIR filter gain Tx side (dB) DevicePlutoSDRBox(const std::string& uri); ~DevicePlutoSDRBox(); @@ -88,7 +89,7 @@ public: bool getRxSampleRates(SampleRates& sampleRates); bool getTxSampleRates(SampleRates& sampleRates); void setSampleRate(uint32_t sampleRate); - void setFIR(uint32_t sampleRate, uint32_t intdec, uint32_t bw, int gain); + void setFIR(uint32_t sampleRate, uint32_t intdec, DeviceUse use, uint32_t bw, int gain); void setFIREnable(bool enable); void setLOPPMTenths(int ppmTenths); bool getRSSI(std::string& rssiStr, unsigned int chan); @@ -111,7 +112,7 @@ private: bool parseSampleRates(const std::string& rateStr, SampleRates& sampleRates); void setFilter(const std::string& filterConfigStr); - void formatFIRHeader(std::ostringstream& str, uint32_t intdec, int32_t gain); + void formatFIRHeader(std::ostringstream& str, uint32_t intdec); void formatFIRCoefficients(std::ostringstream& str, uint32_t nbTaps, double normalizedBW); void getXO(); void setTracking(); diff --git a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp index c9cb8a283..704648cb2 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp @@ -322,7 +322,7 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool fo (settings.m_lpfFIRBW != m_settings.m_lpfFIRBW) || (settings.m_lpfFIRGain != m_settings.m_lpfFIRGain) || force) { - plutoBox->setFIR(settings.m_devSampleRate, settings.m_lpfFIRlog2Decim, settings.m_lpfFIRBW, settings.m_lpfFIRGain); // don't bother with the FIR at this point + plutoBox->setFIR(settings.m_devSampleRate, settings.m_lpfFIRlog2Decim, DevicePlutoSDRBox::USE_RX, settings.m_lpfFIRBW, settings.m_lpfFIRGain); plutoBox->setFIREnable(settings.m_lpfFIREnable); // eventually enable/disable FIR plutoBox->setSampleRate(settings.m_devSampleRate); // and set end point sample rate diff --git a/plugins/samplesource/plutosdrinput/plutosdrinputgui.cpp b/plugins/samplesource/plutosdrinput/plutosdrinputgui.cpp index c9bf309bb..736657365 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinputgui.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinputgui.cpp @@ -235,7 +235,7 @@ void PlutoSDRInputGui::on_lpFIRDecimation_currentIndexChanged(int index) void PlutoSDRInputGui::on_lpFIRGain_currentIndexChanged(int index) { - m_settings.m_lpfFIRGain = 6*(index > 1 ? 1 : index) - 6; + m_settings.m_lpfFIRGain = 6*(index > 3 ? 3 : index) - 12; sendSettings(); } @@ -276,7 +276,7 @@ void PlutoSDRInputGui::displaySettings() ui->lpFIREnable->setChecked(m_settings.m_lpfFIREnable); ui->lpFIR->setValue(m_settings.m_lpfFIRBW / 1000); ui->lpFIRDecimation->setCurrentIndex(m_settings.m_lpfFIRlog2Decim); - ui->lpFIRGain->setCurrentIndex((m_settings.m_lpfFIRGain + 6)/6); + ui->lpFIRGain->setCurrentIndex((m_settings.m_lpfFIRGain + 12)/6); ui->lpFIRDecimation->setEnabled(m_settings.m_lpfFIREnable); ui->lpFIRGain->setEnabled(m_settings.m_lpfFIREnable); diff --git a/plugins/samplesource/plutosdrinput/plutosdrinputgui.ui b/plugins/samplesource/plutosdrinput/plutosdrinputgui.ui index 1b665b890..f858acfcc 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinputgui.ui +++ b/plugins/samplesource/plutosdrinput/plutosdrinputgui.ui @@ -701,15 +701,14 @@ - - - 50 - 16777215 - - FIR gain (dB) + + + -12 + + -6 @@ -720,6 +719,11 @@ 0 + + + +6 + +