mirror of
https://github.com/ShaYmez/P25Clients.git
synced 2024-11-25 05:38:39 -05:00
Add TG 9999 for unlinking and improve logging in the gateway.
This commit is contained in:
parent
c560ece1b2
commit
b70dbaa513
@ -53,7 +53,7 @@ m_networkHosts(),
|
|||||||
m_networkReloadTime(0U),
|
m_networkReloadTime(0U),
|
||||||
m_networkParrotAddress("127.0.0.1"),
|
m_networkParrotAddress("127.0.0.1"),
|
||||||
m_networkParrotPort(0U),
|
m_networkParrotPort(0U),
|
||||||
m_networkStartup(0U),
|
m_networkStartup(9999U),
|
||||||
m_networkDebug(false)
|
m_networkDebug(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -192,22 +192,23 @@ void CP25Gateway::run()
|
|||||||
|
|
||||||
LogMessage("Starting P25Gateway-%s", VERSION);
|
LogMessage("Starting P25Gateway-%s", VERSION);
|
||||||
|
|
||||||
bool displayed = false;
|
unsigned int srcId = 0U;
|
||||||
bool seen64 = false;
|
unsigned int dstId = 0U;
|
||||||
bool seen65 = false;
|
|
||||||
|
|
||||||
unsigned int currentId = 0U;
|
unsigned int currentId = 9999U;
|
||||||
in_addr currentAddr;
|
in_addr currentAddr;
|
||||||
unsigned int currentPort = 0U;
|
unsigned int currentPort = 0U;
|
||||||
|
|
||||||
if (remoteNetwork != NULL) {
|
if (remoteNetwork != NULL) {
|
||||||
currentId = m_conf.getNetworkStartup();
|
unsigned int id = m_conf.getNetworkStartup();
|
||||||
CP25Reflector* reflector = reflectors.find(currentId);
|
if (id != 9999U) {
|
||||||
if (reflector != NULL) {
|
CP25Reflector* reflector = reflectors.find(id);
|
||||||
currentAddr = reflector->m_address;
|
if (reflector != NULL) {
|
||||||
currentPort = reflector->m_port;
|
currentId = id;
|
||||||
} else {
|
currentAddr = reflector->m_address;
|
||||||
LogInfo("Startup reflector with id of %u, not found", currentId);
|
currentPort = reflector->m_port;
|
||||||
currentId = 0U;
|
LogMessage("Linked at startup to reflector %u", currentId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +222,7 @@ void CP25Gateway::run()
|
|||||||
unsigned int len = remoteNetwork->readData(buffer, 200U, address, port);
|
unsigned int len = remoteNetwork->readData(buffer, 200U, address, port);
|
||||||
if (len > 0U) {
|
if (len > 0U) {
|
||||||
// If we're linked and it's from the right place, send it on
|
// If we're linked and it's from the right place, send it on
|
||||||
if (currentId != 0U && currentAddr.s_addr == address.s_addr && currentPort == port) {
|
if (currentId != 9999U && currentAddr.s_addr == address.s_addr && currentPort == port) {
|
||||||
// Rewrite the LCF and the destination TG
|
// Rewrite the LCF and the destination TG
|
||||||
if (buffer[0U] == 0x64U) {
|
if (buffer[0U] == 0x64U) {
|
||||||
buffer[1U] = 0x00U; // LCF is for TGs
|
buffer[1U] = 0x00U; // LCF is for TGs
|
||||||
@ -240,33 +241,46 @@ void CP25Gateway::run()
|
|||||||
unsigned int len = localNetwork.readData(buffer, 200U, address, port);
|
unsigned int len = localNetwork.readData(buffer, 200U, address, port);
|
||||||
if (len > 0U) {
|
if (len > 0U) {
|
||||||
if (buffer[0U] == 0x65U) {
|
if (buffer[0U] == 0x65U) {
|
||||||
unsigned int id = 0U;
|
dstId = (buffer[1U] << 16) & 0xFF0000U;
|
||||||
id |= (buffer[1U] << 16) & 0xFF0000U;
|
dstId |= (buffer[2U] << 8) & 0x00FF00U;
|
||||||
id |= (buffer[2U] << 8) & 0x00FF00U;
|
dstId |= (buffer[3U] << 0) & 0x0000FFU;
|
||||||
id |= (buffer[3U] << 0) & 0x0000FFU;
|
} else if (buffer[0U] == 0x66U) {
|
||||||
|
srcId = (buffer[1U] << 16) & 0xFF0000U;
|
||||||
|
srcId |= (buffer[2U] << 8) & 0x00FF00U;
|
||||||
|
srcId |= (buffer[3U] << 0) & 0x0000FFU;
|
||||||
|
|
||||||
if (id != currentId) {
|
if (dstId != currentId) {
|
||||||
CP25Reflector* reflector = reflectors.find(id);
|
if (dstId == 9999U) {
|
||||||
if (reflector != NULL) {
|
std::string callsign = lookup->find(srcId);
|
||||||
currentId = id;
|
LogMessage("Unlinked from reflector %u by %s", currentId, callsign.c_str());
|
||||||
currentAddr = reflector->m_address;
|
currentId = dstId;
|
||||||
currentPort = reflector->m_port;
|
} else {
|
||||||
|
CP25Reflector* reflector = reflectors.find(dstId);
|
||||||
|
if (reflector != NULL) {
|
||||||
|
currentId = dstId;
|
||||||
|
currentAddr = reflector->m_address;
|
||||||
|
currentPort = reflector->m_port;
|
||||||
|
|
||||||
|
std::string callsign = lookup->find(srcId);
|
||||||
|
LogMessage("Linked to reflector %u by %s", currentId, callsign.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite the LCF and the destination TG
|
|
||||||
if (buffer[0U] == 0x64U) {
|
|
||||||
buffer[1U] = 0x00U; // LCF is for TGs
|
|
||||||
} else if (buffer[0U] == 0x65U) {
|
|
||||||
buffer[1U] = (currentId >> 16) & 0xFFU;
|
|
||||||
buffer[2U] = (currentId >> 8) & 0xFFU;
|
|
||||||
buffer[3U] = (currentId >> 0) & 0xFFU;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're linked and we have a network, send it on
|
// If we're linked and we have a network, send it on
|
||||||
if (currentId != 0U && remoteNetwork != NULL)
|
if (currentId != 9999U && remoteNetwork != NULL) {
|
||||||
|
// Rewrite the LCF and the destination TG
|
||||||
|
if (buffer[0U] == 0x64U) {
|
||||||
|
buffer[1U] = 0x00U; // LCF is for TGs
|
||||||
|
} else if (buffer[0U] == 0x65U) {
|
||||||
|
buffer[1U] = (currentId >> 16) & 0xFFU;
|
||||||
|
buffer[2U] = (currentId >> 8) & 0xFFU;
|
||||||
|
buffer[3U] = (currentId >> 0) & 0xFFU;
|
||||||
|
}
|
||||||
|
|
||||||
remoteNetwork->writeData(buffer, len, currentAddr, currentPort);
|
remoteNetwork->writeData(buffer, len, currentAddr, currentPort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ms = stopWatch.elapsed();
|
unsigned int ms = stopWatch.elapsed();
|
||||||
|
Loading…
Reference in New Issue
Block a user