Skip to content

Commit

Permalink
Modify bridge app to conform to the latest Matter specification (#21738)
Browse files Browse the repository at this point in the history
- Add the aggregate node device type at endpoint 1 and add all the bridged nodes as
  endpoint 1 as the parent.
  • Loading branch information
nivi-apple authored and pull[bot] committed Dec 22, 2023
1 parent 84d0b59 commit 1726821
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions examples/bridge-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ DataVersion gLight4DataVersions[ArraySize(bridgedLightClusters)];
#define ZCL_ON_OFF_CLUSTER_REVISION (4u)

int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const EmberAfDeviceType> & deviceTypeList,
const Span<DataVersion> & dataVersionStorage)
const Span<DataVersion> & dataVersionStorage, chip::EndpointId parentEndpointId)
{
uint8_t index = 0;
while (index < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT)
Expand All @@ -170,7 +170,8 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
while (1)
{
dev->SetEndpointId(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(),
Expand Down Expand Up @@ -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 } };
Expand All @@ -369,30 +370,28 @@ static void InitServer(intptr_t context)
// supported clusters so that ZAP will generated the requisite code.
emberAfEndpointEnableDisable(emberAfEndpointFromIndex(static_cast<uint16_t>(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<const EmberAfDeviceType>(gBridgedRootDeviceTypes));
// A bridge has root node device type on EP0 and aggregate node device type (bridge) at EP1
emberAfSetDeviceTypeList(0, Span<const EmberAfDeviceType>(gRootDeviceTypes));
emberAfSetDeviceTypeList(1, Span<const EmberAfDeviceType>(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<const EmberAfDeviceType>(gBridgedOnOffDeviceTypes),
Span<DataVersion>(gLight1DataVersions));
Span<DataVersion>(gLight1DataVersions), 1);
AddDeviceEndpoint(&gLight2, &bridgedLightEndpoint, Span<const EmberAfDeviceType>(gBridgedOnOffDeviceTypes),
Span<DataVersion>(gLight2DataVersions));
Span<DataVersion>(gLight2DataVersions), 1);
AddDeviceEndpoint(&gLight3, &bridgedLightEndpoint, Span<const EmberAfDeviceType>(gBridgedOnOffDeviceTypes),
Span<DataVersion>(gLight3DataVersions));
Span<DataVersion>(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<const EmberAfDeviceType>(gBridgedOnOffDeviceTypes),
Span<DataVersion>(gLight4DataVersions));
Span<DataVersion>(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<const EmberAfDeviceType>(gBridgedOnOffDeviceTypes),
Span<DataVersion>(gLight2DataVersions));
Span<DataVersion>(gLight2DataVersions), 1);
}

extern "C" void app_main()
Expand Down

0 comments on commit 1726821

Please sign in to comment.