From 469d44d6db96cbbb73b1d30e25566d0744e15e2f Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Thu, 8 Jul 2021 09:23:16 +0100 Subject: [PATCH 1/3] If pty connected s/w sends a disable transceive command, dont' send any transceive commands to it --- pttyhandler.cpp | 21 ++++++++++++++++----- pttyhandler.h | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pttyhandler.cpp b/pttyhandler.cpp index 414ead2..b671aa0 100644 --- a/pttyhandler.cpp +++ b/pttyhandler.cpp @@ -117,7 +117,7 @@ void pttyHandler::receiveDataFromRigToPtty(const QByteArray& data) { int fePos=data.lastIndexOf((char)0xfe); - if (fePos>0) + if (fePos > 0 && data.length() > fePos+2) fePos=fePos-1; else { @@ -125,7 +125,14 @@ void pttyHandler::receiveDataFromRigToPtty(const QByteArray& data) printHex(data,false,true); } - if (isConnected && (unsigned char)data[fePos+2] != 0xE1 && (unsigned char)data[fePos+3] != 0xE1) + if (disableTransceive && ((unsigned char)data[fePos + 2] == 0x00 || (unsigned char)data[fePos + 3] == 0x00)) + { + // Ignore data that is sent to/from transceive address as client has requested transceive disabled. + qDebug(logSerial()) << "Transceive command filtered"; + return; + } + + if (isConnected && (unsigned char)data[fePos + 2] != 0xE1 && (unsigned char)data[fePos + 3] != 0xE1) { // send to the pseudo port as well // index 2 is dest, 0xE1 is wfview, 0xE0 is assumed to be the other device. @@ -133,7 +140,7 @@ void pttyHandler::receiveDataFromRigToPtty(const QByteArray& data) // 0xE1 = wfview // 0xE0 = pseudo-term host // 0x00 = broadcast to all - //qInfo(logSerial()) << "Sending data from radio to pseudo-terminal"; + //qInfo(logSerial()) << "Sending data from radio to pseudo-terminal"; sendDataOut(data); } } @@ -221,12 +228,16 @@ void pttyHandler::receiveDataIn(int fd) { reply[3] = inPortData[2]; sendDataOut(inPortData); // Echo command back sendDataOut(reply); + if (!disableTransceive) { + qInfo(logSerial()) << "pty requested CI-V Transceive disable"; + disableTransceive = true; + } } else if (inPortData.length() > lastFE + 2 && ((quint8)inPortData[lastFE + 1] == civId || (quint8)inPortData[lastFE + 2] == civId)) { emit haveDataFromPort(inPortData); - //qInfo(logSerial()) << "Data from pseudo term:"; - //printHex(inPortData, false, true); + qDebug(logSerial()) << "Data from pseudo term:"; + printHex(inPortData, false, true); } if (rolledBack) diff --git a/pttyhandler.h b/pttyhandler.h index ac96684..da52ef8 100644 --- a/pttyhandler.h +++ b/pttyhandler.h @@ -65,7 +65,7 @@ private: bool isConnected=false; // port opened mutable QMutex mutex; void printHex(const QByteArray& pdata, bool printVert, bool printHoriz); - + bool disableTransceive = false; QSocketNotifier *ptReader = nullptr; quint8 civId=0; }; From aeaee8de5252d920d38b569fd9022206552521fb Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Thu, 8 Jul 2021 09:23:53 +0100 Subject: [PATCH 2/3] Delete oldest entry from UDP buffer before adding new one. --- udphandler.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/udphandler.cpp b/udphandler.cpp index a2c8e49..de80e8b 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -1133,6 +1133,10 @@ void udpBase::dataReceived(QByteArray r) { rxBufferMutex.lock(); if (rxSeqBuf.isEmpty()) { + if (rxSeqBuf.size() > 400) + { + rxSeqBuf.erase(rxSeqBuf.begin()); + } rxSeqBuf.insert(in->seq, QTime::currentTime()); } else @@ -1153,6 +1157,10 @@ void udpBase::dataReceived(QByteArray r) { // Add incoming packet to the received buffer and if it is in the missing buffer, remove it. rxSeqBuf.insert(in->seq, QTime::currentTime()); + if (rxSeqBuf.size() > 400) + { + rxSeqBuf.erase(rxSeqBuf.begin()); + } } else { // This is probably one of our missing packets! @@ -1208,7 +1216,15 @@ void udpBase::sendRetransmitRequest() { // We haven't seen this missing packet before qDebug(logUdp()) << this->metaObject()->className() << ": Adding to missing buffer (len=" << rxMissing.size() << "): " << j; + if (rxMissing.size() > 25) + { + rxMissing.erase(rxMissing.begin()); + } rxMissing.insert(j, 0); + if (rxSeqBuf.size() > 400) + { + rxSeqBuf.erase(rxSeqBuf.begin()); + } rxSeqBuf.insert(j, QTime::currentTime()); // Add this missing packet to the rxbuffer as we now long about it. packetsLost++; } @@ -1351,11 +1367,17 @@ void udpBase::sendTrackedPacket(QByteArray d) congestion = 0; } txSeqBuf.insert(sendSeq,s); + if (txSeqBuf.size() > 400) + { + txSeqBuf.erase(txSeqBuf.begin()); + } txBufferMutex.unlock(); } else { qInfo(logUdp()) << this->metaObject()->className() << ": txBuffer mutex is locked"; } - purgeOldEntries(); // Delete entries older than PURGE_SECONDS seconds (currently 5) + // Stop using purgeOldEntries() as it is likely slower than just removing the earliest packet. + //qInfo(logUdp()) << this->metaObject()->className() << "RX:" << rxSeqBuf.size() << "TX:" < Date: Thu, 8 Jul 2021 09:28:20 +0100 Subject: [PATCH 3/3] Remove typo in latency display --- udphandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/udphandler.cpp b/udphandler.cpp index de80e8b..c320e7d 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -195,7 +195,7 @@ void udpHandler::dataReceived() if (txSetup.codec == 0) { txString = "(no tx)"; } - emit haveNetworkStatus(QString("
%1 rx latency: %2 ms / rtt: %3 ms / loss: %4/%5
").arg(txString).arg(tempLatency).arg(latency, 3).arg(totallost, 3).arg(totalsent, 3)); + emit haveNetworkStatus(QString("
%1 rx latency: %2 / rtt: %3 ms / loss: %4/%5
").arg(txString).arg(tempLatency).arg(latency, 3).arg(totallost, 3).arg(totalsent, 3)); } break; }