Important Update:
- DeviceCore: - Added Data Type "bool" - Create boolean var for params of type "bool"
This commit is contained in:
@@ -243,15 +243,16 @@ bool CDeviceCore::CopyTemplateParam( TDevice * Device, TDeviceParam * Template,
|
|||||||
SetDataPath( Param, DataPath, DataNode );
|
SetDataPath( Param, DataPath, DataNode );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Template->DataType == dtUnsigned16) || (Template->DataType == dtUnsigned32_HL) || (Template->DataType == dtUnsigned32_LH)) {
|
if ((Template->DataType == dtBool) || (Template->DataType == dtUnsigned16) ||
|
||||||
UpdateUnsignedValue( Param, *((u_int16_t*)Template->Value), Template->Changed );
|
(Template->DataType == dtUnsigned32_HL) || (Template->DataType == dtUnsigned32_LH)) {
|
||||||
|
UpdateUnsignedValue( Param, *((u_int32_t*)Template->Value), Template->Changed );
|
||||||
if (Template->SetChanged)
|
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)) {
|
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)
|
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)) {
|
else if ((Template->DataType == dtFloat32_L) || (Template->DataType == dtFloat32_B)) {
|
||||||
UpdateFloatValue( Param, *((float*)Template->Value), Template->Changed );
|
UpdateFloatValue( Param, *((float*)Template->Value), Template->Changed );
|
||||||
@@ -389,7 +390,8 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
|||||||
SetDataPath( Param, DataPath, DataNode );
|
SetDataPath( Param, DataPath, DataNode );
|
||||||
|
|
||||||
if ((InitVal = ParamConfig->GetChild( "InitValue", false ))) {
|
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 );
|
UpdateUnsignedValue( Param, InitVal->GetInt(0), Read );
|
||||||
if (Write)
|
if (Write)
|
||||||
SetUnsignedValue( Param, InitVal->GetInt(0), true );
|
SetUnsignedValue( Param, InitVal->GetInt(0), true );
|
||||||
@@ -681,6 +683,18 @@ TDeviceParam * CDeviceCore::AddDeviceParam( TDevice * Device, const char * Param
|
|||||||
// Init values
|
// Init values
|
||||||
switch (DataType)
|
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 :
|
case dtUnsigned16 :
|
||||||
// Create Value pointer
|
// Create Value pointer
|
||||||
(*Param)->Value = (u_int16_t*)malloc( sizeof(u_int16_t) );
|
(*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)
|
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 :
|
case dtUnsigned16 :
|
||||||
if (Init || (*((u_int16_t*)Param->Value) != Value))
|
if (Init || (*((u_int16_t*)Param->Value) != Value))
|
||||||
{
|
{
|
||||||
@@ -1054,6 +1087,25 @@ bool CDeviceCore::UpdateSignedValue( TDeviceParam * Param, const int32_t Value,
|
|||||||
|
|
||||||
switch (Param->DataType)
|
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 :
|
case dtSigned16 :
|
||||||
if (Init || (*((int16_t*)Param->Value) != Value))
|
if (Init || (*((int16_t*)Param->Value) != Value))
|
||||||
{
|
{
|
||||||
@@ -1209,6 +1261,17 @@ bool CDeviceCore::SetUnsignedValue( TDeviceParam * Param, const u_int32_t Value,
|
|||||||
|
|
||||||
switch (Param->DataType)
|
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 :
|
case dtUnsigned16 :
|
||||||
if (Force || (*((u_int16_t*)Param->SetValue) != Value))
|
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)
|
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 :
|
case dtSigned16 :
|
||||||
if (Force || (*((int16_t*)Param->SetValue) != Value))
|
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
|
// Convert to correct type
|
||||||
switch (Param->DataType)
|
switch (Param->DataType)
|
||||||
{
|
{
|
||||||
|
case dtBool :
|
||||||
case dtUnsigned16 :
|
case dtUnsigned16 :
|
||||||
case dtUnsigned32_HL :
|
case dtUnsigned32_HL :
|
||||||
case dtUnsigned32_LH :
|
case dtUnsigned32_LH :
|
||||||
@@ -1413,6 +1488,10 @@ bool CDeviceCore::GetValue( TDeviceParam * Param, char * Value, int &Len )
|
|||||||
// Check if return value longer than actual value
|
// Check if return value longer than actual value
|
||||||
switch (Param->DataType)
|
switch (Param->DataType)
|
||||||
{
|
{
|
||||||
|
case dtBool :
|
||||||
|
sprintf( Value, "%u", (*((bool*)Param->Value)) );
|
||||||
|
break;
|
||||||
|
|
||||||
case dtUnsigned16 :
|
case dtUnsigned16 :
|
||||||
sprintf( Value, "%u", (*((u_int16_t*)Param->Value)) );
|
sprintf( Value, "%u", (*((u_int16_t*)Param->Value)) );
|
||||||
break;
|
break;
|
||||||
@@ -1706,6 +1785,10 @@ bool CDeviceCore::EventOutput( TDeviceParam * Param, bool Force )
|
|||||||
char Message[200];
|
char Message[200];
|
||||||
switch (Param->DataType)
|
switch (Param->DataType)
|
||||||
{
|
{
|
||||||
|
case dtBool :
|
||||||
|
sprintf( Message, "%s: %u\n", Param->Name, *((bool*)Param->Value) );
|
||||||
|
break;
|
||||||
|
|
||||||
case dtUnsigned16 :
|
case dtUnsigned16 :
|
||||||
sprintf( Message, "%s: %u\n", Param->Name, *((u_int16_t*)Param->Value) );
|
sprintf( Message, "%s: %u\n", Param->Name, *((u_int16_t*)Param->Value) );
|
||||||
break;
|
break;
|
||||||
|
|||||||
18
DeviceCore.h
18
DeviceCore.h
@@ -18,12 +18,12 @@
|
|||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Enumerated types
|
// Enumerated types
|
||||||
typedef enum { dtNone = 0, dtUnsigned16 = 1, dtSigned16 = 2, dtUnsigned32_HL = 3, dtUnsigned32_LH = 4,
|
typedef enum { dtNone = 0, dtBool = 1, dtUnsigned16 = 2, dtSigned16 = 3, dtUnsigned32_HL = 4, dtUnsigned32_LH = 5,
|
||||||
dtSigned32_HL = 5, dtSigned32_LH = 6, dtFloat32_L = 7, dtFloat32_B = 8, dtString = 9 } EDeviceDataType;
|
dtSigned32_HL = 6, dtSigned32_LH = 7, dtFloat32_L = 8, dtFloat32_B = 9, dtString = 10 } EDeviceDataType;
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const char DataTypeCount = 10;
|
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" };
|
"Signed32_HL", "Signed32_LH", "Float32_L", "Float32_B", "String" };
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -232,11 +232,7 @@ protected:
|
|||||||
Param = &((*Param)->Next);
|
Param = &((*Param)->Next);
|
||||||
return Param;
|
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 ) {
|
inline TDeviceParam * GetNextReadParam( TDevice * Device, TDeviceParam * LastParam = NULL ) {
|
||||||
if (!Device) return NULL;
|
if (!Device) return NULL;
|
||||||
TDeviceParam * Param = (LastParam)? LastParam->Next : Device->FirstParam;
|
TDeviceParam * Param = (LastParam)? LastParam->Next : Device->FirstParam;
|
||||||
@@ -276,6 +272,12 @@ protected:
|
|||||||
return Group;
|
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
|
// Find Param Groups Items
|
||||||
inline TDeviceParamItem * GetParamItem( TDeviceParamGroup * Group, const char * ParamName ) {
|
inline TDeviceParamItem * GetParamItem( TDeviceParamGroup * Group, const char * ParamName ) {
|
||||||
TDeviceParamItem ** Item = GetParamItemPtr( Group, ParamName );
|
TDeviceParamItem ** Item = GetParamItemPtr( Group, ParamName );
|
||||||
|
|||||||
Reference in New Issue
Block a user