diff --git a/devices/bladerf2/devicebladerf2.cpp b/devices/bladerf2/devicebladerf2.cpp index 8e4d96476..0cfb58573 100644 --- a/devices/bladerf2/devicebladerf2.cpp +++ b/devices/bladerf2/devicebladerf2.cpp @@ -455,7 +455,7 @@ void DeviceBladeRF2::getBandwidthRangeTx(int& min, int& max, int& step) } } -void DeviceBladeRF2::getGlobalGainRangeRx(int& min, int& max, int& step) +void DeviceBladeRF2::getGlobalGainRangeRx(int& min, int& max, int& step, float& scale) { if (m_dev) { @@ -474,11 +474,12 @@ void DeviceBladeRF2::getGlobalGainRangeRx(int& min, int& max, int& step) min = range->min; max = range->max; step = range->step; + scale = range->scale; } } } -void DeviceBladeRF2::getGlobalGainRangeTx(int& min, int& max, int& step) +void DeviceBladeRF2::getGlobalGainRangeTx(int& min, int& max, int& step, float& scale) { if (m_dev) { @@ -497,6 +498,9 @@ void DeviceBladeRF2::getGlobalGainRangeTx(int& min, int& max, int& step) min = range->min; max = range->max; step = range->step; + scale = range->scale; + qDebug("DeviceBladeRF2::getGlobalGainRangeTx: min: %d max: %d step: %d scale: %f", + min, max, step, scale); } } } diff --git a/devices/bladerf2/devicebladerf2.h b/devices/bladerf2/devicebladerf2.h index 805e57692..a5559b42c 100644 --- a/devices/bladerf2/devicebladerf2.h +++ b/devices/bladerf2/devicebladerf2.h @@ -47,8 +47,8 @@ public: void getSampleRateRangeTx(int& min, int& max, int& step); void getBandwidthRangeRx(int& min, int& max, int& step); void getBandwidthRangeTx(int& min, int& max, int& step); - void getGlobalGainRangeRx(int& min, int& max, int& step); - void getGlobalGainRangeTx(int& min, int& max, int& step); + void getGlobalGainRangeRx(int& min, int& max, int& step, float& scale); + void getGlobalGainRangeTx(int& min, int& max, int& step, float& scale); int getGainModesRx(const bladerf_gain_modes**); void setBiasTeeRx(bool enable); void setBiasTeeTx(bool enable); diff --git a/plugins/samplesink/bladerf2output/bladerf2output.cpp b/plugins/samplesink/bladerf2output/bladerf2output.cpp index f49efb3ee..21396b437 100644 --- a/plugins/samplesink/bladerf2output/bladerf2output.cpp +++ b/plugins/samplesink/bladerf2output/bladerf2output.cpp @@ -577,10 +577,10 @@ void BladeRF2Output::getBandwidthRange(int& min, int& max, int& step) } } -void BladeRF2Output::getGlobalGainRange(int& min, int& max, int& step) +void BladeRF2Output::getGlobalGainRange(int& min, int& max, int& step, float& scale) { if (m_deviceShared.m_dev) { - m_deviceShared.m_dev->getGlobalGainRangeTx(min, max, step); + m_deviceShared.m_dev->getGlobalGainRangeTx(min, max, step, scale); } } @@ -827,8 +827,9 @@ bool BladeRF2Output::applySettings(const BladeRF2OutputSettings& settings, bool if (getMessageQueueToGUI()) { int min, max, step; - getGlobalGainRange(min, max, step); - MsgReportGainRange *msg = MsgReportGainRange::create(min, max, step); + float scale; + getGlobalGainRange(min, max, step, scale); + MsgReportGainRange *msg = MsgReportGainRange::create(min, max, step, scale); getMessageQueueToGUI()->push(msg); } } @@ -1062,6 +1063,7 @@ void BladeRF2Output::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& resp if (device) { int min, max, step; + float scale; uint64_t f_min, f_max; device->getBandwidthRangeTx(min, max, step); @@ -1078,7 +1080,7 @@ void BladeRF2Output::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& resp response.getBladeRf2OutputReport()->getFrequencyRange()->setMax(f_max); response.getBladeRf2OutputReport()->getFrequencyRange()->setStep(step); - device->getGlobalGainRangeTx(min, max, step); + device->getGlobalGainRangeTx(min, max, step, scale); response.getBladeRf2OutputReport()->setGlobalGainRange(new SWGSDRangel::SWGRange); response.getBladeRf2OutputReport()->getGlobalGainRange()->setMin(min); diff --git a/plugins/samplesink/bladerf2output/bladerf2output.h b/plugins/samplesink/bladerf2output/bladerf2output.h index c8d87b607..d97ffdd31 100644 --- a/plugins/samplesink/bladerf2output/bladerf2output.h +++ b/plugins/samplesink/bladerf2output/bladerf2output.h @@ -85,21 +85,24 @@ public: int getMin() const { return m_min; } int getMax() const { return m_max; } int getStep() const { return m_step; } + float getScale() const { return m_scale; } - static MsgReportGainRange* create(int min, int max, int step) { - return new MsgReportGainRange(min, max, step); + static MsgReportGainRange* create(int min, int max, int step, float scale) { + return new MsgReportGainRange(min, max, step, scale); } protected: int m_min; int m_max; int m_step; + float m_scale; - MsgReportGainRange(int min, int max, int step) : + MsgReportGainRange(int min, int max, int step, float scale) : Message(), m_min(min), m_max(max), - m_step(step) + m_step(step), + m_scale(scale) {} }; @@ -126,7 +129,7 @@ public: void getFrequencyRange(uint64_t& min, uint64_t& max, int& step); void getSampleRateRange(int& min, int& max, int& step); void getBandwidthRange(int& min, int& max, int& step); - void getGlobalGainRange(int& min, int& max, int& step); + void getGlobalGainRange(int& min, int& max, int& step, float& scale); virtual bool handleMessage(const Message& message); diff --git a/plugins/samplesink/bladerf2output/bladerf2outputgui.cpp b/plugins/samplesink/bladerf2output/bladerf2outputgui.cpp index 50aa56a2a..7c16166ef 100644 --- a/plugins/samplesink/bladerf2output/bladerf2outputgui.cpp +++ b/plugins/samplesink/bladerf2output/bladerf2outputgui.cpp @@ -64,10 +64,10 @@ BladeRF2OutputGui::BladeRF2OutputGui(DeviceUISet *deviceUISet, QWidget* parent) ui->bandwidth->setColorMapper(ColorMapper(ColorMapper::GrayYellow)); ui->bandwidth->setValueRange(5, min/1000, max/1000); - m_sampleSink->getGlobalGainRange(min, max, step); - qDebug("BladeRF2OutputGui::BladeRF2OutputGui: getGlobalGainRange: [%d,%d] step: %d", min, max, step); - ui->gain->setMinimum((min-max)/1000); - ui->gain->setMaximum(0); + m_sampleSink->getGlobalGainRange(m_gainMin, m_gainMax, m_gainStep, m_gainScale); + qDebug("BladeRF2OutputGui::BladeRF2OutputGui: getGlobalGainRange: [%d,%d] step: %d scale: %f", m_gainMin, m_gainMax, m_gainStep, m_gainScale); + ui->gain->setMinimum(m_gainMin/m_gainStep); + ui->gain->setMaximum(m_gainMax/m_gainStep); ui->gain->setPageStep(1); ui->gain->setSingleStep(1); @@ -174,10 +174,9 @@ bool BladeRF2OutputGui::handleMessage(const Message& message) const BladeRF2Output::MsgConfigureBladeRF2& cfg = (BladeRF2Output::MsgConfigureBladeRF2&) message; m_settings = cfg.getSettings(); blockApplySettings(true); - int min, max, step; - m_sampleSink->getGlobalGainRange(min, max, step); - ui->gain->setMinimum((min-max)/1000); - ui->gain->setMaximum(0); + m_sampleSink->getGlobalGainRange(m_gainMin, m_gainMax, m_gainStep, m_gainScale); + ui->gain->setMinimum(m_gainMin/m_gainStep); + ui->gain->setMaximum(m_gainMax/m_gainStep); ui->gain->setPageStep(1); ui->gain->setSingleStep(1); displaySettings(); @@ -188,8 +187,12 @@ bool BladeRF2OutputGui::handleMessage(const Message& message) else if (BladeRF2Output::MsgReportGainRange::match(message)) { const BladeRF2Output::MsgReportGainRange& cfg = (BladeRF2Output::MsgReportGainRange&) message; - ui->gain->setMinimum((cfg.getMin()-cfg.getMax())/1000); - ui->gain->setMaximum(0); + m_gainMin = cfg.getMin(); + m_gainMax = cfg.getMax(); + m_gainStep = cfg.getStep(); + m_gainScale = cfg.getScale(); + ui->gain->setMinimum(m_gainMin/m_gainStep); + ui->gain->setMaximum(m_gainMax/m_gainStep); ui->gain->setSingleStep(1); ui->gain->setPageStep(1); @@ -294,8 +297,8 @@ void BladeRF2OutputGui::displaySettings() ui->bandwidth->setValue(m_settings.m_bandwidth / 1000); ui->interp->setCurrentIndex(m_settings.m_log2Interp); - ui->gainText->setText(tr("%1 dB").arg(m_settings.m_globalGain)); - ui->gain->setValue(m_settings.m_globalGain); + ui->gainText->setText(tr("%1 dB").arg(QString::number(m_settings.m_globalGain, 'f', 2))); + ui->gain->setValue(getGainValue(m_settings.m_globalGain)); ui->biasTee->setChecked(m_settings.m_biasTee); blockApplySettings(false); @@ -363,8 +366,9 @@ void BladeRF2OutputGui::on_interp_currentIndexChanged(int index) void BladeRF2OutputGui::on_gain_valueChanged(int value) { - ui->gainText->setText(tr("%1 dB").arg(value)); - m_settings.m_globalGain = value; + float displayableGain = getGainDB(value); + ui->gainText->setText(tr("%1 dB").arg(QString::number(displayableGain, 'f', 2))); + m_settings.m_globalGain = (int) displayableGain; sendSettings(); } @@ -452,3 +456,19 @@ void BladeRF2OutputGui::openDeviceSettingsDialog(const QPoint& p) sendSettings(); } + +float BladeRF2OutputGui::getGainDB(int gainValue) +{ + float gain = gainValue*m_gainStep*m_gainScale; + // qDebug("BladeRF2OutputGui::getGainDB: gainValue: %d m_gainMin: %d m_gainMax: %d m_gainStep: %d gain: %f", + // gainValue, m_gainMin, m_gainMax, m_gainStep, gain); + return gain; +} + +int BladeRF2OutputGui::getGainValue(float gainDB) +{ + int gain = (gainDB/m_gainScale) / m_gainStep; + // qDebug("BladeRF2OutputGui::getGainValue: gainDB: %f m_gainMin: %d m_gainMax: %d m_gainStep: %d gain: %d", + // gainDB, m_gainMin, m_gainMax, m_gainStep, gain); + return gain; +} diff --git a/plugins/samplesink/bladerf2output/bladerf2outputgui.h b/plugins/samplesink/bladerf2output/bladerf2outputgui.h index 2be21758e..c1ec08aa5 100644 --- a/plugins/samplesink/bladerf2output/bladerf2outputgui.h +++ b/plugins/samplesink/bladerf2output/bladerf2outputgui.h @@ -67,6 +67,10 @@ private: quint64 m_deviceCenterFrequency; //!< Center frequency in device int m_lastEngineState; MessageQueue m_inputMessageQueue; + int m_gainMin; + int m_gainMax; + int m_gainStep; + float m_gainScale; void blockApplySettings(bool block) { m_doApplySettings = !block; } void displaySettings(); @@ -75,6 +79,8 @@ private: void updateSampleRateAndFrequency(); void updateFrequencyLimits(); void setCenterFrequencySetting(uint64_t kHzValue); + float getGainDB(int gainValue); + int getGainValue(float gainDB); private slots: void handleInputMessages(); diff --git a/plugins/samplesink/bladerf2output/readme.md b/plugins/samplesink/bladerf2output/readme.md index cbb9c1f7c..661dfa507 100644 --- a/plugins/samplesink/bladerf2output/readme.md +++ b/plugins/samplesink/bladerf2output/readme.md @@ -8,11 +8,6 @@ This output sample sink plugin sends its samples to a [BladeRF2 device](https:// The plugin will be built only if the [BladeRF host library](https://github.com/Nuand/bladeRF) is installed in your system. If you build it from source and install it in a custom location say: `/opt/install/libbladeRF` you will have to add `-DBLADERF_DIR=/opt/install/libbladeRF/include` to the cmake command line. -Note that libbladeRF v2 with git tag 2018.10-rc1 should be used (official release) thus: - - - The FX3 firmware version should be v2.3.1 - - The FPGA image version should be v0.9.0 - The FPGA .rbf file should be copied to the folder where the `sdrangel` binary resides. You can download FPGA images from [here](https://www.nuand.com/fpga_images/) The BladeRF Host library is also provided by many Linux distributions (check its version) and is built in the SDRangel binary releases. @@ -117,7 +112,7 @@ The main samples buffer is based on the baseband sample rate and will introduce