1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-30 03:38:55 -05:00
sdrangel/plugins/samplesource/rtlsdr/rtlsdrplugin.cpp

147 lines
3.5 KiB
C++
Raw Normal View History

#include <QtPlugin>
#include <rtl-sdr.h>
2017-12-28 18:33:37 -05:00
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
2017-12-28 18:33:37 -05:00
#ifdef SERVER_MODE
#include "rtlsdrinput.h"
#else
#include "rtlsdrgui.h"
2017-12-28 18:33:37 -05:00
#endif
#include "rtlsdrplugin.h"
#include "rtlsdrwebapiadapter.h"
const PluginDescriptor RTLSDRPlugin::m_pluginDescriptor = {
2020-11-21 09:38:04 -05:00
QStringLiteral("RTLSDR"),
QStringLiteral("RTL-SDR Input"),
2022-03-30 16:16:08 -04:00
QStringLiteral("6.20.2"),
2020-11-21 09:38:04 -05:00
QStringLiteral("(c) Edouard Griffiths, F4EXB"),
QStringLiteral("https://github.com/f4exb/sdrangel"),
true,
2020-11-21 09:38:04 -05:00
QStringLiteral("https://github.com/f4exb/sdrangel")
};
static constexpr const char* const m_hardwareID = "RTLSDR";
static constexpr const char* const m_deviceTypeID = RTLSDR_DEVICE_TYPE_ID;
RTLSDRPlugin::RTLSDRPlugin(QObject* parent) :
QObject(parent)
{
}
const PluginDescriptor& RTLSDRPlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void RTLSDRPlugin::initPlugin(PluginAPI* pluginAPI)
{
pluginAPI->registerSampleSource(m_deviceTypeID, this);
}
void RTLSDRPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices)
{
if (listedHwIds.contains(m_hardwareID)) { // check if it was done
return;
}
int count = rtlsdr_get_device_count();
char vendor[256];
char product[256];
char serial[256];
for(int i = 0; i < count; i++)
{
vendor[0] = '\0';
product[0] = '\0';
serial[0] = '\0';
2014-11-03 12:11:08 -05:00
if(rtlsdr_get_device_usb_strings((uint32_t)i, vendor, product, serial) != 0)
continue;
QString displayableName(QString("RTL-SDR[%1] %2").arg(i).arg(serial));
originDevices.append(OriginDevice(
displayableName,
m_hardwareID,
serial,
i, // sequence
1, // Nb Rx
0 // Nb Tx
));
}
listedHwIds.append(m_hardwareID);
}
PluginInterface::SamplingDevices RTLSDRPlugin::enumSampleSources(const OriginDevices& originDevices)
{
SamplingDevices result;
for (OriginDevices::const_iterator it = originDevices.begin(); it != originDevices.end(); ++it)
{
if (it->hardwareId == m_hardwareID)
{
result.append(SamplingDevice(
it->displayableName,
it->hardwareId,
m_deviceTypeID,
it->serial,
it->sequence,
PluginInterface::SamplingDevice::PhysicalDevice,
PluginInterface::SamplingDevice::StreamSingleRx,
1,
0
));
qDebug("RTLSDRPlugin::enumSampleSources: enumerated RTL-SDR device #%d", it->sequence);
}
}
return result;
}
#ifdef SERVER_MODE
DeviceGUI* RTLSDRPlugin::createSampleSourcePluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet)
{
(void) sourceId;
(void) widget;
(void) deviceUISet;
return 0;
}
#else
DeviceGUI* RTLSDRPlugin::createSampleSourcePluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet)
{
if(sourceId == m_deviceTypeID) {
RTLSDRGui* gui = new RTLSDRGui(deviceUISet);
*widget = gui;
return gui;
} else {
return 0;
}
}
#endif
DeviceSampleSource *RTLSDRPlugin::createSampleSourcePluginInstance(const QString& sourceId, DeviceAPI *deviceAPI)
{
if (sourceId == m_deviceTypeID)
{
RTLSDRInput* input = new RTLSDRInput(deviceAPI);
return input;
}
else
{
return 0;
}
}
DeviceWebAPIAdapter *RTLSDRPlugin::createDeviceWebAPIAdapter() const
{
return new RTLSDRWebAPIAdapter();
}