From ee55abd2b910b589bd418bdcb959a9d7bb16c62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Sun, 13 Aug 2023 22:01:45 +0200 Subject: [PATCH 1/4] Allow Setting Value of GroupObject (KO) with Checking Change after Conversion * Return if Value was Changed * Always Set the First Value * Copy on Changes Only * Make Comparison Independent of Sending --- src/knx/group_object.cpp | 23 +++++++++++++++++++++++ src/knx/group_object.h | 12 ++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index 6898ba5..5a973ca 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -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; + } +} \ No newline at end of file diff --git a/src/knx/group_object.h b/src/knx/group_object.h index 88ce274..ca79c98 100644 --- a/src/knx/group_object.h +++ b/src/knx/group_object.h @@ -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 From fd887b9df13ead54afae8ce2c6b22ae504eaeb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Mon, 18 Sep 2023 20:23:06 +0200 Subject: [PATCH 2/4] Fix: Prevent False-Positive Change-Detection from Undefined Bits in (at least) DPT1 --- src/knx/group_object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index 5a973ca..3ade6c5 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -291,7 +291,7 @@ bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type) else { // convert new value to given dtp - uint8_t newData[_dataLength]; + uint8_t newData[_dataLength] = {0}; KNX_Encode_Value(value, newData, _dataLength, type); // check for change in converted value / update value on change only From e9541a9e76dd0e15b2f68278e349fcfc32b32074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Sun, 7 Jan 2024 19:55:42 +0100 Subject: [PATCH 3/4] Extend Doc of `valueNoSendCompare(..)`; Add Note for using `valueNoSend(..)` --- src/knx/group_object.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/knx/group_object.h b/src/knx/group_object.h index ca79c98..7c9191b 100644 --- a/src/knx/group_object.h +++ b/src/knx/group_object.h @@ -168,7 +168,8 @@ class GroupObject 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. + * Check if the value (after conversion to dpt) will differ from current value of the group object and update if necessary. + * Use this method only, when the value change is relevant, otherwise valueNoSend(const KNXValue&, const Dpt&) will do the same (without overhead for comparing) * @param value the value the group object is set to * @param type the datapoint type used for the conversion. * From 0b33f0d67e57390a64c9f3b70c4bcf09099f3e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Sun, 7 Jan 2024 20:18:02 +0100 Subject: [PATCH 4/4] Fix Error Detected in Pipeline: Build knx-demo --- src/knx/group_object.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index 3ade6c5..b7c74d8 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -291,7 +291,8 @@ bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type) else { // convert new value to given dtp - uint8_t newData[_dataLength] = {0}; + uint8_t newData[_dataLength]; + memset(newData, 0, _dataLength); KNX_Encode_Value(value, newData, _dataLength, type); // check for change in converted value / update value on change only