Skip to content

Commit

Permalink
Fix: XLX ID as 3 characters string instead of a number.
Browse files Browse the repository at this point in the history
 * Since some XLX reflectors are using characters instead of numbers (like USA,JPN,etc...), it's not possible to use them as startup reflector.
 * Of course, it's still not possible to switch to that kind of reflector using the xlxBase + 4000 trick.
Update Copyright year.
  • Loading branch information
f1rmb committed Feb 17, 2022
1 parent 518c2a6 commit 4f9f30b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 49 deletions.
17 changes: 13 additions & 4 deletions Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ m_xlxNetworkLocal(0U),
m_xlxNetworkSlot(1U),
m_xlxNetworkTG(8U),
m_xlxNetworkBase(84000U),
m_xlxNetworkStartup(4000U),
m_xlxNetworkStartup("4000"),
m_xlxNetworkRelink(0U),
m_xlxNetworkDebug(false),
m_xlxNetworkUserControl(true),
Expand Down Expand Up @@ -342,8 +342,17 @@ bool CConf::read()
m_xlxNetworkTG = (unsigned int)::atoi(value);
else if (::strcmp(key, "Base") == 0)
m_xlxNetworkBase = (unsigned int)::atoi(value);
else if (::strcmp(key, "Startup") == 0)
m_xlxNetworkStartup = (unsigned int)::atoi(value);
else if (::strcmp(key, "Startup") == 0) {
char buffer[16];
char *p = buffer;

// Right align, then pads with zeros, as XLX IDs are 3 characters length
snprintf(buffer, sizeof(buffer), "%3s", value);
while ((*p != '\0') && (*p == ' '))
*p++ = '0';

m_xlxNetworkStartup = std::string(buffer);
}
else if (::strcmp(key, "Relink") == 0)
m_xlxNetworkRelink = (unsigned int)::atoi(value);
else if (::strcmp(key, "Debug") == 0)
Expand Down Expand Up @@ -1165,7 +1174,7 @@ unsigned int CConf::getXLXNetworkBase() const
return m_xlxNetworkBase;
}

unsigned int CConf::getXLXNetworkStartup() const
std::string CConf::getXLXNetworkStartup() const
{
return m_xlxNetworkStartup;
}
Expand Down
4 changes: 2 additions & 2 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class CConf
unsigned int getXLXNetworkSlot() const;
unsigned int getXLXNetworkTG() const;
unsigned int getXLXNetworkBase() const;
unsigned int getXLXNetworkStartup() const;
std::string getXLXNetworkStartup() const;
unsigned int getXLXNetworkRelink() const;
bool getXLXNetworkDebug() const;
bool getXLXNetworkUserControl() const;
Expand Down Expand Up @@ -380,7 +380,7 @@ class CConf
unsigned int m_xlxNetworkSlot;
unsigned int m_xlxNetworkTG;
unsigned int m_xlxNetworkBase;
unsigned int m_xlxNetworkStartup;
std::string m_xlxNetworkStartup;
unsigned int m_xlxNetworkRelink;
bool m_xlxNetworkDebug;
bool m_xlxNetworkUserControl;
Expand Down
52 changes: 28 additions & 24 deletions DMRGateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void sigHandler(int signum)
const char* HEADER1 = "This software is for use on amateur radio networks only,";
const char* HEADER2 = "it is to be used for educational purposes only. Its use on";
const char* HEADER3 = "commercial networks is strictly prohibited.";
const char* HEADER4 = "Copyright(C) 2017-2020 by Jonathan Naylor, G4KLX and others";
const char* HEADER4 = "Copyright(C) 2017-2022 by Jonathan Naylor, G4KLX and others";

