Merge branch 'master' of /home/development/source/core/redAcore into InterAfrica

This commit is contained in:
Charl Wentzel
2017-07-05 17:16:51 +02:00
4 changed files with 143 additions and 15 deletions

View File

@@ -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)

View File

@@ -83,22 +83,36 @@ void SignalTerminate( int sig )
Terminate = true;
TermCount++;
// Check for Terminate Limit
// Show signal received if not already terminated
std::cerr << "\r\n" << ProcessName << ": ***********************************\n";
std::cerr << "\r\n" << ProcessName << ": ***********************************" << std::endl;
// Create Log Entry
if (Log) Log->Message( dlNone, dlNone, "%s: ** %s signal received [%d] **", ProcessName, SigName, TermCount );
if (TermCount < MaxTermCount) {
if (Log) Log->Message( dlNone, dlNone, "%s: ** Terminating normally... **", ProcessName );
if (Log)
{
Log->Message( dlNone, dlNone, "%s: ** %s signal received [%d] **", ProcessName, SigName, TermCount );
// Check for Terminate Limit
if (TermCount < MaxTermCount) {
Log->Message( dlNone, dlNone, "%s: ** Terminating normally... **", ProcessName );
} else {
Log->Message( dlNone, dlNone, "%s: ** Terminating immediately! **", ProcessName );
}
}
else {
if (Log) Log->Message( dlNone, dlNone, "%s: ** Terminating immediately! **", ProcessName );
else
{
std::cerr << ProcessName << ": ** " << SigName << " signal received [" << TermCount << "] **" << std::endl;
// Check for Terminate Limit
if (TermCount < MaxTermCount) {
std::cerr << ProcessName << ": ** Terminating normally... **" << std::endl;
} else {
std::cerr << ProcessName << ": ** Terminating immediately! **" << std::endl;
}
}
std::cerr << ProcessName << ": ***********************************\n\n";
if (TermCount >= MaxTermCount)
std::cerr << ProcessName << ": ***********************************" << std::endl << std::endl;
// Check for Terminate Limit
if (TermCount >= MaxTermCount) {
exit( sig );
}
return;
}//---------------------------------------------------------------------------
@@ -120,13 +134,19 @@ void SignalAbort( int sig )
}
// Show signal received
std::cerr << "\n" << ProcessName << ": ********************************\n";
std::cerr << "\n" << ProcessName << ": ********************************" << std::endl;
// Create Log Entry - but don't post
if (Log) Log->Message( dlNone, dlNone, "%s: ** %s signal received **", ProcessName, SigName );
if (Log) Log->Message( dlNone, dlNone, "%s: ** Terminating immediately! **", ProcessName );
if (Log) {
Log->Message( dlNone, dlNone, "%s: ** %s signal received **", ProcessName, SigName );
Log->Message( dlNone, dlNone, "%s: ** Terminating immediately! **", ProcessName );
}
else {
std::cerr << ProcessName << ": ** " << SigName << " signal received **" << std::endl;
std::cerr << ProcessName << ": ** Terminating immediately! **" << std::endl;
}
std::cerr << ProcessName << ": ********************************\n\n";
std::cerr << ProcessName << ": ********************************" << std::endl << std::endl;
// Terminate with signal
exit( sig );

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;
}
//---------------------------------------------------------------------------

41
WatchdogCore.h Normal file
View 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_ */