mirror of
https://github.com/thelsing/knx.git
synced 2024-12-18 19:08:18 +01:00
String \0 terminated in group objects (#25)
* String \0 terminated in group objects * Remove copy constructor, fix bugs in setting buffer to 0 * Remove copy constructor in GroupObject
This commit is contained in:
parent
12fb67cc63
commit
093ae425b0
@ -517,15 +517,13 @@ int busValueToAccess(const uint8_t* payload, size_t payload_length, const Dpt& d
|
|||||||
int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(14);
|
ASSERT_PAYLOAD(14);
|
||||||
char strValue[15];
|
|
||||||
strValue[14] = '\0';
|
|
||||||
for (int n = 0; n < 14; ++n)
|
for (int n = 0; n < 14; ++n)
|
||||||
{
|
{
|
||||||
strValue[n] = signed8FromPayload(payload, n);
|
auto value = signed8FromPayload(payload, n);
|
||||||
if (!datatype.subGroup && (strValue[n] & 0x80))
|
if (!datatype.subGroup && (value & 0x80))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
value = strValue;
|
value = (const char*) payload;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,18 +20,6 @@ GroupObject::GroupObject()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupObject::GroupObject(const GroupObject& other)
|
|
||||||
{
|
|
||||||
_data = new uint8_t[other._dataLength];
|
|
||||||
_commFlagEx = other._commFlagEx;
|
|
||||||
_dataLength = other._dataLength;
|
|
||||||
_asap = other._asap;
|
|
||||||
#ifndef SMALL_GROUPOBJECT
|
|
||||||
_updateHandler = other._updateHandler;
|
|
||||||
#endif
|
|
||||||
memcpy(_data, other._data, _dataLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
GroupObject::~GroupObject()
|
GroupObject::~GroupObject()
|
||||||
{
|
{
|
||||||
if (_data)
|
if (_data)
|
||||||
@ -119,7 +107,7 @@ size_t GroupObject::goSize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// see knxspec 3.5.1 p. 178
|
// see knxspec 3.5.1 p. 178
|
||||||
size_t GroupObject::asapValueSize(uint8_t code)
|
size_t GroupObject::asapValueSize(uint8_t code) const
|
||||||
{
|
{
|
||||||
if (code < 7)
|
if (code < 7)
|
||||||
return 0;
|
return 0;
|
||||||
@ -194,6 +182,17 @@ size_t GroupObject::sizeInTelegram()
|
|||||||
return asapValueSize(code);
|
return asapValueSize(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t GroupObject::sizeInMemory() const
|
||||||
|
{
|
||||||
|
uint8_t code = lowByte(ntohs(_table->_tableData[_asap]));
|
||||||
|
size_t result = asapValueSize(code);
|
||||||
|
if (code == 0)
|
||||||
|
return 1;
|
||||||
|
if (code == 14)
|
||||||
|
return 14 + 1;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SMALL_GROUPOBJECT
|
#ifdef SMALL_GROUPOBJECT
|
||||||
GroupObjectUpdatedHandler GroupObject::classCallback()
|
GroupObjectUpdatedHandler GroupObject::classCallback()
|
||||||
{
|
{
|
||||||
|
@ -57,10 +57,6 @@ class GroupObject
|
|||||||
* The constructor.
|
* The constructor.
|
||||||
*/
|
*/
|
||||||
GroupObject();
|
GroupObject();
|
||||||
/**
|
|
||||||
* The copy constructor.
|
|
||||||
*/
|
|
||||||
GroupObject(const GroupObject& other);
|
|
||||||
/**
|
/**
|
||||||
* The destructor.
|
* The destructor.
|
||||||
*/
|
*/
|
||||||
@ -139,6 +135,11 @@ class GroupObject
|
|||||||
* will return 0.
|
* will return 0.
|
||||||
*/
|
*/
|
||||||
size_t sizeInTelegram();
|
size_t sizeInTelegram();
|
||||||
|
/**
|
||||||
|
* returns the size of the group object in the heap memory of the group object. The function returns the same value as goSize(),
|
||||||
|
* exept fot the 14 byte string type to reserve one byte of a \0 terminator character.
|
||||||
|
*/
|
||||||
|
size_t sizeInMemory() const;
|
||||||
/**
|
/**
|
||||||
* returns the pointer to the value of the group object. This can be used if a datapoint type is not supported or if you want do
|
* returns the pointer to the value of the group object. This can be used if a datapoint type is not supported or if you want do
|
||||||
* your own conversion.
|
* your own conversion.
|
||||||
@ -274,7 +275,7 @@ class GroupObject
|
|||||||
static GroupObjectUpdatedHandler _updateHandlerStatic;
|
static GroupObjectUpdatedHandler _updateHandlerStatic;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t asapValueSize(uint8_t code);
|
size_t asapValueSize(uint8_t code) const;
|
||||||
size_t goSize();
|
size_t goSize();
|
||||||
uint16_t _asap = 0;
|
uint16_t _asap = 0;
|
||||||
ComFlagEx _commFlagEx;
|
ComFlagEx _commFlagEx;
|
||||||
|
@ -109,8 +109,9 @@ bool GroupObjectTableObject::initGroupObjects()
|
|||||||
go._table = this;
|
go._table = this;
|
||||||
|
|
||||||
go._dataLength = go.goSize();
|
go._dataLength = go.goSize();
|
||||||
go._data = new uint8_t[go._dataLength];
|
size_t sizeInMemory = go.sizeInMemory();
|
||||||
memset(go._data, 0, go._dataLength);
|
go._data = new uint8_t[sizeInMemory];
|
||||||
|
memset(go._data, 0, sizeInMemory);
|
||||||
|
|
||||||
if (go.valueReadOnInit())
|
if (go.valueReadOnInit())
|
||||||
go.requestObjectRead();
|
go.requestObjectRead();
|
||||||
|
Loading…
Reference in New Issue
Block a user