2014-05-18 15:52:39 +00:00
|
|
|
#ifndef INCLUDE_TCPSRC_H
|
|
|
|
#define INCLUDE_TCPSRC_H
|
|
|
|
|
2016-10-02 20:29:04 +00:00
|
|
|
#include <dsp/basebandsamplesink.h>
|
2015-08-24 21:23:45 +00:00
|
|
|
#include <QMutex>
|
2014-05-18 15:52:39 +00:00
|
|
|
#include <QHostAddress>
|
|
|
|
#include "dsp/nco.h"
|
2014-12-17 21:06:02 +00:00
|
|
|
#include "dsp/fftfilt.h"
|
2014-05-18 15:52:39 +00:00
|
|
|
#include "dsp/interpolator.h"
|
|
|
|
#include "util/message.h"
|
|
|
|
|
2014-12-25 12:00:13 +00:00
|
|
|
#define tcpFftLen 2048
|
2014-12-17 21:06:02 +00:00
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
class QTcpServer;
|
|
|
|
class QTcpSocket;
|
|
|
|
class TCPSrcGUI;
|
|
|
|
|
2016-10-02 20:29:04 +00:00
|
|
|
class TCPSrc : public BasebandSampleSink {
|
2014-05-18 15:52:39 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum SampleFormat {
|
2014-12-03 18:41:38 +00:00
|
|
|
FormatSSB,
|
2014-12-25 12:00:13 +00:00
|
|
|
FormatNFM,
|
|
|
|
FormatS16LE,
|
|
|
|
FormatNone
|
2014-05-18 15:52:39 +00:00
|
|
|
};
|
|
|
|
|
2016-10-02 20:29:04 +00:00
|
|
|
TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, BasebandSampleSink* spectrum);
|
2015-08-17 06:29:34 +00:00
|
|
|
virtual ~TCPSrc();
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2014-12-28 19:04:26 +00:00
|
|
|
void configure(MessageQueue* messageQueue, SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost);
|
2014-05-18 15:52:39 +00:00
|
|
|
void setSpectrum(MessageQueue* messageQueue, bool enabled);
|
2017-05-16 21:39:49 +00:00
|
|
|
double getMagSq() const { return m_magsq; }
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2015-08-25 06:24:23 +00:00
|
|
|
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
|
2015-08-17 06:29:34 +00:00
|
|
|
virtual void start();
|
|
|
|
virtual void stop();
|
|
|
|
virtual bool handleMessage(const Message& cmd);
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
class MsgTCPSrcConnection : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool getConnect() const { return m_connect; }
|
|
|
|
quint32 getID() const { return m_id; }
|
|
|
|
const QHostAddress& getPeerAddress() const { return m_peerAddress; }
|
|
|
|
int getPeerPort() const { return m_peerPort; }
|
|
|
|
|
|
|
|
static MsgTCPSrcConnection* create(bool connect, quint32 id, const QHostAddress& peerAddress, int peerPort)
|
|
|
|
{
|
|
|
|
return new MsgTCPSrcConnection(connect, id, peerAddress, peerPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_connect;
|
|
|
|
quint32 m_id;
|
|
|
|
QHostAddress m_peerAddress;
|
|
|
|
int m_peerPort;
|
|
|
|
|
|
|
|
MsgTCPSrcConnection(bool connect, quint32 id, const QHostAddress& peerAddress, int peerPort) :
|
|
|
|
Message(),
|
|
|
|
m_connect(connect),
|
|
|
|
m_id(id),
|
|
|
|
m_peerAddress(peerAddress),
|
|
|
|
m_peerPort(peerPort)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
class MsgTCPSrcConfigure : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
SampleFormat getSampleFormat() const { return m_sampleFormat; }
|
|
|
|
Real getOutputSampleRate() const { return m_outputSampleRate; }
|
|
|
|
Real getRFBandwidth() const { return m_rfBandwidth; }
|
|
|
|
int getTCPPort() const { return m_tcpPort; }
|
2014-12-28 19:04:26 +00:00
|
|
|
int getBoost() const { return m_boost; }
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2014-12-28 19:04:26 +00:00
|
|
|
static MsgTCPSrcConfigure* create(SampleFormat sampleFormat, Real sampleRate, Real rfBandwidth, int tcpPort, int boost)
|
2014-05-18 15:52:39 +00:00
|
|
|
{
|
2014-12-28 19:04:26 +00:00
|
|
|
return new MsgTCPSrcConfigure(sampleFormat, sampleRate, rfBandwidth, tcpPort, boost);
|
2014-05-18 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SampleFormat m_sampleFormat;
|
|
|
|
Real m_outputSampleRate;
|
|
|
|
Real m_rfBandwidth;
|
|
|
|
int m_tcpPort;
|
2014-12-28 19:04:26 +00:00
|
|
|
int m_boost;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2014-12-28 19:04:26 +00:00
|
|
|
MsgTCPSrcConfigure(SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost) :
|
2014-05-18 15:52:39 +00:00
|
|
|
Message(),
|
|
|
|
m_sampleFormat(sampleFormat),
|
|
|
|
m_outputSampleRate(outputSampleRate),
|
|
|
|
m_rfBandwidth(rfBandwidth),
|
2014-12-28 19:04:26 +00:00
|
|
|
m_tcpPort(tcpPort),
|
|
|
|
m_boost(boost)
|
2014-05-18 15:52:39 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
class MsgTCPSrcSpectrum : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool getEnabled() const { return m_enabled; }
|
|
|
|
|
|
|
|
static MsgTCPSrcSpectrum* create(bool enabled)
|
|
|
|
{
|
|
|
|
return new MsgTCPSrcSpectrum(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_enabled;
|
|
|
|
|
|
|
|
MsgTCPSrcSpectrum(bool enabled) :
|
|
|
|
Message(),
|
|
|
|
m_enabled(enabled)
|
|
|
|
{ }
|
|
|
|
};
|
2015-11-27 07:49:36 +00:00
|
|
|
class MsgTCPConnection : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool getConnect() const { return m_connect; }
|
|
|
|
|
|
|
|
static MsgTCPConnection* create(bool connect)
|
|
|
|
{
|
|
|
|
return new MsgTCPConnection(connect);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_connect;
|
|
|
|
|
|
|
|
MsgTCPConnection(bool connect) :
|
|
|
|
Message(),
|
|
|
|
m_connect(connect)
|
|
|
|
{ }
|
|
|
|
};
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
MessageQueue* m_uiMessageQueue;
|
|
|
|
TCPSrcGUI* m_tcpSrcGUI;
|
|
|
|
|
|
|
|
int m_inputSampleRate;
|
|
|
|
|
|
|
|
int m_sampleFormat;
|
|
|
|
Real m_outputSampleRate;
|
|
|
|
Real m_rfBandwidth;
|
|
|
|
int m_tcpPort;
|
2014-12-28 19:04:26 +00:00
|
|
|
int m_boost;
|
2017-05-16 21:39:49 +00:00
|
|
|
double m_magsq;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2014-12-25 12:00:13 +00:00
|
|
|
Real m_scale;
|
|
|
|
Complex m_last, m_this;
|
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
NCO m_nco;
|
|
|
|
Interpolator m_interpolator;
|
|
|
|
Real m_sampleDistanceRemain;
|
2014-12-17 21:06:02 +00:00
|
|
|
fftfilt* TCPFilter;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
SampleVector m_sampleBuffer;
|
2014-12-17 21:06:02 +00:00
|
|
|
SampleVector m_sampleBufferSSB;
|
2016-10-02 20:29:04 +00:00
|
|
|
BasebandSampleSink* m_spectrum;
|
2014-05-18 15:52:39 +00:00
|
|
|
bool m_spectrumEnabled;
|
|
|
|
|
|
|
|
QTcpServer* m_tcpServer;
|
|
|
|
struct Socket {
|
|
|
|
quint32 id;
|
|
|
|
QTcpSocket* socket;
|
|
|
|
Socket(quint32 _id, QTcpSocket* _socket) :
|
|
|
|
id(_id),
|
|
|
|
socket(_socket)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
typedef QList<Socket> Sockets;
|
2014-12-03 18:41:38 +00:00
|
|
|
Sockets m_ssbSockets;
|
2014-05-18 15:52:39 +00:00
|
|
|
Sockets m_s16leSockets;
|
2014-12-03 18:41:38 +00:00
|
|
|
quint32 m_nextSSBId;
|
2014-05-18 15:52:39 +00:00
|
|
|
quint32 m_nextS16leId;
|
|
|
|
|
2015-08-24 21:23:45 +00:00
|
|
|
QMutex m_settingsMutex;
|
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
void closeAllSockets(Sockets* sockets);
|
2015-11-27 07:49:36 +00:00
|
|
|
void processNewConnection();
|
|
|
|
void processDeconnection();
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
protected slots:
|
|
|
|
void onNewConnection();
|
|
|
|
void onDisconnected();
|
2015-11-19 02:26:46 +00:00
|
|
|
void onTcpServerError(QAbstractSocket::SocketError socketError);
|
2014-05-18 15:52:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDE_TCPSRC_H
|