Files
redAcore/WatchdogCore.cpp
Charl Wentzel d013078c1f Bug fixes:
- Remove LogStr var
- Create new Command Str before adding parameters
- Set Watchdog name correctly
2017-07-05 18:20:29 +02:00

68 lines
1.7 KiB
C++

/*
* 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;
//---------------------------------------------------------------------------
CWatchdogCore::CWatchdogCore( const char * WatchdogName, const int pInterval, CLogCore * pLog, EDebugLevel pDebugLevel ) :
CFunctionCore( WatchdogName, pLog, pDebugLevel, OUT_NORMAL )
{
// Create protocol
Protocol = new CLiteProtocol( 50, '\x01', '\x02', '\x00' );
Protocol->NewCommandStr();
Protocol->AppendParam( WatchdogName, strlen(WatchdogName) );
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;
}
//---------------------------------------------------------------------------