| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2015 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                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 <QAction>
 | 
					
						
							|  |  |  | #include <libairspy/airspy.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "airspygui.h"
 | 
					
						
							|  |  |  | #include "airspyplugin.h"
 | 
					
						
							|  |  |  | #include "plugin/pluginapi.h"
 | 
					
						
							|  |  |  | #include "util/simpleserializer.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const PluginDescriptor AirspyPlugin::m_pluginDescriptor = { | 
					
						
							|  |  |  | 	QString("Airspy Input"), | 
					
						
							|  |  |  | 	QString("---"), | 
					
						
							|  |  |  | 	QString("(c) Edouard Griffiths, F4EXB"), | 
					
						
							|  |  |  | 	QString("https://github.com/f4exb/sdrangel"), | 
					
						
							|  |  |  | 	true, | 
					
						
							|  |  |  | 	QString("https://github.com/f4exb/sdrangel") | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-30 13:53:09 +02:00
										 |  |  | const QString AirspyPlugin::m_deviceTypeID = AIRSPY_DEVICE_TYPE_ID; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | AirspyPlugin::AirspyPlugin(QObject* parent) : | 
					
						
							|  |  |  | 	QObject(parent), | 
					
						
							|  |  |  | 	m_pluginAPI(0) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const PluginDescriptor& AirspyPlugin::getPluginDescriptor() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_pluginDescriptor; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AirspyPlugin::initPlugin(PluginAPI* pluginAPI) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_pluginAPI = pluginAPI; | 
					
						
							| 
									
										
										
										
											2015-09-30 13:53:09 +02:00
										 |  |  | 	m_pluginAPI->registerSampleSource(m_deviceTypeID, this); | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PluginInterface::SampleSourceDevices AirspyPlugin::enumSampleSources() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	SampleSourceDevices result; | 
					
						
							|  |  |  | 	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) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-09-10 05:53:37 +02:00
										 |  |  | 		qCritical("AirspyPlugin::enumSampleSources: failed to initiate Airspy library: %s", airspy_error_name(rc)); | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 03:02:02 +02:00
										 |  |  | 	for (i=0; i < AIRSPY_MAX_DEVICE; 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) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-09-11 03:02:02 +02:00
										 |  |  | 			qDebug("AirspyPlugin::enumSampleSources: try to enumerate Airspy device #%d", i); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2015-09-10 08:12:49 +02:00
										 |  |  | 				qDebug("AirspyPlugin::enumSampleSources: 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); | 
					
						
							|  |  |  | 				uint64_t serial_num = (((uint64_t) serial_msb)<<32) + serial_lsb; | 
					
						
							| 
									
										
										
										
											2015-10-01 05:44:33 +02:00
										 |  |  | 				QString displayedName(QString("Airspy[%1] %2").arg(i).arg(serial_str)); | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				result.append(SampleSourceDevice(displayedName, | 
					
						
							| 
									
										
										
										
											2015-09-30 13:53:09 +02:00
										 |  |  | 						m_deviceTypeID, | 
					
						
							| 
									
										
										
										
											2015-09-30 06:57:40 +02:00
										 |  |  | 						serial_str, | 
					
						
							|  |  |  | 						i)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 03:02:02 +02:00
										 |  |  | 				qDebug("AirspyPlugin::enumSampleSources: enumerated Airspy device #%d", i); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-09-10 08:12:49 +02:00
										 |  |  | 			qDebug("AirspyPlugin::enumSampleSources: 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(); | 
					
						
							|  |  |  | 	qDebug("AirspyPlugin::enumSampleSources: airspy_exit: %s", airspy_error_name(rc)); | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-30 09:01:29 +02:00
										 |  |  | PluginGUI* AirspyPlugin::createSampleSourcePluginGUI(const QString& sourceId) | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (!m_pluginAPI) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-30 13:53:09 +02:00
										 |  |  | 	if(sourceId == m_deviceTypeID) | 
					
						
							| 
									
										
										
										
											2015-09-09 09:13:24 +02:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		AirspyGui* gui = new AirspyGui(m_pluginAPI); | 
					
						
							|  |  |  | 		m_pluginAPI->setInputGUI(gui); | 
					
						
							|  |  |  | 		return gui; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |