| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-18 10:07:41 +01:00
										 |  |  | // Copyright (C) 2015-2023 Edouard Griffiths, F4EXB <f4exb06@gmail.com>          //
 | 
					
						
							|  |  |  | // Copyright (C) 2019 Davide Gerhard <rainbow@irh.it>                            //
 | 
					
						
							|  |  |  | // Copyright (C) 2020 Kacper Michajłow <kasper93@gmail.com>                      //
 | 
					
						
							|  |  |  | // Copyright (C) 2022 Jon Beniston, M7RCE <jon@beniston.com>                     //
 | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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.                                           //
 | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02: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>
 | 
					
						
							|  |  |  | #include <libairspy/airspy.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 16:48:41 +02:00
										 |  |  | #ifdef SERVER_MODE
 | 
					
						
							|  |  |  | #include "airspyinput.h"
 | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | #include "airspygui.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-29 16:48:41 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-08-03 11:21:46 +02:00
										 |  |  | #include "airspywebapiadapter.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | #include "airspyplugin.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:17:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | #include "plugin/pluginapi.h"
 | 
					
						
							| 
									
										
										
										
											2024-04-08 22:40:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-22 11:04:12 +00:00
										 |  |  | #ifdef ANDROID
 | 
					
						
							|  |  |  | #include "util/android.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-11 00:17:06 +01:00
										 |  |  | const int AirspyPlugin::m_maxDevices = 32; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | const PluginDescriptor AirspyPlugin::m_pluginDescriptor = { | 
					
						
							| 
									
										
										
										
											2020-11-21 15:38:04 +01:00
										 |  |  |     QStringLiteral("Airspy"), | 
					
						
							|  |  |  | 	QStringLiteral("Airspy Input"), | 
					
						
							| 
									
										
										
										
											2024-10-06 10:53:38 +02:00
										 |  |  |     QStringLiteral("7.22.1"), | 
					
						
							| 
									
										
										
										
											2020-11-21 15:38:04 +01:00
										 |  |  | 	QStringLiteral("(c) Edouard Griffiths, F4EXB"), | 
					
						
							|  |  |  | 	QStringLiteral("https://github.com/f4exb/sdrangel"), | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 	true, | 
					
						
							| 
									
										
										
										
											2020-11-21 15:38:04 +01:00
										 |  |  | 	QStringLiteral("https://github.com/f4exb/sdrangel") | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 20:24:18 +01:00
										 |  |  | static constexpr const char* const m_hardwareID = "Airspy"; | 
					
						
							|  |  |  | static constexpr const char* const m_deviceTypeID = AIRSPY_DEVICE_TYPE_ID; | 
					
						
							| 
									
										
										
										
											2015-09-30 13:53:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | AirspyPlugin::AirspyPlugin(QObject* parent) : | 
					
						
							| 
									
										
										
										
											2016-05-17 19:26:23 +02:00
										 |  |  | 	QObject(parent) | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const PluginDescriptor& AirspyPlugin::getPluginDescriptor() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_pluginDescriptor; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AirspyPlugin::initPlugin(PluginAPI* pluginAPI) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-17 19:26:23 +02:00
										 |  |  | 	pluginAPI->registerSampleSource(m_deviceTypeID, this); | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | void AirspyPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices) | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  |     if (listedHwIds.contains(m_hardwareID)) { // check if it was done
 | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-22 11:04:12 +00:00
										 |  |  | #ifdef ANDROID
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QStringList serialStrings = Android::listUSBDeviceSerials(0x1d50, 0x60a1); | 
					
						
							|  |  |  |     int deviceNo = 0; | 
					
						
							|  |  |  |     for (const auto serialString : serialStrings) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString displayableName(QString("Airspy[%1] %2").arg(deviceNo).arg(serialString)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         originDevices.append(OriginDevice( | 
					
						
							|  |  |  |             displayableName, | 
					
						
							|  |  |  |             m_hardwareID, | 
					
						
							|  |  |  |             serialString, | 
					
						
							|  |  |  |             deviceNo, | 
					
						
							|  |  |  |             1, | 
					
						
							|  |  |  |             0 | 
					
						
							|  |  |  |         )); | 
					
						
							|  |  |  |         deviceNo++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     listedHwIds.append(m_hardwareID); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 	airspy_read_partid_serialno_t read_partid_serialno; | 
					
						
							| 
									
										
										
										
											2015-09-11 03:02:02 +02:00
										 |  |  | 	struct airspy_device *devinfo; | 
					
						
							|  |  |  | 	uint32_t serial_msb = 0; | 
					
						
							|  |  |  | 	uint32_t serial_lsb = 0; | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 	airspy_error rc; | 
					
						
							| 
									
										
										
										
											2015-09-11 03:02:02 +02:00
										 |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-10 05:53:37 +02:00
										 |  |  | 	rc = (airspy_error) airspy_init(); | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (rc != AIRSPY_SUCCESS) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | 		qCritical("AirspyPlugin::enumOriginDevices: failed to initiate Airspy library: %s", airspy_error_name(rc)); | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-11 00:17:06 +01:00
										 |  |  | 	for (i=0; i < m_maxDevices; i++) | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-09-10 05:53:37 +02:00
										 |  |  | 		rc = (airspy_error) airspy_open(&devinfo); | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (rc == AIRSPY_SUCCESS) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | 			qDebug("AirspyPlugin::enumOriginDevices: try to enumerate Airspy device #%d", i); | 
					
						
							| 
									
										
										
										
											2015-09-11 03:02:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-10 05:53:37 +02:00
										 |  |  | 			rc = (airspy_error) airspy_board_partid_serialno_read(devinfo, &read_partid_serialno); | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (rc != AIRSPY_SUCCESS) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | 				qDebug("AirspyPlugin::enumOriginDevices: failed to read serial no: %s", airspy_error_name(rc)); | 
					
						
							| 
									
										
										
										
											2015-09-11 03:02:02 +02:00
										 |  |  | 				airspy_close(devinfo); | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 				continue; // next
 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 03:02:02 +02:00
										 |  |  | 			if ((read_partid_serialno.serial_no[2] != serial_msb) && (read_partid_serialno.serial_no[3] != serial_lsb)) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				serial_msb = read_partid_serialno.serial_no[2]; | 
					
						
							|  |  |  | 				serial_lsb = read_partid_serialno.serial_no[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				QString serial_str = QString::number(serial_msb, 16) + QString::number(serial_lsb, 16); | 
					
						
							| 
									
										
										
										
											2017-05-25 20:13:34 +02:00
										 |  |  | 				//uint64_t serial_num = (((uint64_t) serial_msb)<<32) + serial_lsb;
 | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | 				QString displayableName(QString("Airspy[%1] %2").arg(i).arg(serial_str)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 originDevices.append(OriginDevice( | 
					
						
							|  |  |  |                     displayableName, | 
					
						
							|  |  |  |                     m_hardwareID, | 
					
						
							|  |  |  |                     serial_str, | 
					
						
							|  |  |  |                     i, | 
					
						
							|  |  |  |                     1, | 
					
						
							|  |  |  |                     0 | 
					
						
							|  |  |  |                 )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				qDebug("AirspyPlugin::enumOriginDevices: enumerated Airspy device #%d", i); | 
					
						
							| 
									
										
										
										
											2015-09-11 03:02:02 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 03:02:02 +02:00
										 |  |  | 			airspy_close(devinfo); | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | 			qDebug("AirspyPlugin::enumOriginDevices: enumerated %d Airspy devices %s", i, airspy_error_name(rc)); | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 			break; // finished
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 03:02:02 +02:00
										 |  |  | 	rc = (airspy_error) airspy_exit(); | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | 	qDebug("AirspyPlugin::enumOriginDevices: airspy_exit: %s", airspy_error_name(rc)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     listedHwIds.append(m_hardwareID); | 
					
						
							| 
									
										
										
										
											2022-12-22 11:04:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-09-17 00:34:11 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PluginInterface::SamplingDevices AirspyPlugin::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, | 
					
						
							|  |  |  |                 m_hardwareID, | 
					
						
							|  |  |  |                 m_deviceTypeID, | 
					
						
							|  |  |  |                 it->serial, | 
					
						
							|  |  |  |                 it->sequence, | 
					
						
							|  |  |  |                 PluginInterface::SamplingDevice::PhysicalDevice, | 
					
						
							|  |  |  |                 PluginInterface::SamplingDevice::StreamSingleRx, | 
					
						
							|  |  |  |                 1, | 
					
						
							|  |  |  |                 0 | 
					
						
							|  |  |  |             )); | 
					
						
							|  |  |  |             qDebug("AirspyPlugin::enumSampleSources: enumerated Airspy device #%d", it->sequence); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 16:48:41 +02:00
										 |  |  | #ifdef SERVER_MODE
 | 
					
						
							| 
									
										
										
										
											2020-10-05 19:23:13 +02:00
										 |  |  | DeviceGUI* AirspyPlugin::createSampleSourcePluginInstanceGUI( | 
					
						
							| 
									
										
										
										
											2019-05-24 09:37:13 +02:00
										 |  |  |         const QString& sourceId, | 
					
						
							|  |  |  |         QWidget **widget, | 
					
						
							|  |  |  |         DeviceUISet *deviceUISet) | 
					
						
							| 
									
										
										
										
											2018-05-29 16:48:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-19 18:50:55 +02:00
										 |  |  |     (void) sourceId; | 
					
						
							|  |  |  |     (void) widget; | 
					
						
							|  |  |  |     (void) deviceUISet; | 
					
						
							| 
									
										
										
										
											2019-08-03 11:21:46 +02:00
										 |  |  |     return nullptr; | 
					
						
							| 
									
										
										
										
											2018-05-29 16:48:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2020-10-05 19:23:13 +02:00
										 |  |  | DeviceGUI* AirspyPlugin::createSampleSourcePluginInstanceGUI( | 
					
						
							| 
									
										
										
										
											2017-10-30 00:02:28 +01:00
										 |  |  |         const QString& sourceId, | 
					
						
							|  |  |  |         QWidget **widget, | 
					
						
							|  |  |  |         DeviceUISet *deviceUISet) | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-17 19:26:23 +02:00
										 |  |  | 	if (sourceId == m_deviceTypeID) | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-30 00:45:23 +01:00
										 |  |  | 		AirspyGui* gui = new AirspyGui(deviceUISet); | 
					
						
							| 
									
										
										
										
											2016-05-17 03:41:01 +02:00
										 |  |  | 		*widget = gui; | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 		return gui; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-08-03 11:21:46 +02:00
										 |  |  | 		return nullptr; | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-05-29 16:48:41 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-09-14 08:49:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-19 10:28:50 +02:00
										 |  |  | DeviceSampleSource *AirspyPlugin::createSampleSourcePluginInstance(const QString& sourceId, DeviceAPI *deviceAPI) | 
					
						
							| 
									
										
										
										
											2017-09-14 08:49:31 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (sourceId == m_deviceTypeID) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         AirspyInput* input = new AirspyInput(deviceAPI); | 
					
						
							|  |  |  |         return input; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-08-03 11:21:46 +02:00
										 |  |  |         return nullptr; | 
					
						
							| 
									
										
										
										
											2017-09-14 08:49:31 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-08-03 11:21:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | DeviceWebAPIAdapter *AirspyPlugin::createDeviceWebAPIAdapter() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return new AirspyWebAPIAdapter(); | 
					
						
							| 
									
										
										
										
											2020-10-05 19:23:13 +02:00
										 |  |  | } |