From 04edaf6e34f4340532da41119590571aa5e01426 Mon Sep 17 00:00:00 2001 From: Charl Wentzel Date: Wed, 5 Jul 2017 17:06:31 +0200 Subject: [PATCH] Major update: - Add CWatchdogCore component. Sends ping to watchdog server --- CMakeLists.txt | 2 +- WatchdogCore.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ WatchdogCore.h | 41 +++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 WatchdogCore.cpp create mode 100644 WatchdogCore.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e1eec3..dacedc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,3 @@ 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) diff --git a/WatchdogCore.cpp b/WatchdogCore.cpp new file mode 100644 index 0000000..2757ed5 --- /dev/null +++ b/WatchdogCore.cpp @@ -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 +#include +#include +#include +#include + +//--------------------------------------------------------------------------- + +// 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; +} +//--------------------------------------------------------------------------- + diff --git a/WatchdogCore.h b/WatchdogCore.h new file mode 100644 index 0000000..a4ddbb8 --- /dev/null +++ b/WatchdogCore.h @@ -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_ */