2021-02-16 16:16:46 +00:00
|
|
|
#ifndef UDPSERVER_H
|
|
|
|
#define UDPSERVER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QUdpSocket>
|
|
|
|
#include <QNetworkDatagram>
|
2021-02-28 20:10:07 +00:00
|
|
|
#include <QNetworkInterface>
|
2021-02-16 16:16:46 +00:00
|
|
|
#include <QHostInfo>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QList>
|
2021-02-28 20:10:07 +00:00
|
|
|
#include <QVector>
|
2021-02-16 16:16:46 +00:00
|
|
|
|
|
|
|
// Allow easy endian-ness conversions
|
|
|
|
#include <QtEndian>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include <udpserversetup.h>
|
2021-02-21 21:05:58 +00:00
|
|
|
#include "packettypes.h"
|
2021-02-28 20:10:07 +00:00
|
|
|
#include "rigidentities.h"
|
|
|
|
#include "audiohandler.h"
|
2021-02-16 16:16:46 +00:00
|
|
|
|
|
|
|
extern void passcode(QString in,QByteArray& out);
|
|
|
|
extern QByteArray parseNullTerminatedString(QByteArray c, int s);
|
|
|
|
|
2021-02-28 20:10:07 +00:00
|
|
|
struct SEQBUFENTRY {
|
|
|
|
QTime timeSent;
|
|
|
|
uint16_t seqNum;
|
|
|
|
QByteArray data;
|
|
|
|
quint8 retransmitCount;
|
|
|
|
};
|
|
|
|
|
2021-02-16 16:16:46 +00:00
|
|
|
class udpServer : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
udpServer(SERVERCONFIG config);
|
|
|
|
~udpServer();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void init();
|
2021-02-18 09:14:41 +00:00
|
|
|
void dataForServer(QByteArray);
|
2021-03-01 19:53:12 +00:00
|
|
|
void receiveAudioData(const audioPacket &data);
|
2021-02-28 20:10:07 +00:00
|
|
|
void receiveRigCaps(rigCapabilities caps);
|
2021-02-18 09:14:41 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void haveDataFromServer(QByteArray);
|
2021-03-22 09:10:03 +00:00
|
|
|
void haveAudioData(audioPacket data);
|
|
|
|
void setupTxAudio(const quint8 samples, const quint8 channels, const quint16 samplerate, const quint16 latency, const bool isUlaw, const bool isInput, QString port, quint8 resampleQuality);
|
|
|
|
void setupRxAudio(const quint8 samples, const quint8 channels, const quint16 samplerate, const quint16 latency, const bool isUlaw, const bool isInput, QString port, quint8 resampleQuality);
|
|
|
|
|
2021-02-16 16:16:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
struct CLIENT {
|
|
|
|
bool connected = false;
|
|
|
|
QHostAddress ipAddress;
|
|
|
|
quint16 port;
|
|
|
|
QByteArray clientName;
|
2021-02-17 23:10:26 +00:00
|
|
|
QDateTime timeConnected;
|
|
|
|
QDateTime lastHeard;
|
|
|
|
bool isStreaming;
|
|
|
|
quint16 civPort;
|
|
|
|
quint16 audioPort;
|
|
|
|
quint16 txBufferLen;
|
2021-02-16 16:16:46 +00:00
|
|
|
quint32 myId;
|
|
|
|
quint32 remoteId;
|
2021-02-28 20:10:07 +00:00
|
|
|
quint16 txSeq=0;
|
|
|
|
quint16 rxSeq;
|
|
|
|
quint16 connSeq;
|
2021-02-16 16:16:46 +00:00
|
|
|
quint16 pingSeq;
|
2021-02-23 20:49:26 +00:00
|
|
|
quint32 rxPingTime; // 32bit as has other info
|
2021-03-06 14:33:31 +00:00
|
|
|
quint8 authInnerSeq;
|
2021-02-16 16:16:46 +00:00
|
|
|
quint16 authSeq;
|
|
|
|
quint16 innerSeq;
|
2021-02-28 20:10:07 +00:00
|
|
|
quint16 sendAudioSeq;
|
2021-03-22 09:10:03 +00:00
|
|
|
quint8 identa;
|
|
|
|
quint32 identb;
|
2021-02-16 16:16:46 +00:00
|
|
|
quint16 tokenRx;
|
2021-02-16 20:55:30 +00:00
|
|
|
quint32 tokenTx;
|
2021-02-23 20:49:26 +00:00
|
|
|
quint32 commonCap;
|
2021-02-17 23:10:26 +00:00
|
|
|
quint8 wdseq;
|
2021-02-16 16:16:46 +00:00
|
|
|
QUdpSocket* socket;
|
|
|
|
|
2021-02-17 23:10:26 +00:00
|
|
|
|
2021-02-16 16:16:46 +00:00
|
|
|
QTimer* pingTimer;
|
|
|
|
QTimer* idleTimer;
|
2021-02-17 23:10:26 +00:00
|
|
|
QTimer* wdTimer;
|
2021-02-28 20:10:07 +00:00
|
|
|
QTimer* retransmitTimer;
|
2021-02-16 16:16:46 +00:00
|
|
|
|
|
|
|
// Only used for audio.
|
|
|
|
quint8 rxCodec;
|
|
|
|
quint8 txCodec;
|
|
|
|
quint16 rxSampleRate;
|
|
|
|
quint16 txSampleRate;
|
2021-02-23 20:49:26 +00:00
|
|
|
SERVERUSER user;
|
2021-02-28 20:10:07 +00:00
|
|
|
|
|
|
|
QVector <SEQBUFENTRY> txSeqBuf;
|
|
|
|
QVector <quint16> rxSeqBuf;
|
|
|
|
QVector <SEQBUFENTRY> rxMissing;
|
2021-03-22 09:10:03 +00:00
|
|
|
quint16 seqPrefix;
|
2021-02-16 16:16:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void controlReceived();
|
|
|
|
void civReceived();
|
|
|
|
void audioReceived();
|
2021-02-28 20:10:07 +00:00
|
|
|
void commonReceived(QList<CLIENT*>* l,CLIENT* c, QByteArray r);
|
|
|
|
|
2021-02-18 13:49:19 +00:00
|
|
|
void sendPing(QList<CLIENT*> *l,CLIENT* c, quint16 seq, bool reply);
|
2021-02-23 20:49:26 +00:00
|
|
|
void sendControl(CLIENT* c, quint8 type, quint16 seq);
|
2021-02-28 20:10:07 +00:00
|
|
|
void sendLoginResponse(CLIENT* c, bool allowed);
|
2021-02-16 16:16:46 +00:00
|
|
|
void sendCapabilities(CLIENT* c);
|
|
|
|
void sendConnectionInfo(CLIENT* c);
|
2021-02-17 23:10:26 +00:00
|
|
|
void sendTokenResponse(CLIENT* c,quint8 type);
|
|
|
|
void sendStatus(CLIENT* c);
|
2021-02-28 20:10:07 +00:00
|
|
|
void sendRetransmitRequest(CLIENT* c);
|
|
|
|
void watchdog(CLIENT* c);
|
2021-03-22 09:10:03 +00:00
|
|
|
void sendRxAudio();
|
2021-02-18 13:49:19 +00:00
|
|
|
void deleteConnection(QList<CLIENT*> *l, CLIENT* c);
|
|
|
|
|
2021-02-16 16:16:46 +00:00
|
|
|
SERVERCONFIG config;
|
|
|
|
|
|
|
|
QUdpSocket* udpControl = Q_NULLPTR;
|
|
|
|
QUdpSocket* udpCiv = Q_NULLPTR;
|
|
|
|
QUdpSocket* udpAudio = Q_NULLPTR;
|
|
|
|
QHostAddress localIP;
|
2021-02-28 20:10:07 +00:00
|
|
|
QString macAddress;
|
2021-02-16 16:16:46 +00:00
|
|
|
|
|
|
|
quint32 controlId = 0;
|
|
|
|
quint32 civId = 0;
|
|
|
|
quint32 audioId = 0;
|
|
|
|
|
2021-02-17 23:10:26 +00:00
|
|
|
quint8 rigciv = 0xa2;
|
|
|
|
|
2021-02-18 13:49:19 +00:00
|
|
|
QMutex mutex; // Used for critical operations.
|
|
|
|
|
2021-02-16 16:16:46 +00:00
|
|
|
QList <CLIENT*> controlClients = QList<CLIENT*>();
|
|
|
|
QList <CLIENT*> civClients = QList<CLIENT*>();
|
|
|
|
QList <CLIENT*> audioClients = QList<CLIENT*>();
|
2021-02-23 20:49:26 +00:00
|
|
|
QTime timeStarted;
|
2021-02-28 20:10:07 +00:00
|
|
|
rigCapabilities rigCaps;
|
2021-03-22 09:10:03 +00:00
|
|
|
|
|
|
|
audioHandler* rxaudio = Q_NULLPTR;
|
|
|
|
QThread* rxAudioThread = Q_NULLPTR;
|
|
|
|
|
|
|
|
audioHandler* txaudio = Q_NULLPTR;
|
|
|
|
QThread* txAudioThread = Q_NULLPTR;
|
|
|
|
|
|
|
|
QTimer* rxAudioTimer=Q_NULLPTR;
|
|
|
|
quint16 rxSampleRate = 0;
|
|
|
|
quint16 txSampleRate = 0;
|
|
|
|
quint8 rxCodec = 0;
|
|
|
|
quint8 txCodec = 0;
|
|
|
|
|
|
|
|
QHostAddress hasTxAudio;
|
2021-02-16 16:16:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // UDPSERVER_H
|