Skip to content

Commit

Permalink
Allow Setting Value of GroupObject (KO) with Checking Change after Co…
Browse files Browse the repository at this point in the history
…nversion

* Return if Value was Changed
* Always Set the First Value
* Copy on Changes Only
* Make Comparison Independent of Sending
  • Loading branch information
cornelius-koepp committed Jan 7, 2024
1 parent c8685fa commit ee55abd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/knx/group_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,26 @@ void GroupObject::valueNoSend(const KNXValue& value, const Dpt& type)

KNX_Encode_Value(value, _data, _dataLength, type);
}

bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type)
{
if (_commFlag == Uninitialized)
{
// always set first value
this->valueNoSend(value, type);
return true;
}
else
{
// convert new value to given dtp
uint8_t newData[_dataLength];
KNX_Encode_Value(value, newData, _dataLength, type);

// check for change in converted value / update value on change only
const bool dataChanged = memcmp(_data, newData, _dataLength);
if (dataChanged)
memcpy(_data, newData, _dataLength);

return dataChanged;
}
}
12 changes: 12 additions & 0 deletions src/knx/group_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ class GroupObject
* The parameters must fit the group object. Otherwise it will stay unchanged.
*/
void valueNoSend(const KNXValue& value, const Dpt& type);

/**
* check if the value (after conversion to dpt) will differ from current value of the group object and update if necessary.
* @param value the value the group object is set to
* @param type the datapoint type used for the conversion.
*
* The parameters must fit the group object. Otherwise it will stay unchanged.
*
* @returns true if the value of the group object has changed
*/
bool valueNoSendCompare(const KNXValue& value, const Dpt& type);

/**
* set the current value of the group object.
* @param value the value the group object is set to
Expand Down

0 comments on commit ee55abd

Please sign in to comment.