Major Update:
- FunctionCore: - Add OutputFormat param on Output() method - override output format - SelectableCore: - Update Log output formats (process/functionblock) - DeviceCore: - Updated device data format (different byte sequences) - Added ID & Address fields to TDevice struct - Add search methods for ID & Address - Update AddDevice() method to check for duplicate ID & address - Handle Invalid reply different from reply timeout - Add methods ValidReplyReceived() for standardise operation - Bug fix: DeviceTypes added as to Device List! - Bug fix: Check if Device/DeviceType created before adding params - Added correct handling of new Device Data types (LH & HL) - Updated log messages
This commit is contained in:
59
DeviceCore.h
59
DeviceCore.h
@@ -18,11 +18,13 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Enumerated types
|
||||
typedef enum { dtNone = 0, dtUnsigned16 = 1, dtSigned16 = 2, dtUnsigned32 = 3, dtSigned32 = 4, dtFloat32 = 5, dtString = 6 } EDeviceDataType;
|
||||
typedef enum { dtNone = 0, dtUnsigned16 = 1, dtSigned16 = 2, dtUnsigned32_HL = 3, dtUnsigned32_LH = 4,
|
||||
dtSigned32_HL = 5, dtSigned32_LH = 6, dtFloat32_L = 7, dtFloat32_B = 8, dtString = 9 } EDeviceDataType;
|
||||
|
||||
// Constants
|
||||
const char DataTypeCount = 6;
|
||||
const char DataTypeName[][20] = { "None", "Unsigned16", "Signed16", "Unsigned32", "Signed32", "Float32", "String" };
|
||||
const char DataTypeCount = 10;
|
||||
const char DataTypeName[][20] = { "None", "Unsigned16", "Signed16", "Unsigned32_HL", "Unsigned32_LH",
|
||||
"Signed32_HL", "Signed32_LH", "Float32_L", "Float32_B", "String" };
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -36,8 +38,12 @@ typedef struct SDeviceParamItem TDeviceParamItem;
|
||||
|
||||
// Devices with are polled
|
||||
struct SDevice {
|
||||
// Device definition
|
||||
// Device Identification
|
||||
char * Name = NULL;
|
||||
int ID = 0;
|
||||
char * Address = NULL;
|
||||
|
||||
// Device Type
|
||||
char * Type = NULL;
|
||||
TDevice * Template = NULL;
|
||||
|
||||
@@ -131,6 +137,7 @@ protected:
|
||||
|
||||
// Reply
|
||||
bool WaitingForReply; // Command sent, waiting for reply
|
||||
bool InvalidReply; // Invalid reply received
|
||||
long ReplyTimeout; // Max waiting time for reply
|
||||
|
||||
// Retry
|
||||
@@ -154,17 +161,41 @@ protected:
|
||||
}
|
||||
|
||||
// Find Devices
|
||||
inline TDevice * GetDevice( const char * Name ) {
|
||||
TDevice ** Device = GetDevicePtr(Name);
|
||||
inline TDevice * GetDeviceByName( const char * pName ) {
|
||||
TDevice ** Device = GetDevicePtrByName( pName );
|
||||
return (Device)? *Device : NULL;
|
||||
}
|
||||
inline TDevice ** GetDevicePtr( const char * Name ) {
|
||||
if (!Name || !*Name) return NULL;
|
||||
inline TDevice ** GetDevicePtrByName( const char * pName ) {
|
||||
if (!pName || !*pName) return NULL;
|
||||
TDevice ** Device = &FirstDevice;
|
||||
while (*Device && strcasecmp( (*Device)->Name, Name ))
|
||||
while (*Device && strcasecmp( (*Device)->Name, pName ))
|
||||
Device = &((*Device)->Next);
|
||||
return Device;
|
||||
}
|
||||
|
||||
inline TDevice * GetDeviceByID( int pID ) {
|
||||
TDevice ** Device = GetDevicePtrByID( pID );
|
||||
return (Device)? *Device : NULL;
|
||||
}
|
||||
inline TDevice ** GetDevicePtrByID( int pID ) {
|
||||
TDevice ** Device = &FirstDevice;
|
||||
while (*Device && ((*Device)->ID != pID ))
|
||||
Device = &((*Device)->Next);
|
||||
return Device;
|
||||
}
|
||||
|
||||
inline TDevice * GetDeviceByAddr( const char * Address ) {
|
||||
TDevice ** Device = GetDevicePtrByName(Address);
|
||||
return (Device)? *Device : NULL;
|
||||
}
|
||||
inline TDevice ** GetDevicePtrByAddr( const char * Address ) {
|
||||
if (!Address || !*Address) return NULL;
|
||||
TDevice ** Device = &FirstDevice;
|
||||
while (*Device && strcasecmp( (*Device)->Address, Address ))
|
||||
Device = &((*Device)->Next);
|
||||
return Device;
|
||||
}
|
||||
|
||||
inline TDevice * GetNextTypeDevice( const char * Type, TDevice * PrevDevice = NULL ) {
|
||||
TDevice * Device = (PrevDevice)? PrevDevice->Next : FirstDevice;
|
||||
while (Device && ((!Type && Device->Type) || (Type && (!Device->Type || strcasecmp( Type, Device->Type )))))
|
||||
@@ -264,7 +295,8 @@ protected:
|
||||
|
||||
// Handle Reply Timing
|
||||
virtual void SetWaitForReply();
|
||||
virtual bool CheckReplyTimeout( int TimeoutPollStep );
|
||||
virtual void ValidReplyReceived();
|
||||
virtual bool CheckReplyTimeout();
|
||||
|
||||
public:
|
||||
// Life cycle
|
||||
@@ -292,9 +324,9 @@ public:
|
||||
}
|
||||
|
||||
// Manage Devices
|
||||
TDevice * AddDevice( const char * DeviceName, const char * Type = NULL );
|
||||
TDevice * AddDevice( const char * DeviceName, const char * Type = NULL, const int ID = 0, const char * Address = NULL );
|
||||
inline bool DestroyDevice( const char * DeviceName ) {
|
||||
TDevice ** Device = GetDevicePtr(DeviceName);
|
||||
TDevice ** Device = GetDevicePtrByName(DeviceName);
|
||||
return (Device)? DestroyDevice( Device ) : false;
|
||||
}
|
||||
|
||||
@@ -335,10 +367,9 @@ public:
|
||||
return SetStringValue( Param, Value, strlen(Value), Force );
|
||||
};
|
||||
|
||||
|
||||
// Handle Interface Commands
|
||||
bool GetCmdParam( const char * Start, char * Param, char ** NextParam );
|
||||
int HandleCommand( const char *ChannelName, const char * Data, const int MaxLen );
|
||||
int HandleCommand( const char *ChannelName, const char * Data, const int MaxLen );
|
||||
|
||||
// Command Text Interfaces
|
||||
bool SetValue( TDeviceParam * Param, const char * Value, const int Len, bool Force );
|
||||
|
||||
Reference in New Issue
Block a user