2015-01-09 03:30:26 -05:00
|
|
|
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
|
|
|
// (C) 2015 John Greb //
|
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-05-19 23:48:39 -04:00
|
|
|
#include "tcpsrc.h"
|
2016-10-02 07:18:07 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
#include <QTcpServer>
|
|
|
|
#include <QTcpSocket>
|
2017-10-07 06:55:17 -04:00
|
|
|
|
|
|
|
#include <dsp/downchannelizer.h>
|
|
|
|
#include "dsp/threadedbasebandsamplesink.h"
|
|
|
|
#include <device/devicesourceapi.h>
|
|
|
|
|
2017-05-19 23:48:39 -04:00
|
|
|
#include "tcpsrcgui.h"
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2017-10-07 04:44:58 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(TCPSrc::MsgConfigureTCPSrc, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(TCPSrc::MsgConfigureChannelizer, Message)
|
2014-05-18 11:52:39 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcConnection, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcSpectrum, Message)
|
|
|
|
|
2017-10-07 06:55:17 -04:00
|
|
|
TCPSrc::TCPSrc(DeviceSourceAPI* deviceAPI) :
|
|
|
|
m_deviceAPI(deviceAPI),
|
2015-08-24 17:23:45 -04:00
|
|
|
m_settingsMutex(QMutex::Recursive)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-12 03:03:02 -04:00
|
|
|
setObjectName("TCPSrc");
|
|
|
|
|
2014-12-03 13:41:38 -05:00
|
|
|
m_inputSampleRate = 96000;
|
2017-10-07 04:24:25 -04:00
|
|
|
m_sampleFormat = TCPSrcSettings::FormatSSB;
|
2014-11-25 03:31:44 -05:00
|
|
|
m_outputSampleRate = 48000;
|
2014-12-03 13:41:38 -05:00
|
|
|
m_rfBandwidth = 32000;
|
2017-05-05 04:40:45 -04:00
|
|
|
m_tcpServer = 0;
|
2014-05-18 11:52:39 -04:00
|
|
|
m_tcpPort = 9999;
|
|
|
|
m_nco.setFreq(0, m_inputSampleRate);
|
2015-01-09 03:30:26 -05:00
|
|
|
m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0);
|
2014-05-18 11:52:39 -04:00
|
|
|
m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate;
|
2017-10-07 06:55:17 -04:00
|
|
|
m_spectrum = 0;
|
2014-05-18 11:52:39 -04:00
|
|
|
m_spectrumEnabled = false;
|
2014-12-03 13:41:38 -05:00
|
|
|
m_nextSSBId = 0;
|
2014-05-18 11:52:39 -04:00
|
|
|
m_nextS16leId = 0;
|
2014-12-17 16:06:02 -05:00
|
|
|
|
2014-12-25 07:00:13 -05:00
|
|
|
m_last = 0;
|
|
|
|
m_this = 0;
|
2014-12-31 12:45:01 -05:00
|
|
|
m_scale = 0;
|
2017-10-07 04:44:58 -04:00
|
|
|
m_volume = 0;
|
2015-11-18 00:05:13 -05:00
|
|
|
m_magsq = 0;
|
2017-10-07 06:55:17 -04:00
|
|
|
|
2017-11-05 19:39:44 -05:00
|
|
|
m_sampleBufferSSB.resize(tcpFftLen);
|
|
|
|
TCPFilter = new fftfilt(0.3 / 48.0, 16.0 / 48.0, tcpFftLen);
|
|
|
|
|
2017-10-07 06:55:17 -04:00
|
|
|
m_channelizer = new DownChannelizer(this);
|
|
|
|
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
|
|
|
|
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TCPSrc::~TCPSrc()
|
|
|
|
{
|
2015-01-09 03:30:26 -05:00
|
|
|
if (TCPFilter) delete TCPFilter;
|
2017-10-07 06:55:17 -04:00
|
|
|
|
|
|
|
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
|
|
|
|
delete m_threadedChannelizer;
|
|
|
|
delete m_channelizer;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TCPSrc::setSpectrum(MessageQueue* messageQueue, bool enabled)
|
|
|
|
{
|
|
|
|
Message* cmd = MsgTCPSrcSpectrum::create(enabled);
|
2015-08-17 02:29:34 -04:00
|
|
|
messageQueue->push(cmd);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2015-08-25 02:24:23 -04:00
|
|
|
void TCPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
Complex ci;
|
2015-05-15 05:29:41 -04:00
|
|
|
fftfilt::cmplx* sideband;
|
2014-12-25 07:00:13 -05:00
|
|
|
Real l, r;
|
2014-12-17 16:06:02 -05:00
|
|
|
|
|
|
|
m_sampleBuffer.clear();
|
|
|
|
|
2015-08-24 17:23:45 -04:00
|
|
|
m_settingsMutex.lock();
|
|
|
|
|
2014-12-28 14:04:26 -05:00
|
|
|
// Rtl-Sdr uses full 16-bit scale; FCDPP does not
|
2015-11-18 00:05:13 -05:00
|
|
|
//int rescale = 32768 * (1 << m_boost);
|
2017-10-07 04:44:58 -04:00
|
|
|
int rescale = (1 << m_volume);
|
2014-12-28 14:04:26 -05:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
for(SampleVector::const_iterator it = begin; it < end; ++it) {
|
2015-11-18 00:05:13 -05:00
|
|
|
//Complex c(it->real() / 32768.0f, it->imag() / 32768.0f);
|
|
|
|
Complex c(it->real(), it->imag());
|
2014-05-18 11:52:39 -04:00
|
|
|
c *= m_nco.nextIQ();
|
|
|
|
|
2016-10-09 19:53:32 -04:00
|
|
|
if(m_interpolator.decimate(&m_sampleDistanceRemain, c, &ci))
|
2015-11-18 00:05:13 -05:00
|
|
|
{
|
|
|
|
m_magsq = ((ci.real()*ci.real() + ci.imag()*ci.imag())*rescale*rescale) / (1<<30);
|
2014-12-28 14:04:26 -05:00
|
|
|
m_sampleBuffer.push_back(Sample(ci.real() * rescale, ci.imag() * rescale));
|
2014-05-18 11:52:39 -04:00
|
|
|
m_sampleDistanceRemain += m_inputSampleRate / m_outputSampleRate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 00:05:13 -05:00
|
|
|
if((m_spectrum != 0) && (m_spectrumEnabled))
|
|
|
|
{
|
2014-06-15 04:32:25 -04:00
|
|
|
m_spectrum->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), positiveOnly);
|
2015-11-18 00:05:13 -05:00
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
|
|
|
for(int i = 0; i < m_s16leSockets.count(); i++)
|
2015-11-18 00:05:13 -05:00
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
m_s16leSockets[i].socket->write((const char*)&m_sampleBuffer[0], m_sampleBuffer.size() * 4);
|
2015-11-18 00:05:13 -05:00
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2017-10-07 04:24:25 -04:00
|
|
|
if((m_sampleFormat == TCPSrcSettings::FormatSSB) && (m_ssbSockets.count() > 0)) {
|
2014-05-18 11:52:39 -04:00
|
|
|
for(SampleVector::const_iterator it = m_sampleBuffer.begin(); it != m_sampleBuffer.end(); ++it) {
|
2015-11-18 00:05:13 -05:00
|
|
|
//Complex cj(it->real() / 30000.0, it->imag() / 30000.0);
|
|
|
|
Complex cj(it->real(), it->imag());
|
2014-12-22 15:23:55 -05:00
|
|
|
int n_out = TCPFilter->runSSB(cj, &sideband, true);
|
2014-12-18 14:17:42 -05:00
|
|
|
if (n_out) {
|
|
|
|
for (int i = 0; i < n_out; i+=2) {
|
2015-11-18 00:05:13 -05:00
|
|
|
//l = (sideband[i].real() + sideband[i].imag()) * 0.7 * 32000.0;
|
|
|
|
//r = (sideband[i+1].real() + sideband[i+1].imag()) * 0.7 * 32000.0;
|
|
|
|
l = (sideband[i].real() + sideband[i].imag()) * 0.7;
|
|
|
|
r = (sideband[i+1].real() + sideband[i+1].imag()) * 0.7;
|
2014-12-25 07:00:13 -05:00
|
|
|
m_sampleBufferSSB.push_back(Sample(l, r));
|
2014-12-18 14:17:42 -05:00
|
|
|
}
|
|
|
|
for(int i = 0; i < m_ssbSockets.count(); i++)
|
|
|
|
m_ssbSockets[i].socket->write((const char*)&m_sampleBufferSSB[0], n_out * 2);
|
|
|
|
m_sampleBufferSSB.clear();
|
2014-12-17 16:06:02 -05:00
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
}
|
2014-12-25 07:00:13 -05:00
|
|
|
|
2017-10-07 04:24:25 -04:00
|
|
|
if((m_sampleFormat == TCPSrcSettings::FormatNFM) && (m_ssbSockets.count() > 0)) {
|
2014-12-25 07:00:13 -05:00
|
|
|
for(SampleVector::const_iterator it = m_sampleBuffer.begin(); it != m_sampleBuffer.end(); ++it) {
|
2015-11-18 00:05:13 -05:00
|
|
|
Complex cj(it->real() / 32768.0f, it->imag() / 32768.0f);
|
2014-12-31 12:45:01 -05:00
|
|
|
// An FFT filter here is overkill, but was already set up for SSB
|
2014-12-25 07:00:13 -05:00
|
|
|
int n_out = TCPFilter->runFilt(cj, &sideband);
|
|
|
|
if (n_out) {
|
|
|
|
Real sum = 1.0;
|
|
|
|
for (int i = 0; i < n_out; i+=2) {
|
|
|
|
l = m_this.real() * (m_last.imag() - sideband[i].imag())
|
|
|
|
- m_this.imag() * (m_last.real() - sideband[i].real());
|
|
|
|
m_last = sideband[i];
|
|
|
|
r = m_last.real() * (m_this.imag() - sideband[i+1].imag())
|
|
|
|
- m_last.imag() * (m_this.real() - sideband[i+1].real());
|
|
|
|
m_this = sideband[i+1];
|
|
|
|
m_sampleBufferSSB.push_back(Sample(l * m_scale, r * m_scale));
|
2017-05-05 04:40:45 -04:00
|
|
|
sum += m_this.real() * m_this.real() + m_this.imag() * m_this.imag();
|
2014-12-25 07:00:13 -05:00
|
|
|
}
|
2014-12-31 12:45:01 -05:00
|
|
|
// TODO: correct levels
|
|
|
|
m_scale = 24000 * tcpFftLen / sum;
|
2014-12-25 07:00:13 -05:00
|
|
|
for(int i = 0; i < m_ssbSockets.count(); i++)
|
|
|
|
m_ssbSockets[i].socket->write((const char*)&m_sampleBufferSSB[0], n_out * 2);
|
|
|
|
m_sampleBufferSSB.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-24 17:23:45 -04:00
|
|
|
|
|
|
|
m_settingsMutex.unlock();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TCPSrc::start()
|
|
|
|
{
|
|
|
|
m_tcpServer = new QTcpServer();
|
|
|
|
connect(m_tcpServer, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
|
2015-11-18 21:26:46 -05:00
|
|
|
connect(m_tcpServer, SIGNAL(acceptError(QAbstractSocket::SocketError)), this, SLOT(onTcpServerError(QAbstractSocket::SocketError)));
|
2014-05-18 11:52:39 -04:00
|
|
|
m_tcpServer->listen(QHostAddress::Any, m_tcpPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TCPSrc::stop()
|
|
|
|
{
|
2014-12-03 13:41:38 -05:00
|
|
|
closeAllSockets(&m_ssbSockets);
|
2014-05-18 11:52:39 -04:00
|
|
|
closeAllSockets(&m_s16leSockets);
|
|
|
|
|
|
|
|
if(m_tcpServer->isListening())
|
|
|
|
m_tcpServer->close();
|
|
|
|
delete m_tcpServer;
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
bool TCPSrc::handleMessage(const Message& cmd)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2016-10-02 15:52:39 -04:00
|
|
|
if (DownChannelizer::MsgChannelizerNotification::match(cmd))
|
2015-08-17 02:29:34 -04:00
|
|
|
{
|
2016-10-02 15:52:39 -04:00
|
|
|
DownChannelizer::MsgChannelizerNotification& notif = (DownChannelizer::MsgChannelizerNotification&) cmd;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2015-08-24 17:23:45 -04:00
|
|
|
m_settingsMutex.lock();
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
m_inputSampleRate = notif.getSampleRate();
|
|
|
|
m_nco.setFreq(-notif.getFrequencyOffset(), m_inputSampleRate);
|
2015-01-09 03:30:26 -05:00
|
|
|
m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0);
|
2014-05-18 11:52:39 -04:00
|
|
|
m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2015-08-24 17:23:45 -04:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
|
2015-08-19 16:12:52 -04:00
|
|
|
qDebug() << "TCPSrc::handleMessage: MsgChannelizerNotification: m_inputSampleRate: " << m_inputSampleRate
|
2015-08-17 02:29:34 -04:00
|
|
|
<< " frequencyOffset: " << notif.getFrequencyOffset();
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
return true;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
2017-10-07 06:55:17 -04:00
|
|
|
else if (MsgConfigureChannelizer::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd;
|
|
|
|
|
|
|
|
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
|
|
|
|
cfg.getSampleRate(),
|
|
|
|
cfg.getCenterFrequency());
|
|
|
|
|
|
|
|
qDebug() << "TCPSrc::handleMessage: MsgConfigureChannelizer:"
|
|
|
|
<< " sampleRate: " << cfg.getSampleRate()
|
|
|
|
<< " centerFrequency: " << cfg.getCenterFrequency();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-07 04:44:58 -04:00
|
|
|
else if (MsgConfigureTCPSrc::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureTCPSrc& cfg = (MsgConfigureTCPSrc&) cmd;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-10-07 04:44:58 -04:00
|
|
|
TCPSrcSettings settings = cfg.getSettings();
|
2015-08-24 17:23:45 -04:00
|
|
|
|
2017-10-07 04:44:58 -04:00
|
|
|
// These settings are set with DownChannelizer::MsgChannelizerNotification
|
|
|
|
settings.m_inputSampleRate = m_settings.m_inputSampleRate;
|
|
|
|
settings.m_inputFrequencyOffset = m_settings.m_inputFrequencyOffset;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-10-07 04:44:58 -04:00
|
|
|
m_settingsMutex.lock();
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-10-07 04:44:58 -04:00
|
|
|
m_sampleFormat = settings.m_sampleFormat;
|
|
|
|
m_outputSampleRate = settings.m_outputSampleRate;
|
|
|
|
m_rfBandwidth = settings.m_rfBandwidth;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-10-07 04:44:58 -04:00
|
|
|
if (settings.m_tcpPort != m_tcpPort)
|
|
|
|
{
|
|
|
|
m_tcpPort = settings.m_tcpPort;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-10-07 04:44:58 -04:00
|
|
|
if(m_tcpServer->isListening())
|
|
|
|
{
|
|
|
|
m_tcpServer->close();
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-10-07 04:44:58 -04:00
|
|
|
m_tcpServer->listen(QHostAddress::Any, m_tcpPort);
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-10-07 04:44:58 -04:00
|
|
|
m_volume = settings.m_volume;
|
|
|
|
m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0);
|
|
|
|
m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate;
|
2015-08-24 17:23:45 -04:00
|
|
|
|
2017-10-07 04:44:58 -04:00
|
|
|
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);
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-10-07 04:44:58 -04:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
|
2017-10-07 06:55:17 -04:00
|
|
|
qDebug() << "TCPSrc::handleMessage: MsgConfigureTCPSrc:"
|
2017-10-07 04:44:58 -04:00
|
|
|
<< " m_sampleFormat: " << m_sampleFormat
|
|
|
|
<< " m_outputSampleRate: " << m_outputSampleRate
|
|
|
|
<< " m_rfBandwidth: " << m_rfBandwidth
|
|
|
|
<< " m_volume: " << m_volume;
|
|
|
|
|
|
|
|
m_settings = settings;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
else if (MsgTCPSrcSpectrum::match(cmd))
|
|
|
|
{
|
|
|
|
MsgTCPSrcSpectrum& spc = (MsgTCPSrcSpectrum&) cmd;
|
|
|
|
|
|
|
|
m_spectrumEnabled = spc.getEnabled();
|
|
|
|
|
2017-10-07 06:55:17 -04:00
|
|
|
qDebug() << "TCPSrc::handleMessage: MsgTCPSrcSpectrum: m_spectrumEnabled: " << m_spectrumEnabled;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
return true;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
2015-12-24 09:30:41 -05:00
|
|
|
else if (MsgTCPSrcConnection::match(cmd))
|
2015-11-27 02:49:36 -05:00
|
|
|
{
|
2015-12-24 09:30:41 -05:00
|
|
|
MsgTCPSrcConnection& con = (MsgTCPSrcConnection&) cmd;
|
2015-11-27 02:49:36 -05:00
|
|
|
|
2017-10-07 06:55:17 -04:00
|
|
|
qDebug() << "TCPSrc::handleMessage: MsgTCPSrcConnection"
|
|
|
|
<< " connect: " << con.getConnect()
|
|
|
|
<< " id: " << con.getID()
|
|
|
|
<< " peer address: " << con.getPeerAddress()
|
|
|
|
<< " peer port: " << con.getPeerPort();
|
|
|
|
|
2015-11-27 02:49:36 -05:00
|
|
|
if (con.getConnect())
|
|
|
|
{
|
|
|
|
processNewConnection();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
processDeconnection();
|
|
|
|
}
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(m_spectrum != 0)
|
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
return m_spectrum->handleMessage(cmd);
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
2016-11-21 12:01:55 -05:00
|
|
|
|
|
|
|
return false;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TCPSrc::closeAllSockets(Sockets* sockets)
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
for(int i = 0; i < sockets->count(); ++i)
|
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
MsgTCPSrcConnection* msg = MsgTCPSrcConnection::create(false, sockets->at(i).id, QHostAddress(), 0);
|
2017-10-07 05:07:46 -04:00
|
|
|
getInputMessageQueue()->push(msg);
|
|
|
|
|
|
|
|
if (getMessageQueueToGUI()) { // Propagate to GUI
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
|
|
|
}
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
sockets->at(i).socket->close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TCPSrc::onNewConnection()
|
|
|
|
{
|
2015-11-18 21:26:46 -05:00
|
|
|
qDebug("TCPSrc::onNewConnection");
|
2015-12-24 09:30:41 -05:00
|
|
|
processNewConnection();
|
2015-11-27 02:49:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TCPSrc::processNewConnection()
|
|
|
|
{
|
|
|
|
qDebug("TCPSrc::processNewConnection");
|
2015-11-18 21:26:46 -05:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
while(m_tcpServer->hasPendingConnections())
|
|
|
|
{
|
2015-11-27 02:49:36 -05:00
|
|
|
qDebug("TCPSrc::processNewConnection: has a pending connection");
|
2014-05-18 11:52:39 -04:00
|
|
|
QTcpSocket* connection = m_tcpServer->nextPendingConnection();
|
2015-11-18 21:26:46 -05:00
|
|
|
connection->setSocketOption(QAbstractSocket:: KeepAliveOption, 1);
|
2014-05-18 11:52:39 -04:00
|
|
|
connect(connection, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
|
|
|
|
|
|
|
|
switch(m_sampleFormat) {
|
2014-12-25 07:00:13 -05:00
|
|
|
|
2017-10-07 04:24:25 -04:00
|
|
|
case TCPSrcSettings::FormatNFM:
|
|
|
|
case TCPSrcSettings::FormatSSB:
|
2015-11-18 21:26:46 -05:00
|
|
|
{
|
2017-10-07 04:24:25 -04:00
|
|
|
quint32 id = (TCPSrcSettings::FormatSSB << 24) | m_nextSSBId;
|
2014-12-03 13:41:38 -05:00
|
|
|
m_nextSSBId = (m_nextSSBId + 1) & 0xffffff;
|
|
|
|
m_ssbSockets.push_back(Socket(id, connection));
|
2017-10-07 05:07:46 -04:00
|
|
|
|
|
|
|
if (getMessageQueueToGUI()) // Notify GUI of peer details
|
|
|
|
{
|
|
|
|
MsgTCPSrcConnection* msg = MsgTCPSrcConnection::create(true, id, connection->peerAddress(), connection->peerPort());
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
|
|
|
}
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-10-07 04:24:25 -04:00
|
|
|
case TCPSrcSettings::FormatS16LE:
|
2015-11-18 21:26:46 -05:00
|
|
|
{
|
2015-11-27 02:49:36 -05:00
|
|
|
qDebug("TCPSrc::processNewConnection: establish new S16LE connection");
|
2017-10-07 04:24:25 -04:00
|
|
|
quint32 id = (TCPSrcSettings::FormatS16LE << 24) | m_nextS16leId;
|
2014-05-18 11:52:39 -04:00
|
|
|
m_nextS16leId = (m_nextS16leId + 1) & 0xffffff;
|
|
|
|
m_s16leSockets.push_back(Socket(id, connection));
|
2017-10-07 05:07:46 -04:00
|
|
|
|
|
|
|
if (getMessageQueueToGUI()) // Notify GUI of peer details
|
|
|
|
{
|
|
|
|
MsgTCPSrcConnection* msg = MsgTCPSrcConnection::create(true, id, connection->peerAddress(), connection->peerPort());
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
|
|
|
}
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
delete connection;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TCPSrc::onDisconnected()
|
2015-11-27 02:49:36 -05:00
|
|
|
{
|
|
|
|
qDebug("TCPSrc::onDisconnected");
|
2015-12-24 09:30:41 -05:00
|
|
|
MsgTCPSrcConnection *cmd = MsgTCPSrcConnection::create(false, 0, QHostAddress::Any, 0);
|
2015-11-27 02:49:36 -05:00
|
|
|
getInputMessageQueue()->push(cmd);
|
2017-10-07 05:07:46 -04:00
|
|
|
|
|
|
|
if (getMessageQueueToGUI()) { // Propagate to GUI
|
|
|
|
getMessageQueueToGUI()->push(cmd);
|
|
|
|
}
|
|
|
|
|
2015-11-27 02:49:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TCPSrc::processDeconnection()
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
quint32 id;
|
2015-08-17 02:29:34 -04:00
|
|
|
QTcpSocket* socket = 0;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2015-11-27 02:49:36 -05:00
|
|
|
qDebug("TCPSrc::processDeconnection");
|
2015-11-18 21:26:46 -05:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
for(int i = 0; i < m_ssbSockets.count(); i++)
|
|
|
|
{
|
|
|
|
if(m_ssbSockets[i].socket == sender())
|
|
|
|
{
|
2014-12-03 13:41:38 -05:00
|
|
|
id = m_ssbSockets[i].id;
|
|
|
|
socket = m_ssbSockets[i].socket;
|
2015-11-18 21:26:46 -05:00
|
|
|
socket->close();
|
2014-12-03 13:41:38 -05:00
|
|
|
m_ssbSockets.removeAt(i);
|
2014-05-18 11:52:39 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
|
|
|
if(socket == 0)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < m_s16leSockets.count(); i++)
|
|
|
|
{
|
|
|
|
if(m_s16leSockets[i].socket == sender())
|
|
|
|
{
|
2015-11-27 02:49:36 -05:00
|
|
|
qDebug("TCPSrc::processDeconnection: remove S16LE socket #%d", i);
|
2015-11-18 21:26:46 -05:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
id = m_s16leSockets[i].id;
|
|
|
|
socket = m_s16leSockets[i].socket;
|
2015-11-18 21:26:46 -05:00
|
|
|
socket->close();
|
2014-05-18 11:52:39 -04:00
|
|
|
m_s16leSockets.removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
|
|
|
if(socket != 0)
|
|
|
|
{
|
2017-10-07 05:07:46 -04:00
|
|
|
MsgTCPSrcConnection* msg = MsgTCPSrcConnection::create(false, id, QHostAddress(), 0);
|
|
|
|
getInputMessageQueue()->push(msg);
|
|
|
|
|
|
|
|
if (getMessageQueueToGUI()) { // Propagate to GUI
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
socket->deleteLater();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
}
|
2015-11-18 21:26:46 -05:00
|
|
|
|
2017-05-25 14:13:34 -04:00
|
|
|
void TCPSrc::onTcpServerError(QAbstractSocket::SocketError socketError __attribute__((unused)))
|
2015-11-18 21:26:46 -05:00
|
|
|
{
|
|
|
|
qDebug("TCPSrc::onTcpServerError: %s", qPrintable(m_tcpServer->errorString()));
|
|
|
|
}
|