mirror of
https://github.com/g4klx/DMRGateway
synced 2025-12-21 05:25:40 +08:00
Convert the relink code to using the Timer class.
This commit is contained in:
@@ -36,8 +36,6 @@
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
@@ -144,7 +142,7 @@ m_xlx1Slot(0U),
|
||||
m_xlx1TG(0U),
|
||||
m_xlx1Base(0U),
|
||||
m_xlx1Startup(4000U),
|
||||
m_xlx1Relink(0U),
|
||||
m_xlx1Relink(1000U),
|
||||
m_xlx1Connected(false),
|
||||
m_rpt1Rewrite(NULL),
|
||||
m_xlx1Rewrite(NULL),
|
||||
@@ -154,7 +152,7 @@ m_xlx2Slot(0U),
|
||||
m_xlx2TG(0U),
|
||||
m_xlx2Base(0U),
|
||||
m_xlx2Startup(4000U),
|
||||
m_xlx2Relink(0U),
|
||||
m_xlx2Relink(1000U),
|
||||
m_xlx2Connected(false),
|
||||
m_rpt2Rewrite(NULL),
|
||||
m_xlx2Rewrite(NULL),
|
||||
@@ -379,10 +377,6 @@ int CDMRGateway::run()
|
||||
unsigned int dmr2DstId[3U];
|
||||
dmr2SrcId[1U] = dmr2SrcId[2U] = dmr2DstId[1U] = dmr2DstId[2U] = 0U;
|
||||
|
||||
//Last seen RF transmissions on XLX, to implement relinking.
|
||||
std::time_t xlx1LastSeenTime = 0;
|
||||
std::time_t xlx2LastSeenTime = 0;
|
||||
|
||||
CStopWatch stopWatch;
|
||||
stopWatch.start();
|
||||
|
||||
@@ -403,6 +397,7 @@ int CDMRGateway::run()
|
||||
|
||||
m_xlx1Reflector = m_xlx1Startup;
|
||||
m_xlx1Connected = true;
|
||||
m_xlx1Relink.stop();
|
||||
} else if (!connected && m_xlx1Connected) {
|
||||
if (m_xlx1Reflector != 4000U) {
|
||||
LogMessage("XLX-1, Unlinking due to loss of connection");
|
||||
@@ -412,12 +407,15 @@ int CDMRGateway::run()
|
||||
|
||||
m_xlx1Reflector = 4000U;
|
||||
m_xlx1Connected = false;
|
||||
} else if (connected && m_xlx1Relink && xlx1LastSeenTime && (unsigned(time(NULL)) - unsigned(xlx1LastSeenTime)) > (m_xlx1Relink * 60U) && m_xlx1Reflector != m_xlx1Startup) {
|
||||
m_xlx1Relink.stop();
|
||||
} else if (connected && m_xlx1Relink.isRunning() && m_xlx1Relink.hasExpired()) {
|
||||
m_xlx1Relink.stop();
|
||||
|
||||
if (m_xlx1Startup != 4000U)
|
||||
writeXLXLink(m_xlx1Id, 4000U, m_xlxNetwork1);
|
||||
|
||||
writeXLXLink(m_xlx1Id, m_xlx1Startup, m_xlxNetwork1);
|
||||
LogMessage("XLX-1, Re-linking to startup reflector %u due to RF inactivity timeout (%u minutes)", m_xlx1Startup, m_xlx1Relink);
|
||||
LogMessage("XLX-1, Re-linking to startup reflector %u due to RF inactivity timeout", m_xlx1Startup);
|
||||
m_xlx1Reflector = m_xlx1Startup;
|
||||
|
||||
if (voice1 != NULL) {
|
||||
@@ -441,6 +439,7 @@ int CDMRGateway::run()
|
||||
|
||||
m_xlx2Reflector = m_xlx2Startup;
|
||||
m_xlx2Connected = true;
|
||||
m_xlx2Relink.stop();
|
||||
} else if (!connected && m_xlx2Connected) {
|
||||
if (m_xlx2Reflector != 4000U) {
|
||||
LogMessage("XLX-2, Unlinking due to loss of connection");
|
||||
@@ -450,12 +449,15 @@ int CDMRGateway::run()
|
||||
|
||||
m_xlx2Reflector = 4000U;
|
||||
m_xlx2Connected = false;
|
||||
} else if (connected && m_xlx2Relink && xlx2LastSeenTime && (unsigned(time(NULL)) - unsigned(xlx2LastSeenTime)) > (m_xlx2Relink * 60U) && m_xlx2Reflector != m_xlx2Startup) {
|
||||
if (m_xlx2Startup != 4000U)
|
||||
writeXLXLink(m_xlx2Id, 4000U, m_xlxNetwork2);
|
||||
m_xlx2Relink.stop();
|
||||
} else if (connected && m_xlx2Relink.isRunning() && m_xlx2Relink.hasExpired()) {
|
||||
m_xlx2Relink.stop();
|
||||
|
||||
if (m_xlx2Startup != 4000U)
|
||||
writeXLXLink(m_xlx2Id, 4000U, m_xlxNetwork2);
|
||||
|
||||
writeXLXLink(m_xlx2Id, m_xlx2Startup, m_xlxNetwork2);
|
||||
LogMessage("XLX-2, Re-linking to startup reflector %u due to RF inactivity timeout (%u minutes)", m_xlx2Startup, m_xlx2Relink);
|
||||
LogMessage("XLX-2, Re-linking to startup reflector %u due to RF inactivity timeout", m_xlx2Startup);
|
||||
m_xlx2Reflector = m_xlx2Startup;
|
||||
|
||||
if (voice1 != NULL) {
|
||||
@@ -464,7 +466,7 @@ int CDMRGateway::run()
|
||||
else
|
||||
voice1->linkedTo(m_xlx2Startup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CDMRData data;
|
||||
@@ -477,13 +479,17 @@ int CDMRGateway::run()
|
||||
FLCO flco = data.getFLCO();
|
||||
|
||||
if (flco == FLCO_GROUP && slotNo == m_xlx1Slot && dstId == m_xlx1TG) {
|
||||
xlx1LastSeenTime = time(NULL);
|
||||
if (m_xlx1Reflector != m_xlx1Startup)
|
||||
m_xlx1Relink.start();
|
||||
|
||||
m_xlx1Rewrite->process(data, false);
|
||||
m_xlxNetwork1->write(data);
|
||||
status[slotNo] = DMRGWS_XLXREFLECTOR1;
|
||||
timer[slotNo]->start();
|
||||
} else if (flco == FLCO_GROUP && slotNo == m_xlx2Slot && dstId == m_xlx2TG) {
|
||||
xlx2LastSeenTime = time(NULL);
|
||||
if (m_xlx2Reflector != m_xlx2Startup)
|
||||
m_xlx2Relink.start();
|
||||
|
||||
m_xlx2Rewrite->process(data, false);
|
||||
m_xlxNetwork2->write(data);
|
||||
status[slotNo] = DMRGWS_XLXREFLECTOR2;
|
||||
@@ -510,9 +516,13 @@ int CDMRGateway::run()
|
||||
if (dstId != 5000U ) {
|
||||
writeXLXLink(srcId, dstId, m_xlxNetwork1);
|
||||
m_xlx1Reflector = dstId;
|
||||
xlx1LastSeenTime = time(NULL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (m_xlx1Reflector != m_xlx1Startup)
|
||||
m_xlx1Relink.start();
|
||||
else
|
||||
m_xlx2Relink.stop();
|
||||
}
|
||||
|
||||
status[slotNo] = DMRGWS_XLXREFLECTOR1;
|
||||
@@ -552,9 +562,13 @@ int CDMRGateway::run()
|
||||
if (dstId != 5000U ) {
|
||||
writeXLXLink(srcId, dstId, m_xlxNetwork2);
|
||||
m_xlx2Reflector = dstId;
|
||||
xlx2LastSeenTime = time(NULL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (m_xlx2Reflector != m_xlx2Startup)
|
||||
m_xlx2Relink.start();
|
||||
else
|
||||
m_xlx2Relink.stop();
|
||||
}
|
||||
|
||||
status[slotNo] = DMRGWS_XLXREFLECTOR2;
|
||||
@@ -852,6 +866,9 @@ int CDMRGateway::run()
|
||||
|
||||
m_repeater->clock(ms);
|
||||
|
||||
m_xlx1Relink.clock(ms);
|
||||
m_xlx2Relink.clock(ms);
|
||||
|
||||
if (m_dmrNetwork1 != NULL)
|
||||
m_dmrNetwork1->clock(ms);
|
||||
|
||||
@@ -1201,7 +1218,8 @@ bool CDMRGateway::createXLXNetwork1()
|
||||
m_xlx1TG = m_conf.getXLXNetwork1TG();
|
||||
m_xlx1Base = m_conf.getXLXNetwork1Base();
|
||||
m_xlx1Startup = m_conf.getXLXNetwork1Startup();
|
||||
m_xlx1Relink = m_conf.getXLXNetwork1Relink();
|
||||
|
||||
unsigned int xlx1Relink = m_conf.getXLXNetwork1Relink();
|
||||
|
||||
LogInfo(" Slot: %u", m_xlx1Slot);
|
||||
LogInfo(" TG: %u", m_xlx1TG);
|
||||
@@ -1210,10 +1228,12 @@ bool CDMRGateway::createXLXNetwork1()
|
||||
if (m_xlx1Startup != 4000U)
|
||||
LogInfo(" Startup: %u", m_xlx1Startup);
|
||||
|
||||
if (m_xlx1Relink)
|
||||
LogInfo(" Relink: %u minutes", m_xlx1Relink);
|
||||
else
|
||||
if (xlx1Relink > 0U) {
|
||||
LogInfo(" Relink: %u minutes", xlx1Relink);
|
||||
m_xlx1Relink.setTimeout(xlx1Relink * 60U);
|
||||
} else {
|
||||
LogInfo(" Relink: disabled");
|
||||
}
|
||||
|
||||
m_rpt1Rewrite = new CRewriteTG("XLX-1", XLX_SLOT, XLX_TG, m_xlx1Slot, m_xlx1TG, 1U);
|
||||
m_xlx1Rewrite = new CRewriteTG("XLX-1", m_xlx1Slot, m_xlx1TG, XLX_SLOT, XLX_TG, 1U);
|
||||
@@ -1266,7 +1286,8 @@ bool CDMRGateway::createXLXNetwork2()
|
||||
m_xlx2TG = m_conf.getXLXNetwork2TG();
|
||||
m_xlx2Base = m_conf.getXLXNetwork2Base();
|
||||
m_xlx2Startup = m_conf.getXLXNetwork2Startup();
|
||||
m_xlx2Relink = m_conf.getXLXNetwork2Relink();
|
||||
|
||||
unsigned int xlx2Relink = m_conf.getXLXNetwork2Relink();
|
||||
|
||||
LogInfo(" Slot: %u", m_xlx2Slot);
|
||||
LogInfo(" TG: %u", m_xlx2TG);
|
||||
@@ -1275,10 +1296,12 @@ bool CDMRGateway::createXLXNetwork2()
|
||||
if (m_xlx2Startup != 4000U)
|
||||
LogInfo(" Startup: %u", m_xlx2Startup);
|
||||
|
||||
if (m_xlx2Relink)
|
||||
LogInfo(" Relink: %u minutes", m_xlx2Relink);
|
||||
else
|
||||
if (xlx2Relink > 0U) {
|
||||
LogInfo(" Relink: %u minutes", xlx2Relink);
|
||||
m_xlx2Relink.setTimeout(xlx2Relink * 60U);
|
||||
} else {
|
||||
LogInfo(" Relink: disabled");
|
||||
}
|
||||
|
||||
m_rpt2Rewrite = new CRewriteTG("XLX-2", XLX_SLOT, XLX_TG, m_xlx2Slot, m_xlx2TG, 1U);
|
||||
m_xlx2Rewrite = new CRewriteTG("XLX-2", m_xlx2Slot, m_xlx2TG, XLX_SLOT, XLX_TG, 1U);
|
||||
|
||||
Reference in New Issue
Block a user