From e5d4dab7939672f864ceee05529d1f8ad923f209 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 20 Aug 2017 21:48:49 +0100 Subject: [PATCH] Allow for switching between XLX reflectors. --- Conf.cpp | 244 +++------------- Conf.h | 81 ++---- DMRGateway.cpp | 560 ++++++++++++------------------------- DMRGateway.h | 46 ++- DMRGateway.ini | 23 +- DMRGateway.vcxproj | 2 + DMRGateway.vcxproj.filters | 6 + Makefile | 4 +- Reflectors.cpp | 97 +++++++ Reflectors.h | 57 ++++ XLXHosts.txt | 5 + 11 files changed, 434 insertions(+), 691 deletions(-) create mode 100644 Reflectors.cpp create mode 100644 Reflectors.h create mode 100644 XLXHosts.txt diff --git a/Conf.cpp b/Conf.cpp index 0e90b62..72dcc2d 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -33,8 +33,7 @@ enum SECTION { SECTION_VOICE, SECTION_DMR_NETWORK_1, SECTION_DMR_NETWORK_2, - SECTION_XLX_NETWORK_1, - SECTION_XLX_NETWORK_2 + SECTION_XLX_NETWORK }; CConf::CConf(const std::string& file) : @@ -84,34 +83,16 @@ m_dmrNetwork2TypeRewrites(), m_dmrNetwork2SrcRewrites(), m_dmrNetwork2PassAllPC(), m_dmrNetwork2PassAllTG(), -m_xlxNetwork1Enabled(false), -m_xlxNetwork1Name(), -m_xlxNetwork1Id(0U), -m_xlxNetwork1Address(), -m_xlxNetwork1Port(0U), -m_xlxNetwork1Local(0U), -m_xlxNetwork1Password(), -m_xlxNetwork1Slot(1U), -m_xlxNetwork1TG(8U), -m_xlxNetwork1Base(84000U), -m_xlxNetwork1Startup(4000U), -m_xlxNetwork1Relink(0U), -m_xlxNetwork1Options(), -m_xlxNetwork1Debug(false), -m_xlxNetwork2Enabled(false), -m_xlxNetwork2Name(), -m_xlxNetwork2Id(0U), -m_xlxNetwork2Address(), -m_xlxNetwork2Port(0U), -m_xlxNetwork2Local(0U), -m_xlxNetwork2Password(), -m_xlxNetwork2Slot(1U), -m_xlxNetwork2TG(7U), -m_xlxNetwork2Base(74000U), -m_xlxNetwork2Startup(4000U), -m_xlxNetwork2Relink(0U), -m_xlxNetwork2Options(), -m_xlxNetwork2Debug(false) +m_xlxNetworkEnabled(false), +m_xlxNetworkId(0U), +m_xlxNetworkFile(), +m_xlxNetworkLocal(0U), +m_xlxNetworkSlot(1U), +m_xlxNetworkTG(8U), +m_xlxNetworkBase(84000U), +m_xlxNetworkStartup(4000U), +m_xlxNetworkRelink(0U), +m_xlxNetworkDebug(false) { } @@ -141,10 +122,8 @@ bool CConf::read() section = SECTION_LOG; else if (::strncmp(buffer, "[Voice]", 7U) == 0) section = SECTION_VOICE; - else if (::strncmp(buffer, "[XLX Network 1]", 15U) == 0) - section = SECTION_XLX_NETWORK_1; - else if (::strncmp(buffer, "[XLX Network 2]", 15U) == 0) - section = SECTION_XLX_NETWORK_2; + else if (::strncmp(buffer, "[XLX Network]", 13U) == 0) + section = SECTION_XLX_NETWORK; else if (::strncmp(buffer, "[DMR Network 1]", 15U) == 0) section = SECTION_DMR_NETWORK_1; else if (::strncmp(buffer, "[DMR Network 2]", 15U) == 0) @@ -196,64 +175,27 @@ bool CConf::read() m_voiceLanguage = value; else if (::strcmp(key, "Directory") == 0) m_voiceDirectory = value; - } else if (section == SECTION_XLX_NETWORK_1) { + } else if (section == SECTION_XLX_NETWORK) { if (::strcmp(key, "Enabled") == 0) - m_xlxNetwork1Enabled = ::atoi(value) == 1; - else if (::strcmp(key, "Name") == 0) - m_xlxNetwork1Name = value; + m_xlxNetworkEnabled = ::atoi(value) == 1; else if (::strcmp(key, "Id") == 0) - m_xlxNetwork1Id = (unsigned int)::atoi(value); - else if (::strcmp(key, "Address") == 0) - m_xlxNetwork1Address = value; - else if (::strcmp(key, "Port") == 0) - m_xlxNetwork1Port = (unsigned int)::atoi(value); + m_xlxNetworkId = (unsigned int)::atoi(value); + else if (::strcmp(key, "File") == 0) + m_xlxNetworkFile = value; else if (::strcmp(key, "Local") == 0) - m_xlxNetwork1Local = (unsigned int)::atoi(value); - else if (::strcmp(key, "Password") == 0) - m_xlxNetwork1Password = value; + m_xlxNetworkLocal = (unsigned int)::atoi(value); else if (::strcmp(key, "Slot") == 0) - m_xlxNetwork1Slot = (unsigned int)::atoi(value); + m_xlxNetworkSlot = (unsigned int)::atoi(value); else if (::strcmp(key, "TG") == 0) - m_xlxNetwork1TG = (unsigned int)::atoi(value); + m_xlxNetworkTG = (unsigned int)::atoi(value); else if (::strcmp(key, "Base") == 0) - m_xlxNetwork1Base = (unsigned int)::atoi(value); + m_xlxNetworkBase = (unsigned int)::atoi(value); else if (::strcmp(key, "Startup") == 0) - m_xlxNetwork1Startup = (unsigned int)::atoi(value); + m_xlxNetworkStartup = (unsigned int)::atoi(value); else if (::strcmp(key, "Relink") == 0) - m_xlxNetwork1Relink = (unsigned int)::atoi(value); - else if (::strcmp(key, "Options") == 0) - m_xlxNetwork1Options = value; + m_xlxNetworkRelink = (unsigned int)::atoi(value); else if (::strcmp(key, "Debug") == 0) - m_xlxNetwork1Debug = ::atoi(value) == 1; - } else if (section == SECTION_XLX_NETWORK_2) { - if (::strcmp(key, "Enabled") == 0) - m_xlxNetwork2Enabled = ::atoi(value) == 1; - else if (::strcmp(key, "Name") == 0) - m_xlxNetwork2Name = value; - else if (::strcmp(key, "Id") == 0) - m_xlxNetwork2Id = (unsigned int)::atoi(value); - else if (::strcmp(key, "Address") == 0) - m_xlxNetwork2Address = value; - else if (::strcmp(key, "Port") == 0) - m_xlxNetwork2Port = (unsigned int)::atoi(value); - else if (::strcmp(key, "Local") == 0) - m_xlxNetwork2Local = (unsigned int)::atoi(value); - else if (::strcmp(key, "Password") == 0) - m_xlxNetwork2Password = value; - else if (::strcmp(key, "Slot") == 0) - m_xlxNetwork2Slot = (unsigned int)::atoi(value); - else if (::strcmp(key, "TG") == 0) - m_xlxNetwork2TG = (unsigned int)::atoi(value); - else if (::strcmp(key, "Base") == 0) - m_xlxNetwork2Base = (unsigned int)::atoi(value); - else if (::strcmp(key, "Startup") == 0) - m_xlxNetwork2Startup = (unsigned int)::atoi(value); - else if (::strcmp(key, "Relink") == 0) - m_xlxNetwork2Relink = (unsigned int)::atoi(value); - else if (::strcmp(key, "Options") == 0) - m_xlxNetwork2Options = value; - else if (::strcmp(key, "Debug") == 0) - m_xlxNetwork2Debug = ::atoi(value) == 1; + m_xlxNetworkDebug = ::atoi(value) == 1; } else if (section == SECTION_DMR_NETWORK_1) { if (::strcmp(key, "Enabled") == 0) m_dmrNetwork1Enabled = ::atoi(value) == 1; @@ -505,150 +447,54 @@ std::string CConf::getVoiceDirectory() const return m_voiceDirectory; } -bool CConf::getXLXNetwork1Enabled() const +bool CConf::getXLXNetworkEnabled() const { - return m_xlxNetwork1Enabled; + return m_xlxNetworkEnabled; } -std::string CConf::getXLXNetwork1Name() const +unsigned int CConf::getXLXNetworkId() const { - if (m_xlxNetwork1Name.empty()) - return "XLX-1"; - else - return m_xlxNetwork1Name; + return m_xlxNetworkId; } -unsigned int CConf::getXLXNetwork1Id() const +std::string CConf::getXLXNetworkFile() const { - return m_xlxNetwork1Id; + return m_xlxNetworkFile; } -std::string CConf::getXLXNetwork1Address() const +unsigned int CConf::getXLXNetworkLocal() const { - return m_xlxNetwork1Address; + return m_xlxNetworkLocal; } -unsigned int CConf::getXLXNetwork1Port() const +unsigned int CConf::getXLXNetworkSlot() const { - return m_xlxNetwork1Port; + return m_xlxNetworkSlot; } -unsigned int CConf::getXLXNetwork1Local() const +unsigned int CConf::getXLXNetworkTG() const { - return m_xlxNetwork1Local; + return m_xlxNetworkTG; } -unsigned int CConf::getXLXNetwork1Slot() const +unsigned int CConf::getXLXNetworkBase() const { - return m_xlxNetwork1Slot; + return m_xlxNetworkBase; } -unsigned int CConf::getXLXNetwork1TG() const +unsigned int CConf::getXLXNetworkStartup() const { - return m_xlxNetwork1TG; + return m_xlxNetworkStartup; } -unsigned int CConf::getXLXNetwork1Base() const +unsigned int CConf::getXLXNetworkRelink() const { - return m_xlxNetwork1Base; + return m_xlxNetworkRelink; } -unsigned int CConf::getXLXNetwork1Startup() const +bool CConf::getXLXNetworkDebug() const { - return m_xlxNetwork1Startup; -} - -unsigned int CConf::getXLXNetwork1Relink() const -{ - return m_xlxNetwork1Relink; -} - -std::string CConf::getXLXNetwork1Password() const -{ - return m_xlxNetwork1Password; -} - -std::string CConf::getXLXNetwork1Options() const -{ - return m_xlxNetwork1Options; -} - -bool CConf::getXLXNetwork1Debug() const -{ - return m_xlxNetwork1Debug; -} - -bool CConf::getXLXNetwork2Enabled() const -{ - return m_xlxNetwork2Enabled; -} - -std::string CConf::getXLXNetwork2Name() const -{ - if (m_xlxNetwork2Name.empty()) - return "XLX-2"; - else - return m_xlxNetwork2Name; -} - -unsigned int CConf::getXLXNetwork2Id() const -{ - return m_xlxNetwork2Id; -} - -std::string CConf::getXLXNetwork2Address() const -{ - return m_xlxNetwork2Address; -} - -unsigned int CConf::getXLXNetwork2Port() const -{ - return m_xlxNetwork2Port; -} - -unsigned int CConf::getXLXNetwork2Local() const -{ - return m_xlxNetwork2Local; -} - -unsigned int CConf::getXLXNetwork2Slot() const -{ - return m_xlxNetwork2Slot; -} - -unsigned int CConf::getXLXNetwork2TG() const -{ - return m_xlxNetwork2TG; -} - -unsigned int CConf::getXLXNetwork2Base() const -{ - return m_xlxNetwork2Base; -} - -unsigned int CConf::getXLXNetwork2Startup() const -{ - return m_xlxNetwork2Startup; -} - -unsigned int CConf::getXLXNetwork2Relink() const -{ - return m_xlxNetwork2Relink; -} - -std::string CConf::getXLXNetwork2Password() const -{ - return m_xlxNetwork2Password; -} - -std::string CConf::getXLXNetwork2Options() const -{ - return m_xlxNetwork2Options; -} - -bool CConf::getXLXNetwork2Debug() const -{ - return m_xlxNetwork2Debug; + return m_xlxNetworkDebug; } bool CConf::getDMRNetwork1Enabled() const diff --git a/Conf.h b/Conf.h index f596dbb..a438903 100644 --- a/Conf.h +++ b/Conf.h @@ -116,37 +116,17 @@ public: std::vector getDMRNetwork2PassAllPC() const; std::vector getDMRNetwork2PassAllTG() const; - // The XLX Network 1 section - bool getXLXNetwork1Enabled() const; - std::string getXLXNetwork1Name() const; - unsigned int getXLXNetwork1Id() const; - std::string getXLXNetwork1Address() const; - unsigned int getXLXNetwork1Port() const; - unsigned int getXLXNetwork1Local() const; - std::string getXLXNetwork1Password() const; - unsigned int getXLXNetwork1Slot() const; - unsigned int getXLXNetwork1TG() const; - unsigned int getXLXNetwork1Base() const; - unsigned int getXLXNetwork1Startup() const; - unsigned int getXLXNetwork1Relink() const; - std::string getXLXNetwork1Options() const; - bool getXLXNetwork1Debug() const; - - // The XLX Network 2 section - bool getXLXNetwork2Enabled() const; - std::string getXLXNetwork2Name() const; - unsigned int getXLXNetwork2Id() const; - std::string getXLXNetwork2Address() const; - unsigned int getXLXNetwork2Port() const; - unsigned int getXLXNetwork2Local() const; - std::string getXLXNetwork2Password() const; - unsigned int getXLXNetwork2Slot() const; - unsigned int getXLXNetwork2TG() const; - unsigned int getXLXNetwork2Base() const; - unsigned int getXLXNetwork2Startup() const; - unsigned int getXLXNetwork2Relink() const; - std::string getXLXNetwork2Options() const; - bool getXLXNetwork2Debug() const; + // The XLX Network section + bool getXLXNetworkEnabled() const; + unsigned int getXLXNetworkId() const; + std::string getXLXNetworkFile() const; + unsigned int getXLXNetworkLocal() const; + unsigned int getXLXNetworkSlot() const; + unsigned int getXLXNetworkTG() const; + unsigned int getXLXNetworkBase() const; + unsigned int getXLXNetworkStartup() const; + unsigned int getXLXNetworkRelink() const; + bool getXLXNetworkDebug() const; private: std::string m_file; @@ -200,35 +180,16 @@ private: std::vector m_dmrNetwork2PassAllPC; std::vector m_dmrNetwork2PassAllTG; - bool m_xlxNetwork1Enabled; - std::string m_xlxNetwork1Name; - unsigned int m_xlxNetwork1Id; - std::string m_xlxNetwork1Address; - unsigned int m_xlxNetwork1Port; - unsigned int m_xlxNetwork1Local; - std::string m_xlxNetwork1Password; - unsigned int m_xlxNetwork1Slot; - unsigned int m_xlxNetwork1TG; - unsigned int m_xlxNetwork1Base; - unsigned int m_xlxNetwork1Startup; - unsigned int m_xlxNetwork1Relink; - std::string m_xlxNetwork1Options; - bool m_xlxNetwork1Debug; - - bool m_xlxNetwork2Enabled; - std::string m_xlxNetwork2Name; - unsigned int m_xlxNetwork2Id; - std::string m_xlxNetwork2Address; - unsigned int m_xlxNetwork2Port; - unsigned int m_xlxNetwork2Local; - std::string m_xlxNetwork2Password; - unsigned int m_xlxNetwork2Slot; - unsigned int m_xlxNetwork2TG; - unsigned int m_xlxNetwork2Base; - unsigned int m_xlxNetwork2Startup; - unsigned int m_xlxNetwork2Relink; - std::string m_xlxNetwork2Options; - bool m_xlxNetwork2Debug; + bool m_xlxNetworkEnabled; + unsigned int m_xlxNetworkId; + std::string m_xlxNetworkFile; + unsigned int m_xlxNetworkLocal; + unsigned int m_xlxNetworkSlot; + unsigned int m_xlxNetworkTG; + unsigned int m_xlxNetworkBase; + unsigned int m_xlxNetworkStartup; + unsigned int m_xlxNetworkRelink; + bool m_xlxNetworkDebug; }; #endif diff --git a/DMRGateway.cpp b/DMRGateway.cpp index db7424b..2a513cd 100644 --- a/DMRGateway.cpp +++ b/DMRGateway.cpp @@ -70,8 +70,7 @@ enum DMRGW_STATUS { DMRGWS_NONE, DMRGWS_DMRNETWORK1, DMRGWS_DMRNETWORK2, - DMRGWS_XLXREFLECTOR1, - DMRGWS_XLXREFLECTOR2 + DMRGWS_XLXREFLECTOR }; const char* HEADER1 = "This software is for use on amateur radio networks only,"; @@ -136,30 +135,22 @@ m_dmrNetwork1(NULL), m_dmr1Name(), m_dmrNetwork2(NULL), m_dmr2Name(), -m_xlxNetwork1(NULL), -m_xlx1Name(), -m_xlxNetwork2(NULL), -m_xlx2Name(), -m_xlx1Id(0U), -m_xlx1Reflector(4000U), -m_xlx1Slot(0U), -m_xlx1TG(0U), -m_xlx1Base(0U), -m_xlx1Startup(4000U), -m_xlx1Relink(1000U), -m_xlx1Connected(false), -m_rpt1Rewrite(NULL), -m_xlx1Rewrite(NULL), -m_xlx2Id(0U), -m_xlx2Reflector(4000U), -m_xlx2Slot(0U), -m_xlx2TG(0U), -m_xlx2Base(0U), -m_xlx2Startup(4000U), -m_xlx2Relink(1000U), -m_xlx2Connected(false), -m_rpt2Rewrite(NULL), -m_xlx2Rewrite(NULL), +m_xlxReflectors(NULL), +m_xlxNetwork(NULL), +m_xlxId(0U), +m_xlxNumber(0U), +m_xlxReflector(4000U), +m_xlxSlot(0U), +m_xlxTG(0U), +m_xlxBase(0U), +m_xlxLocal(0U), +m_xlxStartup(950U), +m_xlxRoom(4000U), +m_xlxRelink(1000U), +m_xlxConnected(false), +m_xlxDebug(false), +m_rptRewrite(NULL), +m_xlxRewrite(NULL), m_dmr1NetRewrites(), m_dmr1RFRewrites(), m_dmr2NetRewrites(), @@ -189,10 +180,8 @@ CDMRGateway::~CDMRGateway() for (std::vector::iterator it = m_dmr2Passalls.begin(); it != m_dmr2Passalls.end(); ++it) delete *it; - delete m_rpt1Rewrite; - delete m_xlx1Rewrite; - delete m_rpt2Rewrite; - delete m_xlx2Rewrite; + delete m_rptRewrite; + delete m_xlxRewrite; } int CDMRGateway::run() @@ -317,23 +306,16 @@ int CDMRGateway::run() } - if (m_conf.getXLXNetwork1Enabled()) { - ret = createXLXNetwork1(); - if (!ret) - return 1; - } - - if (m_conf.getXLXNetwork2Enabled()) { - ret = createXLXNetwork2(); + if (m_conf.getXLXNetworkEnabled()) { + ret = createXLXNetwork(); if (!ret) return 1; } unsigned int timeout = m_conf.getTimeout(); - CVoice* voice1 = NULL; - CVoice* voice2 = NULL; - if (m_conf.getVoiceEnabled() && (m_xlxNetwork1 != NULL || m_xlxNetwork2 != NULL)) { + CVoice* voice = NULL; + if (m_conf.getVoiceEnabled() && m_xlxNetwork != NULL) { std::string language = m_conf.getVoiceLanguage(); std::string directory = m_conf.getVoiceDirectory(); @@ -342,22 +324,11 @@ int CDMRGateway::run() LogInfo(" Language: %s", language.c_str()); LogInfo(" Directory: %s", directory.c_str()); - if (m_xlxNetwork1 != NULL) { - voice1 = new CVoice(directory, language, m_repeater->getId(), m_xlx1Slot, m_xlx1TG); - bool ret = voice1->open(); - if (!ret) { - delete voice1; - voice1 = NULL; - } - } - - if (m_xlxNetwork2 != NULL) { - voice2 = new CVoice(directory, language, m_repeater->getId(), m_xlx2Slot, m_xlx2TG); - bool ret = voice2->open(); - if (!ret) { - delete voice2; - voice2 = NULL; - } + voice = new CVoice(directory, language, m_repeater->getId(), m_xlxSlot, m_xlxTG); + bool ret = voice->open(); + if (!ret) { + delete voice; + voice = NULL; } } @@ -389,86 +360,49 @@ int CDMRGateway::run() bool changed = false; while (!m_killed) { - if (m_xlxNetwork1 != NULL) { - bool connected = m_xlxNetwork1->isConnected(); - if (connected && !m_xlx1Connected) { - if (m_xlx1Startup != 4000U) { - writeXLXLink(m_xlx1Id, m_xlx1Startup, m_xlxNetwork1); - LogMessage("%s, Linking to reflector %u at startup", m_xlx1Name.c_str(), m_xlx1Startup); - if (voice1 != NULL) - voice1->linkedTo(m_xlx1Startup); + if (m_xlxNetwork != NULL) { + bool connected = m_xlxNetwork->isConnected(); + if (connected && !m_xlxConnected) { + if (m_xlxRoom != 4000U) { + writeXLXLink(m_xlxId, m_xlxRoom, m_xlxNetwork); + LogMessage("XLX, Linking to reflector %u in XLX%03u", m_xlxRoom, m_xlxNumber); + if (voice != NULL) + voice->linkedTo(m_xlxRoom); } - m_xlx1Reflector = m_xlx1Startup; - m_xlx1Connected = true; - m_xlx1Relink.stop(); - } else if (!connected && m_xlx1Connected) { - if (m_xlx1Reflector != 4000U) { - LogMessage("%s, Unlinking due to loss of connection", m_xlx1Name.c_str()); - if (voice1 != NULL) - voice1->unlinked(); + m_xlxReflector = m_xlxRoom; + m_xlxConnected = true; + m_xlxRelink.stop(); + } else if (!connected && m_xlxConnected) { + if (m_xlxReflector != 4000U) { + LogMessage("XLX, Unlinking from XLX%03u due to loss of connection", m_xlxNumber); + if (voice != NULL) + voice->unlinked(); } - m_xlx1Reflector = 4000U; - m_xlx1Connected = false; - m_xlx1Relink.stop(); - } else if (connected && m_xlx1Relink.isRunning() && m_xlx1Relink.hasExpired()) { - m_xlx1Relink.stop(); + m_xlxReflector = 4000U; + m_xlxConnected = false; + m_xlxRelink.stop(); + } else if (connected && m_xlxRelink.isRunning() && m_xlxRelink.hasExpired()) { + m_xlxRelink.stop(); - if (m_xlx1Startup != 4000U) - writeXLXLink(m_xlx1Id, 4000U, m_xlxNetwork1); + if (m_xlxNumber != m_xlxStartup) { + LogMessage("XLX, Re-linking to startup reflector %u in XLX%03u due to RF inactivity timeout", m_xlxRoom, m_xlxNumber); + linkXLX(m_xlxStartup); + } else { + if (m_xlxRoom != 4000U) + writeXLXLink(m_xlxId, 4000U, m_xlxNetwork); - writeXLXLink(m_xlx1Id, m_xlx1Startup, m_xlxNetwork1); - LogMessage("%s, Re-linking to startup reflector %u due to RF inactivity timeout", m_xlx1Name.c_str(), m_xlx1Startup); - m_xlx1Reflector = m_xlx1Startup; + writeXLXLink(m_xlxId, m_xlxRoom, m_xlxNetwork); + LogMessage("XLX, Re-linking to startup reflector %u in XLX%03u due to RF inactivity timeout", m_xlxRoom, m_xlxNumber); + m_xlxReflector = m_xlxRoom; - if (voice1 != NULL) { - if (m_xlx1Reflector == 4000U) - voice1->unlinked(); - else - voice1->linkedTo(m_xlx1Startup); - } - } - } - - if (m_xlxNetwork2 != NULL) { - bool connected = m_xlxNetwork2->isConnected(); - if (connected && !m_xlx2Connected) { - if (m_xlx2Startup != 4000U) { - writeXLXLink(m_xlx2Id, m_xlx2Startup, m_xlxNetwork2); - LogMessage("%s, Linking to reflector %u at startup", m_xlx2Name.c_str(), m_xlx2Startup); - if (voice2 != NULL) - voice2->linkedTo(m_xlx2Startup); - } - - m_xlx2Reflector = m_xlx2Startup; - m_xlx2Connected = true; - m_xlx2Relink.stop(); - } else if (!connected && m_xlx2Connected) { - if (m_xlx2Reflector != 4000U) { - LogMessage("%s, Unlinking due to loss of connection", m_xlx2Name.c_str()); - if (voice2 != NULL) - voice2->unlinked(); - } - - m_xlx2Reflector = 4000U; - m_xlx2Connected = false; - m_xlx2Relink.stop(); - } else if (connected && m_xlx2Relink.isRunning() && m_xlx2Relink.hasExpired()) { - m_xlx2Relink.stop(); - - if (m_xlx2Startup != 4000U) - writeXLXLink(m_xlx2Id, 4000U, m_xlxNetwork2); - - writeXLXLink(m_xlx2Id, m_xlx2Startup, m_xlxNetwork2); - LogMessage("%s, Re-linking to startup reflector %u due to RF inactivity timeout", m_xlx2Name.c_str(), m_xlx2Startup); - m_xlx2Reflector = m_xlx2Startup; - - if (voice1 != NULL) { - if (m_xlx1Reflector == 4000U) - voice1->unlinked(); - else - voice1->linkedTo(m_xlx2Startup); + if (voice != NULL) { + if (m_xlxReflector == 4000U) + voice->unlinked(); + else + voice->linkedTo(m_xlxStartup); + } } } } @@ -482,114 +416,64 @@ int CDMRGateway::run() unsigned int dstId = data.getDstId(); FLCO flco = data.getFLCO(); - if (flco == FLCO_GROUP && slotNo == m_xlx1Slot && dstId == m_xlx1TG) { - if (m_xlx1Reflector != m_xlx1Startup) - m_xlx1Relink.start(); + if (flco == FLCO_GROUP && slotNo == m_xlxSlot && dstId == m_xlxTG) { + if (m_xlxReflector != m_xlxRoom || m_xlxNumber != m_xlxStartup) + m_xlxRelink.start(); - m_xlx1Rewrite->process(data, false); - m_xlxNetwork1->write(data); - status[slotNo] = DMRGWS_XLXREFLECTOR1; + m_xlxRewrite->process(data, false); + m_xlxNetwork->write(data); + status[slotNo] = DMRGWS_XLXREFLECTOR; timer[slotNo]->start(); - } else if (flco == FLCO_GROUP && slotNo == m_xlx2Slot && dstId == m_xlx2TG) { - if (m_xlx2Reflector != m_xlx2Startup) - m_xlx2Relink.start(); - - m_xlx2Rewrite->process(data, false); - m_xlxNetwork2->write(data); - status[slotNo] = DMRGWS_XLXREFLECTOR2; - timer[slotNo]->start(); - } else if ((dstId <= (m_xlx1Base + 26U) || dstId == (m_xlx1Base + 1000U)) && flco == FLCO_USER_USER && slotNo == m_xlx1Slot && dstId >= m_xlx1Base) { + } else if ((dstId <= (m_xlxBase + 26U) || dstId == (m_xlxBase + 1000U)) && flco == FLCO_USER_USER && slotNo == m_xlxSlot && dstId >= m_xlxBase) { dstId += 4000U; - dstId -= m_xlx1Base; + dstId -= m_xlxBase; - if (dstId != m_xlx1Reflector) { + if (dstId != m_xlxReflector) { if (dstId == 4000U) { - LogMessage("%s, Unlinking", m_xlx1Name.c_str()); + LogMessage("XLX, Unlinking from reflector %u in XLX%03u", m_xlxRoom, m_xlxNumber); } else if (dstId == 5000U) { - if (m_xlx1Reflector != 4000U) - voice1->linkedTo(m_xlx1Reflector); + if (m_xlxReflector != 4000U) + voice->linkedTo(m_xlxReflector); else - voice1->unlinked(); + voice->unlinked(); } else { - if (m_xlx1Reflector != 4000U) - writeXLXLink(srcId, 4000U, m_xlxNetwork1); + if (m_xlxReflector != 4000U) + writeXLXLink(srcId, 4000U, m_xlxNetwork); - LogMessage("%s, Linking to reflector %u", m_xlx1Name.c_str(), dstId); + LogMessage("XLX, Linking to reflector %u in XLX%03u", dstId, m_xlxNumber); } if (dstId != 5000U ) { - writeXLXLink(srcId, dstId, m_xlxNetwork1); - m_xlx1Reflector = dstId; + writeXLXLink(srcId, dstId, m_xlxNetwork); + m_xlxReflector = dstId; changed = true; } - if (m_xlx1Reflector != m_xlx1Startup) - m_xlx1Relink.start(); + if (m_xlxReflector != m_xlxRoom) + m_xlxRelink.start(); else - m_xlx2Relink.stop(); + m_xlxRelink.stop(); } - status[slotNo] = DMRGWS_XLXREFLECTOR1; + status[slotNo] = DMRGWS_XLXREFLECTOR; timer[slotNo]->start(); - if (voice1 != NULL) { + if (voice = NULL) { unsigned char type = data.getDataType(); if (type == DT_TERMINATOR_WITH_LC) { if (changed) { - if (m_xlx1Reflector == 4000U) - voice1->unlinked(); + if (m_xlxReflector == 4000U) + voice->unlinked(); else - voice1->linkedTo(m_xlx1Reflector); - changed = false; - } - } - } - } else if ((dstId <= (m_xlx2Base + 26U) || dstId == (m_xlx2Base + 1000U)) && flco == FLCO_USER_USER && slotNo == m_xlx2Slot && dstId >= m_xlx2Base) { - dstId += 4000U; - dstId -= m_xlx2Base; - - if (dstId != m_xlx2Reflector) { - if (dstId == 4000U) { - LogMessage("%s, Unlinking", m_xlx2Name.c_str()); - } else if (dstId == 5000U) { - if (m_xlx2Reflector != 4000U) - voice2->linkedTo(m_xlx2Reflector); - else - voice2->unlinked(); - } else { - if (m_xlx2Reflector != 4000U) - writeXLXLink(srcId, 4000U, m_xlxNetwork2); - - LogMessage("%s, Linking to reflector %u", m_xlx2Name.c_str(), dstId); - } - - if (dstId != 5000U ) { - writeXLXLink(srcId, dstId, m_xlxNetwork2); - m_xlx2Reflector = dstId; - changed = true; - } - - if (m_xlx2Reflector != m_xlx2Startup) - m_xlx2Relink.start(); - else - m_xlx2Relink.stop(); - } - - status[slotNo] = DMRGWS_XLXREFLECTOR2; - timer[slotNo]->start(); - - if (voice2 != NULL) { - unsigned char type = data.getDataType(); - if (type == DT_TERMINATOR_WITH_LC) { - if (changed) { - if (m_xlx2Reflector == 4000U) - voice2->unlinked(); - else - voice2->linkedTo(m_xlx2Reflector); + voice->linkedTo(m_xlxReflector); changed = false; } } } + } else if (dstId > 8000U && dstId < 9000U && flco == FLCO_USER_USER && slotNo == m_xlxSlot) { + unsigned int number = dstId - 8000U; + if (number != m_xlxNumber) + linkXLX(number); } else { unsigned int slotNo = data.getSlotNo(); unsigned int srcId = data.getSrcId(); @@ -693,40 +577,20 @@ int CDMRGateway::run() } } - if (m_xlxNetwork1 != NULL) { - ret = m_xlxNetwork1->read(data); + if (m_xlxNetwork != NULL) { + ret = m_xlxNetwork->read(data); if (ret) { - if (status[m_xlx1Slot] == DMRGWS_NONE || status[m_xlx1Slot] == DMRGWS_XLXREFLECTOR1) { - bool ret = m_rpt1Rewrite->process(data, false); + if (status[m_xlxSlot] == DMRGWS_NONE || status[m_xlxSlot] == DMRGWS_XLXREFLECTOR) { + bool ret = m_rptRewrite->process(data, false); if (ret) { m_repeater->write(data); - status[m_xlx1Slot] = DMRGWS_XLXREFLECTOR1; - timer[m_xlx1Slot]->start(); + status[m_xlxSlot] = DMRGWS_XLXREFLECTOR; + timer[m_xlxSlot]->start(); } else { unsigned int slotNo = data.getSlotNo(); unsigned int dstId = data.getDstId(); FLCO flco = data.getFLCO(); - LogWarning("%s, Unexpected data from slot %u %s%u", m_xlx1Name.c_str(), slotNo, flco == FLCO_GROUP ? "TG" : "", dstId); - } - } - } - } - - if (m_xlxNetwork2 != NULL) { - ret = m_xlxNetwork2->read(data); - if (ret) { - if (status[m_xlx2Slot] == DMRGWS_NONE || status[m_xlx2Slot] == DMRGWS_XLXREFLECTOR2) { - bool ret = m_rpt2Rewrite->process(data, false); - if (ret) { - m_repeater->write(data); - status[m_xlx2Slot] = DMRGWS_XLXREFLECTOR2; - timer[m_xlx2Slot]->start(); - } - else { - unsigned int slotNo = data.getSlotNo(); - unsigned int dstId = data.getDstId(); - FLCO flco = data.getFLCO(); - LogWarning("%s, Unexpected data from slot %u %s%u", m_xlx2Name.c_str(), slotNo, flco == FLCO_GROUP ? "TG" : "", dstId); + LogWarning("XLX%03u, Unexpected data from slot %u %s%u", m_xlxNumber, slotNo, flco == FLCO_GROUP ? "TG" : "", dstId); } } } @@ -826,10 +690,8 @@ int CDMRGateway::run() unsigned int length; ret = m_repeater->readPosition(buffer, length); if (ret) { - if (m_xlxNetwork1 != NULL) - m_xlxNetwork1->writePosition(buffer, length); - if (m_xlxNetwork2 != NULL) - m_xlxNetwork2->writePosition(buffer, length); + if (m_xlxNetwork != NULL) + m_xlxNetwork->writePosition(buffer, length); if (m_dmrNetwork1 != NULL) m_dmrNetwork1->writePosition(buffer, length); if (m_dmrNetwork2 != NULL) @@ -837,31 +699,20 @@ int CDMRGateway::run() } ret = m_repeater->readTalkerAlias(buffer, length); if (ret) { - if (m_xlxNetwork1 != NULL) - m_xlxNetwork1->writeTalkerAlias(buffer, length); - if (m_xlxNetwork2 != NULL) - m_xlxNetwork2->writeTalkerAlias(buffer, length); + if (m_xlxNetwork != NULL) + m_xlxNetwork->writeTalkerAlias(buffer, length); if (m_dmrNetwork1 != NULL) m_dmrNetwork1->writeTalkerAlias(buffer, length); if (m_dmrNetwork2 != NULL) m_dmrNetwork2->writeTalkerAlias(buffer, length); } - if (voice1 != NULL) { - ret = voice1->read(data); + if (voice != NULL) { + ret = voice->read(data); if (ret) { m_repeater->write(data); - status[m_xlx1Slot] = DMRGWS_XLXREFLECTOR1; - timer[m_xlx1Slot]->start(); - } - } - - if (voice2 != NULL) { - ret = voice2->read(data); - if (ret) { - m_repeater->write(data); - status[m_xlx2Slot] = DMRGWS_XLXREFLECTOR2; - timer[m_xlx2Slot]->start(); + status[m_xlxSlot] = DMRGWS_XLXREFLECTOR; + timer[m_xlxSlot]->start(); } } @@ -870,8 +721,7 @@ int CDMRGateway::run() m_repeater->clock(ms); - m_xlx1Relink.clock(ms); - m_xlx2Relink.clock(ms); + m_xlxRelink.clock(ms); if (m_dmrNetwork1 != NULL) m_dmrNetwork1->clock(ms); @@ -879,17 +729,11 @@ int CDMRGateway::run() if (m_dmrNetwork2 != NULL) m_dmrNetwork2->clock(ms); - if (m_xlxNetwork1 != NULL) - m_xlxNetwork1->clock(ms); + if (m_xlxNetwork != NULL) + m_xlxNetwork->clock(ms); - if (m_xlxNetwork2 != NULL) - m_xlxNetwork2->clock(ms); - - if (voice1 != NULL) - voice1->clock(ms); - - if (voice2 != NULL) - voice2->clock(ms); + if (voice != NULL) + voice->clock(ms); for (unsigned int i = 1U; i < 3U; i++) { timer[i]->clock(ms); @@ -903,8 +747,7 @@ int CDMRGateway::run() CThread::sleep(10U); } - delete voice1; - delete voice2; + delete voice; m_repeater->close(); delete m_repeater; @@ -919,19 +762,16 @@ int CDMRGateway::run() delete m_dmrNetwork2; } - if (m_xlxNetwork1 != NULL) { - m_xlxNetwork1->close(); - delete m_xlxNetwork1; - } - - if (m_xlxNetwork2 != NULL) { - m_xlxNetwork2->close(); - delete m_xlxNetwork2; + if (m_xlxNetwork != NULL) { + m_xlxNetwork->close(); + delete m_xlxNetwork; } delete timer[1U]; delete timer[2U]; + delete m_xlxReflectors; + return 0; } @@ -1205,142 +1045,94 @@ bool CDMRGateway::createDMRNetwork2() return true; } -bool CDMRGateway::createXLXNetwork1() +bool CDMRGateway::createXLXNetwork() { - std::string address = m_conf.getXLXNetwork1Address(); - unsigned int port = m_conf.getXLXNetwork1Port(); - unsigned int local = m_conf.getXLXNetwork1Local(); - m_xlx1Id = m_conf.getXLXNetwork1Id(); - m_xlx1Name = m_conf.getXLXNetwork1Name(); - std::string password = m_conf.getXLXNetwork1Password(); - bool debug = m_conf.getXLXNetwork1Debug(); + std::string fileName = m_conf.getXLXNetworkFile(); - if (m_xlx1Id == 0U) - m_xlx1Id = m_repeater->getId(); + m_xlxReflectors = new CReflectors(fileName); - LogInfo("XLX Network 1 Parameters"); - LogInfo(" Name: %s", m_xlx1Name.c_str()); - LogInfo(" Id: %u", m_xlx1Id); - LogInfo(" Address: %s", address.c_str()); - LogInfo(" Port: %u", port); - if (local > 0U) - LogInfo(" Local: %u", local); - else - LogInfo(" Local: random"); - - m_xlxNetwork1 = new CDMRNetwork(address, port, local, m_xlx1Id, password, m_xlx1Name, debug); - - std::string options = m_conf.getXLXNetwork1Options(); - if (!options.empty()) { - LogInfo(" Options: %s", options.c_str()); - m_xlxNetwork1->setOptions(options); - } - - unsigned char config[400U]; - unsigned int len = m_repeater->getConfig(config); - - m_xlxNetwork1->setConfig(config, len); - - bool ret = m_xlxNetwork1->open(); + bool ret = m_xlxReflectors->load(); if (!ret) { - delete m_xlxNetwork1; - m_xlxNetwork1 = NULL; + delete m_xlxReflectors; return false; } - m_xlx1Slot = m_conf.getXLXNetwork1Slot(); - m_xlx1TG = m_conf.getXLXNetwork1TG(); - m_xlx1Base = m_conf.getXLXNetwork1Base(); - m_xlx1Startup = m_conf.getXLXNetwork1Startup(); + m_xlxLocal = m_conf.getXLXNetworkLocal(); + m_xlxId = m_conf.getXLXNetworkId(); + m_xlxDebug = m_conf.getXLXNetworkDebug(); - unsigned int xlx1Relink = m_conf.getXLXNetwork1Relink(); + if (m_xlxId == 0U) + m_xlxId = m_repeater->getId(); - LogInfo(" Slot: %u", m_xlx1Slot); - LogInfo(" TG: %u", m_xlx1TG); - LogInfo(" Base: %u", m_xlx1Base); + m_xlxSlot = m_conf.getXLXNetworkSlot(); + m_xlxTG = m_conf.getXLXNetworkTG(); + m_xlxBase = m_conf.getXLXNetworkBase(); + m_xlxStartup = m_conf.getXLXNetworkStartup(); - if (m_xlx1Startup != 4000U) - LogInfo(" Startup: %u", m_xlx1Startup); + unsigned int xlxRelink = m_conf.getXLXNetworkRelink(); - if (xlx1Relink > 0U) { - LogInfo(" Relink: %u minutes", xlx1Relink); - m_xlx1Relink.setTimeout(xlx1Relink * 60U); + LogInfo("XLX Network Parameters"); + LogInfo(" Id: %u", m_xlxId); + LogInfo(" Hosts file: %s", fileName.c_str()); + if (m_xlxLocal > 0U) + LogInfo(" Local: %u", m_xlxLocal); + else + LogInfo(" Local: random"); + LogInfo(" Slot: %u", m_xlxSlot); + LogInfo(" TG: %u", m_xlxTG); + LogInfo(" Base: %u", m_xlxBase); + if (m_xlxStartup > 0U) + LogInfo(" Startup: XLX%03u", m_xlxStartup); + if (xlxRelink > 0U) { + m_xlxRelink.setTimeout(xlxRelink * 60U); + LogInfo(" Relink: %u minutes", xlxRelink); } else { LogInfo(" Relink: disabled"); } - m_rpt1Rewrite = new CRewriteTG(m_xlx1Name, XLX_SLOT, XLX_TG, m_xlx1Slot, m_xlx1TG, 1U); - m_xlx1Rewrite = new CRewriteTG(m_xlx1Name, m_xlx1Slot, m_xlx1TG, XLX_SLOT, XLX_TG, 1U); + if (m_xlxStartup > 0U) + linkXLX(m_xlxStartup); + + m_rptRewrite = new CRewriteTG("XLX", XLX_SLOT, XLX_TG, m_xlxSlot, m_xlxTG, 1U); + m_xlxRewrite = new CRewriteTG("XLX", m_xlxSlot, m_xlxTG, XLX_SLOT, XLX_TG, 1U); return true; } -bool CDMRGateway::createXLXNetwork2() +bool CDMRGateway::linkXLX(unsigned int number) { - std::string address = m_conf.getXLXNetwork2Address(); - unsigned int port = m_conf.getXLXNetwork2Port(); - unsigned int local = m_conf.getXLXNetwork2Local(); - m_xlx2Id = m_conf.getXLXNetwork2Id(); - m_xlx2Name = m_conf.getXLXNetwork2Name(); - std::string password = m_conf.getXLXNetwork2Password(); - bool debug = m_conf.getXLXNetwork2Debug(); + CReflector* reflector = m_xlxReflectors->find(number); + if (reflector == NULL) + return false; - if (m_xlx2Id == 0U) - m_xlx2Id = m_repeater->getId(); - - LogInfo("XLX Network 2 Parameters"); - LogInfo(" Name: %s", m_xlx2Name.c_str()); - LogInfo(" Id: %u", m_xlx2Id); - LogInfo(" Address: %s", address.c_str()); - LogInfo(" Port: %u", port); - if (local > 0U) - LogInfo(" Local: %u", local); - else - LogInfo(" Local: random"); - - m_xlxNetwork2 = new CDMRNetwork(address, port, local, m_xlx2Id, password, m_xlx2Name, debug); - - std::string options = m_conf.getXLXNetwork2Options(); - if (!options.empty()) { - LogInfo(" Options: %s", options.c_str()); - m_xlxNetwork2->setOptions(options); + if (m_xlxNetwork != NULL) { + LogMessage("XLX, Disconnecting from XLX%03u", m_xlxNumber); + m_xlxNetwork->close(); + delete m_xlxNetwork; + m_xlxRelink.setTimeout(0U); } + m_xlxConnected = false; + + m_xlxNetwork = new CDMRNetwork(reflector->m_address, reflector->m_port, m_xlxLocal, m_xlxId, reflector->m_password, "XLX", m_xlxDebug); + unsigned char config[400U]; unsigned int len = m_repeater->getConfig(config); - m_xlxNetwork2->setConfig(config, len); + m_xlxNetwork->setConfig(config, len); - bool ret = m_xlxNetwork2->open(); + bool ret = m_xlxNetwork->open(); if (!ret) { - delete m_xlxNetwork2; - m_xlxNetwork2 = NULL; + delete m_xlxNetwork; + m_xlxNetwork = NULL; return false; } - m_xlx2Slot = m_conf.getXLXNetwork2Slot(); - m_xlx2TG = m_conf.getXLXNetwork2TG(); - m_xlx2Base = m_conf.getXLXNetwork2Base(); - m_xlx2Startup = m_conf.getXLXNetwork2Startup(); + m_xlxNumber = number; + m_xlxRoom = reflector->m_startup; + m_xlxRelink.stop(); - unsigned int xlx2Relink = m_conf.getXLXNetwork2Relink(); - - LogInfo(" Slot: %u", m_xlx2Slot); - LogInfo(" TG: %u", m_xlx2TG); - LogInfo(" Base: %u", m_xlx2Base); - - if (m_xlx2Startup != 4000U) - LogInfo(" Startup: %u", m_xlx2Startup); - - if (xlx2Relink > 0U) { - LogInfo(" Relink: %u minutes", xlx2Relink); - m_xlx2Relink.setTimeout(xlx2Relink * 60U); - } else { - LogInfo(" Relink: disabled"); - } - - m_rpt2Rewrite = new CRewriteTG(m_xlx2Name, XLX_SLOT, XLX_TG, m_xlx2Slot, m_xlx2TG, 1U); - m_xlx2Rewrite = new CRewriteTG(m_xlx2Name, m_xlx2Slot, m_xlx2TG, XLX_SLOT, XLX_TG, 1U); + LogMessage("XLX, Connecting to XLX%03u", m_xlxNumber); return true; } diff --git a/DMRGateway.h b/DMRGateway.h index 820f211..01e423e 100644 --- a/DMRGateway.h +++ b/DMRGateway.h @@ -22,6 +22,7 @@ #include "RepeaterProtocol.h" #include "MMDVMNetwork.h" #include "DMRNetwork.h" +#include "Reflectors.h" #include "RewriteTG.h" #include "Rewrite.h" #include "Timer.h" @@ -44,30 +45,22 @@ private: std::string m_dmr1Name; CDMRNetwork* m_dmrNetwork2; std::string m_dmr2Name; - CDMRNetwork* m_xlxNetwork1; - std::string m_xlx1Name; - CDMRNetwork* m_xlxNetwork2; - std::string m_xlx2Name; - unsigned int m_xlx1Id; - unsigned int m_xlx1Reflector; - unsigned int m_xlx1Slot; - unsigned int m_xlx1TG; - unsigned int m_xlx1Base; - unsigned int m_xlx1Startup; - CTimer m_xlx1Relink; - bool m_xlx1Connected; - CRewriteTG* m_rpt1Rewrite; - CRewriteTG* m_xlx1Rewrite; - unsigned int m_xlx2Id; - unsigned int m_xlx2Reflector; - unsigned int m_xlx2Slot; - unsigned int m_xlx2TG; - unsigned int m_xlx2Base; - unsigned int m_xlx2Startup; - CTimer m_xlx2Relink; - bool m_xlx2Connected; - CRewriteTG* m_rpt2Rewrite; - CRewriteTG* m_xlx2Rewrite; + CReflectors* m_xlxReflectors; + CDMRNetwork* m_xlxNetwork; + unsigned int m_xlxId; + unsigned int m_xlxNumber; + unsigned int m_xlxReflector; + unsigned int m_xlxSlot; + unsigned int m_xlxTG; + unsigned int m_xlxBase; + unsigned int m_xlxLocal; + unsigned int m_xlxStartup; + unsigned int m_xlxRoom; + CTimer m_xlxRelink; + bool m_xlxConnected; + bool m_xlxDebug; + CRewriteTG* m_rptRewrite; + CRewriteTG* m_xlxRewrite; std::vector m_dmr1NetRewrites; std::vector m_dmr1RFRewrites; std::vector m_dmr2NetRewrites; @@ -78,8 +71,9 @@ private: bool createMMDVM(); bool createDMRNetwork1(); bool createDMRNetwork2(); - bool createXLXNetwork1(); - bool createXLXNetwork2(); + bool createXLXNetwork(); + + bool linkXLX(unsigned int number); void writeXLXLink(unsigned int srcId, unsigned int dstId, CDMRNetwork* network); }; diff --git a/DMRGateway.ini b/DMRGateway.ini index a904d98..3387b9d 100644 --- a/DMRGateway.ini +++ b/DMRGateway.ini @@ -20,32 +20,15 @@ Enabled=1 Language=en_GB Directory=./Audio -[XLX Network 1] +[XLX Network] Enabled=1 -Name=XLX950 -Address=xlx950.epf.lu -Port=62030 +File=XLXHosts.txt # Local=3351 -# Options= Slot=1 TG=6 Base=64000 -Startup=4005 +Startup=950 Relink=10 -Password=passw0rd -Debug=0 - -[XLX Network 2] -Enabled=0 -Name=XLX000 -Address=44.131.4.1 -Port=62030 -# Local=3351 -# Options= -Slot=1 -TG=7 -Base=74000 -Password=passw0rd Debug=0 # BrandMeister diff --git a/DMRGateway.vcxproj b/DMRGateway.vcxproj index 985bb7a..2cb8e1b 100644 --- a/DMRGateway.vcxproj +++ b/DMRGateway.vcxproj @@ -173,6 +173,7 @@ + @@ -212,6 +213,7 @@ + diff --git a/DMRGateway.vcxproj.filters b/DMRGateway.vcxproj.filters index 9b5a406..239becf 100644 --- a/DMRGateway.vcxproj.filters +++ b/DMRGateway.vcxproj.filters @@ -125,6 +125,9 @@ Header Files + + Header Files + @@ -232,5 +235,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/Makefile b/Makefile index ac8fa2a..b0ae9f3 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ LIBS = -lpthread LDFLAGS = -g OBJECTS = BPTC19696.o Conf.o CRC.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREmbeddedData.o DMREMB.o DMRFullLC.o DMRGateway.o DMRLC.o DMRNetwork.o DMRSlotType.o \ - Golay2087.o Hamming.o Log.o MMDVMNetwork.o PassAllPC.o PassAllTG.o QR1676.o RepeaterProtocol.o Rewrite.o RewritePC.o RewriteSrc.o RewriteTG.o RewriteType.o \ - RS129.o SHA256.o StopWatch.o Sync.o Thread.o Timer.o UDPSocket.o Utils.o Voice.o + Golay2087.o Hamming.o Log.o MMDVMNetwork.o PassAllPC.o PassAllTG.o QR1676.o Reflectors.o RepeaterProtocol.o Rewrite.o RewritePC.o RewriteSrc.o RewriteTG.o \ + RewriteType.o RS129.o SHA256.o StopWatch.o Sync.o Thread.o Timer.o UDPSocket.o Utils.o Voice.o all: DMRGateway diff --git a/Reflectors.cpp b/Reflectors.cpp new file mode 100644 index 0000000..4c0f428 --- /dev/null +++ b/Reflectors.cpp @@ -0,0 +1,97 @@ +/* +* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "Reflectors.h" +#include "Log.h" + +#include +#include +#include +#include +#include +#include + +CReflectors::CReflectors(const std::string& hostsFile) : +m_hostsFile(hostsFile), +m_reflectors() +{ +} + +CReflectors::~CReflectors() +{ + for (std::vector::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) + delete *it; + + m_reflectors.clear(); +} + +bool CReflectors::load() +{ + for (std::vector::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) + delete *it; + + m_reflectors.clear(); + + FILE* fp = ::fopen(m_hostsFile.c_str(), "rt"); + if (fp != NULL) { + char buffer[100U]; + while (::fgets(buffer, 100U, fp) != NULL) { + if (buffer[0U] == '#') + continue; + + char* p1 = ::strtok(buffer, ";\r\n"); + char* p2 = ::strtok(NULL, ";\r\n"); + char* p3 = ::strtok(NULL, ";\r\n"); + char* p4 = ::strtok(NULL, ";\r\n"); + char* p5 = ::strtok(NULL, "\r\n"); + + if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL && p5 != NULL) { + CReflector* refl = new CReflector; + refl->m_id = (unsigned int)::atoi(p1); + refl->m_address = std::string(p2); + refl->m_port = (unsigned int)::atoi(p3); + refl->m_startup = (unsigned int)::atoi(p4); + refl->m_password = std::string(p5); + m_reflectors.push_back(refl); + } + } + + ::fclose(fp); + } + + size_t size = m_reflectors.size(); + LogInfo("Loaded %u XLX reflectors", size); + + size = m_reflectors.size(); + if (size == 0U) + return false; + + return true; +} + +CReflector* CReflectors::find(unsigned int id) +{ + for (std::vector::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) { + if (id == (*it)->m_id) + return *it; + } + + LogMessage("Trying to find non existent XLX reflector with an id of %u", id); + + return NULL; +} diff --git a/Reflectors.h b/Reflectors.h new file mode 100644 index 0000000..4bc62b3 --- /dev/null +++ b/Reflectors.h @@ -0,0 +1,57 @@ +/* +* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#if !defined(Reflectors_H) +#define Reflectors_H + +#include +#include + +class CReflector { +public: + CReflector() : + m_id(0U), + m_address(), + m_port(0U), + m_startup(0U), + m_password() + { + } + + unsigned int m_id; + std::string m_address; + unsigned int m_port; + unsigned int m_startup; + std::string m_password; +}; + +class CReflectors { +public: + CReflectors(const std::string& hostsFile); + ~CReflectors(); + + bool load(); + + CReflector* find(unsigned int id); + +private: + std::string m_hostsFile; + std::vector m_reflectors; +}; + +#endif diff --git a/XLXHosts.txt b/XLXHosts.txt new file mode 100644 index 0000000..a47ac16 --- /dev/null +++ b/XLXHosts.txt @@ -0,0 +1,5 @@ +# The format of this file is: +# XLX Number;host;port;default;password + +# XLX950 +950;xlx950.epf.lu;62030;4005;passw0rd