- Implement new ApplicationCore:
- Manage Tools: Log, DataTree, JSONparser & Selector
- Load configuration, Manage FunctionBlocks
- FunctionCore & dirived classes, SignalCore:
- affects: SelectableCore, DeviceCore, FileCore, WatchdogCore
- Do not pass Log()
- Define and pass Type
- Update/reduce included headers
- Use ProcessName and Application global vars
- Get Log, DataTree from Application
- Use virtual Init() function to set must have Channels/Handles
- DataTreeCore:
- Bug fix: Check if child members exist and destroy in SetValuePtr()
- Add method GetFirstChild with BaseMember & Path
- Bug fix: do not use RootMember if no Parent in GetChildxxx() methods
- SignalCore, SelectCore:
- Use Application->Log()
- FunctionCore:
- Add itself to Application (function list)
- Add parameter: LinkConfigMember, Type
- Use virtual LoadConfigData() to configure from DataTree
- Rename methods: LoadConfig() -> InitConfig(),
InitLogging() -> SetLogParam(), SetDebugLevel() -> SetLogLevel()
- Add method: GetType(), LoadChannelLinkData(), InitChannelLinks()
- Modify LinkIn/OutputChannel() to use name for InFunction, not pointer
- SelectableCore & Dirived classes:
- Affects DeviceCore & WatchdogClient
- Rename parameter: Select -> Selector, BaseMember -> ConfigMember
- Get Selector from Application->Selector
- Change Handles JSON structure from Array to Key:Value pairs
- Bug fix: check if Selector exist during Input()
- Bug fix: do not set PortNo if not exist
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
|
|
/* none */
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// 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, const char * Type = "Device" );
|
|
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_ */
|