Skip to content

Commit

Permalink
Create a new function to get the real index of the endpoint, that con…
Browse files Browse the repository at this point in the history
…tains a specific cluster server, as stored in emAfEndpoints. Use it in Onoff cluster server to map the endpoint to the EventControl array of the server
  • Loading branch information
jmartinez-silabs committed May 11, 2023
1 parent f40e0bf commit 922dc60
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app/clusters/on-off-server/on-off-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ bool OnOffServer::areStartUpOnOffServerAttributesNonVolatile(EndpointId endpoint
*/
EmberEventControl * OnOffServer::getEventControl(EndpointId endpoint)
{
uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, OnOff::Id);
uint16_t index = emberAfGetClusterServerEndpointIndex(endpoint, OnOff::Id);
if (index >= ArraySize(gEventControls))
{
return nullptr;
Expand Down
36 changes: 36 additions & 0 deletions src/app/util/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,42 @@ uint16_t emberAfIndexFromEndpointIncludingDisabledEndpoints(chip::EndpointId end
*/
uint16_t emberAfFindClusterServerEndpointIndex(chip::EndpointId endpoint, chip::ClusterId clusterId);

/**
* Returns the index of the given endpoint, in the list of all defined endpoints,
* that support the given cluster.
*
* Returns kEmberInvalidEndpointIndex if the given endpoint does not support the
* given cluster or if the given endpoint is disabled.
*
* Contrary to emberAfFindClusterServerEndpointIndex, this function always return the same index
* for a given endpointId, static or dynamic.
*
* This index reflects where the data of the endpoint is located in
* emAfEndpoints
*
* For example, if a device has 4 fixed endpoints (ids 0-3) and 2 dynamic
* endpoints, and cluster X is supported on endpoints 1 and 3, then:
*
* 1) emberAfGetClusterServerEndpointIndex(0, X) returns kEmberInvalidEndpointIndex
* 2) emberAfGetClusterServerEndpointIndex(1, X) returns 1
* 3) emberAfGetClusterServerEndpointIndex(2, X) returns kEmberInvalidEndpointIndex
* 4) emberAfGetClusterServerEndpointIndex(3, X) returns 3
* Note for Dynamic endpoints the index will always be >= to FIXED_ENDPOINT_COUNT
*
* If a dynamic endpoint is defined to dynamic index 1 with endpoint id 7,
* and supports cluster X, (via emberAfSetDynamicEndpoint(1, 7, ...))
* then emberAfGetClusterServerEndpointIndex(7, X) returns 5 (DynamicEndpointIndex 1 + FIXED_ENDPOINT_COUNT).
*
* If now a second dynamic endpoint is defined to dynamic index 0
* with endpoint id 9, and also supports cluster X (via emberAfSetDynamicEndpoint(0, 9, ...)),
*
* emberAfGetClusterServerEndpointIndex(9, X) returns 4.
* and emberAfGetClusterServerEndpointIndex(7, X) still returns 5
*
*/
uint16_t emberAfGetClusterServerEndpointIndex(chip::EndpointId endpoint, chip::ClusterId cluster);

/**
* @brief Returns the total number of endpoints (dynamic and pre-compiled).
*/
Expand Down
17 changes: 17 additions & 0 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,23 @@ static uint16_t findIndexFromEndpoint(EndpointId endpoint, bool ignoreDisabledEn
return kEmberInvalidEndpointIndex;
}

uint16_t emberAfGetClusterServerEndpointIndex(EndpointId endpoint, ClusterId cluster)
{
uint16_t epIndex = findIndexFromEndpoint(endpoint, true /*ignoreDisabledEndpoints*/);

// Endpoint must be configured and enabled
if (epIndex != kEmberInvalidEndpointIndex)
{
if (emberAfFindClusterInType(emAfEndpoints[epIndex].endpointType, cluster, CLUSTER_MASK_SERVER) == nullptr)
{
// The provided endpoint do not contain the given cluster server.
return kEmberInvalidEndpointIndex;
}
}

return epIndex;
}

bool emberAfEndpointIsEnabled(EndpointId endpoint)
{
uint16_t index = findIndexFromEndpoint(endpoint,
Expand Down

0 comments on commit 922dc60

Please sign in to comment.