/* * WatchdogCore.cpp * * Created on: July 2017 * Author: wentzelc */ // Standard C/C++ Libraries /* none */ // redA Libraries #include "ApplicationCore.h" #include "WatchdogCore.h" //--------------------------------------------------------------------------- // Global vars extern char * ProcessName; //extern CApplication * Application; //--------------------------------------------------------------------------- // Function Constructor CFunctionCore * NewWatchdogCore( const char * Name ) { return (CFunctionCore*) new CWatchdogCore( Name ); } //--------------------------------------------------------------------------- CWatchdogCore::CWatchdogCore( const char * pName, const char * pType ) : CSelectableCore( pName, pType ) { // Create protocol Protocol = new CLiteProtocol( 50, '\x02', '\x03', '\x00' ); Protocol->CreateCommand( ProcessName, "watchdog", "ping" ); // Start timer PingInterval = 500; SetStartTime( &PingTimer ); // Handle Ping = NULL; } //--------------------------------------------------------------------------- CWatchdogCore::~CWatchdogCore() { // Destroy Protocol if (Protocol) delete Protocol; } //--------------------------------------------------------------------------- bool CWatchdogCore::SetInterval( int pPingInterval ) { PingInterval = pPingInterval; return true; } //--------------------------------------------------------------------------- bool CWatchdogCore::Init( CDataMember * FunctionConfig ) { // Call Previous ingi if (!CSelectableCore::Init( FunctionConfig )) return false; // Set specific parameters SetInterval( Config->GetChInt( "PingInterval", 500, true )); // Create handle and set reference, if not done if (!(Ping = GetHandle( "Ping" ))) Ping = CreateHandle( "Ping", false ); return true; } //--------------------------------------------------------------------------- bool CWatchdogCore::Process() { // Manage socket connections CSelectableCore::Process(); // Watchdog ping if (Timeout( PingTimer, PingInterval )) { // Send command OutputHandle( Ping, Protocol->GetCommandStr(), Protocol->GetCommandLen() ); // Reset timer SetStartTime( &PingTimer ); } return true; } //---------------------------------------------------------------------------