Fix for pkt7 (ping) requests and improve rtt counter

merge-requests/1/head
Phil Taylor 2021-02-06 10:54:20 +00:00
rodzic 8c20e1d944
commit ee9517159a
2 zmienionych plików z 16 dodań i 13 usunięć

Wyświetl plik

@ -95,10 +95,11 @@ void udpHandler::DataReceived()
}
break;
case (21): // pkt7,
if (r.mid(1, 5) == QByteArrayLiteral("\x00\x00\x00\x07\x00") && serialAndAudioOpened && lastPacket7Sent>0)
if (r.mid(1, 5) == QByteArrayLiteral("\x00\x00\x00\x07\x00") && r[16] == (char)0x01 && serialAndAudioOpened)
{
//qDebug("Got response!");
// This is a response to our pkt7 request so measure latency (only once fully connected though.
latency += (time(NULL) - lastPacket7Sent);
latency += lastPacket7Sent.msecsTo(QDateTime::currentDateTime());
latency /= 2;
emit haveNetworkStatus("rtt: " + QString::number(latency) + " ms");
}
@ -750,7 +751,7 @@ void udpBase::SendPkt0Idle(bool tracked=true,quint16 seq=0)
static_cast<unsigned char>(remoteSID >> 24 & 0xff), static_cast<unsigned char>(remoteSID >> 16 & 0xff), static_cast<unsigned char>(remoteSID >> 8 & 0xff), static_cast<unsigned char>(remoteSID & 0xff)
};
lastPacket0Sent = time(NULL); // Is this used?
lastPacket0Sent = QDateTime::currentDateTime(); // Is this used?
if (!tracked) {
p[6] = seq & 0xff;
@ -772,12 +773,13 @@ void udpBase::SendPkt7Idle()
const unsigned char p[] = { 0x15, 0x00, 0x00, 0x00, 0x07, 0x00, static_cast<unsigned char>(pkt7SendSeq & 0xff),static_cast<unsigned char>(pkt7SendSeq >> 8 & 0xff),
static_cast<unsigned char>(localSID >> 24 & 0xff), static_cast<unsigned char>(localSID >> 16 & 0xff), static_cast<unsigned char>(localSID >> 8 & 0xff), static_cast<unsigned char>(localSID & 0xff),
static_cast<unsigned char>(remoteSID >> 24 & 0xff), static_cast<unsigned char>(remoteSID >> 16 & 0xff), static_cast<unsigned char>(remoteSID >> 8 & 0xff), static_cast<unsigned char>(remoteSID & 0xff),
static_cast<unsigned char>(rand()),static_cast<unsigned char>(innerSendSeq & 0xff),static_cast<unsigned char>(innerSendSeq >> 8 & 0xff), 0x06
0x00, static_cast<unsigned char>(rand()),static_cast<unsigned char>(innerSendSeq & 0xff),static_cast<unsigned char>(innerSendSeq >> 8 & 0xff), 0x06
};
lastPacket7Sent = time(NULL);
//qDebug() << this->metaObject()->className() << ": Send pkt7: " << QByteArray::fromRawData((const char*)p, sizeof(p));
lastPacket7Sent = QDateTime::currentDateTime();
udp->writeDatagram(QByteArray::fromRawData((const char*)p, sizeof(p)), radioIP, port);
pkt7SendSeq++;
innerSendSeq++;
return;
}

Wyświetl plik

@ -7,6 +7,7 @@
#include <QHostInfo>
#include <QTimer>
#include <QMutex>
#include <QDateTime>
// Allow easy endian-ness conversions
#include <QtEndian>
@ -45,16 +46,16 @@ public:
char authID[6] = { 0, 0, 0, 0, 0, 0 };
char a8replyID[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
uint16_t authInnerSendSeq = 0;
uint16_t innerSendSeq = 0;
uint16_t innerSendSeq = 0x8304; // Not sure why?
uint16_t sendSeqB = 0;
uint16_t sendSeq = 1;
uint16_t lastReceivedSeq = 0;
uint16_t pkt0SendSeq = 0;
uint16_t pkt7SendSeq = 0;
uint16_t periodicSeq = 0;
time_t lastPacket0Sent = 0;
time_t lastPacket7Sent = 0;
int latency = 0;
QDateTime lastPacket0Sent;
QDateTime lastPacket7Sent;
quint64 latency = 0;
QString username = "";
QString password = "";