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

RTLSDR plugin: continuous sample rate setting

This commit is contained in:
f4exb 2017-04-02 02:00:05 +02:00
parent f91eba5b10
commit 365154767a
10 changed files with 154 additions and 227 deletions

View File

@ -16,56 +16,6 @@
#include "devicehackrfvalues.h" #include "devicehackrfvalues.h"
const unsigned int HackRFSampleRates::m_nb_rates = 22;
const unsigned int HackRFSampleRates::m_rates[HackRFSampleRates::m_nb_rates] = {
2400000,
2600000,
3000000,
3150000, // for PAL-M
3200000,
3250000, // For PAL-BGIL
4000000,
4333333, // for GSM
4800000,
5600000,
6000000,
6300000, // for PAL-M
6400000,
6500000, // For PAL-BGIL
8000000,
9600000,
12000000,
12800000,
16000000,
18000000,
19200000,
20000000};
unsigned int HackRFSampleRates::getRate(unsigned int rate_index)
{
if (rate_index < m_nb_rates)
{
return m_rates[rate_index];
}
else
{
return m_rates[0];
}
}
unsigned int HackRFSampleRates::getRateIndex(unsigned int rate)
{
for (unsigned int i=0; i < m_nb_rates; i++)
{
if (rate == m_rates[i])
{
return i;
}
}
return 0;
}
const unsigned int HackRFBandwidths::m_nb_bw = 16; const unsigned int HackRFBandwidths::m_nb_bw = 16;
const unsigned int HackRFBandwidths::m_bw_k[HackRFBandwidths::m_nb_bw] = { const unsigned int HackRFBandwidths::m_bw_k[HackRFBandwidths::m_nb_bw] = {
1750, 1750,

View File

@ -17,14 +17,6 @@
#ifndef DEVICES_HACKRF_DEVICEHACKRFVALUES_H_ #ifndef DEVICES_HACKRF_DEVICEHACKRFVALUES_H_
#define DEVICES_HACKRF_DEVICEHACKRFVALUES_H_ #define DEVICES_HACKRF_DEVICEHACKRFVALUES_H_
class HackRFSampleRates {
public:
static unsigned int getRate(unsigned int rate_index);
static unsigned int getRateIndex(unsigned int rate);
static const unsigned int m_nb_rates;
static const unsigned int m_rates[];
};
class HackRFBandwidths { class HackRFBandwidths {
public: public:
static unsigned int getBandwidth(unsigned int bandwidth_index); static unsigned int getBandwidth(unsigned int bandwidth_index);

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>320</width> <width>320</width>
<height>300</height> <height>200</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -19,7 +19,7 @@
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>320</width> <width>320</width>
<height>300</height> <height>200</height>
</size> </size>
</property> </property>
<property name="font"> <property name="font">

View File

@ -40,12 +40,8 @@ RTLSDRGui::RTLSDRGui(DeviceSourceAPI *deviceAPI, QWidget* parent) :
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
ui->centerFrequency->setValueRange(7, 24000U, 1900000U); ui->centerFrequency->setValueRange(7, 24000U, 1900000U);
ui->sampleRate->clear(); ui->newSampleRate->setColorMapper(ColorMapper(ColorMapper::ReverseGreenYellow));
ui->newSampleRate->setValueRange(7, 950000U, 2400000U);
for (int i = 0; i < RTLSDRSampleRates::getNbRates(); i++)
{
ui->sampleRate->addItem(QString::number(RTLSDRSampleRates::getRate(i)/1000));
}
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()));
@ -202,8 +198,6 @@ void RTLSDRGui::displaySettings()
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
ui->dcOffset->setChecked(m_settings.m_dcBlock); ui->dcOffset->setChecked(m_settings.m_dcBlock);
ui->iqImbalance->setChecked(m_settings.m_iqImbalance); ui->iqImbalance->setChecked(m_settings.m_iqImbalance);
unsigned int sampleRateIndex = RTLSDRSampleRates::getRateIndex(m_settings.m_devSampleRate);
ui->sampleRate->setCurrentIndex(sampleRateIndex);
ui->ppm->setValue(m_settings.m_loPpmCorrection); ui->ppm->setValue(m_settings.m_loPpmCorrection);
ui->ppmText->setText(tr("%1").arg(m_settings.m_loPpmCorrection)); ui->ppmText->setText(tr("%1").arg(m_settings.m_loPpmCorrection));
ui->decim->setCurrentIndex(m_settings.m_log2Decim); ui->decim->setCurrentIndex(m_settings.m_log2Decim);
@ -305,10 +299,6 @@ void RTLSDRGui::on_gain_valueChanged(int value)
void RTLSDRGui::on_sampleRate_currentIndexChanged(int index) void RTLSDRGui::on_sampleRate_currentIndexChanged(int index)
{ {
int newrate = RTLSDRSampleRates::getRate(index);
m_settings.m_devSampleRate = newrate;
sendSettings();
} }
void RTLSDRGui::on_startStop_toggled(bool checked) void RTLSDRGui::on_startStop_toggled(bool checked)
@ -402,48 +392,21 @@ void RTLSDRGui::on_checkBox_stateChanged(int state)
sendSettings(); sendSettings();
} }
const unsigned int RTLSDRSampleRates::m_nb_rates = 13; void RTLSDRGui::on_newSampleRate_changed(quint64 value)
const unsigned int RTLSDRSampleRates::m_rates[] = {
250000,
256000,
1000000,
1024000,
1152000,
1200000,
1536000,
1600000,
2000000,
2048000,
2166667, // for GSM
2304000,
2400000};
unsigned int RTLSDRSampleRates::getRate(unsigned int rate_index)
{ {
if (rate_index < m_nb_rates) m_settings.m_devSampleRate = value;
{ sendSettings();
return m_rates[rate_index];
}
else
{
return m_rates[0];
}
} }
unsigned int RTLSDRSampleRates::getRateIndex(unsigned int rate) void RTLSDRGui::on_lowSampleRate_toggled(bool checked)
{ {
for (unsigned int i=0; i < m_nb_rates; i++) if (checked) {
{ ui->newSampleRate->setValueRange(7, 230000U, 300000U);
if (rate == m_rates[i]) } else {
{ ui->newSampleRate->setValueRange(7, 950000U, 2400000U);
return i;
}
} }
return 0; m_settings.m_devSampleRate = ui->newSampleRate->getValueNew();
} qDebug("RTLSDRGui::on_lowSampleRate_toggled: %d S/s", m_settings.m_devSampleRate);
sendSettings();
unsigned int RTLSDRSampleRates::getNbRates()
{
return RTLSDRSampleRates::m_nb_rates;
} }

