Skip to content

Commit a60344e

Browse files
committed
Overwrite the default implementation of Administrator Commissioning Cluster
1 parent 8ba371a commit a60344e

File tree

1 file changed

+51
-0
lines changed
  • examples/fabric-bridge-app/linux

1 file changed

+51
-0
lines changed

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

+51
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636

3737
using namespace chip;
3838

39+
using namespace chip::app;
40+
using namespace chip::app::Clusters;
41+
using namespace chip::app::Clusters::AdministratorCommissioning;
42+
3943
#define ZCL_DESCRIPTOR_CLUSTER_REVISION (1u)
4044
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION (2u)
4145
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP (0u)
@@ -97,10 +101,57 @@ void AttemptRpcClientConnect(System::Layer * systemLayer, void * appState)
97101
}
98102
#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
99103

104+
class AdministratorCommissioningCommandHandler : public CommandHandlerInterface
105+
{
106+
public:
107+
// Register for the AdministratorCommissioning cluster on all endpoints.
108+
AdministratorCommissioningCommandHandler() :
109+
CommandHandlerInterface(Optional<EndpointId>::Missing(), AdministratorCommissioning::Id)
110+
{}
111+
112+
void InvokeCommand(HandlerContext & handlerContext) override;
113+
};
114+
115+
void AdministratorCommissioningCommandHandler::InvokeCommand(HandlerContext & handlerContext)
116+
{
117+
using Protocols::InteractionModel::Status;
118+
119+
EndpointId endpointId = handlerContext.mRequestPath.mEndpointId;
120+
ChipLogProgress(NotSpecified, "Received command to open commissioning window on Endpoind: %d", endpointId);
121+
122+
if (handlerContext.mRequestPath.mCommandId != Commands::OpenCommissioningWindow::Id || endpointId == kRootEndpointId)
123+
{
124+
// Proceed with default handling in Administrator Commissioning Server
125+
return;
126+
}
127+
128+
handlerContext.SetCommandHandled();
129+
Status status = Status::Success;
130+
131+
#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
132+
Device * device = DeviceMgr().GetDevice(endpointId);
133+
if (device != nullptr && OpenCommissioningWindow(device->GetNodeId()) == CHIP_NO_ERROR)
134+
{
135+
ChipLogProgress(NotSpecified, "Commissioning window is now open");
136+
}
137+
else
138+
{
139+
status = Status::Failure;
140+
ChipLogProgress(NotSpecified, "Commissioning window is failed to open");
141+
}
142+
#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
143+
144+
handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, status);
145+
}
146+
147+
AdministratorCommissioningCommandHandler gAdministratorCommissioningCommandHandler;
148+
100149
} // namespace
101150

102151
void ApplicationInit()
103152
{
153+
InteractionModelEngine::GetInstance()->RegisterCommandHandler(&gAdministratorCommissioningCommandHandler);
154+
104155
#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
105156
InitRpcServer(kFabricBridgeServerPort);
106157
AttemptRpcClientConnect(&DeviceLayer::SystemLayer(), nullptr);

0 commit comments

Comments
 (0)