mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-31 13:00:26 -04:00 
			
		
		
		
	TCP source: use settings in source
This commit is contained in:
		
							parent
							
								
									8cc0f53635
								
							
						
					
					
						commit
						9c1d2e43b1
					
				| @ -21,7 +21,8 @@ | ||||
| #include <QTcpSocket> | ||||
| #include "tcpsrcgui.h" | ||||
| 
 | ||||
| MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcConfigure, Message) | ||||
| MESSAGE_CLASS_DEFINITION(TCPSrc::MsgConfigureTCPSrc, Message) | ||||
| MESSAGE_CLASS_DEFINITION(TCPSrc::MsgConfigureChannelizer, Message) | ||||
| MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcConnection, Message) | ||||
| MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcSpectrum, Message) | ||||
| 
 | ||||
| @ -49,7 +50,7 @@ TCPSrc::TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, BasebandSampl | ||||
| 	m_last = 0; | ||||
| 	m_this = 0; | ||||
| 	m_scale = 0; | ||||
| 	m_boost = 0; | ||||
| 	m_volume = 0; | ||||
| 	m_magsq = 0; | ||||
| 	m_sampleBufferSSB.resize(tcpFftLen); | ||||
| 	TCPFilter = new fftfilt(0.3 / 48.0, 16.0 / 48.0, tcpFftLen); | ||||
| @ -61,12 +62,6 @@ TCPSrc::~TCPSrc() | ||||
| 	if (TCPFilter) delete TCPFilter; | ||||
| } | ||||
| 
 | ||||
| void TCPSrc::configure(MessageQueue* messageQueue, TCPSrcSettings::SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost) | ||||
| { | ||||
| 	Message* cmd = MsgTCPSrcConfigure::create(sampleFormat, outputSampleRate, rfBandwidth, tcpPort, boost); | ||||
| 	messageQueue->push(cmd); | ||||
| } | ||||
| 
 | ||||
| void TCPSrc::setSpectrum(MessageQueue* messageQueue, bool enabled) | ||||
| { | ||||
| 	Message* cmd = MsgTCPSrcSpectrum::create(enabled); | ||||
| @ -85,7 +80,7 @@ void TCPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector: | ||||
| 
 | ||||
| 	// Rtl-Sdr uses full 16-bit scale; FCDPP does not
 | ||||
| 	//int rescale = 32768 * (1 << m_boost);
 | ||||
| 	int rescale = (1 << m_boost); | ||||
| 	int rescale = (1 << m_volume); | ||||
| 
 | ||||
| 	for(SampleVector::const_iterator it = begin; it < end; ++it) { | ||||
| 		//Complex c(it->real() / 32768.0f, it->imag() / 32768.0f);
 | ||||
| @ -199,50 +194,59 @@ bool TCPSrc::handleMessage(const Message& cmd) | ||||
| 
 | ||||
| 		return true; | ||||
| 	} | ||||
| 	else if (MsgTCPSrcConfigure::match(cmd)) | ||||
| 	{ | ||||
| 		MsgTCPSrcConfigure& cfg = (MsgTCPSrcConfigure&) cmd; | ||||
|     else if (MsgConfigureTCPSrc::match(cmd)) | ||||
|     { | ||||
|         MsgConfigureTCPSrc& cfg = (MsgConfigureTCPSrc&) cmd; | ||||
| 
 | ||||
| 		m_settingsMutex.lock(); | ||||
|         TCPSrcSettings settings = cfg.getSettings(); | ||||
| 
 | ||||
| 		m_sampleFormat = cfg.getSampleFormat(); | ||||
| 		m_outputSampleRate = cfg.getOutputSampleRate(); | ||||
| 		m_rfBandwidth = cfg.getRFBandwidth(); | ||||
|         // These settings are set with DownChannelizer::MsgChannelizerNotification
 | ||||
|         settings.m_inputSampleRate = m_settings.m_inputSampleRate; | ||||
|         settings.m_inputFrequencyOffset = m_settings.m_inputFrequencyOffset; | ||||
| 
 | ||||
| 		if (cfg.getTCPPort() != m_tcpPort) | ||||
| 		{ | ||||
| 			m_tcpPort = cfg.getTCPPort(); | ||||
|         m_settingsMutex.lock(); | ||||
| 
 | ||||
| 			if(m_tcpServer->isListening()) | ||||
| 			{ | ||||
| 				m_tcpServer->close(); | ||||
| 			} | ||||
|         m_sampleFormat = settings.m_sampleFormat; | ||||
|         m_outputSampleRate = settings.m_outputSampleRate; | ||||
|         m_rfBandwidth = settings.m_rfBandwidth; | ||||
| 
 | ||||
| 			m_tcpServer->listen(QHostAddress::Any, m_tcpPort); | ||||
| 		} | ||||
|         if (settings.m_tcpPort != m_tcpPort) | ||||
|         { | ||||
|             m_tcpPort = settings.m_tcpPort; | ||||
| 
 | ||||
| 		m_boost = cfg.getBoost(); | ||||
| 		m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0); | ||||
| 		m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate; | ||||
|             if(m_tcpServer->isListening()) | ||||
|             { | ||||
|                 m_tcpServer->close(); | ||||
|             } | ||||
| 
 | ||||
| 		if (m_sampleFormat == TCPSrcSettings::FormatSSB) | ||||
| 		{ | ||||
| 			TCPFilter->create_filter(0.3 / 48.0, m_rfBandwidth / 2.0 / m_outputSampleRate); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			TCPFilter->create_filter(0.0, m_rfBandwidth / 2.0 / m_outputSampleRate); | ||||
| 		} | ||||
|             m_tcpServer->listen(QHostAddress::Any, m_tcpPort); | ||||
|         } | ||||
| 
 | ||||
| 		m_settingsMutex.unlock(); | ||||
|         m_volume = settings.m_volume; | ||||
|         m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0); | ||||
|         m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate; | ||||
| 
 | ||||
| 		qDebug() << "  - MsgTCPSrcConfigure: m_sampleFormat: " << m_sampleFormat | ||||
| 				<< " m_outputSampleRate: " << m_outputSampleRate | ||||
| 				<< " m_rfBandwidth: " << m_rfBandwidth | ||||
| 				<< " m_boost: " << m_boost; | ||||
|         if (m_sampleFormat == TCPSrcSettings::FormatSSB) | ||||
|         { | ||||
|             TCPFilter->create_filter(0.3 / 48.0, m_rfBandwidth / 2.0 / m_outputSampleRate); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             TCPFilter->create_filter(0.0, m_rfBandwidth / 2.0 / m_outputSampleRate); | ||||
|         } | ||||
| 
 | ||||
| 		return true; | ||||
| 	} | ||||
|         m_settingsMutex.unlock(); | ||||
| 
 | ||||
|         qDebug() << "MsgConfigureTCPSrc::handleMessage: MsgConfigureTCPSrc:" | ||||
|                 << " m_sampleFormat: " << m_sampleFormat | ||||
|                 << " m_outputSampleRate: " << m_outputSampleRate | ||||
|                 << " m_rfBandwidth: " << m_rfBandwidth | ||||
|                 << " m_volume: " << m_volume; | ||||
| 
 | ||||
|         m_settings = settings; | ||||
| 
 | ||||
