| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2016 Edouard Griffiths, F4EXB                                   //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 06:39:30 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +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 <QTime>
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <QMutexLocker>
 | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  | #include <QNetworkAccessManager>
 | 
					
						
							|  |  |  | #include <QNetworkReply>
 | 
					
						
							|  |  |  | #include <QBuffer>
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | #include <QThread>
 | 
					
						
							| 
									
										
										
										
											2017-10-14 05:23:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <complex.h>
 | 
					
						
							|  |  |  | #include <algorithm>
 | 
					
						
							| 
									
										
										
										
											2017-10-14 05:23:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  | #include "SWGChannelSettings.h"
 | 
					
						
							|  |  |  | #include "SWGChannelReport.h"
 | 
					
						
							|  |  |  | #include "SWGAMModReport.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | #include "dsp/dspengine.h"
 | 
					
						
							| 
									
										
										
										
											2018-02-14 20:11:36 +01:00
										 |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | #include "device/deviceapi.h"
 | 
					
						
							| 
									
										
										
										
											2020-10-23 00:11:18 +02:00
										 |  |  | #include "feature/feature.h"
 | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  | #include "util/db.h"
 | 
					
						
							| 
									
										
										
										
											2020-10-23 00:11:18 +02:00
										 |  |  | #include "maincore.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-14 05:23:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | #include "wfmmodbaseband.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | #include "wfmmod.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(WFMMod::MsgConfigureWFMMod, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(WFMMod::MsgConfigureFileSourceName, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(WFMMod::MsgConfigureFileSourceSeek, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(WFMMod::MsgConfigureFileSourceStreamTiming, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(WFMMod::MsgReportFileSourceStreamData, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(WFMMod::MsgReportFileSourceStreamTiming, Message) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 20:24:18 +01:00
										 |  |  | const char* const WFMMod::m_channelIdURI = "sdrangel.channeltx.modwfm"; | 
					
						
							|  |  |  | const char* const WFMMod::m_channelId = "WFMMod"; | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | WFMMod::WFMMod(DeviceAPI *deviceAPI) : | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  |     ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), | 
					
						
							| 
									
										
										
										
											2017-10-14 05:23:45 +02:00
										 |  |  |     m_deviceAPI(deviceAPI), | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | 	m_settingsMutex(QMutex::Recursive), | 
					
						
							|  |  |  |     m_fileSize(0), | 
					
						
							|  |  |  | 	m_recordLength(0), | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | 	m_sampleRate(48000) | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  | 	setObjectName(m_channelId); | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_thread = new QThread(this); | 
					
						
							|  |  |  |     m_basebandSource = new WFMModBaseband(); | 
					
						
							|  |  |  |     m_basebandSource->setInputFileStream(&m_ifstream); | 
					
						
							| 
									
										
										
										
											2020-12-21 02:30:29 +01:00
										 |  |  |     m_basebandSource->setChannel(this); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_basebandSource->moveToThread(m_thread); | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-16 10:26:49 +01:00
										 |  |  |     applySettings(m_settings, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_deviceAPI->addChannelSource(this); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |     m_deviceAPI->addChannelSourceAPI(this); | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_networkManager = new QNetworkAccessManager(); | 
					
						
							|  |  |  |     connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); | 
					
						
							| 
									
										
										
										
											2021-06-29 21:47:27 +02:00
										 |  |  |     connect(&m_channelMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleChannelMessages())); | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | WFMMod::~WFMMod() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |     disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); | 
					
						
							|  |  |  |     delete m_networkManager; | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |     m_deviceAPI->removeChannelSourceAPI(this); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_deviceAPI->removeChannelSource(this); | 
					
						
							|  |  |  |     delete m_basebandSource; | 
					
						
							|  |  |  |     delete m_thread; | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | void WFMMod::start() | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | 	qDebug("WFMMod::start"); | 
					
						
							|  |  |  |     m_basebandSource->reset(); | 
					
						
							|  |  |  |     m_thread->start(); | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | void WFMMod::stop() | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     qDebug("WFMMod::stop"); | 
					
						
							|  |  |  | 	m_thread->exit(); | 
					
						
							|  |  |  | 	m_thread->wait(); | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | void WFMMod::pull(SampleVector::iterator& begin, unsigned int nbSamples) | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     m_basebandSource->pull(begin, nbSamples); | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool WFMMod::handleMessage(const Message& cmd) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-11-21 00:40:55 +01:00
										 |  |  |     if (MsgConfigureWFMMod::match(cmd)) | 
					
						
							| 
									
										
										
										
											2017-10-14 04:45:44 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         MsgConfigureWFMMod& cfg = (MsgConfigureWFMMod&) cmd; | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |         qDebug() << "WFMMod::handleMessage: MsgConfigureWFMMod"; | 
					
						
							| 
									
										
										
										
											2017-10-14 04:45:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         WFMModSettings settings = cfg.getSettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 00:18:51 +01:00
										 |  |  |         applySettings(cfg.getSettings(), cfg.getForce()); | 
					
						
							| 
									
										
										
										
											2017-10-14 04:45:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | 	else if (MsgConfigureFileSourceName::match(cmd)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgConfigureFileSourceName& conf = (MsgConfigureFileSourceName&) cmd; | 
					
						
							|  |  |  |         m_fileName = conf.getFileName(); | 
					
						
							|  |  |  |         openFileStream(); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (MsgConfigureFileSourceSeek::match(cmd)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) cmd; | 
					
						
							|  |  |  |         int seekPercentage = conf.getPercentage(); | 
					
						
							|  |  |  |         seekFileStream(seekPercentage); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (MsgConfigureFileSourceStreamTiming::match(cmd)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     	std::size_t samplesCount; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     	if (m_ifstream.eof()) { | 
					
						
							|  |  |  |     		samplesCount = m_fileSize / sizeof(Real); | 
					
						
							|  |  |  |     	} else { | 
					
						
							|  |  |  |     		samplesCount = m_ifstream.tellg() / sizeof(Real); | 
					
						
							|  |  |  |     	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     	MsgReportFileSourceStreamTiming *report; | 
					
						
							|  |  |  |         report = MsgReportFileSourceStreamTiming::create(samplesCount); | 
					
						
							|  |  |  |         getMessageQueueToGUI()->push(report); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |     else if (CWKeyer::MsgConfigureCWKeyer::match(cmd)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) cmd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (m_settings.m_useReverseAPI) { | 
					
						
							|  |  |  |             webapiReverseSendCWSettings(cfg.getSettings()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-02-14 20:11:36 +01:00
										 |  |  |     else if (DSPSignalNotification::match(cmd)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |         // Forward to the source
 | 
					
						
							|  |  |  |         DSPSignalNotification& notif = (DSPSignalNotification&) cmd; | 
					
						
							|  |  |  |         DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy
 | 
					
						
							|  |  |  |         qDebug() << "WFMMod::handleMessage: DSPSignalNotification"; | 
					
						
							|  |  |  |         m_basebandSource->getInputMessageQueue()->push(rep); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 20:11:36 +01:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-29 21:47:27 +02:00
										 |  |  |     else if (MainCore::MsgChannelDemodQuery::match(cmd)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug() << "WFMMod::handleMessage: MsgChannelDemodQuery"; | 
					
						
							|  |  |  |         sendSampleRateToDemodAnalyzer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WFMMod::openFileStream() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_ifstream.is_open()) { | 
					
						
							|  |  |  |         m_ifstream.close(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary | std::ios::ate); | 
					
						
							|  |  |  |     m_fileSize = m_ifstream.tellg(); | 
					
						
							|  |  |  |     m_ifstream.seekg(0,std::ios_base::beg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_sampleRate = 48000; // fixed rate
 | 
					
						
							|  |  |  |     m_recordLength = m_fileSize / (sizeof(Real) * m_sampleRate); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     qDebug() << "WFMMod::openFileStream: " << m_fileName.toStdString().c_str() | 
					
						
							|  |  |  |             << " fileSize: " << m_fileSize << "bytes" | 
					
						
							|  |  |  |             << " length: " << m_recordLength << " seconds"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MsgReportFileSourceStreamData *report; | 
					
						
							|  |  |  |     report = MsgReportFileSourceStreamData::create(m_sampleRate, m_recordLength); | 
					
						
							|  |  |  |     getMessageQueueToGUI()->push(report); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WFMMod::seekFileStream(int seekPercentage) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QMutexLocker mutexLocker(&m_settingsMutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_ifstream.is_open()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int seekPoint = ((m_recordLength * seekPercentage) / 100) * m_sampleRate; | 
					
						
							|  |  |  |         seekPoint *= sizeof(Real); | 
					
						
							|  |  |  |         m_ifstream.clear(); | 
					
						
							|  |  |  |         m_ifstream.seekg(seekPoint, std::ios::beg); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 00:18:51 +01:00
										 |  |  | void WFMMod::applySettings(const WFMModSettings& settings, bool force) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     qDebug() << "WFMMod::applySettings:" | 
					
						
							|  |  |  |             << " m_inputFrequencyOffset: " << settings.m_inputFrequencyOffset | 
					
						
							|  |  |  |             << " m_rfBandwidth: " << settings.m_rfBandwidth | 
					
						
							|  |  |  |             << " m_afBandwidth: " << settings.m_afBandwidth | 
					
						
							|  |  |  |             << " m_fmDeviation: " << settings.m_fmDeviation | 
					
						
							|  |  |  |             << " m_volumeFactor: " << settings.m_volumeFactor | 
					
						
							|  |  |  |             << " m_toneFrequency: " << settings.m_toneFrequency | 
					
						
							|  |  |  |             << " m_channelMute: " << settings.m_channelMute | 
					
						
							|  |  |  |             << " m_playLoop: " << settings.m_playLoop | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |             << " m_modAFInput: " << settings.m_modAFInput | 
					
						
							| 
									
										
										
										
											2018-03-29 17:27:03 +02:00
										 |  |  |             << " m_audioDeviceName: " << settings.m_audioDeviceName | 
					
						
							| 
									
										
										
										
											2019-04-20 19:53:16 +02:00
										 |  |  |             << " m_useReverseAPI: " << settings.m_useReverseAPI | 
					
						
							|  |  |  |             << " m_reverseAPIAddress: " << settings.m_reverseAPIAddress | 
					
						
							|  |  |  |             << " m_reverseAPIPort: " << settings.m_reverseAPIPort | 
					
						
							|  |  |  |             << " m_reverseAPIDeviceIndex: " << settings.m_reverseAPIDeviceIndex | 
					
						
							|  |  |  |             << " m_reverseAPIChannelIndex: " << settings.m_reverseAPIChannelIndex | 
					
						
							| 
									
										
										
										
											2017-12-30 00:18:51 +01:00
										 |  |  |             << " force: " << force; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |     QList<QString> reverseAPIKeys; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("inputFrequencyOffset"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((settings.m_fmDeviation != m_settings.m_fmDeviation) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("fmDeviation"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((settings.m_volumeFactor != m_settings.m_volumeFactor) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("volumeFactor"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((settings.m_channelMute != m_settings.m_channelMute) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("channelMute"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((settings.m_playLoop != m_settings.m_playLoop) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("playLoop"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((settings.m_modAFInput != m_settings.m_modAFInput) || force) { | 
					
						
							|  |  |  |         reverseAPIKeys.append("modAFInput"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     if ((settings.m_afBandwidth != m_settings.m_afBandwidth) || force) { | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |         reverseAPIKeys.append("afBandwidth"); | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     if ((settings.m_rfBandwidth != m_settings.m_rfBandwidth) || force) { | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |         reverseAPIKeys.append("rfBandwidth"); | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     if ((settings.m_toneFrequency != m_settings.m_toneFrequency) || force) { | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |         reverseAPIKeys.append("toneFrequency"); | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-21 00:40:55 +01:00
										 |  |  |     if ((settings.m_audioDeviceName != m_settings.m_audioDeviceName) || force) { | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |         reverseAPIKeys.append("audioDeviceName"); | 
					
						
							| 
									
										
										
										
											2018-03-29 17:27:03 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 01:22:55 +01:00
										 |  |  |     if (m_settings.m_streamIndex != settings.m_streamIndex) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (m_deviceAPI->getSampleMIMO()) // change of stream is possible for MIMO devices only
 | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-12-23 23:41:35 +01:00
										 |  |  |             m_deviceAPI->removeChannelSourceAPI(this); | 
					
						
							| 
									
										
										
										
											2019-11-19 01:22:55 +01:00
										 |  |  |             m_deviceAPI->removeChannelSource(this, m_settings.m_streamIndex); | 
					
						
							|  |  |  |             m_deviceAPI->addChannelSource(this, settings.m_streamIndex); | 
					
						
							| 
									
										
										
										
											2019-12-23 23:41:35 +01:00
										 |  |  |             m_deviceAPI->addChannelSourceAPI(this); | 
					
						
							| 
									
										
										
										
											2019-11-19 01:22:55 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         reverseAPIKeys.append("streamIndex"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     WFMModBaseband::MsgConfigureWFMModBaseband *msg = WFMModBaseband::MsgConfigureWFMModBaseband::create(settings, force); | 
					
						
							|  |  |  |     m_basebandSource->getInputMessageQueue()->push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |     if (settings.m_useReverseAPI) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) || | 
					
						
							|  |  |  |                 (m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) || | 
					
						
							|  |  |  |                 (m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) || | 
					
						
							|  |  |  |                 (m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex) || | 
					
						
							|  |  |  |                 (m_settings.m_reverseAPIChannelIndex != settings.m_reverseAPIChannelIndex); | 
					
						
							|  |  |  |         webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-13 13:04:36 +01:00
										 |  |  |     QList<MessageQueue*> *messageQueues = MainCore::instance()->getMessagePipes().getMessageQueues(this, "settings"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (messageQueues) { | 
					
						
							|  |  |  |         sendChannelSettings(messageQueues, reverseAPIKeys, settings, force); | 
					
						
							| 
									
										
										
										
											2020-10-23 00:11:18 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-13 13:44:07 +02:00
										 |  |  |     m_settings = settings; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-12-17 23:15:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | QByteArray WFMMod::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool WFMMod::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgConfigureWFMMod *msg = MsgConfigureWFMMod::create(m_settings, true); | 
					
						
							|  |  |  |         m_inputMessageQueue.push(msg); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_settings.resetToDefaults(); | 
					
						
							|  |  |  |         MsgConfigureWFMMod *msg = MsgConfigureWFMMod::create(m_settings, true); | 
					
						
							|  |  |  |         m_inputMessageQueue.push(msg); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 21:47:27 +02:00
										 |  |  | void WFMMod::sendSampleRateToDemodAnalyzer() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QList<MessageQueue*> *messageQueues = MainCore::instance()->getMessagePipes().getMessageQueues(this, "reportdemod"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (messageQueues) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QList<MessageQueue*>::iterator it = messageQueues->begin(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (; it != messageQueues->end(); ++it) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             MainCore::MsgChannelDemodReport *msg = MainCore::MsgChannelDemodReport::create( | 
					
						
							|  |  |  |                 this, | 
					
						
							|  |  |  |                 getAudioSampleRate() | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |             (*it)->push(msg); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  | int WFMMod::webapiSettingsGet( | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelSettings& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |         QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  |     response.setWfmModSettings(new SWGSDRangel::SWGWFMModSettings()); | 
					
						
							|  |  |  |     response.getWfmModSettings()->init(); | 
					
						
							|  |  |  |     webapiFormatChannelSettings(response, m_settings); | 
					
						
							| 
									
										
										
										
											2019-08-01 23:21:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getWfmModSettings()->getCwKeyer(); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     const CWKeyerSettings& cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); | 
					
						
							| 
									
										
										
										
											2019-08-01 23:21:57 +02:00
										 |  |  |     CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WFMMod::webapiSettingsPutPatch( | 
					
						
							|  |  |  |                 bool force, | 
					
						
							|  |  |  |                 const QStringList& channelSettingsKeys, | 
					
						
							|  |  |  |                 SWGSDRangel::SWGChannelSettings& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |                 QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2018-08-08 09:17:25 +02:00
										 |  |  |     WFMModSettings settings = m_settings; | 
					
						
							| 
									
										
										
										
											2019-08-01 23:21:57 +02:00
										 |  |  |     webapiUpdateChannelSettings(settings, channelSettingsKeys, response); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("cwKeyer")) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getWfmModSettings()->getCwKeyer(); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |         CWKeyerSettings cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); | 
					
						
							| 
									
										
										
										
											2019-08-01 23:21:57 +02:00
										 |  |  |         CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, cwKeyerSettings, apiCwKeyerSettings); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         CWKeyer::MsgConfigureCWKeyer *msgCwKeyer = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |         m_basebandSource->getCWKeyer().getInputMessageQueue()->push(msgCwKeyer); | 
					
						
							| 
									
										
										
										
											2019-08-01 23:21:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (m_guiMessageQueue) // forward to GUI if any
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             CWKeyer::MsgConfigureCWKeyer *msgCwKeyerToGUI = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force); | 
					
						
							|  |  |  |             m_guiMessageQueue->push(msgCwKeyerToGUI); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MsgConfigureWFMMod *msg = MsgConfigureWFMMod::create(settings, force); | 
					
						
							|  |  |  |     m_inputMessageQueue.push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_guiMessageQueue) // forward to GUI if any
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgConfigureWFMMod *msgToGUI = MsgConfigureWFMMod::create(settings, force); | 
					
						
							|  |  |  |         m_guiMessageQueue->push(msgToGUI); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     webapiFormatChannelSettings(response, settings); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-01 23:21:57 +02:00
										 |  |  | void WFMMod::webapiUpdateChannelSettings( | 
					
						
							|  |  |  |         WFMModSettings& settings, | 
					
						
							|  |  |  |         const QStringList& channelSettingsKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelSettings& response) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  |     if (channelSettingsKeys.contains("channelMute")) { | 
					
						
							|  |  |  |         settings.m_channelMute = response.getWfmModSettings()->getChannelMute() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-01 23:21:57 +02:00
										 |  |  |     if (channelSettingsKeys.contains("inputFrequencyOffset")) { | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  |         settings.m_inputFrequencyOffset = response.getWfmModSettings()->getInputFrequencyOffset(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("modAFInput")) { | 
					
						
							|  |  |  |         settings.m_modAFInput = (WFMModSettings::WFMModInputAF) response.getWfmModSettings()->getModAfInput(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("playLoop")) { | 
					
						
							|  |  |  |         settings.m_playLoop = response.getWfmModSettings()->getPlayLoop() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("rfBandwidth")) { | 
					
						
							|  |  |  |         settings.m_rfBandwidth = response.getWfmModSettings()->getRfBandwidth(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("afBandwidth")) { | 
					
						
							|  |  |  |         settings.m_afBandwidth = response.getWfmModSettings()->getAfBandwidth(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("rgbColor")) { | 
					
						
							|  |  |  |         settings.m_rgbColor = response.getWfmModSettings()->getRgbColor(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("title")) { | 
					
						
							|  |  |  |         settings.m_title = *response.getWfmModSettings()->getTitle(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("toneFrequency")) { | 
					
						
							|  |  |  |         settings.m_toneFrequency = response.getWfmModSettings()->getToneFrequency(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("volumeFactor")) { | 
					
						
							|  |  |  |         settings.m_volumeFactor = response.getWfmModSettings()->getVolumeFactor(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("fmDeviation")) { | 
					
						
							|  |  |  |         settings.m_fmDeviation = response.getWfmModSettings()->getFmDeviation(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-17 11:09:07 +01:00
										 |  |  |     if (channelSettingsKeys.contains("streamIndex")) { | 
					
						
							|  |  |  |         settings.m_streamIndex = response.getWfmModSettings()->getStreamIndex(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-20 19:53:16 +02:00
										 |  |  |     if (channelSettingsKeys.contains("useReverseAPI")) { | 
					
						
							|  |  |  |         settings.m_useReverseAPI = response.getWfmModSettings()->getUseReverseApi() != 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("reverseAPIAddress")) { | 
					
						
							|  |  |  |         settings.m_reverseAPIAddress = *response.getWfmModSettings()->getReverseApiAddress(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("reverseAPIPort")) { | 
					
						
							|  |  |  |         settings.m_reverseAPIPort = response.getWfmModSettings()->getReverseApiPort(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) { | 
					
						
							|  |  |  |         settings.m_reverseAPIDeviceIndex = response.getWfmModSettings()->getReverseApiDeviceIndex(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("reverseAPIChannelIndex")) { | 
					
						
							|  |  |  |         settings.m_reverseAPIChannelIndex = response.getWfmModSettings()->getReverseApiChannelIndex(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WFMMod::webapiReportGet( | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelReport& response, | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |         QString& errorMessage) | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-13 08:51:14 +01:00
										 |  |  |     (void) errorMessage; | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  |     response.setWfmModReport(new SWGSDRangel::SWGWFMModReport()); | 
					
						
							|  |  |  |     response.getWfmModReport()->init(); | 
					
						
							|  |  |  |     webapiFormatChannelReport(response); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WFMMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const WFMModSettings& settings) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     response.getWfmModSettings()->setChannelMute(settings.m_channelMute ? 1 : 0); | 
					
						
							|  |  |  |     response.getWfmModSettings()->setInputFrequencyOffset(settings.m_inputFrequencyOffset); | 
					
						
							|  |  |  |     response.getWfmModSettings()->setModAfInput((int) settings.m_modAFInput); | 
					
						
							|  |  |  |     response.getWfmModSettings()->setPlayLoop(settings.m_playLoop ? 1 : 0); | 
					
						
							|  |  |  |     response.getWfmModSettings()->setRfBandwidth(settings.m_rfBandwidth); | 
					
						
							|  |  |  |     response.getWfmModSettings()->setAfBandwidth(settings.m_afBandwidth); | 
					
						
							|  |  |  |     response.getWfmModSettings()->setFmDeviation(settings.m_fmDeviation); | 
					
						
							|  |  |  |     response.getWfmModSettings()->setRgbColor(settings.m_rgbColor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (response.getWfmModSettings()->getTitle()) { | 
					
						
							|  |  |  |         *response.getWfmModSettings()->getTitle() = settings.m_title; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.getWfmModSettings()->setTitle(new QString(settings.m_title)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.getWfmModSettings()->setToneFrequency(settings.m_toneFrequency); | 
					
						
							|  |  |  |     response.getWfmModSettings()->setVolumeFactor(settings.m_volumeFactor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!response.getWfmModSettings()->getCwKeyer()) { | 
					
						
							|  |  |  |         response.getWfmModSettings()->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (response.getWfmModSettings()->getAudioDeviceName()) { | 
					
						
							|  |  |  |         *response.getWfmModSettings()->getAudioDeviceName() = settings.m_audioDeviceName; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.getWfmModSettings()->setAudioDeviceName(new QString(settings.m_audioDeviceName)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-20 19:53:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.getWfmModSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (response.getWfmModSettings()->getReverseApiAddress()) { | 
					
						
							|  |  |  |         *response.getWfmModSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.getWfmModSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.getWfmModSettings()->setReverseApiPort(settings.m_reverseAPIPort); | 
					
						
							|  |  |  |     response.getWfmModSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  |     response.getWfmModSettings()->setReverseApiChannelIndex(settings.m_reverseAPIChannelIndex); | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WFMMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     response.getWfmModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq())); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     response.getWfmModReport()->setAudioSampleRate(m_basebandSource->getAudioSampleRate()); | 
					
						
							|  |  |  |     response.getWfmModReport()->setChannelSampleRate(m_basebandSource->getChannelSampleRate()); | 
					
						
							| 
									
										
										
										
											2018-04-09 00:37:17 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  | void WFMMod::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const WFMModSettings& settings, bool force) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); | 
					
						
							| 
									
										
										
										
											2020-10-23 00:11:18 +02:00
										 |  |  |     webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIAddress) | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIPort) | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIDeviceIndex) | 
					
						
							|  |  |  |             .arg(settings.m_reverseAPIChannelIndex); | 
					
						
							|  |  |  |     m_networkRequest.setUrl(QUrl(channelSettingsURL)); | 
					
						
							|  |  |  |     m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QBuffer *buffer = new QBuffer(); | 
					
						
							|  |  |  |     buffer->open((QBuffer::ReadWrite)); | 
					
						
							|  |  |  |     buffer->write(swgChannelSettings->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 swgChannelSettings; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WFMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); | 
					
						
							|  |  |  |     swgChannelSettings->setDirection(1); // single source (Tx)
 | 
					
						
							|  |  |  |     swgChannelSettings->setChannelType(new QString("WFMMod")); | 
					
						
							|  |  |  |     swgChannelSettings->setWfmModSettings(new SWGSDRangel::SWGWFMModSettings()); | 
					
						
							|  |  |  |     SWGSDRangel::SWGWFMModSettings *swgWFMModSettings = swgChannelSettings->getWfmModSettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     swgWFMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); | 
					
						
							|  |  |  |     SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgWFMModSettings->getCwKeyer(); | 
					
						
							|  |  |  |     m_basebandSource->getCWKeyer().webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") | 
					
						
							|  |  |  |             .arg(m_settings.m_reverseAPIAddress) | 
					
						
							|  |  |  |             .arg(m_settings.m_reverseAPIPort) | 
					
						
							|  |  |  |             .arg(m_settings.m_reverseAPIDeviceIndex) | 
					
						
							|  |  |  |             .arg(m_settings.m_reverseAPIChannelIndex); | 
					
						
							|  |  |  |     m_networkRequest.setUrl(QUrl(channelSettingsURL)); | 
					
						
							|  |  |  |     m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QBuffer *buffer = new QBuffer(); | 
					
						
							|  |  |  |     buffer->open((QBuffer::ReadWrite)); | 
					
						
							|  |  |  |     buffer->write(swgChannelSettings->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 swgChannelSettings; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-13 13:04:36 +01:00
										 |  |  | void WFMMod::sendChannelSettings( | 
					
						
							|  |  |  |     QList<MessageQueue*> *messageQueues, | 
					
						
							|  |  |  |     QList<QString>& channelSettingsKeys, | 
					
						
							|  |  |  |     const WFMModSettings& settings, | 
					
						
							|  |  |  |     bool force) | 
					
						
							| 
									
										
										
										
											2020-10-23 00:11:18 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-12-13 13:04:36 +01:00
										 |  |  |     QList<MessageQueue*>::iterator it = messageQueues->begin(); | 
					
						
							| 
									
										
										
										
											2020-10-23 00:11:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-13 13:04:36 +01:00
										 |  |  |     for (; it != messageQueues->end(); ++it) | 
					
						
							| 
									
										
										
										
											2020-10-23 00:11:18 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-12-13 13:04:36 +01:00
										 |  |  |         SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); | 
					
						
							|  |  |  |         webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); | 
					
						
							|  |  |  |         MainCore::MsgChannelSettings *msg = MainCore::MsgChannelSettings::create( | 
					
						
							|  |  |  |             this, | 
					
						
							|  |  |  |             channelSettingsKeys, | 
					
						
							|  |  |  |             swgChannelSettings, | 
					
						
							|  |  |  |             force | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         (*it)->push(msg); | 
					
						
							| 
									
										
										
										
											2020-10-23 00:11:18 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WFMMod::webapiFormatChannelSettings( | 
					
						
							|  |  |  |         QList<QString>& channelSettingsKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelSettings *swgChannelSettings, | 
					
						
							|  |  |  |         const WFMModSettings& settings, | 
					
						
							|  |  |  |         bool force | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |     swgChannelSettings->setDirection(1); // single source (Tx)
 | 
					
						
							| 
									
										
										
										
											2019-03-25 13:57:59 +01:00
										 |  |  |     swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet()); | 
					
						
							|  |  |  |     swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex()); | 
					
						
							| 
									
										
										
										
											2020-10-23 00:11:18 +02:00
										 |  |  |     swgChannelSettings->setChannelType(new QString(m_channelId)); | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |     swgChannelSettings->setWfmModSettings(new SWGSDRangel::SWGWFMModSettings()); | 
					
						
							|  |  |  |     SWGSDRangel::SWGWFMModSettings *swgWFMModSettings = swgChannelSettings->getWfmModSettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // transfer data that has been modified. When force is on transfer all data except reverse API data
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("channelMute") || force) { | 
					
						
							|  |  |  |         swgWFMModSettings->setChannelMute(settings.m_channelMute ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("inputFrequencyOffset") || force) { | 
					
						
							|  |  |  |         swgWFMModSettings->setInputFrequencyOffset(settings.m_inputFrequencyOffset); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("modAFInput") || force) { | 
					
						
							|  |  |  |         swgWFMModSettings->setModAfInput((int) settings.m_modAFInput); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("playLoop") || force) { | 
					
						
							|  |  |  |         swgWFMModSettings->setPlayLoop(settings.m_playLoop ? 1 : 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("rfBandwidth") || force) { | 
					
						
							|  |  |  |         swgWFMModSettings->setRfBandwidth(settings.m_rfBandwidth); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("afBandwidth") || force) { | 
					
						
							|  |  |  |         swgWFMModSettings->setAfBandwidth(settings.m_afBandwidth); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("rgbColor") || force) { | 
					
						
							|  |  |  |         swgWFMModSettings->setRgbColor(settings.m_rgbColor); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("title") || force) { | 
					
						
							|  |  |  |         swgWFMModSettings->setTitle(new QString(settings.m_title)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("toneFrequency") || force) { | 
					
						
							|  |  |  |         swgWFMModSettings->setToneFrequency(settings.m_toneFrequency); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("volumeFactor") || force) { | 
					
						
							|  |  |  |         swgWFMModSettings->setVolumeFactor(settings.m_volumeFactor); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (channelSettingsKeys.contains("fmDeviation")) { | 
					
						
							|  |  |  |         swgWFMModSettings->setFmDeviation(settings.m_fmDeviation); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-17 11:09:07 +01:00
										 |  |  |     if (channelSettingsKeys.contains("streamIndex")) { | 
					
						
							|  |  |  |         swgWFMModSettings->setStreamIndex(settings.m_streamIndex); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |     if (channelSettingsKeys.contains("audioDeviceName") || force) { | 
					
						
							|  |  |  |         swgWFMModSettings->setAudioDeviceName(new QString(settings.m_audioDeviceName)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (force) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |         const CWKeyerSettings& cwKeyerSettings = m_basebandSource->getCWKeyer().getSettings(); | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |         swgWFMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings()); | 
					
						
							|  |  |  |         SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgWFMModSettings->getCwKeyer(); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |         m_basebandSource->getCWKeyer().webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WFMMod::networkManagerFinished(QNetworkReply *reply) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QNetworkReply::NetworkError replyError = reply->error(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (replyError) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qWarning() << "WFMMod::networkManagerFinished:" | 
					
						
							|  |  |  |                 << " error(" << (int) replyError | 
					
						
							|  |  |  |                 << "): " << replyError | 
					
						
							|  |  |  |                 << ": " << reply->errorString(); | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString answer = reply->readAll(); | 
					
						
							|  |  |  |         answer.chop(1); // remove last \n
 | 
					
						
							|  |  |  |         qDebug("WFMMod::networkManagerFinished: reply:\n%s", answer.toStdString().c_str()); | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     reply->deleteLater(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double WFMMod::getMagSq() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_basebandSource->getMagSq(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CWKeyer *WFMMod::getCWKeyer() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return &m_basebandSource->getCWKeyer(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WFMMod::setLevelMeter(QObject *levelMeter) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     connect(m_basebandSource, SIGNAL(levelChanged(qreal, qreal, int)), levelMeter, SLOT(levelChanged(qreal, qreal, int))); | 
					
						
							| 
									
										
										
										
											2018-12-21 16:25:22 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-11-17 11:09:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | uint32_t WFMMod::getNumberOfDeviceStreams() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_deviceAPI->getNbSinkStreams(); | 
					
						
							| 
									
										
										
										
											2020-08-02 10:11:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WFMMod::getAudioSampleRate() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_basebandSource->getAudioSampleRate(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WFMMod::getFeedbackAudioSampleRate() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_basebandSource->getFeedbackAudioSampleRate(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-06-29 21:47:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void WFMMod::handleChannelMessages() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Message* message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while ((message = m_channelMessageQueue.pop()) != nullptr) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (handleMessage(*message)) { | 
					
						
							|  |  |  | 			delete message; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |