2021-02-03 20:00:40 +00:00
|
|
|
#ifndef UDPHANDLER_H
|
|
|
|
#define UDPHANDLER_H
|
|
|
|
|
2022-05-10 23:11:29 +00:00
|
|
|
|
2021-02-03 20:00:40 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QUdpSocket>
|
|
|
|
#include <QNetworkDatagram>
|
|
|
|
#include <QHostInfo>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QMutex>
|
2021-02-06 10:54:20 +00:00
|
|
|
#include <QDateTime>
|
2021-02-11 19:18:35 +00:00
|
|
|
#include <QByteArray>
|
2021-02-22 22:25:09 +00:00
|
|
|
#include <QVector>
|
2021-05-17 15:03:53 +00:00
|
|
|
#include <QMap>
|
2022-01-23 17:54:40 +00:00
|
|
|
#include <QUuid>
|
2021-02-03 20:00:40 +00:00
|
|
|
|
|
|
|
// Allow easy endian-ness conversions
|
|
|
|
#include <QtEndian>
|
|
|
|
|
|
|
|
// Needed for audio
|
|
|
|
#include <QBuffer>
|
2021-02-08 08:31:48 +00:00
|
|
|
#include <QThread>
|
2021-02-03 20:00:40 +00:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
2021-02-20 18:29:23 +00:00
|
|
|
#include "packettypes.h"
|
2022-05-10 23:11:29 +00:00
|
|
|
#include "audiohandler.h"
|
|
|
|
#include "udpbase.h"
|
|
|
|
#include "udpcivdata.h"
|
|
|
|
#include "udpaudio.h"
|
2021-02-03 20:00:40 +00:00
|
|
|
|
2022-08-25 04:52:36 +00:00
|
|
|
#define audioLevelBufferSize (4)
|
2021-02-03 20:00:40 +00:00
|
|
|
|
|
|
|
// Class to handle the connection/disconnection of the radio.
|
|
|
|
class udpHandler: public udpBase
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2021-06-04 07:24:26 +00:00
|
|
|
udpHandler(udpPreferences prefs, audioSetup rxAudio, audioSetup txAudio);
|
2021-02-03 20:00:40 +00:00
|
|
|
~udpHandler();
|
|
|
|
|
2021-02-20 18:29:23 +00:00
|
|
|
bool streamOpened = false;
|
2021-02-03 20:00:40 +00:00
|
|
|
|
2021-02-13 23:25:24 +00:00
|
|
|
udpCivData* civ = Q_NULLPTR;
|
|
|
|
udpAudio* audio = Q_NULLPTR;
|
2021-02-03 20:00:40 +00:00
|
|
|
|
2022-01-21 19:23:32 +00:00
|
|
|
unsigned char numRadios;
|
|
|
|
QList<radio_cap_packet> radios;
|
2021-02-03 20:00:40 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void receiveDataFromUserToRig(QByteArray); // This slot will send data on to
|
2021-02-13 23:25:24 +00:00
|
|
|
void receiveFromCivStream(QByteArray);
|
2021-03-01 19:53:12 +00:00
|
|
|
void receiveAudioData(const audioPacket &data);
|
2021-02-27 00:37:00 +00:00
|
|
|
void changeLatency(quint16 value);
|
2021-03-22 18:53:34 +00:00
|
|
|
void setVolume(unsigned char value);
|
2021-02-21 14:53:42 +00:00
|
|
|
void init();
|
2022-01-23 17:54:40 +00:00
|
|
|
void setCurrentRadio(quint8 radio);
|
2022-08-24 22:02:00 +00:00
|
|
|
void getRxLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over);
|
|
|
|
void getTxLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over);
|
2021-02-03 20:00:40 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void haveDataFromPort(QByteArray data); // emit this when we have data, connect to rigcommander
|
2021-03-01 19:53:12 +00:00
|
|
|
void haveAudioData(audioPacket data); // emit this when we have data, connect to rigcommander
|
2023-01-05 19:37:53 +00:00
|
|
|
void haveNetworkError(errorType);
|
2021-02-27 00:37:00 +00:00
|
|
|
void haveChangeLatency(quint16 value);
|
2021-03-22 18:53:34 +00:00
|
|
|
void haveSetVolume(unsigned char value);
|
2022-01-22 15:12:36 +00:00
|
|
|
void haveNetworkStatus(networkStatus);
|
2022-08-24 05:24:05 +00:00
|
|
|
void haveNetworkAudioLevels(networkAudioLevels);
|
2021-05-21 15:30:52 +00:00
|
|
|
void haveBaudRate(quint32 baudrate);
|
2022-01-21 19:23:32 +00:00
|
|
|
void requestRadioSelection(QList<radio_cap_packet> radios);
|
2022-01-23 17:54:40 +00:00
|
|
|
void setRadioUsage(quint8, quint8 busy, QString name, QString mac);
|
2021-02-03 20:00:40 +00:00
|
|
|
private:
|
2021-02-20 18:29:23 +00:00
|
|
|
|
2021-02-14 07:53:55 +00:00
|
|
|
void sendAreYouThere();
|
|
|
|
|
2021-02-13 23:25:24 +00:00
|
|
|
void dataReceived();
|
|
|
|
|
2021-02-20 18:29:23 +00:00
|
|
|
void sendRequestStream();
|
2021-02-13 23:25:24 +00:00
|
|
|
void sendLogin();
|
|
|
|
void sendToken(uint8_t magic);
|
|
|
|
|
2021-02-03 20:00:40 +00:00
|
|
|
bool gotA8ReplyID = false;
|
|
|
|
bool gotAuthOK = false;
|
|
|
|
|
|
|
|
bool sentPacketLogin = false;
|
|
|
|
bool sentPacketConnect = false;
|
|
|
|
bool sentPacketConnect2 = false;
|
|
|
|
|
2021-02-07 17:40:38 +00:00
|
|
|
bool radioInUse = false;
|
|
|
|
|
2021-02-13 23:25:24 +00:00
|
|
|
quint16 controlPort;
|
|
|
|
quint16 civPort;
|
2021-02-13 23:28:28 +00:00
|
|
|
quint16 audioPort;
|
2021-02-13 23:25:24 +00:00
|
|
|
|
2022-01-23 15:06:31 +00:00
|
|
|
quint16 civLocalPort;
|
|
|
|
quint16 audioLocalPort;
|
|
|
|
|
2021-06-04 07:24:26 +00:00
|
|
|
audioSetup rxSetup;
|
|
|
|
audioSetup txSetup;
|
2021-03-01 20:31:05 +00:00
|
|
|
|
2021-02-08 16:53:26 +00:00
|
|
|
quint16 reauthInterval = 60000;
|
2021-02-21 01:18:14 +00:00
|
|
|
QString devName;
|
|
|
|
QString compName;
|
|
|
|
QString audioType;
|
|
|
|
//QByteArray replyId;
|
2021-02-20 18:29:23 +00:00
|
|
|
quint16 tokRequest;
|
|
|
|
quint32 token;
|
|
|
|
// These are for stream ident info.
|
2022-01-21 19:23:32 +00:00
|
|
|
quint8 macaddress[8];
|
2022-01-29 22:50:58 +00:00
|
|
|
quint8 guid[GUIDLEN];
|
2022-01-21 23:58:18 +00:00
|
|
|
bool useGuid = false;
|
2021-02-21 15:06:27 +00:00
|
|
|
QByteArray usernameEncoded;
|
|
|
|
QByteArray passwordEncoded;
|
|
|
|
|
2021-02-21 14:53:42 +00:00
|
|
|
QTimer* tokenTimer = Q_NULLPTR;
|
|
|
|
QTimer* areYouThereTimer = Q_NULLPTR;
|
2021-02-13 23:25:24 +00:00
|
|
|
|
2021-02-14 07:53:55 +00:00
|
|
|
bool highBandwidthConnection = false;
|
2021-05-18 08:32:56 +00:00
|
|
|
quint8 civId = 0;
|
|
|
|
quint16 rxSampleRates = 0;
|
|
|
|
quint16 txSampleRates = 0;
|
2022-01-22 15:12:36 +00:00
|
|
|
networkStatus status;
|
2022-04-18 19:29:50 +00:00
|
|
|
bool splitWf = false;
|
2022-08-24 05:24:05 +00:00
|
|
|
|
|
|
|
unsigned char audioLevelsTxPeak[audioLevelBufferSize];
|
|
|
|
unsigned char audioLevelsRxPeak[audioLevelBufferSize];
|
2022-08-24 22:02:00 +00:00
|
|
|
|
|
|
|
unsigned char audioLevelsTxRMS[audioLevelBufferSize];
|
|
|
|
unsigned char audioLevelsRxRMS[audioLevelBufferSize];
|
|
|
|
|
|
|
|
unsigned char audioLevelsTxPosition = 0;
|
|
|
|
unsigned char audioLevelsRxPosition = 0;
|
2022-08-24 05:24:05 +00:00
|
|
|
unsigned char findMean(unsigned char *d);
|
2022-08-24 22:02:00 +00:00
|
|
|
unsigned char findMax(unsigned char *d);
|
2022-08-24 05:24:05 +00:00
|
|
|
|
|
|
|
|
2021-02-03 20:00:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-02-03 22:10:37 +00:00
|
|
|
#endif
|