Skip to content

Commit

Permalink
Make dynamic endpoint lifetime more similar to that of fixed endpoints.
Browse files Browse the repository at this point in the history
Specific changes:

1) Ensure that dynamic endpoints land in initializeEndpoint (via
   emberAfEndpointEnableDisable) like fixed ones do (via emAfCallInits).

2) Ensure that clearing an dynamic endpoint properly disables it.
   This makes sure we call emberAfDeactivateClusterTick as needed and
   we can add other cleanup inside emberAfEndpointEnableDisable as it
   becomes useful.

3) Move the emberAfPluginDescriptorServerInitCallback calls for
   dymanic endpoints to the one choke-point in
   emberAfEndpointEnableDisable.  This also fixes a pre-existing issue
   where disabling a fixed endpoint would not correctly update the
   descriptor bits.

4) In descriptor, check for enabled state before trying to actually
   touch the endpoint's data, not after we have tried to touch some of
   it.
  • Loading branch information
bzbarsky-apple committed Sep 13, 2021
1 parent bc2d74b commit 90289ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/app/clusters/descriptor/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ void emberAfPluginDescriptorServerInitCallback(void)

for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
{
EndpointId endpoint = emberAfEndpointFromIndex(index);
if (!emberAfContainsCluster(endpoint, Descriptor::Id))
if (!emberAfEndpointIndexIsEnabled(index))
{
continue;
}

if (!emberAfEndpointIndexIsEnabled(index))
EndpointId endpoint = emberAfEndpointFromIndex(index);
if (!emberAfContainsCluster(endpoint, Descriptor::Id))
{
continue;
}
Expand Down
25 changes: 13 additions & 12 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ void emberAfEndpointConfigure(void)
#ifdef DYNAMIC_ENDPOINT_COUNT
if (MAX_ENDPOINT_COUNT > FIXED_ENDPOINT_COUNT)
{
// This is assuming that EMBER_AF_ENDPOINT_DISABLED is 0
static_assert(EMBER_AF_ENDPOINT_DISABLED == 0, "We are creating enabled dynamic endpoints!");
memset(&emAfEndpoints[FIXED_ENDPOINT_COUNT], 0,
sizeof(EmberAfDefinedEndpoint) * (MAX_ENDPOINT_COUNT - FIXED_ENDPOINT_COUNT));
}
Expand Down Expand Up @@ -196,15 +198,14 @@ EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, EmberAfEn
emAfEndpoints[index].deviceVersion = deviceVersion;
emAfEndpoints[index].endpointType = ep;
emAfEndpoints[index].networkIndex = 0;
emAfEndpoints[index].bitmask = EMBER_AF_ENDPOINT_ENABLED;
// Start the endpoint off as disabled.
emAfEndpoints[index].bitmask = EMBER_AF_ENDPOINT_DISABLED;

emberAfSetDynamicEndpointCount(MAX_ENDPOINT_COUNT - FIXED_ENDPOINT_COUNT);
emberAfSetDeviceEnabled(id, true);

#ifdef ZCL_USING_DESCRIPTOR_CLUSTER_SERVER
// Rebuild descriptor attributes on all endpoints
emberAfPluginDescriptorServerInitCallback();
#endif
// Now enable the endpoint.
emberAfEndpointEnableDisable(id, true);
emberAfSetDeviceEnabled(id, true);

return EMBER_ZCL_STATUS_SUCCESS;
}
Expand All @@ -221,14 +222,9 @@ EndpointId emberAfClearDynamicEndpoint(uint16_t index)
if (ep)
{
emberAfSetDeviceEnabled(ep, false);
emberAfEndpointEnableDisable(ep, false);
emAfEndpoints[index].endpoint = 0;
emAfEndpoints[index].bitmask = 0;
}

#ifdef ZCL_USING_DESCRIPTOR_CLUSTER_SERVER
// Rebuild descriptor attributes on all endpoints
emberAfPluginDescriptorServerInitCallback();
#endif
}

return ep;
Expand Down Expand Up @@ -981,6 +977,11 @@ bool emberAfEndpointEnableDisable(EndpointId endpoint, bool enable)
(cluster->mask & CLUSTER_MASK_CLIENT ? EMBER_AF_CLIENT_CLUSTER_TICK : EMBER_AF_SERVER_CLUSTER_TICK));
}
}

#ifdef ZCL_USING_DESCRIPTOR_CLUSTER_SERVER
// Rebuild descriptor attributes on all endpoints
emberAfPluginDescriptorServerInitCallback();
#endif
}

return true;
Expand Down

0 comments on commit 90289ff

Please sign in to comment.