From 5a0668f9ecd01e21f3870793e3a855b281ef2499 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 26 Aug 2015 02:03:20 +0200 Subject: [PATCH] Deep redesign: fixed RTLSDR input plugin --- include/dsp/samplesource.h | 6 ++- plugins/samplesource/bladerf/bladerfplugin.h | 2 +- plugins/samplesource/fcd/fcdplugin.h | 2 +- .../filesource/filesourceinput.cpp | 5 +++ .../filesource/filesourceplugin.h | 2 +- plugins/samplesource/rtlsdr/rtlsdrgui.cpp | 22 +++++++++- plugins/samplesource/rtlsdr/rtlsdrgui.h | 1 + plugins/samplesource/rtlsdr/rtlsdrinput.cpp | 41 ++++++++++-------- plugins/samplesource/rtlsdr/rtlsdrplugin.h | 2 +- sdrbase/dsp/dspengine.cpp | 16 ++++--- sdrbase/mainwindow.cpp | 6 ++- sdrbase/plugin/pluginmanager.cpp | 43 +++++++++++++------ 12 files changed, 102 insertions(+), 46 deletions(-) diff --git a/include/dsp/samplesource.h b/include/dsp/samplesource.h index 1bf5f76c1..1eb52aa31 100644 --- a/include/dsp/samplesource.h +++ b/include/dsp/samplesource.h @@ -42,6 +42,7 @@ public: MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } MessageQueue *getOutputMessageQueue() { return &m_outputMessageQueue; } + MessageQueue *getOutputMessageQueueToGUI() { return &m_outputMessageQueueToGUI; } SampleFifo* getSampleFifo() { return &m_sampleFifo; } protected slots: @@ -49,8 +50,9 @@ protected slots: protected: SampleFifo m_sampleFifo; - MessageQueue m_inputMessageQueue; - MessageQueue m_outputMessageQueue; + MessageQueue m_inputMessageQueue; //!< Input queue to the source + MessageQueue m_outputMessageQueue; //!< Generic output queue + MessageQueue m_outputMessageQueueToGUI; //!< Output queue specialized for the source GUI }; #endif // INCLUDE_SAMPLESOURCE_H diff --git a/plugins/samplesource/bladerf/bladerfplugin.h b/plugins/samplesource/bladerf/bladerfplugin.h index c2b22ae41..ad3860048 100644 --- a/plugins/samplesource/bladerf/bladerfplugin.h +++ b/plugins/samplesource/bladerf/bladerfplugin.h @@ -20,7 +20,7 @@ #include #include "plugin/plugininterface.h" -class BlderfPlugin : public QObject, PluginInterface { +class BlderfPlugin : public QObject, public PluginInterface { Q_OBJECT Q_INTERFACES(PluginInterface) Q_PLUGIN_METADATA(IID "org.osmocom.sdr.samplesource.bladerf") diff --git a/plugins/samplesource/fcd/fcdplugin.h b/plugins/samplesource/fcd/fcdplugin.h index e8ef29757..cfa549ff2 100644 --- a/plugins/samplesource/fcd/fcdplugin.h +++ b/plugins/samplesource/fcd/fcdplugin.h @@ -4,7 +4,7 @@ #include #include "plugin/plugininterface.h" -class FCDPlugin : public QObject, PluginInterface { +class FCDPlugin : public QObject, public PluginInterface { Q_OBJECT Q_INTERFACES(PluginInterface) Q_PLUGIN_METADATA(IID "org.osmocom.sdr.samplesource.fcd") diff --git a/plugins/samplesource/filesource/filesourceinput.cpp b/plugins/samplesource/filesource/filesourceinput.cpp index 7506d77a9..55f331bab 100644 --- a/plugins/samplesource/filesource/filesourceinput.cpp +++ b/plugins/samplesource/filesource/filesourceinput.cpp @@ -109,6 +109,11 @@ void FileSourceInput::openFileStream() getOutputMessageQueue()->push(report); } +bool FileSourceInput::init(const Message& message) +{ + return false; +} + bool FileSourceInput::start(int device) { QMutexLocker mutexLocker(&m_mutex); diff --git a/plugins/samplesource/filesource/filesourceplugin.h b/plugins/samplesource/filesource/filesourceplugin.h index 3ec8e13a2..666ec930c 100644 --- a/plugins/samplesource/filesource/filesourceplugin.h +++ b/plugins/samplesource/filesource/filesourceplugin.h @@ -20,7 +20,7 @@ #include #include "plugin/plugininterface.h" -class FileSourcePlugin : public QObject, PluginInterface { +class FileSourcePlugin : public QObject, public PluginInterface { Q_OBJECT Q_INTERFACES(PluginInterface) Q_PLUGIN_METADATA(IID "org.osmocom.sdr.samplesource.filesource") diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp index 360faa057..c17cbbefb 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp @@ -1,3 +1,4 @@ +#include #include "rtlsdrgui.h" #include "ui_rtlsdrgui.h" #include "plugin/pluginapi.h" @@ -18,6 +19,7 @@ RTLSDRGui::RTLSDRGui(PluginAPI* pluginAPI, QWidget* parent) : displaySettings(); m_sampleSource = new RTLSDRInput(); + connect(m_sampleSource->getOutputMessageQueueToGUI(), SIGNAL(messageEnqueued()), this, SLOT(HandleSourceMessages())); DSPEngine::instance()->setSource(m_sampleSource); } @@ -77,6 +79,7 @@ bool RTLSDRGui::handleMessage(const Message& message) { if (RTLSDRInput::MsgReportRTLSDR::match(message)) { + qDebug() << "RTLSDRGui::handleMessage: MsgReportRTLSDR"; m_gains = ((RTLSDRInput::MsgReportRTLSDR&) message).getGains(); displaySettings(); return true; @@ -87,6 +90,21 @@ bool RTLSDRGui::handleMessage(const Message& message) } } +void RTLSDRGui::HandleSourceMessages() +{ + Message* message; + + while ((message = m_sampleSource->getOutputMessageQueueToGUI()->pop()) != 0) + { + qDebug("RTLSDRGui::HandleSourceMessages: message: %s", message->getIdentifier()); + + if (handleMessage(*message)) + { + delete message; + } + } +} + void RTLSDRGui::displaySettings() { ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); @@ -219,8 +237,8 @@ void RTLSDRGui::on_checkBox_stateChanged(int state) sendSettings(); } -unsigned int RTLSDRSampleRates::m_rates[] = {288, 1024, 1536, 1152, 2048, 2500 }; -unsigned int RTLSDRSampleRates::m_nb_rates = 6; +unsigned int RTLSDRSampleRates::m_rates[] = {288, 1152, 1536, 2304}; +unsigned int RTLSDRSampleRates::m_nb_rates = 4; unsigned int RTLSDRSampleRates::getRate(unsigned int rate_index) { diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.h b/plugins/samplesource/rtlsdr/rtlsdrgui.h index 03a3cc3cb..a06aba748 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.h +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.h @@ -49,6 +49,7 @@ private slots: void on_samplerate_valueChanged(int value); void on_checkBox_stateChanged(int state); void updateHardware(); + void HandleSourceMessages(); }; class RTLSDRSampleRates { diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp index 869926add..f0c2d0e79 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// +#include #include #include #include "rtlsdrinput.h" @@ -94,6 +95,11 @@ RTLSDRInput::~RTLSDRInput() stop(); } +bool RTLSDRInput::init(const Message& message) +{ + return false; +} + bool RTLSDRInput::start(int device) { QMutexLocker mutexLocker(&m_mutex); @@ -111,13 +117,13 @@ bool RTLSDRInput::start(int device) if (!m_sampleFifo.setSize(96000 * 4)) { - qCritical("Could not allocate SampleFifo"); + qCritical("RTLSDRInput::start: Could not allocate SampleFifo"); return false; } if ((res = rtlsdr_open(&m_dev, device)) < 0) { - qCritical("could not open RTLSDR #%d: %s", device, strerror(errno)); + qCritical("RTLSDRInput::start: could not open RTLSDR #%d: %s", device, strerror(errno)); return false; } @@ -127,31 +133,31 @@ bool RTLSDRInput::start(int device) if ((res = rtlsdr_get_usb_strings(m_dev, vendor, product, serial)) < 0) { - qCritical("error accessing USB device"); + qCritical("RTLSDRInput::start: error accessing USB device"); stop(); return false; } - qWarning("RTLSDRInput open: %s %s, SN: %s", vendor, product, serial); + qWarning("RTLSDRInput::start: open: %s %s, SN: %s", vendor, product, serial); m_deviceDescription = QString("%1 (SN %2)").arg(product).arg(serial); - if ((res = rtlsdr_set_sample_rate(m_dev, 1024000)) < 0) + if ((res = rtlsdr_set_sample_rate(m_dev, 1152000)) < 0) { - qCritical("could not set sample rate: 1024k S/s"); + qCritical("RTLSDRInput::start: could not set sample rate: 1024k S/s"); stop(); return false; } if ((res = rtlsdr_set_tuner_gain_mode(m_dev, 1)) < 0) { - qCritical("error setting tuner gain mode"); + qCritical("RTLSDRInput::start: error setting tuner gain mode"); stop(); return false; } if ((res = rtlsdr_set_agc_mode(m_dev, 0)) < 0) { - qCritical("error setting agc mode"); + qCritical("RTLSDRInput::start: error setting agc mode"); stop(); return false; } @@ -160,7 +166,7 @@ bool RTLSDRInput::start(int device) if (numberOfGains < 0) { - qCritical("error getting number of gain values supported"); + qCritical("RTLSDRInput::start: error getting number of gain values supported"); stop(); return false; } @@ -169,21 +175,27 @@ bool RTLSDRInput::start(int device) if (rtlsdr_get_tuner_gains(m_dev, &m_gains[0]) < 0) { - qCritical("error getting gain values"); + qCritical("RTLSDRInput::start: error getting gain values"); stop(); return false; } + else + { + qDebug() << "RTLSDRInput::start: " << m_gains.size() << "gains"; + MsgReportRTLSDR *message = MsgReportRTLSDR::create(m_gains); + getOutputMessageQueueToGUI()->push(message); + } if ((res = rtlsdr_reset_buffer(m_dev)) < 0) { - qCritical("could not reset USB EP buffers: %s", strerror(errno)); + qCritical("RTLSDRInput::start: could not reset USB EP buffers: %s", strerror(errno)); stop(); return false; } if ((m_rtlSDRThread = new RTLSDRThread(m_dev, &m_sampleFifo)) == NULL) { - qFatal("out of memory"); + qFatal("RTLSDRInput::start: out of memory"); stop(); return false; } @@ -194,11 +206,6 @@ bool RTLSDRInput::start(int device) applySettings(m_settings, true); - qDebug("RTLSDRInput::start"); - - MsgReportRTLSDR *message = MsgReportRTLSDR::create(m_gains); - getOutputMessageQueue()->push(message); - return true; } diff --git a/plugins/samplesource/rtlsdr/rtlsdrplugin.h b/plugins/samplesource/rtlsdr/rtlsdrplugin.h index 203889e98..3775daa7e 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrplugin.h +++ b/plugins/samplesource/rtlsdr/rtlsdrplugin.h @@ -4,7 +4,7 @@ #include #include "plugin/plugininterface.h" -class RTLSDRPlugin : public QObject, PluginInterface { +class RTLSDRPlugin : public QObject, public PluginInterface { Q_OBJECT Q_INTERFACES(PluginInterface) Q_PLUGIN_METADATA(IID "org.osmocom.sdr.samplesource.rtl-sdr") diff --git a/sdrbase/dsp/dspengine.cpp b/sdrbase/dsp/dspengine.cpp index 11da2d18e..b256f3b74 100644 --- a/sdrbase/dsp/dspengine.cpp +++ b/sdrbase/dsp/dspengine.cpp @@ -614,7 +614,7 @@ void DSPEngine::handleInputMessages() while ((message = m_inputMessageQueue.pop()) != 0) { - qDebug(" - message: %s", message->getIdentifier()); + qDebug("DSPEngine::handleInputMessages: message: %s", message->getIdentifier()); if (DSPConfigureCorrection::match(*message)) { @@ -635,9 +635,9 @@ void DSPEngine::handleInputMessages() m_qRange = 1 << 16; m_imbalance = 65536; } - } - delete message; + delete message; + } } } @@ -645,12 +645,14 @@ void DSPEngine::handleSourceMessages() { Message *message; - qDebug() << "DSPEngine::handleSourceMessages"; - while ((message = m_sampleSource->getOutputMessageQueue()->pop()) != 0) { + qDebug() << "DSPEngine::handleSourceMessages: " << message->getIdentifier(); + if (DSPSignalNotification::match(*message)) { + qDebug() << "DSPEngine::handleSourceMessages: process DSPSignalNotification"; + DSPSignalNotification *notif = (DSPSignalNotification *) message; // update DSP values @@ -678,9 +680,9 @@ void DSPEngine::handleSourceMessages() DSPSignalNotification* rep = new DSPSignalNotification(*notif); // make a copy for the output queue m_outputMessageQueue.push(rep); - } - delete message; + delete message; + } } } diff --git a/sdrbase/mainwindow.cpp b/sdrbase/mainwindow.cpp index 56ccec626..4fedce954 100644 --- a/sdrbase/mainwindow.cpp +++ b/sdrbase/mainwindow.cpp @@ -93,6 +93,8 @@ MainWindow::MainWindow(QWidget* parent) : m_masterTimer.start(50); + qDebug() << "MainWindow::MainWindow: m_pluginManager->loadPlugins ..."; + m_pluginManager->loadPlugins(); bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true); @@ -347,9 +349,9 @@ void MainWindow::handleDSPMessages() updateSampleRate(); qDebug() << "MainWindow::handleDSPMessages: forward to file sink"; m_fileSink->handleMessage(*notif); - } - delete message; + delete message; + } } } diff --git a/sdrbase/plugin/pluginmanager.cpp b/sdrbase/plugin/pluginmanager.cpp index 3ec6a52ab..d295a8bf6 100644 --- a/sdrbase/plugin/pluginmanager.cpp +++ b/sdrbase/plugin/pluginmanager.cpp @@ -28,13 +28,16 @@ PluginManager::~PluginManager() void PluginManager::loadPlugins() { + qDebug() << "PluginManager::loadPlugins: " << qPrintable(QApplication::instance()->applicationDirPath()); + QDir pluginsDir = QDir(QApplication::instance()->applicationDirPath()); loadPlugins(pluginsDir); qSort(m_plugins); - for(Plugins::const_iterator it = m_plugins.begin(); it != m_plugins.end(); ++it) { + for (Plugins::const_iterator it = m_plugins.begin(); it != m_plugins.end(); ++it) + { it->plugin->initPlugin(&m_pluginAPI); } @@ -321,22 +324,38 @@ void PluginManager::loadPlugins(const QDir& dir) foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { - QPluginLoader* loader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName)); - PluginInterface* plugin = qobject_cast(loader->instance()); + if (fileName.endsWith(".so")) + { + qDebug() << "PluginManager::loadPlugins: fileName: " << qPrintable(fileName); - if (loader->isLoaded()) { - qWarning("loaded plugin %s", qPrintable(fileName)); - } + QPluginLoader* loader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName)); + PluginInterface* plugin = qobject_cast(loader->instance()); - if (plugin != NULL) { - m_plugins.append(Plugin(fileName, loader, plugin)); - } else { - loader->unload(); - delete loader; + if (loader->isLoaded()) + { + qWarning("PluginManager::loadPlugins: loaded plugin %s", qPrintable(fileName)); + } + else + { + qWarning() << "PluginManager::loadPlugins: " << qPrintable(loader->errorString()); + } + + if (plugin != 0) + { + m_plugins.append(Plugin(fileName, loader, plugin)); + } + else + { + loader->unload(); + delete loader; + } } } - foreach (QString dirName, pluginsDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { + // recursive calls on subdirectories + + foreach (QString dirName, pluginsDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) + { loadPlugins(pluginsDir.absoluteFilePath(dirName)); } }