From 160584463d85a70f50b21aa6dc492e5e28d77add Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Mon, 15 Nov 2021 10:59:05 -0800 Subject: [PATCH] Add API to find if an endpoint of given index contains the ZCL server. (#11753) --- src/app/util/af.h | 11 +++++++++++ src/app/util/attribute-storage.cpp | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/app/util/af.h b/src/app/util/af.h index ccab4f7a7bd578..6900ef11a37efb 100644 --- a/src/app/util/af.h +++ b/src/app/util/af.h @@ -147,6 +147,17 @@ bool emberAfContainsServerWithMfgCode(chip::EndpointId endpoint, chip::ClusterId */ bool emberAfContainsServer(chip::EndpointId endpoint, chip::ClusterId clusterId); +/** + * @brief Returns true if endpoint of given index contains the ZCL server with specified id. + * + * This function returns true if + * the endpoint of given index contains server of a given cluster. + * If this function is used with a manufacturer specific clusterId + * then this will return the first cluster that it finds in the Cluster table. + * and will not return any other clusters that share that id. + */ +bool emberAfContainsServerFromIndex(uint16_t index, chip::ClusterId clusterId); + /** * @brief Returns true if endpoint contains cluster client. * diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 6d435f5ead7b89..a04a413434b679 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -798,6 +798,20 @@ bool emberAfContainsClient(EndpointId endpoint, ClusterId clusterId) return (emberAfFindClusterWithMfgCode(endpoint, clusterId, CLUSTER_MASK_CLIENT, EMBER_AF_NULL_MANUFACTURER_CODE) != NULL); } +// This will find the first server that has the clusterId given from the index of endpoint, regardless of mfgCode. +bool emberAfContainsServerFromIndex(uint16_t index, ClusterId clusterId) +{ + if (index == 0xFFFF) + { + return false; + } + else + { + return emberAfFindClusterInTypeWithMfgCode(emAfEndpoints[index].endpointType, clusterId, CLUSTER_MASK_SERVER, + EMBER_AF_NULL_MANUFACTURER_CODE); + } +} + // Finds the cluster that matches endpoint, clusterId, direction, and manufacturerCode. EmberAfCluster * emberAfFindClusterWithMfgCode(EndpointId endpoint, ClusterId clusterId, EmberAfClusterMask mask, uint16_t manufacturerCode)