Allow Updating ComObject with Sending On Modification Only

This commit is contained in:
Cornelius Köpp 2023-08-13 22:01:45 +02:00
parent 4c16a38803
commit 1eb4a797a5
2 changed files with 25 additions and 0 deletions

View File

@ -279,3 +279,18 @@ void GroupObject::valueNoSend(const KNXValue& value, const Dpt& type)
KNX_Encode_Value(value, _data, _dataLength, type); KNX_Encode_Value(value, _data, _dataLength, type);
} }
void GroupObject::valueSendChangedOnly(const KNXValue& value, const Dpt& type)
{
// save current value
const uint8_t oldLength = _dataLength;
uint8_t* old = new uint8_t[_dataLength];
memcpy(old, _data, oldLength);
// update value in com-object, without sending to bus
valueNoSend(value, type);
// only when raw data differs trigger sending
if (oldLength!=_dataLength || memcmp(old, _data, oldLength)!=0)
objectWritten();
}

View File

@ -166,6 +166,16 @@ class GroupObject
* The parameters must fit the group object. Otherwise it will stay unchanged. * The parameters must fit the group object. Otherwise it will stay unchanged.
*/ */
void valueNoSend(const KNXValue& value, const Dpt& type); void valueNoSend(const KNXValue& value, const Dpt& type);
/**
* set the current value of the group object and only when resulting value differes, changes the state of the group object to ::WriteRequest.
* @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.
*/
void valueSendChangedOnly(const KNXValue& value, const Dpt& type);
/** /**
* set the current value of the group object. * set the current value of the group object.
* @param value the value the group object is set to * @param value the value the group object is set to