Merge branch 'master' into WatchdogCore
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
PROJECT(lib_redAcore)
|
PROJECT(lib_redAcore)
|
||||||
|
|
||||||
ADD_LIBRARY(redAcore TimingCore.cpp DateTimeCore.cpp LogCore.cpp SignalCore.cpp DataTreeCore.cpp JSONparseCore.cpp BufferCore.cpp LiteProtocolCore.cpp FunctionCore.cpp DeviceCore.cpp FileCore.cpp SelectCore.cpp SelectableCore.cpp)
|
ADD_LIBRARY(redAcore TimingCore.cpp DateTimeCore.cpp LogCore.cpp SignalCore.cpp DataTreeCore.cpp JSONparseCore.cpp BufferCore.cpp LiteProtocolCore.cpp FunctionCore.cpp WatchdogCore.cpp DeviceCore.cpp FileCore.cpp SelectCore.cpp SelectableCore.cpp)
|
||||||
|
|||||||
67
WatchdogCore.cpp
Normal file
67
WatchdogCore.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
41
WatchdogCore.h
Normal file
41
WatchdogCore.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* WatchdogCore.h
|
||||||
|
*
|
||||||
|
* Created on: July 2017
|
||||||
|
* Author: wentzelc
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef REDACORE_WATCHDOGCORE_H_
|
||||||
|
#define REDACORE_WATCHDOGCORE_H_
|
||||||
|
|
||||||
|
// redA Libraries
|
||||||
|
#include "FunctionCore.h"
|
||||||
|
#include "LiteProtocolCore.h"
|
||||||
|
|
||||||
|
// Standard C/C++ Libraries
|
||||||
|
/*none*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class CWatchdogCore : public CFunctionCore
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// Command
|
||||||
|
CLiteProtocol * Protocol;
|
||||||
|
|
||||||
|
// Timing
|
||||||
|
timeval PingTimer;
|
||||||
|
int PingTimeout;
|
||||||
|
|
||||||
|
// Channel
|
||||||
|
TChannel * Ping;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CWatchdogCore( const char * WatchdogName, const int pInterval, CLogCore * pLog, EDebugLevel pDebugLevel );
|
||||||
|
virtual ~CWatchdogCore();
|
||||||
|
|
||||||
|
virtual bool Process();
|
||||||
|
};
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif /* REDACORE_WATCHDOGCORE_H_ */
|
||||||
Reference in New Issue
Block a user