Major update:

- Add CWatchdogCore component.  Sends ping to watchdog server
This commit is contained in:
Charl Wentzel
2017-07-05 17:06:31 +02:00
parent c50d920f94
commit 04edaf6e34
3 changed files with 109 additions and 1 deletions

67
WatchdogCore.cpp Normal file
View File

@@ -0,0 +1,67 @@
/*
* WatchdogCore.cpp
*
* Created on: July 2017
* Author: wentzelc
*/
// redA Libraries
#include "WatchdogCore.h"
#include "TimingCore.h"
// Standard C/C++ Libraries
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
//---------------------------------------------------------------------------
// Global vars
extern char * ProcessName;
char LogStr[1000]; // Temporary var to create log messages, globally available to save on memory operations
//---------------------------------------------------------------------------
CWatchdogCore::CWatchdogCore( const char * WatchdogName, const int pInterval, CLogCore * pLog, EDebugLevel pDebugLevel ) :
CFunctionCore( Name, pLog, pDebugLevel, OUT_NORMAL )
{
// Create protocol
Protocol = new CLiteProtocol( 50, '\x01', '\x02', '\x00' );
Protocol->AppendParam( Name, strlen(Name) );
Protocol->AppendParam( ProcessName, strlen(ProcessName) );
Protocol->AppendParam( "ping", 4 );
// Start timer
PingTimeout = 500;
SetStartTime( &PingTimer );
// Create Channel
Ping = AddChannel( "Ping" );
}
//---------------------------------------------------------------------------
CWatchdogCore::~CWatchdogCore()
{
// Destroy Protocol
if (Protocol)
delete Protocol;
}
//---------------------------------------------------------------------------
bool CWatchdogCore::Process()
{
if (Timeout( PingTimer, PingTimeout ))
{
// Send command
Output( Ping, Protocol->GetCommandStr(), Protocol->GetCommandLen() );
// Reset timer
SetStartTime( &PingTimer );
}
return false;
}
//---------------------------------------------------------------------------