| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2016-03-29 03:17:59 +02:00
										 |  |  | // Copyright (C) 2016 Edouard Griffiths, F4EXB                                   //
 | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +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                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // FIXME: FCD is handled very badly!
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2016-05-12 23:35:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-27 12:50:38 +02:00
										 |  |  | #include "dsp/dspengine.h"
 | 
					
						
							| 
									
										
										
										
											2017-09-04 23:41:58 +02:00
										 |  |  | #include <dsp/filerecord.h>
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | #include "fcdproplusinput.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:17:55 +02:00
										 |  |  | #include <device/devicesourceapi.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | #include "fcdproplusgui.h"
 | 
					
						
							|  |  |  | #include "fcdproplusthread.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-05 05:50:29 +02:00
										 |  |  | #include "fcdtraits.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-05 11:46:56 +02:00
										 |  |  | #include "fcdproplusconst.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(FCDProPlusInput::MsgConfigureFCD, Message) | 
					
						
							| 
									
										
										
										
											2017-09-04 23:41:58 +02:00
										 |  |  | MESSAGE_CLASS_DEFINITION(FCDProPlusInput::MsgFileRecord, Message) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:17:55 +02:00
										 |  |  | FCDProPlusInput::FCDProPlusInput(DeviceSourceAPI *deviceAPI) : | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |     m_deviceAPI(deviceAPI), | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	m_dev(0), | 
					
						
							|  |  |  | 	m_settings(), | 
					
						
							|  |  |  | 	m_FCDThread(0), | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  | 	m_deviceDescription(fcd_traits<ProPlus>::displayedName), | 
					
						
							|  |  |  | 	m_running(false) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  |     openDevice(); | 
					
						
							| 
									
										
										
										
											2017-09-04 23:41:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     char recFileNameCStr[30]; | 
					
						
							|  |  |  |     sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); | 
					
						
							|  |  |  |     m_fileSink = new FileRecord(std::string(recFileNameCStr)); | 
					
						
							|  |  |  |     m_deviceAPI->addSink(m_fileSink); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | FCDProPlusInput::~FCDProPlusInput() | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  |     if (m_running) stop(); | 
					
						
							| 
									
										
										
										
											2017-09-04 23:41:58 +02:00
										 |  |  |     m_deviceAPI->removeSink(m_fileSink); | 
					
						
							|  |  |  |     delete m_fileSink; | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  |     closeDevice(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-15 02:32:30 +02:00
										 |  |  | void FCDProPlusInput::destroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  | bool FCDProPlusInput::openDevice() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int device = m_deviceAPI->getSampleSourceSequence(); | 
					
						
							|  |  |  |     qDebug() << "FCDProPlusInput::openDevice with device #" << device; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_dev = fcdOpen(fcd_traits<ProPlus>::vendorId, fcd_traits<ProPlus>::productId, device); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_dev == 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qCritical("FCDProPlusInput::start: could not open FCD"); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 03:40:45 +02:00
										 |  |  | bool FCDProPlusInput::start() | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  | //	QMutexLocker mutexLocker(&m_mutex);
 | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  |     if (!m_dev) { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  |     if (m_running) stop(); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  |     qDebug() << "FCDProPlusInput::start"; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Apply settings before streaming to avoid bus contention;
 | 
					
						
							|  |  |  | 	 * there is very little spare bandwidth on a full speed USB device. | 
					
						
							| 
									
										
										
										
											2015-09-03 08:39:57 +02:00
										 |  |  | 	 * Failure is harmless if no device is found | 
					
						
							|  |  |  | 	 * ... This is rubbish...*/ | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-03 08:39:57 +02:00
										 |  |  | 	//applySettings(m_settings, true);
 | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(!m_sampleFifo.setSize(96000*4)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		qCritical("Could not allocate SampleFifo"); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | 	if ((m_FCDThread = new FCDProPlusThread(&m_sampleFifo)) == NULL) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		qFatal("out of memory"); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-03 08:39:57 +02:00
										 |  |  | 	m_FCDThread->startWork(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  | //	mutexLocker.unlock();
 | 
					
						
							| 
									
										
										
										
											2015-09-03 08:39:57 +02:00
										 |  |  | 	applySettings(m_settings, true); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | 	qDebug("FCDProPlusInput::started"); | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  | 	m_running = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  | void FCDProPlusInput::closeDevice() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-17 12:00:13 +02:00
										 |  |  |     if (m_dev == 0) { // was never open
 | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  |     fcdClose(m_dev); | 
					
						
							|  |  |  |     m_dev = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | void FCDProPlusInput::stop() | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QMutexLocker mutexLocker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (m_FCDThread) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_FCDThread->stopWork(); | 
					
						
							|  |  |  | 		// wait for thread to quit ?
 | 
					
						
							|  |  |  | 		delete m_FCDThread; | 
					
						
							|  |  |  | 		m_FCDThread = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 03:29:50 +02:00
										 |  |  | 	m_running = false; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | const QString& FCDProPlusInput::getDeviceDescription() const | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	return m_deviceDescription; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | int FCDProPlusInput::getSampleRate() const | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-09-05 05:50:29 +02:00
										 |  |  | 	return fcd_traits<ProPlus>::sampleRate; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | quint64 FCDProPlusInput::getCenterFrequency() const | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 	return m_settings.m_centerFrequency; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | bool FCDProPlusInput::handleMessage(const Message& message) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	if(MsgConfigureFCD::match(message)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | 		qDebug() << "FCDProPlusInput::handleMessage: MsgConfigureFCD"; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 		MsgConfigureFCD& conf = (MsgConfigureFCD&) message; | 
					
						
							| 
									
										
										
										
											2017-10-14 09:37:55 +02:00
										 |  |  | 		applySettings(conf.getSettings(), conf.getForce()); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-09-04 23:41:58 +02:00
										 |  |  |     else if (MsgFileRecord::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgFileRecord& conf = (MsgFileRecord&) message; | 
					
						
							|  |  |  |         qDebug() << "FCDProPlusInput::handleMessage: MsgFileRecord: " << conf.getStartStop(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (conf.getStartStop()) { | 
					
						
							|  |  |  |             m_fileSink->startRecording(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_fileSink->stopRecording(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | void FCDProPlusInput::applySettings(const FCDProPlusSettings& settings, bool force) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	bool signalChange = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 20:39:14 +02:00
										 |  |  | 	if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency) | 
					
						
							|  |  |  |             || (m_settings.m_transverterMode != settings.m_transverterMode) | 
					
						
							|  |  |  |             || (m_settings.m_transverterDeltaFrequency != settings.m_transverterDeltaFrequency)) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-09-25 20:39:14 +02:00
										 |  |  |         qint64 deviceCenterFrequency = settings.m_centerFrequency; | 
					
						
							|  |  |  |         deviceCenterFrequency -= settings.m_transverterMode ? settings.m_transverterDeltaFrequency : 0; | 
					
						
							|  |  |  |         deviceCenterFrequency = deviceCenterFrequency < 0 ? 0 : deviceCenterFrequency; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 20:39:14 +02:00
										 |  |  |         if (m_dev != 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             set_center_freq((double) deviceCenterFrequency); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         qDebug() << "FCDProPlusInput::applySettings: center freq: " << settings.m_centerFrequency << " Hz" | 
					
						
							|  |  |  |                 << " device center freq: " << deviceCenterFrequency << " Hz"; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 20:39:14 +02:00
										 |  |  |         m_settings.m_centerFrequency = settings.m_centerFrequency; | 
					
						
							|  |  |  |         signalChange = true; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 	if ((m_settings.m_lnaGain != settings.m_lnaGain) || force) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 		m_settings.m_lnaGain = settings.m_lnaGain; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 			set_lna_gain(settings.m_lnaGain); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 	if ((m_settings.m_biasT != settings.m_biasT) || force) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 		m_settings.m_biasT = settings.m_biasT; | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 			set_bias_t(settings.m_biasT); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-12 23:35:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 	if ((m_settings.m_mixGain != settings.m_mixGain) || force) | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 		m_settings.m_mixGain = settings.m_mixGain; | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 			set_mixer_gain(settings.m_mixGain); | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 	if ((m_settings.m_ifGain != settings.m_ifGain) || force) | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 		m_settings.m_ifGain = settings.m_ifGain; | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 			set_if_gain(settings.m_ifGain); | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 	if ((m_settings.m_ifFilterIndex != settings.m_ifFilterIndex) || force) | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 		m_settings.m_ifFilterIndex = settings.m_ifFilterIndex; | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 			set_if_filter(settings.m_ifFilterIndex); | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 	if ((m_settings.m_rfFilterIndex != settings.m_rfFilterIndex) || force) | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 		m_settings.m_rfFilterIndex = settings.m_rfFilterIndex; | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 			set_rf_filter(settings.m_rfFilterIndex); | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 	if ((m_settings.m_LOppmTenths != settings.m_LOppmTenths) || force) | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 		m_settings.m_LOppmTenths = settings.m_LOppmTenths; | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			set_lo_ppm(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 04:13:04 +02:00
										 |  |  | 	if ((m_settings.m_dcBlock != settings.m_dcBlock) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_settings.m_dcBlock = settings.m_dcBlock; | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  | 		m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqImbalance); | 
					
						
							| 
									
										
										
										
											2015-10-01 04:13:04 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((m_settings.m_iqImbalance != settings.m_iqImbalance) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_settings.m_iqImbalance = settings.m_iqImbalance; | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  | 		m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqImbalance); | 
					
						
							| 
									
										
										
										
											2015-10-01 04:13:04 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 	if (signalChange) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 		DSPSignalNotification *notif = new DSPSignalNotification(fcd_traits<ProPlus>::sampleRate, m_settings.m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2017-09-04 23:41:58 +02:00
										 |  |  |         m_fileSink->handleMessage(*notif); // forward to file sink
 | 
					
						
							| 
									
										
										
										
											2017-09-13 23:40:06 +02:00
										 |  |  |         m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | void FCDProPlusInput::set_center_freq(double freq) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 	freq += freq*(((double) m_settings.m_LOppmTenths)/10000000.0); | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 	if (fcdAppSetFreq(m_dev, freq) == FCD_MODE_NONE) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		qDebug("No FCD HID found for frquency change"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | void FCDProPlusInput::set_bias_t(bool on) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	quint8 cmd = on ? 1 : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-05 06:24:02 +02:00
										 |  |  | 	fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_BIAS_TEE, &cmd, 1); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 04:10:38 +02:00
										 |  |  | void FCDProPlusInput::set_lna_gain(bool on) | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	quint8 cmd = on ? 1 : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-05 06:24:02 +02:00
										 |  |  | 	fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_LNA_GAIN, &cmd, 1); | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-05 11:46:56 +02:00
										 |  |  | void FCDProPlusInput::set_mixer_gain(bool on) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	quint8 cmd = on ? 1 : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_MIXER_GAIN, &cmd, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FCDProPlusInput::set_if_gain(int gain) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (gain < 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	quint8 cmd_value = gain; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 	if (fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_IF_GAIN, &cmd_value, 1) != FCD_MODE_APP) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		qWarning() << "FCDProPlusInput::set_if_gain: failed to set at " << cmd_value; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-05 11:46:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FCDProPlusInput::set_if_filter(int filterIndex) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ((filterIndex < 0) || (filterIndex >= FCDProPlusConstants::fcdproplus_if_filter_nb_values())) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	quint8 cmd_value = FCDProPlusConstants::if_filters[filterIndex].value; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 	if (fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_IF_FILTER, &cmd_value, 1) != FCD_MODE_APP) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		qWarning() << "FCDProPlusInput::set_if_filter: failed to set at " << cmd_value; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-05 11:46:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FCDProPlusInput::set_rf_filter(int filterIndex) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ((filterIndex < 0) || (filterIndex >= FCDProPlusConstants::fcdproplus_rf_filter_nb_values())) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	quint8 cmd_value = FCDProPlusConstants::rf_filters[filterIndex].value; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | 	if (fcdAppSetParam(m_dev, FCDPROPLUS_HID_CMD_SET_RF_FILTER, &cmd_value, 1) != FCD_MODE_APP) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		qWarning() << "FCDProPlusInput::set_rf_filter: failed to set at " << cmd_value; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-05 11:46:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | void FCDProPlusInput::set_lo_ppm() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-01 03:37:53 +02:00
										 |  |  | 	set_center_freq((double) m_settings.m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2015-09-06 01:34:20 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-05 11:46:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-03 03:57:54 +02:00
										 |  |  | 
 |