mirror of
https://github.com/g4klx/DMRGateway
synced 2025-12-20 21:25:37 +08:00
Use the unified rewriting code.
This commit is contained in:
72
Conf.cpp
72
Conf.cpp
@@ -60,8 +60,7 @@ m_dmrNetwork1Local(0U),
|
||||
m_dmrNetwork1Password(),
|
||||
m_dmrNetwork1Debug(false),
|
||||
m_dmrNetwork1TGRewrites(),
|
||||
m_dmrNetwork1PrivateSlot1(false),
|
||||
m_dmrNetwork1PrivateSlot2(false),
|
||||
m_dmrNetwork1PCRewrites(),
|
||||
m_dmrNetwork2Enabled(false),
|
||||
m_dmrNetwork2Id(0U),
|
||||
m_dmrNetwork2Address(),
|
||||
@@ -70,8 +69,7 @@ m_dmrNetwork2Local(0U),
|
||||
m_dmrNetwork2Password(),
|
||||
m_dmrNetwork2Debug(false),
|
||||
m_dmrNetwork2TGRewrites(),
|
||||
m_dmrNetwork2PrivateSlot1(false),
|
||||
m_dmrNetwork2PrivateSlot2(false),
|
||||
m_dmrNetwork2PCRewrites(),
|
||||
m_xlxNetworkEnabled(false),
|
||||
m_xlxNetworkId(0U),
|
||||
m_xlxNetworkAddress(),
|
||||
@@ -204,17 +202,29 @@ bool CConf::read()
|
||||
char* p3 = ::strtok(NULL, ", ");
|
||||
char* p4 = ::strtok(NULL, " \r\n");
|
||||
if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL) {
|
||||
CRewriteStruct rewrite;
|
||||
CTGRewriteStruct rewrite;
|
||||
rewrite.m_fromSlot = ::atoi(p1);
|
||||
rewrite.m_fromTG = ::atoi(p2);
|
||||
rewrite.m_toSlot = ::atoi(p3);
|
||||
rewrite.m_toTG = ::atoi(p4);
|
||||
m_dmrNetwork1TGRewrites.push_back(rewrite);
|
||||
}
|
||||
} else if (::strcmp(key, "PrivateSlot1") == 0)
|
||||
m_dmrNetwork1PrivateSlot1 = ::atoi(value) == 1;
|
||||
else if (::strcmp(key, "PrivateSlot2") == 0)
|
||||
m_dmrNetwork1PrivateSlot2 = ::atoi(value) == 1;
|
||||
} else if (::strcmp(key, "PCRewrite") == 0) {
|
||||
char* p1 = ::strtok(value, ", ");
|
||||
char* p2 = ::strtok(NULL, ", ");
|
||||
char* p3 = ::strtok(NULL, ", ");
|
||||
char* p4 = ::strtok(NULL, ", ");
|
||||
char* p5 = ::strtok(NULL, " \r\n");
|
||||
if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL && p5 != NULL) {
|
||||
CPCRewriteStruct rewrite;
|
||||
rewrite.m_fromSlot = ::atoi(p1);
|
||||
rewrite.m_fromId = ::atoi(p2);
|
||||
rewrite.m_toSlot = ::atoi(p3);
|
||||
rewrite.m_toId = ::atoi(p4);
|
||||
rewrite.m_range = ::atoi(p5);
|
||||
m_dmrNetwork1PCRewrites.push_back(rewrite);
|
||||
}
|
||||
}
|
||||
} else if (section == SECTION_DMR_NETWORK_2) {
|
||||
if (::strcmp(key, "Enabled") == 0)
|
||||
m_dmrNetwork2Enabled = ::atoi(value) == 1;
|
||||
@@ -236,17 +246,29 @@ bool CConf::read()
|
||||
char* p3 = ::strtok(NULL, ", ");
|
||||
char* p4 = ::strtok(NULL, " \r\n");
|
||||
if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL) {
|
||||
CRewriteStruct rewrite;
|
||||
CTGRewriteStruct rewrite;
|
||||
rewrite.m_fromSlot = ::atoi(p1);
|
||||
rewrite.m_fromTG = ::atoi(p2);
|
||||
rewrite.m_toSlot = ::atoi(p3);
|
||||
rewrite.m_toTG = ::atoi(p4);
|
||||
m_dmrNetwork2TGRewrites.push_back(rewrite);
|
||||
}
|
||||
} else if (::strcmp(key, "PrivateSlot1") == 0)
|
||||
m_dmrNetwork2PrivateSlot1 = ::atoi(value) == 1;
|
||||
else if (::strcmp(key, "PrivateSlot2") == 0)
|
||||
m_dmrNetwork2PrivateSlot2 = ::atoi(value) == 1;
|
||||
} else if (::strcmp(key, "PCRewrite") == 0) {
|
||||
char* p1 = ::strtok(value, ", ");
|
||||
char* p2 = ::strtok(NULL, ", ");
|
||||
char* p3 = ::strtok(NULL, ", ");
|
||||
char* p4 = ::strtok(NULL, ", ");
|
||||
char* p5 = ::strtok(NULL, " \r\n");
|
||||
if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL && p5 != NULL) {
|
||||
CPCRewriteStruct rewrite;
|
||||
rewrite.m_fromSlot = ::atoi(p1);
|
||||
rewrite.m_fromId = ::atoi(p2);
|
||||
rewrite.m_toSlot = ::atoi(p3);
|
||||
rewrite.m_toId = ::atoi(p4);
|
||||
rewrite.m_range = ::atoi(p5);
|
||||
m_dmrNetwork2PCRewrites.push_back(rewrite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,19 +432,14 @@ bool CConf::getDMRNetwork1Debug() const
|
||||
return m_dmrNetwork1Debug;
|
||||
}
|
||||
|
||||
std::vector<CRewriteStruct> CConf::getDMRNetwork1TGRewrites() const
|
||||
std::vector<CTGRewriteStruct> CConf::getDMRNetwork1TGRewrites() const
|
||||
{
|
||||
return m_dmrNetwork1TGRewrites;
|
||||
}
|
||||
|
||||
bool CConf::getDMRNetwork1PrivateSlot1() const
|
||||
std::vector<CPCRewriteStruct> CConf::getDMRNetwork1PCRewrites() const
|
||||
{
|
||||
return m_dmrNetwork1PrivateSlot1;
|
||||
}
|
||||
|
||||
bool CConf::getDMRNetwork1PrivateSlot2() const
|
||||
{
|
||||
return m_dmrNetwork1PrivateSlot2;
|
||||
return m_dmrNetwork1PCRewrites;
|
||||
}
|
||||
|
||||
bool CConf::getDMRNetwork2Enabled() const
|
||||
@@ -460,17 +477,12 @@ bool CConf::getDMRNetwork2Debug() const
|
||||
return m_dmrNetwork2Debug;
|
||||
}
|
||||
|
||||
std::vector<CRewriteStruct> CConf::getDMRNetwork2TGRewrites() const
|
||||
std::vector<CTGRewriteStruct> CConf::getDMRNetwork2TGRewrites() const
|
||||
{
|
||||
return m_dmrNetwork2TGRewrites;
|
||||
}
|
||||
|
||||
bool CConf::getDMRNetwork2PrivateSlot1() const
|
||||
std::vector<CPCRewriteStruct> CConf::getDMRNetwork2PCRewrites() const
|
||||
{
|
||||
return m_dmrNetwork2PrivateSlot1;
|
||||
}
|
||||
|
||||
bool CConf::getDMRNetwork2PrivateSlot2() const
|
||||
{
|
||||
return m_dmrNetwork2PrivateSlot2;
|
||||
return m_dmrNetwork2PCRewrites;
|
||||
}
|
||||
|
||||
30
Conf.h
30
Conf.h
@@ -22,13 +22,21 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct CRewriteStruct {
|
||||
struct CTGRewriteStruct {
|
||||
unsigned int m_fromSlot;
|
||||
unsigned int m_fromTG;
|
||||
unsigned int m_toSlot;
|
||||
unsigned int m_toTG;
|
||||
};
|
||||
|
||||
struct CPCRewriteStruct {
|
||||
unsigned int m_fromSlot;
|
||||
unsigned int m_fromId;
|
||||
unsigned int m_toSlot;
|
||||
unsigned int m_toId;
|
||||
unsigned int m_range;
|
||||
};
|
||||
|
||||
class CConf
|
||||
{
|
||||
public:
|
||||
@@ -65,9 +73,8 @@ public:
|
||||
unsigned int getDMRNetwork1Local() const;
|
||||
std::string getDMRNetwork1Password() const;
|
||||
bool getDMRNetwork1Debug() const;
|
||||
std::vector<CRewriteStruct> getDMRNetwork1TGRewrites() const;
|
||||
bool getDMRNetwork1PrivateSlot1() const;
|
||||
bool getDMRNetwork1PrivateSlot2() const;
|
||||
std::vector<CTGRewriteStruct> getDMRNetwork1TGRewrites() const;
|
||||
std::vector<CPCRewriteStruct> getDMRNetwork1PCRewrites() const;
|
||||
|
||||
// The DMR Network 2 section
|
||||
bool getDMRNetwork2Enabled() const;
|
||||
@@ -77,9 +84,8 @@ public:
|
||||
unsigned int getDMRNetwork2Local() const;
|
||||
std::string getDMRNetwork2Password() const;
|
||||
bool getDMRNetwork2Debug() const;
|
||||
std::vector<CRewriteStruct> getDMRNetwork2TGRewrites() const;
|
||||
bool getDMRNetwork2PrivateSlot1() const;
|
||||
bool getDMRNetwork2PrivateSlot2() const;
|
||||
std::vector<CTGRewriteStruct> getDMRNetwork2TGRewrites() const;
|
||||
std::vector<CPCRewriteStruct> getDMRNetwork2PCRewrites() const;
|
||||
|
||||
// The XLX Network section
|
||||
bool getXLXNetworkEnabled() const;
|
||||
@@ -119,9 +125,8 @@ private:
|
||||
unsigned int m_dmrNetwork1Local;
|
||||
std::string m_dmrNetwork1Password;
|
||||
bool m_dmrNetwork1Debug;
|
||||
std::vector<CRewriteStruct> m_dmrNetwork1TGRewrites;
|
||||
bool m_dmrNetwork1PrivateSlot1;
|
||||
bool m_dmrNetwork1PrivateSlot2;
|
||||
std::vector<CTGRewriteStruct> m_dmrNetwork1TGRewrites;
|
||||
std::vector<CPCRewriteStruct> m_dmrNetwork1PCRewrites;
|
||||
|
||||
bool m_dmrNetwork2Enabled;
|
||||
unsigned int m_dmrNetwork2Id;
|
||||
@@ -130,9 +135,8 @@ private:
|
||||
unsigned int m_dmrNetwork2Local;
|
||||
std::string m_dmrNetwork2Password;
|
||||
bool m_dmrNetwork2Debug;
|
||||
std::vector<CRewriteStruct> m_dmrNetwork2TGRewrites;
|
||||
bool m_dmrNetwork2PrivateSlot1;
|
||||
bool m_dmrNetwork2PrivateSlot2;
|
||||
std::vector<CTGRewriteStruct> m_dmrNetwork2TGRewrites;
|
||||
std::vector<CPCRewriteStruct> m_dmrNetwork2PCRewrites;
|
||||
|
||||
bool m_xlxNetworkEnabled;
|
||||
unsigned int m_xlxNetworkId;
|
||||
|
||||
137
DMRGateway.cpp
137
DMRGateway.cpp
@@ -19,6 +19,7 @@
|
||||
#include "DMRGateway.h"
|
||||
#include "Version.h"
|
||||
#include "StopWatch.h"
|
||||
#include "RewritePC.h"
|
||||
#include "Thread.h"
|
||||
#include "Voice.h"
|
||||
#include "Log.h"
|
||||
@@ -126,27 +127,26 @@ m_xlxRewrite(NULL),
|
||||
m_dmr1NetRewrites(),
|
||||
m_dmr1RFRewrites(),
|
||||
m_dmr2NetRewrites(),
|
||||
m_dmr2RFRewrites(),
|
||||
m_dmr1PrivateSlot1(false),
|
||||
m_dmr1PrivateSlot2(false),
|
||||
m_dmr2PrivateSlot1(false),
|
||||
m_dmr2PrivateSlot2(false)
|
||||
m_dmr2RFRewrites()
|
||||
{
|
||||
}
|
||||
|
||||
CDMRGateway::~CDMRGateway()
|
||||
{
|
||||
for (std::vector<CRewriteTG*>::iterator it = m_dmr1NetRewrites.begin(); it != m_dmr1NetRewrites.end(); ++it)
|
||||
for (std::vector<IRewrite*>::iterator it = m_dmr1NetRewrites.begin(); it != m_dmr1NetRewrites.end(); ++it)
|
||||
delete *it;
|
||||
|
||||
for (std::vector<CRewriteTG*>::iterator it = m_dmr1RFRewrites.begin(); it != m_dmr1RFRewrites.end(); ++it)
|
||||
for (std::vector<IRewrite*>::iterator it = m_dmr1RFRewrites.begin(); it != m_dmr1RFRewrites.end(); ++it)
|
||||
delete *it;
|
||||
|
||||
for (std::vector<CRewriteTG*>::iterator it = m_dmr2NetRewrites.begin(); it != m_dmr2NetRewrites.end(); ++it)
|
||||
for (std::vector<IRewrite*>::iterator it = m_dmr2NetRewrites.begin(); it != m_dmr2NetRewrites.end(); ++it)
|
||||
delete *it;
|
||||
|
||||
for (std::vector<CRewriteTG*>::iterator it = m_dmr2RFRewrites.begin(); it != m_dmr2RFRewrites.end(); ++it)
|
||||
for (std::vector<IRewrite*>::iterator it = m_dmr2RFRewrites.begin(); it != m_dmr2RFRewrites.end(); ++it)
|
||||
delete *it;
|
||||
|
||||
delete m_rptRewrite;
|
||||
delete m_xlxRewrite;
|
||||
}
|
||||
|
||||
int CDMRGateway::run()
|
||||
@@ -346,30 +346,12 @@ int CDMRGateway::run()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (flco == FLCO_USER_USER) {
|
||||
if (m_dmrNetwork1 != NULL && slotNo == 1U && m_dmr1PrivateSlot1) {
|
||||
m_dmrNetwork1->write(data);
|
||||
status[slotNo] = DMRGWS_NETWORK1;
|
||||
timer[slotNo]->start();
|
||||
} else if (m_dmrNetwork1 != NULL && slotNo == 2U && m_dmr1PrivateSlot2) {
|
||||
m_dmrNetwork1->write(data);
|
||||
status[slotNo] = DMRGWS_NETWORK1;
|
||||
timer[slotNo]->start();
|
||||
} else if (m_dmrNetwork2 != NULL && slotNo == 1U && m_dmr2PrivateSlot1) {
|
||||
m_dmrNetwork2->write(data);
|
||||
status[slotNo] = DMRGWS_NETWORK2;
|
||||
timer[slotNo]->start();
|
||||
} else if (m_dmrNetwork2 != NULL && slotNo == 2U && m_dmr2PrivateSlot2) {
|
||||
m_dmrNetwork2->write(data);
|
||||
status[slotNo] = DMRGWS_NETWORK2;
|
||||
timer[slotNo]->start();
|
||||
}
|
||||
} else {
|
||||
bool rewritten = false;
|
||||
|
||||
if (m_dmrNetwork1 != NULL) {
|
||||
// Rewrite the slot and/or TG or neither
|
||||
for (std::vector<CRewriteTG*>::iterator it = m_dmr1RFRewrites.begin(); it != m_dmr1RFRewrites.end(); ++it) {
|
||||
for (std::vector<IRewrite*>::iterator it = m_dmr1RFRewrites.begin(); it != m_dmr1RFRewrites.end(); ++it) {
|
||||
bool ret = (*it)->process(data);
|
||||
if (ret) {
|
||||
rewritten = true;
|
||||
@@ -390,7 +372,7 @@ int CDMRGateway::run()
|
||||
if (!rewritten) {
|
||||
if (m_dmrNetwork2 != NULL) {
|
||||
// Rewrite the slot and/or TG or neither
|
||||
for (std::vector<CRewriteTG*>::iterator it = m_dmr2RFRewrites.begin(); it != m_dmr2RFRewrites.end(); ++it) {
|
||||
for (std::vector<IRewrite*>::iterator it = m_dmr2RFRewrites.begin(); it != m_dmr2RFRewrites.end(); ++it) {
|
||||
bool ret = (*it)->process(data);
|
||||
if (ret) {
|
||||
rewritten = true;
|
||||
@@ -433,23 +415,9 @@ int CDMRGateway::run()
|
||||
if (m_dmrNetwork1 != NULL) {
|
||||
ret = m_dmrNetwork1->read(data);
|
||||
if (ret) {
|
||||
FLCO flco = data.getFLCO();
|
||||
if (flco == FLCO_USER_USER) {
|
||||
unsigned int slotNo = data.getSlotNo();
|
||||
|
||||
if (slotNo == 1U && m_dmr1PrivateSlot1) {
|
||||
m_repeater->write(data);
|
||||
status[slotNo] = DMRGWS_NETWORK1;
|
||||
timer[slotNo]->start();
|
||||
} else if (slotNo == 2U && m_dmr1PrivateSlot2) {
|
||||
m_repeater->write(data);
|
||||
status[slotNo] = DMRGWS_NETWORK1;
|
||||
timer[slotNo]->start();
|
||||
}
|
||||
} else {
|
||||
// Rewrite the slot and/or TG or neither
|
||||
bool rewritten = false;
|
||||
for (std::vector<CRewriteTG*>::iterator it = m_dmr1NetRewrites.begin(); it != m_dmr1NetRewrites.end(); ++it) {
|
||||
for (std::vector<IRewrite*>::iterator it = m_dmr1NetRewrites.begin(); it != m_dmr1NetRewrites.end(); ++it) {
|
||||
bool ret = (*it)->process(data);
|
||||
if (ret) {
|
||||
rewritten = true;
|
||||
@@ -460,9 +428,10 @@ int CDMRGateway::run()
|
||||
if (rewritten) {
|
||||
unsigned int slotNo = data.getSlotNo();
|
||||
unsigned int dstId = data.getDstId();
|
||||
FLCO flco = data.getFLCO();
|
||||
|
||||
// Stop the DMR network from using the same TG as XLX after rewriting
|
||||
if (slotNo != m_xlxSlot || dstId != m_xlxTG) {
|
||||
// Stop the DMR network from using the same TG and slot as XLX after rewriting
|
||||
if (flco != FLCO_GROUP || slotNo != m_xlxSlot || dstId != m_xlxTG) {
|
||||
if (status[slotNo] == DMRGWS_NONE || status[slotNo] == DMRGWS_NETWORK1) {
|
||||
m_repeater->write(data);
|
||||
status[slotNo] = DMRGWS_NETWORK1;
|
||||
@@ -472,28 +441,13 @@ int CDMRGateway::run()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_dmrNetwork2 != NULL) {
|
||||
ret = m_dmrNetwork2->read(data);
|
||||
if (ret) {
|
||||
FLCO flco = data.getFLCO();
|
||||
if (flco == FLCO_USER_USER) {
|
||||
unsigned int slotNo = data.getSlotNo();
|
||||
|
||||
if (slotNo == 1U && m_dmr2PrivateSlot1) {
|
||||
m_repeater->write(data);
|
||||
status[slotNo] = DMRGWS_NETWORK2;
|
||||
timer[slotNo]->start();
|
||||
} else if (slotNo == 2U && m_dmr2PrivateSlot2) {
|
||||
m_repeater->write(data);
|
||||
status[slotNo] = DMRGWS_NETWORK2;
|
||||
timer[slotNo]->start();
|
||||
}
|
||||
} else {
|
||||
// Rewrite the slot and/or TG or neither
|
||||
bool rewritten = false;
|
||||
for (std::vector<CRewriteTG*>::iterator it = m_dmr2NetRewrites.begin(); it != m_dmr2NetRewrites.end(); ++it) {
|
||||
for (std::vector<IRewrite*>::iterator it = m_dmr2NetRewrites.begin(); it != m_dmr2NetRewrites.end(); ++it) {
|
||||
bool ret = (*it)->process(data);
|
||||
if (ret) {
|
||||
rewritten = true;
|
||||
@@ -504,9 +458,10 @@ int CDMRGateway::run()
|
||||
if (rewritten) {
|
||||
unsigned int slotNo = data.getSlotNo();
|
||||
unsigned int dstId = data.getDstId();
|
||||
FLCO flco = data.getFLCO();
|
||||
|
||||
// Stop the DMR network from using the same TG as XLX after rewriting
|
||||
if (slotNo != m_xlxSlot || dstId != m_xlxTG) {
|
||||
// Stop the DMR network from using the same TG and slot as XLX after rewriting
|
||||
if (flco != FLCO_GROUP || slotNo != m_xlxSlot || dstId != m_xlxTG) {
|
||||
if (status[slotNo] == DMRGWS_NONE || status[slotNo] == DMRGWS_NETWORK2) {
|
||||
m_repeater->write(data);
|
||||
status[slotNo] = DMRGWS_NETWORK2;
|
||||
@@ -516,7 +471,6 @@ int CDMRGateway::run()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (voice != NULL) {
|
||||
ret = voice->read(data);
|
||||
@@ -578,9 +532,6 @@ int CDMRGateway::run()
|
||||
delete m_xlxNetwork;
|
||||
}
|
||||
|
||||
delete m_rptRewrite;
|
||||
delete m_xlxRewrite;
|
||||
|
||||
delete timer[1U];
|
||||
delete timer[2U];
|
||||
|
||||
@@ -654,22 +605,27 @@ bool CDMRGateway::createDMRNetwork1()
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<CRewriteStruct> rewrites = m_conf.getDMRNetwork1TGRewrites();
|
||||
for (std::vector<CRewriteStruct>::const_iterator it = rewrites.begin(); it != rewrites.end(); ++it) {
|
||||
std::vector<CTGRewriteStruct> tgRewrites = m_conf.getDMRNetwork1TGRewrites();
|
||||
for (std::vector<CTGRewriteStruct>::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);
|
||||
|
||||
CRewriteTG* netRewrite = new CRewriteTG((*it).m_toSlot, (*it).m_toTG, (*it).m_fromSlot, (*it).m_fromTG);
|
||||
CRewriteTG* rfRewrite = new CRewriteTG((*it).m_fromSlot, (*it).m_fromTG, (*it).m_toSlot, (*it).m_toTG);
|
||||
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);
|
||||
|
||||
m_dmr1NetRewrites.push_back(netRewrite);
|
||||
m_dmr1RFRewrites.push_back(rfRewrite);
|
||||
m_dmr1NetRewrites.push_back(netTGRewrite);
|
||||
m_dmr1RFRewrites.push_back(rfTGRewrite);
|
||||
}
|
||||
|
||||
m_dmr1PrivateSlot1 = m_conf.getDMRNetwork1PrivateSlot1();
|
||||
m_dmr1PrivateSlot2 = m_conf.getDMRNetwork1PrivateSlot2();
|
||||
std::vector<CPCRewriteStruct> pcRewrites = m_conf.getDMRNetwork1PCRewrites();
|
||||
for (std::vector<CPCRewriteStruct>::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(" Private slot 1: %s", m_dmr1PrivateSlot1 ? "yes" : "no");
|
||||
LogInfo(" Private slot 2: %s", m_dmr1PrivateSlot2 ? "yes" : "no");
|
||||
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);
|
||||
|
||||
m_dmr1NetRewrites.push_back(netPCRewrite);
|
||||
m_dmr1RFRewrites.push_back(rfPCRewrite);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -715,22 +671,27 @@ bool CDMRGateway::createDMRNetwork2()
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<CRewriteStruct> rewrites = m_conf.getDMRNetwork2TGRewrites();
|
||||
for (std::vector<CRewriteStruct>::const_iterator it = rewrites.begin(); it != rewrites.end(); ++it) {
|
||||
std::vector<CTGRewriteStruct> tgRewrites = m_conf.getDMRNetwork2TGRewrites();
|
||||
for (std::vector<CTGRewriteStruct>::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);
|
||||
|
||||
CRewriteTG* netRewrite = new CRewriteTG((*it).m_toSlot, (*it).m_toTG, (*it).m_fromSlot, (*it).m_fromTG);
|
||||
CRewriteTG* rfRewrite = new CRewriteTG((*it).m_fromSlot, (*it).m_fromTG, (*it).m_toSlot, (*it).m_toTG);
|
||||
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);
|
||||
|
||||
m_dmr2NetRewrites.push_back(netRewrite);
|
||||
m_dmr2RFRewrites.push_back(rfRewrite);
|
||||
m_dmr2NetRewrites.push_back(netTGRewrite);
|
||||
m_dmr2RFRewrites.push_back(rfTGRewrite);
|
||||
}
|
||||
|
||||
m_dmr2PrivateSlot1 = m_conf.getDMRNetwork2PrivateSlot1();
|
||||
m_dmr2PrivateSlot2 = m_conf.getDMRNetwork2PrivateSlot2();
|
||||
std::vector<CPCRewriteStruct> pcRewrites = m_conf.getDMRNetwork2PCRewrites();
|
||||
for (std::vector<CPCRewriteStruct>::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(" Private slot 1: %s", m_dmr2PrivateSlot1 ? "yes" : "no");
|
||||
LogInfo(" Private slot 2: %s", m_dmr2PrivateSlot2 ? "yes" : "no");
|
||||
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);
|
||||
|
||||
m_dmr2NetRewrites.push_back(netPCRewrite);
|
||||
m_dmr2RFRewrites.push_back(rfPCRewrite);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
13
DMRGateway.h
13
DMRGateway.h
@@ -23,6 +23,7 @@
|
||||
#include "MMDVMNetwork.h"
|
||||
#include "DMRNetwork.h"
|
||||
#include "RewriteTG.h"
|
||||
#include "Rewrite.h"
|
||||
#include "Conf.h"
|
||||
|
||||
#include <string>
|
||||
@@ -46,14 +47,10 @@ private:
|
||||
unsigned int m_xlxTG;
|
||||
CRewriteTG* m_rptRewrite;
|
||||
CRewriteTG* m_xlxRewrite;
|
||||
std::vector<CRewriteTG*> m_dmr1NetRewrites;
|
||||
std::vector<CRewriteTG*> m_dmr1RFRewrites;
|
||||
std::vector<CRewriteTG*> m_dmr2NetRewrites;
|
||||
std::vector<CRewriteTG*> m_dmr2RFRewrites;
|
||||
bool m_dmr1PrivateSlot1;
|
||||
bool m_dmr1PrivateSlot2;
|
||||
bool m_dmr2PrivateSlot1;
|
||||
bool m_dmr2PrivateSlot2;
|
||||
std::vector<IRewrite*> m_dmr1NetRewrites;
|
||||
std::vector<IRewrite*> m_dmr1RFRewrites;
|
||||
std::vector<IRewrite*> m_dmr2NetRewrites;
|
||||
std::vector<IRewrite*> m_dmr2RFRewrites;
|
||||
|
||||
bool createMMDVM();
|
||||
bool createDMRNetwork1();
|
||||
|
||||
@@ -36,8 +36,7 @@ Address=44.131.4.1
|
||||
Port=62031
|
||||
# Local=3352
|
||||
TGRewrite=1,9,1,9
|
||||
PrivateSlot1=1
|
||||
PrivateSlot2=1
|
||||
PCRewrite=2,4000,2,4000,1000
|
||||
Password=PASSWORD
|
||||
Debug=0
|
||||
|
||||
@@ -47,7 +46,6 @@ Address=44.131.4.1
|
||||
Port=62031
|
||||
# Local=3352
|
||||
TGRewrite=2,9,2,9
|
||||
PrivateSlot1=0
|
||||
PrivateSlot2=0
|
||||
PCRewrite=2,6000,2,4000,1000
|
||||
Password=PASSWORD
|
||||
Debug=0
|
||||
|
||||
@@ -164,6 +164,8 @@
|
||||
<ClInclude Include="MMDVMNetwork.h" />
|
||||
<ClInclude Include="QR1676.h" />
|
||||
<ClInclude Include="RepeaterProtocol.h" />
|
||||
<ClInclude Include="Rewrite.h" />
|
||||
<ClInclude Include="RewritePC.h" />
|
||||
<ClInclude Include="RewriteTG.h" />
|
||||
<ClInclude Include="RingBuffer.h" />
|
||||
<ClInclude Include="RS129.h" />
|
||||
@@ -195,6 +197,8 @@
|
||||
<ClCompile Include="MMDVMNetwork.cpp" />
|
||||
<ClCompile Include="QR1676.cpp" />
|
||||
<ClCompile Include="RepeaterProtocol.cpp" />
|
||||
<ClCompile Include="Rewrite.cpp" />
|
||||
<ClCompile Include="RewritePC.cpp" />
|
||||
<ClCompile Include="RewriteTG.cpp" />
|
||||
<ClCompile Include="RS129.cpp" />
|
||||
<ClCompile Include="SHA256.cpp" />
|
||||
|
||||
@@ -101,6 +101,12 @@
|
||||
<ClInclude Include="RewriteTG.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="RewritePC.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Rewrite.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Conf.cpp">
|
||||
@@ -184,5 +190,11 @@
|
||||
<ClCompile Include="RewriteTG.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="RewritePC.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Rewrite.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
3
Makefile
3
Makefile
@@ -5,7 +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 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 RewriteTG.o RS129.o SHA256.o StopWatch.o Sync.o Thread.o Timer.o UDPSocket.o Utils.o \
|
||||
Voice.o
|
||||
|
||||
all: DMRGateway
|
||||
|
||||
|
||||
23
Rewrite.cpp
Normal file
23
Rewrite.cpp
Normal 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 "Rewrite.h"
|
||||
|
||||
IRewrite::~IRewrite()
|
||||
{
|
||||
}
|
||||
34
Rewrite.h
Normal file
34
Rewrite.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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(REWRITE_H)
|
||||
#define REWRITE_H
|
||||
|
||||
#include "DMRData.h"
|
||||
|
||||
class IRewrite {
|
||||
public:
|
||||
virtual ~IRewrite() = 0;
|
||||
|
||||
virtual bool process(CDMRData& data) = 0;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
117
RewritePC.cpp
Normal file
117
RewritePC.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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 "RewritePC.h"
|
||||
|
||||
#include "DMRDefines.h"
|
||||
#include "DMRFullLC.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
|
||||
CRewritePC::CRewritePC(unsigned int fromSlot, unsigned int fromId, unsigned int toSlot, unsigned int toId, unsigned int range) :
|
||||
m_fromSlot(fromSlot),
|
||||
m_fromIdStart(fromId),
|
||||
m_fromIdEnd(fromId + range),
|
||||
m_toSlot(toSlot),
|
||||
m_toIdStart(toId),
|
||||
m_lc(FLCO_USER_USER, 0U, 0U),
|
||||
m_embeddedLC()
|
||||
{
|
||||
assert(fromSlot == 1U || fromSlot == 2U);
|
||||
assert(toSlot == 1U || toSlot == 2U);
|
||||
}
|
||||
|
||||
CRewritePC::~CRewritePC()
|
||||
{
|
||||
}
|
||||
|
||||
bool CRewritePC::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_fromIdStart || dstId >= m_fromIdEnd)
|
||||
return false;
|
||||
|
||||
if (m_fromSlot != m_toSlot)
|
||||
data.setSlotNo(m_toSlot);
|
||||
|
||||
if (m_fromIdStart != m_toIdStart) {
|
||||
unsigned int newDstId = dstId + m_toIdStart - m_fromIdStart;
|
||||
|
||||
data.setDstId(newDstId);
|
||||
|
||||
unsigned char dataType = data.getDataType();
|
||||
|
||||
switch (dataType) {
|
||||
case DT_VOICE_LC_HEADER:
|
||||
case DT_TERMINATOR_WITH_LC:
|
||||
processHeader(data, newDstId, dataType);
|
||||
break;
|
||||
case DT_VOICE:
|
||||
processVoice(data, newDstId);
|
||||
break;
|
||||
case DT_VOICE_SYNC:
|
||||
// Nothing to do
|
||||
break;
|
||||
default:
|
||||
// Not sure what to do
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CRewritePC::processHeader(CDMRData& data, unsigned int dstId, unsigned char dataType)
|
||||
{
|
||||
unsigned int srcId = data.getSrcId();
|
||||
if (srcId != m_lc.getSrcId() || dstId != m_lc.getDstId()) {
|
||||
m_lc.setSrcId(srcId);
|
||||
m_lc.setDstId(dstId);
|
||||
m_embeddedLC.setLC(m_lc);
|
||||
}
|
||||
|
||||
unsigned char buffer[DMR_FRAME_LENGTH_BYTES];
|
||||
data.getData(buffer);
|
||||
|
||||
CDMRFullLC fullLC;
|
||||
fullLC.encode(m_lc, buffer, dataType);
|
||||
|
||||
data.setData(buffer);
|
||||
}
|
||||
|
||||
void CRewritePC::processVoice(CDMRData& data, unsigned int dstId)
|
||||
{
|
||||
unsigned int srcId = data.getSrcId();
|
||||
if (srcId != m_lc.getSrcId() || dstId != m_lc.getDstId()) {
|
||||
m_lc.setSrcId(srcId);
|
||||
m_lc.setDstId(dstId);
|
||||
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);
|
||||
}
|
||||
48
RewritePC.h
Normal file
48
RewritePC.h
Normal file
@@ -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(REWRITEPC_H)
|
||||
#define REWRITEPC_H
|
||||
|
||||
#include "DMREmbeddedData.h"
|
||||
#include "Rewrite.h"
|
||||
#include "DMRData.h"
|
||||
#include "DMRLC.h"
|
||||
|
||||
class CRewritePC : public IRewrite {
|
||||
public:
|
||||
CRewritePC(unsigned int fromSLot, unsigned int fromId, unsigned int toSlot, unsigned int toId, unsigned int range);
|
||||
virtual ~CRewritePC();
|
||||
|
||||
virtual bool process(CDMRData& data);
|
||||
|
||||
private:
|
||||
unsigned int m_fromSlot;
|
||||
unsigned int m_fromIdStart;
|
||||
unsigned int m_fromIdEnd;
|
||||
unsigned int m_toSlot;
|
||||
unsigned int m_toIdStart;
|
||||
CDMRLC m_lc;
|
||||
CDMREmbeddedData m_embeddedLC;
|
||||
|
||||
void processHeader(CDMRData& data, unsigned int dstId, unsigned char dataType);
|
||||
void processVoice(CDMRData& data, unsigned int dstId);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -20,15 +20,16 @@
|
||||
#define REWRITETG_H
|
||||
|
||||
#include "DMREmbeddedData.h"
|
||||
#include "Rewrite.h"
|
||||
#include "DMRData.h"
|
||||
#include "DMRLC.h"
|
||||
|
||||
class CRewriteTG {
|
||||
class CRewriteTG : public IRewrite {
|
||||
public:
|
||||
CRewriteTG(unsigned int fromSLot, unsigned int fromTG, unsigned int toSlot, unsigned int toTG);
|
||||
~CRewriteTG();
|
||||
virtual ~CRewriteTG();
|
||||
|
||||
bool process(CDMRData& data);
|
||||
virtual bool process(CDMRData& data);
|
||||
|
||||
private:
|
||||
unsigned int m_fromSlot;
|
||||
|
||||
Reference in New Issue
Block a user