From a3b5c378e15ffacee0d9958d5ba6527d4d42d025 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 23 Aug 2020 13:22:18 +0100 Subject: [PATCH] Make the NXDN Reflector more robust. --- .gitignore | 4 +++ NXDNReflector/NXDNReflector.cpp | 45 +++++++++++++++++++-------------- NXDNReflector/Version.h | 2 +- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index f66aa40..0907130 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ x64 *.user *.VC.db .vs +NXDNGateway/NXDNGateway +NXDNParrot/NXDNParrot +NXDNReflector/NXDNReflector + diff --git a/NXDNReflector/NXDNReflector.cpp b/NXDNReflector/NXDNReflector.cpp index e9bb32f..9cf49ec 100644 --- a/NXDNReflector/NXDNReflector.cpp +++ b/NXDNReflector/NXDNReflector.cpp @@ -216,9 +216,14 @@ void CNXDNReflector::run() LogMessage("Starting NXDNReflector-%s", VERSION); + enum { + ACTIVE_NONE, + ACTIVE_YSF, + ACTIVE_ICOM, + ACTIVE_KENWOOD + } active = ACTIVE_NONE; + CNXDNRepeater* current = NULL; - bool icomActive = false; - bool kenwoodActive = false; unsigned short srcId = 0U; unsigned short dstId = 0U; @@ -316,14 +321,16 @@ void CNXDNReflector::run() if (grp && dstId == tg) { rpt->m_timer.start(); - if (current == NULL && !(icomActive || kenwoodActive)) { + if (current == NULL && active == ACTIVE_NONE) { current = rpt; std::string callsign = lookup->find(srcId); LogMessage("Transmission from %s at %s to %s%u", callsign.c_str(), current->m_callsign.c_str(), grp ? "TG " : "", dstId); + + active = ACTIVE_YSF; } - if (current == rpt) { + if (active == ACTIVE_YSF) { watchdogTimer.start(); for (std::vector::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { @@ -341,8 +348,9 @@ void CNXDNReflector::run() if ((buffer[9U] & 0x08U) == 0x08U) { LogMessage("Received end of transmission"); - watchdogTimer.stop(); current = NULL; + active = ACTIVE_NONE; + watchdogTimer.stop(); } } } @@ -357,7 +365,7 @@ void CNXDNReflector::run() len = m_icomNetwork->read(buffer); if (len > 0U) { if (current == NULL) { - if (!icomActive) { + if (active == ACTIVE_NONE) { if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x01U) { bool tempGrp = (buffer[7U] & 0x20U) == 0x20U; unsigned short tempSrcId = (buffer[8U] << 8) | buffer[9U]; @@ -372,7 +380,7 @@ void CNXDNReflector::run() std::string callsign = lookup->find(srcId); LogMessage("Transmission from %s on Icom Network to %s%u", callsign.c_str(), grp ? "TG " : "", dstId); - icomActive = true; + active = ACTIVE_ICOM; } } if ((buffer[0U] & 0xF0U) == 0x90U && buffer[2U] == 0x09U) { @@ -389,12 +397,12 @@ void CNXDNReflector::run() std::string callsign = lookup->find(srcId); LogMessage("Transmission from %s on Icom Network to %s%u", callsign.c_str(), grp ? "TG " : "", dstId); - icomActive = true; + active = ACTIVE_ICOM; } } } - if (icomActive) { + if (active == ACTIVE_ICOM) { watchdogTimer.start(); for (std::vector::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { @@ -408,12 +416,12 @@ void CNXDNReflector::run() if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x08U) { LogMessage("Received end of transmission"); - icomActive = false; + active = ACTIVE_NONE; watchdogTimer.stop(); } if ((buffer[0U] & 0xF0U) == 0x90U && buffer[2U] == 0x08U) { LogMessage("Received end of transmission"); - icomActive = false; + active = ACTIVE_NONE; watchdogTimer.stop(); } } @@ -425,7 +433,7 @@ void CNXDNReflector::run() len = m_kenwoodNetwork->read(buffer); if (len > 0U) { if (current == NULL) { - if (!kenwoodActive) { + if (active == ACTIVE_NONE) { if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x01U) { bool tempGrp = (buffer[7U] & 0x20U) == 0x20U; unsigned short tempSrcId = (buffer[8U] << 8) | buffer[9U]; @@ -440,7 +448,7 @@ void CNXDNReflector::run() std::string callsign = lookup->find(srcId); LogMessage("Transmission from %s on Kenwood Network to %s%u", callsign.c_str(), grp ? "TG " : "", dstId); - kenwoodActive = true; + active = ACTIVE_KENWOOD; } } if ((buffer[0U] & 0xF0U) == 0x90U && buffer[2U] == 0x09U) { @@ -457,12 +465,12 @@ void CNXDNReflector::run() std::string callsign = lookup->find(srcId); LogMessage("Transmission from %s on Kenwood Network to %s%u", callsign.c_str(), grp ? "TG " : "", dstId); - kenwoodActive = true; + active = ACTIVE_KENWOOD; } } } - if (kenwoodActive) { + if (active == ACTIVE_KENWOOD) { watchdogTimer.start(); for (std::vector::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { @@ -476,12 +484,12 @@ void CNXDNReflector::run() if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && buffer[5U] == 0x08U) { LogMessage("Received end of transmission"); - kenwoodActive = false; + active = ACTIVE_NONE; watchdogTimer.stop(); } if ((buffer[0U] & 0xF0U) == 0x90U && buffer[2U] == 0x08U) { LogMessage("Received end of transmission"); - kenwoodActive = false; + active = ACTIVE_NONE; watchdogTimer.stop(); } } @@ -514,8 +522,7 @@ void CNXDNReflector::run() LogMessage("Network watchdog has expired"); watchdogTimer.stop(); current = NULL; - icomActive = false; - kenwoodActive = false; + active = ACTIVE_NONE; } dumpTimer.clock(ms); diff --git a/NXDNReflector/Version.h b/NXDNReflector/Version.h index e0f936f..a12e5e2 100644 --- a/NXDNReflector/Version.h +++ b/NXDNReflector/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20200822"; +const char* VERSION = "20200823"; #endif