| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-18 09:58:55 +01:00
										 |  |  | // Copyright (C) 2016-2023 Edouard Griffiths, F4EXB <f4exb06@gmail.com>          //
 | 
					
						
							|  |  |  | // Copyright (C) 2021 Andreas Baulig <free.geronimo@hotmail.de>                  //
 | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 06:39:30 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  | #include <QNetworkReply>
 | 
					
						
							|  |  |  | #include <QBuffer>
 | 
					
						
							| 
									
										
										
										
											2021-08-04 13:38:42 +00:00
										 |  |  | #include <QDateTime>
 | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 18:22:45 +01:00
										 |  |  | #include "SWGDeviceSettings.h"
 | 
					
						
							|  |  |  | #include "SWGDeviceState.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | #include "util/simpleserializer.h"
 | 
					
						
							|  |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							|  |  |  | #include "dsp/filerecord.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | #include "device/deviceapi.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-22 21:47:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | #include "fileoutput.h"
 | 
					
						
							|  |  |  | #include "fileoutputworker.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(FileOutput::MsgConfigureFileOutput, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(FileOutput::MsgStartStop, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(FileOutput::MsgConfigureFileOutputName, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(FileOutput::MsgConfigureFileOutputWork, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(FileOutput::MsgConfigureFileOutputStreamTiming, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(FileOutput::MsgReportFileOutputGeneration, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(FileOutput::MsgReportFileOutputStreamTiming, Message) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | FileOutput::FileOutput(DeviceAPI *deviceAPI) : | 
					
						
							| 
									
										
										
										
											2016-10-22 21:47:59 +02:00
										 |  |  |     m_deviceAPI(deviceAPI), | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	m_settings(), | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	m_deviceDescription("FileOutput"), | 
					
						
							| 
									
										
										
										
											2017-09-14 13:55:57 +02:00
										 |  |  | 	m_masterTimer(deviceAPI->getMasterTimer()) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-21 00:27:08 +02:00
										 |  |  |     m_deviceAPI->setNbSinkStreams(1); | 
					
						
							| 
									
										
										
										
											2023-05-18 10:20:27 +02:00
										 |  |  |     m_networkManager = new QNetworkAccessManager(); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | FileOutput::~FileOutput() | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-05-26 22:02:18 +02:00
										 |  |  | 	delete m_networkManager; | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	FileOutput::stop(); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | void FileOutput::destroy() | 
					
						
							| 
									
										
										
										
											2017-09-16 11:34:25 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | void FileOutput::openFileStream() | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (m_ofstream.is_open()) { | 
					
						
							|  |  |  | 		m_ofstream.close(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  | 	m_ofstream.open(m_settings.m_fileName.toStdString().c_str(), std::ios::binary); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-10 14:05:21 +02:00
										 |  |  |     FileRecord::Header header; | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	auto actualSampleRate = (int) (m_settings.m_sampleRate * (1<<m_settings.m_log2Interp)); | 
					
						
							| 
									
										
										
										
											2018-10-10 14:05:21 +02:00
										 |  |  |     header.sampleRate = actualSampleRate; | 
					
						
							|  |  |  |     header.centerFrequency = m_settings.m_centerFrequency; | 
					
						
							| 
									
										
										
										
											2021-08-04 13:38:42 +00:00
										 |  |  |     m_startingTimeStamp = QDateTime::currentMSecsSinceEpoch(); | 
					
						
							|  |  |  |     header.startTimeStamp = (quint64)m_startingTimeStamp; | 
					
						
							| 
									
										
										
										
											2018-10-10 14:05:21 +02:00
										 |  |  |     header.sampleSize = SDR_RX_SAMP_SZ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FileRecord::writeHeader(m_ofstream, header); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  | 	qDebug() << "FileOutput::openFileStream: " << m_settings.m_fileName.toStdString().c_str(); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | void FileOutput::init() | 
					
						
							| 
									
										
										
										
											2017-12-25 12:59:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |     applySettings(m_settings, QList<QString>(), true); | 
					
						
							| 
									
										
										
										
											2017-12-25 12:59:44 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | bool FileOutput::start() | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QMutexLocker mutexLocker(&m_mutex); | 
					
						
							| 
									
										
										
										
											2024-08-21 05:27:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_running) { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	qDebug() << "FileOutput::start"; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-23 10:54:54 +02:00
										 |  |  | 	openFileStream(); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	m_fileOutputWorker = new FileOutputWorker(&m_ofstream, &m_sampleSourceFifo); | 
					
						
							|  |  |  |     m_fileOutputWorker->moveToThread(&m_fileOutputWorkerThread); | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	m_fileOutputWorker->setSamplerate((int) m_settings.m_sampleRate); | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	m_fileOutputWorker->setLog2Interpolation(m_settings.m_log2Interp); | 
					
						
							|  |  |  | 	m_fileOutputWorker->connectTimer(m_masterTimer); | 
					
						
							| 
									
										
										
										
											2020-07-12 10:22:24 +02:00
										 |  |  | 	startWorker(); | 
					
						
							| 
									
										
										
										
											2024-08-21 05:27:01 +02:00
										 |  |  |     m_running = true; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mutexLocker.unlock(); | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	qDebug("FileOutput::start: started"); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 07:40:16 +02:00
										 |  |  |     if (getMessageQueueToGUI()) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  |         MsgReportFileOutputGeneration *report = MsgReportFileOutputGeneration::create(true); // acquisition on
 | 
					
						
							| 
									
										
										
										
											2017-10-14 07:40:16 +02:00
										 |  |  |         getMessageQueueToGUI()->push(report); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | void FileOutput::stop() | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QMutexLocker mutexLocker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-21 05:27:01 +02:00
										 |  |  |     if (!m_running) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qDebug() << "FileSourceInput::stop"; | 
					
						
							|  |  |  |     m_running = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	if (m_fileOutputWorker) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-07-12 10:22:24 +02:00
										 |  |  | 		stopWorker(); | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		delete m_fileOutputWorker; | 
					
						
							|  |  |  | 		m_fileOutputWorker = nullptr; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-23 10:54:54 +02:00
										 |  |  |     if (m_ofstream.is_open()) { | 
					
						
							|  |  |  |         m_ofstream.close(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 07:40:16 +02:00
										 |  |  |     if (getMessageQueueToGUI()) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  |         MsgReportFileOutputGeneration *report = MsgReportFileOutputGeneration::create(false); // acquisition off
 | 
					
						
							| 
									
										
										
										
											2017-10-14 07:40:16 +02:00
										 |  |  |         getMessageQueueToGUI()->push(report); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | void FileOutput::startWorker() | 
					
						
							| 
									
										
										
										
											2020-07-12 12:51:38 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  |     m_fileOutputWorker->startWork(); | 
					
						
							|  |  |  |     m_fileOutputWorkerThread.start(); | 
					
						
							| 
									
										
										
										
											2020-07-12 12:51:38 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | void FileOutput::stopWorker() | 
					
						
							| 
									
										
										
										
											2020-07-12 12:51:38 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  |     m_fileOutputWorker->stopWork(); | 
					
						
							|  |  |  |     m_fileOutputWorkerThread.quit(); | 
					
						
							|  |  |  |     m_fileOutputWorkerThread.wait(); | 
					
						
							| 
									
										
										
										
											2020-07-12 12:51:38 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | QByteArray FileOutput::serialize() const | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | bool FileOutput::deserialize(const QByteArray& data) | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     bool success = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_settings.resetToDefaults(); | 
					
						
							|  |  |  |         success = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |     MsgConfigureFileOutput* message = MsgConfigureFileOutput::create(m_settings, QList<QString>(), true); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |         MsgConfigureFileOutput* messageToGUI = MsgConfigureFileOutput::create(m_settings, QList<QString>(), true); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return success; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | const QString& FileOutput::getDeviceDescription() const | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	return m_deviceDescription; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | int FileOutput::getSampleRate() const | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	return (int) m_settings.m_sampleRate; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | quint64 FileOutput::getCenterFrequency() const | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-10-23 10:38:44 +02:00
										 |  |  | 	return m_settings.m_centerFrequency; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | void FileOutput::setCenterFrequency(qint64 centerFrequency) | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  |     FileOutputSettings settings = m_settings; | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |     settings.m_centerFrequency = centerFrequency; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |     MsgConfigureFileOutput* message = MsgConfigureFileOutput::create(settings, QList<QString>{"centerFrequency"}, false); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |         MsgConfigureFileOutput* messageToGUI = MsgConfigureFileOutput::create(settings, QList<QString>{"centerFrequency"}, false); | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |         m_guiMessageQueue->push(messageToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | std::time_t FileOutput::getStartingTimeStamp() const | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	return m_startingTimeStamp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | bool FileOutput::handleMessage(const Message& message) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	if (MsgConfigureFileOutputName::match(message)) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 		auto& conf = (const MsgConfigureFileOutputName&) message; | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  | 		m_settings.m_fileName = conf.getFileName(); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		openFileStream(); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  | 	else if (MsgStartStop::match(message)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         auto& cmd = (const MsgStartStop&) message; | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  |         qDebug() << "FileOutput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (cmd.getStartStop()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |             if (m_deviceAPI->initDeviceEngine()) { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |                 m_deviceAPI->startDeviceEngine(); | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             m_deviceAPI->stopDeviceEngine(); | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |         if (m_settings.m_useReverseAPI) { | 
					
						
							|  |  |  |             webapiReverseSendStartStop(cmd.getStartStop()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +01:00
										 |  |  |         return true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	else if (MsgConfigureFileOutput::match(message)) | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         qDebug() << "FileOutput::handleMessage: MsgConfigureFileOutput"; | 
					
						
							|  |  |  |         auto& conf = (const MsgConfigureFileOutput&) message; | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |         applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce()); | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	else if (MsgConfigureFileOutputWork::match(message)) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 		auto& conf = (const MsgConfigureFileOutputWork&) message; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		bool working = conf.isWorking(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 		if (m_fileOutputWorker != nullptr) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2020-07-12 10:22:24 +02:00
										 |  |  | 			if (working) { | 
					
						
							|  |  |  | 				startWorker(); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				stopWorker(); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	else if (MsgConfigureFileOutputStreamTiming::match(message)) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 		if (m_fileOutputWorker != nullptr && getMessageQueueToGUI()) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 			auto *report = MsgReportFileOutputStreamTiming::create(m_fileOutputWorker->getSamplesCount()); | 
					
						
							| 
									
										
										
										
											2017-10-14 07:34:00 +02:00
										 |  |  | 			getMessageQueueToGUI()->push(report); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  | void FileOutput::applySettings(const FileOutputSettings& settings, const QList<QString>& settingsKeys, bool force) | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |     qDebug() << "FileOutput::applySettings: force:" << force << settings.getDebugString(settingsKeys, force); | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  |     QMutexLocker mutexLocker(&m_mutex); | 
					
						
							| 
									
										
										
										
											2016-10-22 21:47:59 +02:00
										 |  |  |     bool forwardChange = false; | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |     if (force || settingsKeys.contains("centerFrequency")) | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-10-22 21:47:59 +02:00
										 |  |  |         forwardChange = true; | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |     if (force || settingsKeys.contains("sampleRate")) | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (m_fileOutputWorker != nullptr) { | 
					
						
							|  |  |  |             m_fileOutputWorker->setSamplerate((int) settings.m_sampleRate); | 
					
						
							| 
									
										
										
										
											2016-10-23 10:38:44 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-22 21:47:59 +02:00
										 |  |  |         forwardChange = true; | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-10-22 21:47:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |     if (force || settingsKeys.contains("log2Interp")) | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         if (m_fileOutputWorker != nullptr) { | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |             m_fileOutputWorker->setLog2Interpolation(settings.m_log2Interp); | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         forwardChange = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-14 18:58:12 +02:00
										 |  |  |     if (settings.m_useReverseAPI) | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |         bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) || | 
					
						
							|  |  |  |             settingsKeys.contains("reverseAPIAddress") || | 
					
						
							|  |  |  |             settingsKeys.contains("reverseAPIPort") || | 
					
						
							|  |  |  |             settingsKeys.contains("reverseAPIDeviceIndex"); | 
					
						
							|  |  |  |         webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force); | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |     if (force) { | 
					
						
							|  |  |  |         m_settings = settings; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         m_settings.applySettings(settingsKeys, settings); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-22 21:47:59 +02:00
										 |  |  |     if (forwardChange) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  |         qDebug("FileOutput::applySettings: forward: m_centerFrequency: %llu m_sampleRate: %llu m_log2Interp: %d", | 
					
						
							| 
									
										
										
										
											2016-10-23 02:22:00 +02:00
										 |  |  |                 m_settings.m_centerFrequency, | 
					
						
							| 
									
										
										
										
											2017-01-02 03:14:46 +01:00
										 |  |  |                 m_settings.m_sampleRate, | 
					
						
							|  |  |  |                 m_settings.m_log2Interp); | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         auto *notif = new DSPSignalNotification((int) m_settings.m_sampleRate, m_settings.m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2017-09-13 23:42:28 +02:00
										 |  |  |         m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); | 
					
						
							| 
									
										
										
										
											2016-10-22 21:47:59 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-10-22 21:47:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  | int FileOutput::webapiSettingsGet( | 
					
						
							|  |  |  |                 SWGSDRangel::SWGDeviceSettings& response, | 
					
						
							|  |  |  |                 QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) errorMessage; | 
					
						
							|  |  |  |     response.setFileOutputSettings(new SWGSDRangel::SWGFileOutputSettings()); | 
					
						
							|  |  |  |     response.getFileOutputSettings()->init(); | 
					
						
							|  |  |  |     webapiFormatDeviceSettings(response, m_settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int FileOutput::webapiSettingsPutPatch( | 
					
						
							|  |  |  |                 bool force, | 
					
						
							|  |  |  |                 const QStringList& deviceSettingsKeys, | 
					
						
							|  |  |  |                 SWGSDRangel::SWGDeviceSettings& response, // query + response
 | 
					
						
							|  |  |  |                 QString& errorMessage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) errorMessage; | 
					
						
							|  |  |  |     FileOutputSettings settings = m_settings; | 
					
						
							|  |  |  |     webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |     MsgConfigureFileOutput *msg = MsgConfigureFileOutput::create(settings, deviceSettingsKeys, force); | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |     m_inputMessageQueue.push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) // forward to GUI if any
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  |         MsgConfigureFileOutput *msgToGUI = MsgConfigureFileOutput::create(settings, deviceSettingsKeys, force); | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |         m_guiMessageQueue->push(msgToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     webapiFormatDeviceSettings(response, settings); | 
					
						
							|  |  |  |     return 200; | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-12-14 18:22:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | int FileOutput::webapiRunGet( | 
					
						
							| 
									
										
										
										
											2017-12-14 18:22:45 +01:00
										 |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |         QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2017-12-14 18:22:45 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2017-12-14 18:22:45 +01:00
										 |  |  |     m_deviceAPI->getDeviceEngineStateStr(*response.getState()); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | int FileOutput::webapiRun( | 
					
						
							| 
									
										
										
										
											2017-12-14 18:22:45 +01:00
										 |  |  |         bool run, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |         QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2017-12-14 18:22:45 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2017-12-14 23:29:12 +01:00
										 |  |  |     m_deviceAPI->getDeviceEngineStateStr(*response.getState()); | 
					
						
							| 
									
										
										
										
											2017-12-14 18:22:45 +01:00
										 |  |  |     MsgStartStop *message = MsgStartStop::create(run); | 
					
						
							|  |  |  |     m_inputMessageQueue.push(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgStartStop *messagetoGui = MsgStartStop::create(run); | 
					
						
							|  |  |  |         m_guiMessageQueue->push(messagetoGui); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  | void FileOutput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const FileOutputSettings& settings) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     response.getFileOutputSettings()->setFileName(new QString(settings.m_fileName)); | 
					
						
							|  |  |  |     response.getFileOutputSettings()->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  |     response.getFileOutputSettings()->setSampleRate(settings.m_sampleRate); | 
					
						
							|  |  |  |     response.getFileOutputSettings()->setLog2Interp(settings.m_log2Interp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.getFileOutputSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (response.getFileOutputSettings()->getReverseApiAddress()) { | 
					
						
							|  |  |  |         *response.getFileOutputSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.getFileOutputSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.getFileOutputSettings()->setReverseApiPort(settings.m_reverseAPIPort); | 
					
						
							|  |  |  |     response.getFileOutputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileOutput::webapiUpdateDeviceSettings( | 
					
						
							|  |  |  |         FileOutputSettings& settings, | 
					
						
							|  |  |  |         const QStringList& deviceSettingsKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceSettings& response) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("fileName")) { | 
					
						
							|  |  |  |         settings.m_fileName = *response.getFileOutputSettings()->getFileName(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("centerFrequency")) { | 
					
						
							|  |  |  |         settings.m_centerFrequency = response.getFileOutputSettings()->getCenterFrequency(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("sampleRate")) { | 
					
						
							|  |  |  |         settings.m_sampleRate = response.getFileOutputSettings()->getSampleRate(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2Interp")) { | 
					
						
							|  |  |  |         settings.m_log2Interp = response.getFileOutputSettings()->getLog2Interp(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("useReverseAPI")) { | 
					
						
							|  |  |  |         settings.m_useReverseAPI = response.getFileOutputSettings()->getUseReverseApi() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIAddress")) { | 
					
						
							|  |  |  |         settings.m_reverseAPIAddress = *response.getFileOutputSettings()->getReverseApiAddress(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIPort")) { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         settings.m_reverseAPIPort = (uint16_t) response.getFileOutputSettings()->getReverseApiPort(); | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |         settings.m_reverseAPIDeviceIndex = (uint16_t) response.getFileOutputSettings()->getReverseApiDeviceIndex(); | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 10:25:19 +01:00
										 |  |  | void FileOutput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const FileOutputSettings& settings, bool force) | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |     swgDeviceSettings->setDirection(1); // single Tx
 | 
					
						
							|  |  |  |     swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); | 
					
						
							|  |  |  |     swgDeviceSettings->setDeviceHwType(new QString("FileOutput")); | 
					
						
							|  |  |  |     swgDeviceSettings->setFileOutputSettings(new SWGSDRangel::SWGFileOutputSettings()); | 
					
						
							|  |  |  |     SWGSDRangel::SWGFileOutputSettings *swgFileOutputSettings = swgDeviceSettings->getFileOutputSettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // transfer data that has been modified. When force is on transfer all data except reverse API data
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("centerFrequency") || force) { | 
					
						
							|  |  |  |         swgFileOutputSettings->setCenterFrequency(settings.m_centerFrequency); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("sampleRate") || force) { | 
					
						
							|  |  |  |         swgFileOutputSettings->setSampleRate(settings.m_sampleRate); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("log2Interp") || force) { | 
					
						
							|  |  |  |         swgFileOutputSettings->setLog2Interp(settings.m_log2Interp); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (deviceSettingsKeys.contains("fileName") || force) { | 
					
						
							|  |  |  |         swgFileOutputSettings->setFileName(new QString(settings.m_fileName)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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"); | 
					
						
							| 
									
										
										
										
											2017-12-14 18:22:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     auto *buffer = new QBuffer(); | 
					
						
							|  |  |  |     buffer->open(QBuffer::ReadWrite); | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |     buffer->write(swgDeviceSettings->asJson().toUtf8()); | 
					
						
							|  |  |  |     buffer->seek(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Always use PATCH to avoid passing reverse API settings
 | 
					
						
							|  |  |  |     QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer); | 
					
						
							|  |  |  |     buffer->setParent(reply); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     delete swgDeviceSettings; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileOutput::webapiReverseSendStartStop(bool start) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     auto *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings(); | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |     swgDeviceSettings->setDirection(1); // single Tx
 | 
					
						
							|  |  |  |     swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex()); | 
					
						
							|  |  |  |     swgDeviceSettings->setDeviceHwType(new QString("FileOutput")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  |     auto *buffer = new QBuffer(); | 
					
						
							|  |  |  |     buffer->open(QBuffer::ReadWrite); | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  |     buffer->write(swgDeviceSettings->asJson().toUtf8()); | 
					
						
							|  |  |  |     buffer->seek(0); | 
					
						
							|  |  |  |     QNetworkReply *reply; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (start) { | 
					
						
							|  |  |  |         reply = m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         reply = m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     buffer->setParent(reply); | 
					
						
							|  |  |  |     delete swgDeviceSettings; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | void FileOutput::networkManagerFinished(QNetworkReply *reply) const | 
					
						
							| 
									
										
										
										
											2021-05-18 01:52:25 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QNetworkReply::NetworkError replyError = reply->error(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (replyError) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qWarning() << "FileOutput::networkManagerFinished:" | 
					
						
							|  |  |  |                 << " error(" << (int) replyError | 
					
						
							|  |  |  |                 << "): " << replyError | 
					
						
							|  |  |  |                 << ": " << reply->errorString(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString answer = reply->readAll(); | 
					
						
							|  |  |  |         answer.chop(1); // remove last \n
 | 
					
						
							|  |  |  |         qDebug("FileOutput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     reply->deleteLater(); | 
					
						
							|  |  |  | } |