Skip to content

Commit

Permalink
Simple support of composed Bridged Devices. (#17506)
Browse files Browse the repository at this point in the history
* Simple support of composed Bridged Devices.

* Restyled by clang-format

* Rename ComposedEpId to ParentEndpointId.

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
AntonGrey and restyled-commits authored Apr 20, 2022
1 parent 18338b9 commit dd0f7c9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/app/clusters/descriptor/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/app/util/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ uint16_t emberAfGetDynamicIndexFromEndpoint(EndpointId id)

EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const EmberAfEndpointType * ep,
const chip::Span<chip::DataVersion> & dataVersionStorage,
chip::Span<const EmberAfDeviceType> deviceTypeList)
chip::Span<const EmberAfDeviceType> deviceTypeList, EndpointId parentEndpointId)
{
auto realIndex = index + FIXED_ENDPOINT_COUNT;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/app/util/attribute-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,12 @@ CHIP_ERROR emberAfSetDeviceTypeList(chip::EndpointId endpoint, chip::Span<const
// An optional device type list can be passed in as well. If provided, the memory
// backing the list needs to remain allocated until this dynamic endpoint is cleared.
//
// An optional parent endpoint id should be passed for child endpoints of composed device.
//
EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, chip::EndpointId id, const EmberAfEndpointType * ep,
const chip::Span<chip::DataVersion> & dataVersionStorage,
chip::Span<const EmberAfDeviceType> deviceTypeList = {});
chip::Span<const EmberAfDeviceType> deviceTypeList = {},
chip::EndpointId parentEndpointId = chip::kInvalidEndpointId);
chip::EndpointId emberAfClearDynamicEndpoint(uint16_t index);
uint16_t emberAfGetDynamicIndexFromEndpoint(chip::EndpointId id);

Expand Down

0 comments on commit dd0f7c9

Please sign in to comment.