From 88eacf7422af8a0d7e30db2d5213eeb583ea907f Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 13 Jun 2018 19:41:35 +0100 Subject: [PATCH] Optionally suppress time messages when messages are being queued. --- Conf.cpp | 9 +++++++++ Conf.h | 2 ++ DAPNETGateway.cpp | 49 ++++++++++++++++++++++++----------------------- DAPNETGateway.h | 2 ++ DAPNETGateway.ini | 1 + 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index 7951393..080dfce 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -48,6 +48,7 @@ m_logFileRoot(), m_dapnetAddress(), m_dapnetPort(0U), m_dapnetAuthKey(), +m_dapnetSuppressTime(true), m_dapnetDebug(false) { } @@ -118,6 +119,8 @@ bool CConf::read() m_dapnetPort = (unsigned int)::atoi(value); else if (::strcmp(key, "AuthKey") == 0) m_dapnetAuthKey = value; + else if (::strcmp(key, "SuppressTimeWhenBusy") == 0) + m_dapnetSuppressTime = ::atoi(value) == 1; else if (::strcmp(key, "Debug") == 0) m_dapnetDebug = ::atoi(value) == 1; } @@ -193,7 +196,13 @@ std::string CConf::getDAPNETAuthKey() const return m_dapnetAuthKey; } +bool CConf::getDAPNETSuppressTime() const +{ + return m_dapnetSuppressTime; +} + bool CConf::getDAPNETDebug() const { return m_dapnetDebug; } + diff --git a/Conf.h b/Conf.h index 47344b2..113ea22 100644 --- a/Conf.h +++ b/Conf.h @@ -47,6 +47,7 @@ public: std::string getDAPNETAddress() const; unsigned int getDAPNETPort() const; std::string getDAPNETAuthKey() const; + bool getDAPNETSuppressTime() const; bool getDAPNETDebug() const; private: @@ -66,6 +67,7 @@ private: std::string m_dapnetAddress; unsigned int m_dapnetPort; std::string m_dapnetAuthKey; + bool m_dapnetSuppressTime; bool m_dapnetDebug; }; diff --git a/DAPNETGateway.cpp b/DAPNETGateway.cpp index 35e5cdd..f0c42fb 100644 --- a/DAPNETGateway.cpp +++ b/DAPNETGateway.cpp @@ -49,8 +49,6 @@ const char* DEFAULT_INI_FILE = "/etc/DAPNETGateway.ini"; const unsigned char FUNCTIONAL_NUMERIC = 0U; const unsigned char FUNCTIONAL_ALPHANUMERIC = 3U; -const unsigned int FRAME_TIME = 1000U * (17U * 32U) / 1200U; - int main(int argc, char** argv) { const char* iniFile = DEFAULT_INI_FILE; @@ -218,15 +216,11 @@ int CDAPNETGateway::run() ::LogMessage("Logged into the DAPNET network"); - CTimer messageTimer(1000U, 0U, FRAME_TIME); + CTimer messageTimer(1000U, 0U, 200U); CStopWatch stopWatch; stopWatch.start(); - unsigned int calls = 0U; - - bool tx = false; - LogMessage("Starting DAPNETGateway-%s", VERSION); for (;;) { @@ -255,8 +249,16 @@ int CDAPNETGateway::run() CPOCSAGMessage* message = m_dapnetNetwork->readMessage(); if (message != NULL) { - LogDebug("Queueing message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message); - m_queue.push_front(message); + if (!messageTimer.isRunning() || !m_queue.empty()) { + if (!isTimeMessage(message)) { + LogDebug("Queueing message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message); + m_queue.push_front(message); + } else { + LogDebug("Rejecting message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message); + } + } else { + LogMessage("Sending message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message); + } } unsigned int ms = stopWatch.elapsed(); @@ -264,22 +266,9 @@ int CDAPNETGateway::run() messageTimer.clock(ms); if (messageTimer.isRunning() && messageTimer.hasExpired()) { - if (!m_queue.empty()) { - if (!tx) - calls = 0U; - - tx = true; - + if (!m_queue.empty()) sendData(); - calls++; - } else { - if (tx) - LogMessage("Sent %u messages within that batch", calls); - - tx = false; - } - messageTimer.start(); } @@ -305,7 +294,7 @@ bool CDAPNETGateway::sendData() if (!m_queue.empty()) { CPOCSAGMessage* message = m_queue.back(); m_queue.pop_back(); - LogDebug("Sending message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message); + LogMessage("Sending message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message); m_pocsagNetwork->write(message); delete message; return true; @@ -328,3 +317,15 @@ bool CDAPNETGateway::recover() return false; } + +bool CDAPNETGateway::isTimeMessage(const CPOCSAGMessage* message) const +{ + if (message->m_type == 5U && message->m_functional == FUNCTIONAL_NUMERIC) + return true; + + if (message->m_type == 6U && message->m_functional == FUNCTIONAL_ALPHANUMERIC && ::memcmp(message->m_message, "XTIME=", 6U) == 0) + return true; + + return false; +} + diff --git a/DAPNETGateway.h b/DAPNETGateway.h index ebd4079..088685e 100644 --- a/DAPNETGateway.h +++ b/DAPNETGateway.h @@ -43,6 +43,8 @@ private: bool sendData(); bool recover(); + bool isTimeMessage(const CPOCSAGMessage* message) const; }; #endif + diff --git a/DAPNETGateway.ini b/DAPNETGateway.ini index cd9fdb7..c701985 100644 --- a/DAPNETGateway.ini +++ b/DAPNETGateway.ini @@ -17,4 +17,5 @@ FileRoot=DAPNETGateway Address=dapnet.afu.rwth-aachen.de Port=43434 AuthKey=TOPSECRET +SuppressTimeWhenBusy=1 Debug=0