Important Update:
- DeviceCore: - Add dtNone data type - Add Config param, reference to data tree - Add Init() methods, loading config from JSON - Add GetDataType() method, converts text to data type enum - Add Set/UpdateStringValue() methods with Len param - Clear compiler warnings, missing switch case values
This commit is contained in:
20
DeviceCore.h
20
DeviceCore.h
@@ -17,9 +17,10 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Enumerated types
|
||||
typedef enum { dtUnsigned16 = 0, dtSigned16 = 1, dtUnsigned32 = 2, dtSigned32 = 3, dtFloat32 = 4, dtString = 5 } EMBDataType;
|
||||
typedef enum { dtNone = 0, dtUnsigned16 = 1, dtSigned16 = 2, dtUnsigned32 = 3, dtSigned32 = 4, dtFloat32 = 5, dtString = 6 } EMBDataType;
|
||||
|
||||
// Constants
|
||||
const char DataTypeCount = 6;
|
||||
const char DataTypeName[][20] = { "Unsigned16", "Signed16", "Unsigned32", "Signed32", "Float32", "String" };
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -70,6 +71,9 @@ struct SDeviceParam {
|
||||
class CDeviceCore : public CFunctionCore
|
||||
{
|
||||
protected:
|
||||
// Configuration
|
||||
CDataMember * Config;
|
||||
|
||||
// Update
|
||||
int UpdateInterval;
|
||||
timeval UpdateTimeout;
|
||||
@@ -159,6 +163,13 @@ protected:
|
||||
}
|
||||
|
||||
// Tools
|
||||
inline EMBDataType GetDataType( const char * TypeName ) {
|
||||
int Type;
|
||||
for (Type = 0; Type < DataTypeCount; Type++)
|
||||
if (!strcasecmp( TypeName, DataTypeName[Type])) break;
|
||||
return (Type == DataTypeCount)? dtNone : (EMBDataType)Type;
|
||||
}
|
||||
|
||||
bool CompareParamString( const char * ParamValue, const int ParamLen, const char * Value, const int Len );
|
||||
|
||||
// Generate events
|
||||
@@ -177,6 +188,9 @@ public:
|
||||
CDeviceCore( const char * pName, const char * pType = TYPE_DEVICE );
|
||||
virtual ~CDeviceCore();
|
||||
|
||||
// Configuration
|
||||
bool Init( CDataMember * FunctionConfig );
|
||||
|
||||
// Generate events
|
||||
bool SetPollParam( int pPollInterval );
|
||||
bool SetReplyParam( int pReplyTimeout, int pMaxRetries );
|
||||
@@ -196,12 +210,16 @@ public:
|
||||
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 );
|
||||
bool UpdateStringValue( TDeviceParam * Param, const char * Value, bool Init )
|
||||
{ return UpdateStringValue( Param, Value, strlen(Value), 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 );
|
||||
bool SetStringValue( TDeviceParam * Param, const char * Value, bool Force )
|
||||
{ return SetStringValue( Param, Value, strlen(Value), Force ); };
|
||||
|
||||
// Text Interfaces
|
||||
bool SetValue( TDeviceParam * Param, const char * Value, const int Len, bool Force );
|
||||
|
||||
Reference in New Issue
Block a user