| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-18 09:58:55 +01:00
										 |  |  | // Copyright (C) 2017-2019, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com>    //
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01: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:39:30 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01: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-26 19:22:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | #include <QNetworkReply>
 | 
					
						
							|  |  |  | #include <QBuffer>
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  | #include "SWGDeviceSettings.h"
 | 
					
						
							|  |  |  | #include "SWGDeviceState.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | #include "dsp/dspdevicesourceengine.h"
 | 
					
						
							|  |  |  | #include "device/deviceapi.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-29 05:49:14 +02:00
										 |  |  | #include "bladerf1/devicebladerf1shared.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | #include "bladerf1outputthread.h"
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | #include "bladerf1output.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | MESSAGE_CLASS_DEFINITION(Bladerf1Output::MsgConfigureBladerf1, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(Bladerf1Output::MsgStartStop, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(Bladerf1Output::MsgReportBladerf1, Message) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | Bladerf1Output::Bladerf1Output(DeviceAPI *deviceAPI) : | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     m_deviceAPI(deviceAPI), | 
					
						
							|  |  |  | 	m_settings(), | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | 	m_dev(nullptr), | 
					
						
							|  |  |  | 	m_bladerfThread(nullptr), | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  | 	m_deviceDescription("BladeRFOutput"), | 
					
						
							|  |  |  | 	m_running(false) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_sampleSourceFifo.resize(SampleSourceFifo::getSizePolicy(m_settings.m_devSampleRate)); | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     openDevice(); | 
					
						
							| 
									
										
										
										
											2019-05-21 00:27:08 +02:00
										 |  |  |     m_deviceAPI->setNbSinkStreams(1); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     m_deviceAPI->setBuddySharedPtr(&m_sharedParams); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     m_networkManager = new QNetworkAccessManager(); | 
					
						
							| 
									
										
										
										
											2022-03-23 22:32:23 +01:00
										 |  |  |     QObject::connect( | 
					
						
							|  |  |  |         m_networkManager, | 
					
						
							|  |  |  |         &QNetworkAccessManager::finished, | 
					
						
							|  |  |  |         this, | 
					
						
							|  |  |  |         &Bladerf1Output::networkManagerFinished | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | Bladerf1Output::~Bladerf1Output() | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-03-23 22:32:23 +01:00
										 |  |  |     QObject::disconnect( | 
					
						
							|  |  |  |         m_networkManager, | 
					
						
							|  |  |  |         &QNetworkAccessManager::finished, | 
					
						
							|  |  |  |         this, | 
					
						
							|  |  |  |         &Bladerf1Output::networkManagerFinished | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     delete m_networkManager; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_running) { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         Bladerf1Output::stop(); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     closeDevice(); | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     m_deviceAPI->setBuddySharedPtr(nullptr); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::destroy() | 
					
						
							| 
									
										
										
										
											2017-09-16 11:34:25 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | bool Bladerf1Output::openDevice() | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     if (m_dev != nullptr) { | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |         closeDevice(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     int res; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_sampleSourceFifo.resize(SampleSourceFifo::getSizePolicy(m_settings.m_devSampleRate)); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     if (!m_deviceAPI->getSourceBuddies().empty()) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         const DeviceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0]; | 
					
						
							|  |  |  |         const DeviceBladeRF1Params *buddySharedParams = (DeviceBladeRF1Params *) sourceBuddy->getBuddySharedPtr(); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (buddySharedParams == nullptr) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             qCritical("BladerfOutput::start: could not get shared parameters from buddy"); | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (buddySharedParams->m_dev == nullptr) // device is not opened by buddy
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |             qCritical("BladerfOutput::start: could not get BladeRF handle from buddy"); | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         m_sharedParams = *buddySharedParams; // copy parameters from buddy
 | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         m_dev = m_sharedParams.m_dev;          // get BladeRF handle
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         if (!DeviceBladeRF1::open_bladerf(&m_dev, qPrintable(m_deviceAPI->getSamplingDeviceSerial()))) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             qCritical("BladerfOutput::start: could not open BladeRF %s", qPrintable(m_deviceAPI->getSamplingDeviceSerial())); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_sharedParams.m_dev = m_dev; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 23:12:00 +02:00
										 |  |  |     if ((res = bladerf_sync_config(m_dev, BLADERF_TX_X1, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |         qCritical("BladerfOutput::start: bladerf_sync_config with return code %d", res); | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_TX, true)) < 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |         qCritical("BladerfOutput::start: bladerf_enable_module with return code %d", res); | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::init() | 
					
						
							| 
									
										
										
										
											2017-12-25 12:59:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |     applySettings(m_settings, QList<QString>(), true); | 
					
						
							| 
									
										
										
										
											2017-12-25 12:59:44 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | bool Bladerf1Output::start() | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-21 05:27:01 +02:00
										 |  |  | 	QMutexLocker mutexLocker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_running) { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (!m_dev) { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |     m_bladerfThread = new Bladerf1OutputThread(m_dev, &m_sampleSourceFifo); | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  | 	m_bladerfThread->setLog2Interpolation(m_settings.m_log2Interp); | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |     m_bladerfThread->startWork(); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	qDebug("BladerfOutput::start: started"); | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     m_running = true; | 
					
						
							| 
									
										
										
										
											2024-08-21 05:27:01 +02:00
										 |  |  | 	mutexLocker.unlock(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	applySettings(m_settings, QList<QString>(), true); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::closeDevice() | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  |     int res; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-21 05:27:01 +02:00
										 |  |  |     if (m_dev == nullptr) { // was never open
 | 
					
						
							| 
									
										
										
										
											2017-04-17 12:00:13 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  |     if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_TX, false)) < 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         qCritical("BladerfOutput::closeDevice: bladerf_enable_module with return code %d", res); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-21 05:27:01 +02:00
										 |  |  |     if (m_deviceAPI->getSourceBuddies().empty()) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 23:40:14 +02:00
										 |  |  |         qDebug("BladerfOutput::closeDevice: closing device since Rx side is not open"); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:56:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (m_dev != nullptr) // close BladeRF
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             bladerf_close(m_dev); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-21 05:27:01 +02:00
										 |  |  |     m_sharedParams.m_dev = nullptr; | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     m_dev = nullptr; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::stop() | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-21 05:27:01 +02:00
										 |  |  | 	QMutexLocker mutexLocker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_running) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_running = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_bladerfThread) | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		m_bladerfThread->stopWork(); | 
					
						
							|  |  |  | 		delete m_bladerfThread; | 
					
						
							| 
									
										
										
										
											2024-08-21 05:27:01 +02:00
										 |  |  | 		m_bladerfThread = nullptr; | 
					
						
							| 
									
										
										
										
											2017-04-13 21:26:36 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | QByteArray Bladerf1Output::serialize() const | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | bool Bladerf1Output::deserialize(const QByteArray& data) | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     bool success = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_settings.resetToDefaults(); | 
					
						
							|  |  |  |         success = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |     MsgConfigureBladerf1* message = MsgConfigureBladerf1::create(m_settings, QList<QString>(), true); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |         MsgConfigureBladerf1* messageToGUI = MsgConfigureBladerf1::create(m_settings, QList<QString>(), true); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return success; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | const QString& Bladerf1Output::getDeviceDescription() const | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	return m_deviceDescription; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | int Bladerf1Output::getSampleRate() const | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	int rate = m_settings.m_devSampleRate; | 
					
						
							|  |  |  | 	return (rate / (1<<m_settings.m_log2Interp)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | quint64 Bladerf1Output::getCenterFrequency() const | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	return m_settings.m_centerFrequency; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::setCenterFrequency(qint64 centerFrequency) | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |     BladeRF1OutputSettings settings = m_settings; | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |     settings.m_centerFrequency = centerFrequency; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |     MsgConfigureBladerf1* message = MsgConfigureBladerf1::create(settings, QList<QString>{"centerFrequency"}, false); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |         MsgConfigureBladerf1* messageToGUI = MsgConfigureBladerf1::create(settings, QList<QString>{"centerFrequency"}, false); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | bool Bladerf1Output::handleMessage(const Message& message) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | 	if (MsgConfigureBladerf1::match(message)) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 		auto& conf = (const MsgConfigureBladerf1&) message; | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | 		qDebug() << "BladerfOutput::handleMessage: MsgConfigureBladerf"; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  | 		if (!applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce())) { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 			qDebug("BladeRF config error"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |     else if (MsgStartStop::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         auto& cmd = (const MsgStartStop&) message; | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  |         qDebug() << "BladerfOutput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (cmd.getStartStop()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |             if (m_deviceAPI->initDeviceEngine()) { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |                 m_deviceAPI->startDeviceEngine(); | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             m_deviceAPI->stopDeviceEngine(); | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |         if (m_settings.m_useReverseAPI) { | 
					
						
							|  |  |  |             webapiReverseSendStartStop(cmd.getStartStop()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  | bool Bladerf1Output::applySettings(const BladeRF1OutputSettings& settings, const QList<QString>& settingsKeys, bool force) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  | 	qDebug() << "BladerfOutput::applySettings: force:" << force << settings.getDebugString(settingsKeys, force); | 
					
						
							| 
									
										
										
										
											2017-08-08 23:09:51 +02:00
										 |  |  | 	bool forwardChange    = false; | 
					
						
							|  |  |  |     bool suspendOwnThread = false; | 
					
						
							|  |  |  |     bool threadWasRunning = false; | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	QMutexLocker mutexLocker(&m_mutex); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |     if (settingsKeys.contains("devSampleRate") || | 
					
						
							|  |  |  |         settingsKeys.contains("log2Interp") || force) | 
					
						
							| 
									
										
										
										
											2017-08-08 23:09:51 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         suspendOwnThread = true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     if (suspendOwnThread && m_bladerfThread && m_bladerfThread->isRunning()) | 
					
						
							| 
									
										
										
										
											2017-08-08 23:09:51 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         m_bladerfThread->stopWork(); | 
					
						
							|  |  |  |         threadWasRunning = true; | 
					
						
							| 
									
										
										
										
											2017-08-08 23:09:51 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  | 	if (settingsKeys.contains("devSampleRate") || | 
					
						
							|  |  |  |         settingsKeys.contains("log2Interp") || force) | 
					
						
							| 
									
										
										
										
											2017-08-08 23:09:51 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-11-15 09:37:14 +01:00
										 |  |  | #if defined(_MSC_VER)
 | 
					
						
							|  |  |  |         unsigned int fifoRate = (unsigned int) settings.m_devSampleRate / (1<<settings.m_log2Interp); | 
					
						
							|  |  |  |         fifoRate = fifoRate < 48000U ? 48000U : fifoRate; | 
					
						
							| 
									
										
										
										
											2022-03-23 22:32:23 +01:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |         unsigned int fifoRate = std::max( | 
					
						
							|  |  |  |             (unsigned int) settings.m_devSampleRate / (1<<settings.m_log2Interp), | 
					
						
							|  |  |  |             DeviceBladeRF1Shared::m_sampleFifoMinRate); | 
					
						
							| 
									
										
										
										
											2019-11-15 09:37:14 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |         m_sampleSourceFifo.resize(SampleSourceFifo::getSizePolicy(fifoRate)); | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         forwardChange = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (m_dev != nullptr) | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             unsigned int actualSamplerate; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |             if (bladerf_set_sample_rate(m_dev, BLADERF_MODULE_TX, settings.m_devSampleRate, &actualSamplerate) < 0) { | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |                 qCritical("BladerfOutput::applySettings: could not set sample rate: %d", settings.m_devSampleRate); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |                 qDebug() << "BladerfOutput::applySettings: bladerf_set_sample_rate(BLADERF_MODULE_TX) actual sample rate is " << actualSamplerate; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |     if (settingsKeys.contains("log2Interp") || force) | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         forwardChange = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (m_bladerfThread != nullptr) | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             m_bladerfThread->setLog2Interpolation(settings.m_log2Interp); | 
					
						
							|  |  |  |             qDebug() << "BladerfOutput::applySettings: set interpolation to " << (1<<settings.m_log2Interp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	if ((m_dev != nullptr) && (settingsKeys.contains("vga1") || force)) | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (bladerf_set_txvga1(m_dev, settings.m_vga1) != 0) { | 
					
						
							|  |  |  |             qDebug("BladerfOutput::applySettings: bladerf_set_txvga1() failed"); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             qDebug() << "BladerfOutput::applySettings: VGA1 gain set to " << settings.m_vga1; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	if ((m_dev != nullptr) && (settingsKeys.contains("vga2") || force)) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (bladerf_set_txvga2(m_dev, settings.m_vga2) != 0) { | 
					
						
							|  |  |  |             qDebug("BladerfOutput::applySettings:bladerf_set_rxvga2() failed"); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             qDebug() << "BladerfOutput::applySettings: VGA2 gain set to " << settings.m_vga2; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	if ((m_dev != nullptr) && (settingsKeys.contains("xb200") || force)) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         bool changeSettings; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (!m_deviceAPI->getSourceBuddies().empty()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             DeviceAPI *buddy = m_deviceAPI->getSourceBuddies()[0]; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |             if (buddy->getDeviceSourceEngine()->state() == DSPDeviceSourceEngine::State::StRunning) { // Tx side running
 | 
					
						
							|  |  |  |                 changeSettings = false; | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |                 changeSettings = true; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else // No Rx open
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             changeSettings = true; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (changeSettings) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (settings.m_xb200) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |                 if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) != 0) { | 
					
						
							|  |  |  |                     qDebug("BladerfOutput::applySettings: bladerf_expansion_attach(xb200) failed"); | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     qDebug() << "BladerfOutput::applySettings: Attach XB200"; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (bladerf_expansion_attach(m_dev, BLADERF_XB_NONE) != 0) { | 
					
						
							|  |  |  |                     qDebug("BladerfOutput::applySettings: bladerf_expansion_attach(none) failed"); | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     qDebug() << "BladerfOutput::applySettings: Detach XB200"; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             m_sharedParams.m_xb200Attached = settings.m_xb200; | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	if ((m_dev != nullptr) && (settingsKeys.contains("xb200Path") || force)) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (bladerf_xb200_set_path(m_dev, BLADERF_MODULE_TX, settings.m_xb200Path) != 0) { | 
					
						
							|  |  |  |             qDebug("BladerfOutput::applySettings: bladerf_xb200_set_path(BLADERF_MODULE_TX) failed"); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             qDebug() << "BladerfOutput::applySettings: set xb200 path to " << settings.m_xb200Path; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	if ((m_dev != nullptr) && (settingsKeys.contains("xb200Filter") || force)) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (bladerf_xb200_set_filterbank(m_dev, BLADERF_MODULE_TX, settings.m_xb200Filter) != 0) { | 
					
						
							|  |  |  |             qDebug("BladerfOutput::applySettings: bladerf_xb200_set_filterbank(BLADERF_MODULE_TX) failed"); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             qDebug() << "BladerfOutput::applySettings: set xb200 filter to " << settings.m_xb200Filter; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	if ((m_dev != nullptr) && (settingsKeys.contains("bandwidth") || force)) | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         unsigned int actualBandwidth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (bladerf_set_bandwidth(m_dev, BLADERF_MODULE_TX, settings.m_bandwidth, &actualBandwidth) < 0) { | 
					
						
							|  |  |  |             qCritical("BladerfOutput::applySettings: could not set bandwidth: %d", settings.m_bandwidth); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             qDebug() << "BladerfOutput::applySettings: bladerf_set_bandwidth(BLADERF_MODULE_TX) actual bandwidth is " << actualBandwidth; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  | 	if (settingsKeys.contains("centerFrequency")) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 		forwardChange = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if ((m_dev != nullptr) && (bladerf_set_frequency( m_dev, BLADERF_MODULE_TX, settings.m_centerFrequency ) != 0)) { | 
					
						
							|  |  |  |             qDebug("BladerfOutput::applySettings: bladerf_set_frequency(%lld) failed", settings.m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-08 23:09:51 +02:00
										 |  |  |     if (threadWasRunning) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_bladerfThread->startWork(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-14 18:58:12 +02:00
										 |  |  |     if (settings.m_useReverseAPI) | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |         bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) || | 
					
						
							|  |  |  |             settingsKeys.contains("reverseAPIAddress") || | 
					
						
							|  |  |  |             settingsKeys.contains("reverseAPIPort") || | 
					
						
							|  |  |  |             settingsKeys.contains("reverseAPIDeviceIndex"); | 
					
						
							|  |  |  |         webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |     if (force) { | 
					
						
							|  |  |  |         m_settings = settings; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         m_settings.applySettings(settingsKeys, settings); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-09 22:33:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	if (forwardChange) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		int sampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Interp); | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 		auto *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2017-09-13 23:42:28 +02:00
										 |  |  | 		m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); | 
					
						
							| 
									
										
										
										
											2017-01-02 10:39:21 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | int Bladerf1Output::webapiSettingsGet( | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |                 SWGSDRangel::SWGDeviceSettings& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |                 QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |     response.setBladeRf1OutputSettings(new SWGSDRangel::SWGBladeRF1OutputSettings()); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->init(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     webapiFormatDeviceSettings(response, m_settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | void Bladerf1Output::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const BladeRF1OutputSettings& settings) | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |     response.getBladeRf1OutputSettings()->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setDevSampleRate(settings.m_devSampleRate); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setVga1(settings.m_vga1); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setVga2(settings.m_vga2); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setBandwidth(settings.m_bandwidth); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setLog2Interp(settings.m_log2Interp); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setXb200(settings.m_xb200 ? 1 : 0); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setXb200Path((int) settings.m_xb200Path); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setXb200Filter((int) settings.m_xb200Filter); | 
					
						
							| 
									
										
										
										
											2019-01-11 14:45:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (response.getBladeRf1OutputSettings()->getReverseApiAddress()) { | 
					
						
							|  |  |  |         *response.getBladeRf1OutputSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.getBladeRf1OutputSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setReverseApiPort(settings.m_reverseAPIPort); | 
					
						
							|  |  |  |     response.getBladeRf1OutputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | int Bladerf1Output::webapiSettingsPutPatch( | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |                 bool force, | 
					
						
							|  |  |  |                 const QStringList& deviceSettingsKeys, | 
					
						
							|  |  |  |                 SWGSDRangel::SWGDeviceSettings& response, // query + response
 | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |                 QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  |     BladeRF1OutputSettings settings = m_settings; | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  |     webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |     MsgConfigureBladerf1 *msg = MsgConfigureBladerf1::create(settings, deviceSettingsKeys, force); | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  |     m_inputMessageQueue.push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) // forward to GUI if any
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  |         MsgConfigureBladerf1 *msgToGUI = MsgConfigureBladerf1::create(settings, deviceSettingsKeys, force); | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  |         m_guiMessageQueue->push(msgToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     webapiFormatDeviceSettings(response, settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-05 18:29:09 +02:00
										 |  |  | void Bladerf1Output::webapiUpdateDeviceSettings( | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  |     BladeRF1OutputSettings& 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.getBladeRf1OutputSettings()->getCenterFrequency(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("devSampleRate")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_devSampleRate = response.getBladeRf1OutputSettings()->getDevSampleRate(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("vga1")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_vga1 = response.getBladeRf1OutputSettings()->getVga1(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("vga2")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_vga2 = response.getBladeRf1OutputSettings()->getVga2(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("bandwidth")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_bandwidth = response.getBladeRf1OutputSettings()->getBandwidth(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2Interp")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_log2Interp = response.getBladeRf1OutputSettings()->getLog2Interp(); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200")) { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         settings.m_xb200 = response.getBladeRf1OutputSettings()->getXb200() == 0 ? false : true; | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200Path")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_xb200Path = static_cast<bladerf_xb200_path>(response.getBladeRf1OutputSettings()->getXb200Path()); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200Filter")) { | 
					
						
							| 
									
										
										
										
											2018-09-19 05:54:07 +02:00
										 |  |  |         settings.m_xb200Filter = static_cast<bladerf_xb200_filter>(response.getBladeRf1OutputSettings()->getXb200Filter()); | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-01-11 14:45:00 +01:00
										 |  |  |     if (deviceSettingsKeys.contains("useReverseAPI")) { | 
					
						
							|  |  |  |         settings.m_useReverseAPI = response.getBladeRf1OutputSettings()->getUseReverseApi() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIAddress")) { | 
					
						
							|  |  |  |         settings.m_reverseAPIAddress = *response.getBladeRf1OutputSettings()->getReverseApiAddress(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIPort")) { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         settings.m_reverseAPIPort = (uint16_t) response.getBladeRf1OutputSettings()->getReverseApiPort(); | 
					
						
							| 
									
										
										
										
											2019-01-11 14:45:00 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         settings.m_reverseAPIDeviceIndex = (uint16_t) response.getBladeRf1OutputSettings()->getReverseApiDeviceIndex(); | 
					
						
							| 
									
										
										
										
											2019-01-11 14:45:00 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-31 19:29:52 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | int Bladerf1Output::webapiRunGet( | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |         QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  |     m_deviceAPI->getDeviceEngineStateStr(*response.getState()); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 08:42:59 +02:00
										 |  |  | int Bladerf1Output::webapiRun( | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  |         bool run, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |         QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2017-12-14 23:29:12 +01:00
										 |  |  |     m_deviceAPI->getDeviceEngineStateStr(*response.getState()); | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |     MsgStartStop *message = MsgStartStop::create(run); | 
					
						
							|  |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |         MsgStartStop *messagetoGui = MsgStartStop::create(run); | 
					
						
							|  |  |  |         m_guiMessageQueue->push(messagetoGui); | 
					
						
							| 
									
										
										
										
											2017-12-10 01:57:50 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-29 23:56:46 +02:00
										 |  |  | void Bladerf1Output::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const BladeRF1OutputSettings& settings, bool force) | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |     swgDeviceSettings->setDirection(1); // single Tx
 | 
					
						
							| 
									
										
										
										
											2019-03-25 13:46:42 +01:00
										 |  |  |     swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     swgDeviceSettings->setDeviceHwType(new QString("BladeRF1")); | 
					
						
							|  |  |  |     swgDeviceSettings->setBladeRf1OutputSettings(new SWGSDRangel::SWGBladeRF1OutputSettings()); | 
					
						
							|  |  |  |     SWGSDRangel::SWGBladeRF1OutputSettings *swgBladeRF1OutputSettings = swgDeviceSettings->getBladeRf1OutputSettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // transfer data that has been modified. When force is on transfer all data except reverse API data
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("centerFrequency") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("devSampleRate") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setDevSampleRate(settings.m_devSampleRate); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("vga1") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setVga1(settings.m_vga1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("vga2") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setVga2(settings.m_vga2); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("bandwidth") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setBandwidth(settings.m_bandwidth); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2Interp") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setLog2Interp(settings.m_log2Interp); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setXb200(settings.m_xb200 ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200Path") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setXb200Path((int) settings.m_xb200Path); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("xb200Filter") || force) { | 
					
						
							|  |  |  |         swgBladeRF1OutputSettings->setXb200Filter((int) settings.m_xb200Filter); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString deviceSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/settings") | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIAddress) | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIPort) | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  |     m_networkRequest.setUrl(QUrl(deviceSettingsURL)); | 
					
						
							|  |  |  |     m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     auto *buffer = new QBuffer(); | 
					
						
							|  |  |  |     buffer->open(QBuffer::ReadWrite); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     buffer->write(swgDeviceSettings->asJson().toUtf8()); | 
					
						
							|  |  |  |     buffer->seek(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Always use PATCH to avoid passing reverse API settings
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer); | 
					
						
							|  |  |  |     buffer->setParent(reply); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     delete swgDeviceSettings; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Bladerf1Output::webapiReverseSendStartStop(bool start) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |     swgDeviceSettings->setDirection(1); // single Tx
 | 
					
						
							| 
									
										
										
										
											2019-03-25 15:26:01 +01:00
										 |  |  |     swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); | 
					
						
							|  |  |  |     swgDeviceSettings->setDeviceHwType(new QString("BladeRF1")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +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:26:01 +01:00
										 |  |  |     m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     auto *buffer = new QBuffer(); | 
					
						
							|  |  |  |     buffer->open(QBuffer::ReadWrite); | 
					
						
							| 
									
										
										
										
											2019-03-25 15:26:01 +01:00
										 |  |  |     buffer->write(swgDeviceSettings->asJson().toUtf8()); | 
					
						
							|  |  |  |     buffer->seek(0); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     QNetworkReply *reply; | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (start) { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |         reply = m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |         reply = m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-14 16:58:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     buffer->setParent(reply); | 
					
						
							| 
									
										
										
										
											2019-06-14 16:58:09 +02:00
										 |  |  |     delete swgDeviceSettings; | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | void Bladerf1Output::networkManagerFinished(QNetworkReply *reply) const | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     QNetworkReply::NetworkError replyError = reply->error(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (replyError) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qWarning() << "Bladerf1Output::networkManagerFinished:" | 
					
						
							|  |  |  |                 << " error(" << (int) replyError | 
					
						
							|  |  |  |                 << "): " << replyError | 
					
						
							|  |  |  |                 << ": " << reply->errorString(); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString answer = reply->readAll(); | 
					
						
							|  |  |  |         answer.chop(1); // remove last \n
 | 
					
						
							|  |  |  |         qDebug("Bladerf1Output::networkManagerFinished: reply:\n%s", answer.toStdString().c_str()); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     reply->deleteLater(); | 
					
						
							| 
									
										
										
										
											2018-12-26 19:22:52 +01:00
										 |  |  | } |