Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple support of composed Bridged Devices. #17506

Merged
merged 3 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
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