1
0
Fork 0

Add an inactivity timer to the gateway.

ycs232-kbc
Jonathan Naylor 8 years ago
parent 76428bb0cb
commit 4ae82cfd8d

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -67,6 +67,7 @@ m_networkReloadTime(0U),
m_networkParrotAddress("127.0.0.1"), m_networkParrotAddress("127.0.0.1"),
m_networkParrotPort(0U), m_networkParrotPort(0U),
m_networkStartup(), m_networkStartup(),
m_networkInactivityTimeout(0U),
m_networkDebug(false) m_networkDebug(false)
{ {
} }
@ -183,6 +184,8 @@ bool CConf::read()
m_networkParrotPort = (unsigned int)::atoi(value); m_networkParrotPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "Startup") == 0) else if (::strcmp(key, "Startup") == 0)
m_networkStartup = value; m_networkStartup = value;
else if (::strcmp(key, "InactivityTimeout") == 0)
m_networkInactivityTimeout = (unsigned int)::atoi(value);
else if (::strcmp(key, "Debug") == 0) else if (::strcmp(key, "Debug") == 0)
m_networkDebug = ::atoi(value) == 1; m_networkDebug = ::atoi(value) == 1;
} }
@ -343,6 +346,11 @@ std::string CConf::getNetworkStartup() const
return m_networkStartup; return m_networkStartup;
} }
unsigned int CConf::getNetworkInactivityTimeout() const
{
return m_networkInactivityTimeout;
}
bool CConf::getNetworkDebug() const bool CConf::getNetworkDebug() const
{ {
return m_networkDebug; return m_networkDebug;

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -69,6 +69,7 @@ public:
std::string getNetworkParrotAddress() const; std::string getNetworkParrotAddress() const;
unsigned int getNetworkParrotPort() const; unsigned int getNetworkParrotPort() const;
std::string getNetworkStartup() const; std::string getNetworkStartup() const;
unsigned int getNetworkInactivityTimeout() const;
bool getNetworkDebug() const; bool getNetworkDebug() const;
private: private:
@ -107,6 +108,7 @@ private:
std::string m_networkParrotAddress; std::string m_networkParrotAddress;
unsigned int m_networkParrotPort; unsigned int m_networkParrotPort;
std::string m_networkStartup; std::string m_networkStartup;
unsigned int m_networkInactivityTimeout;
bool m_networkDebug; bool m_networkDebug;
}; };

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 by Jonathan Naylor G4KLX * Copyright (C) 2016,2017 by Jonathan Naylor G4KLX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -192,6 +192,7 @@ int CYSFGateway::run()
return 1; return 1;
} }
CTimer inactivityTimer(1000U, m_conf.getNetworkInactivityTimeout() * 60U);
CTimer lostTimer(1000U, 120U); CTimer lostTimer(1000U, 120U);
CTimer pollTimer(1000U, 5U); CTimer pollTimer(1000U, 5U);
@ -227,6 +228,7 @@ int CYSFGateway::run()
m_netNetwork->writePoll(); m_netNetwork->writePoll();
m_netNetwork->writePoll(); m_netNetwork->writePoll();
inactivityTimer.start();
lostTimer.start(); lostTimer.start();
pollTimer.start(); pollTimer.start();
@ -273,6 +275,7 @@ int CYSFGateway::run()
m_netNetwork->writePoll(); m_netNetwork->writePoll();
m_netNetwork->writePoll(); m_netNetwork->writePoll();
inactivityTimer.start();
lostTimer.start(); lostTimer.start();
pollTimer.start(); pollTimer.start();
@ -287,6 +290,7 @@ int CYSFGateway::run()
m_netNetwork->writeUnlink(); m_netNetwork->writeUnlink();
m_netNetwork->setDestination(); m_netNetwork->setDestination();
inactivityTimer.stop();
lostTimer.stop(); lostTimer.stop();
pollTimer.stop(); pollTimer.stop();
@ -301,8 +305,10 @@ int CYSFGateway::run()
m_gps->data(buffer + 14U, buffer + 35U, fi, dt, fn, ft); m_gps->data(buffer + 14U, buffer + 35U, fi, dt, fn, ft);
} }
if (networkEnabled && m_linked && !m_exclude) if (networkEnabled && m_linked && !m_exclude) {
m_netNetwork->write(buffer); m_netNetwork->write(buffer);
inactivityTimer.start();
}
if ((buffer[34U] & 0x01U) == 0x01U) { if ((buffer[34U] & 0x01U) == 0x01U) {
if (m_gps != NULL) if (m_gps != NULL)
@ -331,10 +337,30 @@ int CYSFGateway::run()
if (m_wiresX != NULL) if (m_wiresX != NULL)
m_wiresX->clock(ms); m_wiresX->clock(ms);
inactivityTimer.clock(ms);
if (inactivityTimer.isRunning() && inactivityTimer.hasExpired()) {
if (m_linked) {
LogMessage("Disconnecting due to inactivity");
m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink();
m_netNetwork->writeUnlink();
m_netNetwork->setDestination();
lostTimer.stop();
pollTimer.stop();
m_linked = false;
}
inactivityTimer.stop();
}
lostTimer.clock(ms); lostTimer.clock(ms);
if (lostTimer.isRunning() && lostTimer.hasExpired()) { if (lostTimer.isRunning() && lostTimer.hasExpired()) {
LogWarning("Link has failed, polls lost"); LogWarning("Link has failed, polls lost");
m_netNetwork->setDestination(); m_netNetwork->setDestination();
inactivityTimer.stop();
lostTimer.stop(); lostTimer.stop();
pollTimer.stop(); pollTimer.stop();
m_linked = false; m_linked = false;

@ -40,4 +40,5 @@ ReloadTime=60
ParrotAddress=127.0.0.1 ParrotAddress=127.0.0.1
ParrotPort=42000 ParrotPort=42000
# Startup= # Startup=
InactivityTimeout=10
Debug=0 Debug=0

Loading…
Cancel
Save