mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-03 06:24:48 -04:00
BladeRF2: fixed global gain setting. Fixes issue #630
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user