Skip to content

Commit f6eeb48

Browse files
andy31415restyled-commitsandreilitvin
authored andcommitted
Add ICD support (featuremap and commands) to FabricAdmin/FabricBridge samples (project-chip#34855)
* Add extra attributes to the bridged device basic info structures, remove nonsense comments * Make use of AAI for BridgedDeviceBasicInformation cluster * Restyled by gn * Fix sizes for software version * Update the synchronized device proto to have more data in it * Switch to unique ptr in the registry, making sure memory management works (fixed memory leak on remove device) * Use more std::optional * Bump revision to 4 * Forward attributes from the create call into the bridged device * Make attribute mapping actually work * Restyle * Ensure unique IDs are generated * Restyle * Increase size to 33 to allow for a null terminator * make sure that the rpc structures are initialized * Restyle * Add some fake data to test moving the data around * Remove unused members that were likely just copied over * make the attributes optional * Prepare some device sync data - reading the basic info cluster * Prepare some device sync data - reading the basic info cluster * Full implementation of forwarding data * Restyle * Add missing file * Restyle * reset readclient, since this may reset the exchange manager ... seems cleaner * Add the verifyOrDie * Restyled by clang-format * Fix string size for HW and software versions * Move ICD support: set separate commands, handle feature mask * Restyle * Remove some of the spammier logs * Enfore RPC enabling for synchronized device addition * Add device sync in progress tracking * Undo submodule update * Fix up device sync progress tracking to better handle errors * Restyled by clang-format * Fix typo * Undo submodule update * Fix merge * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Andrei Litvin <andreilitvin@google.com>
1 parent c80090e commit f6eeb48

File tree

6 files changed

+42
-30
lines changed

6 files changed

+42
-30
lines changed

examples/fabric-admin/commands/pairing/DeviceSynchronization.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "fabric_bridge_service/fabric_bridge_service.pb.h"
2727
#include "fabric_bridge_service/fabric_bridge_service.rpc.pb.h"
2828

29-
/// Ensures that device data is synchronized to the remove fabric bridge.
29+
/// Ensures that device data is synchronized to the remote fabric bridge.
3030
///
3131
/// Includes a state machine that:
3232
/// - initiates a "read basic information data" command to fetch basic information

examples/fabric-bridge-app/fabric-bridge-common/include/BridgedDevice.h

+11-8
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ class BridgedDevice
4343
BridgedDevice(chip::NodeId nodeId);
4444
virtual ~BridgedDevice() = default;
4545

46+
[[nodiscard]] bool IsReachable() const { return mReachable; }
47+
void SetReachable(bool reachable);
48+
4649
void LogActiveChangeEvent(uint32_t promisedActiveDurationMs);
4750

48-
bool IsReachable();
49-
bool IsIcd();
50-
void SetReachable(bool reachable);
51+
[[nodiscard]] bool IsIcd() const { return mIsIcd; }
52+
void SetIcd(bool icd) { mIsIcd = icd; }
5153

5254
inline void SetEndpointId(chip::EndpointId id) { mEndpointId = id; };
5355
inline chip::EndpointId GetEndpointId() { return mEndpointId; };
@@ -63,11 +65,12 @@ class BridgedDevice
6365
void SetUniqueId(const std::string & value) { mAttributes.uniqueId = value; }
6466

6567
protected:
66-
bool mReachable;
67-
bool mIsIcd = false;
68-
chip::NodeId mNodeId;
69-
chip::EndpointId mEndpointId;
70-
chip::EndpointId mParentEndpointId;
68+
bool mReachable = false;
69+
bool mIsIcd = false;
70+
71+
chip::NodeId mNodeId = 0;
72+
chip::EndpointId mEndpointId = 0;
73+
chip::EndpointId mParentEndpointId = 0;
7174

7275
BridgedAttributes mAttributes;
7376
};

examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDevice.cpp

+1-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "BridgedDevice.h"
2020

2121
#include <cstdio>
22-
#include <string>
2322

2423
#include <app/EventLogging.h>
2524
#include <platform/CHIPDeviceLayer.h>
@@ -32,7 +31,7 @@ struct ActiveChangeEventWorkData
3231
uint32_t mPromisedActiveDuration;
3332
};
3433

35-
static void ActiveChangeEventWork(intptr_t arg)
34+
void ActiveChangeEventWork(intptr_t arg)
3635
{
3736
ActiveChangeEventWorkData * data = reinterpret_cast<ActiveChangeEventWorkData *>(arg);
3837

@@ -68,16 +67,6 @@ void BridgedDevice::LogActiveChangeEvent(uint32_t promisedActiveDurationMs)
6867
chip::DeviceLayer::PlatformMgr().ScheduleWork(ActiveChangeEventWork, reinterpret_cast<intptr_t>(workdata));
6968
}
7069

