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:
@@ -18,7 +18,7 @@
|
||||
|
||||
// Global Vars
|
||||
extern char * ProcessName;
|
||||
//extern CApplication * Application;
|
||||
extern CApplication * Application;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -50,6 +50,9 @@ CDeviceCore::CDeviceCore( const char * pName, const char * pType ) : CFunctionCo
|
||||
|
||||
// Update Timer
|
||||
SetUpdate( 0 );
|
||||
|
||||
// Data Structures
|
||||
Config = NULL;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -61,6 +64,45 @@ CDeviceCore::~CDeviceCore()
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CDeviceCore::Init( CDataMember * FunctionConfig )
|
||||
{
|
||||
char * ConfigName = NULL;
|
||||
CDataMember * PollConfig = NULL;
|
||||
int IntVal1;
|
||||
int IntVal2;
|
||||
|
||||
// Call Previous load config
|
||||
if (!CFunctionCore::Init( FunctionConfig ))
|
||||
return false;
|
||||
|
||||
// Get configuration
|
||||
if ((Config = FunctionConfig->GetChild( "Config", true )) && Config->isString()) {
|
||||
ConfigName = (char*)FunctionConfig->GetChStr( "Config" );
|
||||
Config = Application->Config->GetChild( ConfigName, true );
|
||||
}
|
||||
if (Config->isNull()) Config->SetObject();
|
||||
|
||||
// Load Polling configuration
|
||||
PollConfig = Config->GetChild( "Polling", true );
|
||||
if (PollConfig->isNull()) PollConfig->SetObject();
|
||||
|
||||
IntVal1 = PollConfig->GetChInt( "PollInterval", 500, true );
|
||||
SetPollParam( IntVal1 );
|
||||
|
||||
IntVal1 = PollConfig->GetChInt( "ReplyTimeout", 250, true );
|
||||
IntVal2 = PollConfig->GetChInt( "MaxRetries", 3, true );
|
||||
SetReplyParam( IntVal1, IntVal2 );
|
||||
|
||||
IntVal1 = PollConfig->GetChInt( "UpdateInterval", 1000, true );
|
||||
SetUpdate( IntVal1 );
|
||||
|
||||
Log->Message( LogLevel, dlMedium, "%s/%s: Set Polling param - Int:%d, TO:%d, Max:%d, Up:%d",
|
||||
ProcessName, Name, PollInterval, ReplyTimeout, MaxRetries, UpdateInterval );
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CDeviceCore::SetPollParam( int pPollInterval )
|
||||
{
|
||||
PollInterval = pPollInterval;
|
||||
@@ -316,6 +358,9 @@ TDeviceParam * CDeviceCore::AddDeviceParam( TDevice * Device, const char * Param
|
||||
(*Param)->SetValue = (char*)malloc( ParamLen + 1 );
|
||||
memset( (*Param)->SetValue, 0x0, (*Param)->SetLen+1 );
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,6 +853,9 @@ bool CDeviceCore::GetValue( TDeviceParam * Param, char * Value, int &Len )
|
||||
Value[ Param->Len ] = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -925,6 +973,9 @@ bool CDeviceCore::EventOutput( TDeviceParam * Param, bool Force )
|
||||
case dtString :
|
||||
sprintf( Message, "%s: %s\n", Param->Name, (char*)Param->Value );
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
Output( Param->EventChannel, Message, strlen(Message) );
|
||||
|
||||
|
||||
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