View File

@ -68,6 +68,8 @@ private:
private slots: private slots:
void handleDSPMessages(); void handleDSPMessages();
void on_centerFrequency_changed(quint64 value); void on_centerFrequency_changed(quint64 value);
void on_newSampleRate_changed(quint64 value);
void on_lowSampleRate_toggled(bool checked);
void on_dcOffset_toggled(bool checked); void on_dcOffset_toggled(bool checked);
void on_iqImbalance_toggled(bool checked); void on_iqImbalance_toggled(bool checked);
void on_decim_currentIndexChanged(int index); void on_decim_currentIndexChanged(int index);
@ -83,14 +85,4 @@ private slots:
void handleSourceMessages(); void handleSourceMessages();
}; };
class RTLSDRSampleRates {
public:
static unsigned int getRate(unsigned int rate_index);
static unsigned int getRateIndex(unsigned int rate);
static unsigned int getNbRates();
private:
static const unsigned int m_nb_rates;
static const unsigned int m_rates[];
};
#endif // INCLUDE_RTLSDRGUI_H #endif // INCLUDE_RTLSDRGUI_H

View File

@ -6,20 +6,20 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>300</width> <width>320</width>
<height>190</height> <height>220</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>300</width> <width>320</width>
<height>190</height> <height>220</height>
</size> </size>
</property> </property>
<property name="font"> <property name="font">
@ -35,7 +35,16 @@
<property name="spacing"> <property name="spacing">
<number>3</number> <number>3</number>
</property> </property>
<property name="margin"> <property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number> <number>2</number>
</property> </property>
<item> <item>
@ -248,38 +257,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
</layout> <item row="0" column="5">
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_rateDecimPos">
<item row="0" column="0">
<widget class="QLabel" name="samplerateLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>SR</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="sampleRateUnit">
<property name="text">
<string>k</string>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QComboBox" name="fcPos"> <widget class="QComboBox" name="fcPos">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
@ -310,47 +288,115 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="0" column="7"> <item row="0" column="4">
<widget class="QLabel" name="fcPosLabel"> <widget class="QLabel" name="fcPosLabel">
<property name="text"> <property name="text">
<string>Fp</string> <string>Fp</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="9"> </layout>
<spacer name="horizontalSpacer_fcPos"> </item>
<item>
<widget class="Line" name="line_4">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="sampleRate">
<property name="toolTip">
<string>Sample rate in kS/s</string>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="5"> <item>
<layout class="QHBoxLayout" name="sampleRateLayout">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item>
<widget class="ButtonSwitch" name="lowSampleRate">
<property name="toolTip">
<string>Toggle low/high sample rate range</string>
</property>
<property name="text">
<string>L</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="samplerateLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>SR</string>
</property>
</widget>
</item>
<item>
<widget class="ValueDial" name="newSampleRate" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>16</height>
</size>
</property>
<property name="font">
<font>
<family>Monospace</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="toolTip">
<string>Device sample rate (S/s)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="sampleRateUnit">
<property name="text">
<string>S/s</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_decim">
<property name="text">
<string>Dec</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="decim"> <widget class="QComboBox" name="decim">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
@ -396,15 +442,22 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="0" column="4"> </layout>
<widget class="QLabel" name="label_decim"> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_direct">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="toolTip">
<string>RTLSDR special direct sampling mode (HF Bands)</string>
</property>
<property name="text"> <property name="text">
<string>Dec</string> <string>No-mod Direct Sampling</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="6"> <item>
<spacer name="horizontalSpacer_5"> <spacer name="horizontalSpacer_3">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -480,33 +533,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_direct">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="toolTip">
<string>RTLSDR special direct sampling mode (HF Bands)</string>
</property>
<property name="text">
<string>No-mod Direct Sampling</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item> <item>
<widget class="Line" name="line_2"> <widget class="Line" name="line_2">
<property name="orientation"> <property name="orientation">