71-
bool BridgedDevice::IsReachable()
72-
{
73-
return mReachable;
74-
}
75-
76-
bool BridgedDevice::IsIcd()
77-
{
78-
return mIsIcd;
79-
}
80-
8170
void BridgedDevice::SetReachable(bool reachable)
8271
{
8372
mReachable = reachable;

examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDeviceBasicInformationImpl.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <app/AttributeAccessInterfaceRegistry.h>
2525

2626
static constexpr unsigned kBridgedDeviceBasicInformationClusterRevision = 4;
27-
static constexpr unsigned kBridgedDeviceBasicInformationFeatureMap = 0;
2827

2928
using namespace ::chip;
3029
using namespace ::chip::app;
@@ -49,9 +48,12 @@ CHIP_ERROR BridgedDeviceBasicInformationImpl::Read(const ConcreteReadAttributePa
4948
case BasicInformation::Attributes::ClusterRevision::Id:
5049
encoder.Encode(kBridgedDeviceBasicInformationClusterRevision);
5150
break;
52-
case BasicInformation::Attributes::FeatureMap::Id:
53-
encoder.Encode(kBridgedDeviceBasicInformationFeatureMap);
54-
break;
51+
case BasicInformation::Attributes::FeatureMap::Id: {
52+
BitMask<Clusters::BridgedDeviceBasicInformation::Feature> features;
53+
features.Set(Clusters::BridgedDeviceBasicInformation::Feature::kBridgedICDSupport, dev->IsIcd());
54+
encoder.Encode(features);
55+
}
56+
break;
5557
case BasicInformation::Attributes::UniqueID::Id:
5658
encoder.Encode(CharSpan::fromCharString(dev->GetBridgedAttributes().uniqueId.c_str()));
5759
break;

examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDeviceManager.cpp

+22-5
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,31 @@ constexpr CommandId administratorCommissioningCommands[] = {
141141
kInvalidCommandId,
142142
};
143143

144+
// clang-format off
144145
// Declare Cluster List for Bridged Node endpoint
145146
DECLARE_DYNAMIC_CLUSTER_LIST_BEGIN(bridgedNodeClusters)
146-
DECLARE_DYNAMIC_CLUSTER(Descriptor::Id, descriptorAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr),
147+
DECLARE_DYNAMIC_CLUSTER(Descriptor::Id, descriptorAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr),
148+
DECLARE_DYNAMIC_CLUSTER(BridgedDeviceBasicInformation::Id, bridgedDeviceBasicAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr),
149+
DECLARE_DYNAMIC_CLUSTER(EcosystemInformation::Id, ecosystemInformationBasicAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr),
150+
DECLARE_DYNAMIC_CLUSTER(AdministratorCommissioning::Id, AdministratorCommissioningAttrs, ZAP_CLUSTER_MASK(SERVER),
151+
administratorCommissioningCommands, nullptr)
152+
DECLARE_DYNAMIC_CLUSTER_LIST_END;
153+
154+
DECLARE_DYNAMIC_CLUSTER_LIST_BEGIN(icdBridgedNodeClusters)
155+
DECLARE_DYNAMIC_CLUSTER(Descriptor::Id, descriptorAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr),
147156
DECLARE_DYNAMIC_CLUSTER(BridgedDeviceBasicInformation::Id, bridgedDeviceBasicAttrs, ZAP_CLUSTER_MASK(SERVER),
148157
bridgedDeviceBasicInformationCommands, nullptr),
149-
DECLARE_DYNAMIC_CLUSTER(EcosystemInformation::Id, ecosystemInformationBasicAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr),
150158
DECLARE_DYNAMIC_CLUSTER(AdministratorCommissioning::Id, AdministratorCommissioningAttrs, ZAP_CLUSTER_MASK(SERVER),
151-
administratorCommissioningCommands, nullptr) DECLARE_DYNAMIC_CLUSTER_LIST_END;
159+
administratorCommissioningCommands, nullptr)
160+
DECLARE_DYNAMIC_CLUSTER_LIST_END;
161+
// clang-format on
152162

153163
// Declare Bridged Node endpoint
154164
DECLARE_DYNAMIC_ENDPOINT(sBridgedNodeEndpoint, bridgedNodeClusters);
165+
DECLARE_DYNAMIC_ENDPOINT(sIcdBridgedNodeEndpoint, icdBridgedNodeClusters);
166+
167+
// TODO: this is a single version array, however we may have many
168+
// different clusters that are independent.
155169
DataVersion sBridgedNodeDataVersions[ArraySize(bridgedNodeClusters)];
156170

157171
const EmberAfDeviceType sBridgedDeviceTypes[] = { { DEVICE_TYPE_BRIDGED_NODE, DEVICE_VERSION_DEFAULT } };
@@ -171,9 +185,12 @@ void BridgedDeviceManager::Init()
171185
std::optional<unsigned> BridgedDeviceManager::AddDeviceEndpoint(std::unique_ptr<BridgedDevice> dev,
172186
chip::EndpointId parentEndpointId)
173187
{
174-
EmberAfEndpointType * ep = &sBridgedNodeEndpoint;
188+
EmberAfEndpointType * ep = dev->IsIcd() ? &sIcdBridgedNodeEndpoint : &sBridgedNodeEndpoint;
189+
175190
const chip::Span<const EmberAfDeviceType> & deviceTypeList = Span<const EmberAfDeviceType>(sBridgedDeviceTypes);
176-
const chip::Span<chip::DataVersion> & dataVersionStorage = Span<DataVersion>(sBridgedNodeDataVersions);
191+
192+
// TODO: this shares data version among different clusters, which seems incorrect
193+
const chip::Span<chip::DataVersion> & dataVersionStorage = Span<DataVersion>(sBridgedNodeDataVersions);
177194

178195
if (dev->GetBridgedAttributes().uniqueId.empty())
179196
{

examples/fabric-bridge-app/linux/RpcServer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pw::Status FabricBridge::AddSynchronizedDevice(const chip_rpc_SynchronizedDevice
109109
}
110110

111111
device->SetBridgedAttributes(attributes);
112+
device->SetIcd(request.has_is_icd && request.is_icd);
112113

113114
auto result = BridgeDeviceMgr().AddDeviceEndpoint(std::move(device), 1 /* parentEndpointId */);
114115
if (!result.has_value())

0 commit comments

Comments
 (0)