Files
redAcore/WatchdogCore.cpp
Charl Wentzel 889df6c7de Important Update:
- DeviceCore:
  - Added PollCycle variable (not used here)
- WatchdogCore:
  - Return "true" on in Process()
- SelectableCore:
  - Minor update (code compacted)
- Application/Function:
  - Added CApplication as friend of CFunction
  - Added param WaitToTerminate on Function
  - Application Run() only exists if all (WaitToTerminate) functions
    has terminated cleanly.
2019-03-09 20:41:25 +02:00

95 lines
2.4 KiB
C++

/*
* 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( FunctionConfig->GetChInt( "Parameters/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;
}
//---------------------------------------------------------------------------