|         return true; | ||||
|     } | ||||
| 	else if (MsgTCPSrcSpectrum::match(cmd)) | ||||
| 	{ | ||||
| 		MsgTCPSrcSpectrum& spc = (MsgTCPSrcSpectrum&) cmd; | ||||
|  | ||||
| @ -22,10 +22,56 @@ class TCPSrc : public BasebandSampleSink { | ||||
| 	Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|     class MsgConfigureTCPSrc : public Message { | ||||
|         MESSAGE_CLASS_DECLARATION | ||||
| 
 | ||||
|     public: | ||||
|         const TCPSrcSettings& getSettings() const { return m_settings; } | ||||
|         bool getForce() const { return m_force; } | ||||
| 
 | ||||
|         static MsgConfigureTCPSrc* create(const TCPSrcSettings& settings, bool force) | ||||
|         { | ||||
|             return new MsgConfigureTCPSrc(settings, force); | ||||
|         } | ||||
| 
 | ||||
|     private: | ||||
|         TCPSrcSettings m_settings; | ||||
|         bool m_force; | ||||
| 
 | ||||
|         MsgConfigureTCPSrc(const TCPSrcSettings& settings, bool force) : | ||||
|             Message(), | ||||
|             m_settings(settings), | ||||
|             m_force(force) | ||||
|         { | ||||
|         } | ||||
|     }; | ||||
| 
 | ||||
|     class MsgConfigureChannelizer : public Message { | ||||
|         MESSAGE_CLASS_DECLARATION | ||||
| 
 | ||||
|     public: | ||||
|         int getSampleRate() const { return m_sampleRate; } | ||||
|         int getCenterFrequency() const { return m_centerFrequency; } | ||||
| 
 | ||||
|         static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency) | ||||
|         { | ||||
|             return new MsgConfigureChannelizer(sampleRate, centerFrequency); | ||||
|         } | ||||
| 
 | ||||
|     private: | ||||
|         int m_sampleRate; | ||||
|         int  m_centerFrequency; | ||||
| 
 | ||||
|         MsgConfigureChannelizer(int sampleRate, int centerFrequency) : | ||||
|             Message(), | ||||
|             m_sampleRate(sampleRate), | ||||
|             m_centerFrequency(centerFrequency) | ||||
|         { } | ||||
|     }; | ||||
| 
 | ||||
| 	TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, BasebandSampleSink* spectrum); | ||||
| 	virtual ~TCPSrc(); | ||||
| 
 | ||||
| 	void configure(MessageQueue* messageQueue, TCPSrcSettings::SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost); | ||||
| 	void setSpectrum(MessageQueue* messageQueue, bool enabled); | ||||
| 	double getMagSq() const { return m_magsq; } | ||||
| 
 | ||||
| @ -64,37 +110,6 @@ public: | ||||
| 	}; | ||||
| 
 | ||||
