From d0ceb6416398e4681a9c7cdfc92a9a27f5055f2d Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 3 May 2020 22:24:37 +0100 Subject: [PATCH] Add ranges to dynamic rewrite exclusion private calls/talk groups. --- Conf.cpp | 60 ++++++++++++++++++++++++++++++++++++++-------- Conf.h | 2 +- RewriteDynTGNet.h | 8 +++---- RewriteDynTGRF.cpp | 22 +++++++++++------ RewriteDynTGRF.h | 4 ++-- Version.h | 2 +- 6 files changed, 73 insertions(+), 25 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index 13d9a62..11fbac1 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -432,8 +432,16 @@ bool CConf::read() rewrite.m_toTG = ::atoi(p5); rewrite.m_range = ::atoi(p6); for (std::vector::const_iterator it = p7.cbegin(); it != p7.cend(); ++it) { - unsigned int tg = ::atoi(*it); - rewrite.m_exclTGs.push_back(tg); + const char* exclusion = *it; + const char* p = NULL; + if ((p = ::strchr(exclusion, '-')) != NULL) { + unsigned int tgstart = (unsigned int)::atoi(exclusion); + unsigned int tgend = (unsigned int)::atoi(p + 1U); + rewrite.m_exclTGs.push_back(std::make_pair(tgstart, tgend)); + } else { + unsigned int tg = (unsigned int)::atoi(*it); + rewrite.m_exclTGs.push_back(std::make_pair(tg, tg)); + } } m_dmrNetwork1TGDynRewrites.push_back(rewrite); } @@ -554,8 +562,16 @@ bool CConf::read() rewrite.m_toTG = ::atoi(p5); rewrite.m_range = ::atoi(p6); for (std::vector::const_iterator it = p7.cbegin(); it != p7.cend(); ++it) { - unsigned int tg = ::atoi(*it); - rewrite.m_exclTGs.push_back(tg); + const char* exclusion = *it; + const char* p = NULL; + if ((p = ::strchr(exclusion, '-')) != NULL) { + unsigned int tgstart = (unsigned int)::atoi(exclusion); + unsigned int tgend = (unsigned int)::atoi(p + 1U); + rewrite.m_exclTGs.push_back(std::make_pair(tgstart, tgend)); + } else { + unsigned int tg = (unsigned int)::atoi(*it); + rewrite.m_exclTGs.push_back(std::make_pair(tg, tg)); + } } m_dmrNetwork2TGDynRewrites.push_back(rewrite); } @@ -676,8 +692,16 @@ bool CConf::read() rewrite.m_toTG = ::atoi(p5); rewrite.m_range = ::atoi(p6); for (std::vector::const_iterator it = p7.cbegin(); it != p7.cend(); ++it) { - unsigned int tg = ::atoi(*it); - rewrite.m_exclTGs.push_back(tg); + const char* exclusion = *it; + const char* p = NULL; + if ((p = ::strchr(exclusion, '-')) != NULL) { + unsigned int tgstart = (unsigned int)::atoi(exclusion); + unsigned int tgend = (unsigned int)::atoi(p + 1U); + rewrite.m_exclTGs.push_back(std::make_pair(tgstart, tgend)); + } else { + unsigned int tg = (unsigned int)::atoi(*it); + rewrite.m_exclTGs.push_back(std::make_pair(tg, tg)); + } } m_dmrNetwork3TGDynRewrites.push_back(rewrite); } @@ -798,8 +822,16 @@ bool CConf::read() rewrite.m_toTG = ::atoi(p5); rewrite.m_range = ::atoi(p6); for (std::vector::const_iterator it = p7.cbegin(); it != p7.cend(); ++it) { - unsigned int tg = ::atoi(*it); - rewrite.m_exclTGs.push_back(tg); + const char* exclusion = *it; + const char* p = NULL; + if ((p = ::strchr(exclusion, '-')) != NULL) { + unsigned int tgstart = (unsigned int)::atoi(exclusion); + unsigned int tgend = (unsigned int)::atoi(p + 1U); + rewrite.m_exclTGs.push_back(std::make_pair(tgstart, tgend)); + } else { + unsigned int tg = (unsigned int)::atoi(*it); + rewrite.m_exclTGs.push_back(std::make_pair(tg, tg)); + } } m_dmrNetwork4TGDynRewrites.push_back(rewrite); } @@ -920,8 +952,16 @@ bool CConf::read() rewrite.m_toTG = ::atoi(p5); rewrite.m_range = ::atoi(p6); for (std::vector::const_iterator it = p7.cbegin(); it != p7.cend(); ++it) { - unsigned int tg = ::atoi(*it); - rewrite.m_exclTGs.push_back(tg); + const char* exclusion = *it; + const char* p = NULL; + if ((p = ::strchr(exclusion, '-')) != NULL) { + unsigned int tgstart = (unsigned int)::atoi(exclusion); + unsigned int tgend = (unsigned int)::atoi(p + 1U); + rewrite.m_exclTGs.push_back(std::make_pair(tgstart, tgend)); + } else { + unsigned int tg = (unsigned int)::atoi(*it); + rewrite.m_exclTGs.push_back(std::make_pair(tg, tg)); + } } m_dmrNetwork5TGDynRewrites.push_back(rewrite); } diff --git a/Conf.h b/Conf.h index b038329..b6c0c00 100644 --- a/Conf.h +++ b/Conf.h @@ -61,7 +61,7 @@ struct CTGDynRewriteStruct { unsigned int m_statusPC; unsigned int m_toTG; unsigned int m_range; - std::vector m_exclTGs; + std::vector> m_exclTGs; }; struct CIdRewriteStruct { diff --git a/RewriteDynTGNet.h b/RewriteDynTGNet.h index 60b59c7..6b62b17 100644 --- a/RewriteDynTGNet.h +++ b/RewriteDynTGNet.h @@ -34,10 +34,10 @@ public: void setCurrentTG(unsigned int tg); private: - std::string m_name; - unsigned int m_slot; - unsigned int m_toTG; - unsigned int m_currentTG; + std::string m_name; + unsigned int m_slot; + unsigned int m_toTG; + unsigned int m_currentTG; }; #endif diff --git a/RewriteDynTGRF.cpp b/RewriteDynTGRF.cpp index 728b472..67b0f66 100644 --- a/RewriteDynTGRF.cpp +++ b/RewriteDynTGRF.cpp @@ -25,7 +25,7 @@ #include #include -CRewriteDynTGRF::CRewriteDynTGRF(const std::string& name, unsigned int slot, unsigned int fromTG, unsigned int toTG, unsigned int discPC, unsigned int statusPC, unsigned int range, const std::vector& exclTGs, CRewriteDynTGNet* rewriteNet, CDynVoice* voice) : +CRewriteDynTGRF::CRewriteDynTGRF(const std::string& name, unsigned int slot, unsigned int fromTG, unsigned int toTG, unsigned int discPC, unsigned int statusPC, unsigned int range, const std::vector>& exclTGs, CRewriteDynTGNet* rewriteNet, CDynVoice* voice) : CRewrite(), m_name(name), m_slot(slot), @@ -105,11 +105,15 @@ PROCESS_RESULT CRewriteDynTGRF::process(CDMRData& data, bool trace) return RESULT_IGNORED; } - if (slotNo == m_slot && std::find(m_exclTGs.cbegin(), m_exclTGs.cend(), dstId) != m_exclTGs.cend()) { - if (trace) - LogDebug("Rule Trace,\tRewriteDynTGRF from %s Slot=%u Dst=%u: not matched", m_name.c_str(), m_slot, dstId); + if (slotNo == m_slot) { + for (std::vector>::const_iterator it = m_exclTGs.cbegin(); it != m_exclTGs.cend(); ++it) { + if (dstId >= (*it).first && dstId <= (*it).second) { + if (trace) + LogDebug("Rule Trace,\tRewriteDynTGRF from %s Slot=%u Dst=%u: not matched", m_name.c_str(), m_slot, dstId); - return RESULT_UNMATCHED; + return RESULT_UNMATCHED; + } + } } if (slotNo == m_slot && dstId >= m_fromTGStart && dstId <= m_fromTGEnd) { @@ -159,8 +163,12 @@ void CRewriteDynTGRF::tgChange(unsigned int slot, unsigned int tg) if (slot == m_slot && tg == m_statusPC) return; - if (slot == m_slot && std::find(m_exclTGs.cbegin(), m_exclTGs.cend(), tg) != m_exclTGs.cend()) - return; + if (slot == m_slot) { + for (std::vector>::const_iterator it = m_exclTGs.cbegin(); it != m_exclTGs.cend(); ++it) { + if (tg >= (*it).first && tg <= (*it).second) + return; + } + } if (slot == m_slot && tg >= m_fromTGStart && tg <= m_fromTGEnd) { if (m_currentTG != tg) { diff --git a/RewriteDynTGRF.h b/RewriteDynTGRF.h index d5a2b06..48e5223 100644 --- a/RewriteDynTGRF.h +++ b/RewriteDynTGRF.h @@ -30,7 +30,7 @@ class CRewriteDynTGRF : public CRewrite { public: - CRewriteDynTGRF(const std::string& name, unsigned int slot, unsigned int fromTG, unsigned int toTG, unsigned int discPC, unsigned int statusPC, unsigned int range, const std::vector& exclTGs, CRewriteDynTGNet* rewriteNet, CDynVoice* voice); + CRewriteDynTGRF(const std::string& name, unsigned int slot, unsigned int fromTG, unsigned int toTG, unsigned int discPC, unsigned int statusPC, unsigned int range, const std::vector>& exclTGs, CRewriteDynTGNet* rewriteNet, CDynVoice* voice); virtual ~CRewriteDynTGRF(); virtual PROCESS_RESULT process(CDMRData& data, bool trace); @@ -47,7 +47,7 @@ private: unsigned int m_toTG; unsigned int m_discPC; unsigned int m_statusPC; - std::vector m_exclTGs; + std::vector> m_exclTGs; CRewriteDynTGNet* m_rewriteNet; CDynVoice* m_voice; unsigned int m_currentTG; diff --git a/Version.h b/Version.h index aa4c644..cae5135 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20200421"; +const char* VERSION = "20200503"; #endif