Skip to content

Commit 7996efa

Browse files
committed
Modify bridge app to conform to the latest Matter specification
- Add the aggregate node device type at endpoint 1 and add all the bridged nodes as endpoint 1 as the parent.
1 parent 4b366e2 commit 7996efa

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

examples/bridge-app/esp32/main/main.cpp

+16-18
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ DataVersion gLight4DataVersions[ArraySize(bridgedLightClusters)];
146146
#define ZCL_ON_OFF_CLUSTER_REVISION (4u)
147147

148148
int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const EmberAfDeviceType> & deviceTypeList,
149-
const Span<DataVersion> & dataVersionStorage)
149+
const Span<DataVersion> & dataVersionStorage, chip::EndpointId parentEndpointId)
150150
{
151151
uint8_t index = 0;
152152
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
@@ -158,7 +158,7 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
158158
while (1)
159159
{
160160
dev->SetEndpointId(gCurrentEndpointId);
161-
ret = emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList);
161+
ret = emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList, parentEndpointId);
162162
if (ret == EMBER_ZCL_STATUS_SUCCESS)
163163
{
164164
ChipLogProgress(DeviceLayer, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(),
@@ -337,8 +337,8 @@ bool emberAfActionsClusterInstantActionCallback(app::CommandHandler * commandObj
337337
return true;
338338
}
339339

340-
const EmberAfDeviceType gBridgedRootDeviceTypes[] = { { DEVICE_TYPE_ROOT_NODE, DEVICE_VERSION_DEFAULT },
341-
{ DEVICE_TYPE_BRIDGE, DEVICE_VERSION_DEFAULT } };
340+
const EmberAfDeviceType gRootDeviceTypes[] = { { DEVICE_TYPE_ROOT_NODE, DEVICE_VERSION_DEFAULT } };
341+
const EmberAfDeviceType gAggregateNodeDeviceTypes[] = { { DEVICE_TYPE_BRIDGE, DEVICE_VERSION_DEFAULT } };
342342

343343
const EmberAfDeviceType gBridgedOnOffDeviceTypes[] = { { DEVICE_TYPE_LO_ON_OFF_LIGHT, DEVICE_VERSION_DEFAULT },
344344
{ DEVICE_TYPE_BRIDGED_NODE, DEVICE_VERSION_DEFAULT } };
@@ -357,30 +357,28 @@ static void InitServer(intptr_t context)
357357
// supported clusters so that ZAP will generated the requisite code.
358358
emberAfEndpointEnableDisable(emberAfEndpointFromIndex(static_cast<uint16_t>(emberAfFixedEndpointCount() - 1)), false);
359359

360-
//
361-
// By default, ZAP only supports specifying a single device type in the UI. However for bridges, they are both
362-
// a Bridge and Matter Root Node device on EP0. Consequently, over-ride the generated value to correct this.
363-
//
364-
emberAfSetDeviceTypeList(0, Span<const EmberAfDeviceType>(gBridgedRootDeviceTypes));
360+
// A bridge has root node device type on EP0 and aggregate node device type (bridge) at EP1
361+
emberAfSetDeviceTypeList(0, Span<const EmberAfDeviceType>(gRootDeviceTypes));
362+
emberAfSetDeviceTypeList(1, Span<const EmberAfDeviceType>(gAggregateNodeDeviceTypes));
365363

366-
// Add lights 1..3 --> will be mapped to ZCL endpoints 2, 3, 4
364+
// Add lights 1..3 --> will be mapped to ZCL endpoints 3, 4, 5
367365
AddDeviceEndpoint(&gLight1, &bridgedLightEndpoint, Span<const EmberAfDeviceType>(gBridgedOnOffDeviceTypes),
368-
Span<DataVersion>(gLight1DataVersions));
366+
Span<DataVersion>(gLight1DataVersions), 1);
369367
AddDeviceEndpoint(&gLight2, &bridgedLightEndpoint, Span<const EmberAfDeviceType>(gBridgedOnOffDeviceTypes),
370-
Span<DataVersion>(gLight2DataVersions));
368+
Span<DataVersion>(gLight2DataVersions), 1);
371369
AddDeviceEndpoint(&gLight3, &bridgedLightEndpoint, Span<const EmberAfDeviceType>(gBridgedOnOffDeviceTypes),
372-
Span<DataVersion>(gLight3DataVersions));
370+
Span<DataVersion>(gLight3DataVersions), 1);
373371

374-
// Remove Light 2 -- Lights 1 & 3 will remain mapped to endpoints 2 & 4
372+
// Remove Light 2 -- Lights 1 & 3 will remain mapped to endpoints 3 & 5
375373
RemoveDeviceEndpoint(&gLight2);
376374

377-
// Add Light 4 -- > will be mapped to ZCL endpoint 5
375+
// Add Light 4 -- > will be mapped to ZCL endpoint 6
378376
AddDeviceEndpoint(&gLight4, &bridgedLightEndpoint, Span<const EmberAfDeviceType>(gBridgedOnOffDeviceTypes),
379-
Span<DataVersion>(gLight4DataVersions));
377+
Span<DataVersion>(gLight4DataVersions), 1);
380378

381-
// Re-add Light 2 -- > will be mapped to ZCL endpoint 6
379+
// Re-add Light 2 -- > will be mapped to ZCL endpoint 7
382380
AddDeviceEndpoint(&gLight2, &bridgedLightEndpoint, Span<const EmberAfDeviceType>(gBridgedOnOffDeviceTypes),
383-
Span<DataVersion>(gLight2DataVersions));
381+
Span<DataVersion>(gLight2DataVersions), 1);
384382
}
385383

386384
extern "C" void app_main()

0 commit comments

Comments
 (0)