mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-15 12:51:49 -05:00
Deep redesign: fixed RTLSDR input plugin
This commit is contained in:
parent
a68104ab65
commit
5a0668f9ec
@ -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
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include <QObject>
|
||||
#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")
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <QObject>
|
||||
#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")
|
||||
|
@ -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);
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include <QObject>
|
||||
#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")
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <QDebug>
|
||||
#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)
|
||||
{
|
||||
|
@ -49,6 +49,7 @@ private slots:
|
||||
void on_samplerate_valueChanged(int value);
|
||||
void on_checkBox_stateChanged(int state);
|
||||
void updateHardware();
|
||||
void HandleSourceMessages();
|
||||
};
|
||||
|
||||
class RTLSDRSampleRates {
|
||||
|
@ -15,6 +15,7 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QDebug>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <QObject>
|
||||
#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")
|
||||
|
@ -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,22 +635,24 @@ void DSPEngine::handleInputMessages()
|
||||
m_qRange = 1 << 16;
|
||||
m_imbalance = 65536;
|
||||
}
|
||||
}
|
||||
|
||||
delete message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,10 +680,10 @@ void DSPEngine::handleSourceMessages()
|
||||
|
||||
DSPSignalNotification* rep = new DSPSignalNotification(*notif); // make a copy for the output queue
|
||||
m_outputMessageQueue.push(rep);
|
||||
}
|
||||
|
||||
delete message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DSPEngine::setAudioSampleRate(uint rate)
|
||||
|
@ -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,10 +349,10 @@ void MainWindow::handleDSPMessages()
|
||||
updateSampleRate();
|
||||
qDebug() << "MainWindow::handleDSPMessages: forward to file sink";
|
||||
m_fileSink->handleMessage(*notif);
|
||||
}
|
||||
|
||||
delete message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::handleMessages()
|
||||
|
@ -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))
|
||||
{
|
||||
if (fileName.endsWith(".so"))
|
||||
{
|
||||
qDebug() << "PluginManager::loadPlugins: fileName: " << qPrintable(fileName);
|
||||
|
||||
QPluginLoader* loader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName));
|
||||
PluginInterface* plugin = qobject_cast<PluginInterface*>(loader->instance());
|
||||
|
||||
if (loader->isLoaded()) {
|
||||
qWarning("loaded plugin %s", qPrintable(fileName));
|
||||
if (loader->isLoaded())
|
||||
{
|
||||
qWarning("PluginManager::loadPlugins: loaded plugin %s", qPrintable(fileName));
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "PluginManager::loadPlugins: " << qPrintable(loader->errorString());
|
||||
}
|
||||
|
||||
if (plugin != NULL) {
|
||||
if (plugin != 0)
|
||||
{
|
||||
m_plugins.append(Plugin(fileName, loader, plugin));
|
||||
} else {
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user