| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2015 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                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "util/simpleserializer.h"
 | 
					
						
							|  |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							|  |  |  | #include "dsp/dspengine.h"
 | 
					
						
							|  |  |  | #include "sdrdaemongui.h"
 | 
					
						
							|  |  |  | #include "sdrdaemoninput.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-02 10:30:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:17:55 +02:00
										 |  |  | #include <device/devicesourceapi.h>
 | 
					
						
							| 
									
										
										
										
											2016-10-02 10:30:58 +02:00
										 |  |  | #include <dsp/filerecord.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-17 02:22:05 +01:00
										 |  |  | #include "sdrdaemonudphandler.h"
 | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-01 08:24:14 +01:00
										 |  |  | MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgConfigureSDRdaemonUDPLink, Message) | 
					
						
							| 
									
										
										
										
											2016-02-17 23:47:03 +01:00
										 |  |  | MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgConfigureSDRdaemonAutoCorr, Message) | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgConfigureSDRdaemonWork, Message) | 
					
						
							| 
									
										
										
										
											2016-03-18 14:03:34 +01:00
										 |  |  | MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgConfigureSDRdaemonAutoFollowPolicy, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgConfigureSDRdaemonResetIndexes, Message) | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgConfigureSDRdaemonStreamTiming, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgReportSDRdaemonAcquisition, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgReportSDRdaemonStreamData, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgReportSDRdaemonStreamTiming, Message) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:17:55 +02:00
										 |  |  | SDRdaemonInput::SDRdaemonInput(const QTimer& masterTimer, DeviceSourceAPI *deviceAPI) : | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |     m_deviceAPI(deviceAPI), | 
					
						
							| 
									
										
										
										
											2016-02-01 08:24:14 +01:00
										 |  |  | 	m_address("127.0.0.1"), | 
					
						
							|  |  |  | 	m_port(9090), | 
					
						
							| 
									
										
										
										
											2016-02-17 02:22:05 +01:00
										 |  |  | 	m_SDRdaemonUDPHandler(0), | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | 	m_deviceDescription(), | 
					
						
							|  |  |  | 	m_sampleRate(0), | 
					
						
							|  |  |  | 	m_centerFrequency(0), | 
					
						
							|  |  |  | 	m_startingTimeStamp(0), | 
					
						
							| 
									
										
										
										
											2016-03-18 14:03:34 +01:00
										 |  |  |     m_masterTimer(masterTimer), | 
					
						
							|  |  |  |     m_autoFollowRate(false), | 
					
						
							|  |  |  |     m_autoCorrBuffer(false) | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-02-17 02:22:05 +01:00
										 |  |  | 	m_sampleFifo.setSize(96000 * 4); | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  | 	m_SDRdaemonUDPHandler = new SDRdaemonUDPHandler(&m_sampleFifo, getOutputMessageQueueToGUI(), m_deviceAPI); | 
					
						
							| 
									
										
										
										
											2016-02-20 23:02:34 +01:00
										 |  |  | 	m_SDRdaemonUDPHandler->connectTimer(&m_masterTimer); | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SDRdaemonInput::~SDRdaemonInput() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	stop(); | 
					
						
							| 
									
										
										
										
											2016-02-17 02:22:05 +01:00
										 |  |  | 	delete m_SDRdaemonUDPHandler; | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 03:40:45 +02:00
										 |  |  | bool SDRdaemonInput::start() | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-02-17 02:22:05 +01:00
										 |  |  | 	qDebug() << "SDRdaemonInput::start"; | 
					
						
							|  |  |  | 	MsgConfigureSDRdaemonWork *command = MsgConfigureSDRdaemonWork::create(true); | 
					
						
							|  |  |  | 	getInputMessageQueue()->push(command); | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SDRdaemonInput::stop() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	qDebug() << "SDRdaemonInput::stop"; | 
					
						
							| 
									
										
										
										
											2016-02-17 02:22:05 +01:00
										 |  |  | 	MsgConfigureSDRdaemonWork *command = MsgConfigureSDRdaemonWork::create(false); | 
					
						
							|  |  |  | 	getInputMessageQueue()->push(command); | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const QString& SDRdaemonInput::getDeviceDescription() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_deviceDescription; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int SDRdaemonInput::getSampleRate() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_sampleRate; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | quint64 SDRdaemonInput::getCenterFrequency() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_centerFrequency; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | std::time_t SDRdaemonInput::getStartingTimeStamp() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_startingTimeStamp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-26 21:40:54 +01:00
										 |  |  | void SDRdaemonInput::getRemoteAddress(QString &s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (m_SDRdaemonUDPHandler) { | 
					
						
							|  |  |  | 		m_SDRdaemonUDPHandler->getRemoteAddress(s); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | bool SDRdaemonInput::handleMessage(const Message& message) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-02-01 08:24:14 +01:00
										 |  |  | 	if (MsgConfigureSDRdaemonUDPLink::match(message)) | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-02-20 23:02:34 +01:00
										 |  |  | 		MsgConfigureSDRdaemonUDPLink& conf = (MsgConfigureSDRdaemonUDPLink&) message; | 
					
						
							|  |  |  | 		m_SDRdaemonUDPHandler->configureUDPLink(conf.getAddress(), conf.getPort()); | 
					
						
							| 
									
										
										
										
											2016-02-17 23:47:03 +01:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (MsgConfigureSDRdaemonAutoCorr::match(message)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		MsgConfigureSDRdaemonAutoCorr& conf = (MsgConfigureSDRdaemonAutoCorr&) message; | 
					
						
							|  |  |  | 		bool dcBlock = conf.getDCBlock(); | 
					
						
							|  |  |  | 		bool iqImbalance = conf.getIQImbalance(); | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  | 		m_deviceAPI->configureCorrections(dcBlock, iqImbalance); | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-18 14:03:34 +01:00
										 |  |  |     else if (MsgConfigureSDRdaemonAutoFollowPolicy::match(message)) | 
					
						
							| 
									
										
										
										
											2016-03-11 05:25:25 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-03-18 14:03:34 +01:00
										 |  |  |         MsgConfigureSDRdaemonAutoFollowPolicy& conf = (MsgConfigureSDRdaemonAutoFollowPolicy&) message; | 
					
						
							| 
									
										
										
										
											2016-03-11 05:25:25 +01:00
										 |  |  | 		bool autoFollowRate = conf.autoFollowRate(); | 
					
						
							| 
									
										
										
										
											2016-03-18 14:03:34 +01:00
										 |  |  |         bool autoCorrBuffer = conf.autoCorrBuffer(); | 
					
						
							|  |  |  |         if (autoFollowRate != m_autoFollowRate) { | 
					
						
							|  |  |  |             m_SDRdaemonUDPHandler->setAutoFollowRate(autoFollowRate); | 
					
						
							|  |  |  |             m_autoFollowRate = autoFollowRate; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (autoCorrBuffer != m_autoCorrBuffer) { | 
					
						
							|  |  |  |             m_SDRdaemonUDPHandler->setAutoCorrBuffer(autoCorrBuffer); | 
					
						
							|  |  |  |             m_autoCorrBuffer = autoCorrBuffer; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-11 05:25:25 +01:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-18 14:03:34 +01:00
										 |  |  |     else if (MsgConfigureSDRdaemonResetIndexes::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_SDRdaemonUDPHandler->resetIndexes(); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | 	else if (MsgConfigureSDRdaemonWork::match(message)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		MsgConfigureSDRdaemonWork& conf = (MsgConfigureSDRdaemonWork&) message; | 
					
						
							|  |  |  | 		bool working = conf.isWorking(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-17 02:22:05 +01:00
										 |  |  | 		if (working) { | 
					
						
							|  |  |  | 			m_SDRdaemonUDPHandler->start(); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			m_SDRdaemonUDPHandler->stop(); | 
					
						
							| 
									
										
										
										
											2016-01-24 19:21:21 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (MsgConfigureSDRdaemonStreamTiming::match(message)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |