Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sending Wrong Values on Failed Conversion to DPT (Draft for Redesign in devel) #301

Draft
wants to merge 4 commits into
base: devel
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions src/knx/group_object/group_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<class DPT> bool _valueNoSend(const DPT& value);

};

bool operator==(const GroupObject& lhs, const GroupObject& rhs);

template<class DPT> void GroupObject::value(const DPT& value)
{
valueNoSend(value);
objectWritten();
if (_valueNoSend(value))
{
// write on successful conversion/setting value only
objectWritten();
}
}

template<class DPT> DPT GroupObject::value()
Expand All @@ -508,14 +523,24 @@ namespace Knx
}

template<class DPT> void GroupObject::valueNoSend(const DPT& value)
{
// ignore actual updating TODO check replacing valueNoSend with _valueNoSend
_valueNoSend(value);
}

template<class DPT> bool GroupObject::_valueNoSend(const KNXValue& value)
{
if (value.size() != sizeCode())
return;

if (_uninitialized)
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);

value.encode(_data);
return encodingDone;
}

template<class DPT> bool GroupObject::valueNoSendCompare(const DPT& value)
Expand All @@ -526,15 +551,22 @@ namespace Knx
if (_uninitialized)
{
// always set first value
this->valueNoSend(value);
return true;
return _valueNoSend(value);
}
else
{
// convert new value to given dtp
// convert new value to given DPT
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);
Expand Down
Loading