From 503af50070570543a9e6630d2a849c0cd50148d4 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 30 Apr 2017 11:13:35 +0100 Subject: [PATCH] Virtualise the repeater protocol class. --- DMRGateway.cpp | 40 +++++++++++++++---------------- DMRGateway.h | 11 +++++---- DMRGateway.vcxproj | 2 ++ DMRGateway.vcxproj.filters | 6 +++++ MMDVMNetwork.h | 21 ++++++++-------- Makefile | 2 +- RepeaterProtocol.cpp | 23 ++++++++++++++++++ RepeaterProtocol.h | 49 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 118 insertions(+), 36 deletions(-) create mode 100644 RepeaterProtocol.cpp create mode 100644 RepeaterProtocol.h diff --git a/DMRGateway.cpp b/DMRGateway.cpp index 657d70f..db752f3 100644 --- a/DMRGateway.cpp +++ b/DMRGateway.cpp @@ -112,7 +112,7 @@ int main(int argc, char** argv) CDMRGateway::CDMRGateway(const std::string& confFile) : m_conf(confFile), -m_mmdvm(NULL), +m_repeater(NULL), m_dmrNetwork(NULL), m_xlxNetwork(NULL), m_reflector(4000U) @@ -216,11 +216,11 @@ int CDMRGateway::run() for (;;) { unsigned char config[400U]; - unsigned int len = m_mmdvm->getConfig(config); + unsigned int len = m_repeater->getConfig(config); if (len > 0U) break; - m_mmdvm->clock(10U); + m_repeater->clock(10U); CThread::sleep(10U); } @@ -231,7 +231,7 @@ int CDMRGateway::run() unsigned int xlxTG = m_conf.getXLXTG(); unsigned int timeout = m_conf.getTimeout(); - LogInfo("Id: %u", m_mmdvm->getId()); + LogInfo("Id: %u", m_repeater->getId()); LogInfo("XLX Local Slot: %u", xlxSlot); LogInfo("XLX Local TG: %u", xlxTG); LogInfo("Timeout: %us", timeout); @@ -259,7 +259,7 @@ int CDMRGateway::run() while (!m_killed) { CDMRData data; - bool ret = m_mmdvm->read(data); + bool ret = m_repeater->read(data); if (ret) { unsigned int slotNo = data.getSlotNo(); if (slotNo == xlxSlot) { @@ -308,7 +308,7 @@ int CDMRGateway::run() unsigned int slotNo = data.getSlotNo(); if (slotNo == XLX_SLOT) { rptRewrite.process(data); - m_mmdvm->write(data); + m_repeater->write(data); status = DMRGWS_REFLECTOR; timer.start(); } @@ -324,20 +324,20 @@ int CDMRGateway::run() FLCO flco = data.getFLCO(); if (flco != FLCO_GROUP || dstId != xlxTG) { if (status == DMRGWS_NONE || status == DMRGWS_NETWORK) { - m_mmdvm->write(data); + m_repeater->write(data); status = DMRGWS_NETWORK; timer.start(); } } } else { - m_mmdvm->write(data); + m_repeater->write(data); } } unsigned int ms = stopWatch.elapsed(); stopWatch.start(); - m_mmdvm->clock(ms); + m_repeater->clock(ms); m_dmrNetwork->clock(ms); m_xlxNetwork->clock(ms); @@ -353,8 +353,8 @@ int CDMRGateway::run() LogMessage("DMRGateway-%s is exiting on receipt of SIGHUP1", VERSION); - m_mmdvm->close(); - delete m_mmdvm; + m_repeater->close(); + delete m_repeater; m_dmrNetwork->close(); delete m_dmrNetwork; @@ -379,12 +379,12 @@ bool CDMRGateway::createMMDVM() LogInfo(" Local Address: %s", localAddress.c_str()); LogInfo(" Local Port: %u", localPort); - m_mmdvm = new CMMDVMNetwork(rptAddress, rptPort, localAddress, localPort, debug); + m_repeater = new CMMDVMNetwork(rptAddress, rptPort, localAddress, localPort, debug); - bool ret = m_mmdvm->open(); + bool ret = m_repeater->open(); if (!ret) { - delete m_mmdvm; - m_mmdvm = NULL; + delete m_repeater; + m_repeater = NULL; return false; } @@ -396,7 +396,7 @@ bool CDMRGateway::createDMRNetwork() std::string address = m_conf.getDMRNetworkAddress(); unsigned int port = m_conf.getDMRNetworkPort(); unsigned int local = m_conf.getDMRNetworkLocal(); - unsigned int id = m_mmdvm->getId(); + unsigned int id = m_repeater->getId(); std::string password = m_conf.getDMRNetworkPassword(); bool debug = m_conf.getDMRNetworkDebug(); @@ -410,14 +410,14 @@ bool CDMRGateway::createDMRNetwork() m_dmrNetwork = new CDMRNetwork(address, port, local, id, password, "DMR", debug); - std::string options = m_mmdvm->getOptions(); + std::string options = m_repeater->getOptions(); if (!options.empty()) { LogInfo(" Options: %s", options.c_str()); m_dmrNetwork->setOptions(options); } unsigned char config[400U]; - unsigned int len = m_mmdvm->getConfig(config); + unsigned int len = m_repeater->getConfig(config); m_dmrNetwork->setConfig(config, len); @@ -436,7 +436,7 @@ bool CDMRGateway::createXLXNetwork() std::string address = m_conf.getXLXNetworkAddress(); unsigned int port = m_conf.getXLXNetworkPort(); unsigned int local = m_conf.getXLXNetworkLocal(); - unsigned int id = m_mmdvm->getId(); + unsigned int id = m_repeater->getId(); std::string password = m_conf.getXLXNetworkPassword(); std::string options = m_conf.getXLXNetworkOptions(); bool debug = m_conf.getXLXNetworkDebug(); @@ -457,7 +457,7 @@ bool CDMRGateway::createXLXNetwork() } unsigned char config[400U]; - unsigned int len = m_mmdvm->getConfig(config); + unsigned int len = m_repeater->getConfig(config); m_xlxNetwork->setConfig(config, len); diff --git a/DMRGateway.h b/DMRGateway.h index c590fc3..8461701 100644 --- a/DMRGateway.h +++ b/DMRGateway.h @@ -19,6 +19,7 @@ #if !defined(DMRGateway_H) #define DMRGateway_H +#include "RepeaterProtocol.h" #include "MMDVMNetwork.h" #include "DMRNetwork.h" #include "Conf.h" @@ -34,11 +35,11 @@ public: int run(); private: - CConf m_conf; - CMMDVMNetwork* m_mmdvm; - CDMRNetwork* m_dmrNetwork; - CDMRNetwork* m_xlxNetwork; - unsigned int m_reflector; + CConf m_conf; + IRepeaterProtocol* m_repeater; + CDMRNetwork* m_dmrNetwork; + CDMRNetwork* m_xlxNetwork; + unsigned int m_reflector; bool createMMDVM(); bool createDMRNetwork(); diff --git a/DMRGateway.vcxproj b/DMRGateway.vcxproj index 72a1265..81f3c09 100644 --- a/DMRGateway.vcxproj +++ b/DMRGateway.vcxproj @@ -161,6 +161,7 @@ + @@ -187,6 +188,7 @@ + diff --git a/DMRGateway.vcxproj.filters b/DMRGateway.vcxproj.filters index 2c1e3ea..d9ba2e6 100644 --- a/DMRGateway.vcxproj.filters +++ b/DMRGateway.vcxproj.filters @@ -86,6 +86,9 @@ Header Files + + Header Files + @@ -154,5 +157,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/MMDVMNetwork.h b/MMDVMNetwork.h index 620a82b..cc7561e 100644 --- a/MMDVMNetwork.h +++ b/MMDVMNetwork.h @@ -19,6 +19,7 @@ #if !defined(MMDVMNetwork_H) #define MMDVMNetwork_H +#include "RepeaterProtocol.h" #include "UDPSocket.h" #include "Timer.h" #include "RingBuffer.h" @@ -27,27 +28,27 @@ #include #include -class CMMDVMNetwork +class CMMDVMNetwork : public IRepeaterProtocol { public: CMMDVMNetwork(const std::string& rptAddress, unsigned int rptPort, const std::string& localAddress, unsigned int localPort, bool debug); - ~CMMDVMNetwork(); + virtual ~CMMDVMNetwork(); - std::string getOptions() const; + virtual std::string getOptions() const; - unsigned int getConfig(unsigned char* config) const; + virtual unsigned int getConfig(unsigned char* config) const; - unsigned int getId() const; + virtual unsigned int getId() const; - bool open(); + virtual bool open(); - bool read(CDMRData& data); + virtual bool read(CDMRData& data); - bool write(const CDMRData& data); + virtual bool write(const CDMRData& data); - void clock(unsigned int ms); + virtual void clock(unsigned int ms); - void close(); + virtual void close(); private: in_addr m_rptAddress; diff --git a/Makefile b/Makefile index 50f7871..a2e111b 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ LIBS = -lpthread LDFLAGS = -g OBJECTS = BPTC19696.o Conf.o CRC.o DMRData.o DMREmbeddedData.o DMRFullLC.o DMRGateway.o DMRLC.o DMRNetwork.o DMRSlotType.o Golay2087.o Hamming.o Log.o MMDVMNetwork.o \ - Rewrite.o RS129.o SHA256.o StopWatch.o Thread.o Timer.o UDPSocket.o Utils.o + RepeaterProtocol.o Rewrite.o RS129.o SHA256.o StopWatch.o Thread.o Timer.o UDPSocket.o Utils.o all: DMRGateway diff --git a/RepeaterProtocol.cpp b/RepeaterProtocol.cpp new file mode 100644 index 0000000..d49eb62 --- /dev/null +++ b/RepeaterProtocol.cpp @@ -0,0 +1,23 @@ +/* +* Copyright (C) 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 "RepeaterProtocol.h" + +IRepeaterProtocol::~IRepeaterProtocol() +{ +} diff --git a/RepeaterProtocol.h b/RepeaterProtocol.h new file mode 100644 index 0000000..a8dd6d0 --- /dev/null +++ b/RepeaterProtocol.h @@ -0,0 +1,49 @@ +/* +* Copyright (C) 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(RepeaterProtocol_H) +#define RepeaterProtocol_H + +#include "DMRData.h" + +#include + +class IRepeaterProtocol { +public: + virtual ~IRepeaterProtocol() = 0; + + virtual std::string getOptions() const = 0; + + virtual unsigned int getConfig(unsigned char* config) const = 0; + + virtual unsigned int getId() const = 0; + + virtual bool open() = 0; + + virtual bool read(CDMRData& data) = 0; + + virtual bool write(const CDMRData& data) = 0; + + virtual void clock(unsigned int ms) = 0; + + virtual void close() = 0; + +private: +}; + +#endif