| 
									
										
										
										
											2017-01-02 10:39:21 +01: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 <string.h>
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | #include <QNetworkReply>
 | 
					
						
							|  |  |  | #include <QBuffer>
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  | #include "SWGDeviceSettings.h"
 | 
					
						
							|  |  |  | #include "SWGDeviceState.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  | #include "dsp/dspengine.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | #include "device/devicesinkapi.h"
 | 
					
						
							|  |  |  | #include "device/devicesourceapi.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-29 05:49:14 +02:00
										 |  |  | #include "bladerf1/devicebladerf1shared.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | #include "bladerf1outputthread.h"
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | #include "bladerf1output.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | MESSAGE_CLASS_DEFINITION(Bladerf1Output::MsgConfigureBladerf1, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(Bladerf1Output::MsgStartStop, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(Bladerf1Output::MsgReportBladerf1, Message) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | Bladerf1Output::Bladerf1Output(DeviceSinkAPI *deviceAPI) : | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     m_deviceAPI(deviceAPI), | 
					
						
							|  |  |  | 	m_settings(), | 
					
						
							|  |  |  | 	m_dev(0), | 
					
						
							|  |  |  | 	m_bladerfThread(0), | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  | 	m_deviceDescription("BladeRFOutput"), | 
					
						
							|  |  |  | 	m_running(false) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-15 17:37:53 +02:00
										 |  |  |     m_sampleSourceFifo.resize(16*BLADERFOUTPUT_BLOCKSIZE); | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     openDevice(); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     m_deviceAPI->setBuddySharedPtr(&m_sharedParams); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     m_networkManager = new QNetworkAccessManager(); | 
					
						
							|  |  |  |     connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | Bladerf1Output::~Bladerf1Output() | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); | 
					
						
							|  |  |  |     delete m_networkManager; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_running) { | 
					
						
							|  |  |  |         stop(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     closeDevice(); | 
					
						
							| 
									
										
										
										
											2017-01-03 09:09:51 +01:00
										 |  |  |     m_deviceAPI->setBuddySharedPtr(0); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::destroy() | 
					
						
							| 
									
										
										
										
											2017-09-16 11:34:25 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | bool Bladerf1Output::openDevice() | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     if (m_dev != 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         closeDevice(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     int res; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |     m_sampleSourceFifo.resize(m_settings.m_devSampleRate/(1<<(m_settings.m_log2Interp <= 4 ? m_settings.m_log2Interp : 4))); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_deviceAPI->getSourceBuddies().size() > 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         DeviceSourceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0]; | 
					
						
							| 
									
										
										
										
											2018-09-19 05:26:18 +02:00
										 |  |  |         DeviceBladeRF1Params *buddySharedParams = (DeviceBladeRF1Params *) sourceBuddy->getBuddySharedPtr(); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (buddySharedParams == 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qCritical("BladerfOutput::start: could not get shared parameters from buddy"); | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         if (buddySharedParams->m_dev == 0) // device is not opened by buddy
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |             qCritical("BladerfOutput::start: could not get BladeRF handle from buddy"); | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         m_sharedParams = *(buddySharedParams); // copy parameters from buddy
 | 
					
						
							|  |  |  |         m_dev = m_sharedParams.m_dev;          // get BladeRF handle
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:26:18 +02:00
										 |  |  |         if (!DeviceBladeRF1::open_bladerf(&m_dev, qPrintable(m_deviceAPI->getSampleSinkSerial()))) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-04-14 01:59:09 +02:00
										 |  |  |             qCritical("BladerfOutput::start: could not open BladeRF %s", qPrintable(m_deviceAPI->getSampleSinkSerial())); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_sharedParams.m_dev = m_dev; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // TODO: adjust USB transfer data according to sample rate
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:12:00 +02:00
										 |  |  |     if ((res = bladerf_sync_config(m_dev, BLADERF_TX_X1, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |         qCritical("BladerfOutput::start: bladerf_sync_config with return code %d", res); | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_TX, true)) < 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |         qCritical("BladerfOutput::start: bladerf_enable_module with return code %d", res); | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::init() | 
					
						
							| 
									
										
										
										
											2017-12-25 12:59:44 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     applySettings(m_settings, true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | bool Bladerf1Output::start() | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  | { | 
					
						
							|  |  |  | //	QMutexLocker mutexLocker(&m_mutex);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_dev) { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_running) stop(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |     m_bladerfThread = new Bladerf1OutputThread(m_dev, &m_sampleSourceFifo); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  | //	mutexLocker.unlock();
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	applySettings(m_settings, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  | 	m_bladerfThread->setLog2Interpolation(m_settings.m_log2Interp); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |     m_bladerfThread->startWork(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	qDebug("BladerfOutput::start: started"); | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     m_running = true; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::closeDevice() | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  |     int res; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-17 12:00:13 +02:00
										 |  |  |     if (m_dev == 0) { // was never open
 | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  |     if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_TX, false)) < 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         qCritical("BladerfOutput::closeDevice: bladerf_enable_module with return code %d", res); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |     if (m_deviceAPI->getSourceBuddies().size() == 0) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         qDebug("BladerfOutput::closeDevice: closing device since Rx side is not open"); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         if (m_dev != 0) // close BladeRF
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             bladerf_close(m_dev); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_sharedParams.m_dev = 0; | 
					
						
							| 
									
										
										
										
											2017-01-03 09:09:51 +01:00
										 |  |  |     m_dev = 0; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::stop() | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  | { | 
					
						
							|  |  |  | //	QMutexLocker mutexLocker(&m_mutex);
 | 
					
						
							|  |  |  |     if (m_bladerfThread != 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_bladerfThread->stopWork(); | 
					
						
							|  |  |  | 		delete m_bladerfThread; | 
					
						
							|  |  |  | 		m_bladerfThread = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_running = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | QByteArray Bladerf1Output::serialize() const | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | bool Bladerf1Output::deserialize(const QByteArray& data) | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     bool success = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_settings.resetToDefaults(); | 
					
						
							|  |  |  |         success = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |     MsgConfigureBladerf1* message = MsgConfigureBladerf1::create(m_settings, true); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |         MsgConfigureBladerf1* messageToGUI = MsgConfigureBladerf1::create(m_settings, true); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return success; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | const QString& Bladerf1Output::getDeviceDescription() const | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	return m_deviceDescription; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | int Bladerf1Output::getSampleRate() const | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	int rate = m_settings.m_devSampleRate; | 
					
						
							|  |  |  | 	return (rate / (1<<m_settings.m_log2Interp)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | quint64 Bladerf1Output::getCenterFrequency() const | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	return m_settings.m_centerFrequency; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::setCenterFrequency(qint64 centerFrequency) | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |     BladeRF1OutputSettings settings = m_settings; | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |     settings.m_centerFrequency = centerFrequency; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |     MsgConfigureBladerf1* message = MsgConfigureBladerf1::create(settings, false); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |         MsgConfigureBladerf1* messageToGUI = MsgConfigureBladerf1::create(settings, false); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | bool Bladerf1Output::handleMessage(const Message& message) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | 	if (MsgConfigureBladerf1::match(message)) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | 		MsgConfigureBladerf1& conf = (MsgConfigureBladerf1&) message; | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | 		qDebug() << "BladerfOutput::handleMessage: MsgConfigureBladerf"; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 07:10:42 +02:00
										 |  |  | 		if (!applySettings(conf.getSettings(), conf.getForce())) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			qDebug("BladeRF config error"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |     else if (MsgStartStop::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgStartStop& cmd = (MsgStartStop&) message; | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  |         qDebug() << "BladerfOutput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (cmd.getStartStop()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (m_deviceAPI->initGeneration()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 m_deviceAPI->startGeneration(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_deviceAPI->stopGeneration(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |         if (m_settings.m_useReverseAPI) { | 
					
						
							|  |  |  |             webapiReverseSendStartStop(cmd.getStartStop()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | bool Bladerf1Output::applySettings(const BladeRF1OutputSettings& settings, bool force) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-08-08 23:09:51 +02:00
										 |  |  | 	bool forwardChange    = false; | 
					
						
							|  |  |  |     bool suspendOwnThread = false; | 
					
						
							|  |  |  |     bool threadWasRunning = false; | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     QList<QString> reverseAPIKeys; | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  | //	QMutexLocker mutexLocker(&m_mutex);
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	qDebug() << "BladerfOutput::applySettings: m_dev: " << m_dev; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("centerFrequency"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("devSampleRate"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((m_settings.m_log2Interp != settings.m_log2Interp) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("log2Interp"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-08 23:09:51 +02:00
										 |  |  |     if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || | 
					
						
							|  |  |  |         (m_settings.m_log2Interp != settings.m_log2Interp) || force) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         suspendOwnThread = true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-08 23:09:51 +02:00
										 |  |  |     if (suspendOwnThread) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (m_bladerfThread) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (m_bladerfThread->isRunning()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 m_bladerfThread->stopWork(); | 
					
						
							|  |  |  |                 threadWasRunning = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-08 23:09:51 +02:00
										 |  |  | 	if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || (m_settings.m_log2Interp != settings.m_log2Interp) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-09 00:31:23 +02:00
										 |  |  | 	    int fifoSize; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-09 22:59:46 +02:00
										 |  |  | 	    if (settings.m_log2Interp >= 5) | 
					
						
							| 
									
										
										
										
											2017-08-09 00:31:23 +02:00
										 |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:26:18 +02:00
										 |  |  | 	        fifoSize = DeviceBladeRF1Shared::m_sampleFifoMinSize32; | 
					
						
							| 
									
										
										
										
											2017-08-09 00:31:23 +02:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	    else | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2018-11-16 13:44:58 +01:00
										 |  |  |             fifoSize = (std::max)( | 
					
						
							| 
									
										
										
										
											2018-09-19 05:26:18 +02:00
										 |  |  | 	            (int) ((settings.m_devSampleRate/(1<<settings.m_log2Interp)) * DeviceBladeRF1Shared::m_sampleFifoLengthInSeconds), | 
					
						
							|  |  |  | 	            DeviceBladeRF1Shared::m_sampleFifoMinSize); | 
					
						
							| 
									
										
										
										
											2017-08-09 00:31:23 +02:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_sampleSourceFifo.resize(fifoSize); | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         forwardChange = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (m_dev != 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             unsigned int actualSamplerate; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |             if (bladerf_set_sample_rate(m_dev, BLADERF_MODULE_TX, settings.m_devSampleRate, &actualSamplerate) < 0) { | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |                 qCritical("BladerfOutput::applySettings: could not set sample rate: %d", settings.m_devSampleRate); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |                 qDebug() << "BladerfOutput::applySettings: bladerf_set_sample_rate(BLADERF_MODULE_TX) actual sample rate is " << actualSamplerate; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((m_settings.m_log2Interp != settings.m_log2Interp) || force) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         forwardChange = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (m_bladerfThread != 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_bladerfThread->setLog2Interpolation(settings.m_log2Interp); | 
					
						
							|  |  |  |             qDebug() << "BladerfOutput::applySettings: set interpolation to " << (1<<settings.m_log2Interp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((m_settings.m_vga1 != settings.m_vga1) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |         reverseAPIKeys.append("vga1"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 		if (m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 			if (bladerf_set_txvga1(m_dev, settings.m_vga1) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 				qDebug("BladerfOutput::applySettings: bladerf_set_txvga1() failed"); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 				qDebug() << "BladerfOutput::applySettings: VGA1 gain set to " << settings.m_vga1; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((m_settings.m_vga2 != settings.m_vga2) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |         reverseAPIKeys.append("vga2"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 		if(m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 			if (bladerf_set_txvga2(m_dev, settings.m_vga2) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 				qDebug("BladerfOutput::applySettings:bladerf_set_rxvga2() failed"); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 				qDebug() << "BladerfOutput::applySettings: VGA2 gain set to " << settings.m_vga2; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((m_settings.m_xb200 != settings.m_xb200) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |         reverseAPIKeys.append("xb200"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 		if (m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  |             bool changeSettings; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (m_deviceAPI->getSourceBuddies().size() > 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |                 if (buddy->getDeviceSourceEngine()->state() == DSPDeviceSourceEngine::StRunning) { // Tx side running
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |                     changeSettings = false; | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |                     changeSettings = true; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else // No Rx open
 | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 changeSettings = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (changeSettings) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |                 if (settings.m_xb200) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |                     if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |                         qDebug("BladerfOutput::applySettings: bladerf_expansion_attach(xb200) failed"); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |                     } else { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |                         qDebug() << "BladerfOutput::applySettings: Attach XB200"; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |                     if (bladerf_expansion_attach(m_dev, BLADERF_XB_NONE) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |                         qDebug("BladerfOutput::applySettings: bladerf_expansion_attach(none) failed"); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |                     } else { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |                         qDebug() << "BladerfOutput::applySettings: Detach XB200"; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |                 m_sharedParams.m_xb200Attached = settings.m_xb200; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((m_settings.m_xb200Path != settings.m_xb200Path) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |         reverseAPIKeys.append("xb200Path"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 		if (m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 			if (bladerf_xb200_set_path(m_dev, BLADERF_MODULE_TX, settings.m_xb200Path) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 				qDebug("BladerfOutput::applySettings: bladerf_xb200_set_path(BLADERF_MODULE_TX) failed"); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 				qDebug() << "BladerfOutput::applySettings: set xb200 path to " << settings.m_xb200Path; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((m_settings.m_xb200Filter != settings.m_xb200Filter) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |         reverseAPIKeys.append("xb200Filter"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 		if (m_dev != 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 			if (bladerf_xb200_set_filterbank(m_dev, BLADERF_MODULE_TX, settings.m_xb200Filter) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 				qDebug("BladerfOutput::applySettings: bladerf_xb200_set_filterbank(BLADERF_MODULE_TX) failed"); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 				qDebug() << "BladerfOutput::applySettings: set xb200 filter to " << settings.m_xb200Filter; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((m_settings.m_bandwidth != settings.m_bandwidth) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |         reverseAPIKeys.append("bandwidth"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (m_dev != 0) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			unsigned int actualBandwidth; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 			if (bladerf_set_bandwidth(m_dev, BLADERF_MODULE_TX, settings.m_bandwidth, &actualBandwidth) < 0) { | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 				qCritical("BladerfOutput::applySettings: could not set bandwidth: %d", settings.m_bandwidth); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 				qDebug() << "BladerfOutput::applySettings: bladerf_set_bandwidth(BLADERF_MODULE_TX) actual bandwidth is " << actualBandwidth; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (m_settings.m_centerFrequency != settings.m_centerFrequency) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		forwardChange = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 	if (m_dev != 0) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 		if (bladerf_set_frequency( m_dev, BLADERF_MODULE_TX, settings.m_centerFrequency ) != 0) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 			qDebug("BladerfOutput::applySettings: bladerf_set_frequency(%lld) failed", settings.m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-08 23:09:51 +02:00
										 |  |  |     if (threadWasRunning) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_bladerfThread->startWork(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     if (settings.m_useReverseAPI) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) || | 
					
						
							|  |  |  |                 (m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) || | 
					
						
							|  |  |  |                 (m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) || | 
					
						
							|  |  |  |                 (m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  |         webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_settings = settings; | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	if (forwardChange) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		int sampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Interp); | 
					
						
							|  |  |  | 		DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2017-09-13 23:42:28 +02:00
										 |  |  | 		m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qDebug() << "BladerfOutput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz" | 
					
						
							| 
									
										
										
										
											2017-04-02 04:34:58 +02:00
										 |  |  | 			<< " device sample rate: " << m_settings.m_devSampleRate << "S/s" | 
					
						
							|  |  |  | 			<< " baseband sample rate: " << m_settings.m_devSampleRate/(1<<m_settings.m_log2Interp) << "S/s" | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 			<< " BW: " << m_settings.m_bandwidth << "Hz"; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | int Bladerf1Output::webapiSettingsGet( | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |                 SWGSDRangel::SWGDeviceSettings& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |                 QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |     response.setBladeRf1OutputSettings(new SWGSDRangel::SWGBladeRF1OutputSettings()); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->init(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     webapiFormatDeviceSettings(response, m_settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const BladeRF1OutputSettings& settings) | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |     response.getBladeRf1OutputSettings()->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setDevSampleRate(settings.m_devSampleRate); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setVga1(settings.m_vga1); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setVga2(settings.m_vga2); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setBandwidth(settings.m_bandwidth); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setLog2Interp(settings.m_log2Interp); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setXb200(settings.m_xb200 ? 1 : 0); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setXb200Path((int) settings.m_xb200Path); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setXb200Filter((int) settings.m_xb200Filter); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | int Bladerf1Output::webapiSettingsPutPatch( | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |                 bool force, | 
					
						
							|  |  |  |                 const QStringList& deviceSettingsKeys, | 
					
						
							|  |  |  |                 SWGSDRangel::SWGDeviceSettings& response, // query + response
 | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |                 QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |     BladeRF1OutputSettings settings = m_settings; | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("centerFrequency")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_centerFrequency = response.getBladeRf1OutputSettings()->getCenterFrequency(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("devSampleRate")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_devSampleRate = response.getBladeRf1OutputSettings()->getDevSampleRate(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("vga1")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_vga1 = response.getBladeRf1OutputSettings()->getVga1(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("vga2")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_vga2 = response.getBladeRf1OutputSettings()->getVga2(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("bandwidth")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_bandwidth = response.getBladeRf1OutputSettings()->getBandwidth(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2Interp")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_log2Interp = response.getBladeRf1OutputSettings()->getLog2Interp(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_xb200 = response.getBladeRf1OutputSettings()->getXb200() == 0 ? 0 : 1; | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200Path")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_xb200Path = static_cast<bladerf_xb200_path>(response.getBladeRf1OutputSettings()->getXb200Path()); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200Filter")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_xb200Filter = static_cast<bladerf_xb200_filter>(response.getBladeRf1OutputSettings()->getXb200Filter()); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |     MsgConfigureBladerf1 *msg = MsgConfigureBladerf1::create(settings, force); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     m_inputMessageQueue.push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) // forward to GUI if any
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |         MsgConfigureBladerf1 *msgToGUI = MsgConfigureBladerf1::create(settings, force); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |         m_guiMessageQueue->push(msgToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     webapiFormatDeviceSettings(response, settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | int Bladerf1Output::webapiRunGet( | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |         QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  |     m_deviceAPI->getDeviceEngineStateStr(*response.getState()); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | int Bladerf1Output::webapiRun( | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  |         bool run, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |         QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2017-12-14 23:29:12 +01:00
										 |  |  |     m_deviceAPI->getDeviceEngineStateStr(*response.getState()); | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |     MsgStartStop *message = MsgStartStop::create(run); | 
					
						
							|  |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |         MsgStartStop *messagetoGui = MsgStartStop::create(run); | 
					
						
							|  |  |  |         m_guiMessageQueue->push(messagetoGui); | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | void Bladerf1Output::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const BladeRF1OutputSettings& settings, bool force) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); | 
					
						
							|  |  |  |     swgDeviceSettings->setTx(1); | 
					
						
							|  |  |  |     swgDeviceSettings->setDeviceHwType(new QString("BladeRF1")); | 
					
						
							|  |  |  |     swgDeviceSettings->setBladeRf1OutputSettings(new SWGSDRangel::SWGBladeRF1OutputSettings()); | 
					
						
							|  |  |  |     SWGSDRangel::SWGBladeRF1OutputSettings *swgBladeRF1OutputSettings = swgDeviceSettings->getBladeRf1OutputSettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // transfer data that has been modified. When force is on transfer all data except reverse API data
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("centerFrequency") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("devSampleRate") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setDevSampleRate(settings.m_devSampleRate); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("vga1") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setVga1(settings.m_vga1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("vga2") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setVga2(settings.m_vga2); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("bandwidth") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setBandwidth(settings.m_bandwidth); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2Interp") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setLog2Interp(settings.m_log2Interp); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setXb200(settings.m_xb200 ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200Path") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setXb200Path((int) settings.m_xb200Path); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200Filter") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setXb200Filter((int) settings.m_xb200Filter); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString deviceSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/settings") | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIAddress) | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIPort) | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  |     m_networkRequest.setUrl(QUrl(deviceSettingsURL)); | 
					
						
							|  |  |  |     m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QBuffer *buffer=new QBuffer(); | 
					
						
							|  |  |  |     buffer->open((QBuffer::ReadWrite)); | 
					
						
							|  |  |  |     buffer->write(swgDeviceSettings->asJson().toUtf8()); | 
					
						
							|  |  |  |     buffer->seek(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Always use PATCH to avoid passing reverse API settings
 | 
					
						
							|  |  |  |     m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     delete swgDeviceSettings; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Bladerf1Output::webapiReverseSendStartStop(bool start) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QString deviceSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/run") | 
					
						
							|  |  |  |             .arg(m_settings.m_reverseAPIAddress) | 
					
						
							|  |  |  |             .arg(m_settings.m_reverseAPIPort) | 
					
						
							|  |  |  |             .arg(m_settings.m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  |     m_networkRequest.setUrl(QUrl(deviceSettingsURL)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (start) { | 
					
						
							|  |  |  |         m_networkManager->sendCustomRequest(m_networkRequest, "POST"); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         m_networkManager->sendCustomRequest(m_networkRequest, "DELETE"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Bladerf1Output::networkManagerFinished(QNetworkReply *reply) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QNetworkReply::NetworkError replyError = reply->error(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (replyError) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qWarning() << "Bladerf1Output::networkManagerFinished:" | 
					
						
							|  |  |  |                 << " error(" << (int) replyError | 
					
						
							|  |  |  |                 << "): " << replyError | 
					
						
							|  |  |  |                 << ": " << reply->errorString(); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString answer = reply->readAll(); | 
					
						
							|  |  |  |     answer.chop(1); // remove last \n
 | 
					
						
							|  |  |  |     qDebug("Bladerf1Output::networkManagerFinished: reply:\n%s", answer.toStdString().c_str()); | 
					
						
							|  |  |  | } |