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

BladeRF2 input: implemented LO soft correction

This commit is contained in:
f4exb 2018-09-30 10:26:53 +02:00
parent b0d17193d6
commit b5c4b532ae
11 changed files with 97 additions and 20 deletions

View File

@ -36,18 +36,21 @@ public:
public:
uint64_t getCenterFrequency() const { return m_centerFrequency; }
int getLOppmTenths() const { return m_LOppmTenths; }
int getFcPos() const { return m_fcPos; }
int getDevSampleRate() const { return m_devSampleRate; }
bool getRxElseTx() const { return m_rxElseTx; }
static MsgReportBuddyChange* create(
uint64_t centerFrequency,
int LOppmTenths,
int fcPos,
int devSampleRate,
bool rxElseTx)
{
return new MsgReportBuddyChange(
centerFrequency,
LOppmTenths,
fcPos,
devSampleRate,
rxElseTx);
@ -55,17 +58,20 @@ public:
private:
uint64_t m_centerFrequency; //!< Center frequency
int m_LOppmTenths; //!< LO soft correction in tenths of ppm
int m_fcPos; //!< Center frequency position
int m_devSampleRate; //!< device/host sample rate
bool m_rxElseTx; //!< tells which side initiated the message
MsgReportBuddyChange(
uint64_t centerFrequency,
int LOppmTenths,
int fcPos,
int devSampleRate,
bool rxElseTx) :
Message(),
m_centerFrequency(centerFrequency),
m_LOppmTenths(LOppmTenths),
m_fcPos(fcPos),
m_devSampleRate(devSampleRate),
m_rxElseTx(rxElseTx)

View File

@ -803,6 +803,7 @@ bool BladeRF2Output::applySettings(const BladeRF2OutputSettings& settings, bool
DeviceBladeRF2Shared::MsgReportBuddyChange *report = DeviceBladeRF2Shared::MsgReportBuddyChange::create(
settings.m_centerFrequency,
0,
0,
settings.m_devSampleRate,
false);
(*itSource)->getSampleSourceInputMessageQueue()->push(report);
@ -820,6 +821,7 @@ bool BladeRF2Output::applySettings(const BladeRF2OutputSettings& settings, bool
DeviceBladeRF2Shared::MsgReportBuddyChange *report = DeviceBladeRF2Shared::MsgReportBuddyChange::create(
settings.m_centerFrequency,
0,
0,
settings.m_devSampleRate,
false);
(*itSink)->getSampleSinkInputMessageQueue()->push(report);

View File

@ -67,8 +67,6 @@ BladeRF2OutputGui::BladeRF2OutputGui(DeviceUISet *deviceUISet, QWidget* parent)
ui->gain->setPageStep(1);
ui->gain->setSingleStep(1);
ui->label_decim->setText(QString::fromUtf8("I\u2191"));
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(500);

View File

@ -319,7 +319,7 @@
<item>
<widget class="QLabel" name="label_decim">
<property name="text">
<string>I</string>
<string>Int</string>
</property>
</widget>
</item>

View File

@ -538,6 +538,25 @@ void BladeRF2Input::setCenterFrequency(qint64 centerFrequency)
}
}
bool BladeRF2Input::setDeviceCenterFrequency(struct bladerf *dev, int requestedChannel, quint64 freq_hz)
{
qint64 df = ((qint64)freq_hz * m_settings.m_LOppmTenths) / 10000000LL;
freq_hz += df;
int status = bladerf_set_frequency(dev, BLADERF_CHANNEL_RX(requestedChannel), freq_hz);
if (status < 0) {
qWarning("BladeRF2Input::setDeviceCenterFrequency: bladerf_set_frequency(%lld) failed: %s",
freq_hz, bladerf_strerror(status));
return false;
}
else
{
qDebug("BladeRF2Input::setDeviceCenterFrequency: bladerf_set_frequency(%lld)", freq_hz);
return true;
}
}
void BladeRF2Input::getFrequencyRange(uint64_t& min, uint64_t& max, int& step)
{
if (m_deviceShared.m_dev) {
@ -595,9 +614,10 @@ bool BladeRF2Input::handleMessage(const Message& message)
{
int requestedChannel = m_deviceAPI->getItemIndex();
if (report.getRxElseTx()) // Rx buddy change: check for: frequency, gain mode and value, bias tee, sample rate, bandwidth
if (report.getRxElseTx()) // Rx buddy change: check for: frequency, LO correction, gain mode and value, bias tee, sample rate, bandwidth
{
settings.m_devSampleRate = report.getDevSampleRate();
settings.m_LOppmTenths = report.getLOppmTenths();
settings.m_centerFrequency = report.getCenterFrequency();
settings.m_fcPos = (BladeRF2InputSettings::fcPos_t) report.getFcPos();
@ -785,6 +805,7 @@ bool BladeRF2Input::applySettings(const BladeRF2InputSettings& settings, bool fo
}
if ((m_settings.m_centerFrequency != settings.m_centerFrequency)
|| (m_settings.m_LOppmTenths != settings.m_LOppmTenths)
|| (m_settings.m_devSampleRate != settings.m_devSampleRate)
|| (m_settings.m_fcPos != settings.m_fcPos)
|| (m_settings.m_log2Decim != settings.m_log2Decim) || force)
@ -801,16 +822,8 @@ bool BladeRF2Input::applySettings(const BladeRF2InputSettings& settings, bool fo
if (dev != 0)
{
int status = bladerf_set_frequency(dev, BLADERF_CHANNEL_RX(requestedChannel), deviceCenterFrequency);
if (status < 0) {
qWarning("BladeRF2Input::applySettings: bladerf_set_frequency(%lld) failed: %s",
settings.m_centerFrequency, bladerf_strerror(status));
}
else
if (setDeviceCenterFrequency(dev, requestedChannel, deviceCenterFrequency))
{
qDebug("BladeRF2Input::applySettings: bladerf_set_frequency(%lld)", settings.m_centerFrequency);
if (getMessageQueueToGUI())
{
int min, max, step;
@ -882,6 +895,7 @@ bool BladeRF2Input::applySettings(const BladeRF2InputSettings& settings, bool fo
{
DeviceBladeRF2Shared::MsgReportBuddyChange *report = DeviceBladeRF2Shared::MsgReportBuddyChange::create(
settings.m_centerFrequency,
settings.m_LOppmTenths,
(int) settings.m_fcPos,
settings.m_devSampleRate,
true);
@ -899,6 +913,7 @@ bool BladeRF2Input::applySettings(const BladeRF2InputSettings& settings, bool fo
{
DeviceBladeRF2Shared::MsgReportBuddyChange *report = DeviceBladeRF2Shared::MsgReportBuddyChange::create(
settings.m_centerFrequency,
settings.m_LOppmTenths,
(int) settings.m_fcPos,
settings.m_devSampleRate,
true);
@ -910,6 +925,7 @@ bool BladeRF2Input::applySettings(const BladeRF2InputSettings& settings, bool fo
qDebug() << "BladeRF2Input::applySettings: "
<< " m_centerFrequency: " << m_settings.m_centerFrequency << " Hz"
<< " m_LOppmTenths: " << m_settings.m_LOppmTenths
<< " m_bandwidth: " << m_settings.m_bandwidth
<< " m_log2Decim: " << m_settings.m_log2Decim
<< " m_fcPos: " << m_settings.m_fcPos

View File

@ -29,6 +29,7 @@ class DeviceSourceAPI;
class BladeRF2InputThread;
class FileRecord;
struct bladerf_gain_modes;
struct bladerf;
class BladeRF2Input : public DeviceSampleSource
{
@ -191,6 +192,7 @@ private:
BladeRF2InputThread *findThread();
void moveThreadToBuddy();
bool applySettings(const BladeRF2InputSettings& settings, bool force = false);
bool setDeviceCenterFrequency(struct bladerf *dev, int requestedChannel, quint64 freq_hz);
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const BladeRF2InputSettings& settings);
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
};

View File

@ -229,6 +229,8 @@ void BladeRF2InputGui::displaySettings()
blockApplySettings(true);
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
ui->LOppm->setValue(m_settings.m_LOppmTenths);
ui->LOppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
ui->sampleRate->setValue(m_settings.m_devSampleRate);
ui->bandwidth->setValue(m_settings.m_bandwidth / 1000);
@ -262,6 +264,13 @@ void BladeRF2InputGui::on_centerFrequency_changed(quint64 value)
sendSettings();
}
void BladeRF2InputGui::on_LOppm_valueChanged(int value)
{
ui->LOppmText->setText(QString("%1").arg(QString::number(value/10.0, 'f', 1)));
m_settings.m_LOppmTenths = value;
sendSettings();
}
void BladeRF2InputGui::on_sampleRate_changed(quint64 value)
{
m_settings.m_devSampleRate = value;

View File

@ -74,6 +74,7 @@ private:
private slots:
void handleInputMessages();
void on_centerFrequency_changed(quint64 value);
void on_LOppm_valueChanged(int value);
void on_sampleRate_changed(quint64 value);
void on_dcOffset_toggled(bool checked);
void on_iqImbalance_toggled(bool checked);

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>350</width>
<height>200</height>
<height>220</height>
</rect>
</property>
<property name="sizePolicy">
@ -19,7 +19,7 @@
<property name="minimumSize">
<size>
<width>350</width>
<height>200</height>
<height>220</height>
</size>
</property>
<property name="font">
@ -174,11 +174,50 @@
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<layout class="QHBoxLayout" name="LOppm_layout">
<item>
<widget class="QLabel" name="LOppmLabel">
<property name="text">
<string>LO ppm</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="LOppm">
<property name="toolTip">
<string>Local Oscillator ppm correction</string>
</property>
<property name="minimum">
<number>-20</number>
</property>
<property name="maximum">
<number>20</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="LOppmText">
<property name="minimumSize">
<size>
<width>26</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>-0.0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_corr">

View File

@ -26,6 +26,7 @@ BladeRF2InputSettings::BladeRF2InputSettings()
void BladeRF2InputSettings::resetToDefaults()
{
m_centerFrequency = 435000*1000;
m_LOppmTenths = 0;
m_devSampleRate = 3072000;
m_bandwidth = 1500000;
m_gainMode = 0;
@ -51,6 +52,7 @@ QByteArray BladeRF2InputSettings::serialize() const
s.writeS32(7, (int) m_fcPos);
s.writeBool(8, m_dcBlock);
s.writeBool(9, m_iqCorrection);
s.writeS32(10, m_LOppmTenths);
return s.final();
}
@ -79,6 +81,7 @@ bool BladeRF2InputSettings::deserialize(const QByteArray& data)
m_fcPos = (fcPos_t) intval;
d.readBool(8, &m_dcBlock);
d.readBool(9, &m_iqCorrection);
d.readS32(10, &m_LOppmTenths);
return true;
}

View File

@ -29,6 +29,7 @@ struct BladeRF2InputSettings {
} fcPos_t;
quint64 m_centerFrequency;
qint32 m_LOppmTenths;
qint32 m_devSampleRate;
qint32 m_bandwidth;
int m_gainMode;