From 9a7b6a5e80b87df50451d7d5a17933f0465ad3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Fri, 1 Nov 2024 19:28:25 +0100 Subject: [PATCH 1/8] Fix `valueNoSendCompare`: DPT Conversion Fail Resulted in Setting KO to 0 --- src/knx/group_object.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index 5a9ad28..d600bdc 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -301,7 +301,13 @@ bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type) // convert new value to given dtp uint8_t newData[_dataLength]; memset(newData, 0, _dataLength); - KNX_Encode_Value(value, newData, _dataLength, type); + const bool encodingDone = KNX_Encode_Value(value, newData, _dataLength, type); + if (!encodingDone) + { + // value conversion to DPT failed + // do NOT update the value of the KO! + return false; + } // check for change in converted value / update value on change only const bool dataChanged = memcmp(_data, newData, _dataLength); From 3de8903b5259a6f53a637aa49054093f27e9058b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Fri, 1 Nov 2024 19:29:16 +0100 Subject: [PATCH 2/8] Fix: Typo --- 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 d600bdc..21dce73 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -298,7 +298,7 @@ bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type) } else { - // convert new value to given dtp + // convert new value to given DPT uint8_t newData[_dataLength]; memset(newData, 0, _dataLength); const bool encodingDone = KNX_Encode_Value(value, newData, _dataLength, type); From 483d868dac7e0998a39edd606ef351ff987f8c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Fri, 1 Nov 2024 20:22:16 +0100 Subject: [PATCH 3/8] Fix `valueNoSend`: Do NOT End KO Uninitialized when Value Conversion Failed --- src/knx/group_object.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index 21dce73..e1e069b 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -282,10 +282,11 @@ void GroupObject::valueNoSend(const KNXValue& value) void GroupObject::valueNoSend(const KNXValue& value, const Dpt& type) { - if (_commFlagEx.uninitialized) - commFlag(Ok); + const bool encodingDone = KNX_Encode_Value(value, _data, _dataLength, type); - KNX_Encode_Value(value, _data, _dataLength, type); + // initialize on succesful conversion only + if (encodingDone && _commFlagEx.uninitialized) + commFlag(Ok); } bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type) From b8f914c3587ca9e0c310c1e6379b7f19c783d7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Fri, 1 Nov 2024 20:44:51 +0100 Subject: [PATCH 4/8] Fix: Do NOT Send when Updating KO Failed on Value Conversion --- src/knx/group_object.cpp | 18 ++++++++++++++---- src/knx/group_object.h | 12 ++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index e1e069b..3865d4a 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -226,8 +226,11 @@ GroupObjectUpdatedHandler GroupObject::callback() void GroupObject::value(const KNXValue& value, const Dpt& type) { - valueNoSend(value, type); - objectWritten(); + if (_valueNoSend(value, type)) + { + // write on successful conversion/setting value only + objectWritten(); + } } @@ -281,12 +284,20 @@ void GroupObject::valueNoSend(const KNXValue& value) #endif void GroupObject::valueNoSend(const KNXValue& value, const Dpt& type) +{ + // ignore actual updating TODO check replacing valueNoSend with _valueNoSend + _valueNoSend(value, type); +} + +bool GroupObject::_valueNoSend(const KNXValue& value, const Dpt& type) { const bool encodingDone = KNX_Encode_Value(value, _data, _dataLength, type); // initialize on succesful conversion only if (encodingDone && _commFlagEx.uninitialized) commFlag(Ok); + + return encodingDone; } bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type) @@ -294,8 +305,7 @@ bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type) if (_commFlagEx.uninitialized) { // always set first value - this->valueNoSend(value, type); - return true; + return _valueNoSend(value, type); } else { diff --git a/src/knx/group_object.h b/src/knx/group_object.h index 02bd0c3..80133a0 100644 --- a/src/knx/group_object.h +++ b/src/knx/group_object.h @@ -284,4 +284,16 @@ class GroupObject GroupObjectUpdatedHandler _updateHandler; Dpt _datapointType; #endif + + /** + * set the current value of the group object and show success. + * @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 was updated after successful conversion. + */ + bool _valueNoSend(const KNXValue& value, const Dpt& type); + }; From 6b75e1e854783c60d3eb562ba08cb7a45720cabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Fri, 8 Nov 2024 22:55:55 +0100 Subject: [PATCH 5/8] Fix Format Issue: Remove Blank Line at End --- src/knx/group_object.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/knx/group_object.h b/src/knx/group_object.h index 80133a0..eb65ea3 100644 --- a/src/knx/group_object.h +++ b/src/knx/group_object.h @@ -295,5 +295,4 @@ class GroupObject * @returns true if the value of the group object was updated after successful conversion. */ bool _valueNoSend(const KNXValue& value, const Dpt& type); - }; From a5d5b70d8708b4617f8f82151036ca28e2039359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Fri, 8 Nov 2024 23:06:02 +0100 Subject: [PATCH 6/8] Fix Format: Indention --- src/knx/group_object.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/knx/group_object.h b/src/knx/group_object.h index e2e08a7..2f1da9b 100644 --- a/src/knx/group_object.h +++ b/src/knx/group_object.h @@ -277,14 +277,14 @@ class GroupObject Dpt _datapointType; #endif - /** - * set the current value of the group object and show success. - * @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 was updated after successful conversion. - */ - bool _valueNoSend(const KNXValue& value, const Dpt& type); + /** + * set the current value of the group object and show success. + * @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 was updated after successful conversion. + */ + bool _valueNoSend(const KNXValue& value, const Dpt& type); }; From 16e644cfa893ad912c08b6a7b0ab5815ed6ec700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Fri, 8 Nov 2024 23:46:52 +0100 Subject: [PATCH 7/8] Fix Format: Indention --- src/knx/group_object.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index 3865d4a..cc5eaa3 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -333,8 +333,8 @@ bool GroupObject::valueCompare(const KNXValue& value, const Dpt& type) { if (valueNoSendCompare(value, type)) { - objectWritten(); - return true; + objectWritten(); + return true; } return false; } \ No newline at end of file From 1cb2d56de159c356e494e36b78f399f5fbcf8cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Fri, 8 Nov 2024 23:52:43 +0100 Subject: [PATCH 8/8] Group-Object Value Update: Return Indication for Success/Fail of Conversion to DPT Remove _valueNoSend(..) as valueNoSend(..) is now the same --- src/knx/group_object.cpp | 24 ++++++++++-------------- src/knx/group_object.h | 35 ++++++++++++++++------------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index cc5eaa3..6b9143d 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -224,13 +224,15 @@ GroupObjectUpdatedHandler GroupObject::callback() } #endif -void GroupObject::value(const KNXValue& value, const Dpt& type) +bool GroupObject::value(const KNXValue& value, const Dpt& type) { - if (_valueNoSend(value, type)) + if (valueNoSend(value, type)) { // write on successful conversion/setting value only objectWritten(); + return true; } + return false; } @@ -265,9 +267,9 @@ bool GroupObject::tryValue(KNXValue& value) } -void GroupObject::value(const KNXValue& value) +bool GroupObject::value(const KNXValue& value) { - this->value(value, _datapointType); + return this->value(value, _datapointType); } @@ -277,19 +279,13 @@ KNXValue GroupObject::value() } -void GroupObject::valueNoSend(const KNXValue& value) +bool GroupObject::valueNoSend(const KNXValue& value) { - valueNoSend(value, _datapointType); + return valueNoSend(value, _datapointType); } #endif -void GroupObject::valueNoSend(const KNXValue& value, const Dpt& type) -{ - // ignore actual updating TODO check replacing valueNoSend with _valueNoSend - _valueNoSend(value, type); -} - -bool GroupObject::_valueNoSend(const KNXValue& value, const Dpt& type) +bool GroupObject::valueNoSend(const KNXValue& value, const Dpt& type) { const bool encodingDone = KNX_Encode_Value(value, _data, _dataLength, type); @@ -305,7 +301,7 @@ bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type) if (_commFlagEx.uninitialized) { // always set first value - return _valueNoSend(value, type); + return valueNoSend(value, type); } else { diff --git a/src/knx/group_object.h b/src/knx/group_object.h index eb65ea3..4d7823a 100644 --- a/src/knx/group_object.h +++ b/src/knx/group_object.h @@ -171,8 +171,10 @@ class GroupObject * @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 was converted successfully to the datapoint type and the group object was updated. */ - void value(const KNXValue& value, const Dpt& type); + bool value(const KNXValue& value, const Dpt& type); /** * Check if the value (after conversion to dpt) will differ from current value of the group object and changes the state of the group object to ::WriteRequest if different. @@ -182,18 +184,20 @@ class GroupObject * * The parameters must fit the group object. Otherwise it will stay unchanged. * - * @returns true if the value of the group object has changed + * @returns true if the value of the group object has changed, false if conversion results in same value as stored in group object or failed. */ bool valueCompare(const KNXValue& value, const Dpt& type); /** - * set the current value of the group object. + * set the current value of the group object and show success. * @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 value was converted successfully to the datapoint type and the group object was updated. */ - void valueNoSend(const KNXValue& value, const Dpt& type); + bool 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. @@ -203,7 +207,7 @@ class GroupObject * * The parameters must fit the group object. Otherwise it will stay unchanged. * - * @returns true if the value of the group object has changed + * @returns true if the value of the group object has changed, false if conversion results in same value as stored in group object or failed. */ bool valueNoSendCompare(const KNXValue& value, const Dpt& type); @@ -229,15 +233,19 @@ class GroupObject * @param value the value the group object is set to * * The parameters must fit the group object and dhe datapoint type must be set with dataPointType(). Otherwise it will stay unchanged. + * + * @returns true if the value was converted successfully to the datapoint type and the group object was updated. */ - void value(const KNXValue& value); + bool value(const KNXValue& value); /** * set the current value of the group object. * @param value the value the group object is set to * - * The parameters must fit the group object and dhe datapoint type must be set with dataPointType(). Otherwise it will stay unchanged. + * The parameters must fit the group object and the datapoint type must be set with dataPointType(). Otherwise it will stay unchanged. + * + * @returns true if the value was converted successfully to the datapoint type and the group object was updated. */ - void valueNoSend(const KNXValue& value); + bool valueNoSend(const KNXValue& value); /** * set the current value of the group object. * @param value the value the group object is set to @@ -284,15 +292,4 @@ class GroupObject GroupObjectUpdatedHandler _updateHandler; Dpt _datapointType; #endif - - /** - * set the current value of the group object and show success. - * @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 was updated after successful conversion. - */ - bool _valueNoSend(const KNXValue& value, const Dpt& type); };