diff --git a/Conf.cpp b/Conf.cpp index 1c1a07e..aa12d56 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -61,6 +61,8 @@ m_dmrNetwork1Password(), m_dmrNetwork1Debug(false), m_dmrNetwork1TGRewrites(), m_dmrNetwork1PCRewrites(), +m_dmrNetwork1TypeRewrites(), +m_dmrNetwork1SrcRewrites(), m_dmrNetwork2Enabled(false), m_dmrNetwork2Id(0U), m_dmrNetwork2Address(), @@ -70,6 +72,8 @@ m_dmrNetwork2Password(), m_dmrNetwork2Debug(false), m_dmrNetwork2TGRewrites(), m_dmrNetwork2PCRewrites(), +m_dmrNetwork2TypeRewrites(), +m_dmrNetwork2SrcRewrites(), m_xlxNetworkEnabled(false), m_xlxNetworkId(0U), m_xlxNetworkAddress(), @@ -200,13 +204,15 @@ bool CConf::read() char* p1 = ::strtok(value, ", "); char* p2 = ::strtok(NULL, ", "); char* p3 = ::strtok(NULL, ", "); - char* p4 = ::strtok(NULL, " \r\n"); - if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL) { + char* p4 = ::strtok(NULL, ", "); + char* p5 = ::strtok(NULL, " \r\n"); + if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL && p5 != NULL) { CTGRewriteStruct rewrite; rewrite.m_fromSlot = ::atoi(p1); rewrite.m_fromTG = ::atoi(p2); rewrite.m_toSlot = ::atoi(p3); rewrite.m_toTG = ::atoi(p4); + rewrite.m_range = ::atoi(p5); m_dmrNetwork1TGRewrites.push_back(rewrite); } } else if (::strcmp(key, "PCRewrite") == 0) { @@ -224,6 +230,32 @@ bool CConf::read() rewrite.m_range = ::atoi(p5); m_dmrNetwork1PCRewrites.push_back(rewrite); } + } else if (::strcmp(key, "TypeRewrite") == 0) { + char* p1 = ::strtok(value, ", "); + char* p2 = ::strtok(NULL, ", "); + char* p3 = ::strtok(NULL, ", "); + char* p4 = ::strtok(NULL, " \r\n"); + if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL) { + CTypeRewriteStruct rewrite; + rewrite.m_fromSlot = ::atoi(p1); + rewrite.m_fromId = ::atoi(p2); + rewrite.m_toSlot = ::atoi(p3); + rewrite.m_toTG = ::atoi(p4); + m_dmrNetwork1TypeRewrites.push_back(rewrite); + } + } else if (::strcmp(key, "SrcRewrite") == 0) { + char* p1 = ::strtok(value, ", "); + char* p2 = ::strtok(NULL, ", "); + char* p3 = ::strtok(NULL, ", "); + char* p4 = ::strtok(NULL, " \r\n"); + if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL) { + CSrcRewriteStruct rewrite; + rewrite.m_fromSlot = ::atoi(p1); + rewrite.m_fromId = ::atoi(p2); + rewrite.m_toSlot = ::atoi(p3); + rewrite.m_toTG = ::atoi(p4); + m_dmrNetwork1SrcRewrites.push_back(rewrite); + } } } else if (section == SECTION_DMR_NETWORK_2) { if (::strcmp(key, "Enabled") == 0) @@ -244,13 +276,15 @@ bool CConf::read() char* p1 = ::strtok(value, ", "); char* p2 = ::strtok(NULL, ", "); char* p3 = ::strtok(NULL, ", "); - char* p4 = ::strtok(NULL, " \r\n"); - if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL) { + char* p4 = ::strtok(NULL, ", "); + char* p5 = ::strtok(NULL, " \r\n"); + if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL && p5 != NULL) { CTGRewriteStruct rewrite; rewrite.m_fromSlot = ::atoi(p1); rewrite.m_fromTG = ::atoi(p2); rewrite.m_toSlot = ::atoi(p3); rewrite.m_toTG = ::atoi(p4); + rewrite.m_range = ::atoi(p5); m_dmrNetwork2TGRewrites.push_back(rewrite); } } else if (::strcmp(key, "PCRewrite") == 0) { @@ -268,6 +302,32 @@ bool CConf::read() rewrite.m_range = ::atoi(p5); m_dmrNetwork2PCRewrites.push_back(rewrite); } + } else if (::strcmp(key, "TypeRewrite") == 0) { + char* p1 = ::strtok(value, ", "); + char* p2 = ::strtok(NULL, ", "); + char* p3 = ::strtok(NULL, ", "); + char* p4 = ::strtok(NULL, " \r\n"); + if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL) { + CTypeRewriteStruct rewrite; + rewrite.m_fromSlot = ::atoi(p1); + rewrite.m_fromId = ::atoi(p2); + rewrite.m_toSlot = ::atoi(p3); + rewrite.m_toTG = ::atoi(p4); + m_dmrNetwork2TypeRewrites.push_back(rewrite); + } + } else if (::strcmp(key, "SrcRewrite") == 0) { + char* p1 = ::strtok(value, ", "); + char* p2 = ::strtok(NULL, ", "); + char* p3 = ::strtok(NULL, ", "); + char* p4 = ::strtok(NULL, " \r\n"); + if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL) { + CSrcRewriteStruct rewrite; + rewrite.m_fromSlot = ::atoi(p1); + rewrite.m_fromId = ::atoi(p2); + rewrite.m_toSlot = ::atoi(p3); + rewrite.m_toTG = ::atoi(p4); + m_dmrNetwork2SrcRewrites.push_back(rewrite); + } } } } @@ -442,6 +502,16 @@ std::vector CConf::getDMRNetwork1PCRewrites() const return m_dmrNetwork1PCRewrites; } +std::vector CConf::getDMRNetwork1TypeRewrites() const +{ + return m_dmrNetwork1TypeRewrites; +} + +std::vector CConf::getDMRNetwork1SrcRewrites() const +{ + return m_dmrNetwork1SrcRewrites; +} + bool CConf::getDMRNetwork2Enabled() const { return m_dmrNetwork2Enabled; @@ -486,3 +556,13 @@ std::vector CConf::getDMRNetwork2PCRewrites() const { return m_dmrNetwork2PCRewrites; } + +std::vector CConf::getDMRNetwork2TypeRewrites() const +{ + return m_dmrNetwork2TypeRewrites; +} + +std::vector CConf::getDMRNetwork2SrcRewrites() const +{ + return m_dmrNetwork2SrcRewrites; +} diff --git a/Conf.h b/Conf.h index f078699..549157e 100644 --- a/Conf.h +++ b/Conf.h @@ -27,6 +27,7 @@ struct CTGRewriteStruct { unsigned int m_fromTG; unsigned int m_toSlot; unsigned int m_toTG; + unsigned int m_range; }; struct CPCRewriteStruct { @@ -37,6 +38,20 @@ struct CPCRewriteStruct { unsigned int m_range; }; +struct CTypeRewriteStruct { + unsigned int m_fromSlot; + unsigned int m_fromId; + unsigned int m_toSlot; + unsigned int m_toTG; +}; + +struct CSrcRewriteStruct { + unsigned int m_fromSlot; + unsigned int m_fromId; + unsigned int m_toSlot; + unsigned int m_toTG; +}; + class CConf { public: @@ -73,8 +88,10 @@ public: unsigned int getDMRNetwork1Local() const; std::string getDMRNetwork1Password() const; bool getDMRNetwork1Debug() const; - std::vector getDMRNetwork1TGRewrites() const; - std::vector getDMRNetwork1PCRewrites() const; + std::vector getDMRNetwork1TGRewrites() const; + std::vector getDMRNetwork1PCRewrites() const; + std::vector getDMRNetwork1TypeRewrites() const; + std::vector getDMRNetwork1SrcRewrites() const; // The DMR Network 2 section bool getDMRNetwork2Enabled() const; @@ -84,8 +101,10 @@ public: unsigned int getDMRNetwork2Local() const; std::string getDMRNetwork2Password() const; bool getDMRNetwork2Debug() const; - std::vector getDMRNetwork2TGRewrites() const; - std::vector getDMRNetwork2PCRewrites() const; + std::vector getDMRNetwork2TGRewrites() const; + std::vector getDMRNetwork2PCRewrites() const; + std::vector getDMRNetwork2TypeRewrites() const; + std::vector getDMRNetwork2SrcRewrites() const; // The XLX Network section bool getXLXNetworkEnabled() const; @@ -125,8 +144,10 @@ private: unsigned int m_dmrNetwork1Local; std::string m_dmrNetwork1Password; bool m_dmrNetwork1Debug; - std::vector m_dmrNetwork1TGRewrites; - std::vector m_dmrNetwork1PCRewrites; + std::vector m_dmrNetwork1TGRewrites; + std::vector m_dmrNetwork1PCRewrites; + std::vector m_dmrNetwork1TypeRewrites; + std::vector m_dmrNetwork1SrcRewrites; bool m_dmrNetwork2Enabled; unsigned int m_dmrNetwork2Id; @@ -135,8 +156,10 @@ private: unsigned int m_dmrNetwork2Local; std::string m_dmrNetwork2Password; bool m_dmrNetwork2Debug; - std::vector m_dmrNetwork2TGRewrites; - std::vector m_dmrNetwork2PCRewrites; + std::vector m_dmrNetwork2TGRewrites; + std::vector m_dmrNetwork2PCRewrites; + std::vector m_dmrNetwork2TypeRewrites; + std::vector m_dmrNetwork2SrcRewrites; bool m_xlxNetworkEnabled; unsigned int m_xlxNetworkId; diff --git a/DMRGateway.cpp b/DMRGateway.cpp index c260dde..aecdc8c 100644 --- a/DMRGateway.cpp +++ b/DMRGateway.cpp @@ -16,10 +16,12 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include "RewriteType.h" +#include "RewriteSrc.h" #include "DMRGateway.h" -#include "Version.h" #include "StopWatch.h" #include "RewritePC.h" +#include "Version.h" #include "Thread.h" #include "Voice.h" #include "Log.h" @@ -607,24 +609,41 @@ bool CDMRGateway::createDMRNetwork1() std::vector tgRewrites = m_conf.getDMRNetwork1TGRewrites(); for (std::vector::const_iterator it = tgRewrites.begin(); it != tgRewrites.end(); ++it) { - LogInfo(" TG Rewrite: %u:%u -> %u:%u", (*it).m_fromSlot, (*it).m_fromTG, (*it).m_toSlot, (*it).m_toTG); + LogInfo(" Rewrite RF: %u:TG%u-TG%u -> %u:TG%u-TG%u", (*it).m_fromSlot, (*it).m_fromTG, (*it).m_fromTG + (*it).m_range - 1U, (*it).m_toSlot, (*it).m_toTG, (*it).m_toTG + (*it).m_range - 1U); + LogInfo(" Rewrite Net: %u:TG%u-TG%u -> %u:TG%u-TG%u", (*it).m_toSlot, (*it).m_toTG, (*it).m_toTG + (*it).m_range - 1U, (*it).m_fromSlot, (*it).m_fromTG, (*it).m_fromTG + (*it).m_range - 1U); - CRewriteTG* netTGRewrite = new CRewriteTG((*it).m_toSlot, (*it).m_toTG, (*it).m_fromSlot, (*it).m_fromTG); - CRewriteTG* rfTGRewrite = new CRewriteTG((*it).m_fromSlot, (*it).m_fromTG, (*it).m_toSlot, (*it).m_toTG); + CRewriteTG* rfRewrite = new CRewriteTG("DMR-1", (*it).m_fromSlot, (*it).m_fromTG, (*it).m_toSlot, (*it).m_toTG, (*it).m_range); + CRewriteTG* netRewrite = new CRewriteTG("DMR-1", (*it).m_toSlot, (*it).m_toTG, (*it).m_fromSlot, (*it).m_fromTG, (*it).m_range); - m_dmr1NetRewrites.push_back(netTGRewrite); - m_dmr1RFRewrites.push_back(rfTGRewrite); + m_dmr1RFRewrites.push_back(rfRewrite); + m_dmr1NetRewrites.push_back(netRewrite); } std::vector pcRewrites = m_conf.getDMRNetwork1PCRewrites(); for (std::vector::const_iterator it = pcRewrites.begin(); it != pcRewrites.end(); ++it) { - LogInfo(" PC Rewrite: %u:%u-%u -> %u:%u-%u", (*it).m_fromSlot, (*it).m_fromId, (*it).m_fromId + (*it).m_range - 1U, (*it).m_toSlot, (*it).m_toId, (*it).m_toId + (*it).m_range - 1U); + LogInfo(" Rewrite RF: %u:%u-%u -> %u:%u-%u", (*it).m_fromSlot, (*it).m_fromId, (*it).m_fromId + (*it).m_range - 1U, (*it).m_toSlot, (*it).m_toId, (*it).m_toId + (*it).m_range - 1U); - CRewritePC* netPCRewrite = new CRewritePC((*it).m_toSlot, (*it).m_toId, (*it).m_fromSlot, (*it).m_fromId, (*it).m_range); - CRewritePC* rfPCRewrite = new CRewritePC((*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toId, (*it).m_range); + CRewritePC* rewrite = new CRewritePC("DMR-1", (*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toId, (*it).m_range); - m_dmr1NetRewrites.push_back(netPCRewrite); - m_dmr1RFRewrites.push_back(rfPCRewrite); + m_dmr1RFRewrites.push_back(rewrite); + } + + std::vector typeRewrites = m_conf.getDMRNetwork1TypeRewrites(); + for (std::vector::const_iterator it = typeRewrites.begin(); it != typeRewrites.end(); ++it) { + LogInfo(" Rewrite Net: %u:%u -> %u:TG%u", (*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toTG); + + CRewriteType* rewrite = new CRewriteType("DMR-1", (*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toTG); + + m_dmr1NetRewrites.push_back(rewrite); + } + + std::vector srcRewrites = m_conf.getDMRNetwork1SrcRewrites(); + for (std::vector::const_iterator it = srcRewrites.begin(); it != srcRewrites.end(); ++it) { + LogInfo(" Rewrite Net: %u:%u -> %u:TG%u", (*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toTG); + + CRewriteSrc* rewrite = new CRewriteSrc("DMR-1", (*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toTG); + + m_dmr1NetRewrites.push_back(rewrite); } return true; @@ -673,24 +692,41 @@ bool CDMRGateway::createDMRNetwork2() std::vector tgRewrites = m_conf.getDMRNetwork2TGRewrites(); for (std::vector::const_iterator it = tgRewrites.begin(); it != tgRewrites.end(); ++it) { - LogInfo(" TG Rewrite: %u:%u -> %u:%u", (*it).m_fromSlot, (*it).m_fromTG, (*it).m_toSlot, (*it).m_toTG); + LogInfo(" Rewrite RF: %u:TG%u-TG%u -> %u:TG%u-TG%u", (*it).m_fromSlot, (*it).m_fromTG, (*it).m_fromTG + (*it).m_range - 1U, (*it).m_toSlot, (*it).m_toTG, (*it).m_toTG + (*it).m_range - 1U); + LogInfo(" Rewrite Net: %u:TG%u-TG%u -> %u:TG%u-TG%u", (*it).m_toSlot, (*it).m_toTG, (*it).m_toTG + (*it).m_range - 1U, (*it).m_fromSlot, (*it).m_fromTG, (*it).m_fromTG + (*it).m_range - 1U); - CRewriteTG* netTGRewrite = new CRewriteTG((*it).m_toSlot, (*it).m_toTG, (*it).m_fromSlot, (*it).m_fromTG); - CRewriteTG* rfTGRewrite = new CRewriteTG((*it).m_fromSlot, (*it).m_fromTG, (*it).m_toSlot, (*it).m_toTG); + CRewriteTG* rfRewrite = new CRewriteTG("DMR-2", (*it).m_fromSlot, (*it).m_fromTG, (*it).m_toSlot, (*it).m_toTG, (*it).m_range); + CRewriteTG* netRewrite = new CRewriteTG("DMR-2", (*it).m_toSlot, (*it).m_toTG, (*it).m_fromSlot, (*it).m_fromTG, (*it).m_range); - m_dmr2NetRewrites.push_back(netTGRewrite); - m_dmr2RFRewrites.push_back(rfTGRewrite); + m_dmr2RFRewrites.push_back(rfRewrite); + m_dmr2NetRewrites.push_back(netRewrite); } std::vector pcRewrites = m_conf.getDMRNetwork2PCRewrites(); for (std::vector::const_iterator it = pcRewrites.begin(); it != pcRewrites.end(); ++it) { - LogInfo(" PC Rewrite: %u:%u-%u -> %u:%u-%u", (*it).m_fromSlot, (*it).m_fromId, (*it).m_fromId + (*it).m_range - 1U, (*it).m_toSlot, (*it).m_toId, (*it).m_toId + (*it).m_range - 1U); + LogInfo(" Rewrite RF: %u:%u-%u -> %u:%u-%u", (*it).m_fromSlot, (*it).m_fromId, (*it).m_fromId + (*it).m_range - 1U, (*it).m_toSlot, (*it).m_toId, (*it).m_toId + (*it).m_range - 1U); - CRewritePC* netPCRewrite = new CRewritePC((*it).m_toSlot, (*it).m_toId, (*it).m_fromSlot, (*it).m_fromId, (*it).m_range); - CRewritePC* rfPCRewrite = new CRewritePC((*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toId, (*it).m_range); + CRewritePC* rewrite = new CRewritePC("DMR-2", (*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toId, (*it).m_range); - m_dmr2NetRewrites.push_back(netPCRewrite); - m_dmr2RFRewrites.push_back(rfPCRewrite); + m_dmr2RFRewrites.push_back(rewrite); + } + + std::vector typeRewrites = m_conf.getDMRNetwork2TypeRewrites(); + for (std::vector::const_iterator it = typeRewrites.begin(); it != typeRewrites.end(); ++it) { + LogInfo(" Rewrite Net: %u:%u -> %u:TG%u", (*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toTG); + + CRewriteType* rewrite = new CRewriteType("DMR-2", (*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toTG); + + m_dmr2NetRewrites.push_back(rewrite); + } + + std::vector srcRewrites = m_conf.getDMRNetwork2SrcRewrites(); + for (std::vector::const_iterator it = srcRewrites.begin(); it != srcRewrites.end(); ++it) { + LogInfo(" Rewrite Net: %u:%u -> %u:TG%u", (*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toTG); + + CRewriteSrc* rewrite = new CRewriteSrc("DMR-2", (*it).m_fromSlot, (*it).m_fromId, (*it).m_toSlot, (*it).m_toTG); + + m_dmr2NetRewrites.push_back(rewrite); } return true; @@ -743,8 +779,8 @@ bool CDMRGateway::createXLXNetwork() LogInfo(" Slot: %u", m_xlxSlot); LogInfo(" TG: %u", m_xlxTG); - m_rptRewrite = new CRewriteTG(XLX_SLOT, XLX_TG, m_xlxSlot, m_xlxTG); - m_xlxRewrite = new CRewriteTG(m_xlxSlot, m_xlxTG, XLX_SLOT, XLX_TG); + 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; } diff --git a/DMRGateway.ini b/DMRGateway.ini index f611cce..059904a 100644 --- a/DMRGateway.ini +++ b/DMRGateway.ini @@ -35,17 +35,21 @@ Enabled=1 Address=44.131.4.1 Port=62031 # Local=3352 -TGRewrite=1,9,1,9 +TGRewrite=1,9,1,9,1 PCRewrite=2,4000,2,4000,1000 +SrcRewrite=2,12345,2,9 Password=PASSWORD Debug=0 [DMR Network 2] Enabled=0 Address=44.131.4.1 -Port=62031 +Port=55555 # Local=3352 -TGRewrite=2,9,2,9 +TGRewrite=2,9,2,9,1 PCRewrite=2,6000,2,4000,1000 +TypeRewrite=1,2351,1,2351 +TypeRewrite=1,235,1,235 +TypeRewrite=2,9,2,9 Password=PASSWORD Debug=0 diff --git a/DMRGateway.vcxproj b/DMRGateway.vcxproj index d1b87ff..06458c7 100644 --- a/DMRGateway.vcxproj +++ b/DMRGateway.vcxproj @@ -166,7 +166,9 @@ + + @@ -199,7 +201,9 @@ + + diff --git a/DMRGateway.vcxproj.filters b/DMRGateway.vcxproj.filters index 2bca120..05fbb47 100644 --- a/DMRGateway.vcxproj.filters +++ b/DMRGateway.vcxproj.filters @@ -107,6 +107,12 @@ Header Files + + Header Files + + + Header Files + @@ -196,5 +202,11 @@ Source Files + + Source Files + + + Source Files + \ No newline at end of file diff --git a/Makefile b/Makefile index bda4bc9..f0283c1 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ LIBS = -lpthread LDFLAGS = -g OBJECTS = BPTC19696.o Conf.o CRC.o DMRData.o DMREmbeddedData.o DMREMB.o DMRFullLC.o DMRGateway.o DMRLC.o DMRNetwork.o DMRSlotType.o Golay2087.o Hamming.o Log.o \ - MMDVMNetwork.o QR1676.o RepeaterProtocol.o Rewrite.o RewritePC.o RewriteTG.o RS129.o SHA256.o StopWatch.o Sync.o Thread.o Timer.o UDPSocket.o Utils.o \ - Voice.o + MMDVMNetwork.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 all: DMRGateway diff --git a/RewritePC.cpp b/RewritePC.cpp index b3360ae..8cf295c 100644 --- a/RewritePC.cpp +++ b/RewritePC.cpp @@ -24,7 +24,8 @@ #include #include -CRewritePC::CRewritePC(unsigned int fromSlot, unsigned int fromId, unsigned int toSlot, unsigned int toId, unsigned int range) : +CRewritePC::CRewritePC(const char* name, unsigned int fromSlot, unsigned int fromId, unsigned int toSlot, unsigned int toId, unsigned int range) : +m_name(name), m_fromSlot(fromSlot), m_fromIdStart(fromId), m_fromIdEnd(fromId + range), diff --git a/RewritePC.h b/RewritePC.h index efc8297..1299b71 100644 --- a/RewritePC.h +++ b/RewritePC.h @@ -26,12 +26,13 @@ class CRewritePC : public IRewrite { public: - CRewritePC(unsigned int fromSLot, unsigned int fromId, unsigned int toSlot, unsigned int toId, unsigned int range); + CRewritePC(const char* name, unsigned int fromSlot, unsigned int fromId, unsigned int toSlot, unsigned int toId, unsigned int range); virtual ~CRewritePC(); virtual bool process(CDMRData& data); private: + const char* m_name; unsigned int m_fromSlot; unsigned int m_fromIdStart; unsigned int m_fromIdEnd; diff --git a/RewriteSrc.cpp b/RewriteSrc.cpp new file mode 100644 index 0000000..06e5e7a --- /dev/null +++ b/RewriteSrc.cpp @@ -0,0 +1,103 @@ +/* +* 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 "RewriteSrc.h" + +#include "DMRDefines.h" +#include "DMRFullLC.h" +#include "Log.h" + +#include +#include + +CRewriteSrc::CRewriteSrc(const char* name, unsigned int fromSlot, unsigned int fromId, unsigned int toSlot, unsigned int toTG) : +m_name(name), +m_fromSlot(fromSlot), +m_fromId(fromId), +m_toSlot(toSlot), +m_toTG(toTG), +m_lc(FLCO_GROUP, fromId, toTG), +m_embeddedLC() +{ + assert(fromSlot == 1U || fromSlot == 2U); + assert(toSlot == 1U || toSlot == 2U); + + m_embeddedLC.setLC(m_lc); +} + +CRewriteSrc::~CRewriteSrc() +{ +} + +bool CRewriteSrc::process(CDMRData& data) +{ + FLCO flco = data.getFLCO(); + unsigned int srcId = data.getSrcId(); + unsigned int slotNo = data.getSlotNo(); + + if (flco != FLCO_USER_USER || slotNo != m_fromSlot || srcId != m_fromId) + return false; + + if (m_fromSlot != m_toSlot) + data.setSlotNo(m_toSlot); + + data.setDstId(m_toTG); + data.setFLCO(FLCO_GROUP); + + unsigned char dataType = data.getDataType(); + + switch (dataType) { + case DT_VOICE_LC_HEADER: + case DT_TERMINATOR_WITH_LC: + processHeader(data, dataType); + break; + case DT_VOICE: + processVoice(data); + break; + case DT_VOICE_SYNC: + // Nothing to do + break; + default: + // Not sure what to do + break; + } + + return true; +} + +void CRewriteSrc::processHeader(CDMRData& data, unsigned char dataType) +{ + unsigned char buffer[DMR_FRAME_LENGTH_BYTES]; + data.getData(buffer); + + CDMRFullLC fullLC; + fullLC.encode(m_lc, buffer, dataType); + + data.setData(buffer); +} + +void CRewriteSrc::processVoice(CDMRData& data) +{ + unsigned char buffer[DMR_FRAME_LENGTH_BYTES]; + data.getData(buffer); + + unsigned char n = data.getN(); + m_embeddedLC.getData(buffer, n); + + data.setData(buffer); +} diff --git a/RewriteSrc.h b/RewriteSrc.h new file mode 100644 index 0000000..e643eee --- /dev/null +++ b/RewriteSrc.h @@ -0,0 +1,48 @@ +/* +* 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(REWRITESRC_H) +#define REWRITESRC_H + +#include "DMREmbeddedData.h" +#include "Rewrite.h" +#include "DMRData.h" +#include "DMRLC.h" + +class CRewriteSrc : public IRewrite { +public: + CRewriteSrc(const char* name, unsigned int fromSlot, unsigned int fromId, unsigned int toSlot, unsigned int toTG); + virtual ~CRewriteSrc(); + + virtual bool process(CDMRData& data); + +private: + const char* m_name; + unsigned int m_fromSlot; + unsigned int m_fromId; + unsigned int m_toSlot; + unsigned int m_toTG; + CDMRLC m_lc; + CDMREmbeddedData m_embeddedLC; + + void processHeader(CDMRData& data, unsigned char dataType); + void processVoice(CDMRData& data); +}; + + +#endif diff --git a/RewriteTG.cpp b/RewriteTG.cpp index 3185037..0bbca05 100644 --- a/RewriteTG.cpp +++ b/RewriteTG.cpp @@ -24,11 +24,13 @@ #include #include -CRewriteTG::CRewriteTG(unsigned int fromSlot, unsigned int fromTG, unsigned int toSlot, unsigned int toTG) : +CRewriteTG::CRewriteTG(const char* name, unsigned int fromSlot, unsigned int fromTG, unsigned int toSlot, unsigned int toTG, unsigned int range) : +m_name(name), m_fromSlot(fromSlot), -m_fromTG(fromTG), +m_fromTGStart(fromTG), +m_fromTGEnd(fromTG + range), m_toSlot(toSlot), -m_toTG(toTG), +m_toTGStart(toTG), m_lc(FLCO_GROUP, 0U, toTG), m_embeddedLC() { @@ -46,24 +48,26 @@ bool CRewriteTG::process(CDMRData& data) unsigned int dstId = data.getDstId(); unsigned int slotNo = data.getSlotNo(); - if (flco != FLCO_GROUP || slotNo != m_fromSlot || dstId != m_fromTG) + if (flco != FLCO_GROUP || slotNo != m_fromSlot || dstId < m_fromTGStart || dstId >= m_fromTGEnd) return false; if (m_fromSlot != m_toSlot) data.setSlotNo(m_toSlot); - if (m_fromTG != m_toTG) { - data.setDstId(m_toTG); + if (m_fromTGStart != m_toTGStart) { + unsigned int newTG = dstId + m_toTGStart - m_fromTGStart; + + data.setDstId(newTG); unsigned char dataType = data.getDataType(); switch (dataType) { case DT_VOICE_LC_HEADER: case DT_TERMINATOR_WITH_LC: - processHeader(data, dataType); + processHeader(data, newTG, dataType); break; case DT_VOICE: - processVoice(data); + processVoice(data, newTG); break; case DT_VOICE_SYNC: // Nothing to do @@ -77,11 +81,12 @@ bool CRewriteTG::process(CDMRData& data) return true; } -void CRewriteTG::processHeader(CDMRData& data, unsigned char dataType) +void CRewriteTG::processHeader(CDMRData& data, unsigned int tg, unsigned char dataType) { unsigned int srcId = data.getSrcId(); - if (srcId != m_lc.getSrcId()) { + if (srcId != m_lc.getSrcId() || tg != m_lc.getDstId()) { m_lc.setSrcId(srcId); + m_lc.setDstId(tg); m_embeddedLC.setLC(m_lc); } @@ -94,11 +99,12 @@ void CRewriteTG::processHeader(CDMRData& data, unsigned char dataType) data.setData(buffer); } -void CRewriteTG::processVoice(CDMRData& data) +void CRewriteTG::processVoice(CDMRData& data, unsigned int tg) { unsigned int srcId = data.getSrcId(); - if (srcId != m_lc.getSrcId()) { + if (srcId != m_lc.getSrcId() || tg != m_lc.getDstId()) { m_lc.setSrcId(srcId); + m_lc.setDstId(tg); m_embeddedLC.setLC(m_lc); } diff --git a/RewriteTG.h b/RewriteTG.h index da79c63..6565df3 100644 --- a/RewriteTG.h +++ b/RewriteTG.h @@ -26,21 +26,23 @@ class CRewriteTG : public IRewrite { public: - CRewriteTG(unsigned int fromSLot, unsigned int fromTG, unsigned int toSlot, unsigned int toTG); + CRewriteTG(const char*name, unsigned int fromSlot, unsigned int fromTG, unsigned int toSlot, unsigned int toTG, unsigned int range); virtual ~CRewriteTG(); virtual bool process(CDMRData& data); private: + const char* m_name; unsigned int m_fromSlot; - unsigned int m_fromTG; + unsigned int m_fromTGStart; + unsigned int m_fromTGEnd; unsigned int m_toSlot; - unsigned int m_toTG; + unsigned int m_toTGStart; CDMRLC m_lc; CDMREmbeddedData m_embeddedLC; - void processHeader(CDMRData& data, unsigned char dataType); - void processVoice(CDMRData& data); + void processHeader(CDMRData& data, unsigned int tg, unsigned char dataType); + void processVoice(CDMRData& data, unsigned int tg); }; diff --git a/RewriteType.cpp b/RewriteType.cpp new file mode 100644 index 0000000..156f510 --- /dev/null +++ b/RewriteType.cpp @@ -0,0 +1,115 @@ +/* +* 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 "RewriteType.h" + +#include "DMRDefines.h" +#include "DMRFullLC.h" +#include "Log.h" + +#include +#include + +CRewriteType::CRewriteType(const char* name, unsigned int fromSlot, unsigned int fromId, unsigned int toSlot, unsigned int toTG) : +m_name(name), +m_fromSlot(fromSlot), +m_fromId(fromId), +m_toSlot(toSlot), +m_toTG(toTG), +m_lc(FLCO_GROUP, 0U, toTG), +m_embeddedLC() +{ + assert(fromSlot == 1U || fromSlot == 2U); + assert(toSlot == 1U || toSlot == 2U); +} + +CRewriteType::~CRewriteType() +{ +} + +bool CRewriteType::process(CDMRData& data) +{ + FLCO flco = data.getFLCO(); + unsigned int dstId = data.getDstId(); + unsigned int slotNo = data.getSlotNo(); + + if (flco != FLCO_USER_USER || slotNo != m_fromSlot || dstId != m_fromId) + return false; + + if (m_fromSlot != m_toSlot) + data.setSlotNo(m_toSlot); + + data.setDstId(m_toTG); + data.setFLCO(FLCO_GROUP); + + unsigned char dataType = data.getDataType(); + + switch (dataType) { + case DT_VOICE_LC_HEADER: + case DT_TERMINATOR_WITH_LC: + processHeader(data, dataType); + break; + case DT_VOICE: + processVoice(data); + break; + case DT_VOICE_SYNC: + // Nothing to do + break; + default: + // Not sure what to do + break; + } + + return true; +} + +void CRewriteType::processHeader(CDMRData& data, unsigned char dataType) +{ + unsigned int srcId = data.getSrcId(); + if (srcId != m_lc.getSrcId()) { + m_lc.setSrcId(srcId); + m_embeddedLC.setLC(m_lc); + } + + LogDebug("%s, Private call to TG rewrite of id: %u", m_name, m_fromId); + + unsigned char buffer[DMR_FRAME_LENGTH_BYTES]; + data.getData(buffer); + + CDMRFullLC fullLC; + fullLC.encode(m_lc, buffer, dataType); + + data.setData(buffer); +} + +void CRewriteType::processVoice(CDMRData& data) +{ + unsigned int srcId = data.getSrcId(); + if (srcId != m_lc.getSrcId()) { + m_lc.setSrcId(srcId); + m_embeddedLC.setLC(m_lc); + } + + unsigned char buffer[DMR_FRAME_LENGTH_BYTES]; + data.getData(buffer); + + unsigned char n = data.getN(); + m_embeddedLC.getData(buffer, n); + + data.setData(buffer); +} diff --git a/RewriteType.h b/RewriteType.h new file mode 100644 index 0000000..5730848 --- /dev/null +++ b/RewriteType.h @@ -0,0 +1,48 @@ +/* +* 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(REWRITETYPE_H) +#define REWRITETYPE_H + +#include "DMREmbeddedData.h" +#include "Rewrite.h" +#include "DMRData.h" +#include "DMRLC.h" + +class CRewriteType : public IRewrite { +public: + CRewriteType(const char* name, unsigned int fromSlot, unsigned int fromId, unsigned int toSlot, unsigned int toTG); + virtual ~CRewriteType(); + + virtual bool process(CDMRData& data); + +private: + const char* m_name; + unsigned int m_fromSlot; + unsigned int m_fromId; + unsigned int m_toSlot; + unsigned int m_toTG; + CDMRLC m_lc; + CDMREmbeddedData m_embeddedLC; + + void processHeader(CDMRData& data, unsigned char dataType); + void processVoice(CDMRData& data); +}; + + +#endif diff --git a/Version.h b/Version.h index f831bb0..455501e 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20170514"; +const char* VERSION = "20170515"; #endif