1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 00:18:37 -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

@ -120,22 +120,22 @@ void RTLSDRGui::on_iqImbalance_toggled(bool checked)
QByteArray RTLSDRGui::serialize() const QByteArray RTLSDRGui::serialize() const
{ {
return m_settings.serialize(); return m_settings.serialize();
} }
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();
return true; return true;
} }
else else
{ {
resetToDefaults(); resetToDefaults();
return false; return false;
} }
} }
bool RTLSDRGui::handleMessage(const Message& message) bool RTLSDRGui::handleMessage(const Message& message)

View File

@ -196,187 +196,152 @@ quint64 RTLSDRInput::getCenterFrequency() const
bool RTLSDRInput::handleMessage(const Message& message) 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);
{
qDebug("RTLSDR config error");
}
return true; if (!success)
} {
else qDebug("RTLSDRInput::handleMessage: config error");
{ }
return false;
} return true;
}
else
{
return false;
}
} }
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;
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)
{
forwardChange = true;
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_dev != 0)
{
if (rtlsdr_set_freq_correction(m_dev, settings.m_loPpmCorrection) < 0)
{
qCritical("could not set LO ppm correction: %d", settings.m_loPpmCorrection);
}
else
{
m_settings.m_loPpmCorrection = settings.m_loPpmCorrection;
}
}
}
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
{
forwardChange = true;
if(m_dev != 0)
{
m_settings.m_log2Decim = settings.m_log2Decim;
m_rtlSDRThread->setLog2Decimation(settings.m_log2Decim);
}
}
if (m_settings.m_centerFrequency != settings.m_centerFrequency)
{ {
forwardChange = true; m_settings.m_dcBlock = settings.m_dcBlock;
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqImbalance);
} }
qint64 deviceCenterFrequency = m_settings.m_centerFrequency; if ((m_settings.m_iqImbalance != settings.m_iqImbalance) || force)
qint64 f_img = deviceCenterFrequency; {
quint32 devSampleRate = m_settings.m_devSampleRate; m_settings.m_iqImbalance = settings.m_iqImbalance;
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqImbalance);
}
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency) if ((m_settings.m_loPpmCorrection != settings.m_loPpmCorrection) || force)
|| (m_settings.m_fcPos != settings.m_fcPos)) {
{ if (m_dev != 0)
m_settings.m_centerFrequency = settings.m_centerFrequency; {
if (rtlsdr_set_freq_correction(m_dev, settings.m_loPpmCorrection) < 0)
{
qCritical("could not set LO ppm correction: %d", settings.m_loPpmCorrection);
}
else
{
m_settings.m_loPpmCorrection = settings.m_loPpmCorrection;
}
}
}
if ((m_settings.m_log2Decim == 0) || (settings.m_fcPos == RTLSDRSettings::FC_POS_CENTER)) if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force)
{ {
deviceCenterFrequency = m_settings.m_centerFrequency; m_settings.m_devSampleRate = settings.m_devSampleRate;
f_img = deviceCenterFrequency; forwardChange = true;
}
else
{
if (settings.m_fcPos == RTLSDRSettings::FC_POS_INFRA)
{
deviceCenterFrequency = m_settings.m_centerFrequency + (devSampleRate / 4);
f_img = deviceCenterFrequency + devSampleRate/2;
}
else if (settings.m_fcPos == RTLSDRSettings::FC_POS_SUPRA)
{
deviceCenterFrequency = m_settings.m_centerFrequency - (devSampleRate / 4);
f_img = deviceCenterFrequency - devSampleRate/2;
}
}
if(m_dev != 0) if(m_dev != 0)
{ {
if (rtlsdr_set_center_freq( m_dev, deviceCenterFrequency ) != 0) if( rtlsdr_set_sample_rate(m_dev, settings.m_devSampleRate) < 0)
{ {
qDebug("rtlsdr_set_center_freq(%lld) failed", deviceCenterFrequency); qCritical("RTLSDRInput::applySettings: could not set sample rate: %d", settings.m_devSampleRate);
} }
else else
{ {
qDebug() << "RTLSDRInput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz" m_rtlSDRThread->setSamplerate(settings.m_devSampleRate);
<< " device center freq: " << deviceCenterFrequency << " Hz" qDebug("RTLSDRInput::applySettings: sample rate set to %d", m_settings.m_devSampleRate);
<< " device sample rate: " << devSampleRate << "Hz" }
<< " Actual sample rate: " << devSampleRate/(1<<m_settings.m_log2Decim) << "Hz" }
<< " img: " << f_img << "Hz"; }
}
}
}
if ((m_settings.m_fcPos != settings.m_fcPos) || force) if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
{ {
m_settings.m_fcPos = settings.m_fcPos; m_settings.m_log2Decim = settings.m_log2Decim;
forwardChange = true;
if(m_dev != 0) if(m_dev != 0)
{ {
m_rtlSDRThread->setFcPos((int) m_settings.m_fcPos); m_rtlSDRThread->setLog2Decimation(settings.m_log2Decim);
qDebug() << "RTLSDRInput: set fc pos (enum) to " << (int) m_settings.m_fcPos; }
} }
}
/* qint64 deviceCenterFrequency = m_settings.m_centerFrequency;
if(m_dev != 0) qint64 f_img = deviceCenterFrequency;
{ quint32 devSampleRate =m_settings.m_devSampleRate;
qint64 centerFrequency = m_settings.m_centerFrequency + (m_settings.m_devSampleRate / 4);
if (m_settings.m_log2Decim == 0) if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency)
{ // Little wooby-doop if no decimation || (m_settings.m_fcPos != settings.m_fcPos))
centerFrequency = m_settings.m_centerFrequency; {
} m_settings.m_centerFrequency = settings.m_centerFrequency;
else forwardChange = true;
{
centerFrequency = m_settings.m_centerFrequency + (m_settings.m_devSampleRate / 4);
}
if (rtlsdr_set_center_freq( m_dev, centerFrequency ) != 0) if ((m_settings.m_log2Decim == 0) || (settings.m_fcPos == RTLSDRSettings::FC_POS_CENTER))
{ {
qDebug("rtlsdr_set_center_freq(%lld) failed", m_settings.m_centerFrequency); deviceCenterFrequency = m_settings.m_centerFrequency;
} f_img = deviceCenterFrequency;
}*/ }
else
{
if (settings.m_fcPos == RTLSDRSettings::FC_POS_INFRA)
{
deviceCenterFrequency = m_settings.m_centerFrequency + (devSampleRate / 4);
f_img = deviceCenterFrequency + devSampleRate/2;
}
else if (settings.m_fcPos == RTLSDRSettings::FC_POS_SUPRA)
{
deviceCenterFrequency = m_settings.m_centerFrequency - (devSampleRate / 4);
f_img = deviceCenterFrequency - devSampleRate/2;
}
}
if ((m_settings.m_dcBlock != settings.m_dcBlock) || force) if(m_dev != 0)
{ {
m_settings.m_dcBlock = settings.m_dcBlock; if (rtlsdr_set_center_freq( m_dev, deviceCenterFrequency ) != 0)
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqImbalance); {
} qDebug("rtlsdr_set_center_freq(%lld) failed", deviceCenterFrequency);
}
else
{
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"
<< " img: " << f_img << "Hz";
}
}
}
if ((m_settings.m_iqImbalance != settings.m_iqImbalance) || force) if ((m_settings.m_fcPos != settings.m_fcPos) || force)
{ {
m_settings.m_iqImbalance = settings.m_iqImbalance; m_settings.m_fcPos = settings.m_fcPos;
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqImbalance);
} if(m_dev != 0)
{
m_rtlSDRThread->setFcPos((int) m_settings.m_fcPos);
qDebug() << "RTLSDRInput: set fc pos (enum) to " << (int) m_settings.m_fcPos;
}
}
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);
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency); DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency);
m_deviceAPI->getDeviceInputMessageQueue()->push(notif); m_deviceAPI->getDeviceInputMessageQueue()->push(notif);
} }
return true; return true;
} }
void RTLSDRInput::set_ds_mode(int on) void RTLSDRInput::set_ds_mode(int on)