From 1ca079041f834020b8c679df252ee079c6136960 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Wed, 5 Sep 2018 14:57:40 -0400 Subject: [PATCH] Updated APRSISClient to drop packets older than 5 minutes --- APRSISClient.cpp | 16 ++++++++++++++-- APRSISClient.h | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/APRSISClient.cpp b/APRSISClient.cpp index 49a4f9c..7b43dbb 100644 --- a/APRSISClient.cpp +++ b/APRSISClient.cpp @@ -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; diff --git a/APRSISClient.h b/APRSISClient.h index d078a4e..3e7a59e 100644 --- a/APRSISClient.h +++ b/APRSISClient.h @@ -1,6 +1,7 @@ #ifndef APRSISCLIENT_H #define APRSISCLIENT_H +#include #include #include #include @@ -55,7 +56,7 @@ private: QString m_localGrid; QString m_localPasscode; - QQueue m_frameQueue; + QQueue> m_frameQueue; QString m_host; quint16 m_port; QTimer m_timer;