- DataTreeCore:
- Bug fix: GetMember() error if member not found
- FunctionCore: (affected: SelectableCore, FileCore, WatchdogCore)
- Made destructor virual
- Standardize method parameter naming, e.g. pName, pLog
- Renamed parameters: DebugLevel -> LogLevel, OutputDisplay -> LogOutput
- Reinstated parameter BaseMember
- Removed logging parameters from constructor
- Created method InitLoggging() (shows "Function Created" message)
- Split LoadConfig() method into parts:
- Implemented public LoadConfig() methods
- Implemented LoadConfigData() method, load parameters from DataTree
- WatchdogCore:
- Derive from CSelectableCore instead of CFunctionCore
- Rename parameter: PingTimeout -> PingInterval
- Replace Ping Channel with Handle only
- Add method SetInterval()
- Send command direct to handle with (channel) Input()
- SelectableCore:
- Rename parameters: Auto -> AutoManage, ReopenTimeout -> ReopenDelay
- Implemented own virtual LoadConfigData() method
- DeviceCore:
- Made all logging conditional: if (Log) Log->Message(...)
- SelectCore:
- Renamed parameters: DebugLevel -> LogLevel
207 lines
6.8 KiB
C++
207 lines
6.8 KiB
C++
/*
|
|
* FunctionCore.h
|
|
*
|
|
* Created on: 18 May 2016
|
|
* Author: wentzelc
|
|
*/
|
|
|
|
#ifndef REDACORE_DEVICECORE_H_
|
|
#define REDACORE_DEVICECORE_H_
|
|
|
|
// redA Libraries
|
|
#include "FunctionCore.h"
|
|
|
|
// Standard C/C++ Libraries
|
|
/* no additional */
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Enumerated types
|
|
typedef enum { dtUnsigned16 = 0, dtSigned16 = 1, dtUnsigned32 = 2, dtSigned32 = 3, dtFloat32 = 4, dtString = 5 } EMBDataType;
|
|
|
|
// Constants
|
|
const char DataTypeName[][20] = { "Unsigned16", "Signed16", "Unsigned32", "Signed32", "Float32", "String" };
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Structure prototypes
|
|
typedef struct SDevice TDevice;
|
|
typedef struct SDeviceParam TDeviceParam;
|
|
|
|
// Devices with are polled
|
|
struct SDevice {
|
|
char * Name;
|
|
bool Online;
|
|
|
|
TDeviceParam * FirstParam;
|
|
|
|
TDevice * Next;
|
|
};
|
|
|
|
// Data parameters of devices
|
|
struct SDeviceParam {
|
|
char * Name;
|
|
EMBDataType DataType;
|
|
|
|
bool Scan;
|
|
TChannel * EventChannel;
|
|
long UpdateInterval;
|
|
timeval UpdateTimeout;
|
|
|
|
void * Value;
|
|
int Len;
|
|
bool Changed;
|
|
|
|
void * SetValue;
|
|
int SetLen;
|
|
bool SetChanged;
|
|
|
|
TDeviceParam * Next;
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
class CDeviceCore : public CFunctionCore
|
|
{
|
|
protected:
|
|
// Update
|
|
int UpdateInterval;
|
|
timeval UpdateTimeout;
|
|
|
|
// Parameters
|
|
TDevice * FirstDevice;
|
|
TDevice * ActiveDevice;
|
|
|
|
// Standard channels
|
|
TChannel * DeviceChannel;
|
|
TChannel * CmdChannel;
|
|
|
|
// Poll
|
|
int PollStep; // Position in polling sequence
|
|
timeval PollWait; // Time at which last poll was done
|
|
long PollInterval; // Minimum delay between polls
|
|
|
|
// Reply
|
|
bool WaitingForReply; // Command sent, waiting for reply
|
|
long ReplyTimeout; // Max waiting time for reply
|
|
|
|
// Retry
|
|
int PollRetry; // No of polling retries that has timed out
|
|
int MaxRetries; // Max allowed retries
|
|
|
|
// Manage Devices
|
|
bool DestroyDevice( TDevice ** Device );
|
|
|
|
// Find Devices
|
|
inline TDevice * GetDevice( const char * Name ) {
|
|
TDevice * Device = FirstDevice;
|
|
while (Device && strcasecmp( Device->Name, Name ))
|
|
Device = Device->Next;
|
|
return Device;
|
|
}
|
|
inline TDevice ** GetDevicePtr( const char * Name ) {
|
|
TDevice ** Device = &FirstDevice;
|
|
while (*Device && strcasecmp( (*Device)->Name, Name ))
|
|
Device = &((*Device)->Next);
|
|
return Device;
|
|
}
|
|
inline TDevice * GetNextOnlineDevice( TDevice * LastDevice ) {
|
|
TDevice * Device = LastDevice;
|
|
while (Device && !Device->Online)
|
|
Device = Device->Next;
|
|
return Device;
|
|
}
|
|
|
|
// Manage Params
|
|
bool DestroyDeviceParam( TDeviceParam ** Param );
|
|
|
|
// Find Params
|
|
inline TDeviceParam * GetDeviceParam( TDevice * Device, const char * Name ) {
|
|
if (!Device) return NULL;
|
|
TDeviceParam * Param = Device->FirstParam;
|
|
while (Param && strcasecmp( Param->Name, Name ))
|
|
Param = Param->Next;
|
|
return Param;
|
|
}
|
|
inline TDeviceParam ** GetDeviceParamPtr( TDevice * Device, const char * Name ) {
|
|
if (!Device) return NULL;
|
|
TDeviceParam ** Param = &Device->FirstParam;
|
|
while (*Param && strcasecmp( (*Param)->Name, Name ))
|
|
Param = &((*Param)->Next);
|
|
return Param;
|
|
}
|
|
inline TDeviceParam * GetNextScanParam( TDevice * Device, TDeviceParam * LastParam = NULL ) {
|
|
if (!Device) return NULL;
|
|
TDeviceParam * Param = (LastParam)? LastParam->Next : Device->FirstParam;
|
|
while (Param && (!Param->Scan))
|
|
Param = Param->Next;
|
|
return Param;
|
|
}
|
|
inline TDeviceParam * GetNextChangedParam( TDevice * Device, TDeviceParam * LastParam = NULL ) {
|
|
if (!Device) return NULL;
|
|
TDeviceParam * Param = (LastParam)? LastParam->Next : Device->FirstParam;
|
|
while (Param && (!Param->Changed))
|
|
Param = Param->Next;
|
|
return Param;
|
|
}
|
|
inline TDeviceParam * GetNextSetChangedParam( TDevice * Device, TDeviceParam * LastParam = NULL ) {
|
|
if (!Device) return NULL;
|
|
TDeviceParam * Param = (LastParam)? LastParam->Next : Device->FirstParam;
|
|
while (Param && (!Param->SetChanged))
|
|
Param = Param->Next;
|
|
return Param;
|
|
}
|
|
|
|
// Tools
|
|
bool CompareParamString( const char * ParamValue, const int ParamLen, const char * Value, const int Len );
|
|
|
|
// Generate events
|
|
bool EventOutput( TDeviceParam * Param, bool Force );
|
|
bool TimedParamEvents();
|
|
|
|
// Manage device
|
|
virtual bool DeviceOnline( TDevice * Device, bool Online );
|
|
|
|
// Handle Reply Timing
|
|
virtual void SetWaitForReply();
|
|
virtual bool CheckReplyTimeout( int TimeoutPollStep );
|
|
|
|
public:
|
|
// Life cycle
|
|
CDeviceCore( const char * pName, CLogCore * pLog );
|
|
virtual ~CDeviceCore();
|
|
|
|
// Generate events
|
|
bool SetPollParam( int pPollInterval );
|
|
bool SetReplyParam( int pReplyTimeout, int pMaxRetries );
|
|
bool SetUpdate( int pUpdateInterval );
|
|
bool SetParamScan( TDeviceParam * Param, bool Scan, const char * ChannelName, long pUpdateInterval );
|
|
|
|
// Manage Devices
|
|
TDevice * AddDevice( const char * DeviceName );
|
|
bool DestroyDevice( const char * DeviceName );
|
|
|
|
// Manage Params
|
|
TDeviceParam * AddDeviceParam( TDevice * Device, const char * ParamName, EMBDataType DataType, int ParamLen = 1 );
|
|
bool DestroyDeviceParam( TDevice * Device, const char * ParamName );
|
|
|
|
// Update/Init Param values
|
|
bool UpdateUnsignedValue( TDeviceParam * Param, const u_int32_t Value, bool Init );
|
|
bool UpdateSignedValue( TDeviceParam * Param, const int32_t Value, bool Init );
|
|
bool UpdateFloatValue( TDeviceParam * Param, const float Value, bool Init );
|
|
bool UpdateStringValue( TDeviceParam * Param, const char * Value, const int Len, bool Init );
|
|
|
|
// Change Param Update instruction
|
|
bool SetUnsignedValue( TDeviceParam * Param, const u_int32_t Value, bool Force );
|
|
bool SetSignedValue( TDeviceParam * Param, const int32_t Value, bool Force );
|
|
bool SetFloatValue( TDeviceParam * Param, const float Value, bool Force );
|
|
bool SetStringValue( TDeviceParam * Param, const char * Value, const int Len, bool Force );
|
|
|
|
// Text Interfaces
|
|
bool SetValue( TDeviceParam * Param, const char * Value, const int Len, bool Force );
|
|
bool GetValue( TDeviceParam * Param, char * Value, int &Len );
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
|
|
#endif /* REDACORE_DEVICECORE_H_ */
|