try to keep alive longer

dev
Tom Early 5 years ago
parent 7e3947438e
commit 94e079f9c4

@ -223,7 +223,8 @@ void CQnetITAP::Run(const char *cfgfile)
keep_running = true;
unsigned int poll_counter = 0;
bool is_alive = false;
bool initialized = false;
bool alive = true;
acknowledged = true;
CTimer ackTimer;
CTimer lastdataTimer;
@ -256,41 +257,40 @@ void CQnetITAP::Run(const char *cfgfile)
// check for a dead or disconnected radio
if (10.0 < lastdataTimer.time())
{
printf("no activity from radio for 10 sec. Exiting...\n");
break;
printf("no activity from radio for 10 sec. Restarting...\n");
alive = false;
}
if (pingTimer.time() >= pingtime)
if (alive && keep_running && (pingTimer.time() >= pingtime))
{
if (poll_counter < 18 )
{
const unsigned char poll[2] = { 0xffu, 0xffu };
SendTo(poll);
if (poll_counter == 17)
SendToIcom(poll);
if (poll_counter++ == 17)
pingtime = 1.0;
}
else
{
const unsigned char ping[2] = { 0x02u, 0x02u };
SendTo(ping);
SendToIcom(ping);
}
poll_counter++;
pingTimer.start();
}
unsigned char buf[100];
if (keep_running && FD_ISSET(serfd, &readfds)) // there is something to read!
if (keep_running && FD_ISSET(serfd, &readfds)) // there is something to read from the Icom!
{
switch (GetITAPData(buf))
{
case RT_ERROR:
keep_running = false;
alive = false;
break;
case RT_HEADER:
{
unsigned char ack_header[3] = { 0x03U, 0x11U, 0x0U };
SendTo(ack_header);
SendToIcom(ack_header);
}
if (ProcessITAP(buf))
keep_running = false;
@ -300,14 +300,14 @@ void CQnetITAP::Run(const char *cfgfile)
{
unsigned char ack_voice[4] = { 0x04U, 0x13U, 0x0U, 0x0U };
ack_voice[2] = buf[2];
SendTo(ack_voice);
SendToIcom(ack_voice);
}
if (ProcessITAP(buf))
keep_running = false;
lastdataTimer.start();
break;
case RT_PONG:
if (! is_alive)
if (! initialized)
{
if (LOG_DEBUG)
{
@ -317,7 +317,7 @@ void CQnetITAP::Run(const char *cfgfile)
}
else
printf("Icom Radio is connected.\n");
is_alive = true;
initialized = true;
}
lastdataTimer.start();
break;
@ -365,7 +365,7 @@ void CQnetITAP::Run(const char *cfgfile)
break;
}
if (0 == memcmp(buf, "DSVT", 4))
if (alive && (0 == memcmp(buf, "DSVT", 4)))
{
//printf("read %d bytes from QnetGateway\n", (int)len);
if (ProcessGateway(len, buf))
@ -379,13 +379,13 @@ void CQnetITAP::Run(const char *cfgfile)
{
if (acknowledged)
{
if (is_alive)
if (initialized)
{
if (! queue.empty())
{
CFrame frame = queue.front();
queue.pop();
SendTo(frame.data());
SendToIcom(frame.data());
ackTimer.start();
acknowledged = false;
}
@ -396,11 +396,17 @@ void CQnetITAP::Run(const char *cfgfile)
if (ackTimer.time() >= ackwait)
{
fprintf(stderr, "Icom failure suspected, restarting...\n");
alive = false;
}
}
}
if (! alive)
{
close(serfd);
poll_counter = 0;
pingtime = 0.001;
is_alive = false;
acknowledged = true;
initialized = false;
alive = acknowledged = true;
lastdataTimer.start();
pingTimer.start();
serfd = OpenITAP();
@ -415,14 +421,12 @@ void CQnetITAP::Run(const char *cfgfile)
}
}
}
}
}
close(serfd);
ToGate.Close();
}
int CQnetITAP::SendTo(const unsigned char *buf)
void CQnetITAP::SendToIcom(const unsigned char *buf)
{
ssize_t n;
unsigned int ptr = 0;
@ -436,7 +440,7 @@ int CQnetITAP::SendTo(const unsigned char *buf)
if (EAGAIN != errno)
{
printf("Error %d writing to %s: %s\n", errno, ITAP_DEVICE.c_str(), strerror(errno));
return -1;
return;
}
}
ptr += n;
@ -452,12 +456,9 @@ int CQnetITAP::SendTo(const unsigned char *buf)
if (EAGAIN != errno)
{
printf("Error %d writing to %s: %s\n", errno, ITAP_DEVICE.c_str(), strerror(errno));
return -1;
}
}
}
return length;
}
bool CQnetITAP::ProcessGateway(const int len, const unsigned char *raw)

@ -122,7 +122,7 @@ private:
bool ProcessGateway(const int len, const unsigned char *raw);
bool ProcessITAP(const unsigned char *raw);
int OpenITAP();
int SendTo(const unsigned char *buf);
void SendToIcom(const unsigned char *buf);
REPLY_TYPE GetITAPData(unsigned char *buf);
void calcPFCS(const unsigned char *packet, unsigned char *pfcs);
void DumpSerialPacket(const char *title, const unsigned char *);

Loading…
Cancel
Save

Powered by TurnKey Linux.