Translate DMR Id to callsign from a file.

This commit is contained in:
Jonathan Naylor 2016-04-12 18:26:13 +01:00
parent 9c59294c23
commit 8eb564ba37
18 changed files with 87 additions and 43 deletions

View file

@ -85,6 +85,7 @@ m_dmrColorCode(2U),
m_dmrSelfOnly(false),
m_dmrPrefixes(),
m_dmrBlackList(),
m_dmrLookupFile(),
m_fusionEnabled(true),
m_fusionParrotEnabled(false),
m_dstarNetworkEnabled(true),
@ -278,7 +279,8 @@ bool CConf::read()
m_dmrBlackList.push_back(id);
p = ::strtok(NULL, ",\r\n");
}
}
} else if (::strcmp(key, "LookupFile") == 0)
m_dmrLookupFile = value;
} else if (section == SECTION_FUSION) {
if (::strcmp(key, "Enable") == 0)
m_fusionEnabled = ::atoi(value) == 1;
@ -547,6 +549,11 @@ std::vector<unsigned int> CConf::getDMRBlackList() const
return m_dmrBlackList;
}
std::string CConf::getDMRLookupFile() const
{
return m_dmrLookupFile;
}
bool CConf::getFusionEnabled() const
{
return m_fusionEnabled;

2
Conf.h
View file

@ -80,6 +80,7 @@ public:
bool getDMRSelfOnly() const;
std::vector<unsigned int> getDMRPrefixes() const;
std::vector<unsigned int> getDMRBlackList() const;
std::string getDMRLookupFile() const;
// The System Fusion section
bool getFusionEnabled() const;
@ -167,6 +168,7 @@ private:
bool m_dmrSelfOnly;
std::vector<unsigned int> m_dmrPrefixes;
std::vector<unsigned int> m_dmrBlackList;
std::string m_dmrLookupFile;
bool m_fusionEnabled;
bool m_fusionParrotEnabled;

View file

@ -20,7 +20,7 @@
#include <cassert>
#include <algorithm>
CDMRControl::CDMRControl(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, unsigned int timeout, CModem* modem, CDMRIPSC* network, IDisplay* display, bool duplex) :
CDMRControl::CDMRControl(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, unsigned int timeout, CModem* modem, CDMRIPSC* network, IDisplay* display, bool duplex, const std::string& lookupFile) :
m_id(id),
m_colorCode(colorCode),
m_selfOnly(selfOnly),
@ -29,12 +29,16 @@ m_blackList(blackList),
m_modem(modem),
m_network(network),
m_slot1(1U, timeout),
m_slot2(2U, timeout)
m_slot2(2U, timeout),
m_lookup(NULL)
{
assert(modem != NULL);
assert(display != NULL);
CDMRSlot::init(id, colorCode, selfOnly, prefixes, blackList, modem, network, display, duplex);
m_lookup = new CDMRLookup(lookupFile);
m_lookup->read();
CDMRSlot::init(id, colorCode, selfOnly, prefixes, blackList, modem, network, display, duplex, m_lookup);
}
CDMRControl::~CDMRControl()
@ -61,36 +65,38 @@ bool CDMRControl::processWakeup(const unsigned char* data)
unsigned int srcId = csbk.getSrcId();
unsigned int bsId = csbk.getBSId();
std::string src = m_lookup->find(srcId);
if (m_selfOnly) {
if (srcId != m_id) {
LogMessage("Invalid CSBK BS_Dwn_Act received from %u", srcId);
LogMessage("Invalid CSBK BS_Dwn_Act received from %s", src.c_str());
return false;
}
} else {
if (std::find(m_blackList.begin(), m_blackList.end(), srcId) != m_blackList.end()) {
LogMessage("Invalid CSBK BS_Dwn_Act received from %u", srcId);
LogMessage("Invalid CSBK BS_Dwn_Act received from %s", src.c_str());
return false;
}
unsigned int prefix = srcId / 10000U;
if (prefix == 0U || prefix > 999U) {
LogMessage("Invalid CSBK BS_Dwn_Act received from %u", srcId);
LogMessage("Invalid CSBK BS_Dwn_Act received from %s", src.c_str());
return false;
}
if (m_prefixes.size() > 0U) {
if (std::find(m_prefixes.begin(), m_prefixes.end(), prefix) == m_prefixes.end()) {
LogMessage("Invalid CSBK BS_Dwn_Act received from %u", srcId);
LogMessage("Invalid CSBK BS_Dwn_Act received from %s", src.c_str());
return false;
}
}
}
if (bsId == 0xFFFFFFU) {
LogMessage("CSBK BS_Dwn_Act for ANY received from %u", srcId);
LogMessage("CSBK BS_Dwn_Act for ANY received from %s", src.c_str());
return true;
} else if (bsId == m_id) {
LogMessage("CSBK BS_Dwn_Act for %u received from %u", bsId, srcId);
LogMessage("CSBK BS_Dwn_Act for %u received from %s", bsId, src.c_str());
return true;
}

View file

@ -19,6 +19,7 @@
#if !defined(DMRControl_H)
#define DMRControl_H
#include "DMRLookup.h"
#include "DMRIPSC.h"
#include "Display.h"
#include "DMRSlot.h"
@ -29,7 +30,7 @@
class CDMRControl {
public:
CDMRControl(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, unsigned int timeout, CModem* modem, CDMRIPSC* network, IDisplay* display, bool duplex);
CDMRControl(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, unsigned int timeout, CModem* modem, CDMRIPSC* network, IDisplay* display, bool duplex, const std::string& lookupFile);
~CDMRControl();
bool processWakeup(const unsigned char* data);
@ -52,6 +53,7 @@ private:
CDMRIPSC* m_network;
CDMRSlot m_slot1;
CDMRSlot m_slot2;
CDMRLookup* m_lookup;
};
#endif

4
DMRIds.dat Normal file
View file

@ -0,0 +1,4 @@
#
# The format of the file is the DMR Id followed by the callsign
#
2351351 G4KLX

View file

@ -36,6 +36,7 @@ CModem* CDMRSlot::m_modem = NULL;
CDMRIPSC* CDMRSlot::m_network = NULL;
IDisplay* CDMRSlot::m_display = NULL;
bool CDMRSlot::m_duplex = true;
CDMRLookup* CDMRSlot::m_lookup = NULL;
unsigned char* CDMRSlot::m_idle = NULL;
@ -173,12 +174,14 @@ void CDMRSlot::writeModem(unsigned char *data)
m_rfState = RS_RF_AUDIO;
std::string src = m_lookup->find(id);
if (m_netState == RS_NET_IDLE) {
setShortLC(m_slotNo, m_rfLC->getDstId(), m_rfLC->getFLCO(), true);
m_display->writeDMR(m_slotNo, id, m_rfLC->getFLCO() == FLCO_GROUP, m_rfLC->getDstId(), "R");
m_display->writeDMR(m_slotNo, src.c_str(), m_rfLC->getFLCO() == FLCO_GROUP, m_rfLC->getDstId(), "R");
}
LogMessage("DMR Slot %u, received RF voice header from %u to %s%u", m_slotNo, id, m_rfLC->getFLCO() == FLCO_GROUP ? "TG " : "", m_rfLC->getDstId());
LogMessage("DMR Slot %u, received RF voice header from %s to %s%u", m_slotNo, src.c_str(), m_rfLC->getFLCO() == FLCO_GROUP ? "TG " : "", m_rfLC->getDstId());
} else if (dataType == DT_VOICE_PI_HEADER) {
if (m_rfState != RS_RF_AUDIO)
return;
@ -280,12 +283,14 @@ void CDMRSlot::writeModem(unsigned char *data)
m_rfState = RS_RF_DATA;
std::string src = m_lookup->find(srcId);
if (m_netState == RS_NET_IDLE) {
setShortLC(m_slotNo, dstId, gi ? FLCO_GROUP : FLCO_USER_USER, false);
m_display->writeDMR(m_slotNo, srcId, gi, dstId, "R");
m_display->writeDMR(m_slotNo, src.c_str(), gi, dstId, "R");
}
LogMessage("DMR Slot %u, received RF data header from %u to %s%u, %u blocks", m_slotNo, srcId, gi ? "TG ": "", dstId, m_rfFrames);
LogMessage("DMR Slot %u, received RF data header from %s to %s%u, %u blocks", m_slotNo, src.c_str(), gi ? "TG ": "", dstId, m_rfFrames);
} else if (dataType == DT_CSBK) {
CDMRCSBK csbk;
bool valid = csbk.put(data + 2U);
@ -553,12 +558,14 @@ void CDMRSlot::writeModem(unsigned char *data)
m_rfState = RS_RF_AUDIO;
std::string src = m_lookup->find(m_rfLC->getSrcId());
if (m_netState == RS_NET_IDLE) {
setShortLC(m_slotNo, m_rfLC->getDstId(), m_rfLC->getFLCO(), true);
m_display->writeDMR(m_slotNo, m_rfLC->getSrcId(), m_rfLC->getFLCO() == FLCO_GROUP, m_rfLC->getDstId(), "R");
m_display->writeDMR(m_slotNo, src.c_str(), m_rfLC->getFLCO() == FLCO_GROUP, m_rfLC->getDstId(), "R");
}
LogMessage("DMR Slot %u, received RF late entry from %u to %s%u", m_slotNo, m_rfLC->getSrcId(), m_rfLC->getFLCO() == FLCO_GROUP ? "TG " : "", m_rfLC->getDstId());
LogMessage("DMR Slot %u, received RF late entry from %s to %s%u", m_slotNo, src.c_str(), m_rfLC->getFLCO() == FLCO_GROUP ? "TG " : "", m_rfLC->getDstId());
}
}
}
@ -730,13 +737,15 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
setShortLC(m_slotNo, m_netLC->getDstId(), m_netLC->getFLCO(), true);
m_display->writeDMR(m_slotNo, m_netLC->getSrcId(), m_netLC->getFLCO() == FLCO_GROUP, m_netLC->getDstId(), "N");
std::string src = m_lookup->find(m_netLC->getSrcId());
m_display->writeDMR(m_slotNo, src.c_str(), m_netLC->getFLCO() == FLCO_GROUP, m_netLC->getDstId(), "N");
#if defined(DUMP_DMR)
openFile();
writeFile(data);
#endif
LogMessage("DMR Slot %u, received network voice header from %u to %s%u", m_slotNo, m_netLC->getSrcId(), m_netLC->getFLCO() == FLCO_GROUP ? "TG " : "", m_netLC->getDstId());
LogMessage("DMR Slot %u, received network voice header from %s to %s%u", m_slotNo, src.c_str(), m_netLC->getFLCO() == FLCO_GROUP ? "TG " : "", m_netLC->getDstId());
} else if (dataType == DT_VOICE_PI_HEADER) {
if (m_netState != RS_NET_AUDIO)
return;
@ -845,9 +854,11 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
setShortLC(m_slotNo, dmrData.getDstId(), gi ? FLCO_GROUP : FLCO_USER_USER, false);
m_display->writeDMR(m_slotNo, dmrData.getSrcId(), gi, dmrData.getDstId(), "N");
std::string src = m_lookup->find(dmrData.getSrcId());
LogMessage("DMR Slot %u, received network data header from %u to %s%u, %u blocks", m_slotNo, dmrData.getSrcId(), gi ? "TG ": "", dmrData.getDstId(), m_netFrames);
m_display->writeDMR(m_slotNo, src.c_str(), gi, dmrData.getDstId(), "N");
LogMessage("DMR Slot %u, received network data header from %s to %s%u, %u blocks", m_slotNo, src.c_str(), gi ? "TG ": "", dmrData.getDstId(), m_netFrames);
} else if (dataType == DT_VOICE_SYNC) {
if (m_netState == RS_NET_IDLE) {
m_netLC = new CDMRLC(dmrData.getFLCO(), dmrData.getSrcId(), dmrData.getDstId());
@ -870,9 +881,11 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
setShortLC(m_slotNo, m_netLC->getDstId(), m_netLC->getFLCO(), true);
m_display->writeDMR(m_slotNo, m_netLC->getSrcId(), m_netLC->getFLCO() == FLCO_GROUP, m_netLC->getDstId(), "N");
std::string src = m_lookup->find(m_netLC->getSrcId());
LogMessage("DMR Slot %u, received network late entry from %u to %s%u", m_slotNo, m_netLC->getSrcId(), m_netLC->getFLCO() == FLCO_GROUP ? "TG " : "", m_netLC->getDstId());
m_display->writeDMR(m_slotNo, src.c_str(), m_netLC->getFLCO() == FLCO_GROUP, m_netLC->getDstId(), "N");
LogMessage("DMR Slot %u, received network late entry from %s to %s%u", m_slotNo, src.c_str(), m_netLC->getFLCO() == FLCO_GROUP ? "TG " : "", m_netLC->getDstId());
}
if (m_netState == RS_NET_AUDIO) {
@ -1229,11 +1242,12 @@ void CDMRSlot::writeQueueNet(const unsigned char *data)
m_queue.addData(data, len);
}
void CDMRSlot::init(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, CModem* modem, CDMRIPSC* network, IDisplay* display, bool duplex)
void CDMRSlot::init(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, CModem* modem, CDMRIPSC* network, IDisplay* display, bool duplex, CDMRLookup* lookup)
{
assert(id != 0U);
assert(modem != NULL);
assert(display != NULL);
assert(lookup != NULL);
m_id = id;
m_colorCode = colorCode;
@ -1244,6 +1258,7 @@ void CDMRSlot::init(unsigned int id, unsigned int colorCode, bool selfOnly, cons
m_network = network;
m_display = display;
m_duplex = duplex;
m_lookup = lookup;
m_idle = new unsigned char[DMR_FRAME_LENGTH_BYTES + 2U];

View file

@ -23,6 +23,7 @@
#include "DMRDataHeader.h"
#include "RingBuffer.h"
#include "StopWatch.h"
#include "DMRLookup.h"
#include "AMBEFEC.h"
#include "DMRSlot.h"
#include "DMRData.h"
@ -49,7 +50,7 @@ public:
void clock();
static void init(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, CModem* modem, CDMRIPSC* network, IDisplay* display, bool duplex);
static void init(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blackList, CModem* modem, CDMRIPSC* network, IDisplay* display, bool duplex, CDMRLookup* lookup);
private:
unsigned int m_slotNo;
@ -93,6 +94,7 @@ private:
static CDMRIPSC* m_network;
static IDisplay* m_display;
static bool m_duplex;
static CDMRLookup* m_lookup;
static unsigned char* m_idle;

View file

@ -36,7 +36,7 @@ public:
virtual void writeDStar(const char* my1, const char* my2, const char* your, const char* type) = 0;
virtual void clearDStar() = 0;
virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId, const char* type) = 0;
virtual void writeDMR(unsigned int slotNo, const char* src, bool group, unsigned int dstId, const char* type) = 0;
virtual void clearDMR(unsigned int slotNo) = 0;
virtual void writeFusion(const char* source, const char* dest) = 0;

View file

@ -154,8 +154,9 @@ void CHD44780::clearDStar()
}
}
void CHD44780::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, unsigned int dstId, const char* type)
void CHD44780::writeDMR(unsigned int slotNo, const char* src, bool group, unsigned int dstId, const char* type)
{
assert(src != NULL);
assert(type != NULL);
if (!m_dmr) {
@ -178,18 +179,18 @@ void CHD44780::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, uns
if (slotNo == 1U) {
char buffer[40U];
if (m_cols > 16U)
::sprintf(buffer, "%s %u > %s%u", type, srcId, group ? "TG" : "", dstId);
::sprintf(buffer, "%s %s > %s%u", type, src, group ? "TG" : "", dstId);
else
::sprintf(buffer, "%u > %s%u", srcId, group ? "TG" : "", dstId);
::sprintf(buffer, "%s > %s%u", src, group ? "TG" : "", dstId);
::lcdPosition(m_fd, 0, m_rows > 2U ? 1 : 0);
::lcdPrintf(m_fd, "1 %.*s", m_cols - 2U, buffer);
} else {
char buffer[40U];
if (m_cols > 16U)
::sprintf(buffer, "%s %u > %s%u", type, srcId, group ? "TG" : "", dstId);
::sprintf(buffer, "%s %s > %s%u", type, src, group ? "TG" : "", dstId);
else
::sprintf(buffer, "%u > %s%u", srcId, group ? "TG" : "", dstId);
::sprintf(buffer, "%s > %s%u", src, group ? "TG" : "", dstId);
::lcdPosition(m_fd, 0, m_rows > 2U ? 2 : 1);
::lcdPrintf(m_fd, "2 %.*s", m_cols - 2U, buffer);

View file

@ -40,7 +40,7 @@ public:
virtual void writeDStar(const char* my1, const char* my2, const char* your, const char* type);
virtual void clearDStar();
virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId, const char* type);
virtual void writeDMR(unsigned int slotNo, const char* src, bool group, unsigned int dstId, const char* type);
virtual void clearDMR(unsigned int slotNo);
virtual void writeFusion(const char* source, const char* dest);

View file

@ -48,6 +48,7 @@ Id=123456
ColorCode=1
SelfOnly=0
# Prefixes=234,235
LookupFile=DMRIds.dat
[System Fusion]
Enable=1

View file

@ -168,6 +168,7 @@ int CMMDVMHost::run()
std::vector<unsigned int> prefixes = m_conf.getDMRPrefixes();
std::vector<unsigned int> blackList = m_conf.getDMRBlackList();
unsigned int timeout = m_conf.getTimeout();
std::string lookupFile = m_conf.getDMRLookupFile();
LogInfo("DMR Parameters");
LogInfo(" Id: %u", id);
@ -177,8 +178,9 @@ int CMMDVMHost::run()
if (blackList.size() > 0U)
LogInfo(" Black List: %u", blackList.size());
LogInfo(" Timeout: %us", timeout);
LogInfo(" Lookup File: %s", lookupFile.length() > 0U ? lookupFile.c_str() : "None");
dmr = new CDMRControl(id, colorCode, selfOnly, prefixes, blackList, timeout, m_modem, m_dmrNetwork, m_display, m_duplex);
dmr = new CDMRControl(id, colorCode, selfOnly, prefixes, blackList, timeout, m_modem, m_dmrNetwork, m_display, m_duplex, lookupFile);
}
CYSFControl* ysf = NULL;

View file

@ -119,8 +119,9 @@ void CNextion::clearDStar()
sendCommand("t1.txt=\"\"");
}
void CNextion::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, unsigned int dstId, const char* type)
void CNextion::writeDMR(unsigned int slotNo, const char* src, bool group, unsigned int dstId, const char* type)
{
assert(src != NULL);
assert(type != NULL);
if (m_mode != MODE_DMR) {
@ -135,7 +136,7 @@ void CNextion::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, uns
if (slotNo == 1U) {
char text[30U];
::sprintf(text, "t0.txt=\"1 %s %u\"", type, srcId);
::sprintf(text, "t0.txt=\"1 %s %s\"", type, src);
sendCommand(text);
::sprintf(text, "t1.txt=\"%s%u\"", group ? "TG" : "", dstId);
@ -143,7 +144,7 @@ void CNextion::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, uns
} else {
char text[30U];
::sprintf(text, "t2.txt=\"2 %s %u\"", type, srcId);
::sprintf(text, "t2.txt=\"2 %s %s\"", type, src);
sendCommand(text);
::sprintf(text, "t3.txt=\"%s%u\"", group ? "TG" : "", dstId);

View file

@ -41,7 +41,7 @@ public:
virtual void writeDStar(const char* my1, const char* my2, const char* your, const char* type);
virtual void clearDStar();
virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId, const char* type);
virtual void writeDMR(unsigned int slotNo, const char* src, bool group, unsigned int dstId, const char* type);
virtual void clearDMR(unsigned int slotNo);
virtual void writeFusion(const char* source, const char* dest);

View file

@ -51,7 +51,7 @@ void CNullDisplay::clearDStar()
{
}
void CNullDisplay::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, unsigned int dstId, const char* type)
void CNullDisplay::writeDMR(unsigned int slotNo, const char* src, bool group, unsigned int dstId, const char* type)
{
}

View file

@ -39,7 +39,7 @@ public:
virtual void writeDStar(const char* my1, const char* my2, const char* your, const char* type);
virtual void clearDStar();
virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId, const char* type);
virtual void writeDMR(unsigned int slotNo, const char* src, bool group, unsigned int dstId, const char* type);
virtual void clearDMR(unsigned int slotNo);
virtual void writeFusion(const char* source, const char* dest);