int main(int argc, char** argv)
{
Expand Down Expand Up @@ -141,15 +141,15 @@ m_dmr5Name(),
m_xlxReflectors(NULL),
m_xlxNetwork(NULL),
m_xlxId(0U),
m_xlxNumber(0U),
m_xlxNumber("000"),
m_xlxReflector(4000U),
m_xlxSlot(0U),
m_xlxTG(0U),
m_xlxBase(0U),
m_xlxLocal(0U),
m_xlxPort(62030U),
m_xlxPassword("passw0rd"),
m_xlxStartup(950U),
m_xlxStartup("950"),
m_xlxRoom(4000U),
m_xlxRelink(1000U),
m_xlxConnected(false),
Expand Down Expand Up @@ -548,13 +548,13 @@ int CDMRGateway::run()
if (m_xlxReflector >= 4001U && m_xlxReflector <= 4026U) {
writeXLXLink(m_xlxId, m_xlxReflector, m_xlxNetwork);
char c = ('A' + (m_xlxReflector % 100U)) - 1U;
LogMessage("XLX, Linking to reflector XLX%03u %c", m_xlxNumber, c);
LogMessage("XLX, Linking to reflector XLX%s %c", m_xlxNumber.c_str(), c);
if (m_xlxVoice != NULL)
m_xlxVoice->linkedTo(m_xlxNumber, m_xlxReflector);
} else if (m_xlxRoom >= 4001U && m_xlxRoom <= 4026U) {
writeXLXLink(m_xlxId, m_xlxRoom, m_xlxNetwork);
char c = ('A' + (m_xlxRoom % 100U)) - 1U;
LogMessage("XLX, Linking to reflector XLX%03u %c", m_xlxNumber, c);
LogMessage("XLX, Linking to reflector XLX%s %c", m_xlxNumber.c_str(), c);
if (m_xlxVoice != NULL)
m_xlxVoice->linkedTo(m_xlxNumber, m_xlxRoom);
m_xlxReflector = m_xlxRoom;
Expand All @@ -570,7 +570,7 @@ int CDMRGateway::run()
else
m_xlxRelink.start();
} else if (!connected && m_xlxConnected) {
LogMessage("XLX, Unlinking from XLX%03u due to loss of connection", m_xlxNumber);
LogMessage("XLX, Unlinking from XLX%s due to loss of connection", m_xlxNumber.c_str());

if (m_xlxVoice != NULL)
m_xlxVoice->unlinked();
Expand All @@ -581,13 +581,13 @@ int CDMRGateway::run()
m_xlxRelink.stop();

if (m_xlxNumber != m_xlxStartup) {
if (m_xlxStartup > 0U) {
if (m_xlxStartup != "4000") {
m_xlxReflector = 4000U;
char c = ('A' + (m_xlxRoom % 100U)) - 1U;
LogMessage("XLX, Re-linking to startup reflector XLX%03u %c due to RF inactivity timeout", m_xlxNumber, c);
LogMessage("XLX, Re-linking to startup reflector XLX%s %c due to RF inactivity timeout", m_xlxNumber.c_str(), c);
linkXLX(m_xlxStartup);
} else {
LogMessage("XLX, Unlinking from XLX%03u due to RF inactivity timeout", m_xlxNumber);
LogMessage("XLX, Unlinking from XLX%s due to RF inactivity timeout", m_xlxNumber.c_str());
unlinkXLX();
}
} else {
Expand All @@ -597,10 +597,10 @@ int CDMRGateway::run()
if (m_xlxRoom >= 4001U && m_xlxRoom <= 4026U) {
writeXLXLink(m_xlxId, m_xlxRoom, m_xlxNetwork);
char c = ('A' + (m_xlxRoom % 100U)) - 1U;
LogMessage("XLX, Re-linking to startup reflector XLX%03u %c due to RF inactivity timeout", m_xlxNumber, c);
LogMessage("XLX, Re-linking to startup reflector XLX%s %c due to RF inactivity timeout", m_xlxNumber.c_str(), c);
} else if (m_xlxReflector >= 4001U && m_xlxReflector <= 4026U) {
char c = ('A' + (m_xlxReflector % 100U)) - 1U;
LogMessage("XLX, Unlinking from reflector XLX%03u %c due to RF inactivity timeout", m_xlxNumber, c);
LogMessage("XLX, Unlinking from reflector XLX%s %c due to RF inactivity timeout", m_xlxNumber.c_str(), c);
}

m_xlxReflector = m_xlxRoom;
Expand Down Expand Up @@ -643,14 +643,14 @@ int CDMRGateway::run()
writeXLXLink(srcId, 4000U, m_xlxNetwork);
m_xlxReflector = 4000U;
char c = ('A' + (m_xlxRoom % 100U)) - 1U;
LogMessage("XLX, Unlinking from reflector XLX%03u %c", m_xlxNumber, c);
LogMessage("XLX, Unlinking from reflector XLX%s %c", m_xlxNumber.c_str(), c);
} else if (dstId != 5000U) {
if (m_xlxReflector != 4000U)
writeXLXLink(srcId, 4000U, m_xlxNetwork);
writeXLXLink(srcId, dstId, m_xlxNetwork);
m_xlxReflector = dstId;
char c = ('A' + (dstId % 100U)) - 1U;
LogMessage("XLX, Linking to reflector XLX%03u %c", m_xlxNumber, c);
LogMessage("XLX, Linking to reflector XLX%s %c", m_xlxNumber.c_str(), c);
}

if (m_xlxReflector != m_xlxRoom)
Expand All @@ -677,11 +677,15 @@ int CDMRGateway::run()
}
}
} else if (dstId >= (m_xlxBase + 4000U) && dstId < (m_xlxBase + 5000U) && flco == FLCO_USER_USER && slotNo == m_xlxSlot && m_xlxUserControl) {
char dstIdBuf[16];

dstId -= 4000U;
dstId -= m_xlxBase;

if (dstId != m_xlxNumber)
linkXLX(dstId);
// it's all 3 characters IDS, and not digits.
snprintf(dstIdBuf, sizeof(dstIdBuf), "%03u", dstId);
if (std::string(dstIdBuf) != m_xlxNumber)
linkXLX(dstIdBuf);
} else {
unsigned int slotNo = data.getSlotNo();
unsigned int srcId = data.getSrcId();
Expand Down Expand Up @@ -942,7 +946,7 @@ int CDMRGateway::run()
unsigned int slotNo = data.getSlotNo();
unsigned int dstId = data.getDstId();
FLCO flco = data.getFLCO();
LogWarning("XLX%03u, Unexpected data from slot %u %s%u", m_xlxNumber, slotNo, flco == FLCO_GROUP ? "TG" : "", dstId);
LogWarning("XLX%s, Unexpected data from slot %u %s%u", m_xlxNumber.c_str(), slotNo, flco == FLCO_GROUP ? "TG" : "", dstId);
}
}
}
Expand Down Expand Up @@ -2257,8 +2261,8 @@ bool CDMRGateway::createXLXNetwork()
LogInfo(" TG: %u", m_xlxTG);
LogInfo(" Base: %u", m_xlxBase);

