| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include <QtPlugin>
 | 
					
						
							|  |  |  | #include <rtl-sdr.h>
 | 
					
						
							| 
									
										
										
										
											2017-12-29 00:33:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "plugin/pluginapi.h"
 | 
					
						
							|  |  |  | #include "util/simpleserializer.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:17:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-29 00:33:37 +01:00
										 |  |  | #ifdef SERVER_MODE
 | 
					
						
							|  |  |  | #include "rtlsdrinput.h"
 | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "rtlsdrgui.h"
 | 
					
						
							| 
									
										
										
										
											2017-12-29 00:33:37 +01:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | #include "rtlsdrplugin.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  | #include "rtlsdrwebapiadapter.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const PluginDescriptor RTLSDRPlugin::m_pluginDescriptor = { | 
					
						
							| 
									
										
										
										
											2019-12-16 01:03:47 +01:00
										 |  |  |     QString("RTLSDR"), | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	QString("RTL-SDR Input"), | 
					
						
							| 
									
										
										
										
											2020-06-27 10:52:43 +02:00
										 |  |  | 	QString("4.14.12"), | 
					
						
							| 
									
										
										
										
											2015-09-02 01:16:40 +02:00
										 |  |  | 	QString("(c) Edouard Griffiths, F4EXB"), | 
					
						
							|  |  |  | 	QString("https://github.com/f4exb/sdrangel"), | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	true, | 
					
						
							| 
									
										
										
										
											2015-09-02 01:16:40 +02:00
										 |  |  | 	QString("https://github.com/f4exb/sdrangel") | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-29 12:41:10 +01:00
										 |  |  | const QString RTLSDRPlugin::m_hardwareID = "RTLSDR"; | 
					
						
							| 
									
										
										
										
											2015-10-01 05:05:46 +02:00
										 |  |  | const QString RTLSDRPlugin::m_deviceTypeID = RTLSDR_DEVICE_TYPE_ID; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | RTLSDRPlugin::RTLSDRPlugin(QObject* parent) : | 
					
						
							|  |  |  | 	QObject(parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const PluginDescriptor& RTLSDRPlugin::getPluginDescriptor() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_pluginDescriptor; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RTLSDRPlugin::initPlugin(PluginAPI* pluginAPI) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-17 17:53:22 +02:00
										 |  |  | 	pluginAPI->registerSampleSource(m_deviceTypeID, this); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | void RTLSDRPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  |     if (listedHwIds.contains(m_hardwareID)) { // check if it was done
 | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	int count = rtlsdr_get_device_count(); | 
					
						
							|  |  |  | 	char vendor[256]; | 
					
						
							|  |  |  | 	char product[256]; | 
					
						
							|  |  |  | 	char serial[256]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | 	for(int i = 0; i < count; i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		vendor[0] = '\0'; | 
					
						
							|  |  |  | 		product[0] = '\0'; | 
					
						
							|  |  |  | 		serial[0] = '\0'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-03 17:11:08 +00:00
										 |  |  | 		if(rtlsdr_get_device_usb_strings((uint32_t)i, vendor, product, serial) != 0) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | 		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
 | 
					
						
							|  |  |  |         )); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-17 14:52:18 +01:00
										 |  |  | #ifdef SERVER_MODE
 | 
					
						
							|  |  |  | PluginInstanceGUI* RTLSDRPlugin::createSampleSourcePluginInstanceGUI( | 
					
						
							| 
									
										
										
										
											2019-05-24 09:37:13 +02:00
										 |  |  |         const QString& sourceId, | 
					
						
							|  |  |  |         QWidget **widget, | 
					
						
							|  |  |  |         DeviceUISet *deviceUISet) | 
					
						
							| 
									
										
										
										
											2017-12-17 14:52:18 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-19 18:50:55 +02:00
										 |  |  |     (void) sourceId; | 
					
						
							|  |  |  |     (void) widget; | 
					
						
							|  |  |  |     (void) deviceUISet; | 
					
						
							| 
									
										
										
										
											2017-12-17 14:52:18 +01:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2017-10-30 00:02:28 +01:00
										 |  |  | PluginInstanceGUI* RTLSDRPlugin::createSampleSourcePluginInstanceGUI( | 
					
						
							|  |  |  |         const QString& sourceId, | 
					
						
							|  |  |  |         QWidget **widget, | 
					
						
							|  |  |  |         DeviceUISet *deviceUISet) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-01 05:05:46 +02:00
										 |  |  | 	if(sourceId == m_deviceTypeID) { | 
					
						
							| 
									
										
										
										
											2017-10-30 00:45:23 +01:00
										 |  |  | 		RTLSDRGui* gui = new RTLSDRGui(deviceUISet); | 
					
						
							| 
									
										
										
										
											2016-05-17 03:41:01 +02:00
										 |  |  | 		*widget = gui; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		return gui; | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-09-14 13:34:32 +02:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-12-17 14:52:18 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-09-14 13:34:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-19 10:28:50 +02:00
										 |  |  | DeviceSampleSource *RTLSDRPlugin::createSampleSourcePluginInstance(const QString& sourceId, DeviceAPI *deviceAPI) | 
					
						
							| 
									
										
										
										
											2017-09-14 13:34:32 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (sourceId == m_deviceTypeID) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         RTLSDRInput* input = new RTLSDRInput(deviceAPI); | 
					
						
							|  |  |  |         return input; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  | DeviceWebAPIAdapter *RTLSDRPlugin::createDeviceWebAPIAdapter() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return new RTLSDRWebAPIAdapter(); | 
					
						
							|  |  |  | } |