Updated APRSISClient to drop packets older than 5 minutes
This commit is contained in:
parent
e922df7635
commit
1ca079041f
@ -4,6 +4,8 @@
|
||||
|
||||
#include "varicode.h"
|
||||
|
||||
const int PACKET_TIMEOUT_SECONDS = 300;
|
||||
|
||||
APRSISClient::APRSISClient(QString host, quint16 port, QObject *parent):
|
||||
QTcpSocket(parent),
|
||||
m_host(host),
|
||||
@ -207,7 +209,7 @@ void APRSISClient::enqueueThirdParty(QString theircall, QString payload){
|
||||
}
|
||||
|
||||
void APRSISClient::enqueueRaw(QString aprsFrame){
|
||||
m_frameQueue.enqueue(aprsFrame);
|
||||
m_frameQueue.enqueue({ aprsFrame, QDateTime::currentDateTimeUtc() });
|
||||
}
|
||||
|
||||
void APRSISClient::processQueue(bool disconnect){
|
||||
@ -254,8 +256,18 @@ void APRSISClient::processQueue(bool disconnect){
|
||||
}
|
||||
|
||||
while(!m_frameQueue.isEmpty()){
|
||||
QByteArray data = m_frameQueue.head().toLocal8Bit();
|
||||
auto pair = m_frameQueue.head();
|
||||
auto frame = pair.first;
|
||||
auto timestamp = pair.second;
|
||||
|
||||
// if the packet is older than the timeout, drop it.
|
||||
if(timestamp.secsTo(QDateTime::currentDateTimeUtc()) > PACKET_TIMEOUT_SECONDS){
|
||||
qDebug() << "APRSISClient Packet Timeout:" << frame;
|
||||
m_frameQueue.dequeue();
|
||||
continue;
|
||||
}
|
||||
|
||||
QByteArray data = frame.toLocal8Bit();
|
||||
if(write(data) == -1){
|
||||
qDebug() << "APRSISClient Write Error:" << errorString();
|
||||
return;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef APRSISCLIENT_H
|
||||
#define APRSISCLIENT_H
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QTcpSocket>
|
||||
#include <QQueue>
|
||||
#include <QPair>
|
||||
@ -55,7 +56,7 @@ private:
|
||||
QString m_localGrid;
|
||||
QString m_localPasscode;
|
||||
|
||||
QQueue<QString> m_frameQueue;
|
||||
QQueue<QPair<QString, QDateTime>> m_frameQueue;
|
||||
QString m_host;
|
||||
quint16 m_port;
|
||||
QTimer m_timer;
|
||||
|
Loading…
Reference in New Issue
Block a user