From 43a1e0e14bba1f232aaab29d0d02ba0be5d333d2 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 23 Sep 2017 19:15:56 +0200 Subject: [PATCH] Transverter frequency shift logic. Implemented it for RTLSDR --- plugins/samplesource/rtlsdr/rtlsdrgui.cpp | 41 +++++++++++++---- plugins/samplesource/rtlsdr/rtlsdrgui.h | 2 + plugins/samplesource/rtlsdr/rtlsdrgui.ui | 2 +- plugins/samplesource/rtlsdr/rtlsdrinput.cpp | 45 +++++++++++++++---- plugins/samplesource/rtlsdr/rtlsdrinput.h | 9 ++++ plugins/samplesource/rtlsdr/rtlsdrplugin.cpp | 2 +- .../samplesource/rtlsdr/rtlsdrsettings.cpp | 9 ++++ plugins/samplesource/rtlsdr/rtlsdrsettings.h | 3 ++ sdrbase/gui/transverterbutton.cpp | 2 +- sdrbase/gui/transverterdialog.cpp | 4 +- 10 files changed, 97 insertions(+), 22 deletions(-) diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp index 6c2b84309..574d40b40 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp @@ -28,6 +28,7 @@ #include "dsp/dspengine.h" #include "dsp/dspcommands.h" + RTLSDRGui::RTLSDRGui(DeviceSourceAPI *deviceAPI, QWidget* parent) : QWidget(parent), ui(new Ui::RTLSDRGui), @@ -40,10 +41,10 @@ RTLSDRGui::RTLSDRGui(DeviceSourceAPI *deviceAPI, QWidget* parent) : ui->setupUi(this); ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); - ui->centerFrequency->setValueRange(7, 24000U, 1900000U); + updateFrequencyLimits(); ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow)); - ui->sampleRate->setValueRange(7, 950000U, 2400000U); + ui->sampleRate->setValueRange(7, RTLSDRInput::sampleRateHighRangeMin, RTLSDRInput::sampleRateHighRangeMax); connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware())); connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus())); @@ -175,6 +176,18 @@ void RTLSDRGui::updateSampleRateAndFrequency() ui->deviceRateText->setText(tr("%1k").arg(QString::number(m_sampleRate / 1000.0f, 'g', 5))); } +void RTLSDRGui::updateFrequencyLimits() +{ + // values in kHz + qint64 minLimit = (m_settings.m_noModMode ? RTLSDRInput::frequencyLowRangeMin : RTLSDRInput::frequencyHighRangeMin) + m_settings.m_transverterDeltaFrequency/1000; + qint64 maxLimit = (m_settings.m_noModMode ? RTLSDRInput::frequencyLowRangeMax : RTLSDRInput::frequencyHighRangeMax) + m_settings.m_transverterDeltaFrequency/1000; + + minLimit = minLimit < 0 ? 0 : minLimit > 9999999 ? 9999999 : minLimit; + maxLimit = maxLimit < 0 ? 0 : maxLimit > 9999999 ? 9999999 : maxLimit; + + ui->centerFrequency->setValueRange(7, minLimit, maxLimit); +} + void RTLSDRGui::displayGains() { if (m_gains.size() > 0) @@ -214,6 +227,9 @@ void RTLSDRGui::displaySettings() ui->ppmText->setText(tr("%1").arg(m_settings.m_loPpmCorrection)); ui->decim->setCurrentIndex(m_settings.m_log2Decim); ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos); + ui->checkBox->setChecked(m_settings.m_noModMode); + ui->transverter->setDeltaFrequency(m_settings.m_transverterDeltaFrequency); + ui->transverter->setChecked(m_settings.m_transverterMode); } void RTLSDRGui::sendSettings() @@ -316,6 +332,14 @@ void RTLSDRGui::on_record_toggled(bool checked) m_sampleSource->getInputMessageQueue()->push(message); } +void RTLSDRGui::on_transverter_toggled(bool checked) +{ + m_settings.m_transverterMode = checked; + m_settings.m_transverterDeltaFrequency = checked ? ui->transverter->getDeltaFrequency() : 0; + updateFrequencyLimits(); + sendSettings(); +} + void RTLSDRGui::updateHardware() { RTLSDRInput::MsgConfigureRTLSDR* message = RTLSDRInput::MsgConfigureRTLSDR::create(m_settings); @@ -356,18 +380,17 @@ void RTLSDRGui::on_checkBox_stateChanged(int state) { if (state == Qt::Checked) { - // Direct Modes: 0: off, 1: I, 2: Q, 3: NoMod. - ((RTLSDRInput*)m_sampleSource)->set_ds_mode(3); ui->gain->setEnabled(false); - ui->centerFrequency->setValueRange(7, 1000U, 275000U); + m_settings.m_noModMode = true; + updateFrequencyLimits(); ui->centerFrequency->setValue(7000); m_settings.m_centerFrequency = 7000 * 1000; } else { - ((RTLSDRInput*)m_sampleSource)->set_ds_mode(0); ui->gain->setEnabled(true); - ui->centerFrequency->setValueRange(7, 28500U, 1700000U); + m_settings.m_noModMode = false; + updateFrequencyLimits(); ui->centerFrequency->setValue(434000); ui->gain->setValue(0); m_settings.m_centerFrequency = 435000 * 1000; @@ -391,9 +414,9 @@ void RTLSDRGui::on_sampleRate_changed(quint64 value) void RTLSDRGui::on_lowSampleRate_toggled(bool checked) { if (checked) { - ui->sampleRate->setValueRange(7, 230000U, 300000U); + ui->sampleRate->setValueRange(7, RTLSDRInput::sampleRateLowRangeMin, RTLSDRInput::sampleRateLowRangeMax); } else { - ui->sampleRate->setValueRange(7, 950000U, 2400000U); + ui->sampleRate->setValueRange(7, RTLSDRInput::sampleRateHighRangeMin, RTLSDRInput::sampleRateHighRangeMax); } m_settings.m_devSampleRate = ui->sampleRate->getValueNew(); diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.h b/plugins/samplesource/rtlsdr/rtlsdrgui.h index 5b8b002ee..d3f4da031 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.h +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.h @@ -69,6 +69,7 @@ private: void displaySettings(); void sendSettings(); void updateSampleRateAndFrequency(); + void updateFrequencyLimits(); private slots: void handleInputMessages(); @@ -86,6 +87,7 @@ private slots: void on_agc_stateChanged(int state); void on_startStop_toggled(bool checked); void on_record_toggled(bool checked); + void on_transverter_toggled(bool checked); void updateHardware(); void updateStatus(); }; diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.ui b/plugins/samplesource/rtlsdr/rtlsdrgui.ui index e6e5e23dc..b8937a0d6 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.ui +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.ui @@ -299,7 +299,7 @@ - + Transverter frequency translation toggle diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp index 147b06904..0eebfe1cb 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp @@ -32,6 +32,15 @@ MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgConfigureRTLSDR, Message) MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgReportRTLSDR, Message) MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgFileRecord, Message) +const quint64 RTLSDRInput::frequencyLowRangeMin = 1000UL; +const quint64 RTLSDRInput::frequencyLowRangeMax = 275000UL; +const quint64 RTLSDRInput::frequencyHighRangeMin = 24000UL; +const quint64 RTLSDRInput::frequencyHighRangeMax = 1900000UL; +const int RTLSDRInput::sampleRateLowRangeMin = 230000U; +const int RTLSDRInput::sampleRateLowRangeMax = 300000U; +const int RTLSDRInput::sampleRateHighRangeMin = 950000U; +const int RTLSDRInput::sampleRateHighRangeMax = 2400000U; + RTLSDRInput::RTLSDRInput(DeviceSourceAPI *deviceAPI) : m_deviceAPI(deviceAPI), m_settings(), @@ -354,35 +363,43 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force) } } - qint64 deviceCenterFrequency = m_settings.m_centerFrequency; - qint64 f_img = deviceCenterFrequency; - quint32 devSampleRate =m_settings.m_devSampleRate; - if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency) - || (m_settings.m_fcPos != settings.m_fcPos)) + || (m_settings.m_fcPos != settings.m_fcPos) + || (m_settings.m_transverterMode != settings.m_transverterMode) + || (m_settings.m_transverterDeltaFrequency != settings.m_transverterDeltaFrequency)) { m_settings.m_centerFrequency = settings.m_centerFrequency; + m_settings.m_transverterMode = settings.m_transverterMode; + m_settings.m_transverterDeltaFrequency = settings.m_transverterDeltaFrequency; + qint64 deviceCenterFrequency = m_settings.m_centerFrequency; + + deviceCenterFrequency -= m_settings.m_transverterMode ? m_settings.m_transverterDeltaFrequency : 0; + + qint64 f_img = deviceCenterFrequency; + quint32 devSampleRate = m_settings.m_devSampleRate; + forwardChange = true; if ((m_settings.m_log2Decim == 0) || (settings.m_fcPos == RTLSDRSettings::FC_POS_CENTER)) { - deviceCenterFrequency = m_settings.m_centerFrequency; f_img = deviceCenterFrequency; } else { if (settings.m_fcPos == RTLSDRSettings::FC_POS_INFRA) { - deviceCenterFrequency = m_settings.m_centerFrequency + (devSampleRate / 4); + deviceCenterFrequency += (devSampleRate / 4); f_img = deviceCenterFrequency + devSampleRate/2; } else if (settings.m_fcPos == RTLSDRSettings::FC_POS_SUPRA) { - deviceCenterFrequency = m_settings.m_centerFrequency - (devSampleRate / 4); + deviceCenterFrequency -= (devSampleRate / 4); f_img = deviceCenterFrequency - devSampleRate/2; } } + deviceCenterFrequency = deviceCenterFrequency < 0 ? 0 : deviceCenterFrequency; + if (m_dev != 0) { if (rtlsdr_set_center_freq( m_dev, deviceCenterFrequency ) != 0) @@ -411,6 +428,18 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force) } } + if ((m_settings.m_noModMode != settings.m_noModMode) || force) + { + m_settings.m_noModMode = settings.m_noModMode; + + // Direct Modes: 0: off, 1: I, 2: Q, 3: NoMod. + if (m_settings.m_noModMode) { + set_ds_mode(3); + } else { + set_ds_mode(0); + } + } + if (forwardChange) { int sampleRate = m_settings.m_devSampleRate/(1<& getGains() const { return m_gains; } void set_ds_mode(int on); + static const quint64 frequencyLowRangeMin; + static const quint64 frequencyLowRangeMax; + static const quint64 frequencyHighRangeMin; + static const quint64 frequencyHighRangeMax; + static const int sampleRateLowRangeMin; + static const int sampleRateLowRangeMax; + static const int sampleRateHighRangeMin; + static const int sampleRateHighRangeMax; + private: DeviceSourceAPI *m_deviceAPI; FileRecord *m_fileSink; //!< File sink to record device I/Q output diff --git a/plugins/samplesource/rtlsdr/rtlsdrplugin.cpp b/plugins/samplesource/rtlsdr/rtlsdrplugin.cpp index b168512fd..757766330 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrplugin.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrplugin.cpp @@ -11,7 +11,7 @@ const PluginDescriptor RTLSDRPlugin::m_pluginDescriptor = { QString("RTL-SDR Input"), - QString("3.7.2"), + QString("3.7.3"), QString("(c) Edouard Griffiths, F4EXB"), QString("https://github.com/f4exb/sdrangel"), true, diff --git a/plugins/samplesource/rtlsdr/rtlsdrsettings.cpp b/plugins/samplesource/rtlsdr/rtlsdrsettings.cpp index edf29351d..703306865 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrsettings.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrsettings.cpp @@ -35,6 +35,9 @@ void RTLSDRSettings::resetToDefaults() m_dcBlock = false; m_iqImbalance = false; m_agc = false; + m_noModMode = false; + m_transverterMode = false; + m_transverterDeltaFrequency = 0; } QByteArray RTLSDRSettings::serialize() const @@ -50,6 +53,9 @@ QByteArray RTLSDRSettings::serialize() const s.writeS32(8, m_devSampleRate); s.writeBool(9, m_lowSampleRate); s.writeBool(10, m_agc); + s.writeBool(11, m_noModMode); + s.writeBool(12, m_transverterMode); + s.writeS64(13, m_transverterDeltaFrequency); return s.final(); } @@ -78,6 +84,9 @@ bool RTLSDRSettings::deserialize(const QByteArray& data) d.readS32(8, &m_devSampleRate, 1024*1000); d.readBool(9, &m_lowSampleRate, false); d.readBool(10, &m_agc, false); + d.readBool(11, &m_noModMode, false); + d.readBool(12, &m_transverterMode, false); + d.readS64(13, &m_transverterDeltaFrequency, 0); return true; } diff --git a/plugins/samplesource/rtlsdr/rtlsdrsettings.h b/plugins/samplesource/rtlsdr/rtlsdrsettings.h index ff257de71..d9c9a2476 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrsettings.h +++ b/plugins/samplesource/rtlsdr/rtlsdrsettings.h @@ -34,6 +34,9 @@ struct RTLSDRSettings { bool m_dcBlock; bool m_iqImbalance; bool m_agc; + bool m_noModMode; + bool m_transverterMode; + qint64 m_transverterDeltaFrequency; RTLSDRSettings(); void resetToDefaults(); diff --git a/sdrbase/gui/transverterbutton.cpp b/sdrbase/gui/transverterbutton.cpp index 33b2eb9d4..ddfd366f2 100644 --- a/sdrbase/gui/transverterbutton.cpp +++ b/sdrbase/gui/transverterbutton.cpp @@ -33,7 +33,7 @@ void TransverterButton::onToggled(bool checked) if (checked) { TransverterDialog transverterDialog(&m_deltaFrequency, this); transverterDialog.exec(); - setToolTip(tr("Transverter frequency translation toggle. Delta frequency %1 kHz").arg(m_deltaFrequency)); + setToolTip(tr("Transverter frequency translation toggle. Delta frequency %1 kHz").arg(m_deltaFrequency/1000)); } } diff --git a/sdrbase/gui/transverterdialog.cpp b/sdrbase/gui/transverterdialog.cpp index c6e3e557e..d6ac37108 100644 --- a/sdrbase/gui/transverterdialog.cpp +++ b/sdrbase/gui/transverterdialog.cpp @@ -32,7 +32,7 @@ TransverterDialog::TransverterDialog(qint64 *deltaFrequency, QWidget* parent) : ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03))); ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); ui->deltaFrequency->setValueRange(false, 7, -9999999, 9999999); - ui->deltaFrequency->setValue(*m_deltaFrequency); + ui->deltaFrequency->setValue(*m_deltaFrequency/1000); } TransverterDialog::~TransverterDialog() @@ -42,6 +42,6 @@ TransverterDialog::~TransverterDialog() void TransverterDialog::accept() { - *m_deltaFrequency = ui->deltaFrequency->getValueNew(); + *m_deltaFrequency = ui->deltaFrequency->getValueNew()*1000; QDialog::accept(); }