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:
Charl Wentzel
2018-12-10 21:21:13 +02:00
parent 2ff8f556aa
commit 07f746db2a
2 changed files with 71 additions and 2 deletions

View File

@@ -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) );