From 57d8d8936a8685eb6bdf2d59892f05608a9f4019 Mon Sep 17 00:00:00 2001 From: Nivi Sarkar <55898241+nivi-apple@users.noreply.github.com> Date: Wed, 10 Aug 2022 10:43:00 -0700 Subject: [PATCH] Modify bridge app to conform to the latest Matter specification (#21738) - Add the aggregate node device type at endpoint 1 and add all the bridged nodes as endpoint 1 as the parent. --- examples/bridge-app/esp32/main/main.cpp | 35 ++++++++++++------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/examples/bridge-app/esp32/main/main.cpp b/examples/bridge-app/esp32/main/main.cpp index 447df2222cb391..9f26baffa44d2c 100644 --- a/examples/bridge-app/esp32/main/main.cpp +++ b/examples/bridge-app/esp32/main/main.cpp @@ -158,7 +158,7 @@ DataVersion gLight4DataVersions[ArraySize(bridgedLightClusters)]; #define ZCL_ON_OFF_CLUSTER_REVISION (4u) int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span & deviceTypeList, - const Span & dataVersionStorage) + const Span & dataVersionStorage, chip::EndpointId parentEndpointId) { uint8_t index = 0; while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT) @@ -170,7 +170,8 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const SpanSetEndpointId(gCurrentEndpointId); - ret = emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList); + ret = + emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList, parentEndpointId); if (ret == EMBER_ZCL_STATUS_SUCCESS) { ChipLogProgress(DeviceLayer, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(), @@ -349,8 +350,8 @@ bool emberAfActionsClusterInstantActionCallback(app::CommandHandler * commandObj return true; } -const EmberAfDeviceType gBridgedRootDeviceTypes[] = { { DEVICE_TYPE_ROOT_NODE, DEVICE_VERSION_DEFAULT }, - { DEVICE_TYPE_BRIDGE, DEVICE_VERSION_DEFAULT } }; +const EmberAfDeviceType gRootDeviceTypes[] = { { DEVICE_TYPE_ROOT_NODE, DEVICE_VERSION_DEFAULT } }; +const EmberAfDeviceType gAggregateNodeDeviceTypes[] = { { DEVICE_TYPE_BRIDGE, DEVICE_VERSION_DEFAULT } }; const EmberAfDeviceType gBridgedOnOffDeviceTypes[] = { { DEVICE_TYPE_LO_ON_OFF_LIGHT, DEVICE_VERSION_DEFAULT }, { DEVICE_TYPE_BRIDGED_NODE, DEVICE_VERSION_DEFAULT } }; @@ -369,30 +370,28 @@ static void InitServer(intptr_t context) // supported clusters so that ZAP will generated the requisite code. emberAfEndpointEnableDisable(emberAfEndpointFromIndex(static_cast(emberAfFixedEndpointCount() - 1)), false); - // - // By default, ZAP only supports specifying a single device type in the UI. However for bridges, they are both - // a Bridge and Matter Root Node device on EP0. Consequently, over-ride the generated value to correct this. - // - emberAfSetDeviceTypeList(0, Span(gBridgedRootDeviceTypes)); + // A bridge has root node device type on EP0 and aggregate node device type (bridge) at EP1 + emberAfSetDeviceTypeList(0, Span(gRootDeviceTypes)); + emberAfSetDeviceTypeList(1, Span(gAggregateNodeDeviceTypes)); - // Add lights 1..3 --> will be mapped to ZCL endpoints 2, 3, 4 + // Add lights 1..3 --> will be mapped to ZCL endpoints 3, 4, 5 AddDeviceEndpoint(&gLight1, &bridgedLightEndpoint, Span(gBridgedOnOffDeviceTypes), - Span(gLight1DataVersions)); + Span(gLight1DataVersions), 1); AddDeviceEndpoint(&gLight2, &bridgedLightEndpoint, Span(gBridgedOnOffDeviceTypes), - Span(gLight2DataVersions)); + Span(gLight2DataVersions), 1); AddDeviceEndpoint(&gLight3, &bridgedLightEndpoint, Span(gBridgedOnOffDeviceTypes), - Span(gLight3DataVersions)); + Span(gLight3DataVersions), 1); - // Remove Light 2 -- Lights 1 & 3 will remain mapped to endpoints 2 & 4 + // Remove Light 2 -- Lights 1 & 3 will remain mapped to endpoints 3 & 5 RemoveDeviceEndpoint(&gLight2); - // Add Light 4 -- > will be mapped to ZCL endpoint 5 + // Add Light 4 -- > will be mapped to ZCL endpoint 6 AddDeviceEndpoint(&gLight4, &bridgedLightEndpoint, Span(gBridgedOnOffDeviceTypes), - Span(gLight4DataVersions)); + Span(gLight4DataVersions), 1); - // Re-add Light 2 -- > will be mapped to ZCL endpoint 6 + // Re-add Light 2 -- > will be mapped to ZCL endpoint 7 AddDeviceEndpoint(&gLight2, &bridgedLightEndpoint, Span(gBridgedOnOffDeviceTypes), - Span(gLight2DataVersions)); + Span(gLight2DataVersions), 1); } extern "C" void app_main()