| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2015-06-07 17:56:19 +02:00
										 |  |  | // Copyright (C) 2015 Edouard Griffiths, F4EXB                                   //
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 06:57:41 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-09 10:33:04 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | #include <QNetworkReply>
 | 
					
						
							|  |  |  | #include <QBuffer>
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-09 12:41:42 +01:00
										 |  |  | #include "SWGDeviceSettings.h"
 | 
					
						
							|  |  |  | #include "SWGDeviceState.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | #include "util/simpleserializer.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | #include "dsp/dspdevicesourceengine.h"
 | 
					
						
							|  |  |  | #include "dsp/dspdevicesinkengine.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-27 12:50:38 +02:00
										 |  |  | #include "dsp/dspengine.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | #include "device/deviceapi.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:17:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | #include "bladerf1input.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | #include "bladerf1inputthread.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | MESSAGE_CLASS_DEFINITION(Bladerf1Input::MsgConfigureBladerf1, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(Bladerf1Input::MsgStartStop, Message) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | Bladerf1Input::Bladerf1Input(DeviceAPI *deviceAPI) : | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |     m_deviceAPI(deviceAPI), | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	m_settings(), | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	m_dev(0), | 
					
						
							| 
									
										
										
										
											2020-06-21 11:46:08 +02:00
										 |  |  | 	m_bladerfThread(nullptr), | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  | 	m_deviceDescription("BladeRFInput"), | 
					
						
							|  |  |  | 	m_running(false) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-03-17 21:10:30 +01:00
										 |  |  |     m_sampleFifo.setLabel(m_deviceDescription); | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |     openDevice(); | 
					
						
							| 
									
										
										
										
											2019-05-21 00:27:08 +02:00
										 |  |  |     m_deviceAPI->setNbSourceStreams(1); | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  |     m_deviceAPI->setBuddySharedPtr(&m_sharedParams); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_networkManager = new QNetworkAccessManager(); | 
					
						
							| 
									
										
										
										
											2022-03-23 22:32:23 +01:00
										 |  |  |     QObject::connect( | 
					
						
							|  |  |  |         m_networkManager, | 
					
						
							|  |  |  |         &QNetworkAccessManager::finished, | 
					
						
							|  |  |  |         this, | 
					
						
							|  |  |  |         &Bladerf1Input::networkManagerFinished | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | Bladerf1Input::~Bladerf1Input() | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-03-23 22:32:23 +01:00
										 |  |  |     QObject::disconnect( | 
					
						
							|  |  |  |         m_networkManager, | 
					
						
							|  |  |  |         &QNetworkAccessManager::finished, | 
					
						
							|  |  |  |         this, | 
					
						
							|  |  |  |         &Bladerf1Input::networkManagerFinished | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |     delete m_networkManager; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_running) { | 
					
						
							|  |  |  |         stop(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |     closeDevice(); | 
					
						
							| 
									
										
										
										
											2017-01-03 09:09:51 +01:00
										 |  |  |     m_deviceAPI->setBuddySharedPtr(0); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | void Bladerf1Input::destroy() | 
					
						
							| 
									
										
										
										
											2017-09-15 02:32:30 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | bool Bladerf1Input::openDevice() | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |     if (m_dev != 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         closeDevice(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |     int res; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |     if (!m_sampleFifo.setSize(96000 * 4)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         qCritical("BladerfInput::openDevice: could not allocate SampleFifo"); | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |     if (m_deviceAPI->getSinkBuddies().size() > 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         DeviceAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0]; | 
					
						
							| 
									
										
										
										
											2018-09-19 05:26:18 +02:00
										 |  |  |         DeviceBladeRF1Params *buddySharedParams = (DeviceBladeRF1Params *) sinkBuddy->getBuddySharedPtr(); | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |         if (buddySharedParams == 0) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |             qCritical("BladerfInput::openDevice: could not get shared parameters from buddy"); | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         if (buddySharedParams->m_dev == 0) // device is not opened by buddy
 | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |             qCritical("BladerfInput::openDevice: could not get BladeRF handle from buddy"); | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +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-04-13 20:16:33 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         if (!DeviceBladeRF1::open_bladerf(&m_dev, qPrintable(m_deviceAPI->getSamplingDeviceSerial()))) | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             qCritical("BladerfInput::start: could not open BladeRF %s", qPrintable(m_deviceAPI->getSamplingDeviceSerial())); | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  |         m_sharedParams.m_dev = m_dev; | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // 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_RX_X1, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |         qCritical("BladerfInput::start: bladerf_sync_config with return code %d", res); | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_RX, true)) < 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |         qCritical("BladerfInput::start: bladerf_enable_module with return code %d", res); | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | void Bladerf1Input::init() | 
					
						
							| 
									
										
										
										
											2017-12-25 09:10:19 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     applySettings(m_settings, true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | bool Bladerf1Input::start() | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  | { | 
					
						
							|  |  |  | //	QMutexLocker mutexLocker(&m_mutex);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:12:00 +02:00
										 |  |  |     if (!m_dev) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("BladerfInput::start: no device handle"); | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_running) stop(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | 	m_bladerfThread = new Bladerf1InputThread(m_dev, &m_sampleFifo); | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  | 	m_bladerfThread->setLog2Decimation(m_settings.m_log2Decim); | 
					
						
							|  |  |  | 	m_bladerfThread->setFcPos((int) m_settings.m_fcPos); | 
					
						
							| 
									
										
										
										
											2020-06-21 11:46:08 +02:00
										 |  |  |     m_bladerfThread->setIQOrder(m_settings.m_iqOrder); | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	m_bladerfThread->startWork(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  | //	mutexLocker.unlock();
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	applySettings(m_settings, true); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 22:15:16 +02:00
										 |  |  | 	qDebug("BladerfInput::startInput: started"); | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  | 	m_running = true; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | void Bladerf1Input::closeDevice() | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  |     int res; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02: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_RX, false)) < 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qCritical("BladerfInput::stop: bladerf_enable_module with return code %d", res); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |     if (m_deviceAPI->getSinkBuddies().size() == 0) | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         qDebug("BladerfInput::closeDevice: closing device since Tx side is not open"); | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if(m_dev != 0) // close BladeRF
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             bladerf_close(m_dev); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_sharedParams.m_dev = 0; | 
					
						
							| 
									
										
										
										
											2017-01-03 09:09:51 +01:00
										 |  |  |     m_dev = 0; | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | void Bladerf1Input::stop() | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  | { | 
					
						
							|  |  |  | //	QMutexLocker mutexLocker(&m_mutex);
 | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-21 11:46:08 +02:00
										 |  |  | 	if(m_bladerfThread) | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		m_bladerfThread->stopWork(); | 
					
						
							|  |  |  | 		delete m_bladerfThread; | 
					
						
							| 
									
										
										
										
											2020-06-21 11:46:08 +02:00
										 |  |  | 		m_bladerfThread = nullptr; | 
					
						
							| 
									
										
										
										
											2017-04-13 20:16:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_running = false; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | QByteArray Bladerf1Input::serialize() const | 
					
						
							| 
									
										
										
										
											2017-12-28 03:21:48 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | bool Bladerf1Input::deserialize(const QByteArray& data) | 
					
						
							| 
									
										
										
										
											2017-12-28 03:21:48 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     bool success = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_settings.resetToDefaults(); | 
					
						
							|  |  |  |         success = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  |     MsgConfigureBladerf1* message = MsgConfigureBladerf1::create(m_settings, true); | 
					
						
							| 
									
										
										
										
											2017-12-28 03:21:48 +01:00
										 |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  |         MsgConfigureBladerf1* messageToGUI = MsgConfigureBladerf1::create(m_settings, true); | 
					
						
							| 
									
										
										
										
											2017-12-28 03:21:48 +01:00
										 |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return success; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | const QString& Bladerf1Input::getDeviceDescription() const | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	return m_deviceDescription; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | int Bladerf1Input::getSampleRate() const | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	int rate = m_settings.m_devSampleRate; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	return (rate / (1<<m_settings.m_log2Decim)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | quint64 Bladerf1Input::getCenterFrequency() const | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	return m_settings.m_centerFrequency; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | void Bladerf1Input::setCenterFrequency(qint64 centerFrequency) | 
					
						
							| 
									
										
										
										
											2017-12-28 03:21:48 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  |     BladeRF1InputSettings settings = m_settings; | 
					
						
							| 
									
										
										
										
											2017-12-28 03:21:48 +01:00
										 |  |  |     settings.m_centerFrequency = centerFrequency; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  |     MsgConfigureBladerf1* message = MsgConfigureBladerf1::create(settings, false); | 
					
						
							| 
									
										
										
										
											2017-12-28 03:21:48 +01:00
										 |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  |         MsgConfigureBladerf1* messageToGUI = MsgConfigureBladerf1::create(settings, false); | 
					
						
							| 
									
										
										
										
											2017-12-28 03:21:48 +01:00
										 |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | bool Bladerf1Input::handleMessage(const Message& message) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | 	if (MsgConfigureBladerf1::match(message)) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | 		MsgConfigureBladerf1& conf = (MsgConfigureBladerf1&) message; | 
					
						
							|  |  |  | 		qDebug() << "Bladerf1Input::handleMessage: MsgConfigureBladerf1"; | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 06:36:29 +02:00
										 |  |  | 		if (!applySettings(conf.getSettings(), conf.getForce())) | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 			qDebug("BladeRF config error"); | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-14 00:19:59 +01:00
										 |  |  |     else if (MsgStartStop::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgStartStop& cmd = (MsgStartStop&) message; | 
					
						
							|  |  |  |         qDebug() << "BladerfInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (cmd.getStartStop()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             if (m_deviceAPI->initDeviceEngine()) | 
					
						
							| 
									
										
										
										
											2017-12-14 00:19:59 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |                 m_deviceAPI->startDeviceEngine(); | 
					
						
							| 
									
										
										
										
											2017-12-14 00:19:59 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             m_deviceAPI->stopDeviceEngine(); | 
					
						
							| 
									
										
										
										
											2017-12-14 00:19:59 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |         if (m_settings.m_useReverseAPI) { | 
					
						
							|  |  |  |             webapiReverseSendStartStop(cmd.getStartStop()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 00:19:59 +01:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | bool Bladerf1Input::applySettings(const BladeRF1InputSettings& settings, bool force) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-19 09:24:44 +02:00
										 |  |  | 	bool forwardChange = false; | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |     QList<QString> reverseAPIKeys; | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  | //	QMutexLocker mutexLocker(&m_mutex);
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	qDebug() << "BladerfInput::applySettings: m_dev: " << m_dev; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |     if ((m_settings.m_dcBlock != settings.m_dcBlock) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("dcBlock"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((m_settings.m_iqCorrection != settings.m_iqCorrection) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("iqCorrection"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 02:12:44 +01:00
										 |  |  | 	if ((m_settings.m_dcBlock != settings.m_dcBlock) || | 
					
						
							|  |  |  | 	    (m_settings.m_iqCorrection != settings.m_iqCorrection) || force) | 
					
						
							| 
									
										
										
										
											2015-10-01 03:18:20 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 		m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection); | 
					
						
							| 
									
										
										
										
											2015-10-01 03:18:20 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	if ((m_settings.m_lnaGain != settings.m_lnaGain) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |         reverseAPIKeys.append("lnaGain"); | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		if (m_dev != 0) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			if(bladerf_set_lna_gain(m_dev, getLnaGain(settings.m_lnaGain)) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  | 				qDebug("BladerfInput::applySettings: bladerf_set_lna_gain() failed"); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 				qDebug() << "BladerfInput::applySettings: LNA gain set to " << getLnaGain(settings.m_lnaGain); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	if ((m_settings.m_vga1 != settings.m_vga1) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |         reverseAPIKeys.append("vga1"); | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		if (m_dev != 0) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			if(bladerf_set_rxvga1(m_dev, settings.m_vga1) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  | 				qDebug("BladerfInput::applySettings: bladerf_set_rxvga1() failed"); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 				qDebug() << "BladerfInput::applySettings: VGA1 gain set to " << settings.m_vga1; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	if ((m_settings.m_vga2 != settings.m_vga2) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |         reverseAPIKeys.append("vga2"); | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		if(m_dev != 0) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			if(bladerf_set_rxvga2(m_dev, settings.m_vga2) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  | 				qDebug("BladerfInput::applySettings: bladerf_set_rxvga2() failed"); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 				qDebug() << "BladerfInput::applySettings: VGA2 gain set to " << settings.m_vga2; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	if ((m_settings.m_xb200 != settings.m_xb200) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |         reverseAPIKeys.append("xb200"); | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		if (m_dev != 0) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 		    bool changeSettings; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		    if (m_deviceAPI->getSinkBuddies().size() > 0) | 
					
						
							|  |  |  | 		    { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | 		        DeviceAPI *buddy = m_deviceAPI->getSinkBuddies()[0]; | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 		        if (buddy->getDeviceSinkEngine()->state() == DSPDeviceSinkEngine::StRunning) { // Tx side running
 | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 		            changeSettings = false; | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 		        } else { | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 		            changeSettings = true; | 
					
						
							|  |  |  | 		        } | 
					
						
							|  |  |  | 		    } | 
					
						
							|  |  |  | 		    else // No Tx open
 | 
					
						
							|  |  |  | 		    { | 
					
						
							|  |  |  |                 changeSettings = true; | 
					
						
							|  |  |  | 		    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		    if (changeSettings) | 
					
						
							|  |  |  | 		    { | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 	            if (settings.m_xb200) | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 	            { | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 	                if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  | 	                    qDebug("BladerfInput::applySettings: bladerf_expansion_attach(xb200) failed"); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 	                } else { | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  | 	                    qDebug() << "BladerfInput::applySettings: Attach XB200"; | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 	                } | 
					
						
							|  |  |  | 	            } | 
					
						
							|  |  |  | 	            else | 
					
						
							|  |  |  | 	            { | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 	                if (bladerf_expansion_attach(m_dev, BLADERF_XB_NONE) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  | 	                    qDebug("BladerfInput::applySettings: bladerf_expansion_attach(none) failed"); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 	                } else { | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  | 	                    qDebug() << "BladerfInput::applySettings: Detach XB200"; | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 	                } | 
					
						
							|  |  |  | 	            } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 	            m_sharedParams.m_xb200Attached = settings.m_xb200; | 
					
						
							| 
									
										
										
										
											2016-12-30 16:13:28 +01:00
										 |  |  | 		    } | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	if ((m_settings.m_xb200Path != settings.m_xb200Path) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |         reverseAPIKeys.append("xb200Path"); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (m_dev != 0) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			if(bladerf_xb200_set_path(m_dev, BLADERF_MODULE_RX, settings.m_xb200Path) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  | 				qDebug("BladerfInput::applySettings: bladerf_xb200_set_path(BLADERF_MODULE_RX) failed"); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 				qDebug() << "BladerfInput::applySettings: set xb200 path to " << settings.m_xb200Path; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	if ((m_settings.m_xb200Filter != settings.m_xb200Filter) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |         reverseAPIKeys.append("xb200Filter"); | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		if (m_dev != 0) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			if(bladerf_xb200_set_filterbank(m_dev, BLADERF_MODULE_RX, settings.m_xb200Filter) != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  | 				qDebug("BladerfInput::applySettings: bladerf_xb200_set_filterbank(BLADERF_MODULE_RX) failed"); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 				qDebug() << "BladerfInput::applySettings: set xb200 filter to " << settings.m_xb200Filter; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |         reverseAPIKeys.append("devSampleRate"); | 
					
						
							| 
									
										
										
										
											2015-08-19 09:24:44 +02:00
										 |  |  | 		forwardChange = true; | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		if (m_dev != 0) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 			unsigned int actualSamplerate; | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			if (bladerf_set_sample_rate(m_dev, BLADERF_MODULE_RX, settings.m_devSampleRate, &actualSamplerate) < 0) { | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 				qCritical("BladerfInput::applySettings: could not set sample rate: %d", settings.m_devSampleRate); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  | 				qDebug() << "BladerfInput::applySettings: bladerf_set_sample_rate(BLADERF_MODULE_RX) actual sample rate is " << actualSamplerate; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	if ((m_settings.m_bandwidth != settings.m_bandwidth) || force) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |         reverseAPIKeys.append("bandwidth"); | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		if(m_dev != 0) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 			unsigned int actualBandwidth; | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			if( bladerf_set_bandwidth(m_dev, BLADERF_MODULE_RX, settings.m_bandwidth, &actualBandwidth) < 0) { | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 				qCritical("BladerfInput::applySettings: could not set bandwidth: %d", settings.m_bandwidth); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  | 				qDebug() << "BladerfInput::applySettings: bladerf_set_bandwidth(BLADERF_MODULE_RX) actual bandwidth is " << actualBandwidth; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 03:28:30 +01:00
										 |  |  | 	if ((m_settings.m_fcPos != settings.m_fcPos) || force) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |         reverseAPIKeys.append("fcPos"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-21 11:46:08 +02:00
										 |  |  | 		if (m_bladerfThread) | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-01-20 03:28:30 +01:00
										 |  |  | 			m_bladerfThread->setFcPos((int) settings.m_fcPos); | 
					
						
							|  |  |  | 			qDebug() << "BladerfInput::applySettings: set fc pos (enum) to " << (int) settings.m_fcPos; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 03:28:30 +01:00
										 |  |  |     if ((m_settings.m_log2Decim != settings.m_log2Decim) || force) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |         reverseAPIKeys.append("log2Decim"); | 
					
						
							| 
									
										
										
										
											2018-01-20 03:28:30 +01:00
										 |  |  |         forwardChange = true; | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-21 11:46:08 +02:00
										 |  |  |         if (m_bladerfThread) | 
					
						
							| 
									
										
										
										
											2018-01-20 03:28:30 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  |             m_bladerfThread->setLog2Decimation(settings.m_log2Decim); | 
					
						
							|  |  |  |             qDebug() << "BladerfInput::applySettings: set decimation to " << (1<<settings.m_log2Decim); | 
					
						
							| 
									
										
										
										
											2018-01-20 03:28:30 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-02 01:00:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-21 11:46:08 +02:00
										 |  |  |     if ((m_settings.m_iqOrder != settings.m_iqOrder) || force) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         reverseAPIKeys.append("iqOrder"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (m_bladerfThread) { | 
					
						
							|  |  |  |             m_bladerfThread->setIQOrder(settings.m_iqOrder); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |     if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("centerFrequency"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 03:28:30 +01:00
										 |  |  |     if ((m_settings.m_centerFrequency != settings.m_centerFrequency) | 
					
						
							| 
									
										
										
										
											2018-05-10 14:58:07 +02:00
										 |  |  |         || (m_settings.m_devSampleRate != settings.m_devSampleRate) | 
					
						
							| 
									
										
										
										
											2018-01-20 03:28:30 +01:00
										 |  |  |         || (m_settings.m_fcPos != settings.m_fcPos) | 
					
						
							|  |  |  |         || (m_settings.m_log2Decim != settings.m_log2Decim) || force) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-05-10 14:58:07 +02:00
										 |  |  |         qint64 deviceCenterFrequency = DeviceSampleSource::calculateDeviceCenterFrequency( | 
					
						
							|  |  |  |                 settings.m_centerFrequency, | 
					
						
							|  |  |  |                 0, | 
					
						
							|  |  |  |                 settings.m_log2Decim, | 
					
						
							|  |  |  |                 (DeviceSampleSource::fcPos_t) settings.m_fcPos, | 
					
						
							| 
									
										
										
										
											2019-04-02 01:10:03 +02:00
										 |  |  |                 settings.m_devSampleRate, | 
					
						
							|  |  |  |                 DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD, | 
					
						
							|  |  |  |                 false); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:58:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 03:28:30 +01:00
										 |  |  |         forwardChange = true; | 
					
						
							| 
									
										
										
										
											2015-08-12 09:03:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 03:28:30 +01:00
										 |  |  |         if (m_dev != 0) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-05-10 14:58:07 +02:00
										 |  |  |             if (bladerf_set_frequency( m_dev, BLADERF_MODULE_RX, deviceCenterFrequency ) != 0) { | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  |                 qWarning("BladerfInput::applySettings: bladerf_set_frequency(%lld) failed", settings.m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:58:07 +02:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  |                 qDebug("BladerfInput::applySettings: bladerf_set_frequency(%lld)", settings.m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2018-01-20 03:28:30 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-19 09:24:44 +02:00
										 |  |  | 	if (forwardChange) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 		int sampleRate = settings.m_devSampleRate/(1<<settings.m_log2Decim); | 
					
						
							|  |  |  | 		DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, settings.m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2017-09-13 23:40:06 +02:00
										 |  |  |         m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); | 
					
						
							| 
									
										
										
										
											2015-08-19 09:24:44 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +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); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  | 	m_settings = settings; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     qDebug() << "BladerfInput::applySettings: " | 
					
						
							|  |  |  |             << " m_centerFrequency: " << m_settings.m_centerFrequency << " Hz" | 
					
						
							|  |  |  |             << " m_bandwidth: " << m_settings.m_bandwidth | 
					
						
							|  |  |  |             << " m_lnaGain: " << m_settings.m_lnaGain | 
					
						
							|  |  |  |             << " m_vga1: " << m_settings.m_vga1 | 
					
						
							|  |  |  |             << " m_vga2: " << m_settings.m_vga2 | 
					
						
							|  |  |  |             << " m_log2Decim: " << m_settings.m_log2Decim | 
					
						
							| 
									
										
										
										
											2020-06-22 02:10:35 +02:00
										 |  |  |             << " m_iqOrder: " << m_settings.m_iqOrder | 
					
						
							| 
									
										
										
										
											2018-05-30 23:37:47 +02:00
										 |  |  |             << " m_fcPos: " << m_settings.m_fcPos | 
					
						
							|  |  |  |             << " m_devSampleRate: " << m_settings.m_devSampleRate | 
					
						
							|  |  |  |             << " m_dcBlock: " << m_settings.m_dcBlock | 
					
						
							|  |  |  |             << " m_iqCorrection: " << m_settings.m_iqCorrection | 
					
						
							|  |  |  |             << " m_xb200Filter: " << m_settings.m_xb200Filter | 
					
						
							|  |  |  |             << " m_xb200Path: " << m_settings.m_xb200Path | 
					
						
							|  |  |  |             << " m_xb200: " << m_settings.m_xb200; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | bladerf_lna_gain Bladerf1Input::getLnaGain(int lnaGain) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	if (lnaGain == 2) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		return BLADERF_LNA_GAIN_MAX; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (lnaGain == 1) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		return BLADERF_LNA_GAIN_MID; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		return BLADERF_LNA_GAIN_BYPASS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | int Bladerf1Input::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.setBladeRf1InputSettings(new SWGSDRangel::SWGBladeRF1InputSettings()); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->init(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     webapiFormatDeviceSettings(response, m_settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | void Bladerf1Input::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const BladeRF1InputSettings& settings) | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |     response.getBladeRf1InputSettings()->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setDevSampleRate(settings.m_devSampleRate); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setLnaGain(settings.m_lnaGain); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setVga1(settings.m_vga1); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setVga2(settings.m_vga2); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setBandwidth(settings.m_bandwidth); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setLog2Decim(settings.m_log2Decim); | 
					
						
							| 
									
										
										
										
											2020-06-22 02:10:35 +02:00
										 |  |  |     response.getBladeRf1InputSettings()->setIqOrder(settings.m_iqOrder ? 1 : 0); | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |     response.getBladeRf1InputSettings()->setFcPos((int) settings.m_fcPos); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setXb200(settings.m_xb200 ? 1 : 0); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setXb200Path((int) settings.m_xb200Path); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setXb200Filter((int) settings.m_xb200Filter); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setDcBlock(settings.m_dcBlock ? 1 : 0); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setIqCorrection(settings.m_iqCorrection ? 1 : 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-11 08:50:47 +01:00
										 |  |  |     response.getBladeRf1InputSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0); | 
					
						
							| 
									
										
										
										
											2019-01-10 22:35:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-11 08:50:47 +01:00
										 |  |  |     if (response.getBladeRf1InputSettings()->getReverseApiAddress()) { | 
					
						
							|  |  |  |         *response.getBladeRf1InputSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress; | 
					
						
							| 
									
										
										
										
											2019-01-10 22:35:38 +01:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2019-01-11 08:50:47 +01:00
										 |  |  |         response.getBladeRf1InputSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress)); | 
					
						
							| 
									
										
										
										
											2019-01-10 22:35:38 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-11 08:50:47 +01:00
										 |  |  |     response.getBladeRf1InputSettings()->setReverseApiPort(settings.m_reverseAPIPort); | 
					
						
							|  |  |  |     response.getBladeRf1InputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | int Bladerf1Input::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:56:39 +02:00
										 |  |  |     BladeRF1InputSettings settings = m_settings; | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  |     webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  |     MsgConfigureBladerf1 *msg = MsgConfigureBladerf1::create(settings, force); | 
					
						
							|  |  |  |     m_inputMessageQueue.push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) // forward to GUI if any
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgConfigureBladerf1 *msgToGUI = MsgConfigureBladerf1::create(settings, force); | 
					
						
							|  |  |  |         m_guiMessageQueue->push(msgToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     webapiFormatDeviceSettings(response, settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Bladerf1Input::webapiUpdateDeviceSettings( | 
					
						
							|  |  |  |         BladeRF1InputSettings& settings, | 
					
						
							|  |  |  |         const QStringList& deviceSettingsKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceSettings& response) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     if (deviceSettingsKeys.contains("centerFrequency")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_centerFrequency = response.getBladeRf1InputSettings()->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.getBladeRf1InputSettings()->getDevSampleRate(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("lnaGain")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_lnaGain = response.getBladeRf1InputSettings()->getLnaGain(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("vga1")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_vga1 = response.getBladeRf1InputSettings()->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.getBladeRf1InputSettings()->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.getBladeRf1InputSettings()->getBandwidth(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2Decim")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_log2Decim = response.getBladeRf1InputSettings()->getLog2Decim(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-22 02:10:35 +02:00
										 |  |  |     if (deviceSettingsKeys.contains("iqOrder")) { | 
					
						
							|  |  |  |         settings.m_iqOrder = response.getBladeRf1InputSettings()->getIqOrder() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     if (deviceSettingsKeys.contains("fcPos")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  |         settings.m_fcPos = static_cast<BladeRF1InputSettings::fcPos_t>(response.getBladeRf1InputSettings()->getFcPos()); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_xb200 = response.getBladeRf1InputSettings()->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.getBladeRf1InputSettings()->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.getBladeRf1InputSettings()->getXb200Filter()); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("dcBlock")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_dcBlock = response.getBladeRf1InputSettings()->getDcBlock() != 0; | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("iqCorrection")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_iqCorrection = response.getBladeRf1InputSettings()->getIqCorrection() != 0; | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-01-10 22:35:38 +01:00
										 |  |  |     if (deviceSettingsKeys.contains("useReverseAPI")) { | 
					
						
							| 
									
										
										
										
											2019-01-11 08:50:47 +01:00
										 |  |  |         settings.m_useReverseAPI = response.getBladeRf1InputSettings()->getUseReverseApi() != 0; | 
					
						
							| 
									
										
										
										
											2019-01-10 22:35:38 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIAddress")) { | 
					
						
							| 
									
										
										
										
											2019-01-11 08:50:47 +01:00
										 |  |  |         settings.m_reverseAPIAddress = *response.getBladeRf1InputSettings()->getReverseApiAddress(); | 
					
						
							| 
									
										
										
										
											2019-01-10 22:35:38 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIPort")) { | 
					
						
							| 
									
										
										
										
											2019-01-11 08:50:47 +01:00
										 |  |  |         settings.m_reverseAPIPort = response.getBladeRf1InputSettings()->getReverseApiPort(); | 
					
						
							| 
									
										
										
										
											2019-01-10 22:35:38 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) { | 
					
						
							| 
									
										
										
										
											2019-01-11 08:50:47 +01:00
										 |  |  |         settings.m_reverseAPIDeviceIndex = response.getBladeRf1InputSettings()->getReverseApiDeviceIndex(); | 
					
						
							| 
									
										
										
										
											2019-01-10 22:35:38 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | int Bladerf1Input::webapiRunGet( | 
					
						
							| 
									
										
										
										
											2017-12-09 12:41:42 +01:00
										 |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |         QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2017-12-09 12:41:42 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2017-12-09 12:41:42 +01:00
										 |  |  |     m_deviceAPI->getDeviceEngineStateStr(*response.getState()); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:56:39 +02:00
										 |  |  | int Bladerf1Input::webapiRun( | 
					
						
							| 
									
										
										
										
											2017-12-09 12:41:42 +01:00
										 |  |  |         bool run, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |         QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2017-12-09 12:41:42 +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:19:59 +01:00
										 |  |  |     MsgStartStop *message = MsgStartStop::create(run); | 
					
						
							|  |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) // forward to GUI if any
 | 
					
						
							| 
									
										
										
										
											2017-12-09 12:41:42 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-12-14 00:19:59 +01:00
										 |  |  |         MsgStartStop *msgToGUI = MsgStartStop::create(run); | 
					
						
							|  |  |  |         m_guiMessageQueue->push(msgToGUI); | 
					
						
							| 
									
										
										
										
											2017-12-09 12:41:42 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | void Bladerf1Input::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const BladeRF1InputSettings& settings, bool force) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |     swgDeviceSettings->setDirection(0); // single Rx
 | 
					
						
							| 
									
										
										
										
											2019-03-25 13:41:38 +01:00
										 |  |  |     swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |     swgDeviceSettings->setDeviceHwType(new QString("BladeRF1")); | 
					
						
							|  |  |  |     swgDeviceSettings->setBladeRf1InputSettings(new SWGSDRangel::SWGBladeRF1InputSettings()); | 
					
						
							|  |  |  |     SWGSDRangel::SWGBladeRF1InputSettings *swgBladeRF1Settings = swgDeviceSettings->getBladeRf1InputSettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // transfer data that has been modified. When force is on transfer all data except reverse API data
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("centerFrequency") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("devSampleRate") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setDevSampleRate(settings.m_devSampleRate); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("lnaGain") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setLnaGain(settings.m_lnaGain); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("vga1") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setVga1(settings.m_vga1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("vga2") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setVga1(settings.m_vga2); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("bandwidth") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setBandwidth(settings.m_bandwidth); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2Decim") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setLog2Decim(settings.m_log2Decim); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-22 02:10:35 +02:00
										 |  |  |     if (deviceSettingsKeys.contains("iqOrder") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setIqOrder(settings.m_iqOrder ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |     if (deviceSettingsKeys.contains("fcPos") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setFcPos((int) settings.m_fcPos); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setXb200(settings.m_xb200 ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200Path") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setXb200Path((int) settings.m_xb200Path); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200Filter") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setXb200Filter((int) settings.m_xb200Filter); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("dcBlock") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setDcBlock(settings.m_dcBlock ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("iqCorrection") || force) { | 
					
						
							|  |  |  |         swgBladeRF1Settings->setIqCorrection(settings.m_iqCorrection ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     QBuffer *buffer = new QBuffer(); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |     buffer->open((QBuffer::ReadWrite)); | 
					
						
							|  |  |  |     buffer->write(swgDeviceSettings->asJson().toUtf8()); | 
					
						
							|  |  |  |     buffer->seek(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Always use PATCH to avoid passing reverse API settings
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer); | 
					
						
							|  |  |  |     buffer->setParent(reply); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     delete swgDeviceSettings; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Bladerf1Input::webapiReverseSendStartStop(bool start) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-25 15:21:17 +01:00
										 |  |  |     SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |     swgDeviceSettings->setDirection(0); // single Rx
 | 
					
						
							| 
									
										
										
										
											2019-03-25 15:21:17 +01:00
										 |  |  |     swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); | 
					
						
							|  |  |  |     swgDeviceSettings->setDeviceHwType(new QString("BladeRF1")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |     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)); | 
					
						
							| 
									
										
										
										
											2019-03-25 15:21:17 +01:00
										 |  |  |     m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     QBuffer *buffer = new QBuffer(); | 
					
						
							| 
									
										
										
										
											2019-03-25 15:21:17 +01:00
										 |  |  |     buffer->open((QBuffer::ReadWrite)); | 
					
						
							|  |  |  |     buffer->write(swgDeviceSettings->asJson().toUtf8()); | 
					
						
							|  |  |  |     buffer->seek(0); | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     QNetworkReply *reply; | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (start) { | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |         reply = m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |         reply = m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-14 16:58:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     buffer->setParent(reply); | 
					
						
							| 
									
										
										
										
											2019-06-14 16:58:09 +02:00
										 |  |  |     delete swgDeviceSettings; | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Bladerf1Input::networkManagerFinished(QNetworkReply *reply) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QNetworkReply::NetworkError replyError = reply->error(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (replyError) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qWarning() << "Bladerf1Input::networkManagerFinished:" | 
					
						
							|  |  |  |                 << " error(" << (int) replyError | 
					
						
							|  |  |  |                 << "): " << replyError | 
					
						
							|  |  |  |                 << ": " << reply->errorString(); | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString answer = reply->readAll(); | 
					
						
							|  |  |  |         answer.chop(1); // remove last \n
 | 
					
						
							|  |  |  |         qDebug("Bladerf1Input::networkManagerFinished: reply:\n%s", answer.toStdString().c_str()); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     reply->deleteLater(); | 
					
						
							| 
									
										
										
										
											2018-12-25 21:05:24 +01:00
										 |  |  | } |