Updated APRSISClient to drop packets older than 5 minutes

This commit is contained in:
Jordan Sherer 2018-09-05 14:57:40 -04:00
parent e922df7635
commit 1ca079041f
2 changed files with 16 additions and 3 deletions

View File

@ -4,6 +4,8 @@
#include "varicode.h" #include "varicode.h"
const int PACKET_TIMEOUT_SECONDS = 300;
APRSISClient::APRSISClient(QString host, quint16 port, QObject *parent): APRSISClient::APRSISClient(QString host, quint16 port, QObject *parent):
QTcpSocket(parent), QTcpSocket(parent),
m_host(host), m_host(host),
@ -207,7 +209,7 @@ void APRSISClient::enqueueThirdParty(QString theircall, QString payload){
} }
void APRSISClient::enqueueRaw(QString aprsFrame){ void APRSISClient::enqueueRaw(QString aprsFrame){
m_frameQueue.enqueue(aprsFrame); m_frameQueue.enqueue({ aprsFrame, QDateTime::currentDateTimeUtc() });
} }
void APRSISClient::processQueue(bool disconnect){ void APRSISClient::processQueue(bool disconnect){
@ -254,8 +256,18 @@ void APRSISClient::processQueue(bool disconnect){
} }
while(!m_frameQueue.isEmpty()){ 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){ if(write(data) == -1){
qDebug() << "APRSISClient Write Error:" << errorString(); qDebug() << "APRSISClient Write Error:" << errorString();
return; return;

View File

@ -1,6 +1,7 @@
#ifndef APRSISCLIENT_H #ifndef APRSISCLIENT_H
#define APRSISCLIENT_H #define APRSISCLIENT_H
#include <QDateTime>
#include <QTcpSocket> #include <QTcpSocket>
#include <QQueue> #include <QQueue>
#include <QPair> #include <QPair>
@ -55,7 +56,7 @@ private:
QString m_localGrid; QString m_localGrid;
QString m_localPasscode; QString m_localPasscode;
QQueue<QString> m_frameQueue; QQueue<QPair<QString, QDateTime>> m_frameQueue;
QString m_host; QString m_host;
quint16 m_port; quint16 m_port;
QTimer m_timer; QTimer m_timer;