1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 08:28:36 -05:00

RTLSDR: reviewed apply settings

This commit is contained in:
f4exb 2017-02-21 05:35:20 +01:00
parent 1174875551
commit 038d9c2f41
2 changed files with 132 additions and 167 deletions

View File

@ -125,7 +125,7 @@ QByteArray RTLSDRGui::serialize() const
bool RTLSDRGui::deserialize(const QByteArray& data) bool RTLSDRGui::deserialize(const QByteArray& data)
{ {
if (m_settings.deserialize(data)) if(m_settings.deserialize(data))
{ {
displaySettings(); displaySettings();
sendSettings(); sendSettings();

View File

@ -199,10 +199,13 @@ bool RTLSDRInput::handleMessage(const Message& message)
if (MsgConfigureRTLSDR::match(message)) if (MsgConfigureRTLSDR::match(message))
{ {
MsgConfigureRTLSDR& conf = (MsgConfigureRTLSDR&) message; MsgConfigureRTLSDR& conf = (MsgConfigureRTLSDR&) message;
qDebug() << "RTLSDRInput::handleMessage: MsgConfigureRTLSDR";
if (!applySettings(conf.getSettings(), false)) bool success = applySettings(conf.getSettings(), false);
if (!success)
{ {
qDebug("RTLSDR config error"); qDebug("RTLSDRInput::handleMessage: config error");
} }
return true; return true;
@ -215,39 +218,18 @@ bool RTLSDRInput::handleMessage(const Message& message)
bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force) bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force)
{ {
QMutexLocker mutexLocker(&m_mutex);
bool forwardChange = false; bool forwardChange = false;
if ((m_settings.m_gain != settings.m_gain) || force) if ((m_settings.m_dcBlock != settings.m_dcBlock) || force)
{ {
m_settings.m_gain = settings.m_gain; m_settings.m_dcBlock = settings.m_dcBlock;
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqImbalance);
if(m_dev != 0)
{
if(rtlsdr_set_tuner_gain(m_dev, m_settings.m_gain) != 0)
{
qDebug("rtlsdr_set_tuner_gain() failed");
}
}
} }
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) if ((m_settings.m_iqImbalance != settings.m_iqImbalance) || force)
{ {
forwardChange = true; m_settings.m_iqImbalance = settings.m_iqImbalance;
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqImbalance);
if(m_dev != 0)
{
if( rtlsdr_set_sample_rate(m_dev, settings.m_devSampleRate) < 0)
{
qCritical("RTLSDRInput::applySettings: could not set sample rate: %d", settings.m_devSampleRate);
}
else
{
m_settings.m_devSampleRate = settings.m_devSampleRate;
m_rtlSDRThread->setSamplerate(settings.m_devSampleRate);
qDebug("RTLSDRInput::applySettings: sample rate set to %d", m_settings.m_devSampleRate);
}
}
} }
if ((m_settings.m_loPpmCorrection != settings.m_loPpmCorrection) || force) if ((m_settings.m_loPpmCorrection != settings.m_loPpmCorrection) || force)
@ -265,30 +247,45 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force)
} }
} }
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force) if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force)
{ {
m_settings.m_devSampleRate = settings.m_devSampleRate;
forwardChange = true; forwardChange = true;
if(m_dev != 0) if(m_dev != 0)
{
if( rtlsdr_set_sample_rate(m_dev, settings.m_devSampleRate) < 0)
{
qCritical("RTLSDRInput::applySettings: could not set sample rate: %d", settings.m_devSampleRate);
}
else
{
m_rtlSDRThread->setSamplerate(settings.m_devSampleRate);
qDebug("RTLSDRInput::applySettings: sample rate set to %d", m_settings.m_devSampleRate);
}
}
}
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
{ {
m_settings.m_log2Decim = settings.m_log2Decim; m_settings.m_log2Decim = settings.m_log2Decim;
forwardChange = true;
if(m_dev != 0)
{
m_rtlSDRThread->setLog2Decimation(settings.m_log2Decim); m_rtlSDRThread->setLog2Decimation(settings.m_log2Decim);
} }
} }
if (m_settings.m_centerFrequency != settings.m_centerFrequency)
{
forwardChange = true;
}
qint64 deviceCenterFrequency = m_settings.m_centerFrequency; qint64 deviceCenterFrequency = m_settings.m_centerFrequency;
qint64 f_img = deviceCenterFrequency; qint64 f_img = deviceCenterFrequency;
quint32 devSampleRate = m_settings.m_devSampleRate; quint32 devSampleRate =m_settings.m_devSampleRate;
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency) 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_centerFrequency = settings.m_centerFrequency; m_settings.m_centerFrequency = settings.m_centerFrequency;
forwardChange = true;
if ((m_settings.m_log2Decim == 0) || (settings.m_fcPos == RTLSDRSettings::FC_POS_CENTER)) if ((m_settings.m_log2Decim == 0) || (settings.m_fcPos == RTLSDRSettings::FC_POS_CENTER))
{ {
@ -337,38 +334,6 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force)
} }
} }
/*
if(m_dev != 0)
{
qint64 centerFrequency = m_settings.m_centerFrequency + (m_settings.m_devSampleRate / 4);
if (m_settings.m_log2Decim == 0)
{ // Little wooby-doop if no decimation
centerFrequency = m_settings.m_centerFrequency;
}
else
{
centerFrequency = m_settings.m_centerFrequency + (m_settings.m_devSampleRate / 4);
}
if (rtlsdr_set_center_freq( m_dev, centerFrequency ) != 0)
{
qDebug("rtlsdr_set_center_freq(%lld) failed", m_settings.m_centerFrequency);
}
}*/
if ((m_settings.m_dcBlock != settings.m_dcBlock) || force)
{
m_settings.m_dcBlock = settings.m_dcBlock;
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqImbalance);
}
if ((m_settings.m_iqImbalance != settings.m_iqImbalance) || force)
{
m_settings.m_iqImbalance = settings.m_iqImbalance;
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqImbalance);
}
if (forwardChange) if (forwardChange)
{ {
int sampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim); int sampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim);