From b1cb145475608277393da7ca84e987011923541c Mon Sep 17 00:00:00 2001 From: Tom Early Date: Fri, 7 Sep 2018 18:27:40 -0700 Subject: [PATCH] kill timer --- QnetITAP.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/QnetITAP.cpp b/QnetITAP.cpp index 8c77b1b..0ad044a 100644 --- a/QnetITAP.cpp +++ b/QnetITAP.cpp @@ -253,6 +253,7 @@ void CQnetITAP::Run(const char *cfgfile) keep_running = true; unsigned poll_counter = 0; bool is_alive = false; + std::chrono::steady_clock::time_point lastdata = std::chrono::steady_clock::now(); while (keep_running) { fd_set readfds; @@ -273,17 +274,23 @@ void CQnetITAP::Run(const char *cfgfile) break; } + // check for a dead or disconnected radio + std::chrono::steady_clock::duration sincelastdata = std::chrono::steady_clock::now() - lastdata; + double deadtime = sincelastdata.count() * std::chrono::steady_clock::period::num / std::chrono::steady_clock::period::den; + if (10.0 < deadtime) { + print("no activity from radio for 10 sec. Exiting...\n"); + break; + } + if (0 == ret) { // nothing to read, so do the polling or pinging - unsigned char buf[3]; if (poll_counter++ < 18) { unsigned char poll[3] = { 0xffu, 0xffu, 0xffu }; - ::memcpy(buf, poll, 3); + SendTo((unsigned char)0x03U, poll); } else { unsigned char ping[3] = { 0x02u, 0x02u, 0xffu }; - ::memcpy(buf, ping, 3); + SendTo((unsigned char)0x03U, ping); } - SendTo((unsigned char)0x03U, buf); continue; } @@ -318,6 +325,7 @@ void CQnetITAP::Run(const char *cfgfile) } if (rt != RT_NOTHING) { + lastdata = std::chrono::steady_clock::now(); //printf("read %d bytes from ITAP\n", (int)buf[0]); if (RT_DATA==rt || RT_HEADER==rt) { if (ProcessITAP(buf)) @@ -336,9 +344,6 @@ void CQnetITAP::Run(const char *cfgfile) is_alive = true; } break; - case RT_TIMEOUT: - printf("DEBUG: Run: got a timeout.\n"); - break; default: break; }