diff --git a/NXDNGateway/IcomNetwork.cpp b/NXDNGateway/IcomNetwork.cpp index 655acb9..056eaae 100644 --- a/NXDNGateway/IcomNetwork.cpp +++ b/NXDNGateway/IcomNetwork.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014,2016,2018 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2014,2016,2018,2020 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 @@ -121,3 +121,7 @@ void CIcomNetwork::close() LogMessage("Closing Icom connection"); } + +void CIcomNetwork::clock(unsigned int ms) +{ +} diff --git a/NXDNGateway/IcomNetwork.h b/NXDNGateway/IcomNetwork.h index 38923d1..1c8f02d 100644 --- a/NXDNGateway/IcomNetwork.h +++ b/NXDNGateway/IcomNetwork.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014,2016,2018 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2014,2016,2018,2020 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 @@ -19,24 +19,27 @@ #ifndef IcomNetwork_H #define IcomNetwork_H +#include "RptNetwork.h" #include "UDPSocket.h" #include "Timer.h" #include #include -class CIcomNetwork { +class CIcomNetwork : public IRptNetwork { public: CIcomNetwork(unsigned int localPort, bool debug); - ~CIcomNetwork(); + virtual ~CIcomNetwork(); - bool open(); + virtual bool open(); - bool write(const unsigned char* data, unsigned int length, const in_addr& address, unsigned int port); + virtual bool write(const unsigned char* data, unsigned int length, const in_addr& address, unsigned int port); - bool read(unsigned char* data, in_addr& address, unsigned int& port); + virtual bool read(unsigned char* data, in_addr& address, unsigned int& port); - void close(); + virtual void close(); + + virtual void clock(unsigned int ms); private: CUDPSocket m_socket; diff --git a/NXDNGateway/Makefile b/NXDNGateway/Makefile index 881ee6d..c587deb 100644 --- a/NXDNGateway/Makefile +++ b/NXDNGateway/Makefile @@ -5,7 +5,7 @@ LIBS = -lpthread LDFLAGS = -g OBJECTS = APRSWriter.o APRSWriterThread.o Conf.o GPSHandler.o IcomNetwork.o Log.o Mutex.o NXDNCRC.o NXDNGateway.o NXDNLookup.o NXDNNetwork.o Reflectors.o \ - StopWatch.o TCPSocket.o Thread.o Timer.o UDPSocket.o Utils.o Voice.o + RptNetwork.o StopWatch.o TCPSocket.o Thread.o Timer.o UDPSocket.o Utils.o Voice.o all: NXDNGateway diff --git a/NXDNGateway/NXDNGateway.cpp b/NXDNGateway/NXDNGateway.cpp index b86fb9e..7483fb3 100644 --- a/NXDNGateway/NXDNGateway.cpp +++ b/NXDNGateway/NXDNGateway.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016,2017,2018 by Jonathan Naylor G4KLX +* Copyright (C) 2016,2017,2018,2020 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 @@ -19,6 +19,7 @@ #include "IcomNetwork.h" #include "NXDNNetwork.h" #include "NXDNGateway.h" +#include "RptNetwork.h" #include "NXDNLookup.h" #include "Reflectors.h" #include "GPSHandler.h" @@ -179,8 +180,8 @@ void CNXDNGateway::run() createGPS(); - CIcomNetwork localNetwork(m_conf.getMyPort(), m_conf.getRptDebug()); - ret = localNetwork.open(); + IRptNetwork* localNetwork = new CIcomNetwork(m_conf.getMyPort(), m_conf.getRptDebug()); + ret = localNetwork->open(); if (!ret) { ::LogFinalise(); return; @@ -189,7 +190,8 @@ void CNXDNGateway::run() CNXDNNetwork remoteNetwork(m_conf.getNetworkPort(), m_conf.getCallsign(), m_conf.getNetworkDebug()); ret = remoteNetwork.open(); if (!ret) { - localNetwork.close(); + localNetwork->close(); + delete localNetwork; ::LogFinalise(); return; } @@ -272,7 +274,7 @@ startupId = 9999U; bool grp = (buffer[9U] & 0x01U) == 0x01U; if (grp && currentId == dstId) - localNetwork.write(buffer + 10U, len - 10U, rptAddr, rptPort); + localNetwork->write(buffer + 10U, len - 10U, rptAddr, rptPort); } // Any network activity is proof that the reflector is alive @@ -281,7 +283,7 @@ startupId = 9999U; } // From the MMDVM to the reflector or control data - len = localNetwork.read(buffer, address, port); + len = localNetwork->read(buffer, address, port); if (len > 0U) { // Only process the beginning and ending voice blocks here if ((buffer[0U] == 0x81U || buffer[0U] == 0x83U) && (buffer[5U] == 0x01U || buffer[5U] == 0x08U)) { @@ -381,7 +383,7 @@ startupId = 9999U; if (voice != NULL) { unsigned int length = voice->read(buffer); if (length > 0U) - localNetwork.write(buffer, length, rptAddr, rptPort); + localNetwork->write(buffer, length, rptAddr, rptPort); } unsigned int ms = stopWatch.elapsed(); @@ -389,6 +391,8 @@ startupId = 9999U; reflectors.clock(ms); + localNetwork->clock(ms); + if (voice != NULL) voice->clock(ms); @@ -469,7 +473,8 @@ startupId = 9999U; delete voice; - localNetwork.close(); + localNetwork->close(); + delete localNetwork; remoteNetwork.close(); diff --git a/NXDNGateway/NXDNGateway.vcxproj b/NXDNGateway/NXDNGateway.vcxproj index 97c3696..658c58c 100644 --- a/NXDNGateway/NXDNGateway.vcxproj +++ b/NXDNGateway/NXDNGateway.vcxproj @@ -159,6 +159,7 @@ + @@ -181,6 +182,7 @@ + diff --git a/NXDNGateway/NXDNGateway.vcxproj.filters b/NXDNGateway/NXDNGateway.vcxproj.filters index 5013a7b..bc39c26 100644 --- a/NXDNGateway/NXDNGateway.vcxproj.filters +++ b/NXDNGateway/NXDNGateway.vcxproj.filters @@ -74,6 +74,9 @@ Header Files + + Header Files + @@ -133,5 +136,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/NXDNGateway/RptNetwork.cpp b/NXDNGateway/RptNetwork.cpp new file mode 100644 index 0000000..952ce99 --- /dev/null +++ b/NXDNGateway/RptNetwork.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2009-2014,2016,2018,2020 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 "RptNetwork.h" + +IRptNetwork::~IRptNetwork() +{ +} diff --git a/NXDNGateway/RptNetwork.h b/NXDNGateway/RptNetwork.h new file mode 100644 index 0000000..36ec99b --- /dev/null +++ b/NXDNGateway/RptNetwork.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2009-2014,2016,2018,2020 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. + */ + +#ifndef RptNetwork_H +#define RptNetwork_H + +#if !defined(_WIN32) && !defined(_WIN64) +#include +#include +#include +#include +#include +#include +#include +#include +#else +#include +#endif + +#include +#include + +class IRptNetwork { +public: + virtual ~IRptNetwork() = 0; + + virtual bool open() = 0; + + virtual bool write(const unsigned char* data, unsigned int length, const in_addr& address, unsigned int port) = 0; + + virtual bool read(unsigned char* data, in_addr& address, unsigned int& port) = 0; + + virtual void close() = 0; + + virtual void clock(unsigned int ms) = 0; + +private: +}; + +#endif