| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-18 10:07:41 +01:00
										 |  |  | // Copyright (C) 2019-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com>    //
 | 
					
						
							|  |  |  | // Copyright (C) 2019 Vort <vvort@yandex.ru>                                     //
 | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							|  |  |  | // (at your option) any later version.                                           //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <QNetworkReply>
 | 
					
						
							|  |  |  | #include <QNetworkAccessManager>
 | 
					
						
							|  |  |  | #include <QBuffer>
 | 
					
						
							| 
									
										
										
										
											2022-10-08 12:10:19 +02:00
										 |  |  | #include <QThread>
 | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  | #include "SWGDeviceSettings.h"
 | 
					
						
							|  |  |  | #include "SWGDeviceState.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-09 00:56:31 +02:00
										 |  |  | #include "SWGDeviceReport.h"
 | 
					
						
							|  |  |  | #include "SWGKiwiSDRReport.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | #include "kiwisdrinput.h"
 | 
					
						
							|  |  |  | #include "device/deviceapi.h"
 | 
					
						
							|  |  |  | #include "kiwisdrworker.h"
 | 
					
						
							|  |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(KiwiSDRInput::MsgConfigureKiwiSDR, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(KiwiSDRInput::MsgStartStop, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(KiwiSDRInput::MsgSetStatus, Message) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | KiwiSDRInput::KiwiSDRInput(DeviceAPI *deviceAPI) : | 
					
						
							|  |  |  |     m_deviceAPI(deviceAPI), | 
					
						
							| 
									
										
										
										
											2022-11-27 00:28:55 +01:00
										 |  |  |     m_sampleRate(12000), | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 	m_settings(), | 
					
						
							|  |  |  | 	m_kiwiSDRWorker(nullptr), | 
					
						
							| 
									
										
										
										
											2022-10-08 12:10:19 +02:00
										 |  |  |     m_kiwiSDRWorkerThread(nullptr), | 
					
						
							| 
									
										
										
										
											2022-03-17 21:10:30 +01:00
										 |  |  | 	m_deviceDescription("KiwiSDR"), | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 	m_running(false), | 
					
						
							| 
									
										
										
										
											2024-04-04 16:15:41 +01:00
										 |  |  | 	m_masterTimer(deviceAPI->getMasterTimer()), | 
					
						
							|  |  |  |     m_latitude(std::numeric_limits<float>::quiet_NaN()), | 
					
						
							|  |  |  |     m_longitude(std::numeric_limits<float>::quiet_NaN()), | 
					
						
							|  |  |  |     m_altitude(std::numeric_limits<float>::quiet_NaN()) | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-03-17 21:10:30 +01:00
										 |  |  |     m_sampleFifo.setLabel(m_deviceDescription); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |     m_deviceAPI->setNbSourceStreams(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_sampleFifo.setSize(getSampleRate() * 2)) { | 
					
						
							|  |  |  |         qCritical("KiwiSDRInput::KiwiSDRInput: Could not allocate SampleFifo"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_networkManager = new QNetworkAccessManager(); | 
					
						
							| 
									
										
										
										
											2022-03-23 22:32:23 +01:00
										 |  |  |     QObject::connect( | 
					
						
							|  |  |  |         m_networkManager, | 
					
						
							|  |  |  |         &QNetworkAccessManager::finished, | 
					
						
							|  |  |  |         this, | 
					
						
							|  |  |  |         &KiwiSDRInput::networkManagerFinished | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | KiwiSDRInput::~KiwiSDRInput() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-03-23 22:32:23 +01:00
										 |  |  |     QObject::disconnect( | 
					
						
							|  |  |  |         m_networkManager, | 
					
						
							|  |  |  |         &QNetworkAccessManager::finished, | 
					
						
							|  |  |  |         this, | 
					
						
							|  |  |  |         &KiwiSDRInput::networkManagerFinished | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |     delete m_networkManager; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_running) { | 
					
						
							|  |  |  |         stop(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KiwiSDRInput::destroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KiwiSDRInput::init() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |     applySettings(m_settings, QList<QString>(), true); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool KiwiSDRInput::start() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QMutexLocker mutexLocker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-08 12:10:19 +02:00
										 |  |  |     if (m_running) { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-08 12:10:19 +02:00
										 |  |  |     m_kiwiSDRWorkerThread = new QThread(); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 	m_kiwiSDRWorker = new KiwiSDRWorker(&m_sampleFifo); | 
					
						
							| 
									
										
										
										
											2022-11-27 00:28:55 +01:00
										 |  |  |     m_kiwiSDRWorker->setInputMessageQueue(getInputMessageQueue()); | 
					
						
							| 
									
										
										
										
											2022-10-08 12:10:19 +02:00
										 |  |  | 	m_kiwiSDRWorker->moveToThread(m_kiwiSDRWorkerThread); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QObject::connect(m_kiwiSDRWorkerThread, &QThread::finished, m_kiwiSDRWorker, &QObject::deleteLater); | 
					
						
							|  |  |  |     QObject::connect(m_kiwiSDRWorkerThread, &QThread::finished, m_kiwiSDRWorkerThread, &QThread::deleteLater); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	connect(this, &KiwiSDRInput::setWorkerCenterFrequency, m_kiwiSDRWorker, &KiwiSDRWorker::onCenterFrequencyChanged); | 
					
						
							|  |  |  | 	connect(this, &KiwiSDRInput::setWorkerServerAddress, m_kiwiSDRWorker, &KiwiSDRWorker::onServerAddressChanged); | 
					
						
							|  |  |  | 	connect(this, &KiwiSDRInput::setWorkerGain, m_kiwiSDRWorker, &KiwiSDRWorker::onGainChanged); | 
					
						
							|  |  |  | 	connect(m_kiwiSDRWorker, &KiwiSDRWorker::updateStatus, this, &KiwiSDRInput::setWorkerStatus); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-08 12:10:19 +02:00
										 |  |  | 	m_kiwiSDRWorkerThread->start(); | 
					
						
							|  |  |  | 	m_running = true; | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-08 12:10:19 +02:00
										 |  |  | 	mutexLocker.unlock(); | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  | 	applySettings(m_settings, QList<QString>(), true); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KiwiSDRInput::stop() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QMutexLocker mutexLocker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-08 12:10:19 +02:00
										 |  |  |     if (!m_running) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-08 13:20:45 +02:00
										 |  |  | 	m_running = false; | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 	setWorkerStatus(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-08 12:10:19 +02:00
										 |  |  | 	if (m_kiwiSDRWorkerThread) | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2022-10-08 12:10:19 +02:00
										 |  |  |         m_kiwiSDRWorkerThread->quit(); | 
					
						
							|  |  |  |         m_kiwiSDRWorkerThread->wait(); | 
					
						
							| 
									
										
										
										
											2022-10-08 11:56:30 +02:00
										 |  |  | 		m_kiwiSDRWorker = nullptr; | 
					
						
							| 
									
										
										
										
											2022-10-08 12:10:19 +02:00
										 |  |  |         m_kiwiSDRWorkerThread = nullptr; | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray KiwiSDRInput::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool KiwiSDRInput::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     bool success = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_settings.resetToDefaults(); | 
					
						
							|  |  |  |         success = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |     MsgConfigureKiwiSDR* message = MsgConfigureKiwiSDR::create(m_settings, QList<QString>(), true); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |         MsgConfigureKiwiSDR* messageToGUI = MsgConfigureKiwiSDR::create(m_settings, QList<QString>(), true); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return success; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const QString& KiwiSDRInput::getDeviceDescription() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_deviceDescription; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int KiwiSDRInput::getSampleRate() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-11-27 00:28:55 +01:00
										 |  |  | 	return m_sampleRate; | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | quint64 KiwiSDRInput::getCenterFrequency() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_settings.m_centerFrequency; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KiwiSDRInput::setCenterFrequency(qint64 centerFrequency) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	KiwiSDRSettings settings = m_settings; | 
					
						
							|  |  |  |     settings.m_centerFrequency = centerFrequency; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |     MsgConfigureKiwiSDR* message = MsgConfigureKiwiSDR::create(settings, QList<QString>{"centerFrequency"}, false); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |         MsgConfigureKiwiSDR* messageToGUI = MsgConfigureKiwiSDR::create(settings, QList<QString>{"centerFrequency"}, false); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KiwiSDRInput::setWorkerStatus(int status) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-08 22:28:06 +02:00
										 |  |  | 	if (m_guiMessageQueue) { | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 		m_guiMessageQueue->push(MsgSetStatus::create(status)); | 
					
						
							| 
									
										
										
										
											2019-06-08 22:28:06 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool KiwiSDRInput::handleMessage(const Message& message) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (MsgConfigureKiwiSDR::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgConfigureKiwiSDR& conf = (MsgConfigureKiwiSDR&) message; | 
					
						
							|  |  |  |         qDebug() << "KiwiSDRInput::handleMessage: MsgConfigureKiwiSDR"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |         bool success = applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce()); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |         if (!success) { | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |             qDebug("KiwiSDRInput::handleMessage: config error"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-11-27 00:28:55 +01:00
										 |  |  |     else if (KiwiSDRWorker::MsgReportSampleRate::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         KiwiSDRWorker::MsgReportSampleRate& report = (KiwiSDRWorker::MsgReportSampleRate&) message; | 
					
						
							|  |  |  |         m_sampleRate = report.getSampleRate(); | 
					
						
							|  |  |  |         qDebug() << "KiwiSDRInput::handleMessage: KiwiSDRWorker::MsgReportSampleRate: m_sampleRate: " << m_sampleRate; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!m_sampleFifo.setSize(m_sampleRate * 2)) { | 
					
						
							|  |  |  |             qCritical("KiwiSDRInput::KiwiSDRInput: Could not allocate SampleFifo"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		DSPSignalNotification *notif = new DSPSignalNotification( | 
					
						
							|  |  |  | 			m_sampleRate, m_settings.m_centerFrequency); | 
					
						
							|  |  |  | 		m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-04-04 16:15:41 +01:00
										 |  |  |     else if (KiwiSDRWorker::MsgReportPosition::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         KiwiSDRWorker::MsgReportPosition& report = (KiwiSDRWorker::MsgReportPosition&) message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_latitude = report.getLatitude(); | 
					
						
							|  |  |  |         m_longitude = report.getLongitude(); | 
					
						
							|  |  |  |         m_altitude = report.getAltitude(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |     else if (MsgStartStop::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgStartStop& cmd = (MsgStartStop&) message; | 
					
						
							|  |  |  |         qDebug() << "KiwiSDRInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (cmd.getStartStop()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |             if (m_deviceAPI->initDeviceEngine()) { | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |                 m_deviceAPI->startDeviceEngine(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_deviceAPI->stopDeviceEngine(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (m_settings.m_useReverseAPI) { | 
					
						
							|  |  |  |             webapiReverseSendStartStop(cmd.getStartStop()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 00:56:31 +02:00
										 |  |  | int KiwiSDRInput::getStatus() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_kiwiSDRWorker) { | 
					
						
							|  |  |  |         return m_kiwiSDRWorker->getStatus(); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  | bool KiwiSDRInput::applySettings(const KiwiSDRSettings& settings, const QList<QString>& settingsKeys, bool force) | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  | 	qDebug() << "KiwiSDRInput::applySettings: force: "<< force << settings.getDebugString(settingsKeys, force); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (settingsKeys.contains("serverAddress") || force) | 
					
						
							| 
									
										
										
										
											2019-06-09 01:44:04 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 		emit setWorkerServerAddress(settings.m_serverAddress); | 
					
						
							| 
									
										
										
										
											2019-06-09 01:44:04 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  | 	if (settingsKeys.contains("gain") || | 
					
						
							|  |  |  | 		settingsKeys.contains("useAGC") || force) | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		emit setWorkerGain(settings.m_gain, settings.m_useAGC); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |     if (settingsKeys.contains("dcBlock")) { | 
					
						
							| 
									
										
										
										
											2019-06-09 20:56:22 +02:00
										 |  |  |         m_deviceAPI->configureCorrections(settings.m_dcBlock, false); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |     if (settingsKeys.contains("centerFrequency") || force) | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |     { | 
					
						
							|  |  |  |         emit setWorkerCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		DSPSignalNotification *notif = new DSPSignalNotification( | 
					
						
							|  |  |  | 			getSampleRate(), settings.m_centerFrequency); | 
					
						
							|  |  |  | 		m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-14 18:58:12 +02:00
										 |  |  |     if (settings.m_useReverseAPI) | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |         bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) || | 
					
						
							|  |  |  |             settingsKeys.contains("reverseAPIAddress") || | 
					
						
							|  |  |  |             settingsKeys.contains("reverseAPIPort") || | 
					
						
							|  |  |  |             settingsKeys.contains("reverseAPIDeviceIndex"); | 
					
						
							|  |  |  |         webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (force) { | 
					
						
							|  |  |  |         m_settings = settings; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         m_settings.applySettings(settingsKeys, settings); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int KiwiSDRInput::webapiRunGet( | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |         QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     (void) errorMessage; | 
					
						
							|  |  |  |     m_deviceAPI->getDeviceEngineStateStr(*response.getState()); | 
					
						
							|  |  |  |     return 200; | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int KiwiSDRInput::webapiRun( | 
					
						
							|  |  |  |         bool run, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |         QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     (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; | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int KiwiSDRInput::webapiSettingsGet( | 
					
						
							|  |  |  |                 SWGSDRangel::SWGDeviceSettings& response, | 
					
						
							|  |  |  |                 QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     (void) errorMessage; | 
					
						
							|  |  |  |     response.setKiwiSdrSettings(new SWGSDRangel::SWGKiwiSDRSettings()); | 
					
						
							|  |  |  |     response.getKiwiSdrSettings()->init(); | 
					
						
							|  |  |  |     webapiFormatDeviceSettings(response, m_settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int KiwiSDRInput::webapiSettingsPutPatch( | 
					
						
							|  |  |  |                 bool force, | 
					
						
							|  |  |  |                 const QStringList& deviceSettingsKeys, | 
					
						
							|  |  |  |                 SWGSDRangel::SWGDeviceSettings& response, // query + response
 | 
					
						
							|  |  |  |                 QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     (void) errorMessage; | 
					
						
							|  |  |  |     KiwiSDRSettings settings = m_settings; | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  |     webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response); | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |     MsgConfigureKiwiSDR *msg = MsgConfigureKiwiSDR::create(settings, deviceSettingsKeys, force); | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  |     m_inputMessageQueue.push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) // forward to GUI if any
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  |         MsgConfigureKiwiSDR *msgToGUI = MsgConfigureKiwiSDR::create(settings, deviceSettingsKeys, force); | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  |         m_guiMessageQueue->push(msgToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     webapiFormatDeviceSettings(response, settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KiwiSDRInput::webapiUpdateDeviceSettings( | 
					
						
							|  |  |  |         KiwiSDRSettings& settings, | 
					
						
							|  |  |  |         const QStringList& deviceSettingsKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceSettings& response) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     if (deviceSettingsKeys.contains("gain")) { | 
					
						
							|  |  |  |         settings.m_gain = response.getKiwiSdrSettings()->getGain(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("useAGC")) { | 
					
						
							|  |  |  |         settings.m_useAGC = response.getKiwiSdrSettings()->getUseAgc(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-09 20:56:22 +02:00
										 |  |  |     if (deviceSettingsKeys.contains("dcBlock")) { | 
					
						
							|  |  |  |         settings.m_dcBlock = response.getKiwiSdrSettings()->getDcBlock() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     if (deviceSettingsKeys.contains("centerFrequency")) { | 
					
						
							|  |  |  |         settings.m_centerFrequency = response.getKiwiSdrSettings()->getCenterFrequency(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("serverAddress")) { | 
					
						
							|  |  |  |         settings.m_serverAddress = *response.getKiwiSdrSettings()->getServerAddress(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("useReverseAPI")) { | 
					
						
							|  |  |  |         settings.m_useReverseAPI = response.getKiwiSdrSettings()->getUseReverseApi() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIAddress")) { | 
					
						
							|  |  |  |         settings.m_reverseAPIAddress = *response.getKiwiSdrSettings()->getReverseApiAddress(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIPort")) { | 
					
						
							|  |  |  |         settings.m_reverseAPIPort = response.getKiwiSdrSettings()->getReverseApiPort(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) { | 
					
						
							|  |  |  |         settings.m_reverseAPIDeviceIndex = response.getKiwiSdrSettings()->getReverseApiDeviceIndex(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 00:56:31 +02:00
										 |  |  | int KiwiSDRInput::webapiReportGet( | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceReport& response, | 
					
						
							|  |  |  |         QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) errorMessage; | 
					
						
							|  |  |  |     response.setKiwiSdrReport(new SWGSDRangel::SWGKiwiSDRReport()); | 
					
						
							|  |  |  |     response.getKiwiSdrReport()->init(); | 
					
						
							|  |  |  |     webapiFormatDeviceReport(response); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | void KiwiSDRInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const KiwiSDRSettings& settings) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     response.getKiwiSdrSettings()->setGain(settings.m_gain); | 
					
						
							|  |  |  |     response.getKiwiSdrSettings()->setUseAgc(settings.m_useAGC ? 1 : 0); | 
					
						
							| 
									
										
										
										
											2019-06-09 20:56:22 +02:00
										 |  |  |     response.getKiwiSdrSettings()->setDcBlock(settings.m_dcBlock ? 1 : 0); | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     response.getKiwiSdrSettings()->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (response.getKiwiSdrSettings()->getServerAddress()) { | 
					
						
							|  |  |  |         *response.getKiwiSdrSettings()->getServerAddress() = settings.m_serverAddress; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.getKiwiSdrSettings()->setServerAddress(new QString(settings.m_serverAddress)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-09 01:44:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.getKiwiSdrSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (response.getKiwiSdrSettings()->getReverseApiAddress()) { | 
					
						
							|  |  |  |         *response.getKiwiSdrSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.getKiwiSdrSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.getKiwiSdrSettings()->setReverseApiPort(settings.m_reverseAPIPort); | 
					
						
							|  |  |  |     response.getKiwiSdrSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 00:56:31 +02:00
										 |  |  | void KiwiSDRInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     response.getKiwiSdrReport()->setStatus(getStatus()); | 
					
						
							| 
									
										
										
										
											2024-04-04 16:15:41 +01:00
										 |  |  |     response.getKiwiSdrReport()->setLatitude(m_latitude); | 
					
						
							|  |  |  |     response.getKiwiSdrReport()->setLongitude(m_longitude); | 
					
						
							|  |  |  |     response.getKiwiSdrReport()->setAltitude(m_altitude); | 
					
						
							| 
									
										
										
										
											2019-06-09 00:56:31 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-23 22:02:47 +02:00
										 |  |  | void KiwiSDRInput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const KiwiSDRSettings& settings, bool force) | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); | 
					
						
							|  |  |  |     swgDeviceSettings->setDirection(0); // single Rx
 | 
					
						
							|  |  |  |     swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); | 
					
						
							|  |  |  |     swgDeviceSettings->setDeviceHwType(new QString("KiwiSDR")); | 
					
						
							|  |  |  |     swgDeviceSettings->setKiwiSdrSettings(new SWGSDRangel::SWGKiwiSDRSettings()); | 
					
						
							|  |  |  |     SWGSDRangel::SWGKiwiSDRSettings *swgKiwiSDRSettings = swgDeviceSettings->getKiwiSdrSettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // transfer data that has been modified. When force is on transfer all data except reverse API data
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("gain")) { | 
					
						
							|  |  |  |         swgKiwiSDRSettings->setGain(settings.m_gain); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("useAGC")) { | 
					
						
							|  |  |  |         swgKiwiSDRSettings->setUseAgc(settings.m_useAGC ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-09 20:56:22 +02:00
										 |  |  |     if (deviceSettingsKeys.contains("dcBlock") || force) { | 
					
						
							|  |  |  |         swgKiwiSDRSettings->setDcBlock(settings.m_dcBlock ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     if (deviceSettingsKeys.contains("centerFrequency") || force) { | 
					
						
							|  |  |  |         swgKiwiSDRSettings->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("serverAddress") || force) { | 
					
						
							|  |  |  |         swgKiwiSDRSettings->setServerAddress(new QString(settings.m_serverAddress)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString deviceSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/settings") | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIAddress) | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIPort) | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  |     m_networkRequest.setUrl(QUrl(deviceSettingsURL)); | 
					
						
							|  |  |  |     m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     QBuffer *buffer = new QBuffer(); | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     buffer->open((QBuffer::ReadWrite)); | 
					
						
							|  |  |  |     buffer->write(swgDeviceSettings->asJson().toUtf8()); | 
					
						
							|  |  |  |     buffer->seek(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Always use PATCH to avoid passing reverse API settings
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer); | 
					
						
							|  |  |  |     buffer->setParent(reply); | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     delete swgDeviceSettings; | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KiwiSDRInput::webapiReverseSendStartStop(bool start) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); | 
					
						
							|  |  |  |     swgDeviceSettings->setDirection(0); // single Rx
 | 
					
						
							|  |  |  |     swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); | 
					
						
							|  |  |  |     swgDeviceSettings->setDeviceHwType(new QString("KiwiSDR")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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)); | 
					
						
							|  |  |  |     m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     QBuffer *buffer = new QBuffer(); | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     buffer->open((QBuffer::ReadWrite)); | 
					
						
							|  |  |  |     buffer->write(swgDeviceSettings->asJson().toUtf8()); | 
					
						
							|  |  |  |     buffer->seek(0); | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     QNetworkReply *reply; | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (start) { | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |         reply = m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer); | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |         reply = m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer); | 
					
						
							| 
									
										
										
										
											2019-06-08 21:25:08 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-14 16:58:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     buffer->setParent(reply); | 
					
						
							| 
									
										
										
										
											2019-06-14 16:58:09 +02:00
										 |  |  |     delete swgDeviceSettings; | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KiwiSDRInput::networkManagerFinished(QNetworkReply *reply) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QNetworkReply::NetworkError replyError = reply->error(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (replyError) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qWarning() << "KiwiSDRInput::networkManagerFinished:" | 
					
						
							|  |  |  |                 << " error(" << (int) replyError | 
					
						
							|  |  |  |                 << "): " << replyError | 
					
						
							|  |  |  |                 << ": " << reply->errorString(); | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString answer = reply->readAll(); | 
					
						
							|  |  |  |         answer.chop(1); // remove last \n
 | 
					
						
							|  |  |  |         qDebug("KiwiSDRInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str()); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:46:21 +01:00
										 |  |  |     reply->deleteLater(); | 
					
						
							| 
									
										
										
										
											2019-06-07 10:33:33 +03:00
										 |  |  | } |