1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 00:18:37 -05:00

BladerRF2 input support. Fixed gain modes handling. Cosmetic changes

This commit is contained in:
f4exb 2018-09-26 01:54:23 +02:00
parent 81ad05cb64
commit 4634fb481d
5 changed files with 67 additions and 50 deletions

View File

@ -50,6 +50,19 @@ BladeRF2Input::BladeRF2Input(DeviceSourceAPI *deviceAPI) :
{ {
openDevice(); openDevice();
if (m_deviceShared.m_dev)
{
const bladerf_gain_modes *modes = 0;
int nbModes = m_deviceShared.m_dev->getGainModesRx(&modes);
if (modes)
{
for (int i = 0; i < nbModes; i++) {
m_gainModes.push_back(GainMode{QString(modes[i].name), modes[i].mode});
}
}
}
m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID()));
m_deviceAPI->addSink(m_fileSink); m_deviceAPI->addSink(m_fileSink);
} }
@ -510,19 +523,6 @@ void BladeRF2Input::getGlobalGainRange(int& min, int& max, int& step)
} }
} }
const bladerf_gain_modes *BladeRF2Input::getGainModes(int& nbGains)
{
const bladerf_gain_modes *modes = 0;
if (m_deviceShared.m_dev) {
nbGains = m_deviceShared.m_dev->getGainModesRx(&modes);
} else {
nbGains = 0;
}
return modes;
}
bool BladeRF2Input::handleMessage(const Message& message) bool BladeRF2Input::handleMessage(const Message& message)
{ {
if (MsgConfigureBladeRF2::match(message)) if (MsgConfigureBladeRF2::match(message))
@ -1025,17 +1025,14 @@ void BladeRF2Input::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& respo
response.getBladeRf2InputReport()->setGainModes(new QList<SWGSDRangel::SWGNamedEnum*>); response.getBladeRf2InputReport()->setGainModes(new QList<SWGSDRangel::SWGNamedEnum*>);
int nbModes; const std::vector<GainMode>& modes = getGainModes();
const bladerf_gain_modes *modes = getGainModes(nbModes); std::vector<GainMode>::const_iterator it = modes.begin();
if (modes) for (; it != modes.end(); ++it)
{ {
for (int i = 0; i < nbModes; modes++) response.getBladeRf2InputReport()->getGainModes()->append(new SWGSDRangel::SWGNamedEnum);
{ response.getBladeRf2InputReport()->getGainModes()->back()->setName(new QString(it->m_name));
response.getBladeRf2InputReport()->getGainModes()->append(new SWGSDRangel::SWGNamedEnum); response.getBladeRf2InputReport()->getGainModes()->back()->setValue(it->m_value);
response.getBladeRf2InputReport()->getGainModes()->back()->setName(new QString(modes[i].name));
response.getBladeRf2InputReport()->getGainModes()->back()->setValue(modes[i].mode);
}
} }
} }
} }

View File

@ -119,6 +119,12 @@ public:
{} {}
}; };
struct GainMode
{
QString m_name;
int m_value;
};
BladeRF2Input(DeviceSourceAPI *deviceAPI); BladeRF2Input(DeviceSourceAPI *deviceAPI);
virtual ~BladeRF2Input(); virtual ~BladeRF2Input();
virtual void destroy(); virtual void destroy();
@ -142,7 +148,7 @@ public:
void getSampleRateRange(int& min, int& max, int& step); void getSampleRateRange(int& min, int& max, int& step);
void getBandwidthRange(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);
const bladerf_gain_modes *getGainModes(int& nbGains); const std::vector<GainMode>& getGainModes() { return m_gainModes; }
virtual bool handleMessage(const Message& message); virtual bool handleMessage(const Message& message);
@ -178,8 +184,7 @@ private:
DeviceBladeRF2Shared m_deviceShared; DeviceBladeRF2Shared m_deviceShared;
BladeRF2InputThread *m_thread; BladeRF2InputThread *m_thread;
FileRecord *m_fileSink; //!< File sink to record device I/Q output FileRecord *m_fileSink; //!< File sink to record device I/Q output
bladerf_gain_modes **m_gainModes; std::vector<GainMode> m_gainModes;
int m_nbGainModes;
bool openDevice(); bool openDevice();
void closeDevice(); void closeDevice();

View File

