Virtualise the repeater protocol class.

This commit is contained in:
Jonathan Naylor
2017-04-30 11:13:35 +01:00
parent 847de9f470
commit 503af50070
8 changed files with 118 additions and 36 deletions

View File

@@ -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);

View File

@@ -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();

View File

@@ -161,6 +161,7 @@
<ClInclude Include="Hamming.h" />
<ClInclude Include="Log.h" />
<ClInclude Include="MMDVMNetwork.h" />
<ClInclude Include="RepeaterProtocol.h" />
<ClInclude Include="Rewrite.h" />
<ClInclude Include="RingBuffer.h" />
<ClInclude Include="RS129.h" />
@@ -187,6 +188,7 @@
<ClCompile Include="Hamming.cpp" />
<ClCompile Include="Log.cpp" />
<ClCompile Include="MMDVMNetwork.cpp" />
<ClCompile Include="RepeaterProtocol.cpp" />
<ClCompile Include="Rewrite.cpp" />
<ClCompile Include="RS129.cpp" />
<ClCompile Include="SHA256.cpp" />

View File

@@ -86,6 +86,9 @@
<ClInclude Include="CRC.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RepeaterProtocol.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Conf.cpp">
@@ -154,5 +157,8 @@
<ClCompile Include="CRC.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RepeaterProtocol.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -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 <string>
#include <cstdint>
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;

View File

@@ -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

23
RepeaterProtocol.cpp Normal file
View File

@@ -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()
{
}

49
RepeaterProtocol.h Normal file
View File

@@ -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 <string>
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