1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-29 19:28:47 -05:00

Merge pull request #1790 from srcejon/rtlsdr_e4k

Fix RTLSDR E4000 gain and bandwidth settings and add RTLSDRBlog V4 support
This commit is contained in:
Edouard Griffiths 2023-08-27 16:27:44 +02:00 committed by GitHub
commit 57fb72130d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 10 deletions

View File

@ -22,7 +22,7 @@ set(MIRISDR_TAG "v2.0.0")
set(LIBSIGMF_TAG "new-namespaces") set(LIBSIGMF_TAG "new-namespaces")
set(PTHREADS4W_TAG "Version-2-11-0-release") set(PTHREADS4W_TAG "Version-2-11-0-release")
set(RTLSDR_TAG 5e73f90f1d85d8db2e583f3dbf1cff052d71d59b) set(RTLSDR_TAG 1261fbb285297da08f4620b18871b6d6d9ec2a7b)
set(RTLSDR_UDEV OFF) set(RTLSDR_UDEV OFF)
set(SOAPYSDR_TAG "soapy-sdr-0.7.1") set(SOAPYSDR_TAG "soapy-sdr-0.7.1")
set(SOAPYSDR_SDRPLAY_TAG "soapy-sdrplay-0.2.0") set(SOAPYSDR_SDRPLAY_TAG "soapy-sdrplay-0.2.0")
@ -1091,7 +1091,11 @@ if (WIN32 OR APPLE)
endif () endif ()
# Disable pkg-config to allow LIBUSB_INCLUDE_DIRS to be used # Disable pkg-config to allow LIBUSB_INCLUDE_DIRS to be used
set(DISABLE_PKGCONFIG "-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=ON") set(DISABLE_PKGCONFIG "-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=ON")
# needs libusb # If we want to use https://github.com/librtlsdr/librtlsdr instead of https://github.com/osmocom/rtl-sdr.git
# - Don't use DISABLE_PKGCONFIG
# - Use -DLIBUSB_INCLUDE_DIR instead of -DLIBUSB_INCLUDE_DIRS
# - Build target is rtl_sdr rather than rtlsdr
# - Use tag development otherwise it will not build with MSVC
ExternalProject_Add(rtlsdr ExternalProject_Add(rtlsdr
GIT_REPOSITORY https://github.com/osmocom/rtl-sdr.git GIT_REPOSITORY https://github.com/osmocom/rtl-sdr.git
GIT_TAG ${RTLSDR_TAG} GIT_TAG ${RTLSDR_TAG}

View File

@ -68,6 +68,14 @@ RTLSDRGui::RTLSDRGui(DeviceUISet *deviceUISet, QWidget* parent) :
m_gains = m_sampleSource->getGains(); m_gains = m_sampleSource->getGains();
displayGains(); displayGains();
rtlsdr_tuner tunerType = m_sampleSource->getTunerType();
// Disable widgets not relevent for this tuner
bool offsetTuningEnabled = (tunerType != RTLSDR_TUNER_R820T) && (tunerType != RTLSDR_TUNER_R828D);
if (!offsetTuningEnabled) {
ui->offsetTuning->setEnabled(false);
}
ui->tunerType->setText("Tuner: " + m_sampleSource->getTunerName());
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
m_sampleSource->setMessageQueueToGUI(&m_inputMessageQueue); m_sampleSource->setMessageQueueToGUI(&m_inputMessageQueue);
} }
@ -200,7 +208,7 @@ void RTLSDRGui::updateFrequencyLimits()
{ {
// values in kHz // values in kHz
qint64 deltaFrequency = m_settings.m_transverterMode ? m_settings.m_transverterDeltaFrequency/1000 : 0; qint64 deltaFrequency = m_settings.m_transverterMode ? m_settings.m_transverterDeltaFrequency/1000 : 0;
qint64 minLimit = (m_settings.m_noModMode ? RTLSDRInput::frequencyLowRangeMin : RTLSDRInput::frequencyHighRangeMin) + deltaFrequency; qint64 minLimit = (m_settings.m_noModMode ? RTLSDRInput::frequencyLowRangeMin : m_sampleSource->m_frequencyHighRangeMin) + deltaFrequency;
qint64 maxLimit = (m_settings.m_noModMode ? RTLSDRInput::frequencyLowRangeMax : RTLSDRInput::frequencyHighRangeMax) + deltaFrequency; qint64 maxLimit = (m_settings.m_noModMode ? RTLSDRInput::frequencyLowRangeMax : RTLSDRInput::frequencyHighRangeMax) + deltaFrequency;
if (m_settings.m_transverterMode) if (m_settings.m_transverterMode)
@ -474,6 +482,7 @@ void RTLSDRGui::on_checkBox_stateChanged(int state)
if (state == Qt::Checked) if (state == Qt::Checked)
{ {
ui->gain->setEnabled(false); ui->gain->setEnabled(false);
ui->offsetTuning->setEnabled(false);
m_settings.m_noModMode = true; m_settings.m_noModMode = true;
updateFrequencyLimits(); updateFrequencyLimits();
ui->centerFrequency->setValue(7000); ui->centerFrequency->setValue(7000);
@ -482,6 +491,7 @@ void RTLSDRGui::on_checkBox_stateChanged(int state)
else else
{ {
ui->gain->setEnabled(true); ui->gain->setEnabled(true);
ui->offsetTuning->setEnabled(true);
m_settings.m_noModMode = false; m_settings.m_noModMode = false;
updateFrequencyLimits(); updateFrequencyLimits();
ui->centerFrequency->setValue(434000); ui->centerFrequency->setValue(434000);

View File

@ -500,12 +500,12 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_direct"> <layout class="QHBoxLayout" name="horizontalLayout_direct">
<item> <item>
<widget class="QCheckBox" name="checkBox"> <widget class="QLabel" name="tunerType">
<property name="toolTip"> <property name="toolTip">
<string>RTLSDR special direct sampling mode (HF Bands)</string> <string>Tuner type</string>
</property> </property>
<property name="text"> <property name="text">
<string>No-mod DS</string> <string>Tuner: Unknown</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -522,6 +522,16 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="toolTip">
<string>RTLSDR special direct sampling mode (HF Bands)</string>
</property>
<property name="text">
<string>DS</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="offsetTuning"> <widget class="QCheckBox" name="offsetTuning">
<property name="toolTip"> <property name="toolTip">

View File

@ -44,7 +44,6 @@ MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgStartStop, Message)
const quint64 RTLSDRInput::frequencyLowRangeMin = 0UL; const quint64 RTLSDRInput::frequencyLowRangeMin = 0UL;
const quint64 RTLSDRInput::frequencyLowRangeMax = 275000UL; const quint64 RTLSDRInput::frequencyLowRangeMax = 275000UL;
const quint64 RTLSDRInput::frequencyHighRangeMin = 24000UL;
const quint64 RTLSDRInput::frequencyHighRangeMax = 2400000UL; const quint64 RTLSDRInput::frequencyHighRangeMax = 2400000UL;
const int RTLSDRInput::sampleRateLowRangeMin = 225001; const int RTLSDRInput::sampleRateLowRangeMin = 225001;
const int RTLSDRInput::sampleRateLowRangeMax = 300000; const int RTLSDRInput::sampleRateLowRangeMax = 300000;
@ -57,6 +56,7 @@ RTLSDRInput::RTLSDRInput(DeviceAPI *deviceAPI) :
m_dev(0), m_dev(0),
m_rtlSDRThread(nullptr), m_rtlSDRThread(nullptr),
m_deviceDescription("RTLSDR"), m_deviceDescription("RTLSDR"),
m_tunerType(RTLSDR_TUNER_UNKNOWN),
m_running(false) m_running(false)
{ {
m_sampleFifo.setLabel(m_deviceDescription); m_sampleFifo.setLabel(m_deviceDescription);
@ -155,9 +155,17 @@ bool RTLSDRInput::openDevice()
return false; return false;
} }
qInfo("RTLSDRInput::openDevice: open: %s %s, SN: %s", vendor, product, serial); m_tunerType = rtlsdr_get_tuner_type(m_dev);
qInfo("RTLSDRInput::openDevice: open: %s %s, SN: %s Tuner: %s", vendor, product, serial, qPrintable(getTunerName()));
m_deviceDescription = QString("%1 (SN %2)").arg(product).arg(serial); m_deviceDescription = QString("%1 (SN %2)").arg(product).arg(serial);
if ((vendor == QStringLiteral("RTLSDRBlog")) && (product == QStringLiteral("Blog V4"))) {
m_frequencyHighRangeMin = 0;
} else {
m_frequencyHighRangeMin = 24000UL;
}
if ((res = rtlsdr_set_sample_rate(m_dev, 1152000)) < 0) if ((res = rtlsdr_set_sample_rate(m_dev, 1152000)) < 0)
{ {
qCritical("RTLSDRInput::openDevice: could not set sample rate: 1024k S/s"); qCritical("RTLSDRInput::openDevice: could not set sample rate: 1024k S/s");
@ -504,7 +512,8 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, const QList<QStr
} }
} }
if (settingsKeys.contains("offsetTuning") || force) // Reapply offset_tuning setting if bandwidth is changed, otherwise frequency response of filter looks wrong on E4000
if (settingsKeys.contains("offsetTuning") || settingsKeys.contains("rfBandwidth") || force)
{ {
if (m_dev != 0) if (m_dev != 0)
{ {
@ -520,6 +529,11 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, const QList<QStr
{ {
if(m_dev != 0) if(m_dev != 0)
{ {
// Nooelec E4000 SDRs appear to require tuner_gain_mode to be reset to manual before
// each call to set_tuner_gain, otherwise tuner AGC seems to be reenabled
if (rtlsdr_set_tuner_gain_mode(m_dev, 1) < 0) {
qCritical("RTLSDRInput::applySettings: error setting tuner gain mode to manual");
}
qDebug() << "Set tuner gain " << settings.m_gain; qDebug() << "Set tuner gain " << settings.m_gain;
if (rtlsdr_set_tuner_gain(m_dev, settings.m_gain) != 0) { if (rtlsdr_set_tuner_gain(m_dev, settings.m_gain) != 0) {
qCritical("RTLSDRInput::applySettings: rtlsdr_set_tuner_gain() failed"); qCritical("RTLSDRInput::applySettings: rtlsdr_set_tuner_gain() failed");
@ -566,6 +580,17 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, const QList<QStr
return true; return true;
} }
QString RTLSDRInput::getTunerName() const
{
const static QStringList names = {"Unknown", "E4000", "FC0012", "FC0013", "FC2580", "R820T", "R828D"};
if ((int) m_tunerType <= names.size()) {
return names[(int) m_tunerType];
} else {
return names[0];
}
}
void RTLSDRInput::set_ds_mode(int on) void RTLSDRInput::set_ds_mode(int on)
{ {
rtlsdr_set_direct_sampling(m_dev, on); rtlsdr_set_direct_sampling(m_dev, on);

View File

@ -133,11 +133,13 @@ public:
SWGSDRangel::SWGDeviceSettings& response); SWGSDRangel::SWGDeviceSettings& response);
const std::vector<int>& getGains() const { return m_gains; } const std::vector<int>& getGains() const { return m_gains; }
rtlsdr_tuner getTunerType() const { return m_tunerType; }
QString getTunerName() const;
void set_ds_mode(int on); void set_ds_mode(int on);
static const quint64 frequencyLowRangeMin; static const quint64 frequencyLowRangeMin;
static const quint64 frequencyLowRangeMax; static const quint64 frequencyLowRangeMax;
static const quint64 frequencyHighRangeMin; quint64 m_frequencyHighRangeMin;
static const quint64 frequencyHighRangeMax; static const quint64 frequencyHighRangeMax;
static const int sampleRateLowRangeMin; static const int sampleRateLowRangeMin;
static const int sampleRateLowRangeMax; static const int sampleRateLowRangeMax;
@ -152,6 +154,7 @@ private:
RTLSDRThread* m_rtlSDRThread; RTLSDRThread* m_rtlSDRThread;
QString m_deviceDescription; QString m_deviceDescription;
std::vector<int> m_gains; std::vector<int> m_gains;
rtlsdr_tuner m_tunerType;
bool m_running; bool m_running;
QNetworkAccessManager *m_networkManager; QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest; QNetworkRequest m_networkRequest;