1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 08:04:49 -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"
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_bw_k[HackRFBandwidths::m_nb_bw] = {
1750,

View File

@ -17,14 +17,6 @@
#ifndef 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 {
public:
static unsigned int getBandwidth(unsigned int bandwidth_index);

View File

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

View File

@ -40,12 +40,8 @@ RTLSDRGui::RTLSDRGui(DeviceSourceAPI *deviceAPI, QWidget* parent) :
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
ui->centerFrequency->setValueRange(7, 24000U, 1900000U);
ui->sampleRate->clear();
for (int i = 0; i < RTLSDRSampleRates::getNbRates(); i++)
{
ui->sampleRate->addItem(QString::number(RTLSDRSampleRates::getRate(i)/1000));
}
ui->newSampleRate->setColorMapper(ColorMapper(ColorMapper::ReverseGreenYellow));
ui->newSampleRate->setValueRange(7, 950000U, 2400000U);
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
@ -202,8 +198,6 @@ void RTLSDRGui::displaySettings()
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
ui->dcOffset->setChecked(m_settings.m_dcBlock);
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->ppmText->setText(tr("%1").arg(m_settings.m_loPpmCorrection));
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)
{
int newrate = RTLSDRSampleRates::getRate(index);
m_settings.m_devSampleRate = newrate;
sendSettings();
}
void RTLSDRGui::on_startStop_toggled(bool checked)
@ -402,48 +392,21 @@ void RTLSDRGui::on_checkBox_stateChanged(int state)
sendSettings();
}
const unsigned int RTLSDRSampleRates::m_nb_rates = 13;
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)
void RTLSDRGui::on_newSampleRate_changed(quint64 value)
{
if (rate_index < m_nb_rates)
{
return m_rates[rate_index];
}
else
{
return m_rates[0];
}
m_settings.m_devSampleRate = value;
sendSettings();
}
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 (rate == m_rates[i])
{
return i;
}
if (checked) {
ui->newSampleRate->setValueRange(7, 230000U, 300000U);
} else {
ui->newSampleRate->setValueRange(7, 950000U, 2400000U);
}
return 0;
}
unsigned int RTLSDRSampleRates::getNbRates()
{
return RTLSDRSampleRates::m_nb_rates;
m_settings.m_devSampleRate = ui->newSampleRate->getValueNew();
qDebug("RTLSDRGui::on_lowSampleRate_toggled: %d S/s", m_settings.m_devSampleRate);
sendSettings();
}

View File

@ -68,6 +68,8 @@ private:
private slots:
void handleDSPMessages();
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_iqImbalance_toggled(bool checked);
void on_decim_currentIndexChanged(int index);
@ -83,14 +85,4 @@ private slots:
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

View File

@ -6,20 +6,20 @@
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>190</height>
<width>320</width>
<height>220</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>190</height>
<width>320</width>
<height>220</height>
</size>
</property>
<property name="font">
@ -35,7 +35,16 @@
<property name="spacing">
<number>3</number>
</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>
</property>
<item>
@ -248,38 +257,7 @@
</property>
</spacer>
</item>
</layout>
</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">
<item row="0" column="5">
<widget class="QComboBox" name="fcPos">
<property name="maximumSize">
<size>
@ -310,47 +288,115 @@
</item>
</widget>
</item>
<item row="0" column="7">
<item row="0" column="4">
<widget class="QLabel" name="fcPosLabel">
<property name="text">
<string>Fp</string>
</property>
</widget>
</item>
<item row="0" column="9">
<spacer name="horizontalSpacer_fcPos">
</layout>
</item>
<item>
<widget class="Line" name="line_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="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>
</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">
<property name="maximumSize">
<size>
@ -396,15 +442,22 @@
</item>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="label_decim">
</layout>
</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>Dec</string>
<string>No-mod Direct Sampling</string>
</property>
</widget>
</item>
<item row="0" column="6">
<spacer name="horizontalSpacer_5">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -480,33 +533,6 @@
</item>
</layout>
</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>
<widget class="Line" name="line_2">
<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"
<< " device center freq: " << deviceCenterFrequency << " Hz"
<< " device sample rate: " << devSampleRate << "Hz"
<< " Actual sample rate: " << devSampleRate/(1<<m_settings.m_log2Decim) << "Hz"
<< " device sample rate: " << devSampleRate << "S/s"
<< " Actual sample rate: " << devSampleRate/(1<<m_settings.m_log2Decim) << "S/s"
<< " img: " << f_img << "Hz";
}
}

View File

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

View File

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

View File

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