wfview/udphandler.h

142 wiersze
3.4 KiB
C
Czysty Zwykły widok Historia

2021-02-03 20:00:40 +00:00
#ifndef UDPHANDLER_H
#define UDPHANDLER_H
2021-02-03 20:00:40 +00:00
#include <QObject>
#include <QUdpSocket>
#include <QNetworkDatagram>
#include <QHostInfo>
#include <QTimer>
#include <QMutex>
#include <QDateTime>
2021-02-11 19:18:35 +00:00
#include <QByteArray>
2021-02-22 22:25:09 +00:00
#include <QVector>
#include <QMap>
#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>
#include "packettypes.h"
#include "audiohandler.h"
#include "udpbase.h"
#include "udpcivdata.h"
#include "udpaudio.h"
2021-02-03 20:00:40 +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();
bool streamOpened = false;
2021-02-03 20:00:40 +00:00
udpCivData* civ = Q_NULLPTR;
udpAudio* audio = Q_NULLPTR;
2021-02-03 20:00:40 +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
void receiveFromCivStream(QByteArray);
void receiveAudioData(const audioPacket &data);
void changeLatency(quint16 value);
void setVolume(unsigned char value);
void init();
void setCurrentRadio(quint8 radio);
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
void haveAudioData(audioPacket data); // emit this when we have data, connect to rigcommander
2023-01-05 19:37:53 +00:00
void haveNetworkError(errorType);
void haveChangeLatency(quint16 value);
void haveSetVolume(unsigned char value);
void haveNetworkStatus(networkStatus);
void haveNetworkAudioLevels(networkAudioLevels);
void haveBaudRate(quint32 baudrate);
void requestRadioSelection(QList<radio_cap_packet> radios);
void setRadioUsage(quint8, quint8 busy, QString name, QString mac);
2021-02-03 20:00:40 +00:00
private:
void sendAreYouThere();
void dataReceived();
void sendRequestStream();
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;
quint16 controlPort;
quint16 civPort;
2021-02-13 23:28:28 +00:00
quint16 audioPort;
quint16 civLocalPort;
quint16 audioLocalPort;
2021-06-04 07:24:26 +00:00
audioSetup rxSetup;
audioSetup txSetup;
quint16 reauthInterval = 60000;
QString devName;
QString compName;
QString audioType;
//QByteArray replyId;
quint16 tokRequest;
quint32 token;
// These are for stream ident info.
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;
QTimer* tokenTimer = Q_NULLPTR;
QTimer* areYouThereTimer = Q_NULLPTR;
bool highBandwidthConnection = false;
2021-05-18 08:32:56 +00:00
quint8 civId = 0;
quint16 rxSampleRates = 0;
quint16 txSampleRates = 0;
networkStatus status;
bool splitWf = false;
unsigned char audioLevelsTxPeak[audioLevelBufferSize];
unsigned char audioLevelsRxPeak[audioLevelBufferSize];
unsigned char audioLevelsTxRMS[audioLevelBufferSize];
unsigned char audioLevelsRxRMS[audioLevelBufferSize];
unsigned char audioLevelsTxPosition = 0;
unsigned char audioLevelsRxPosition = 0;
unsigned char findMean(unsigned char *d);
unsigned char findMax(unsigned char *d);
2021-02-03 20:00:40 +00:00
};
#endif