@ -56,27 +56,27 @@ BladeRF2InputGui::BladeRF2InputGui(DeviceUISet *deviceUISet, QWidget* parent) :
m_sampleSource->getBandwidthRange(min, max, step); m_sampleSource->getBandwidthRange(min, max, step);
ui->bandwidth->setColorMapper(ColorMapper(ColorMapper::GrayYellow)); ui->bandwidth->setColorMapper(ColorMapper(ColorMapper::GrayYellow));
ui->bandwidth->setValueRange(6, min/1000, max/1000); ui->bandwidth->setValueRange(5, min/1000, max/1000);
m_gainModes = m_sampleSource->getGainModes(m_nbGainModes); const std::vector<BladeRF2Input::GainMode>& modes = m_sampleSource->getGainModes();
std::vector<BladeRF2Input::GainMode>::const_iterator it = modes.begin();
if (m_gainModes) ui->gainMode->blockSignals(true);
{
ui->gainMode->blockSignals(true);
for (int i = 0; i < m_nbGainModes; i++) { for (; it != modes.end(); ++it) {
ui->gainMode->addItem(tr("%1").arg(m_gainModes[i].name)); ui->gainMode->addItem(it->m_name);
}
ui->gainMode->blockSignals(false);
} }
ui->gainMode->blockSignals(false);
m_sampleSource->getGlobalGainRange(min, max, step); m_sampleSource->getGlobalGainRange(min, max, step);
ui->gain->setMinimum(min); ui->gain->setMinimum(min);
ui->gain->setMaximum(max); ui->gain->setMaximum(max);
ui->gain->setPageStep(step); ui->gain->setPageStep(step);
ui->gain->setSingleStep(step); ui->gain->setSingleStep(step);
ui->label_decim->setText(QString::fromUtf8("D\u2193"));
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware())); connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus())); connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(500); m_statusTimer.start(500);
@ -238,7 +238,7 @@ void BladeRF2InputGui::displaySettings()
ui->decim->setCurrentIndex(m_settings.m_log2Decim); ui->decim->setCurrentIndex(m_settings.m_log2Decim);
ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos); ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos);
ui->gainText->setText(tr("%1").arg(m_settings.m_globalGain)); ui->gainText->setText(tr("%1 dB").arg(m_settings.m_globalGain));
ui->gain->setValue(m_settings.m_globalGain); ui->gain->setValue(m_settings.m_globalGain);
blockApplySettings(false); blockApplySettings(false);
@ -304,16 +304,20 @@ void BladeRF2InputGui::on_fcPos_currentIndexChanged(int index)
void BladeRF2InputGui::on_gainMode_currentIndexChanged(int index) void BladeRF2InputGui::on_gainMode_currentIndexChanged(int index)
{ {
if (index < m_nbGainModes) const std::vector<BladeRF2Input::GainMode>& modes = m_sampleSource->getGainModes();
unsigned int uindex = index < 0 ? 0 : (unsigned int) index;
if (uindex < modes.size())
{ {
m_settings.m_gainMode = m_gainModes[index].mode; BladeRF2Input::GainMode mode = modes[index];
m_settings.m_gainMode = mode.m_value;
sendSettings(); sendSettings();
} }
} }
void BladeRF2InputGui::on_gain_valueChanged(int value) void BladeRF2InputGui::on_gain_valueChanged(int value)
{ {
ui->gainText->setText(tr("%1").arg(value)); ui->gainText->setText(tr("%1 dB").arg(value));
m_settings.m_globalGain = value; m_settings.m_globalGain = value;
sendSettings(); sendSettings();
} }

View File

@ -65,8 +65,6 @@ private:
quint64 m_deviceCenterFrequency; //!< Center frequency in device quint64 m_deviceCenterFrequency; //!< Center frequency in device
int m_lastEngineState; int m_lastEngineState;
MessageQueue m_inputMessageQueue; MessageQueue m_inputMessageQueue;
const struct bladerf_gain_modes *m_gainModes;
int m_nbGainModes;
void displaySettings(); void displaySettings();
void sendSettings(); void sendSettings();

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>310</width> <width>350</width>
<height>250</height> <height>200</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -18,8 +18,8 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>310</width> <width>350</width>
<height>250</height> <height>200</height>
</size> </size>
</property> </property>
<property name="font"> <property name="font">
@ -265,6 +265,9 @@
<property name="cursor"> <property name="cursor">
<cursorShape>PointingHandCursor</cursorShape> <cursorShape>PointingHandCursor</cursorShape>
</property> </property>
<property name="toolTip">
<string>RF bandwidth</string>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="7"> <item row="0" column="7">
@ -330,6 +333,9 @@
<property name="cursor"> <property name="cursor">
<cursorShape>PointingHandCursor</cursorShape> <cursorShape>PointingHandCursor</cursorShape>
</property> </property>
<property name="toolTip">
<string>Device sample rate</string>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -384,7 +390,7 @@
<item> <item>
<widget class="QLabel" name="label_decim"> <widget class="QLabel" name="label_decim">
<property name="text"> <property name="text">
<string>Dec</string> <string>D</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -442,19 +448,26 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout_decim" columnstretch="0,0,0,0,0,0"> <layout class="QGridLayout" name="gridLayout_decim" columnstretch="0,0,0,0">
<property name="spacing"> <property name="spacing">
<number>3</number> <number>3</number>
</property> </property>
<item row="0" column="2"> <item row="0" column="2">
<widget class="QSlider" name="gain"> <widget class="QSlider" name="gain">
<property name="toolTip">
<string>Gain value</string>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="gainMode"/> <widget class="QComboBox" name="gainMode">
<property name="toolTip">
<string>Gain mode</string>
</property>
</widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="gainLabel"> <widget class="QLabel" name="gainLabel">
@ -467,12 +480,12 @@
<widget class="QLabel" name="gainText"> <widget class="QLabel" name="gainText">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>25</width> <width>45</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>000</string> <string>000 dB</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>