| protected: | ||||
| 	class MsgTCPSrcConfigure : public Message { | ||||
| 		MESSAGE_CLASS_DECLARATION | ||||
| 
 | ||||
| 	public: | ||||
| 		TCPSrcSettings::SampleFormat getSampleFormat() const { return m_sampleFormat; } | ||||
| 		Real getOutputSampleRate() const { return m_outputSampleRate; } | ||||
| 		Real getRFBandwidth() const { return m_rfBandwidth; } | ||||
| 		int getTCPPort() const { return m_tcpPort; } | ||||
| 		int getBoost() const { return m_boost; } | ||||
| 
 | ||||
| 		static MsgTCPSrcConfigure* create(TCPSrcSettings::SampleFormat sampleFormat, Real sampleRate, Real rfBandwidth, int tcpPort, int boost) | ||||
| 		{ | ||||
| 			return new MsgTCPSrcConfigure(sampleFormat, sampleRate, rfBandwidth, tcpPort, boost); | ||||
| 		} | ||||
| 
 | ||||
| 	private: | ||||
| 		TCPSrcSettings::SampleFormat m_sampleFormat; | ||||
| 		Real m_outputSampleRate; | ||||
| 		Real m_rfBandwidth; | ||||
| 		int m_tcpPort; | ||||
| 		int m_boost; | ||||
| 
 | ||||
| 		MsgTCPSrcConfigure(TCPSrcSettings::SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost) : | ||||
| 			Message(), | ||||
| 			m_sampleFormat(sampleFormat), | ||||
| 			m_outputSampleRate(outputSampleRate), | ||||
| 			m_rfBandwidth(rfBandwidth), | ||||
| 			m_tcpPort(tcpPort), | ||||
| 			m_boost(boost) | ||||
| 		{ } | ||||
| 	}; | ||||
| 	class MsgTCPSrcSpectrum : public Message { | ||||
| 		MESSAGE_CLASS_DECLARATION | ||||
| 
 | ||||
| @ -137,13 +152,15 @@ protected: | ||||
| 	MessageQueue* m_uiMessageQueue; | ||||
| 	TCPSrcGUI* m_tcpSrcGUI; | ||||
| 
 | ||||
| 	int m_inputSampleRate; | ||||
|     TCPSrcSettings m_settings; | ||||
| 
 | ||||
|     int m_inputSampleRate; | ||||
| 
 | ||||
| 	int m_sampleFormat; | ||||
| 	Real m_outputSampleRate; | ||||
| 	Real m_rfBandwidth; | ||||
| 	int m_tcpPort; | ||||
| 	int m_boost; | ||||
| 	int m_volume; | ||||
| 	double m_magsq; | ||||
| 
 | ||||
| 	Real m_scale; | ||||
|  | ||||
| @ -81,65 +81,6 @@ bool TCPSrcGUI::deserialize(const QByteArray& data) | ||||
|         resetToDefaults(); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
| //	SimpleDeserializer d(data);
 | ||||
| //
 | ||||
| //	if (!d.isValid())
 | ||||
| //	{
 | ||||
| //		resetToDefaults();
 | ||||
| //		return false;
 | ||||
| //	}
 | ||||
| //
 | ||||
| //	if (d.getVersion() == 1)
 | ||||
| //	{
 | ||||
| //		QByteArray bytetmp;
 | ||||
| //		qint32 s32tmp;
 | ||||
| //		Real realtmp;
 | ||||
| //
 | ||||
| //		blockApplySettings(true);
 | ||||
| //		m_channelMarker.blockSignals(true);
 | ||||
| //
 | ||||
| //		d.readS32(2, &s32tmp, 0);
 | ||||
| //		m_channelMarker.setCenterFrequency(s32tmp);
 | ||||
| //		d.readS32(3, &s32tmp, TCPSrcSettings::FormatSSB);
 | ||||
| //		switch(s32tmp) {
 | ||||
| //			case TCPSrcSettings::FormatSSB:
 | ||||
| //				ui->sampleFormat->setCurrentIndex(0);
 | ||||
| //				break;
 | ||||
| //			case TCPSrcSettings::FormatNFM:
 | ||||
| //				ui->sampleFormat->setCurrentIndex(1);
 | ||||
| //				break;
 | ||||
| //			case TCPSrcSettings::FormatS16LE:
 | ||||
| //				ui->sampleFormat->setCurrentIndex(2);
 | ||||
| //				break;
 | ||||
| //			default:
 | ||||
| //				ui->sampleFormat->setCurrentIndex(0);
 | ||||
| //				break;
 | ||||
| //		}
 | ||||
| //		d.readReal(4, &realtmp, 48000);
 | ||||
| //		ui->sampleRate->setText(QString("%1").arg(realtmp, 0));
 | ||||
| //		d.readReal(5, &realtmp, 32000);
 | ||||
| //		ui->rfBandwidth->setText(QString("%1").arg(realtmp, 0));
 | ||||
| //		d.readS32(6, &s32tmp, 9999);
 | ||||
| //		ui->tcpPort->setText(QString("%1").arg(s32tmp));
 | ||||
| //		d.readBlob(7, &bytetmp);
 | ||||
| //		ui->spectrumGUI->deserialize(bytetmp);
 | ||||
| //		d.readS32(8, &s32tmp, 1);
 | ||||
| //		ui->volume->setValue(s32tmp);
 | ||||
| //		d.readS32(9, &s32tmp, 0);
 | ||||
| //		m_channelMarker.setCenterFrequency(s32tmp);
 | ||||
| //
 | ||||
| //		blockApplySettings(false);
 | ||||
| //		m_channelMarker.blockSignals(false);
 | ||||
| //
 | ||||
| //		applySettings();
 | ||||
| //		return true;
 | ||||
| //	}
 | ||||
| //	else
 | ||||
| //	{
 | ||||
| //		resetToDefaults();
 | ||||
| //		return false;
 | ||||
| //	}
 | ||||
| } | ||||
| 
 | ||||
| bool TCPSrcGUI::handleMessage(const Message& message) | ||||
| @ -264,12 +205,8 @@ void TCPSrcGUI::applySettings() | ||||
| 			m_settings.m_outputSampleRate, | ||||
| 			m_channelMarker.getCenterFrequency()); | ||||
| 
 | ||||
| 		m_tcpSrc->configure(m_tcpSrc->getInputMessageQueue(), | ||||
| 			m_settings.m_sampleFormat, | ||||
| 			m_settings.m_outputSampleRate, | ||||
| 			m_settings.m_rfBandwidth, | ||||
| 			m_settings.m_tcpPort, | ||||
| 			m_settings.m_volume); | ||||
|         TCPSrc::MsgConfigureTCPSrc* message = TCPSrc::MsgConfigureTCPSrc::create( m_settings, false); | ||||
|         m_tcpSrc->getInputMessageQueue()->push(message); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user