Update in progress:
- Started work on Set/Get commands for DeviceCore
This commit is contained in:
102
DeviceCore.cpp
102
DeviceCore.cpp
@@ -518,24 +518,94 @@ bool CDeviceCore::UpdateStringValue( TDeviceParam * Param, const char * Value, c
|
||||
if (!Param || (Param->DataType != dtString))
|
||||
return false;
|
||||
|
||||
// Update register
|
||||
if (Init || !CompareParamString( (char*)Param->Value, Param->Len, Value, Len))
|
||||
switch (Param->DataType)
|
||||
{
|
||||
if (Len >= Param->Len) {
|
||||
// Copy full register length (ignore additional bytes)
|
||||
memcpy( Param->Value, Value, Param->Len );
|
||||
((char*)Param->Value)[ Param->Len ] = 0; // null terminate
|
||||
}
|
||||
else {
|
||||
// Copy new value
|
||||
memcpy( Param->Value, Value, Len );
|
||||
// Zero pad remaining
|
||||
memset( &((char*)Param->Value)[Len], 0x0, (Param->Len - Len + 1) ); // Add null teriminate
|
||||
}
|
||||
// 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;
|
||||
|
||||
// Mark Change
|
||||
Changed = true;
|
||||
Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %s", Name, Param->Name, ((Init)? "initialised" : "changed"), (char*)Param->Value );
|
||||
case dtString :
|
||||
// Update register
|
||||
if (Init || !CompareParamString( (char*)Param->Value, Param->Len, Value, Len))
|
||||
{
|
||||
if (Len >= Param->Len) {
|
||||
// Copy full register length (ignore additional bytes)
|
||||
memcpy( Param->Value, Value, Param->Len );
|
||||
((char*)Param->Value)[ Param->Len ] = 0; // null terminate
|
||||
}
|
||||
else {
|
||||
// Copy new value
|
||||
memcpy( Param->Value, Value, Len );
|
||||
// Zero pad remaining
|
||||
memset( &((char*)Param->Value)[Len], 0x0, (Param->Len - Len + 1) ); // Add null teriminate
|
||||
}
|
||||
|
||||
// Mark Change
|
||||
Changed = true;
|
||||
Log->Message( DebugLevel, dlLow, "%s: '%s' %s - %s", Name, Param->Name, ((Init)? "initialised" : "changed"), (char*)Param->Value );
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
// Invalid Data Type
|
||||
return false;
|
||||
}
|
||||
// Generate Channel Event
|
||||
if (Changed) {
|
||||
|
||||
Reference in New Issue
Block a user