View file

@ -182,8 +182,9 @@ void CTFTSerial::clearDStar()
displayText(" ");
}
void CTFTSerial::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, unsigned int dstId, const char* type)
void CTFTSerial::writeDMR(unsigned int slotNo, const char* src, bool group, unsigned int dstId, const char* type)
{
assert(src != NULL);
assert(type != NULL);
if (m_mode != MODE_DMR) {
@ -207,7 +208,7 @@ void CTFTSerial::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, u
if (slotNo == 1U) {
char text[30U];
::sprintf(text, "1 %s %u", type, srcId);
::sprintf(text, "1 %s %s", type, src);
gotoPosPixel(5U, 55U);
displayText(text);
@ -217,7 +218,7 @@ void CTFTSerial::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, u
} else {
char text[30U];
::sprintf(text, "2 %s %u", type, srcId);
::sprintf(text, "2 %s %s", type, src);
gotoPosPixel(5U, 90U);
displayText(text);

View file

@ -41,7 +41,7 @@ public:
virtual void writeDStar(const char* my1, const char* my2, const char* your, const char* type);
virtual void clearDStar();
virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId, const char* type);
virtual void writeDMR(unsigned int slotNo, const char* src, bool group, unsigned int dstId, const char* type);
virtual void clearDMR(unsigned int slotNo);
virtual void writeFusion(const char* source, const char* dest);