Files
redAcore/WatchdogCore.cpp
Charl Wentzel a972fb9101 Major Update:
- Implement consistent Function addition to application
  - Use TYPE_XXX constants to declare function type
  - Use NewXXXX() methods to call constructor correctly
  - Add FunctionType list (with constructor) to Application
  - Create Function by comparison to FunctionType list
- Simplify LoadConfig() and Init() methods for functions
  - Combine methods into Init() method
  - Pass relevant data member to Init() method
  - Remove all CDataMember references on functions
- ApplicationCore:
  - Split ReadParam() method from LoadConfig() method
  - Split main configuration into separate files:
    - config/ - main config file, general application settings
    - definition/ - application definition, e.g. function blocks
  - Definition and Address List files specified in config file
  - Load address file in address/ branch
  - Made DataTree & JSONparser private
  - Made Config, Definition & Address branches public
  - Removed unnecessary branch references
  - Improved event logging
- DataTreeCore:
  - Allow GetChFirstChild & GetChElement to create parent branches
    with correct type, ie. Object/Array
  - Remove unnecessary Create param from GetXxx functions
  - Bug fix: Print empty objects/arrays correct, ie. empty brackets
  - Bug fix: Adding element at specific index
  - Bug fix: Error when get/create string value with "null"
- FunctionCore:
  - Type param now set as constant via constructor
  - Create empty Handles & Channels objects if none in Config
- SelectableCore:
  - Add Queue length parameter to handles for UNIX and TCP sockets
- DeviceCore:
  - Bug fix: missing Process() method
2018-11-24 13:35:23 +02:00

95 lines
2.4 KiB
C++

/*
* WatchdogCore.cpp
*
* Created on: July 2017
* Author: wentzelc
*/
// Standard C/C++ Libraries
/* none */
// redA Libraries
#include "ApplicationCore.h"
#include "WatchdogCore.h"
//---------------------------------------------------------------------------
// Global vars
extern char * ProcessName;
//extern CApplication * Application;
//---------------------------------------------------------------------------
// Function Constructor
CFunctionCore * NewWatchdogCore( const char * Name ) {
return (CFunctionCore*) new CWatchdogCore( Name );
}
//---------------------------------------------------------------------------
CWatchdogCore::CWatchdogCore( const char * pName, const char * pType ) : CSelectableCore( pName, pType )
{
// Create protocol
Protocol = new CLiteProtocol( 50, '\x02', '\x03', '\x00' );
Protocol->CreateCommand( ProcessName, "watchdog", "ping" );
// Start timer
PingInterval = 500;
SetStartTime( &PingTimer );
// Handle
Ping = NULL;
}
//---------------------------------------------------------------------------
CWatchdogCore::~CWatchdogCore()
{
// Destroy Protocol
if (Protocol)
delete Protocol;
}
//---------------------------------------------------------------------------
bool CWatchdogCore::SetInterval( int pPingInterval )
{
PingInterval = pPingInterval;
return true;
}
//---------------------------------------------------------------------------
bool CWatchdogCore::Init( CDataMember * FunctionConfig )
{
// Call Previous ingi
if (!CSelectableCore::Init( FunctionConfig ))
return false;
// Set specific parameters
SetInterval( FunctionConfig->GetChInt( "Parameters/PingInterval", 500, true ));
// Create handle and set reference, if not done
if (!(Ping = GetHandle( "Ping" )))
Ping = CreateHandle( "Ping", false );
return true;
}
//---------------------------------------------------------------------------
bool CWatchdogCore::Process()
{
// Manage socket connections
CSelectableCore::Process();
// Watchdog ping
if (Timeout( PingTimer, PingInterval ))
{
// Send command
OutputHandle( Ping, Protocol->GetCommandStr(), Protocol->GetCommandLen() );
// Reset timer
SetStartTime( &PingTimer );
}
return false;
}
//---------------------------------------------------------------------------