diff --git a/YSFGateway/Conf.cpp b/YSFGateway/Conf.cpp index fcd6b1d..8b11600 100644 --- a/YSFGateway/Conf.cpp +++ b/YSFGateway/Conf.cpp @@ -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 * 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_networkParrotPort(0U), m_networkStartup(), +m_networkInactivityTimeout(0U), m_networkDebug(false) { } @@ -183,6 +184,8 @@ bool CConf::read() m_networkParrotPort = (unsigned int)::atoi(value); else if (::strcmp(key, "Startup") == 0) m_networkStartup = value; + else if (::strcmp(key, "InactivityTimeout") == 0) + m_networkInactivityTimeout = (unsigned int)::atoi(value); else if (::strcmp(key, "Debug") == 0) m_networkDebug = ::atoi(value) == 1; } @@ -343,6 +346,11 @@ std::string CConf::getNetworkStartup() const return m_networkStartup; } +unsigned int CConf::getNetworkInactivityTimeout() const +{ + return m_networkInactivityTimeout; +} + bool CConf::getNetworkDebug() const { return m_networkDebug; diff --git a/YSFGateway/Conf.h b/YSFGateway/Conf.h index a3655ed..338ed5f 100644 --- a/YSFGateway/Conf.h +++ b/YSFGateway/Conf.h @@ -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 * it under the terms of the GNU General Public License as published by @@ -69,6 +69,7 @@ public: std::string getNetworkParrotAddress() const; unsigned int getNetworkParrotPort() const; std::string getNetworkStartup() const; + unsigned int getNetworkInactivityTimeout() const; bool getNetworkDebug() const; private: @@ -107,6 +108,7 @@ private: std::string m_networkParrotAddress; unsigned int m_networkParrotPort; std::string m_networkStartup; + unsigned int m_networkInactivityTimeout; bool m_networkDebug; }; diff --git a/YSFGateway/YSFGateway.cpp b/YSFGateway/YSFGateway.cpp index 9d7a439..d73dd29 100644 --- a/YSFGateway/YSFGateway.cpp +++ b/YSFGateway/YSFGateway.cpp @@ -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 * it under the terms of the GNU General Public License as published by @@ -192,6 +192,7 @@ int CYSFGateway::run() return 1; } + CTimer inactivityTimer(1000U, m_conf.getNetworkInactivityTimeout() * 60U); CTimer lostTimer(1000U, 120U); CTimer pollTimer(1000U, 5U); @@ -227,6 +228,7 @@ int CYSFGateway::run() m_netNetwork->writePoll(); m_netNetwork->writePoll(); + inactivityTimer.start(); lostTimer.start(); pollTimer.start(); @@ -273,6 +275,7 @@ int CYSFGateway::run() m_netNetwork->writePoll(); m_netNetwork->writePoll(); + inactivityTimer.start(); lostTimer.start(); pollTimer.start(); @@ -287,6 +290,7 @@ int CYSFGateway::run() m_netNetwork->writeUnlink(); m_netNetwork->setDestination(); + inactivityTimer.stop(); lostTimer.stop(); pollTimer.stop(); @@ -301,8 +305,10 @@ int CYSFGateway::run() 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); + inactivityTimer.start(); + } if ((buffer[34U] & 0x01U) == 0x01U) { if (m_gps != NULL) @@ -331,10 +337,30 @@ int CYSFGateway::run() if (m_wiresX != NULL) 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); if (lostTimer.isRunning() && lostTimer.hasExpired()) { LogWarning("Link has failed, polls lost"); m_netNetwork->setDestination(); + inactivityTimer.stop(); lostTimer.stop(); pollTimer.stop(); m_linked = false; diff --git a/YSFGateway/YSFGateway.ini b/YSFGateway/YSFGateway.ini index a4c0e22..4d60d61 100644 --- a/YSFGateway/YSFGateway.ini +++ b/YSFGateway/YSFGateway.ini @@ -40,4 +40,5 @@ ReloadTime=60 ParrotAddress=127.0.0.1 ParrotPort=42000 # Startup= +InactivityTimeout=10 Debug=0