Handle relinking cleanly.

This commit is contained in:
Jonathan Naylor 2016-10-11 22:46:28 +01:00
parent 820fd5471a
commit ce94d72fc6

View File

@ -267,7 +267,12 @@ void CP25Gateway::run()
srcId |= (buffer[3U] << 0) & 0x0000FFU; srcId |= (buffer[3U] << 0) & 0x0000FFU;
if (dstId != currentId) { if (dstId != currentId) {
if (dstId == 9999U) { CP25Reflector* reflector = NULL;
if (dstId != 9999U)
reflector = reflectors.find(dstId);
// If we're unlinking or changing reflectors, unlink from the current one
if (dstId == 9999U || reflector != NULL) {
std::string callsign = lookup->find(srcId); std::string callsign = lookup->find(srcId);
LogMessage("Unlinked from reflector %u by %s", currentId, callsign.c_str()); LogMessage("Unlinked from reflector %u by %s", currentId, callsign.c_str());
currentId = dstId; currentId = dstId;
@ -279,8 +284,9 @@ void CP25Gateway::run()
pollTimer.stop(); pollTimer.stop();
lostTimer.stop(); lostTimer.stop();
} }
} else { }
CP25Reflector* reflector = reflectors.find(dstId);
// Link to the new reflector
if (reflector != NULL) { if (reflector != NULL) {
currentId = dstId; currentId = dstId;
currentAddr = reflector->m_address; currentAddr = reflector->m_address;
@ -299,7 +305,6 @@ void CP25Gateway::run()
} }
} }
} }
}
// 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 != 9999U && remoteNetwork != NULL) { if (currentId != 9999U && remoteNetwork != NULL) {