if (m_xlxStartup > 0U)
LogInfo(" Startup: XLX%03u", m_xlxStartup);
if (m_xlxStartup != "4000")
LogInfo(" Startup: XLX%s", m_xlxStartup.c_str());

if (xlxRelink > 0U) {
m_xlxRelink.setTimeout(xlxRelink * 60U);
Expand All @@ -2273,9 +2277,9 @@ bool CDMRGateway::createXLXNetwork()
LogInfo(" User Control: disabled");

if (m_xlxModule != 0U)
LogInfo(" Module: %c", m_xlxModule);
LogInfo(" Module: %c", m_xlxModule);

if (m_xlxStartup > 0U)
if (m_xlxStartup != "4000")
linkXLX(m_xlxStartup);

m_rptRewrite = new CRewriteTG("XLX", XLX_SLOT, XLX_TG, m_xlxSlot, m_xlxTG, 1U);
Expand All @@ -2300,14 +2304,14 @@ bool CDMRGateway::createDynamicTGControl()
return true;
}

bool CDMRGateway::linkXLX(unsigned int number)
bool CDMRGateway::linkXLX(const std::string &number)
{
CReflector* reflector = m_xlxReflectors->find(number);
if (reflector == NULL)
return false;

if (m_xlxNetwork != NULL) {
LogMessage("XLX, Disconnecting from XLX%03u", m_xlxNumber);
LogMessage("XLX, Disconnecting from XLX%s", m_xlxNumber.c_str());
m_xlxNetwork->close(true);
delete m_xlxNetwork;
}
Expand Down Expand Up @@ -2335,7 +2339,7 @@ bool CDMRGateway::linkXLX(unsigned int number)
m_xlxRoom = reflector->m_startup;
m_xlxReflector = 4000U;

LogMessage("XLX, Connecting to XLX%03u", m_xlxNumber);
LogMessage("XLX, Connecting to XLX%s", m_xlxNumber.c_str());

m_xlxNetwork->enable(m_networkXlxEnabled);

Expand Down Expand Up @@ -2678,7 +2682,7 @@ void CDMRGateway::buildNetworkHostNetworkString(std::string &str, const std::str
{
if (network && (network == m_xlxNetwork)) {
std::string module = ((m_xlxReflector >= 4001U && m_xlxReflector <= 4026U) ? ("_" + std::string(1, (('A' + (m_xlxReflector % 100U)) - 1U))) : "");
str += name + ":\"XLX" + std::to_string(m_xlxNumber) + module + "\"";
str += name + ":\"XLX" + m_xlxNumber + module + "\"";
} else {
std::string host = ((network == NULL) ? "NONE" : network->getName());
str += name + ":\""+ ((network == NULL) ? "NONE" : ((host.length() > 0) ? host : "NONE")) + "\"";
Expand Down
6 changes: 3 additions & 3 deletions DMRGateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ class CDMRGateway
CReflectors* m_xlxReflectors;
CDMRNetwork* m_xlxNetwork;
unsigned int m_xlxId;
unsigned int m_xlxNumber;
std::string m_xlxNumber;
unsigned int m_xlxReflector;
unsigned int m_xlxSlot;
unsigned int m_xlxTG;
unsigned int m_xlxBase;
unsigned short m_xlxLocal;
unsigned short m_xlxPort;
std::string m_xlxPassword;
unsigned int m_xlxStartup;
std::string m_xlxStartup;
unsigned int m_xlxRoom;
CTimer m_xlxRelink;
bool m_xlxConnected;
Expand Down Expand Up @@ -142,7 +142,7 @@ class CDMRGateway
bool createXLXNetwork();
bool createDynamicTGControl();

bool linkXLX(unsigned int number);
bool linkXLX(const std::string &number);
void unlinkXLX();
void writeXLXLink(unsigned int srcId, unsigned int dstId, CDMRNetwork* network);

Expand Down
6 changes: 3 additions & 3 deletions Reflectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool CReflectors::load()

if (p1 != NULL && p2 != NULL && p3 != NULL) {
CReflector* refl = new CReflector;
refl->m_id = (unsigned int)::atoi(p1);
refl->m_id = std::string(p1);
refl->m_address = std::string(p2);
refl->m_startup = (unsigned int)::atoi(p3);
m_reflectors.push_back(refl);
Expand All @@ -83,14 +83,14 @@ bool CReflectors::load()
return true;
}

CReflector* CReflectors::find(unsigned int id)
CReflector* CReflectors::find(const std::string &id)
{
for (std::vector<CReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) {
if (id == (*it)->m_id)
return *it;
}

LogMessage("Trying to find non existent XLX reflector with an id of %u", id);
LogMessage("Trying to find non existent XLX reflector with an id of %s", id.c_str());

return NULL;
}
Expand Down
10 changes: 5 additions & 5 deletions Reflectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
class CReflector {
public:
CReflector() :
m_id(0U),
m_id("0"),
m_address(),
m_startup(0U)
{
}

unsigned int m_id;
std::string m_id;
std::string m_address;
unsigned int m_startup;
};
Expand All @@ -45,14 +45,14 @@ class CReflectors {

bool load();

CReflector* find(unsigned int id);
CReflector* find(const std::string &id);

void clock(unsigned int ms);
void clock(unsigned int ms);

private:
std::string m_hostsFile;
std::vector<CReflector*> m_reflectors;
CTimer m_timer;
CTimer m_timer;
};

#endif
11 changes: 4 additions & 7 deletions XLXVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,8 @@ bool CXLXVoice::open()
return true;
}

void CXLXVoice::linkedTo(unsigned int number, unsigned int room)
void CXLXVoice::linkedTo(const std::string &number, unsigned int room)
{
char letters[10U];
::sprintf(letters, "%03u", number);

std::vector<std::string> words;
if (m_positions.count("linkedto") == 0U) {
words.push_back("linked");
Expand All @@ -145,9 +142,9 @@ void CXLXVoice::linkedTo(unsigned int number, unsigned int room)
words.push_back("X");
words.push_back("L");
words.push_back("X");
words.push_back(std::string(1U, letters[0U]));
words.push_back(std::string(1U, letters[1U]));
words.push_back(std::string(1U, letters[2U]));
words.push_back(number.substr(0U, 1U));
words.push_back(number.substr(1U, 1U));
words.push_back(number.substr(2U, 1U));

// 4001 => 1 => A, 4002 => 2 => B, etc.
room %= 100U;
Expand Down
2 changes: 1 addition & 1 deletion XLXVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CXLXVoice {

bool open();

void linkedTo(unsigned int number, unsigned int room);
void linkedTo(const std::string &number, unsigned int room);
void unlinked();

void reset();
Expand Down

0 comments on commit 4f9f30b

Please sign in to comment.