Skip to content

Commit

Permalink
Reconnect to M17 reflector after timeout or network loss
Browse files Browse the repository at this point in the history
  • Loading branch information
nostar committed Nov 29, 2021
1 parent 8909c35 commit fe4d8de
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
26 changes: 25 additions & 1 deletion DMR2M17/DMR2M17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#define DMR_FRAME_PER 55U
#define M17_FRAME_PER 35U
#define M17_PING_TIMEOUT 35000U

const char* DEFAULT_INI_FILE = "/etc/DMR2M17.ini";

Expand Down Expand Up @@ -315,11 +316,13 @@ int CDMR2M17::run()
CTimer pollTimer(1000U, 8U);
CStopWatch stopWatch;
CStopWatch m17Watch;
CStopWatch m17PingWatch;
CStopWatch dmrWatch;

pollTimer.start();
stopWatch.start();
m17Watch.start();
m17PingWatch.start();
dmrWatch.start();

unsigned short m17_cnt = 0;
Expand All @@ -335,6 +338,13 @@ int CDMR2M17::run()

CDMRData tx_dmrdata;
unsigned int ms = stopWatch.elapsed();

if(m17PingWatch.elapsed() > M17_PING_TIMEOUT){
LogMessage("M17 reflector stopped responding, sending CONN...");
pollTimer.stop();
m17PingWatch.start();
m_m17Network->writeLink(module);
}

if (m17Watch.elapsed() > M17_FRAME_PER) {
unsigned int m17FrameType = m_conv.getM17(m_m17Frame);
Expand Down Expand Up @@ -386,7 +396,21 @@ int CDMR2M17::run()
}

while (m_m17Network->readData(m_m17Frame, 54U) > 0U) {
//CUtils::dump(1U, "M17 Data", m_p25Frame, 22U);
if (!memcmp(m_m17Frame, "PING", 4)) {
m17PingWatch.start();
}
if (!memcmp(m_m17Frame, "ACKN", 4)) {
LogMessage("Received ACKN from reflector");
if(!pollTimer.isRunning()){
pollTimer.start();
}
m17PingWatch.start();
}
if (!memcmp(m_m17Frame, "NACK", 4)) {
LogMessage("Received NACK from reflector");
pollTimer.stop();
m17PingWatch.start();
}
if (!memcmp(m_m17Frame, "M17 ", 4)) {
if (m_m17Frame[34] == 0 && m_m17Frame[35] == 0) {
m_m17Frames = 0;
Expand Down
26 changes: 25 additions & 1 deletion M172DMR/M172DMR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#define DMR_FRAME_PER 55U
#define M17_FRAME_PER 35U
#define M17_PING_TIMEOUT 35000U

#define XLX_SLOT 2U
#define XLX_COLOR_CODE 3U
Expand Down Expand Up @@ -313,9 +314,11 @@ int CM172DMR::run()

CStopWatch stopWatch;
CStopWatch m17Watch;
CStopWatch m17PingWatch;
CStopWatch dmrWatch;
stopWatch.start();
m17Watch.start();
m17PingWatch.start();
dmrWatch.start();
pollTimer.start();

Expand All @@ -331,6 +334,13 @@ int CM172DMR::run()

CDMRData tx_dmrdata;
unsigned int ms = stopWatch.elapsed();

if(m17PingWatch.elapsed() > M17_PING_TIMEOUT){
LogMessage("M17 reflector stopped responding, sending CONN...");
pollTimer.stop();
m17PingWatch.start();
m_m17Network->writeLink(module);
}

if (m_dmrNetwork->isConnected() && !m_xlxmodule.empty() && !m_xlxConnected) {
writeXLXLink(m_defsrcid, m_dstid, m_dmrNetwork);
Expand All @@ -339,7 +349,21 @@ int CM172DMR::run()
}

while (m_m17Network->readData(m_m17Frame, 54U) > 0U) {
//CUtils::dump(1U, "M17 Data", m_p25Frame, 22U);
if (!memcmp(m_m17Frame, "PING", 4)) {
m17PingWatch.start();
}
if (!memcmp(m_m17Frame, "ACKN", 4)) {
LogMessage("Received ACKN from reflector");
if(!pollTimer.isRunning()){
pollTimer.start();
}
m17PingWatch.start();
}
if (!memcmp(m_m17Frame, "NACK", 4)) {
LogMessage("Received NACK from reflector");
pollTimer.stop();
m17PingWatch.start();
}
if (!memcmp(m_m17Frame, "M17 ", 4)) {
if (m_m17Frame[34] == 0 && m_m17Frame[35] == 0) {
m_m17Frames = 0;
Expand Down
32 changes: 28 additions & 4 deletions USRP2M17/USRP2M17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#define USRP_FRAME_PER 15U
#define M17_FRAME_PER 35U
#define M17_PING_TIMEOUT 35000U

const char* DEFAULT_INI_FILE = "/etc/USRP2M17.ini";

Expand Down Expand Up @@ -284,11 +285,13 @@ int CUSRP2M17::run()
CTimer pollTimer(1000U, 8U);
CStopWatch stopWatch;
CStopWatch m17Watch;
CStopWatch m17PingWatch;
CStopWatch usrpWatch;

pollTimer.start();
stopWatch.start();
m17Watch.start();
m17PingWatch.start();
usrpWatch.start();

uint16_t m17_cnt = 0;
Expand All @@ -303,6 +306,13 @@ int CUSRP2M17::run()
memset(buffer, 0, sizeof(buffer));

uint32_t ms = stopWatch.elapsed();

if(m17PingWatch.elapsed() > M17_PING_TIMEOUT){
LogMessage("M17 reflector stopped responding, sending CONN...");
pollTimer.stop();
m17PingWatch.start();
m_m17Network->writeLink(module);
}

if (m17Watch.elapsed() > M17_FRAME_PER) {
uint32_t m17FrameType = m_conv.getM17(m_m17Frame);
Expand Down Expand Up @@ -351,7 +361,6 @@ int CUSRP2M17::run()
m17Watch.start();
}
else if(m17FrameType == TAG_DATA) {
//CUtils::dump(1U, "M17 Data", m_p25Frame, 11U);
m17_cnt++;
memcpy(buffer, "M17 ", 4);
memcpy(buffer+4, &streamid, 2);
Expand All @@ -365,9 +374,24 @@ int CUSRP2M17::run()
m17Watch.start();
}
}

uint32_t len = 0;
while (m_m17Network->readData(m_m17Frame, 54U) > 0U) {
//CUtils::dump(1U, "M17 Data", m_p25Frame, 22U);
if (!memcmp(m_m17Frame, "PING", 4)) {
m17PingWatch.start();
}
if (!memcmp(m_m17Frame, "ACKN", 4)) {
LogMessage("Received ACKN from reflector");
if(!pollTimer.isRunning()){
pollTimer.start();
}
m17PingWatch.start();
}
if (!memcmp(m_m17Frame, "NACK", 4)) {
LogMessage("Received NACK from reflector");
pollTimer.stop();
m17PingWatch.start();
}

if (!memcmp(m_m17Frame, "M17 ", 4)) {
if (m_m17Frame[34] == 0 && m_m17Frame[35] == 0) {
m_m17Frames = 0;
Expand Down Expand Up @@ -444,7 +468,7 @@ int CUSRP2M17::run()
usrpWatch.start();
}
}
uint32_t len = 0;
len = 0;
while ( (len = m_usrpNetwork->readData(m_usrpFrame, 400)) ) {
if(!memcmp(m_usrpFrame, "USRP", 4) && (len == 32)) {
LogMessage("USRP received end of voice transmission, %.1f seconds", float(m_usrpFrames) / 50.0F);
Expand Down

0 comments on commit fe4d8de

Please sign in to comment.