From dd0f7c982fb40d75e17412e983f07ec1956e4284 Mon Sep 17 00:00:00 2001 From: Anton Grey Date: Wed, 20 Apr 2022 17:01:42 +0300 Subject: [PATCH] Simple support of composed Bridged Devices. (#17506) * Simple support of composed Bridged Devices. * Restyled by clang-format * Rename ComposedEpId to ParentEndpointId. Co-authored-by: Restyled.io --- src/app/clusters/descriptor/descriptor.cpp | 16 +++++++++++++++- src/app/util/af-types.h | 5 +++++ src/app/util/af.h | 5 +++++ src/app/util/attribute-storage.cpp | 10 ++++++++-- src/app/util/attribute-storage.h | 5 ++++- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/app/clusters/descriptor/descriptor.cpp b/src/app/clusters/descriptor/descriptor.cpp index 12bae3451f260f..cb3e854704d8b9 100644 --- a/src/app/clusters/descriptor/descriptor.cpp +++ b/src/app/clusters/descriptor/descriptor.cpp @@ -79,7 +79,21 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu } else { - err = aEncoder.EncodeEmptyList(); + err = aEncoder.EncodeList([endpoint](const auto & encoder) -> CHIP_ERROR { + for (uint16_t index = 0; index < emberAfEndpointCount(); index++) + { + if (emberAfEndpointIndexIsEnabled(index)) + { + EndpointId composedEndpointId = emberAfParentEndpointFromIndex(index); + if (composedEndpointId == chip::kInvalidEndpointId || composedEndpointId != endpoint) + continue; + + ReturnErrorOnFailure(encoder.Encode(emberAfEndpointFromIndex(index))); + } + } + + return CHIP_NO_ERROR; + }); } return err; diff --git a/src/app/util/af-types.h b/src/app/util/af-types.h index de500e5edc23bf..31ba518ccfdf2a 100644 --- a/src/app/util/af-types.h +++ b/src/app/util/af-types.h @@ -415,6 +415,11 @@ struct EmberAfDefinedEndpoint * endpoint */ chip::DataVersion * dataVersions = nullptr; + + /** + * Root endpoint id for composed device type. + */ + chip::EndpointId parentEndpointId = chip::kInvalidEndpointId; }; // Cluster specific types diff --git a/src/app/util/af.h b/src/app/util/af.h index b875cc291c76bd..55e4a3aef1a681 100644 --- a/src/app/util/af.h +++ b/src/app/util/af.h @@ -287,6 +287,11 @@ extern EmberAfDefinedEndpoint emAfEndpoints[]; */ chip::EndpointId emberAfEndpointFromIndex(uint16_t index); +/** + * @brief Returns root endpoint of a composed bridged device + */ +chip::EndpointId emberAfParentEndpointFromIndex(uint16_t index); + /** * Returns the index of a given endpoint. Will return 0xFFFF if this is not a * valid endpoint id or if the endpoint is disabled. diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index afb69235dd49b5..b79e7f21563f1b 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -200,7 +200,7 @@ uint16_t emberAfGetDynamicIndexFromEndpoint(EndpointId id) EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const EmberAfEndpointType * ep, const chip::Span & dataVersionStorage, - chip::Span deviceTypeList) + chip::Span deviceTypeList, EndpointId parentEndpointId) { auto realIndex = index + FIXED_ENDPOINT_COUNT; @@ -233,7 +233,8 @@ EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const Emb emAfEndpoints[index].endpointType = ep; emAfEndpoints[index].dataVersions = dataVersionStorage.data(); // Start the endpoint off as disabled. - emAfEndpoints[index].bitmask = EMBER_AF_ENDPOINT_DISABLED; + emAfEndpoints[index].bitmask = EMBER_AF_ENDPOINT_DISABLED; + emAfEndpoints[index].parentEndpointId = parentEndpointId; emberAfSetDynamicEndpointCount(MAX_ENDPOINT_COUNT - FIXED_ENDPOINT_COUNT); @@ -984,6 +985,11 @@ EndpointId emberAfEndpointFromIndex(uint16_t index) return emAfEndpoints[index].endpoint; } +EndpointId emberAfParentEndpointFromIndex(uint16_t index) +{ + return emAfEndpoints[index].parentEndpointId; +} + // If server == true, returns the number of server clusters, // otherwise number of client clusters on this endpoint uint8_t emberAfClusterCount(EndpointId endpoint, bool server) diff --git a/src/app/util/attribute-storage.h b/src/app/util/attribute-storage.h index 63c4c745703225..63910f516bd475 100644 --- a/src/app/util/attribute-storage.h +++ b/src/app/util/attribute-storage.h @@ -268,9 +268,12 @@ CHIP_ERROR emberAfSetDeviceTypeList(chip::EndpointId endpoint, chip::Span & dataVersionStorage, - chip::Span deviceTypeList = {}); + chip::Span deviceTypeList = {}, + chip::EndpointId parentEndpointId = chip::kInvalidEndpointId); chip::EndpointId emberAfClearDynamicEndpoint(uint16_t index); uint16_t emberAfGetDynamicIndexFromEndpoint(chip::EndpointId id);