BladeRF2: fixed global gain setting. Fixes issue #630

This commit is contained in:
f4exb 2020-09-14 23:04:35 +02:00
parent 8026686b1f
commit 54883699d4
12 changed files with 127 additions and 70 deletions

View File

@ -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);
}
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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();

View File

@ -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
<h3>9: Gain control</h3>
Use this slider to adjust gain in manual mode. The gain varies from -89 to 0 dB in 1 dB steps. Thus this is in fact an attenuator
Use this slider to adjust gain in manual mode. The gain varies from -23.75 to 66 dB in 0.25 dB steps. However only integer values are taken into account.
<h3>10: Bias tee control</h3>

View File

@ -591,10 +591,10 @@ void BladeRF2Input::getBandwidthRange(int& min, int& max, int& step)
}
}
void BladeRF2Input::getGlobalGainRange(int& min, int& max, int& step)
void BladeRF2Input::getGlobalGainRange(int& min, int& max, int& step, float& scale)
{
if (m_deviceShared.m_dev) {
m_deviceShared.m_dev->getGlobalGainRangeRx(min, max, step);
m_deviceShared.m_dev->getGlobalGainRangeRx(min, max, step, scale);
}
}
@ -681,8 +681,9 @@ bool BladeRF2Input::handleMessage(const Message& message)
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);
}
}
@ -884,8 +885,9 @@ bool BladeRF2Input::applySettings(const BladeRF2InputSettings& settings, bool fo
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);
}
}
@ -1153,6 +1155,7 @@ void BladeRF2Input::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& respo
if (device)
{
int min, max, step;
float scale;
uint64_t f_min, f_max;
device->getBandwidthRangeRx(min, max, step);
@ -1169,7 +1172,7 @@ void BladeRF2Input::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& respo
response.getBladeRf2InputReport()->getFrequencyRange()->setMax(f_max);
response.getBladeRf2InputReport()->getFrequencyRange()->setStep(step);
device->getGlobalGainRangeRx(min, max, step);
device->getGlobalGainRangeRx(min, max, step, scale);
response.getBladeRf2InputReport()->setGlobalGainRange(new SWGSDRangel::SWGRange);
response.getBladeRf2InputReport()->getGlobalGainRange()->setMin(min);

View File

@ -87,21 +87,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)
{}
};
@ -134,7 +137,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);
const std::vector<GainMode>& getGainModes() { return m_gainModes; }
virtual bool handleMessage(const Message& message);

View File

@ -74,11 +74,11 @@ BladeRF2InputGui::BladeRF2InputGui(DeviceUISet *deviceUISet, QWidget* parent) :
ui->gainMode->blockSignals(false);
m_sampleSource->getGlobalGainRange(min, max, step);
ui->gain->setMinimum(min);
ui->gain->setMaximum(max);
ui->gain->setPageStep(step);
ui->gain->setSingleStep(step);
m_sampleSource->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);
ui->label_decim->setText(QString::fromUtf8("D\u2193"));
@ -187,12 +187,11 @@ bool BladeRF2InputGui::handleMessage(const Message& message)
const BladeRF2Input::MsgConfigureBladeRF2& cfg = (BladeRF2Input::MsgConfigureBladeRF2&) message;
m_settings = cfg.getSettings();
blockApplySettings(true);
int min, max, step;
m_sampleSource->getGlobalGainRange(min, max, step);
ui->gain->setMinimum(min);
ui->gain->setMaximum(max);
ui->gain->setPageStep(step);
ui->gain->setSingleStep(step);
m_sampleSource->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();
blockApplySettings(false);
@ -201,10 +200,14 @@ bool BladeRF2InputGui::handleMessage(const Message& message)
else if (BladeRF2Input::MsgReportGainRange::match(message))
{
const BladeRF2Input::MsgReportGainRange& cfg = (BladeRF2Input::MsgReportGainRange&) message;
ui->gain->setMinimum(cfg.getMin());
ui->gain->setMaximum(cfg.getMax());
ui->gain->setSingleStep(cfg.getStep());
ui->gain->setPageStep(cfg.getStep());
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->setPageStep(1);
ui->gain->setSingleStep(1);
return true;
}
@ -327,8 +330,8 @@ void BladeRF2InputGui::displaySettings()
ui->decim->setCurrentIndex(m_settings.m_log2Decim);
ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos);
ui->gainMode->setCurrentIndex(m_settings.m_gainMode);
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));
if (m_settings.m_gainMode == BLADERF_GAIN_MANUAL) {
ui->gain->setEnabled(true);
@ -446,8 +449,9 @@ void BladeRF2InputGui::on_gainMode_currentIndexChanged(int index)
void BladeRF2InputGui::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();
}
@ -541,3 +545,19 @@ void BladeRF2InputGui::openDeviceSettingsDialog(const QPoint& p)
sendSettings();
}
float BladeRF2InputGui::getGainDB(int gainValue)
{
float gain = gainValue*m_gainStep*m_gainScale;
// qDebug("BladeRF2InputGui::getGainDB: gainValue: %d m_gainMin: %d m_gainMax: %d m_gainStep: %d m_gainScale: %f gain: %f",
// gainValue, m_gainMin, m_gainMax, m_gainStep, m_gainScale, gain);
return gain;
}
int BladeRF2InputGui::getGainValue(float gainDB)
{
int gain = (gainDB/m_gainScale) / m_gainStep;
// qDebug("BladeRF2InputGui::getGainValue: gainDB: %f m_gainMin: %d m_gainMax: %d m_gainStep: %d m_gainScale: %f gain: %d",
// gainDB, m_gainMin, m_gainMax, m_gainStep, m_gainScale, gain);
return gain;
}

View File

@ -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 displaySettings();
void displaySampleRate();
@ -75,6 +79,8 @@ private:
void updateSampleRateAndFrequency();
void updateFrequencyLimits();
void setCenterFrequencySetting(uint64_t kHzValue);
float getGainDB(int gainValue);
int getGainValue(float gainDB);
void blockApplySettings(bool block);
private slots:

View File

@ -8,11 +8,6 @@ This input sample source plugin gets its samples from a [BladeRF 2.0 micro devic
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_INCLUDE_DIR=/opt/install/libbladeRF` 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.