View File

@ -329,8 +329,8 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force)
{ {
qDebug() << "RTLSDRInput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz" qDebug() << "RTLSDRInput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz"
<< " device center freq: " << deviceCenterFrequency << " Hz" << " device center freq: " << deviceCenterFrequency << " Hz"
<< " device sample rate: " << devSampleRate << "Hz" << " device sample rate: " << devSampleRate << "S/s"
<< " Actual sample rate: " << devSampleRate/(1<<m_settings.m_log2Decim) << "Hz" << " Actual sample rate: " << devSampleRate/(1<<m_settings.m_log2Decim) << "S/s"
<< " img: " << f_img << "Hz"; << " img: " << f_img << "Hz";
} }
} }

View File

@ -11,7 +11,7 @@
const PluginDescriptor RTLSDRPlugin::m_pluginDescriptor = { const PluginDescriptor RTLSDRPlugin::m_pluginDescriptor = {
QString("RTL-SDR Input"), QString("RTL-SDR Input"),
QString("3.0.0"), QString("3.3.3"),
QString("(c) Edouard Griffiths, F4EXB"), QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"), QString("https://github.com/f4exb/sdrangel"),
true, true,

View File

@ -26,6 +26,7 @@ RTLSDRSettings::RTLSDRSettings()
void RTLSDRSettings::resetToDefaults() void RTLSDRSettings::resetToDefaults()
{ {
m_devSampleRate = 1024*1000; m_devSampleRate = 1024*1000;
m_lowSampleRate = false;
m_centerFrequency = 435000*1000; m_centerFrequency = 435000*1000;
m_gain = 0; m_gain = 0;
m_loPpmCorrection = 0; m_loPpmCorrection = 0;
@ -39,13 +40,14 @@ QByteArray RTLSDRSettings::serialize() const
{ {
SimpleSerializer s(1); SimpleSerializer s(1);
s.writeS32(1, m_devSampleRate);
s.writeS32(2, m_gain); s.writeS32(2, m_gain);
s.writeS32(3, m_loPpmCorrection); s.writeS32(3, m_loPpmCorrection);
s.writeU32(4, m_log2Decim); s.writeU32(4, m_log2Decim);
s.writeBool(5, m_dcBlock); s.writeBool(5, m_dcBlock);
s.writeBool(6, m_iqImbalance); s.writeBool(6, m_iqImbalance);
s.writeS32(7, (int) m_fcPos); s.writeS32(7, (int) m_fcPos);
s.writeS32(8, m_devSampleRate);
s.writeBool(9, m_lowSampleRate);
return s.final(); return s.final();
} }
@ -64,7 +66,6 @@ bool RTLSDRSettings::deserialize(const QByteArray& data)
{ {
int intval; int intval;
d.readS32(1, &m_devSampleRate, 0);
d.readS32(2, &m_gain, 0); d.readS32(2, &m_gain, 0);
d.readS32(3, &m_loPpmCorrection, 0); d.readS32(3, &m_loPpmCorrection, 0);
d.readU32(4, &m_log2Decim, 4); d.readU32(4, &m_log2Decim, 4);
@ -72,6 +73,8 @@ bool RTLSDRSettings::deserialize(const QByteArray& data)
d.readBool(6, &m_iqImbalance, false); d.readBool(6, &m_iqImbalance, false);
d.readS32(7, &intval, 0); d.readS32(7, &intval, 0);
m_fcPos = (fcPos_t) intval; m_fcPos = (fcPos_t) intval;
d.readS32(8, &m_devSampleRate, 1024*1000);
d.readBool(9, &m_lowSampleRate, false);
return true; return true;
} }

View File

@ -25,6 +25,7 @@ struct RTLSDRSettings {
} fcPos_t; } fcPos_t;
int m_devSampleRate; int m_devSampleRate;
bool m_lowSampleRate;
quint64 m_centerFrequency; quint64 m_centerFrequency;
qint32 m_gain; qint32 m_gain;
qint32 m_loPpmCorrection; qint32 m_loPpmCorrection;