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 );
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user