| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | // Copyright (C) 2017, 2018 Edouard Griffiths, F4EXB                             //
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | // Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc.                          //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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.                                           //
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +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 <cstddef>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include "xtrx_api.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  | #include <QMutexLocker>
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <QNetworkReply>
 | 
					
						
							|  |  |  | #include <QBuffer>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "SWGDeviceSettings.h"
 | 
					
						
							|  |  |  | #include "SWGXtrxInputSettings.h"
 | 
					
						
							|  |  |  | #include "SWGDeviceState.h"
 | 
					
						
							|  |  |  | #include "SWGDeviceReport.h"
 | 
					
						
							|  |  |  | #include "SWGXtrxInputReport.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | #include "device/deviceapi.h"
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							|  |  |  | #include "dsp/filerecord.h"
 | 
					
						
							|  |  |  | #include "xtrxinput.h"
 | 
					
						
							|  |  |  | #include "xtrxinputthread.h"
 | 
					
						
							|  |  |  | #include "xtrx/devicextrxparam.h"
 | 
					
						
							|  |  |  | #include "xtrx/devicextrxshared.h"
 | 
					
						
							| 
									
										
										
										
											2018-12-30 10:13:17 +01:00
										 |  |  | #include "xtrx/devicextrx.h"
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(XTRXInput::MsgConfigureXTRX, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(XTRXInput::MsgGetStreamInfo, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(XTRXInput::MsgGetDeviceInfo, Message) | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  | MESSAGE_CLASS_DEFINITION(XTRXInput::MsgReportClockGenChange, Message) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | MESSAGE_CLASS_DEFINITION(XTRXInput::MsgReportStreamInfo, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(XTRXInput::MsgFileRecord, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(XTRXInput::MsgStartStop, Message) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | XTRXInput::XTRXInput(DeviceAPI *deviceAPI) : | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     m_deviceAPI(deviceAPI), | 
					
						
							|  |  |  |     m_settings(), | 
					
						
							|  |  |  |     m_XTRXInputThread(0), | 
					
						
							|  |  |  |     m_deviceDescription("XTRXInput"), | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     m_running(false) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     openDevice(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID())); | 
					
						
							| 
									
										
										
										
											2019-05-21 00:27:08 +02:00
										 |  |  |     m_deviceAPI->setNbSourceStreams(1); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |     m_deviceAPI->addAncillarySink(m_fileSink); | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_networkManager = new QNetworkAccessManager(); | 
					
						
							|  |  |  |     connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | XTRXInput::~XTRXInput() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); | 
					
						
							|  |  |  |     delete m_networkManager; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (m_running) { | 
					
						
							|  |  |  |         stop(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |     m_deviceAPI->removeAncillarySink(m_fileSink); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     delete m_fileSink; | 
					
						
							|  |  |  |     closeDevice(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::destroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool XTRXInput::openDevice() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!m_sampleFifo.setSize(96000 * 4)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qCritical("XTRXInput::openDevice: could not allocate SampleFifo"); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("XTRXInput::openDevice: allocated SampleFifo"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     // look for Rx buddies and get reference to the device object
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     if (m_deviceAPI->getSourceBuddies().size() > 0) // look source sibling first
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("XTRXInput::openDevice: look in Rx buddies"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         DeviceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0]; | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         DeviceXTRXShared *deviceXTRXShared = (DeviceXTRXShared*) sourceBuddy->getBuddySharedPtr(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (deviceXTRXShared == 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             qCritical("XTRXInput::openDevice: the source buddy shared pointer is null"); | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         DeviceXTRX *device = deviceXTRXShared->m_dev; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (device == 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             qCritical("XTRXInput::openDevice: cannot get device pointer from Rx buddy"); | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         m_deviceShared.m_dev = device; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     // look for Tx buddies and get reference to the device object
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     else if (m_deviceAPI->getSinkBuddies().size() > 0) // then sink
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("XTRXInput::openDevice: look in Tx buddies"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         DeviceAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0]; | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         DeviceXTRXShared *deviceXTRXShared = (DeviceXTRXShared*) sinkBuddy->getBuddySharedPtr(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (deviceXTRXShared == 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             qCritical("XTRXInput::openDevice: the sink buddy shared pointer is null"); | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         DeviceXTRX *device = deviceXTRXShared->m_dev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (device == 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             qCritical("XTRXInput::openDevice: cannot get device pointer from Tx buddy"); | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         m_deviceShared.m_dev = device; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     // There are no buddies then create the first BladeRF2 device
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("XTRXInput::openDevice: open device here"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         m_deviceShared.m_dev = new DeviceXTRX(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         char serial[256]; | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         strcpy(serial, qPrintable(m_deviceAPI->getSamplingDeviceSerial())); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (!m_deviceShared.m_dev->open(serial)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qCritical("XTRXInput::openDevice: cannot open BladeRF2 device"); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-21 00:27:08 +02:00
										 |  |  |     m_deviceShared.m_channel = m_deviceAPI->getDeviceItemIndex(); // publicly allocate channel
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     m_deviceShared.m_source = this; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     m_deviceAPI->setBuddySharedPtr(&m_deviceShared); // propagate common parameters to API
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | void XTRXInput::closeDevice() | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (m_deviceShared.m_dev == 0) { // was never open
 | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (m_running) { | 
					
						
							|  |  |  |         stop(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (m_XTRXInputThread) { // stills own the thread => transfer to a buddy
 | 
					
						
							|  |  |  |         moveThreadToBuddy(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     m_deviceShared.m_channel = -1; // publicly release channel
 | 
					
						
							|  |  |  |     m_deviceShared.m_source = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // No buddies so effectively close the device
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((m_deviceAPI->getSinkBuddies().size() == 0) && (m_deviceAPI->getSourceBuddies().size() == 0)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_deviceShared.m_dev->close(); | 
					
						
							|  |  |  |         delete m_deviceShared.m_dev; | 
					
						
							|  |  |  |         m_deviceShared.m_dev = 0; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | void XTRXInput::init() | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     applySettings(m_settings, true, false); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | XTRXInputThread *XTRXInput::findThread() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_XTRXInputThread == 0) // this does not own the thread
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         XTRXInputThread *xtrxInputThread = 0; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         // find a buddy that has allocated the thread
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies(); | 
					
						
							|  |  |  |         std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (; it != sourceBuddies.end(); ++it) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             XTRXInput *buddySource = ((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_source; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (buddySource) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 xtrxInputThread = buddySource->getThread(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (xtrxInputThread) { | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return xtrxInputThread; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return m_XTRXInputThread; // own thread
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | void XTRXInput::moveThreadToBuddy() | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |     const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies(); | 
					
						
							|  |  |  |     std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     for (; it != sourceBuddies.end(); ++it) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         XTRXInput *buddySource = ((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_source; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (buddySource) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             buddySource->setThread(m_XTRXInputThread); | 
					
						
							|  |  |  |             m_XTRXInputThread = 0;  // zero for others
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | bool XTRXInput::start() | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     // There is a single thread per physical device (Rx side). This thread is unique and referenced by a unique
 | 
					
						
							|  |  |  |     // buddy in the group of source buddies associated with this physical device.
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // This start method is responsible for managing the thread when the streaming of a Rx channel is started
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // It checks the following conditions
 | 
					
						
							|  |  |  |     //   - the thread is allocated or not (by itself or one of its buddies). If it is it grabs the thread pointer.
 | 
					
						
							|  |  |  |     //   - the requested channel is another channel (one is already streaming).
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // The XTRX support library lets you work in two possible modes:
 | 
					
						
							|  |  |  |     //   - Single Input (SI) with only one channel streaming. This can be channel 0 or 1 (channels can be swapped - unlike with BladeRF2).
 | 
					
						
							|  |  |  |     //   - Multiple Input (MI) with two channels streaming using interleaved samples. It MUST be in this configuration if both channels are
 | 
					
						
							|  |  |  |     //     streaming.
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // It manages the transition form SI where only one channel is running to the  Multiple Input (MI) if the both channels are requested.
 | 
					
						
							|  |  |  |     // To perform the transition it stops the thread, deletes it and creates a new one.
 | 
					
						
							|  |  |  |     // It marks the thread as needing start.
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // If there is no thread allocated it means we are in SI mode and it creates a new one with the requested channel.
 | 
					
						
							|  |  |  |     // It marks the thread as needing start.
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // Eventually it registers the FIFO in the thread. If the thread has to be started it enables the channels up to the number of channels
 | 
					
						
							|  |  |  |     // allocated in the thread and starts the thread.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_deviceShared.m_dev || !m_deviceShared.m_dev->getDevice()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("XTRXInput::start: no device object"); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-21 00:27:08 +02:00
										 |  |  |     int requestedChannel = m_deviceAPI->getDeviceItemIndex(); | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     XTRXInputThread *xtrxInputThread = findThread(); | 
					
						
							|  |  |  |     bool needsStart = false; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (xtrxInputThread) // if thread is already allocated
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         qDebug("XTRXInput::start: thread is already allocated"); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         unsigned int nbOriginalChannels = xtrxInputThread->getNbChannels(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         // if one channel is already allocated it must be the other one so we'll end up with both channels
 | 
					
						
							|  |  |  |         // thus we expand by deleting and re-creating the thread
 | 
					
						
							|  |  |  |         if (nbOriginalChannels != 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug("XTRXInput::start: expand channels. Re-allocate thread and take ownership"); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             SampleSinkFifo **fifos = new SampleSinkFifo*[2]; | 
					
						
							|  |  |  |             unsigned int *log2Decims = new unsigned int[2]; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             for (int i = 0; i < 2; i++) // save original FIFO references and data
 | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 fifos[i] = xtrxInputThread->getFifo(i); | 
					
						
							|  |  |  |                 log2Decims[i] = xtrxInputThread->getLog2Decimation(i); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             xtrxInputThread->stopWork(); | 
					
						
							|  |  |  |             delete xtrxInputThread; | 
					
						
							|  |  |  |             xtrxInputThread = new XTRXInputThread(m_deviceShared.m_dev->getDevice(), 2); // MI mode (2 channels)
 | 
					
						
							|  |  |  |             m_XTRXInputThread = xtrxInputThread; // take ownership
 | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |             m_deviceShared.m_thread = xtrxInputThread; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             for (int i = 0; i < 2; i++) // restore original FIFO references
 | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 xtrxInputThread->setFifo(i, fifos[i]); | 
					
						
							|  |  |  |                 xtrxInputThread->setLog2Decimation(i, log2Decims[i]); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             // remove old thread address from buddies (reset in all buddies). The address being held only in the owning source.
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies(); | 
					
						
							|  |  |  |             std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |             for (; it != sourceBuddies.end(); ++it) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |                 ((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_source->setThread(0); | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |                 ((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_thread = 0; | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             // was used as temporary storage:
 | 
					
						
							|  |  |  |             delete[] fifos; | 
					
						
							|  |  |  |             delete[] log2Decims; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             needsStart = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug("XTRXInput::start: keep buddy thread"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else // first allocation
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("XTRXInput::start: allocate thread and take ownership"); | 
					
						
							|  |  |  |         xtrxInputThread = new XTRXInputThread(m_deviceShared.m_dev->getDevice(), 1, requestedChannel); | 
					
						
							|  |  |  |         m_XTRXInputThread = xtrxInputThread; // take ownership
 | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |         m_deviceShared.m_thread = xtrxInputThread; | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         needsStart = true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     xtrxInputThread->setFifo(requestedChannel, &m_sampleFifo); | 
					
						
							|  |  |  |     xtrxInputThread->setLog2Decimation(requestedChannel, m_settings.m_log2SoftDecim); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 21:28:35 +01:00
										 |  |  |     applySettings(m_settings, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (needsStart) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-01-01 10:55:20 +01:00
										 |  |  |         qDebug("XTRXInput::start: (re)start thread"); | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         xtrxInputThread->startWork(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     qDebug("XTRXInput::start: started"); | 
					
						
							|  |  |  |     m_running = true; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | void XTRXInput::stop() | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     // This stop method is responsible for managing the thread when the streaming of a Rx channel is stopped
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // If the thread is currently managing only one channel (SI mode). The thread can be just stopped and deleted.
 | 
					
						
							|  |  |  |     // Then the channel is closed.
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // If the thread is currently managing both channels (MI mode) then we are removing one channel. Thus we must
 | 
					
						
							|  |  |  |     // transition from MI to SI. This transition is handled by stopping the thread, deleting it and creating a new one
 | 
					
						
							|  |  |  |     // managing a single channel.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_running) { | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-21 00:27:08 +02:00
										 |  |  |     int removedChannel = m_deviceAPI->getDeviceItemIndex(); // channel to remove
 | 
					
						
							| 
									
										
										
										
											2019-01-01 10:55:20 +01:00
										 |  |  |     int requestedChannel = removedChannel ^ 1; // channel to keep (opposite channel)
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     XTRXInputThread *xtrxInputThread = findThread(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (xtrxInputThread == 0) { // no thread allocated
 | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     int nbOriginalChannels = xtrxInputThread->getNbChannels(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (nbOriginalChannels == 1) // SI mode => just stop and delete the thread
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         qDebug("XTRXInput::stop: SI mode. Just stop and delete the thread"); | 
					
						
							|  |  |  |         xtrxInputThread->stopWork(); | 
					
						
							|  |  |  |         delete xtrxInputThread; | 
					
						
							|  |  |  |         m_XTRXInputThread = 0; | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |         m_deviceShared.m_thread = 0; | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // remove old thread address from buddies (reset in all buddies)
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies(); | 
					
						
							|  |  |  |         std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |         for (; it != sourceBuddies.end(); ++it) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             ((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_source->setThread(0); | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |             ((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_thread = 0; | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     else if (nbOriginalChannels == 2) // Reduce from MI to SI by deleting and re-creating the thread
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         qDebug("XTRXInput::stop: MI mode. Reduce by deleting and re-creating the thread"); | 
					
						
							|  |  |  |         xtrxInputThread->stopWork(); | 
					
						
							|  |  |  |         delete xtrxInputThread; | 
					
						
							| 
									
										
										
										
											2019-01-01 10:55:20 +01:00
										 |  |  |         xtrxInputThread = new XTRXInputThread(m_deviceShared.m_dev->getDevice(), 1, requestedChannel); | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         m_XTRXInputThread = xtrxInputThread; // take ownership
 | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |         m_deviceShared.m_thread = xtrxInputThread; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 10:55:20 +01:00
										 |  |  |         xtrxInputThread->setFifo(requestedChannel, &m_sampleFifo); | 
					
						
							|  |  |  |         xtrxInputThread->setLog2Decimation(requestedChannel, m_settings.m_log2SoftDecim); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         // remove old thread address from buddies (reset in all buddies). The address being held only in the owning source.
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies(); | 
					
						
							|  |  |  |         std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |         for (; it != sourceBuddies.end(); ++it) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             ((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_source->setThread(0); | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |             ((DeviceXTRXShared*) (*it)->getBuddySharedPtr())->m_thread = 0; | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 10:55:20 +01:00
										 |  |  |         applySettings(m_settings, true); | 
					
						
							| 
									
										
										
										
											2019-01-16 21:28:35 +01:00
										 |  |  |         xtrxInputThread->startWork(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_running = false; | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | void XTRXInput::suspendTxThread() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |     const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies(); | 
					
						
							|  |  |  |     std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     qDebug("XTRXInput::suspendTxThread (%lu)", sinkBuddies.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (; itSink != sinkBuddies.end(); ++itSink) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DeviceXTRXShared *buddySharedPtr = (DeviceXTRXShared *) (*itSink)->getBuddySharedPtr(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ((buddySharedPtr->m_thread) && buddySharedPtr->m_thread->isRunning()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             buddySharedPtr->m_thread->stopWork(); | 
					
						
							|  |  |  |             buddySharedPtr->m_threadWasRunning = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             buddySharedPtr->m_threadWasRunning = false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::resumeTxThread() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |     const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies(); | 
					
						
							|  |  |  |     std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     qDebug("XTRXInput::resumeTxThread (%lu)", sinkBuddies.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (; itSink != sinkBuddies.end(); ++itSink) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DeviceXTRXShared *buddySharedPtr = (DeviceXTRXShared *) (*itSink)->getBuddySharedPtr(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (buddySharedPtr->m_threadWasRunning) { | 
					
						
							|  |  |  |             buddySharedPtr->m_thread->startWork(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray XTRXInput::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool XTRXInput::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     bool success = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_settings.resetToDefaults(); | 
					
						
							|  |  |  |         success = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MsgConfigureXTRX* message = MsgConfigureXTRX::create(m_settings, true); | 
					
						
							|  |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgConfigureXTRX* messageToGUI = MsgConfigureXTRX::create(m_settings, true); | 
					
						
							|  |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return success; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const QString& XTRXInput::getDeviceDescription() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_deviceDescription; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int XTRXInput::getSampleRate() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     double rate = m_settings.m_devSampleRate; | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_deviceShared.m_dev) { | 
					
						
							|  |  |  |         rate = m_deviceShared.m_dev->getActualInputRate(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     return (int)((rate / (1<<m_settings.m_log2SoftDecim))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  | uint32_t XTRXInput::getDevSampleRate() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     uint32_t devSampleRate = m_settings.m_devSampleRate; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_deviceShared.m_dev) { | 
					
						
							|  |  |  |         devSampleRate = m_deviceShared.m_dev->getActualInputRate(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return devSampleRate; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | uint32_t XTRXInput::getLog2HardDecim() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     uint32_t log2HardDecim = m_settings.m_log2HardDecim; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_deviceShared.m_dev && (m_deviceShared.m_dev->getActualInputRate() != 0.0)) { | 
					
						
							|  |  |  |         log2HardDecim = log2(m_deviceShared.m_dev->getClockGen() / m_deviceShared.m_dev->getActualInputRate() / 4); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return log2HardDecim; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double XTRXInput::getClockGen() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_deviceShared.m_dev) { | 
					
						
							|  |  |  |         return m_deviceShared.m_dev->getClockGen(); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return 0.0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | quint64 XTRXInput::getCenterFrequency() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-30 00:45:33 +01:00
										 |  |  |     return m_settings.m_centerFrequency + (m_settings.m_ncoEnable ? m_settings.m_ncoFrequency : 0); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::setCenterFrequency(qint64 centerFrequency) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     XTRXInputSettings settings = m_settings; | 
					
						
							|  |  |  |     settings.m_centerFrequency = centerFrequency - (m_settings.m_ncoEnable ? m_settings.m_ncoFrequency : 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MsgConfigureXTRX* message = MsgConfigureXTRX::create(settings, false); | 
					
						
							|  |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgConfigureXTRX* messageToGUI = MsgConfigureXTRX::create(settings, false); | 
					
						
							|  |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | std::size_t XTRXInput::getChannelIndex() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_deviceShared.m_channel; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::getLORange(float& minF, float& maxF, float& stepF) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     minF = 29e6; | 
					
						
							|  |  |  |     maxF = 3840e6; | 
					
						
							|  |  |  |     stepF = 10; | 
					
						
							|  |  |  |     qDebug("XTRXInput::getLORange: min: %f max: %f step: %f", | 
					
						
							|  |  |  |            minF, maxF, stepF); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::getSRRange(float& minF, float& maxF, float& stepF) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     minF = 100e3; | 
					
						
							|  |  |  |     maxF = 120e6; | 
					
						
							|  |  |  |     stepF = 10; | 
					
						
							|  |  |  |     qDebug("XTRXInput::getSRRange: min: %f max: %f step: %f", | 
					
						
							|  |  |  |            minF, maxF, stepF); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::getLPRange(float& minF, float& maxF, float& stepF) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     minF = 500e3; | 
					
						
							|  |  |  |     maxF = 130e6; | 
					
						
							|  |  |  |     stepF = 10; | 
					
						
							|  |  |  |     qDebug("XTRXInput::getLPRange: min: %f max: %f step: %f", | 
					
						
							|  |  |  |            minF, maxF, stepF); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool XTRXInput::handleMessage(const Message& message) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (MsgConfigureXTRX::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgConfigureXTRX& conf = (MsgConfigureXTRX&) message; | 
					
						
							|  |  |  |         qDebug() << "XTRXInput::handleMessage: MsgConfigureXTRX"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!applySettings(conf.getSettings(), conf.getForce())) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug("XTRXInput::handleMessage config error"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (DeviceXTRXShared::MsgReportBuddyChange::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DeviceXTRXShared::MsgReportBuddyChange& report = (DeviceXTRXShared::MsgReportBuddyChange&) message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (report.getRxElseTx()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_settings.m_devSampleRate   = report.getDevSampleRate(); | 
					
						
							|  |  |  |             m_settings.m_log2HardDecim   = report.getLog2HardDecimInterp(); | 
					
						
							|  |  |  |             m_settings.m_centerFrequency = report.getCenterFrequency(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |             m_settings.m_devSampleRate = m_deviceShared.m_dev->getActualInputRate(); | 
					
						
							|  |  |  |             m_settings.m_log2HardDecim = getLog2HardDecim(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             qDebug() << "XTRXInput::handleMessage: MsgReportBuddyChange:" | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |                      << " host_Hz: " << m_deviceShared.m_dev->getActualInputRate() | 
					
						
							|  |  |  |                      << " adc_Hz: " << m_deviceShared.m_dev->getClockGen() / 4 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |                      << " m_log2HardDecim: " << m_settings.m_log2HardDecim; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (m_settings.m_ncoEnable) // need to reset NCO after sample rate change
 | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-01-04 10:47:34 +01:00
										 |  |  |             applySettings(m_settings, false, true); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         int ncoShift = m_settings.m_ncoEnable ? m_settings.m_ncoFrequency : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         DSPSignalNotification *notif = new DSPSignalNotification( | 
					
						
							|  |  |  |                     m_settings.m_devSampleRate/(1<<m_settings.m_log2SoftDecim), | 
					
						
							|  |  |  |                     m_settings.m_centerFrequency + ncoShift); | 
					
						
							|  |  |  |         m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |         if (getMessageQueueToGUI()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             DeviceXTRXShared::MsgReportBuddyChange *reportToGUI = DeviceXTRXShared::MsgReportBuddyChange::create( | 
					
						
							|  |  |  |                         m_settings.m_devSampleRate, m_settings.m_log2HardDecim, m_settings.m_centerFrequency, true); | 
					
						
							|  |  |  |             getMessageQueueToGUI()->push(reportToGUI); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (DeviceXTRXShared::MsgReportClockSourceChange::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DeviceXTRXShared::MsgReportClockSourceChange& report = (DeviceXTRXShared::MsgReportClockSourceChange&) message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_settings.m_extClock     = report.getExtClock(); | 
					
						
							|  |  |  |         m_settings.m_extClockFreq = report.getExtClockFeq(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-02 15:35:43 +01:00
										 |  |  |         if (getMessageQueueToGUI()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             DeviceXTRXShared::MsgReportClockSourceChange *reportToGUI = DeviceXTRXShared::MsgReportClockSourceChange::create( | 
					
						
							|  |  |  |                         m_settings.m_extClock, m_settings.m_extClockFreq); | 
					
						
							|  |  |  |             getMessageQueueToGUI()->push(reportToGUI); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (MsgGetStreamInfo::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         if (m_deviceAPI->getSamplingDeviceGUIMessageQueue()) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-29 11:07:14 +01:00
										 |  |  |             uint64_t fifolevel = 0; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |             if (m_deviceShared.m_dev && m_deviceShared.m_dev->getDevice()) { | 
					
						
							|  |  |  |                 xtrx_val_get(m_deviceShared.m_dev->getDevice(), XTRX_RX, XTRX_CH_AB, XTRX_PERF_LLFIFO, &fifolevel); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             MsgReportStreamInfo *report = MsgReportStreamInfo::create( | 
					
						
							|  |  |  |                         true, | 
					
						
							|  |  |  |                         true, | 
					
						
							|  |  |  |                         fifolevel, | 
					
						
							| 
									
										
										
										
											2018-12-29 11:07:14 +01:00
										 |  |  |                         65536); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             if (m_deviceAPI->getSamplingDeviceGUIMessageQueue()) { | 
					
						
							|  |  |  |                 m_deviceAPI->getSamplingDeviceGUIMessageQueue()->push(report); | 
					
						
							| 
									
										
										
										
											2018-12-29 11:07:14 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-12-29 03:22:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (MsgGetDeviceInfo::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-29 11:07:14 +01:00
										 |  |  |         double board_temp = 0.0; | 
					
						
							|  |  |  |         bool gps_locked = false; | 
					
						
							| 
									
										
										
										
											2018-12-29 03:22:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (!m_deviceShared.m_dev->getDevice() || ((board_temp = m_deviceShared.get_board_temperature() / 256.0) == 0.0)) { | 
					
						
							| 
									
										
										
										
											2018-12-29 11:07:14 +01:00
										 |  |  |             qDebug("XTRXInput::handleMessage: MsgGetDeviceInfo: cannot get board temperature"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (!m_deviceShared.m_dev->getDevice()) { | 
					
						
							| 
									
										
										
										
											2018-12-29 11:07:14 +01:00
										 |  |  |             qDebug("XTRXInput::handleMessage: MsgGetDeviceInfo: cannot get GPS lock status"); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             gps_locked = m_deviceShared.get_gps_status(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // send to oneself
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         if (m_deviceAPI->getSamplingDeviceGUIMessageQueue()) | 
					
						
							| 
									
										
										
										
											2018-12-29 03:22:37 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-29 11:07:14 +01:00
										 |  |  |             DeviceXTRXShared::MsgReportDeviceInfo *report = DeviceXTRXShared::MsgReportDeviceInfo::create(board_temp, gps_locked); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             m_deviceAPI->getSamplingDeviceGUIMessageQueue()->push(report); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // send to source buddies
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies(); | 
					
						
							|  |  |  |         std::vector<DeviceAPI*>::const_iterator itSource = sourceBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (; itSource != sourceBuddies.end(); ++itSource) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             if ((*itSource)->getSamplingDeviceGUIMessageQueue()) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2018-12-29 11:07:14 +01:00
										 |  |  |                 DeviceXTRXShared::MsgReportDeviceInfo *report = DeviceXTRXShared::MsgReportDeviceInfo::create(board_temp, gps_locked); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |                 (*itSource)->getSamplingDeviceGUIMessageQueue()->push(report); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // send to sink buddies
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies(); | 
					
						
							|  |  |  |         std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (; itSink != sinkBuddies.end(); ++itSink) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             if ((*itSink)->getSamplingDeviceGUIMessageQueue()) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2018-12-29 11:07:14 +01:00
										 |  |  |                 DeviceXTRXShared::MsgReportDeviceInfo *report = DeviceXTRXShared::MsgReportDeviceInfo::create(board_temp, gps_locked); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |                 (*itSink)->getSamplingDeviceGUIMessageQueue()->push(report); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (MsgFileRecord::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgFileRecord& conf = (MsgFileRecord&) message; | 
					
						
							|  |  |  |         qDebug() << "XTRXInput::handleMessage: MsgFileRecord: " << conf.getStartStop(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (conf.getStartStop()) { | 
					
						
							|  |  |  |             m_fileSink->startRecording(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_fileSink->stopRecording(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (MsgStartStop::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgStartStop& cmd = (MsgStartStop&) message; | 
					
						
							|  |  |  |         qDebug() << "XTRXInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (cmd.getStartStop()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             if (m_deviceAPI->initDeviceEngine()) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |                 m_deviceAPI->startDeviceEngine(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             m_deviceAPI->stopDeviceEngine(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static double tia_to_db(unsigned idx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     switch (idx) { | 
					
						
							|  |  |  |     case 1: return 12; | 
					
						
							|  |  |  |     case 2: return 9; | 
					
						
							|  |  |  |     default: return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-30 10:13:17 +01:00
										 |  |  | void XTRXInput::apply_gain_auto(uint32_t gain) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-30 10:13:17 +01:00
										 |  |  |     uint32_t lna, tia, pga; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     DeviceXTRX::getAutoGains(gain, lna, tia, pga); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     apply_gain_lna(lna); | 
					
						
							|  |  |  |     apply_gain_tia(tia_to_db(tia)); | 
					
						
							|  |  |  |     apply_gain_pga(pga); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::apply_gain_lna(double gain) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (xtrx_set_gain(m_deviceShared.m_dev->getDevice(), | 
					
						
							| 
									
										
										
										
											2018-12-31 21:05:19 +01:00
										 |  |  |             m_deviceShared.m_channel == 0 ? XTRX_CH_A : XTRX_CH_B, | 
					
						
							|  |  |  |             XTRX_RX_LNA_GAIN, | 
					
						
							|  |  |  |             gain, | 
					
						
							|  |  |  |             0) < 0) { | 
					
						
							| 
									
										
										
										
											2019-01-04 10:47:34 +01:00
										 |  |  |         qDebug("XTRXInput::apply_gain_lna: xtrx_set_gain(LNA) failed"); | 
					
						
							| 
									
										
										
										
											2018-12-31 21:05:19 +01:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2019-01-04 10:47:34 +01:00
										 |  |  |         qDebug() << "XTRXInput::apply_gain_lna: Gain (LNA) set to " << gain; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::apply_gain_tia(double gain) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (xtrx_set_gain(m_deviceShared.m_dev->getDevice(), | 
					
						
							| 
									
										
										
										
											2018-12-31 21:05:19 +01:00
										 |  |  |             m_deviceShared.m_channel == 0 ? XTRX_CH_A : XTRX_CH_B, | 
					
						
							|  |  |  |             XTRX_RX_TIA_GAIN, | 
					
						
							|  |  |  |             gain, | 
					
						
							|  |  |  |             0) < 0) { | 
					
						
							| 
									
										
										
										
											2019-01-04 10:47:34 +01:00
										 |  |  |         qDebug("XTRXInput::apply_gain_tia: xtrx_set_gain(TIA) failed"); | 
					
						
							| 
									
										
										
										
											2018-12-31 21:05:19 +01:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2019-01-04 10:47:34 +01:00
										 |  |  |         qDebug() << "XTRXInput::apply_gain_tia: Gain (TIA) set to " << gain; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::apply_gain_pga(double gain) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (xtrx_set_gain(m_deviceShared.m_dev->getDevice(), | 
					
						
							| 
									
										
										
										
											2018-12-31 21:05:19 +01:00
										 |  |  |             m_deviceShared.m_channel == 0 ? XTRX_CH_A : XTRX_CH_B, | 
					
						
							|  |  |  |             XTRX_RX_PGA_GAIN, | 
					
						
							|  |  |  |             gain, | 
					
						
							|  |  |  |             0) < 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-01-04 10:47:34 +01:00
										 |  |  |         qDebug("XTRXInput::apply_gain_pga: xtrx_set_gain(PGA) failed"); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-01-04 10:47:34 +01:00
										 |  |  |         qDebug() << "XTRXInput::apply_gain_pga: Gain (PGA) set to " << gain; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, bool forceNCOFrequency) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-21 00:27:08 +02:00
										 |  |  |     int requestedChannel = m_deviceAPI->getDeviceItemIndex(); | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     XTRXInputThread *inputThread = findThread(); | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     QList<QString> reverseAPIKeys; | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     bool forwardChangeOwnDSP = false; | 
					
						
							|  |  |  |     bool forwardChangeRxDSP  = false; | 
					
						
							|  |  |  |     bool forwardChangeAllDSP = false; | 
					
						
							|  |  |  |     bool forwardClockSource  = false; | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     bool rxThreadWasRunning = false; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     bool doLPCalibration = false; | 
					
						
							|  |  |  |     bool doChangeSampleRate = false; | 
					
						
							|  |  |  |     bool doChangeFreq = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool doGainAuto = false; | 
					
						
							|  |  |  |     bool doGainLna = false; | 
					
						
							|  |  |  |     bool doGainTia = false; | 
					
						
							|  |  |  |     bool doGainPga = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // apply settings
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 00:37:27 +01:00
										 |  |  |     qDebug() << "XTRXInput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz" | 
					
						
							|  |  |  |              << " device stream sample rate: " << getDevSampleRate() << "S/s" | 
					
						
							|  |  |  |              << " sample rate with soft decimation: " << getSampleRate() << "S/s" | 
					
						
							|  |  |  |              << " m_devSampleRate: " << m_settings.m_devSampleRate | 
					
						
							|  |  |  |              << " m_dcBlock: " << m_settings.m_dcBlock | 
					
						
							|  |  |  |              << " m_iqCorrection: " << m_settings.m_iqCorrection | 
					
						
							|  |  |  |              << " m_log2SoftDecim: " << m_settings.m_log2SoftDecim | 
					
						
							|  |  |  |              << " m_gain: " << m_settings.m_gain | 
					
						
							|  |  |  |              << " m_lpfBW: " << m_settings.m_lpfBW | 
					
						
							|  |  |  |              << " m_pwrmode: " << m_settings.m_pwrmode | 
					
						
							|  |  |  |              << " m_ncoEnable: " << m_settings.m_ncoEnable | 
					
						
							|  |  |  |              << " m_ncoFrequency: " << m_settings.m_ncoFrequency | 
					
						
							|  |  |  |              << " m_antennaPath: " << m_settings.m_antennaPath | 
					
						
							|  |  |  |              << " m_extClock: " << m_settings.m_extClock | 
					
						
							|  |  |  |              << " m_extClockFreq: " << m_settings.m_extClockFreq | 
					
						
							|  |  |  |              << " force: " << force | 
					
						
							|  |  |  |              << " forceNCOFrequency: " << forceNCOFrequency | 
					
						
							|  |  |  |              << " doLPCalibration: " << doLPCalibration; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     if ((m_settings.m_dcBlock != settings.m_dcBlock) || force) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         reverseAPIKeys.append("dcBlock"); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     if ((m_settings.m_iqCorrection != settings.m_iqCorrection) || force) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         reverseAPIKeys.append("iqCorrection"); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 21:05:19 +01:00
										 |  |  |     if ((m_settings.m_pwrmode != settings.m_pwrmode)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |         reverseAPIKeys.append("pwrmode"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 10:55:20 +01:00
										 |  |  |         if (m_deviceShared.m_dev->getDevice() != 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (xtrx_val_set(m_deviceShared.m_dev->getDevice(), | 
					
						
							|  |  |  |                     XTRX_TRX, | 
					
						
							|  |  |  |                     m_deviceShared.m_channel == 0 ? XTRX_CH_A : XTRX_CH_B, | 
					
						
							|  |  |  |                     XTRX_LMS7_PWR_MODE, | 
					
						
							|  |  |  |                     settings.m_pwrmode) < 0) { | 
					
						
							|  |  |  |                 qCritical("XTRXInput::applySettings: could not set power mode %d", settings.m_pwrmode); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     if ((m_settings.m_extClock != settings.m_extClock) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("extClock"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((m_settings.m_extClockFreq != settings.m_extClockFreq) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("extClockFreq"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((m_settings.m_extClock != settings.m_extClock) | 
					
						
							|  |  |  |        || (settings.m_extClock && (m_settings.m_extClockFreq != settings.m_extClockFreq)) || force) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-01-01 10:55:20 +01:00
										 |  |  |         if (m_deviceShared.m_dev->getDevice() != 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-01-01 10:55:20 +01:00
										 |  |  |             xtrx_set_ref_clk(m_deviceShared.m_dev->getDevice(), | 
					
						
							|  |  |  |                              (settings.m_extClock) ? settings.m_extClockFreq : 0, | 
					
						
							|  |  |  |                              (settings.m_extClock) ? XTRX_CLKSRC_EXT : XTRX_CLKSRC_INT); | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 forwardClockSource = true; | 
					
						
							|  |  |  |                 doChangeSampleRate = true; | 
					
						
							|  |  |  |                 doChangeFreq = true; | 
					
						
							|  |  |  |                 qDebug("XTRXInput::applySettings: clock set to %s (Ext: %d Hz)", | 
					
						
							|  |  |  |                        settings.m_extClock ? "external" : "internal", | 
					
						
							|  |  |  |                        settings.m_extClockFreq); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("devSampleRate"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((m_settings.m_log2HardDecim != settings.m_log2HardDecim) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("log2HardDecim"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     if ((m_settings.m_devSampleRate != settings.m_devSampleRate) | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |        || (m_settings.m_log2HardDecim != settings.m_log2HardDecim) || force) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         forwardChangeAllDSP = true; //m_settings.m_devSampleRate != settings.m_devSampleRate;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (m_deviceShared.m_dev->getDevice() != 0) { | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             doChangeSampleRate = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     if ((m_settings.m_gainMode != settings.m_gainMode) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("gainMode"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((m_settings.m_gain != settings.m_gain) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("gain"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((m_settings.m_lnaGain != settings.m_lnaGain) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("lnaGain"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((m_settings.m_tiaGain != settings.m_tiaGain) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("tiaGain"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((m_settings.m_pgaGain != settings.m_pgaGain) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("pgaGain"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |     if (m_deviceShared.m_dev->getDevice() != 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         if ((m_settings.m_gainMode != settings.m_gainMode) || force) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (settings.m_gainMode == XTRXInputSettings::GAIN_AUTO) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 doGainAuto = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 doGainLna = true; | 
					
						
							|  |  |  |                 doGainTia = true; | 
					
						
							|  |  |  |                 doGainPga = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (m_settings.m_gainMode == XTRXInputSettings::GAIN_AUTO) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |             if (m_settings.m_gain != settings.m_gain) { | 
					
						
							|  |  |  |                 doGainAuto = true; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         else if (m_settings.m_gainMode == XTRXInputSettings::GAIN_MANUAL) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             if (m_settings.m_lnaGain != settings.m_lnaGain) { | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |                 doGainLna = true; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             if (m_settings.m_tiaGain != settings.m_tiaGain) { | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |                 doGainTia = true; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             if (m_settings.m_pgaGain != settings.m_pgaGain) { | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |                 doGainPga = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((m_settings.m_lpfBW != settings.m_lpfBW) || force) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |         reverseAPIKeys.append("lpfBW"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (m_deviceShared.m_dev->getDevice() != 0) { | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             doLPCalibration = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  |     if ((m_settings.m_lpfFIRBW != settings.m_lpfFIRBW) || | 
					
						
							|  |  |  |             (m_settings.m_lpfFIREnable != settings.m_lpfFIREnable) || force) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (LMS_SetGFIRLPF(m_deviceShared.m_deviceParams->getDevice(), | 
					
						
							|  |  |  |                                LMS_CH_RX, | 
					
						
							|  |  |  |                                m_deviceShared.m_channel, | 
					
						
							|  |  |  |                                settings.m_lpfFIREnable, | 
					
						
							|  |  |  |                                settings.m_lpfFIRBW) < 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 qCritical("XTRXInput::applySettings: could %s and set LPF FIR to %f Hz", | 
					
						
							|  |  |  |                           settings.m_lpfFIREnable ? "enable" : "disable", | 
					
						
							|  |  |  |                           settings.m_lpfFIRBW); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 //doCalibration = true;
 | 
					
						
							|  |  |  |                 qDebug("XTRXInput::applySettings: %sd and set LPF FIR to %f Hz", | 
					
						
							|  |  |  |                        settings.m_lpfFIREnable ? "enable" : "disable", | 
					
						
							|  |  |  |                        settings.m_lpfFIRBW); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((m_settings.m_log2SoftDecim != settings.m_log2SoftDecim) || force) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |         reverseAPIKeys.append("log2SoftDecim"); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         forwardChangeOwnDSP = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (inputThread != 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             inputThread->setLog2Decimation(requestedChannel, settings.m_log2SoftDecim); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             qDebug() << "XTRXInput::applySettings: set soft decimation to " << (1<<settings.m_log2SoftDecim); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((m_settings.m_antennaPath != settings.m_antennaPath) || force) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |         reverseAPIKeys.append("antennaPath"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (m_deviceShared.m_dev->getDevice() != 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             if (xtrx_set_antenna(m_deviceShared.m_dev->getDevice(), settings.m_antennaPath) < 0) { | 
					
						
							|  |  |  |                 qCritical("XTRXInput::applySettings: could not set antenna path to %d", (int) settings.m_antennaPath); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 qDebug("XTRXInput::applySettings: set antenna path to %d", (int) settings.m_antennaPath); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         reverseAPIKeys.append("centerFrequency"); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         doChangeFreq = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     if ((m_settings.m_ncoFrequency != settings.m_ncoFrequency) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("ncoFrequency"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((m_settings.m_ncoEnable != settings.m_ncoEnable) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("ncoEnable"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((m_settings.m_ncoFrequency != settings.m_ncoFrequency) | 
					
						
							|  |  |  |        || (m_settings.m_ncoEnable != settings.m_ncoEnable) || force) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         forceNCOFrequency = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +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-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_settings = settings; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (doChangeSampleRate) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         XTRXInputThread *rxThread = findThread(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (rxThread && rxThread->isRunning()) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             rxThread->stopWork(); | 
					
						
							|  |  |  |             rxThreadWasRunning = true; | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         suspendTxThread(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         double master = (settings.m_log2HardDecim == 0) ? 0 : (settings.m_devSampleRate * 4 * (1 << settings.m_log2HardDecim)); | 
					
						
							| 
									
										
										
										
											2018-12-30 00:45:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |         if (m_deviceShared.m_dev->set_samplerate(settings.m_devSampleRate, | 
					
						
							|  |  |  |                 master, //(settings.m_devSampleRate<<settings.m_log2HardDecim)*4,
 | 
					
						
							|  |  |  |                 false) < 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             qCritical("XTRXInput::applySettings: could not set sample rate to %f with oversampling of %d", | 
					
						
							|  |  |  |                       settings.m_devSampleRate, | 
					
						
							|  |  |  |                       1<<settings.m_log2HardDecim); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             doChangeFreq = true; | 
					
						
							|  |  |  |             forceNCOFrequency = true; | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |             forwardChangeAllDSP = true; | 
					
						
							| 
									
										
										
										
											2018-12-30 00:45:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             qDebug("XTRXInput::applySettings: sample rate set to %f with oversampling of %d", | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |                    m_deviceShared.m_dev->getActualInputRate(), | 
					
						
							|  |  |  |                    1 << getLog2HardDecim()); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         resumeTxThread(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (rxThreadWasRunning) { | 
					
						
							|  |  |  |             rxThread->startWork(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (doLPCalibration) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (xtrx_tune_rx_bandwidth(m_deviceShared.m_dev->getDevice(), | 
					
						
							| 
									
										
										
										
											2018-12-31 21:05:19 +01:00
										 |  |  |                 m_deviceShared.m_channel == 0 ? XTRX_CH_A : XTRX_CH_B, | 
					
						
							|  |  |  |                 m_settings.m_lpfBW, | 
					
						
							|  |  |  |                 0) < 0) { | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             qCritical("XTRXInput::applySettings: could not set LPF to %f Hz", m_settings.m_lpfBW); | 
					
						
							| 
									
										
										
										
											2018-12-31 21:05:19 +01:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             qDebug("XTRXInput::applySettings: LPF set to %f Hz", m_settings.m_lpfBW); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (doGainAuto) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         apply_gain_auto(m_settings.m_gain); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (doGainLna) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-30 00:45:33 +01:00
										 |  |  |         apply_gain_lna(m_settings.m_lnaGain); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (doGainTia) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-30 00:45:33 +01:00
										 |  |  |         apply_gain_tia(tia_to_db(m_settings.m_tiaGain)); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (doGainPga) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-30 00:45:33 +01:00
										 |  |  |         apply_gain_pga(m_settings.m_pgaGain); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (doChangeFreq) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         forwardChangeRxDSP = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (m_deviceShared.m_dev->getDevice() != 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |             if (xtrx_tune(m_deviceShared.m_dev->getDevice(), | 
					
						
							| 
									
										
										
										
											2018-12-31 21:05:19 +01:00
										 |  |  |                     XTRX_TUNE_RX_FDD, | 
					
						
							|  |  |  |                     settings.m_centerFrequency, | 
					
						
							|  |  |  |                     0) < 0) { | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |                 qCritical("XTRXInput::applySettings: could not set frequency to %lu", settings.m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2018-12-31 21:05:19 +01:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |                 //doCalibration = true;
 | 
					
						
							|  |  |  |                 qDebug("XTRXInput::applySettings: frequency set to %lu", settings.m_centerFrequency); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (forceNCOFrequency) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-31 01:43:24 +01:00
										 |  |  |         if (m_deviceShared.m_dev->getDevice() != 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 21:05:19 +01:00
										 |  |  |             if (xtrx_tune_ex(m_deviceShared.m_dev->getDevice(), | 
					
						
							|  |  |  |                     XTRX_TUNE_BB_RX, | 
					
						
							|  |  |  |                     m_deviceShared.m_channel == 0 ? XTRX_CH_A : XTRX_CH_B, | 
					
						
							|  |  |  |                     (settings.m_ncoEnable) ? settings.m_ncoFrequency : 0, | 
					
						
							|  |  |  |                     NULL) < 0) | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |             { | 
					
						
							|  |  |  |                 qCritical("XTRXInput::applySettings: could not %s and set NCO to %d Hz", | 
					
						
							|  |  |  |                           settings.m_ncoEnable ? "enable" : "disable", | 
					
						
							|  |  |  |                           settings.m_ncoFrequency); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 forwardChangeOwnDSP = true; | 
					
						
							|  |  |  |                 qDebug("XTRXInput::applySettings: %sd and set NCO to %d Hz", | 
					
						
							|  |  |  |                        settings.m_ncoEnable ? "enable" : "disable", | 
					
						
							|  |  |  |                        settings.m_ncoFrequency); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // forward changes to buddies or oneself
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (forwardChangeAllDSP) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("XTRXInput::applySettings: forward change to all buddies"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         int ncoShift = m_settings.m_ncoEnable ? m_settings.m_ncoFrequency : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // send to self first
 | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |         DSPSignalNotification *notif = new DSPSignalNotification(getSampleRate(), m_settings.m_centerFrequency + ncoShift); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |         if (getMessageQueueToGUI()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             MsgReportClockGenChange *report = MsgReportClockGenChange::create(); | 
					
						
							|  |  |  |             getMessageQueueToGUI()->push(report); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         // send to source buddies
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies(); | 
					
						
							|  |  |  |         std::vector<DeviceAPI*>::const_iterator itSource = sourceBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (; itSource != sourceBuddies.end(); ++itSource) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             DeviceXTRXShared::MsgReportBuddyChange *report = DeviceXTRXShared::MsgReportBuddyChange::create( | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |                     getDevSampleRate(), getLog2HardDecim(), m_settings.m_centerFrequency, true); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             (*itSource)->getSamplingDeviceInputMessageQueue()->push(report); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // send to sink buddies
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies(); | 
					
						
							|  |  |  |         std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (; itSink != sinkBuddies.end(); ++itSink) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             DeviceXTRXShared::MsgReportBuddyChange *report = DeviceXTRXShared::MsgReportBuddyChange::create( | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |                     getDevSampleRate(), getLog2HardDecim(), m_settings.m_centerFrequency, true); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             (*itSink)->getSamplingDeviceInputMessageQueue()->push(report); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (forwardChangeRxDSP) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("XTRXInput::applySettings: forward change to Rx buddies"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         int ncoShift = m_settings.m_ncoEnable ? m_settings.m_ncoFrequency : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // send to self first
 | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |         DSPSignalNotification *notif = new DSPSignalNotification(getSampleRate(), m_settings.m_centerFrequency + ncoShift); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |         if (getMessageQueueToGUI()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             MsgReportClockGenChange *report = MsgReportClockGenChange::create(); | 
					
						
							|  |  |  |             getMessageQueueToGUI()->push(report); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         // send to source buddies
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies(); | 
					
						
							|  |  |  |         std::vector<DeviceAPI*>::const_iterator itSource = sourceBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (; itSource != sourceBuddies.end(); ++itSource) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             DeviceXTRXShared::MsgReportBuddyChange *report = DeviceXTRXShared::MsgReportBuddyChange::create( | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  |                         getDevSampleRate(), getLog2HardDecim(), m_settings.m_centerFrequency, true); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             (*itSource)->getSamplingDeviceInputMessageQueue()->push(report); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (forwardChangeOwnDSP) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("XTRXInput::applySettings: forward change to self only"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         int ncoShift = m_settings.m_ncoEnable ? m_settings.m_ncoFrequency : 0; | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         DSPSignalNotification *notif = new DSPSignalNotification(getSampleRate(), m_settings.m_centerFrequency + ncoShift); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         m_fileSink->handleMessage(*notif); // forward to file sink
 | 
					
						
							|  |  |  |         m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); | 
					
						
							| 
									
										
										
										
											2019-01-04 04:45:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (getMessageQueueToGUI()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             MsgReportClockGenChange *report = MsgReportClockGenChange::create(); | 
					
						
							|  |  |  |             getMessageQueueToGUI()->push(report); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (forwardClockSource) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // send to source buddies
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies(); | 
					
						
							|  |  |  |         std::vector<DeviceAPI*>::const_iterator itSource = sourceBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (; itSource != sourceBuddies.end(); ++itSource) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             DeviceXTRXShared::MsgReportClockSourceChange *report = DeviceXTRXShared::MsgReportClockSourceChange::create( | 
					
						
							|  |  |  |                         m_settings.m_extClock, m_settings.m_extClockFreq); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             (*itSource)->getSamplingDeviceInputMessageQueue()->push(report); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // send to sink buddies
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |         const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies(); | 
					
						
							|  |  |  |         std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin(); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (; itSink != sinkBuddies.end(); ++itSink) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             DeviceXTRXShared::MsgReportClockSourceChange *report = DeviceXTRXShared::MsgReportClockSourceChange::create( | 
					
						
							|  |  |  |                         m_settings.m_extClock, m_settings.m_extClockFreq); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             (*itSink)->getSamplingDeviceInputMessageQueue()->push(report); | 
					
						
							| 
									
										
										
										
											2018-12-29 01:20:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | int XTRXInput::webapiSettingsGet( | 
					
						
							|  |  |  |                 SWGSDRangel::SWGDeviceSettings& response, | 
					
						
							|  |  |  |                 QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) errorMessage; | 
					
						
							|  |  |  |     response.setXtrxInputSettings(new SWGSDRangel::SWGXtrxInputSettings()); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->init(); | 
					
						
							|  |  |  |     webapiFormatDeviceSettings(response, m_settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int XTRXInput::webapiSettingsPutPatch( | 
					
						
							|  |  |  |                 bool force, | 
					
						
							|  |  |  |                 const QStringList& deviceSettingsKeys, | 
					
						
							|  |  |  |                 SWGSDRangel::SWGDeviceSettings& response, // query + response
 | 
					
						
							|  |  |  |                 QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) errorMessage; | 
					
						
							|  |  |  |     XTRXInputSettings settings = m_settings; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("centerFrequency")) { | 
					
						
							|  |  |  |         settings.m_centerFrequency = response.getXtrxInputSettings()->getCenterFrequency(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("devSampleRate")) { | 
					
						
							|  |  |  |         settings.m_devSampleRate = response.getXtrxInputSettings()->getDevSampleRate(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2HardDecim")) { | 
					
						
							|  |  |  |         settings.m_log2HardDecim = response.getXtrxInputSettings()->getLog2HardDecim(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("dcBlock")) { | 
					
						
							|  |  |  |         settings.m_dcBlock = response.getXtrxInputSettings()->getDcBlock() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("iqCorrection")) { | 
					
						
							|  |  |  |         settings.m_iqCorrection = response.getXtrxInputSettings()->getIqCorrection() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2SoftDecim")) { | 
					
						
							|  |  |  |         settings.m_log2SoftDecim = response.getXtrxInputSettings()->getLog2SoftDecim(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("lpfBW")) { | 
					
						
							|  |  |  |         settings.m_lpfBW = response.getXtrxInputSettings()->getLpfBw(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("gain")) { | 
					
						
							|  |  |  |         settings.m_gain = response.getXtrxInputSettings()->getGain(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("ncoEnable")) { | 
					
						
							|  |  |  |         settings.m_ncoEnable = response.getXtrxInputSettings()->getNcoEnable() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("ncoFrequency")) { | 
					
						
							|  |  |  |         settings.m_ncoFrequency = response.getXtrxInputSettings()->getNcoFrequency(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("antennaPath")) { | 
					
						
							|  |  |  |         settings.m_antennaPath = (xtrx_antenna_t) response.getXtrxInputSettings()->getAntennaPath(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("gainMode")) { | 
					
						
							|  |  |  |         settings.m_gainMode = (XTRXInputSettings::GainMode) response.getXtrxInputSettings()->getGainMode(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("lnaGain")) { | 
					
						
							|  |  |  |         settings.m_lnaGain = response.getXtrxInputSettings()->getLnaGain(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("tiaGain")) { | 
					
						
							|  |  |  |         settings.m_tiaGain = response.getXtrxInputSettings()->getTiaGain(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("pgaGain")) { | 
					
						
							|  |  |  |         settings.m_pgaGain = response.getXtrxInputSettings()->getPgaGain(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("extClock")) { | 
					
						
							|  |  |  |         settings.m_extClock = response.getXtrxInputSettings()->getExtClock() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("extClockFreq")) { | 
					
						
							|  |  |  |         settings.m_extClockFreq = response.getXtrxInputSettings()->getExtClockFreq(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("pwrmode")) { | 
					
						
							|  |  |  |         settings.m_pwrmode = response.getXtrxInputSettings()->getPwrmode(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("fileRecordName")) { | 
					
						
							|  |  |  |         settings.m_fileRecordName = *response.getXtrxInputSettings()->getFileRecordName(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("useReverseAPI")) { | 
					
						
							|  |  |  |         settings.m_useReverseAPI = response.getXtrxInputSettings()->getUseReverseApi() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIAddress")) { | 
					
						
							| 
									
										
										
										
											2019-01-13 11:35:31 +01:00
										 |  |  |         settings.m_reverseAPIAddress = *response.getXtrxInputSettings()->getReverseApiAddress(); | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIPort")) { | 
					
						
							|  |  |  |         settings.m_reverseAPIPort = response.getXtrxInputSettings()->getReverseApiPort(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) { | 
					
						
							|  |  |  |         settings.m_reverseAPIDeviceIndex = response.getXtrxInputSettings()->getReverseApiDeviceIndex(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MsgConfigureXTRX *msg = MsgConfigureXTRX::create(settings, force); | 
					
						
							|  |  |  |     m_inputMessageQueue.push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) // forward to GUI if any
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgConfigureXTRX *msgToGUI = MsgConfigureXTRX::create(settings, force); | 
					
						
							|  |  |  |         m_guiMessageQueue->push(msgToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     webapiFormatDeviceSettings(response, settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const XTRXInputSettings& settings) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setDevSampleRate(settings.m_devSampleRate); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setLog2HardDecim(settings.m_log2HardDecim); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setDcBlock(settings.m_dcBlock ? 1 : 0); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setIqCorrection(settings.m_iqCorrection ? 1 : 0); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setLog2SoftDecim(settings.m_log2SoftDecim); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setLpfBw(settings.m_lpfBW); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setGain(settings.m_gain); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setNcoEnable(settings.m_ncoEnable ? 1 : 0); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setNcoFrequency(settings.m_ncoFrequency); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setAntennaPath((int) settings.m_antennaPath); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setGainMode((int) settings.m_gainMode); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setLnaGain(settings.m_lnaGain); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setTiaGain(settings.m_tiaGain); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setPgaGain(settings.m_pgaGain); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setExtClock(settings.m_extClock ? 1 : 0); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setExtClockFreq(settings.m_extClockFreq); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setPwrmode(settings.m_pwrmode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (response.getXtrxInputSettings()->getFileRecordName()) { | 
					
						
							|  |  |  |         *response.getXtrxInputSettings()->getFileRecordName() = settings.m_fileRecordName; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.getXtrxInputSettings()->setFileRecordName(new QString(settings.m_fileRecordName)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (response.getXtrxInputSettings()->getReverseApiAddress()) { | 
					
						
							|  |  |  |         *response.getXtrxInputSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.getXtrxInputSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setReverseApiPort(settings.m_reverseAPIPort); | 
					
						
							|  |  |  |     response.getXtrxInputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int XTRXInput::webapiReportGet( | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceReport& response, | 
					
						
							|  |  |  |         QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) errorMessage; | 
					
						
							|  |  |  |     response.setXtrxInputReport(new SWGSDRangel::SWGXtrxInputReport()); | 
					
						
							|  |  |  |     response.getXtrxInputReport()->init(); | 
					
						
							|  |  |  |     webapiFormatDeviceReport(response); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int XTRXInput::webapiRunGet( | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |         QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) errorMessage; | 
					
						
							|  |  |  |     m_deviceAPI->getDeviceEngineStateStr(*response.getState()); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int XTRXInput::webapiRun( | 
					
						
							|  |  |  |         bool run, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |         QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) errorMessage; | 
					
						
							|  |  |  |     m_deviceAPI->getDeviceEngineStateStr(*response.getState()); | 
					
						
							|  |  |  |     MsgStartStop *message = MsgStartStop::create(run); | 
					
						
							|  |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) // forward to GUI if any
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgStartStop *msgToGUI = MsgStartStop::create(run); | 
					
						
							|  |  |  |         m_guiMessageQueue->push(msgToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int ret; | 
					
						
							|  |  |  |     bool success = false; | 
					
						
							|  |  |  |     double temp = 0.0; | 
					
						
							|  |  |  |     bool gpsStatus = false; | 
					
						
							|  |  |  |     uint64_t fifolevel = 0; | 
					
						
							|  |  |  |     uint32_t fifosize = 1<<16; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_deviceShared.m_dev && m_deviceShared.m_dev->getDevice()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ret = xtrx_val_get(m_deviceShared.m_dev->getDevice(), | 
					
						
							|  |  |  |                      XTRX_RX, XTRX_CH_AB, XTRX_PERF_LLFIFO, &fifolevel); | 
					
						
							|  |  |  |         success = (ret >= 0); | 
					
						
							|  |  |  |         temp = m_deviceShared.get_board_temperature() / 256.0; | 
					
						
							|  |  |  |         gpsStatus = m_deviceShared.get_gps_status(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.getXtrxInputReport()->setSuccess(success ? 1 : 0); | 
					
						
							|  |  |  |     response.getXtrxInputReport()->setFifoSize(fifosize); | 
					
						
							|  |  |  |     response.getXtrxInputReport()->setFifoFill(fifolevel); | 
					
						
							|  |  |  |     response.getXtrxInputReport()->setTemperature(temp); | 
					
						
							|  |  |  |     response.getXtrxInputReport()->setGpsLock(gpsStatus ? 1 : 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const XTRXInputSettings& 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()); | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     swgDeviceSettings->setDeviceHwType(new QString("XTRX")); | 
					
						
							|  |  |  |     swgDeviceSettings->setXtrxInputSettings(new SWGSDRangel::SWGXtrxInputSettings()); | 
					
						
							|  |  |  |     SWGSDRangel::SWGXtrxInputSettings *swgXtrxInputSettings = swgDeviceSettings->getXtrxInputSettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // transfer data that has been modified. When force is on transfer all data except reverse API data
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("centerFrequency") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("devSampleRate") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setDevSampleRate(settings.m_devSampleRate); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2HardDecim") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setLog2HardDecim(settings.m_log2HardDecim); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("dcBlock") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setDcBlock(settings.m_dcBlock ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("iqCorrection") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setIqCorrection(settings.m_iqCorrection ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2SoftDecim") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setLog2SoftDecim(settings.m_log2SoftDecim); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("ncoEnable") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setNcoEnable(settings.m_ncoEnable ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("ncoFrequency") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setNcoFrequency(settings.m_ncoFrequency); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("lpfBW") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setLpfBw(settings.m_lpfBW); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("antennaPath") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setAntennaPath((int) settings.m_antennaPath); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("gainMode") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setGainMode((int) settings.m_gainMode); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("gain") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setGain(settings.m_gain); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("lnaGain") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setLnaGain(settings.m_lnaGain); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("tiaGain") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setTiaGain(settings.m_tiaGain); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("pgaGain") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setPgaGain(settings.m_pgaGain); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("extClock") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setExtClock(settings.m_extClock ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("extClockFreq") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setExtClockFreq(settings.m_extClockFreq); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("pwrmode") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setPwrmode(settings.m_pwrmode); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("fileRecordName") || force) { | 
					
						
							|  |  |  |         swgXtrxInputSettings->setFileRecordName(new QString(settings.m_fileRecordName)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString deviceSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/settings") | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIAddress) | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIPort) | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  |     m_networkRequest.setUrl(QUrl(deviceSettingsURL)); | 
					
						
							|  |  |  |     m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QBuffer *buffer=new QBuffer(); | 
					
						
							|  |  |  |     buffer->open((QBuffer::ReadWrite)); | 
					
						
							|  |  |  |     buffer->write(swgDeviceSettings->asJson().toUtf8()); | 
					
						
							|  |  |  |     buffer->seek(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Always use PATCH to avoid passing reverse API settings
 | 
					
						
							|  |  |  |     m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     delete swgDeviceSettings; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::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("XTRX")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +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"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QBuffer *buffer=new QBuffer(); | 
					
						
							|  |  |  |     buffer->open((QBuffer::ReadWrite)); | 
					
						
							|  |  |  |     buffer->write(swgDeviceSettings->asJson().toUtf8()); | 
					
						
							|  |  |  |     buffer->seek(0); | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (start) { | 
					
						
							| 
									
										
										
										
											2019-03-25 15:21:17 +01:00
										 |  |  |         m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer); | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2019-03-25 15:21:17 +01:00
										 |  |  |         m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer); | 
					
						
							| 
									
										
										
										
											2019-01-01 18:28:53 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void XTRXInput::networkManagerFinished(QNetworkReply *reply) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QNetworkReply::NetworkError replyError = reply->error(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (replyError) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qWarning() << "XTRXInput::networkManagerFinished:" | 
					
						
							|  |  |  |                 << " error(" << (int) replyError | 
					
						
							|  |  |  |                 << "): " << replyError | 
					
						
							|  |  |  |                 << ": " << reply->errorString(); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString answer = reply->readAll(); | 
					
						
							|  |  |  |     answer.chop(1); // remove last \n
 | 
					
						
							|  |  |  |     qDebug("XTRXInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str()); | 
					
						
							|  |  |  | } |