Skip to content

Commit

Permalink
Fix EP0 in dynamic bridge app (#23179)
Browse files Browse the repository at this point in the history
* Fix EP0 in dynamic bridge app

Currently this conflicts with EP0 Descriptor clusters, we register an override that can't provide EP0 values and it vectors into that

* Instead just ignore desciptor clusters

* remove dead code

* Fix style

* Update main.cpp

remove constant

* force add a descriptor cluster to every device
  • Loading branch information
achaulk-goog authored and pull[bot] committed Oct 27, 2023
1 parent a439b7d commit 42f3bb1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
21 changes: 20 additions & 1 deletion examples/dynamic-bridge-app/linux/DynamicDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@
* limitations under the License.
*/

#include <app-common/zap-generated/af-structs.h>
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/cluster-id.h>

#include "DynamicDevice.h"

#define DEVICE_TYPE_BRIDGED_NODE 0x0013
// Device Version for dynamic endpoints:
#define DEVICE_VERSION_DEFAULT 1

namespace {
static const int kDescriptorAttributeArraySize = 254;

DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(descriptorAttrs)
DECLARE_DYNAMIC_ATTRIBUTE(ZCL_DEVICE_LIST_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize, 0), /* device list */
DECLARE_DYNAMIC_ATTRIBUTE(ZCL_SERVER_LIST_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize, 0), /* server list */
DECLARE_DYNAMIC_ATTRIBUTE(ZCL_CLIENT_LIST_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize, 0), /* client list */
DECLARE_DYNAMIC_ATTRIBUTE(ZCL_PARTS_LIST_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize, 0), /* parts list */
DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
} // namespace

DynamicDevice::DynamicDevice() {}

void DynamicDevice::AddDeviceType(EmberAfDeviceType type)
Expand All @@ -34,10 +49,14 @@ Device DynamicDevice::CreateDevice()
{
// All nodes are bridged devices.
mDeviceTypes.push_back(EmberAfDeviceType{ DEVICE_TYPE_BRIDGED_NODE, DEVICE_VERSION_DEFAULT });
mVersions.resize(mClusterRawPtrs.size());
mVersions.resize(mClusterRawPtrs.size() + 1); // +1 for the descriptor cluster
for (auto * c : mClusterRawPtrs)
mClusterBaseRawPtrs.push_back(c);

// Force a default descriptor cluster to be present.
mClusterDecls.emplace_back(
EmberAfCluster DECLARE_DYNAMIC_CLUSTER(ZCL_DESCRIPTOR_CLUSTER_ID, descriptorAttrs, nullptr, nullptr));

return Device(chip::Span<chip::DataVersion>(mVersions.data(), mVersions.size()),
chip::Span<EmberAfCluster>(mClusterDecls.data(), mClusterDecls.size()),
chip::Span<ClusterInterface *>(mClusterBaseRawPtrs.data(), mClusterBaseRawPtrs.size()),
Expand Down
8 changes: 6 additions & 2 deletions examples/dynamic-bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,12 @@ int main(int argc, char * argv[])
clusterAccess.reserve(std::extent<decltype(clusters::kKnownClusters)>::value);
for (auto & entry : clusters::kKnownClusters)
{
clusterAccess.emplace_back(chip::Optional<EndpointId>(), entry.id);
registerAttributeAccessOverride(&clusterAccess.back());
// Desciptor clusters should not be overridden.
if (entry.id != chip::app::Clusters::Descriptor::Id)
{
clusterAccess.emplace_back(chip::Optional<EndpointId>(), entry.id);
registerAttributeAccessOverride(&clusterAccess.back());
}
}

ChipLinuxAppMainLoop();
Expand Down

0 comments on commit 42f3bb1

Please sign in to comment.