Skip to content

Commit

Permalink
Add functions to set Parent Endpoint and Composition Type for an Endp…
Browse files Browse the repository at this point in the history
…oint (#28410)

* Added endpointCompositionType to the EmberAfDefinedEndpoint structure to be used to hold whether an endpoint is flat or tree composed - defaults to Flat to assume previous behaviour as default

* Added functions to support setting and getting composition type and also to set an endpoints parent endpoint

* updated Read handler for parts list to make its else branch for Flat composition and then added a further branch to handle Tree composition

* Restyled by clang-format

* Fixed mistake in return type of emberAfEndpointCompositionTypeForEndpoint

* Removing debug logs

* Restyled by clang-format

* Moved new API funciotns to chip::app namespace and removed ember naming. Made endpoint struct use a proper bitmask as it was basically using an enum in a weird way

* Moved Read for Parts List to use new function naming

* Restyled by clang-format

* Replaced EmberAfStatus with CHIP_ERROR

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Feb 26, 2024
1 parent c8641e7 commit e850f55
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 18 deletions.
20 changes: 19 additions & 1 deletion src/app/clusters/descriptor/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
return CHIP_NO_ERROR;
});
}
else
else if (IsFlatCompositionForEndpoint(endpoint))
{
err = aEncoder.EncodeList([endpoint](const auto & encoder) -> CHIP_ERROR {
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
Expand Down Expand Up @@ -104,6 +104,24 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
return CHIP_NO_ERROR;
});
}
else if (IsTreeCompositionForEndpoint(endpoint))
{
err = aEncoder.EncodeList([endpoint](const auto & encoder) -> CHIP_ERROR {
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
{
if (!emberAfEndpointIndexIsEnabled(index))
continue;

EndpointId parentEndpointId = emberAfParentEndpointFromIndex(index);
if (parentEndpointId == endpoint)
{
ReturnErrorOnFailure(encoder.Encode(emberAfEndpointFromIndex(index)));
}
}

return CHIP_NO_ERROR;
});
}

return err;
}
Expand Down
15 changes: 6 additions & 9 deletions src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,11 @@ typedef struct
uint16_t endpointSize;
} EmberAfEndpointType;

#ifdef DOXYGEN_SHOULD_SKIP_THIS
enum EmberAfEndpointBitmask;
#else
typedef uint8_t EmberAfEndpointBitmask;
enum
#endif
{ EMBER_AF_ENDPOINT_DISABLED = 0x00,
EMBER_AF_ENDPOINT_ENABLED = 0x01,
enum class EmberAfEndpointOptions : uint8_t
{
isEnabled = 0x1,
isFlatComposition = 0x2,
isTreeComposition = 0x3,
};

/**
Expand All @@ -209,7 +206,7 @@ struct EmberAfDefinedEndpoint
/**
* Meta-data about the endpoint
*/
EmberAfEndpointBitmask bitmask = EMBER_AF_ENDPOINT_DISABLED;
chip::BitMask<EmberAfEndpointOptions> bitmask;
/**
* Endpoint type for this endpoint.
*/
Expand Down
27 changes: 26 additions & 1 deletion src/app/util/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ extern EmberAfDefinedEndpoint emAfEndpoints[];
#endif

/**
* @brief Returns root endpoint of a composed bridged device
* @brief Returns parent endpoint for a given endpoint index
*/
chip::EndpointId emberAfParentEndpointFromIndex(uint16_t index);

Expand Down Expand Up @@ -303,5 +303,30 @@ class EnabledEndpointsWithServerCluster
ClusterId mClusterId;
};

/**
* @brief Sets the parent endpoint for a given endpoint
*/
CHIP_ERROR SetParentEndpointForEndpoint(EndpointId childEndpoint, EndpointId parentEndpoint);

/**
* @brief Sets an Endpoint to use Flat Composition
*/
CHIP_ERROR SetFlatCompositionForEndpoint(EndpointId endpoint);

/**
* @brief Sets an Endpoint to use Tree Composition
*/
CHIP_ERROR SetTreeCompositionForEndpoint(EndpointId endpoint);

/**
* @brief Returns true is an Endpoint has flat composition
*/
bool IsFlatCompositionForEndpoint(EndpointId endpoint);

