1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 16:38:37 -05:00
sdrangel/plugins/channelrx/tcpsrc/tcpsrc.h

225 lines
5.5 KiB
C
Raw Normal View History

#ifndef INCLUDE_TCPSRC_H
#define INCLUDE_TCPSRC_H
#include <QMutex>
#include <QHostAddress>
2017-10-07 04:24:25 -04:00
#include "dsp/basebandsamplesink.h"
#include "channel/channelsinkapi.h"
#include "dsp/nco.h"
2014-12-17 16:06:02 -05:00
#include "dsp/fftfilt.h"
#include "dsp/interpolator.h"
#include "util/message.h"
2017-10-07 04:24:25 -04:00
#include "tcpsrcsettings.h"
2014-12-25 07:00:13 -05:00
#define tcpFftLen 2048
2014-12-17 16:06:02 -05:00
class QTcpServer;
class QTcpSocket;
class TCPSrcGUI;
class DeviceSourceAPI;
class ThreadedBasebandSampleSink;
class DownChannelizer;
class TCPSrc : public BasebandSampleSink, public ChannelSinkAPI {
Q_OBJECT
public:
2017-10-07 04:44:58 -04:00
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)
{ }
};
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)
{ }
};
TCPSrc(DeviceSourceAPI* m_deviceAPI);
2015-08-17 02:29:34 -04:00
virtual ~TCPSrc();
2017-12-17 17:15:42 -05:00
virtual void destroy() { delete this; }
void setSpectrum(BasebandSampleSink* spectrum) { m_spectrum = spectrum; }
void setSpectrum(MessageQueue* messageQueue, bool enabled);
2017-05-16 17:39:49 -04:00
double getMagSq() const { return m_magsq; }
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
2015-08-17 02:29:34 -04:00
virtual void start();
virtual void stop();
virtual bool handleMessage(const Message& cmd);
virtual void getIdentifier(QString& id) { id = objectName(); }
virtual void getTitle(QString& title) { title = m_settings.m_title; }
2017-12-17 17:15:42 -05:00
virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; }
virtual QByteArray serialize() const;
virtual bool deserialize(const QByteArray& data);
static const QString m_channelIdURI;
static const QString m_channelId;
protected:
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)
{ }
};
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)
{ }
};
DeviceSourceAPI* m_deviceAPI;
ThreadedBasebandSampleSink* m_threadedChannelizer;
DownChannelizer* m_channelizer;
2017-10-07 04:44:58 -04:00
TCPSrcSettings m_settings;
int m_absoluteFrequencyOffset;
2017-10-07 04:44:58 -04:00
int m_inputSampleRate;
int m_sampleFormat;
Real m_outputSampleRate;
Real m_rfBandwidth;
int m_tcpPort;
2017-10-07 04:44:58 -04:00
int m_volume;
2017-05-16 17:39:49 -04:00
double m_magsq;
2014-12-25 07:00:13 -05:00
Real m_scale;
Complex m_last, m_this;
NCO m_nco;
Interpolator m_interpolator;
Real m_sampleDistanceRemain;
2014-12-17 16:06:02 -05:00
fftfilt* TCPFilter;
SampleVector m_sampleBuffer;
2014-12-17 16:06:02 -05:00
SampleVector m_sampleBufferSSB;
BasebandSampleSink* m_spectrum;
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 13:41:38 -05:00
Sockets m_ssbSockets;
Sockets m_s16leSockets;
2014-12-03 13:41:38 -05:00
quint32 m_nextSSBId;
quint32 m_nextS16leId;
QMutex m_settingsMutex;
void closeAllSockets(Sockets* sockets);
void processNewConnection();
void processDeconnection();
protected slots:
void onNewConnection();
void onDisconnected();
2015-11-18 21:26:46 -05:00
void onTcpServerError(QAbstractSocket::SocketError socketError);
};
#endif // INCLUDE_TCPSRC_H