| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2016 Edouard Griffiths, F4EXB                                   //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 06:57:41 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QtPlugin>
 | 
					
						
							| 
									
										
										
										
											2016-11-15 15:57:13 +01:00
										 |  |  | #include <mirisdr.h>
 | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  | #include "plugin/pluginapi.h"
 | 
					
						
							|  |  |  | #include "util/simpleserializer.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-09 12:10:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:52:44 +02:00
										 |  |  | #ifdef SERVER_MODE
 | 
					
						
							|  |  |  | #include "sdrplayinput.h"
 | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  | #include "sdrplaygui.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:52:44 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  | #include "sdrplayplugin.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  | #include "sdrplaywebapiadapter.h"
 | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const PluginDescriptor SDRPlayPlugin::m_pluginDescriptor = { | 
					
						
							| 
									
										
										
										
											2020-11-21 15:38:04 +01:00
										 |  |  |     QStringLiteral("SDRPlay"), | 
					
						
							|  |  |  |     QStringLiteral("SDRPlay RSP1 Input"), | 
					
						
							|  |  |  |     QStringLiteral("4.19.0"), | 
					
						
							|  |  |  |     QStringLiteral("(c) Edouard Griffiths, F4EXB"), | 
					
						
							|  |  |  |     QStringLiteral("https://github.com/f4exb/sdrangel"), | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  |     true, | 
					
						
							| 
									
										
										
										
											2020-11-21 15:38:04 +01:00
										 |  |  |     QStringLiteral("https://github.com/f4exb/sdrangel") | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 20:24:18 +01:00
										 |  |  | static constexpr const char* const m_hardwareID = "SDRplay1"; | 
					
						
							|  |  |  | static constexpr const char* const m_deviceTypeID = SDRPLAY_DEVICE_TYPE_ID; | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | SDRPlayPlugin::SDRPlayPlugin(QObject* parent) : | 
					
						
							|  |  |  |     QObject(parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const PluginDescriptor& SDRPlayPlugin::getPluginDescriptor() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_pluginDescriptor; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SDRPlayPlugin::initPlugin(PluginAPI* pluginAPI) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     pluginAPI->registerSampleSource(m_deviceTypeID, this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | void SDRPlayPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices) | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  |     if (listedHwIds.contains(m_hardwareID)) { // check if it was done
 | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-15 15:57:13 +01:00
										 |  |  | 	int count = mirisdr_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'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (mirisdr_get_device_usb_strings((uint32_t)i, vendor, product, serial) != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		qDebug("SDRPlayPlugin::enumSampleSources: found %s:%s (%s)", vendor, product, serial); | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | 		QString displayableName(QString("SDRPlay[%1] %2").arg(i).arg(serial)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         originDevices.append(OriginDevice( | 
					
						
							|  |  |  |             displayableName, | 
					
						
							|  |  |  |             m_hardwareID, | 
					
						
							|  |  |  |             serial, | 
					
						
							|  |  |  |             i, // sequence
 | 
					
						
							|  |  |  |             1, // Nb Rx
 | 
					
						
							|  |  |  |             0  // Nb Tx
 | 
					
						
							|  |  |  |         )); | 
					
						
							| 
									
										
										
										
											2016-11-15 15:57:13 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-11-14 18:06:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  |     listedHwIds.append(m_hardwareID); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PluginInterface::SamplingDevices SDRPlayPlugin::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("SDRPlayPlugin::enumSampleSources: enumerated SDRPlay RSP1 device #%d", it->sequence); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return result; | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:52:44 +02:00
										 |  |  | #ifdef SERVER_MODE
 | 
					
						
							| 
									
										
										
										
											2020-10-05 19:23:13 +02:00
										 |  |  | DeviceGUI* SDRPlayPlugin::createSampleSourcePluginInstanceGUI( | 
					
						
							| 
									
										
										
										
											2019-05-24 09:37:13 +02:00
										 |  |  |         const QString& sourceId, | 
					
						
							|  |  |  |         QWidget **widget, | 
					
						
							|  |  |  |         DeviceUISet *deviceUISet) | 
					
						
							| 
									
										
										
										
											2018-05-29 20:52:44 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-19 18:50:55 +02:00
										 |  |  |     (void) sourceId; | 
					
						
							|  |  |  |     (void) widget; | 
					
						
							|  |  |  |     (void) deviceUISet; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:52:44 +02:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2020-10-05 19:23:13 +02:00
										 |  |  | DeviceGUI* SDRPlayPlugin::createSampleSourcePluginInstanceGUI( | 
					
						
							| 
									
										
										
										
											2017-10-30 00:02:28 +01:00
										 |  |  |         const QString& sourceId, | 
					
						
							|  |  |  |         QWidget **widget, | 
					
						
							|  |  |  |         DeviceUISet *deviceUISet) | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     if(sourceId == m_deviceTypeID) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-10-30 00:45:23 +01:00
										 |  |  |         SDRPlayGui* gui = new SDRPlayGui(deviceUISet); | 
					
						
							| 
									
										
										
										
											2016-11-13 02:59:31 +01:00
										 |  |  |         *widget = gui; | 
					
						
							|  |  |  |         return gui; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-05-29 20:52:44 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-09-14 13:34:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-19 10:28:50 +02:00
										 |  |  | DeviceSampleSource *SDRPlayPlugin::createSampleSourcePluginInstance(const QString& sourceId, DeviceAPI *deviceAPI) | 
					
						
							| 
									
										
										
										
											2017-09-14 13:34:32 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (sourceId == m_deviceTypeID) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         SDRPlayInput* input = new SDRPlayInput(deviceAPI); | 
					
						
							|  |  |  |         return input; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  | DeviceWebAPIAdapter *SDRPlayPlugin::createDeviceWebAPIAdapter() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return new SDRPlayWebAPIAdapter(); | 
					
						
							|  |  |  | } |