/**
* @brief Returns true is an Endpoint has tree composition
*/
bool IsTreeCompositionForEndpoint(EndpointId endpoint);

} // namespace app
} // namespace chip
74 changes: 67 additions & 7 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ void emberAfEndpointConfigure()
emAfEndpoints[ep].deviceTypeList = endpointDeviceTypeList(ep);
emAfEndpoints[ep].endpointType = endpointTypeMacro(ep);
emAfEndpoints[ep].dataVersions = currentDataVersions;
emAfEndpoints[ep].bitmask = EMBER_AF_ENDPOINT_ENABLED;

emAfEndpoints[ep].bitmask.Set(EmberAfEndpointOptions::isEnabled);
emAfEndpoints[ep].bitmask.Set(EmberAfEndpointOptions::isFlatComposition);

// Increment currentDataVersions by 1 (slot) for every server cluster
// this endpoint has.
Expand Down Expand Up @@ -271,7 +273,7 @@ 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.Clear(EmberAfEndpointOptions::isEnabled);
emAfEndpoints[index].parentEndpointId = parentEndpointId;

emberAfSetDynamicEndpointCount(MAX_ENDPOINT_COUNT - FIXED_ENDPOINT_COUNT);
Expand Down Expand Up @@ -322,7 +324,7 @@ uint16_t emberAfEndpointCount()

bool emberAfEndpointIndexIsEnabled(uint16_t index)
{
return (emAfEndpoints[index].bitmask & EMBER_AF_ENDPOINT_ENABLED);
return (emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isEnabled));
}

bool emberAfIsStringAttributeType(EmberAfAttributeType attributeType)
Expand Down Expand Up @@ -838,7 +840,7 @@ static uint16_t findIndexFromEndpoint(EndpointId endpoint, bool ignoreDisabledEn
for (epi = 0; epi < emberAfEndpointCount(); epi++)
{
if (emAfEndpoints[epi].endpoint == endpoint &&
(!ignoreDisabledEndpoints || emAfEndpoints[epi].bitmask & EMBER_AF_ENDPOINT_ENABLED))
(!ignoreDisabledEndpoints || emAfEndpoints[epi].bitmask.Has(EmberAfEndpointOptions::isEnabled)))
{
return epi;
}
Expand Down Expand Up @@ -919,11 +921,11 @@ bool emberAfEndpointEnableDisable(EndpointId endpoint, bool enable)
return false;
}

currentlyEnabled = emAfEndpoints[index].bitmask & EMBER_AF_ENDPOINT_ENABLED;
currentlyEnabled = emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isEnabled);

if (enable)
{
emAfEndpoints[index].bitmask |= EMBER_AF_ENDPOINT_ENABLED;
emAfEndpoints[index].bitmask.Set(EmberAfEndpointOptions::isEnabled);
}

#if defined(EZSP_HOST)
Expand Down Expand Up @@ -962,7 +964,7 @@ bool emberAfEndpointEnableDisable(EndpointId endpoint, bool enable)

if (!enable)
{
emAfEndpoints[index].bitmask &= EMBER_AF_ENDPOINT_DISABLED;
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isEnabled);
}

return true;
Expand Down Expand Up @@ -1421,6 +1423,64 @@ app::AttributeAccessInterface * GetAttributeAccessOverride(EndpointId endpointId

return nullptr;
}

CHIP_ERROR SetParentEndpointForEndpoint(EndpointId childEndpoint, EndpointId parentEndpoint)
{
uint16_t childIndex = emberAfIndexFromEndpoint(childEndpoint);
uint16_t parentIndex = emberAfIndexFromEndpoint(parentEndpoint);

if (childIndex == kEmberInvalidEndpointIndex || parentIndex == kEmberInvalidEndpointIndex)
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
emAfEndpoints[childIndex].parentEndpointId = parentEndpoint;
return CHIP_NO_ERROR;
}

CHIP_ERROR SetFlatCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isTreeComposition);
emAfEndpoints[index].bitmask.Set(EmberAfEndpointOptions::isFlatComposition);
return CHIP_NO_ERROR;
}

CHIP_ERROR SetTreeCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isFlatComposition);
emAfEndpoints[index].bitmask.Set(EmberAfEndpointOptions::isTreeComposition);
return CHIP_NO_ERROR;
}

bool IsFlatCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return false;
}
return emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isFlatComposition);
}

bool IsTreeCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return false;
}
return emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isTreeComposition);
}

} // namespace app
} // namespace chip

Expand Down

0 comments on commit e850f55

Please sign in to comment.