2015-11-19 02:55:58 -05:00
|
|
|
#ifndef INCLUDE_UDPSRC_H
|
|
|
|
#define INCLUDE_UDPSRC_H
|
2015-11-18 21:27:37 -05:00
|
|
|
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QHostAddress>
|
|
|
|
#include "dsp/samplesink.h"
|
|
|
|
#include "dsp/nco.h"
|
|
|
|
#include "dsp/fftfilt.h"
|
|
|
|
#include "dsp/interpolator.h"
|
|
|
|
#include "util/message.h"
|
|
|
|
|
2015-11-19 02:55:58 -05:00
|
|
|
#define udpFftLen 2048
|
2015-11-18 21:27:37 -05:00
|
|
|
|
|
|
|
class QTcpServer;
|
|
|
|
class QTcpSocket;
|
|
|
|
class UDPSrcGUI;
|
|
|
|
|
|
|
|
class UDPSrc : public SampleSink {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum SampleFormat {
|
|
|
|
FormatSSB,
|
|
|
|
FormatNFM,
|
|
|
|
FormatS16LE,
|
|
|
|
FormatNone
|
|
|
|
};
|
|
|
|
|
|
|
|
UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* spectrum);
|
|
|
|
virtual ~UDPSrc();
|
|
|
|
|
2015-11-19 02:55:58 -05:00
|
|
|
void configure(MessageQueue* messageQueue, SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int udpPort, int boost);
|
2015-11-18 21:27:37 -05:00
|
|
|
void setSpectrum(MessageQueue* messageQueue, bool enabled);
|
|
|
|
Real getMagSq() const { return m_magsq; }
|
|
|
|
|
|
|
|
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
|
|
|
|
virtual void start();
|
|
|
|
virtual void stop();
|
|
|
|
virtual bool handleMessage(const Message& cmd);
|
|
|
|
|
|
|
|
class MsgUDPSrcConnection : 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 MsgUDPSrcConnection* create(bool connect, quint32 id, const QHostAddress& peerAddress, int peerPort)
|
|
|
|
{
|
|
|
|
return new MsgUDPSrcConnection(connect, id, peerAddress, peerPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_connect;
|
|
|
|
quint32 m_id;
|
|
|
|
QHostAddress m_peerAddress;
|
|
|
|
int m_peerPort;
|
|
|
|
|
|
|
|
MsgUDPSrcConnection(bool connect, quint32 id, const QHostAddress& peerAddress, int peerPort) :
|
|
|
|
Message(),
|
|
|
|
m_connect(connect),
|
|
|
|
m_id(id),
|
|
|
|
m_peerAddress(peerAddress),
|
|
|
|
m_peerPort(peerPort)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
class MsgUDPSrcConfigure : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
SampleFormat getSampleFormat() const { return m_sampleFormat; }
|
|
|
|
Real getOutputSampleRate() const { return m_outputSampleRate; }
|
|
|
|
Real getRFBandwidth() const { return m_rfBandwidth; }
|
2015-11-19 02:55:58 -05:00
|
|
|
int getUDPPort() const { return m_udpPort; }
|
2015-11-18 21:27:37 -05:00
|
|
|
int getBoost() const { return m_boost; }
|
|
|
|
|
2015-11-19 02:55:58 -05:00
|
|
|
static MsgUDPSrcConfigure* create(SampleFormat sampleFormat, Real sampleRate, Real rfBandwidth, int udpPort, int boost)
|
2015-11-18 21:27:37 -05:00
|
|
|
{
|
2015-11-19 02:55:58 -05:00
|
|
|
return new MsgUDPSrcConfigure(sampleFormat, sampleRate, rfBandwidth, udpPort, boost);
|
2015-11-18 21:27:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SampleFormat m_sampleFormat;
|
|
|
|
Real m_outputSampleRate;
|
|
|
|
Real m_rfBandwidth;
|
2015-11-19 02:55:58 -05:00
|
|
|
int m_udpPort;
|
2015-11-18 21:27:37 -05:00
|
|
|
int m_boost;
|
|
|
|
|
2015-11-19 02:55:58 -05:00
|
|
|
MsgUDPSrcConfigure(SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int udpPort, int boost) :
|
2015-11-18 21:27:37 -05:00
|
|
|
Message(),
|
|
|
|
m_sampleFormat(sampleFormat),
|
|
|
|
m_outputSampleRate(outputSampleRate),
|
|
|
|
m_rfBandwidth(rfBandwidth),
|
2015-11-19 02:55:58 -05:00
|
|
|
m_udpPort(udpPort),
|
2015-11-18 21:27:37 -05:00
|
|
|
m_boost(boost)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
class MsgUDPSrcSpectrum : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool getEnabled() const { return m_enabled; }
|
|
|
|
|
|
|
|
static MsgUDPSrcSpectrum* create(bool enabled)
|
|
|
|
{
|
|
|
|
return new MsgUDPSrcSpectrum(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_enabled;
|
|
|
|
|
|
|
|
MsgUDPSrcSpectrum(bool enabled) :
|
|
|
|
Message(),
|
|
|
|
m_enabled(enabled)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MessageQueue* m_uiMessageQueue;
|
2015-11-19 02:55:58 -05:00
|
|
|
UDPSrcGUI* m_udpSrcGUI;
|
2015-11-18 21:27:37 -05:00
|
|
|
|
|
|
|
int m_inputSampleRate;
|
|
|
|
|
|
|
|
int m_sampleFormat;
|
|
|
|
Real m_outputSampleRate;
|
|
|
|
Real m_rfBandwidth;
|
2015-11-19 02:55:58 -05:00
|
|
|
int m_udpPort;
|
2015-11-18 21:27:37 -05:00
|
|
|
int m_boost;
|
|
|
|
Real m_magsq;
|
|
|
|
|
|
|
|
Real m_scale;
|
|
|
|
Complex m_last, m_this;
|
|
|
|
|
|
|
|
NCO m_nco;
|
|
|
|
Interpolator m_interpolator;
|
|
|
|
Real m_sampleDistanceRemain;
|
2015-11-19 02:55:58 -05:00
|
|
|
fftfilt* UDPFilter;
|
2015-11-18 21:27:37 -05:00
|
|
|
|
|
|
|
SampleVector m_sampleBuffer;
|
|
|
|
SampleVector m_sampleBufferSSB;
|
|
|
|
SampleSink* m_spectrum;
|
|
|
|
bool m_spectrumEnabled;
|
|
|
|
|
2015-11-19 02:55:58 -05:00
|
|
|
QTcpServer* m_udpServer;
|
2015-11-18 21:27:37 -05:00
|
|
|
struct Socket {
|
|
|
|
quint32 id;
|
|
|
|
QTcpSocket* socket;
|
|
|
|
Socket(quint32 _id, QTcpSocket* _socket) :
|
|
|
|
id(_id),
|
|
|
|
socket(_socket)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
typedef QList<Socket> Sockets;
|
|
|
|
Sockets m_ssbSockets;
|
|
|
|
Sockets m_s16leSockets;
|
|
|
|
quint32 m_nextSSBId;
|
|
|
|
quint32 m_nextS16leId;
|
|
|
|
|
|
|
|
QMutex m_settingsMutex;
|
|
|
|
|
|
|
|
void closeAllSockets(Sockets* sockets);
|
|
|
|
|
|
|
|
protected slots:
|
|
|
|
void onNewConnection();
|
|
|
|
void onDisconnected();
|
2015-11-19 02:55:58 -05:00
|
|
|
void onUdpServerError(QAbstractSocket::SocketError socketError);
|
2015-11-18 21:27:37 -05:00
|
|
|
};
|
|
|
|
|
2015-11-19 02:55:58 -05:00
|
|
|
#endif // INCLUDE_UDPSRC_H
|