From 23c956cf170ceded672ef0f146cd01aab6feb45a Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 19 Aug 2015 09:24:44 +0200 Subject: [PATCH] Deep redesign: Init sequence review phase #5: fixed source message forwarding for BladeRF only --- plugins/samplesource/bladerf/bladerfinput.cpp | 47 ++++++++++++------- sdrbase/dsp/dspengine.cpp | 16 +++---- sdrbase/mainwindow.cpp | 14 +++--- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/plugins/samplesource/bladerf/bladerfinput.cpp b/plugins/samplesource/bladerf/bladerfinput.cpp index 05ec791d2..3c9755066 100644 --- a/plugins/samplesource/bladerf/bladerfinput.cpp +++ b/plugins/samplesource/bladerf/bladerfinput.cpp @@ -260,6 +260,7 @@ bool BladerfInput::handleMessage(const Message& message) bool BladerfInput::applySettings(const Settings& settings, bool force) { + bool forwardChange = false; QMutexLocker mutexLocker(&m_mutex); qDebug() << "BladerfInput::applySettings: m_dev: " << m_dev; @@ -383,6 +384,7 @@ bool BladerfInput::applySettings(const Settings& settings, bool force) if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) { m_settings.m_devSampleRate = settings.m_devSampleRate; + forwardChange = true; if (m_dev != 0) { @@ -422,6 +424,7 @@ bool BladerfInput::applySettings(const Settings& settings, bool force) if ((m_settings.m_log2Decim != settings.m_log2Decim) || force) { m_settings.m_log2Decim = settings.m_log2Decim; + forwardChange = true; if(m_dev != 0) { @@ -441,45 +444,57 @@ bool BladerfInput::applySettings(const Settings& settings, bool force) } } + if (m_settings.m_centerFrequency != settings.m_centerFrequency) + { + forwardChange = true; + } + m_settings.m_centerFrequency = settings.m_centerFrequency; - qint64 centerFrequency = m_settings.m_centerFrequency; - qint64 f_img = centerFrequency; - qint64 f_cut = centerFrequency + m_settings.m_bandwidth/2; + qint64 deviceCenterFrequency = m_settings.m_centerFrequency; + qint64 f_img = deviceCenterFrequency; + qint64 f_cut = deviceCenterFrequency + m_settings.m_bandwidth/2; if ((m_settings.m_log2Decim == 0) || (m_settings.m_fcPos == FC_POS_CENTER)) { - centerFrequency = m_settings.m_centerFrequency; - f_img = centerFrequency; - f_cut = centerFrequency + m_settings.m_bandwidth/2; + deviceCenterFrequency = m_settings.m_centerFrequency; + f_img = deviceCenterFrequency; + f_cut = deviceCenterFrequency + m_settings.m_bandwidth/2; } else { if (m_settings.m_fcPos == FC_POS_INFRA) { - centerFrequency = m_settings.m_centerFrequency + (m_settings.m_devSampleRate / 4); - f_img = centerFrequency + m_settings.m_devSampleRate/2; - f_cut = centerFrequency + m_settings.m_bandwidth/2; + deviceCenterFrequency = m_settings.m_centerFrequency + (m_settings.m_devSampleRate / 4); + f_img = deviceCenterFrequency + m_settings.m_devSampleRate/2; + f_cut = deviceCenterFrequency + m_settings.m_bandwidth/2; } else if (m_settings.m_fcPos == FC_POS_SUPRA) { - centerFrequency = m_settings.m_centerFrequency - (m_settings.m_devSampleRate / 4); - f_img = centerFrequency - m_settings.m_devSampleRate/2; - f_cut = centerFrequency - m_settings.m_bandwidth/2; + deviceCenterFrequency = m_settings.m_centerFrequency - (m_settings.m_devSampleRate / 4); + f_img = deviceCenterFrequency - m_settings.m_devSampleRate/2; + f_cut = deviceCenterFrequency - m_settings.m_bandwidth/2; } } if (m_dev != NULL) { - if (bladerf_set_frequency( m_dev, BLADERF_MODULE_RX, centerFrequency ) != 0) + if (bladerf_set_frequency( m_dev, BLADERF_MODULE_RX, deviceCenterFrequency ) != 0) { qDebug("bladerf_set_frequency(%lld) failed", m_settings.m_centerFrequency); } } - qDebug() << " - center freq: " << m_settings.m_centerFrequency << " Hz" - << " RF center freq: " << centerFrequency << " Hz" - << " RF sample rate: " << m_settings.m_devSampleRate << "Hz" + if (forwardChange) + { + int sampleRate = m_settings.m_devSampleRate/(1<push(notif); + } + + qDebug() << "BladerfInput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz" + << " device center freq: " << deviceCenterFrequency << " Hz" + << " device sample rate: " << m_settings.m_devSampleRate << "Hz" << " Actual sample rate: " << m_settings.m_devSampleRate/(1<sendWaitSink(notif); } - // pass sample rate to main window + // pass data to listeners - DSPEngineReport* rep = new DSPEngineReport(m_sampleRate, m_centerFrequency); + DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy for the output queue m_outputMessageQueue.push(rep); return StReady; @@ -653,25 +653,25 @@ void DSPEngine::handleSourceMessages() m_sampleRate = notif->getSampleRate(); m_centerFrequency = notif->getFrequencyOffset(); - qDebug() << " - DSPSignalNotification(" << m_sampleRate << "," << m_centerFrequency << ")"; + qDebug() << "DSPEngine::handleSourceMessages: DSPSignalNotification(" << m_sampleRate << "," << m_centerFrequency << ")"; - // forward source changes to sinks + // forward source changes to sinks with immediate execution for(SampleSinks::const_iterator it = m_sampleSinks.begin(); it != m_sampleSinks.end(); it++) { - qDebug() << " - forward message to " << (*it)->objectName().toStdString().c_str(); + qDebug() << "DSPEngine::handleSourceMessages: forward message to " << (*it)->objectName().toStdString().c_str(); (*it)->handleMessage(*message); } for (ThreadedSampleSinks::const_iterator it = m_threadedSampleSinks.begin(); it != m_threadedSampleSinks.end(); ++it) { - qDebug() << " - forward message to ThreadedSampleSink(" << (*it)->getSampleSinkObjectName().toStdString().c_str() << ")"; + qDebug() << "DSPEngine::handleSourceMessages: forward message to ThreadedSampleSink(" << (*it)->getSampleSinkObjectName().toStdString().c_str() << ")"; (*it)->sendWaitSink(*message); } - // forward changes to listeners + // forward changes to listeners on DSP output queue - DSPEngineReport* rep = new DSPEngineReport(m_sampleRate, m_centerFrequency); + DSPSignalNotification* rep = new DSPSignalNotification(*notif); // make a copy for the output queue m_outputMessageQueue.push(rep); } diff --git a/sdrbase/mainwindow.cpp b/sdrbase/mainwindow.cpp index b50e95677..c7669049d 100644 --- a/sdrbase/mainwindow.cpp +++ b/sdrbase/mainwindow.cpp @@ -338,16 +338,16 @@ void MainWindow::handleDSPMessages() std::cerr << "MainWindow::handleDSPMessages: " << message->getIdentifier() << std::endl; - if (DSPEngineReport::match(*message)) + if (DSPSignalNotification::match(*message)) { - DSPEngineReport* rep = (DSPEngineReport*) message; - m_sampleRate = rep->getSampleRate(); - m_centerFrequency = rep->getCenterFrequency(); - qDebug("SampleRate:%d, CenterFrequency:%llu", rep->getSampleRate(), rep->getCenterFrequency()); + DSPSignalNotification* notif = (DSPSignalNotification*) message; + m_sampleRate = notif->getSampleRate(); + m_centerFrequency = notif->getFrequencyOffset(); + qDebug("SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getFrequencyOffset()); updateCenterFreqDisplay(); updateSampleRate(); - qDebug() << "MainWindow::handleMessages: m_fileSink->configure"; - m_fileSink->configure(m_fileSink->getInputMessageQueue(), m_sampleFileName); + qDebug() << "MainWindow::handleDSPMessages: forward to file sink"; + m_fileSink->handleMessage(*notif); } delete message;