Important Update:
- Add GetValue/SetValue commands for Device command interface - Bug fix: use case compare on searches
This commit is contained in:
170
DeviceCore.cpp
170
DeviceCore.cpp
@@ -520,67 +520,6 @@ bool CDeviceCore::UpdateStringValue( TDeviceParam * Param, const char * Value, c
|
||||
|
||||
switch (Param->DataType)
|
||||
{
|
||||
// case dtUnsigned16 :
|
||||
// u_int16_t TestVal;
|
||||
// if (Init || (*((u_int16_t*)Param->Value) != Value))
|
||||
// {
|
||||
// // Set new value & mark change
|
||||
// *((u_int16_t*)Param->Value) = Value;
|
||||
//
|
||||
// // Mark change & log event
|
||||
// Changed = true;
|
||||
// Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %u", Name, Param->Name, ((Init)? "initialised" : "changed"), *((u_int16_t*)Param->Value) );
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case dtUnsigned32 :
|
||||
// if (Init || (*((u_int32_t*)Param->Value) != Value))
|
||||
// {
|
||||
// // Set new value & mark change
|
||||
// *((u_int32_t*)Param->Value) = Value;
|
||||
//
|
||||
// // Mark change & log event
|
||||
// Changed = true;
|
||||
// Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %u", Name, Param->Name, ((Init)? "initialised" : "changed"), *((u_int32_t*)Param->Value) );
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case dtSigned16 :
|
||||
// if (Init || (*((int16_t*)Param->Value) != Value))
|
||||
// {
|
||||
// // Set new value & mark change
|
||||
// *((int16_t*)Param->Value) = Value;
|
||||
//
|
||||
// // Mark change & log event
|
||||
// Changed = true;
|
||||
// Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %d", Name, Param->Name, ((Init)? "initialised" : "changed"), *((int16_t*)Param->Value) );
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case dtSigned32 :
|
||||
// if (Init || (*((int32_t*)Param->Value) != Value))
|
||||
// {
|
||||
// // Set new value & mark change
|
||||
// *((int32_t*)Param->Value) = Value;
|
||||
//
|
||||
// // Mark change & log event
|
||||
// Changed = true;
|
||||
// Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %d", Name, Param->Name, ((Init)? "initialised" : "changed"), *((int32_t*)Param->Value) );
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case dtFloat32 : // Special case, where float value is stored in Integer memory (e.g. modbus register)
|
||||
// if (Init || (*((u_int32_t*)Param->Value) != Value))
|
||||
// {
|
||||
// // Set new value & mark change
|
||||
// *((u_int32_t*)Param->Value) = Value;
|
||||
//
|
||||
// // Mark change & log event
|
||||
// Changed = true;
|
||||
// Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %f", Name, Param->Name, ((Init)? "initialised" : "changed"), *((float*)Param->Value) );
|
||||
// }
|
||||
// break;
|
||||
|
||||
case dtString :
|
||||
// Update register
|
||||
if (Init || !CompareParamString( (char*)Param->Value, Param->Len, Value, Len))
|
||||
@@ -750,6 +689,115 @@ bool CDeviceCore::SetStringValue( TDeviceParam * Param, const char * Value, cons
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CDeviceCore::SetValue( TDeviceParam * Param, const char * Value, const int Len, bool Force )
|
||||
{
|
||||
u_int32_t UnsignedVal;
|
||||
int32_t SignedVal;
|
||||
float FloatVal;
|
||||
|
||||
char * TempStr;
|
||||
bool UseTempStr = false;
|
||||
|
||||
// Validate
|
||||
if (!Param || !Value || !Len)
|
||||
return false;
|
||||
|
||||
// Check if string
|
||||
if (Param->DataType == dtString)
|
||||
{
|
||||
// Simply set string
|
||||
SetStringValue( Param, Value, Len, Force );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure string is zero terminated
|
||||
if (Value[Len] != 0) {
|
||||
TempStr = (char *)malloc( Len+1 );
|
||||
memcpy( TempStr, Value, Len );
|
||||
TempStr[Len] = 0;
|
||||
UseTempStr = true;
|
||||
}
|
||||
|
||||
// Convert to correct type
|
||||
switch (Param->DataType)
|
||||
{
|
||||
case dtUnsigned16 :
|
||||
case dtUnsigned32 :
|
||||
UnsignedVal = (u_int32_t)strtoul( ((UseTempStr)? TempStr : Value), NULL, 10 );
|
||||
SetUnsignedValue( Param, UnsignedVal, Force );
|
||||
break;
|
||||
|
||||
case dtSigned16 :
|
||||
case dtSigned32 :
|
||||
SignedVal = (u_int32_t)strtol( ((UseTempStr)? TempStr : Value), NULL, 10 );
|
||||
SetUnsignedValue( Param, SignedVal, Force );
|
||||
break;
|
||||
|
||||
case dtFloat32 :
|
||||
FloatVal = (u_int32_t) strtof( ((UseTempStr)? TempStr : Value), NULL );
|
||||
SetUnsignedValue( Param, FloatVal, Force );
|
||||
break;
|
||||
|
||||
default :
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clear memory
|
||||
if (UseTempStr) {
|
||||
free( TempStr );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CDeviceCore::GetValue( TDeviceParam * Param, char * Value, int &Len )
|
||||
{
|
||||
// Validate
|
||||
if (!Param || !Value)
|
||||
return false;
|
||||
|
||||
// Check if return value longer than actual value
|
||||
switch (Param->DataType)
|
||||
{
|
||||
case dtUnsigned16 :
|
||||
sprintf( Value, "%u", (*((u_int16_t*)Param->Value)) );
|
||||
break;
|
||||
|
||||
case dtUnsigned32 :
|
||||
sprintf( Value, "%u", (*((u_int32_t*)Param->Value)) );
|
||||
break;
|
||||
|
||||
case dtSigned16 :
|
||||
sprintf( Value, "%d", (*((int16_t*)Param->Value)) );
|
||||
break;
|
||||
|
||||
case dtSigned32 :
|
||||
sprintf( Value, "%d", (*((int32_t*)Param->Value)) );
|
||||
break;
|
||||
|
||||
case dtFloat32 :
|
||||
sprintf( Value, "%f", (*((float*)Param->Value)) );
|
||||
break;
|
||||
|
||||
case dtString :
|
||||
if (Len < Param->Len)
|
||||
{
|
||||
// Only copy requested no of chars
|
||||
memcpy( Value, Param->Value, Len );
|
||||
Value[ Len ] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy( Value, Param->Value, Param->Len );
|
||||
Value[ Param->Len ] = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CDeviceCore::CompareParamString( const char * ParamValue, const int ParamLen, const char * Value, const int Len )
|
||||
{
|
||||
bool Match = true;
|
||||
|
||||
Reference in New Issue
Block a user