Important Update:

- DeviceCore:
  - Added Data Type "bool"
  - Create boolean var for params of type "bool"
This commit is contained in:
Charl Wentzel
2019-07-10 19:37:01 +02:00
parent 77db246541
commit 7d69edffa2
2 changed files with 99 additions and 14 deletions

View File

@@ -243,15 +243,16 @@ bool CDeviceCore::CopyTemplateParam( TDevice * Device, TDeviceParam * Template,
SetDataPath( Param, DataPath, DataNode );
}
if ((Template->DataType == dtUnsigned16) || (Template->DataType == dtUnsigned32_HL) || (Template->DataType == dtUnsigned32_LH)) {
UpdateUnsignedValue( Param, *((u_int16_t*)Template->Value), Template->Changed );
if ((Template->DataType == dtBool) || (Template->DataType == dtUnsigned16) ||
(Template->DataType == dtUnsigned32_HL) || (Template->DataType == dtUnsigned32_LH)) {
UpdateUnsignedValue( Param, *((u_int32_t*)Template->Value), Template->Changed );
if (Template->SetChanged)
SetUnsignedValue( Param, *((u_int16_t*)Template->Value), true );
SetUnsignedValue( Param, *((u_int32_t*)Template->Value), true );
}
else if ((Template->DataType == dtSigned16) || (Template->DataType == dtSigned32_HL) || (Template->DataType == dtSigned32_LH)) {
UpdateSignedValue( Param, *((int16_t*)Template->Value), Template->Changed );
UpdateSignedValue( Param, *((int32_t*)Template->Value), Template->Changed );
if (Template->SetChanged)
SetSignedValue( Param, *((int16_t*)Template->Value), true );
SetSignedValue( Param, *((int32_t*)Template->Value), true );
}
else if ((Template->DataType == dtFloat32_L) || (Template->DataType == dtFloat32_B)) {
UpdateFloatValue( Param, *((float*)Template->Value), Template->Changed );
@@ -389,7 +390,8 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
SetDataPath( Param, DataPath, DataNode );
if ((InitVal = ParamConfig->GetChild( "InitValue", false ))) {
if ((DataType == dtUnsigned16) || (DataType == dtUnsigned32_HL) || (DataType == dtUnsigned32_LH)) {
if ((DataType == dtBool) || (DataType == dtUnsigned16) ||
(DataType == dtUnsigned32_HL) || (DataType == dtUnsigned32_LH)) {
UpdateUnsignedValue( Param, InitVal->GetInt(0), Read );
if (Write)
SetUnsignedValue( Param, InitVal->GetInt(0), true );
@@ -681,6 +683,18 @@ TDeviceParam * CDeviceCore::AddDeviceParam( TDevice * Device, const char * Param
// Init values
switch (DataType)
{
case dtBool :
// Create Value pointer
(*Param)->Value = (bool*)malloc( sizeof(bool) );
*((bool*)(*Param)->Value) = 0;
(*Param)->Len = sizeof(bool);
// Create Set Value pointer
(*Param)->SetValue = (bool*)malloc( sizeof(bool) );
*((bool*)(*Param)->SetValue) = 0;
(*Param)->SetLen = sizeof(bool);
break;
case dtUnsigned16 :
// Create Value pointer
(*Param)->Value = (u_int16_t*)malloc( sizeof(u_int16_t) );
@@ -971,6 +985,25 @@ bool CDeviceCore::UpdateUnsignedValue( TDeviceParam * Param, const u_int32_t Val
switch (Param->DataType)
{
case dtBool :
if (Init || (*((bool*)Param->Value) != Value))
{
// Set new value & mark change
*((bool*)Param->Value) = Value;
if (Param->DataNode)
Param->DataNode->SetInt( *((bool*)Param->Value) );
// Mark change & log event
Changed = true;
if (Log) {
char * DeviceName = (Param->Device->Name)? Param->Device->Name : Param->Device->Type;
Log->Message( LogLevel, dlLow, "%s/%s: %s param '%s/%s' - %u", ProcessName, Name,
((Init)? "Init" : "Changed"), DeviceName, Param->Name, *((bool*)Param->Value) );
}
}
break;
case dtUnsigned16 :
if (Init || (*((u_int16_t*)Param->Value) != Value))
{
@@ -1054,6 +1087,25 @@ bool CDeviceCore::UpdateSignedValue( TDeviceParam * Param, const int32_t Value,
switch (Param->DataType)
{
case dtBool :
if (Init || (*((bool*)Param->Value) != Value))
{
// Set new value & mark change
*((bool*)Param->Value) = Value;
if (Param->DataNode)
Param->DataNode->SetInt( *((bool*)Param->Value) );
// Mark change & log event
Changed = true;
if (Log) {
char * DeviceName = (Param->Device->Name)? Param->Device->Name : Param->Device->Type;
Log->Message( LogLevel, dlLow, "%s/%s: %s param '%s/%s' - %d", ProcessName, Name,
((Init)? "Init" : "Changed"), DeviceName, Param->Name, *((bool*)Param->Value) );
}
}
break;
case dtSigned16 :
if (Init || (*((int16_t*)Param->Value) != Value))
{
@@ -1209,6 +1261,17 @@ bool CDeviceCore::SetUnsignedValue( TDeviceParam * Param, const u_int32_t Value,
switch (Param->DataType)
{
case dtBool :
if (Force || (*((bool*)Param->SetValue) != Value))
{
// Set new value
*((bool*)Param->SetValue) = Value;
// Mark change
Param->SetChanged = true;
}
break;
case dtUnsigned16 :
if (Force || (*((u_int16_t*)Param->SetValue) != Value))
{
@@ -1249,6 +1312,17 @@ bool CDeviceCore::SetSignedValue( TDeviceParam * Param, const int32_t Value, boo
switch (Param->DataType)
{
case dtBool :
if (Force || (*((bool*)Param->SetValue) != Value))
{
// Set new value
*((bool*)Param->SetValue) = Value;
// Mark change
Param->SetChanged = true;
}
break;
case dtSigned16 :
if (Force || (*((int16_t*)Param->SetValue) != Value))
{
@@ -1369,6 +1443,7 @@ bool CDeviceCore::SetValue( TDeviceParam * Param, const char * Value, const int
// Convert to correct type
switch (Param->DataType)
{
case dtBool :
case dtUnsigned16 :
case dtUnsigned32_HL :
case dtUnsigned32_LH :
@@ -1413,6 +1488,10 @@ bool CDeviceCore::GetValue( TDeviceParam * Param, char * Value, int &Len )
// Check if return value longer than actual value
switch (Param->DataType)
{
case dtBool :
sprintf( Value, "%u", (*((bool*)Param->Value)) );
break;
case dtUnsigned16 :
sprintf( Value, "%u", (*((u_int16_t*)Param->Value)) );
break;
@@ -1706,6 +1785,10 @@ bool CDeviceCore::EventOutput( TDeviceParam * Param, bool Force )
char Message[200];
switch (Param->DataType)
{
case dtBool :
sprintf( Message, "%s: %u\n", Param->Name, *((bool*)Param->Value) );
break;
case dtUnsigned16 :
sprintf( Message, "%s: %u\n", Param->Name, *((u_int16_t*)Param->Value) );
break;

View File

@@ -18,12 +18,12 @@
//---------------------------------------------------------------------------
// Enumerated types
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;
typedef enum { dtNone = 0, dtBool = 1, dtUnsigned16 = 2, dtSigned16 = 3, dtUnsigned32_HL = 4, dtUnsigned32_LH = 5,
dtSigned32_HL = 6, dtSigned32_LH = 7, dtFloat32_L = 8, dtFloat32_B = 9, dtString = 10 } EDeviceDataType;
// Constants
const char DataTypeCount = 10;
const char DataTypeName[][20] = { "None", "Unsigned16", "Signed16", "Unsigned32_HL", "Unsigned32_LH",
const char DataTypeName[][20] = { "None", "Boolean", "Unsigned16", "Signed16", "Unsigned32_HL", "Unsigned32_LH",
"Signed32_HL", "Signed32_LH", "Float32_L", "Float32_B", "String" };
//---------------------------------------------------------------------------
@@ -232,11 +232,7 @@ protected:
Param = &((*Param)->Next);
return Param;
}
inline TDeviceParamGroup * GetNextParamGroup( TDevice * Device, TDeviceParamGroup * LastParamGroup = NULL ) {
if (!Device) return NULL;
TDeviceParamGroup * ParamGroup = (LastParamGroup)? LastParamGroup->NextGroup : Device->FirstParamGroup;
return ParamGroup;
}
inline TDeviceParam * GetNextReadParam( TDevice * Device, TDeviceParam * LastParam = NULL ) {
if (!Device) return NULL;
TDeviceParam * Param = (LastParam)? LastParam->Next : Device->FirstParam;
@@ -276,6 +272,12 @@ protected:
return Group;
}
inline TDeviceParamGroup * GetNextParamGroup( TDevice * Device, TDeviceParamGroup * LastParamGroup = NULL ) {
if (!Device) return NULL;
TDeviceParamGroup * ParamGroup = (LastParamGroup)? LastParamGroup->NextGroup : Device->FirstParamGroup;
return ParamGroup;
}
// Find Param Groups Items
inline TDeviceParamItem * GetParamItem( TDeviceParamGroup * Group, const char * ParamName ) {
TDeviceParamItem ** Item = GetParamItemPtr( Group, ParamName );