From 7e440ae816c6115f0d91fc9396f3e949e95ebd69 Mon Sep 17 00:00:00 2001 From: nanosonde Date: Tue, 24 Apr 2018 11:45:57 +0200 Subject: [PATCH 1/6] Fix handling of PropDescRead for special case PID=0. Answer with found property id for given property index. --- bau57B0.cpp | 5 +++-- interface_object.cpp | 5 +++-- interface_object.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bau57B0.cpp b/bau57B0.cpp index cc34d9c..5f26fdf 100644 --- a/bau57B0.cpp +++ b/bau57B0.cpp @@ -181,15 +181,16 @@ void Bau57B0::userMemoryWriteIndication(Priority priority, HopCountType hopType, void Bau57B0::propertyDescriptionReadIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex, uint8_t propertyId, uint8_t propertyIndex) { + uint8_t pid = propertyId; bool writeEnable = false; uint8_t type = 0; uint16_t numberOfElements = 0; uint8_t access = 0; InterfaceObject* obj = getInterfaceObject(objectIndex); if (obj) - obj->readPropertyDescription(propertyId, propertyIndex, writeEnable, type, numberOfElements, access); + obj->readPropertyDescription(pid, propertyIndex, writeEnable, type, numberOfElements, access); - _appLayer.propertyDescriptionReadResponse(AckRequested, priority, hopType, asap, objectIndex, propertyId, propertyIndex, + _appLayer.propertyDescriptionReadResponse(AckRequested, priority, hopType, asap, objectIndex, pid, propertyIndex, writeEnable, type, numberOfElements, access); } diff --git a/interface_object.cpp b/interface_object.cpp index e3db33a..1f4cb9b 100644 --- a/interface_object.cpp +++ b/interface_object.cpp @@ -1,6 +1,6 @@ #include "interface_object.h" -void InterfaceObject::readPropertyDescription(uint8_t propertyId, uint8_t& propertyIndex, bool& writeEnable, uint8_t& type, uint16_t& numberOfElements, uint8_t& access) +void InterfaceObject::readPropertyDescription(uint8_t& propertyId, uint8_t& propertyIndex, bool& writeEnable, uint8_t& type, uint16_t& numberOfElements, uint8_t& access) { PropertyDescription* descriptions = propertyDescriptions(); uint8_t count = propertyCount(); @@ -22,7 +22,7 @@ void InterfaceObject::readPropertyDescription(uint8_t propertyId, uint8_t& prope } else { - if (propertyIndex > 0 && propertyIndex < count) + if (propertyIndex >= 0 && propertyIndex < count) { desc = &descriptions[propertyIndex]; } @@ -30,6 +30,7 @@ void InterfaceObject::readPropertyDescription(uint8_t propertyId, uint8_t& prope if (desc != nullptr) { + propertyId = desc->Id; writeEnable = desc->WriteEnable; type = desc->Type; numberOfElements = desc->MaxElements; diff --git a/interface_object.h b/interface_object.h index 826953f..277b1d8 100644 --- a/interface_object.h +++ b/interface_object.h @@ -57,7 +57,7 @@ public: virtual void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data) = 0; virtual void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count) = 0; virtual uint8_t propertySize(PropertyID id) = 0; - void readPropertyDescription(uint8_t propertyId, uint8_t& propertyIndex, bool& writeEnable, uint8_t& type, uint16_t& numberOfElements, uint8_t& access); + void readPropertyDescription(uint8_t& propertyId, uint8_t& propertyIndex, bool& writeEnable, uint8_t& type, uint16_t& numberOfElements, uint8_t& access); protected: virtual uint8_t propertyCount() = 0; virtual PropertyDescription* propertyDescriptions() = 0; From 2a4473c5ff758de3cc8e611c8d6be057dadab3d5 Mon Sep 17 00:00:00 2001 From: nanosonde Date: Tue, 24 Apr 2018 11:49:04 +0200 Subject: [PATCH 2/6] Add mandatory property description PID_OBJECT_TYPE and fix returned size for this property. --- address_table_object.cpp | 4 +++- application_program_object.cpp | 9 ++++++--- association_table_object.cpp | 1 + device_object.cpp | 7 +++++-- group_object_table_object.cpp | 4 +++- ip_parameter_object.cpp | 4 +++- table_object.cpp | 2 ++ 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/address_table_object.cpp b/address_table_object.cpp index 5630faa..a86189a 100644 --- a/address_table_object.cpp +++ b/address_table_object.cpp @@ -84,7 +84,9 @@ void AddressTableObject::beforeStateChange(LoadState& newState) _groupAddresses = (uint16_t*)_data; } -static PropertyDescription _propertyDescriptions[] = { }; +static PropertyDescription _propertyDescriptions[] = { + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, +}; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); uint8_t AddressTableObject::propertyCount() diff --git a/application_program_object.cpp b/application_program_object.cpp index d77b18c..ac4ff07 100644 --- a/application_program_object.cpp +++ b/application_program_object.cpp @@ -43,10 +43,11 @@ uint8_t ApplicationProgramObject::propertySize(PropertyID id) { switch (id) { - case PID_OBJECT_TYPE: case PID_PEI_TYPE: return 1; - case PID_PROG_VERSION: + case PID_OBJECT_TYPE: + return 2; + case PID_PROG_VERSION: return 5; } return TableObject::propertySize(id); @@ -86,7 +87,9 @@ uint8_t* ApplicationProgramObject::restore(uint8_t* buffer) return TableObject::restore(buffer); } -static PropertyDescription _propertyDescriptions[] = {}; +static PropertyDescription _propertyDescriptions[] = { + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, +}; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); uint8_t ApplicationProgramObject::propertyCount() diff --git a/association_table_object.cpp b/association_table_object.cpp index e575377..6dee6d7 100644 --- a/association_table_object.cpp +++ b/association_table_object.cpp @@ -70,6 +70,7 @@ void AssociationTableObject::beforeStateChange(LoadState& newState) static PropertyDescription _propertyDescriptions[] = { + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, { PID_TABLE, false, PDT_GENERIC_02, 254, ReadLv3 | WriteLv0 }, }; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); diff --git a/device_object.cpp b/device_object.cpp index 34ea7ff..eb1a834 100644 --- a/device_object.cpp +++ b/device_object.cpp @@ -83,13 +83,13 @@ uint8_t DeviceObject::propertySize(PropertyID id) { switch (id) { - case PID_OBJECT_TYPE: case PID_DEVICE_CONTROL: case PID_ROUTING_COUNT: case PID_PROG_MODE: case PID_SUBNET_ADDR: case PID_DEVICE_ADDR: return 1; + case PID_OBJECT_TYPE: case PID_MANUFACTURER_ID: case PID_VERSION: case PID_DEVICE_DESCRIPTOR: @@ -254,7 +254,10 @@ void DeviceObject::version(uint16_t value) _version = value; } -static PropertyDescription _propertyDescriptions[] = {}; +static PropertyDescription _propertyDescriptions[] = { + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, + { PID_SERIAL_NUMBER, false, PDT_GENERIC_06, 1, ReadLv3 | WriteLv0 }, +}; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); uint8_t DeviceObject::propertyCount() diff --git a/group_object_table_object.cpp b/group_object_table_object.cpp index d41d30a..64a6fd4 100644 --- a/group_object_table_object.cpp +++ b/group_object_table_object.cpp @@ -120,7 +120,9 @@ bool GroupObjectTableObject::initGroupObjects() return true; } -static PropertyDescription _propertyDescriptions[] = { }; +static PropertyDescription _propertyDescriptions[] = { + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, +}; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); uint8_t GroupObjectTableObject::propertyCount() diff --git a/ip_parameter_object.cpp b/ip_parameter_object.cpp index 547904d..47d4af9 100644 --- a/ip_parameter_object.cpp +++ b/ip_parameter_object.cpp @@ -304,7 +304,9 @@ void IpParameterObject::additionalLoadControls(uint8_t* data) return; } -static PropertyDescription _propertyDescriptions[] = { }; +static PropertyDescription _propertyDescriptions[] = { + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, +}; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); uint8_t IpParameterObject::propertyCount() diff --git a/table_object.cpp b/table_object.cpp index 57fbb3f..85dad9b 100644 --- a/table_object.cpp +++ b/table_object.cpp @@ -52,6 +52,8 @@ uint8_t TableObject::propertySize(PropertyID id) return 4; case PID_ERROR_CODE: return 1; + case PID_OBJECT_TYPE: + return 2; } return 0; } From daf1cabedfefd2f3896976e59b20dd156e74426d Mon Sep 17 00:00:00 2001 From: nanosonde Date: Tue, 24 Apr 2018 16:32:57 +0200 Subject: [PATCH 3/6] Fix PropDescRead and add comments from spec --- interface_object.cpp | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/interface_object.cpp b/interface_object.cpp index 1f4cb9b..1b71adf 100644 --- a/interface_object.cpp +++ b/interface_object.cpp @@ -6,12 +6,24 @@ void InterfaceObject::readPropertyDescription(uint8_t& propertyId, uint8_t& prop uint8_t count = propertyCount(); PropertyDescription* desc = nullptr; + + // from KNX spec. 03.03.07 Application Layer (page 56) - 3.4.3.3 A_PropertyDescription_Read-service + // [...] and the Property of the object shall be addressed with + // a property_id OR with a property_index.The property_index shall be used ONLY if the property_id is zero. + // [...] + // If the property_id in the A_PropertyDescription_Read - PDU is NOT zero, then the field property_index + // shall be IGNORED; the remote application process shall use the indicated property_id to access the Property + // description.The property_index in the A_PropertyDescription_Response - PDU shall in this case be : + // - the correct value of the Property index of the addressed Property, or + // - the value of the field property_index of the received A_PropertyDescription_Read - PDU. + // For new implementations the property_index shall contain the correct value of the addressed Property. + // If the remote application process has a problem, e.g.Interface Object or Property does not exist, then the + // max_nr_of_elem of the A_PropertyDescription_Response - PDU shall be zero. if (propertyId != 0) - { - - for (uint8_t i = 0; i < count; i++) + { + for (uint8_t i = 0; i < count; i++) { - PropertyDescription d = descriptions[propertyIndex]; + PropertyDescription d = descriptions[i]; if (d.Id != propertyId) continue; @@ -22,18 +34,26 @@ void InterfaceObject::readPropertyDescription(uint8_t& propertyId, uint8_t& prop } else { + // If the property_id in the A_PropertyDescription_Read - PDU is zero, the remote application process shall + // use the indicated property_index to access the Property description.The property_index in the + // A_PropertyDescription_Response - PDU shall be the value of the field property_index of the received + // A_PropertyDescription_Read - PDU if (propertyIndex >= 0 && propertyIndex < count) { desc = &descriptions[propertyIndex]; } } - if (desc != nullptr) - { - propertyId = desc->Id; - writeEnable = desc->WriteEnable; - type = desc->Type; - numberOfElements = desc->MaxElements; - access = desc->Access; - } + if (desc != nullptr) + { + propertyId = desc->Id; + writeEnable = desc->WriteEnable; + type = desc->Type; + numberOfElements = desc->MaxElements; + access = desc->Access; + } + else + { + numberOfElements = 0; + } } \ No newline at end of file From d315aee70e849db0818b67a93927638cd7f049c8 Mon Sep 17 00:00:00 2001 From: nanosonde Date: Wed, 25 Apr 2018 23:20:00 +0200 Subject: [PATCH 4/6] Cosmetic changes. Fix whitespace and "{". --- address_table_object.cpp | 11 ++++--- application_program_object.cpp | 11 ++++--- association_table_object.cpp | 8 ++--- bau57B0.cpp | 24 +++++++------- device_object.cpp | 11 ++++--- group_object_table_object.cpp | 11 ++++--- interface_object.cpp | 58 ++++++++++++++-------------------- ip_parameter_object.cpp | 7 ++-- table_object.cpp | 6 ++-- 9 files changed, 70 insertions(+), 77 deletions(-) diff --git a/address_table_object.cpp b/address_table_object.cpp index a86189a..407be44 100644 --- a/address_table_object.cpp +++ b/address_table_object.cpp @@ -35,7 +35,7 @@ uint16_t AddressTableObject::getGa(uint16_t tsap) { if (loadState() != LS_LOADED || tsap > entryCount() ) return 0; - + return ntohs(_groupAddresses[tsap]); } @@ -58,9 +58,9 @@ uint8_t* AddressTableObject::save(uint8_t* buffer) uint8_t* AddressTableObject::restore(uint8_t* buffer) { buffer = TableObject::restore(buffer); - + _groupAddresses = (uint16_t*)_data; - + return buffer; } @@ -84,8 +84,9 @@ void AddressTableObject::beforeStateChange(LoadState& newState) _groupAddresses = (uint16_t*)_data; } -static PropertyDescription _propertyDescriptions[] = { - { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, +static PropertyDescription _propertyDescriptions[] = +{ + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 } }; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); diff --git a/application_program_object.cpp b/application_program_object.cpp index ac4ff07..9753045 100644 --- a/application_program_object.cpp +++ b/application_program_object.cpp @@ -45,8 +45,8 @@ uint8_t ApplicationProgramObject::propertySize(PropertyID id) { case PID_PEI_TYPE: return 1; - case PID_OBJECT_TYPE: - return 2; + case PID_OBJECT_TYPE: + return 2; case PID_PROG_VERSION: return 5; } @@ -76,7 +76,7 @@ uint32_t ApplicationProgramObject::getInt(uint32_t addr) uint8_t* ApplicationProgramObject::save(uint8_t* buffer) { buffer = pushByteArray(_programVersion, 5, buffer); - + return TableObject::save(buffer); } @@ -87,8 +87,9 @@ uint8_t* ApplicationProgramObject::restore(uint8_t* buffer) return TableObject::restore(buffer); } -static PropertyDescription _propertyDescriptions[] = { - { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, +static PropertyDescription _propertyDescriptions[] = +{ + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 } }; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); diff --git a/association_table_object.cpp b/association_table_object.cpp index 6dee6d7..a6e1dd5 100644 --- a/association_table_object.cpp +++ b/association_table_object.cpp @@ -68,10 +68,10 @@ void AssociationTableObject::beforeStateChange(LoadState& newState) _tableData = (uint16_t*)_data; } -static PropertyDescription _propertyDescriptions[] = -{ - { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, - { PID_TABLE, false, PDT_GENERIC_02, 254, ReadLv3 | WriteLv0 }, +static PropertyDescription _propertyDescriptions[] = +{ + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, + { PID_TABLE, false, PDT_GENERIC_02, 254, ReadLv3 | WriteLv0 } }; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); diff --git a/bau57B0.cpp b/bau57B0.cpp index 5f26fdf..d31f280 100644 --- a/bau57B0.cpp +++ b/bau57B0.cpp @@ -5,10 +5,10 @@ using namespace std; -Bau57B0::Bau57B0(Platform& platform): _memoryReference((uint8_t*)&_deviceObj), _memory(platform), _addrTable(_memoryReference), +Bau57B0::Bau57B0(Platform& platform): _memoryReference((uint8_t*)&_deviceObj), _memory(platform), _addrTable(_memoryReference), _assocTable(_memoryReference), _groupObjTable(_memoryReference), _appProgram(_memoryReference), _ipParameters(_deviceObj, platform), _platform(platform), _appLayer(_assocTable, *this), - _transLayer(_appLayer, _addrTable, _platform), _netLayer(_transLayer), + _transLayer(_appLayer, _addrTable, _platform), _netLayer(_transLayer), _dlLayer(_deviceObj, _addrTable, _ipParameters, _netLayer, _platform) { _appLayer.transportLayer(_transLayer); @@ -50,7 +50,7 @@ void Bau57B0::sendNextGroupTelegram() if (flag == WriteRequest) { uint8_t* data = go.valueRef(); - _appLayer.groupValueWriteRequest(AckRequested, asap, go.priority(), NetworkLayerParameter, data, + _appLayer.groupValueWriteRequest(AckRequested, asap, go.priority(), NetworkLayerParameter, data, go.sizeInTelegram()); } else @@ -121,7 +121,7 @@ void Bau57B0::enabled(bool value) _dlLayer.enabled(value); } -void Bau57B0::memoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number, +void Bau57B0::memoryWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number, uint16_t memoryAddress, uint8_t * data) { memcpy(_memoryReference + memoryAddress, data, number); @@ -131,7 +131,7 @@ void Bau57B0::memoryWriteIndication(Priority priority, HopCountType hopType, uin memoryReadIndication(priority, hopType, asap, number, memoryAddress); } -void Bau57B0::memoryReadIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number, +void Bau57B0::memoryReadIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t number, uint16_t memoryAddress) { _appLayer.memoryReadResponse(AckRequested, priority, hopType, asap, number, memoryAddress, @@ -142,7 +142,7 @@ void Bau57B0::deviceDescriptorReadIndication(Priority priority, HopCountType hop { if (descriptorType != 0) descriptorType = 0x3f; - + uint8_t descriptor[] = { 0x57, 0xb0 }; _appLayer.deviceDescriptorReadResponse(AckRequested, priority, hopType, asap, descriptorType, descriptor); @@ -178,10 +178,10 @@ void Bau57B0::userMemoryWriteIndication(Priority priority, HopCountType hopType, userMemoryReadIndication(priority, hopType, asap, number, memoryAddress); } -void Bau57B0::propertyDescriptionReadIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex, +void Bau57B0::propertyDescriptionReadIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex, uint8_t propertyId, uint8_t propertyIndex) { - uint8_t pid = propertyId; + uint8_t pid = propertyId; bool writeEnable = false; uint8_t type = 0; uint16_t numberOfElements = 0; @@ -194,7 +194,7 @@ void Bau57B0::propertyDescriptionReadIndication(Priority priority, HopCountType writeEnable, type, numberOfElements, access); } -void Bau57B0::propertyValueWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex, +void Bau57B0::propertyValueWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex, uint8_t propertyId, uint8_t numberOfElements, uint16_t startIndex, uint8_t* data, uint8_t length) { InterfaceObject* obj = getInterfaceObject(objectIndex); @@ -216,7 +216,7 @@ void Bau57B0::propertyValueReadIndication(Priority priority, HopCountType hopTyp } else elementCount = 0; - + uint8_t data[size]; if(obj) obj->readProperty((PropertyID)propertyId, startIndex, elementCount, data); @@ -261,11 +261,11 @@ void Bau57B0::groupValueReadIndication(uint16_t asap, Priority priority, HopCoun _appLayer.groupValueReadResponse(AckRequested, asap, priority, hopType, data, go.sizeInTelegram()); } -void Bau57B0::groupValueReadAppLayerConfirm(uint16_t asap, Priority priority, HopCountType hopType, uint8_t* data, +void Bau57B0::groupValueReadAppLayerConfirm(uint16_t asap, Priority priority, HopCountType hopType, uint8_t* data, uint8_t dataLength) { GroupObject& go = _groupObjTable.get(asap); - + if (!go.communicationEnable() || !go.responseUpdateEnable()) return; diff --git a/device_object.cpp b/device_object.cpp index eb1a834..585a657 100644 --- a/device_object.cpp +++ b/device_object.cpp @@ -48,10 +48,10 @@ void DeviceObject::readProperty(PropertyID propertyId, uint32_t start, uint32_t& uint32_t ifObjs[] = { 6, // length OT_DEVICE, OT_ADDR_TABLE, OT_ASSOC_TABLE, OT_GRP_OBJ_TABLE, OT_APPLICATION_PROG, OT_IP_PARAMETER}; - + for (uint32_t i = start; i < (ifObjs[0] + 1) && i < count; i++) pushInt(ifObjs[i], data); - + break; } case PID_DEVICE_DESCRIPTOR: @@ -254,9 +254,10 @@ void DeviceObject::version(uint16_t value) _version = value; } -static PropertyDescription _propertyDescriptions[] = { - { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, - { PID_SERIAL_NUMBER, false, PDT_GENERIC_06, 1, ReadLv3 | WriteLv0 }, +static PropertyDescription _propertyDescriptions[] = +{ + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, + { PID_SERIAL_NUMBER, false, PDT_GENERIC_06, 1, ReadLv3 | WriteLv0 } }; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); diff --git a/group_object_table_object.cpp b/group_object_table_object.cpp index 64a6fd4..21182f2 100644 --- a/group_object_table_object.cpp +++ b/group_object_table_object.cpp @@ -47,10 +47,10 @@ uint8_t* GroupObjectTableObject::save(uint8_t* buffer) uint8_t* GroupObjectTableObject::restore(uint8_t* buffer) { buffer = TableObject::restore(buffer); - + _tableData = (uint16_t*)_data; initGroupObjects(); - + return buffer; } @@ -116,12 +116,13 @@ bool GroupObjectTableObject::initGroupObjects() if (go._dataLength != go.goSize()) return false; } - + return true; } -static PropertyDescription _propertyDescriptions[] = { - { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, +static PropertyDescription _propertyDescriptions[] = +{ + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 } }; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); diff --git a/interface_object.cpp b/interface_object.cpp index 1b71adf..6316d33 100644 --- a/interface_object.cpp +++ b/interface_object.cpp @@ -4,29 +4,19 @@ void InterfaceObject::readPropertyDescription(uint8_t& propertyId, uint8_t& prop { PropertyDescription* descriptions = propertyDescriptions(); uint8_t count = propertyCount(); - + PropertyDescription* desc = nullptr; - - // from KNX spec. 03.03.07 Application Layer (page 56) - 3.4.3.3 A_PropertyDescription_Read-service - // [...] and the Property of the object shall be addressed with - // a property_id OR with a property_index.The property_index shall be used ONLY if the property_id is zero. - // [...] - // If the property_id in the A_PropertyDescription_Read - PDU is NOT zero, then the field property_index - // shall be IGNORED; the remote application process shall use the indicated property_id to access the Property - // description.The property_index in the A_PropertyDescription_Response - PDU shall in this case be : - // - the correct value of the Property index of the addressed Property, or - // - the value of the field property_index of the received A_PropertyDescription_Read - PDU. - // For new implementations the property_index shall contain the correct value of the addressed Property. - // If the remote application process has a problem, e.g.Interface Object or Property does not exist, then the - // max_nr_of_elem of the A_PropertyDescription_Response - PDU shall be zero. + + // from KNX spec. 03.03.07 Application Layer (page 56) - 3.4.3.3 A_PropertyDescription_Read-service + // Summary: either propertyId OR propertyIndex, but not both at the same time if (propertyId != 0) - { - for (uint8_t i = 0; i < count; i++) + { + for (uint8_t i = 0; i < count; i++) { PropertyDescription d = descriptions[i]; if (d.Id != propertyId) continue; - + desc = &d; propertyIndex = i; break; @@ -34,26 +24,24 @@ void InterfaceObject::readPropertyDescription(uint8_t& propertyId, uint8_t& prop } else { - // If the property_id in the A_PropertyDescription_Read - PDU is zero, the remote application process shall - // use the indicated property_index to access the Property description.The property_index in the - // A_PropertyDescription_Response - PDU shall be the value of the field property_index of the received - // A_PropertyDescription_Read - PDU - if (propertyIndex >= 0 && propertyIndex < count) + // If propertyId is zero, propertyIndex shall be used. + // Response: propertyIndex of received A_PropertyDescription_Read + if (propertyIndex >= 0 && propertyIndex < count) { desc = &descriptions[propertyIndex]; } } - - if (desc != nullptr) - { - propertyId = desc->Id; - writeEnable = desc->WriteEnable; - type = desc->Type; - numberOfElements = desc->MaxElements; - access = desc->Access; - } - else - { - numberOfElements = 0; - } + + if (desc != nullptr) + { + propertyId = desc->Id; + writeEnable = desc->WriteEnable; + type = desc->Type; + numberOfElements = desc->MaxElements; + access = desc->Access; + } + else + { + numberOfElements = 0; + } } \ No newline at end of file diff --git a/ip_parameter_object.cpp b/ip_parameter_object.cpp index 47d4af9..a989d7c 100644 --- a/ip_parameter_object.cpp +++ b/ip_parameter_object.cpp @@ -181,7 +181,7 @@ uint32_t IpParameterObject::multicastAddress() const { if (_multicastAddress == 0) return DEFAULT_MULTICAST_ADDR; - + return _multicastAddress; } @@ -304,8 +304,9 @@ void IpParameterObject::additionalLoadControls(uint8_t* data) return; } -static PropertyDescription _propertyDescriptions[] = { - { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, +static PropertyDescription _propertyDescriptions[] = +{ + { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 } }; static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); diff --git a/table_object.cpp b/table_object.cpp index 85dad9b..8b25fee 100644 --- a/table_object.cpp +++ b/table_object.cpp @@ -52,8 +52,8 @@ uint8_t TableObject::propertySize(PropertyID id) return 4; case PID_ERROR_CODE: return 1; - case PID_OBJECT_TYPE: - return 2; + case PID_OBJECT_TYPE: + return 2; } return 0; } @@ -84,7 +84,7 @@ uint8_t* TableObject::save(uint8_t* buffer) buffer = pushByte(_errorCode, buffer); buffer = pushInt(_size, buffer); buffer = pushByteArray(_data, _size, buffer); - + return buffer; } From 7c7d0d0b5bd0a7660333c0c4ceeb7368f04e7aa4 Mon Sep 17 00:00:00 2001 From: nanosonde Date: Wed, 25 Apr 2018 23:23:42 +0200 Subject: [PATCH 5/6] Remove unnecessary check --- interface_object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface_object.cpp b/interface_object.cpp index 6316d33..53fa85e 100644 --- a/interface_object.cpp +++ b/interface_object.cpp @@ -26,7 +26,7 @@ void InterfaceObject::readPropertyDescription(uint8_t& propertyId, uint8_t& prop { // If propertyId is zero, propertyIndex shall be used. // Response: propertyIndex of received A_PropertyDescription_Read - if (propertyIndex >= 0 && propertyIndex < count) + if (propertyIndex < count) { desc = &descriptions[propertyIndex]; } From f420c6dc21929dba72305d4db8b3556367e140cc Mon Sep 17 00:00:00 2001 From: nanosonde Date: Wed, 25 Apr 2018 23:25:15 +0200 Subject: [PATCH 6/6] Remove unnecessary clearing of numberOfElements --- interface_object.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/interface_object.cpp b/interface_object.cpp index 53fa85e..a82e430 100644 --- a/interface_object.cpp +++ b/interface_object.cpp @@ -40,8 +40,4 @@ void InterfaceObject::readPropertyDescription(uint8_t& propertyId, uint8_t& prop numberOfElements = desc->MaxElements; access = desc->Access; } - else - { - numberOfElements = 0; - } } \ No newline at end of file