- SelectableCore:
- Rename methods: SetSerialPortConfig() -> WriteSerialConfig(),
GetSerialPortConfig() -> ReadSerialConfig(),
InputHandle() -> OutputHandle(),
ProcessBuffer() -> ProcessInputBuffer()
SetPortHandle(config)() -> SetSerialHandle(Config)()
- Rename serial port identification: "Port" -> "SerialPort"
- Update logs accordingly
- Add LinePrinter Port
- Add to LoadConfig()
- Add SetLinePrinterHandle() & OpenLinePrinterPort() methods
- Add handling for open/read/write/close events
- Add CloseDelay for AutoManage (non-persistent) ports
- Rename handle timer: ReopenStart -> LastAction
- Reset timer on all open/read/write/close events
- Check for Close timeout in Process() and close port
- Remove CloseChildren parameter on Close() method
- Add QuickReopen parameter to Close() method
- SelectCore:
- Overwrite existing handle - not yet removed
- Handle In/Out baudrate on serial port separately
96 lines
2.3 KiB
C++
96 lines
2.3 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;
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
CWatchdogCore::CWatchdogCore( const char * pName ) :
|
|
CSelectableCore( pName, "WatchdogClient" )
|
|
{
|
|
// 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::LoadConfigData()
|
|
{
|
|
// Call Previous load config
|
|
CSelectableCore::LoadConfigData();
|
|
|
|
// Set specific parameters
|
|
SetInterval( DataTree->GetInt( ConfigMember, "Parameters/PingInterval", 500, true ));
|
|
|
|
return true;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool CWatchdogCore::SetInterval( int pPingInterval )
|
|
{
|
|
PingInterval = pPingInterval;
|
|
return true;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool CWatchdogCore::Init()
|
|
{
|
|
// Create handle and set reference, if not done
|
|
if (!(Ping = GetHandle( "Ping" )))
|
|
Ping = CreateHandle( "Ping", false );
|
|
|
|
// Previous init
|
|
return CSelectableCore::Init();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
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;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|