From 8e2facbb9d2654ef615ca6820c97d15f46906502 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 1/4] (Prepare for devel) Fix: Do NOT Send when Updating KO Failed on Value Conversion - Change Signature of all Set-Methods --- src/knx/group_object/group_object.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/knx/group_object/group_object.h b/src/knx/group_object/group_object.h index 4caa44c9..09fa81ac 100644 --- a/src/knx/group_object/group_object.h +++ b/src/knx/group_object/group_object.h @@ -534,7 +534,15 @@ namespace Knx // convert new value to given dtp uint8_t newData[_dataLength]; memset(newData, 0, _dataLength); + + const bool encodingDone = true; // TODO FIXME for devel! value.encode needs success indicator value.encode(newData); + 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 a42d5713565fcfe059915356a30328f4f9c85fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Sat, 2 Nov 2024 23:00:27 +0100 Subject: [PATCH 2/4] Fix: Typo --- src/knx/group_object/group_object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/knx/group_object/group_object.h b/src/knx/group_object/group_object.h index 09fa81ac..b9b0eaf0 100644 --- a/src/knx/group_object/group_object.h +++ b/src/knx/group_object/group_object.h @@ -531,7 +531,7 @@ namespace Knx } else { - // convert new value to given dtp + // convert new value to given DPT uint8_t newData[_dataLength]; memset(newData, 0, _dataLength); From a7d344fae931e4f27a96eafcdb13cadbe898eb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Sat, 2 Nov 2024 23:10:13 +0100 Subject: [PATCH 3/4] (Prepare for devel) Fix `valueNoSend`: Do NOT End KO Uninitialized when Value Conversion Failed --- src/knx/group_object/group_object.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/knx/group_object/group_object.h b/src/knx/group_object/group_object.h index b9b0eaf0..7acce23a 100644 --- a/src/knx/group_object/group_object.h +++ b/src/knx/group_object/group_object.h @@ -512,10 +512,12 @@ namespace Knx if (value.size() != sizeCode()) return; - if (_uninitialized) - commFlag(Ok); - + const bool encodingDone = true; // TODO FIXME for devel! value.encode needs success indicator value.encode(_data); + + // initialize on succesful conversion only + if (encodingDone && _uninitialized) + commFlag(Ok); } template bool GroupObject::valueNoSendCompare(const DPT& value) From 9ee6e11ca5dc8426b70fa6331dedd32e6a2b14a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Sat, 2 Nov 2024 23:31:08 +0100 Subject: [PATCH 4/4] (Prepare for devel) Fix: Do NOT Send when Updating KO Failed on Value Conversion --- src/knx/group_object/group_object.h | 30 +++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/knx/group_object/group_object.h b/src/knx/group_object/group_object.h index 7acce23a..b460c09c 100644 --- a/src/knx/group_object/group_object.h +++ b/src/knx/group_object/group_object.h @@ -478,14 +478,29 @@ namespace Knx ComFlag _commFlag : 7; uint8_t* _data = 0; uint8_t _dataLength = 0; + + /** + * 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. + */ + template bool _valueNoSend(const DPT& value); + }; bool operator==(const GroupObject& lhs, const GroupObject& rhs); template void GroupObject::value(const DPT& value) { - valueNoSend(value); - objectWritten(); + if (_valueNoSend(value)) + { + // write on successful conversion/setting value only + objectWritten(); + } } template DPT GroupObject::value() @@ -508,6 +523,12 @@ namespace Knx } template void GroupObject::valueNoSend(const DPT& value) + { + // ignore actual updating TODO check replacing valueNoSend with _valueNoSend + _valueNoSend(value); + } + + template bool GroupObject::_valueNoSend(const KNXValue& value) { if (value.size() != sizeCode()) return; @@ -518,6 +539,8 @@ namespace Knx // initialize on succesful conversion only if (encodingDone && _uninitialized) commFlag(Ok); + + return encodingDone; } template bool GroupObject::valueNoSendCompare(const DPT& value) @@ -528,8 +551,7 @@ namespace Knx if (_uninitialized) { // always set first value - this->valueNoSend(value); - return true; + return _valueNoSend(value); } else {