Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plumbing for BRBINFO reachability change #36101

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/common/pigweed/protos/fabric_bridge_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ message AdministratorCommissioningChanged {
optional uint32 opener_vendor_id = 4;
}

message ReachabilityChanged {
ScopedNode id = 1;
bool reachability = 2;
}

service FabricBridge {
rpc AddSynchronizedDevice(SynchronizedDevice) returns (pw.protobuf.Empty){}
rpc RemoveSynchronizedDevice(SynchronizedDevice) returns (pw.protobuf.Empty){}
rpc ActiveChanged(KeepActiveChanged) returns (pw.protobuf.Empty){}
rpc AdminCommissioningAttributeChanged(AdministratorCommissioningChanged) returns (pw.protobuf.Empty){}
rpc DeviceReachableChanged(ReachabilityChanged) returns (pw.protobuf.Empty){}
}
5 changes: 5 additions & 0 deletions examples/common/pigweed/rpc_services/FabricBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class FabricBridge : public pw_rpc::nanopb::FabricBridge::Service<FabricBridge>
{
return pw::Status::Unimplemented();
}

virtual pw::Status DeviceReachableChanged(const chip_rpc_ReachabilityChanged & request, pw_protobuf_Empty & response)
{
return pw::Status::Unimplemented();
}
};

} // namespace rpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class BridgedDevice

[[nodiscard]] bool IsReachable() const { return mReachable; }
void SetReachable(bool reachable);
// Reachability attribute changed and requires marking attribute as dirty and sending
// event.
void ReachableChanged(bool reachable);

void LogActiveChangeEvent(uint32_t promisedActiveDurationMs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ void BridgedDevice::SetReachable(bool reachable)
}
}

void BridgedDevice::ReachableChanged(bool reachable)
{
EndpointId endpointId = mEndpointId;
bool reachableChanged = (mReachable != reachable);
if (reachableChanged)
{
SetReachable(reachable);
DeviceLayer::SystemLayer().ScheduleLambda([endpointId]() {
MatterReportingAttributeChangeCallback(endpointId, app::Clusters::BridgedDeviceBasicInformation::Id,
app::Clusters::BridgedDeviceBasicInformation::Attributes::Reachable::Id);

app::Clusters::BridgedDeviceBasicInformation::Events::ReachableChanged::Type event{};
EventNumber eventNumber = 0;

CHIP_ERROR err = app::LogEvent(event, endpointId, eventNumber);
if (err != CHIP_NO_ERROR)
{
ChipLogProgress(NotSpecified, "LogEvent for ActiveChanged failed %s", err.AsString());
}
});
}
}

void BridgedDevice::SetAdminCommissioningAttributes(const AdminCommissioningAttributes & aAdminCommissioningAttributes)
{
EndpointId endpointId = mEndpointId;
Expand Down
21 changes: 21 additions & 0 deletions examples/fabric-bridge-app/linux/RpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FabricBridge final : public chip::rpc::FabricBridge
pw::Status ActiveChanged(const chip_rpc_KeepActiveChanged & request, pw_protobuf_Empty & response) override;
pw::Status AdminCommissioningAttributeChanged(const chip_rpc_AdministratorCommissioningChanged & request,
pw_protobuf_Empty & response) override;
pw::Status DeviceReachableChanged(const chip_rpc_ReachabilityChanged & request, pw_protobuf_Empty & response) override;
};

pw::Status FabricBridge::AddSynchronizedDevice(const chip_rpc_SynchronizedDevice & request, pw_protobuf_Empty & response)
Expand Down Expand Up @@ -210,6 +211,26 @@ pw::Status FabricBridge::AdminCommissioningAttributeChanged(const chip_rpc_Admin
return pw::OkStatus();
}

pw::Status FabricBridge::DeviceReachableChanged(const chip_rpc_ReachabilityChanged & request, pw_protobuf_Empty & response)
{
VerifyOrReturnValue(request.has_id, pw::Status::InvalidArgument());
ScopedNodeId scopedNodeId(request.id.node_id, request.id.fabric_index);
ChipLogProgress(NotSpecified, "Received device reachable changed: Id=[%d:" ChipLogFormatX64 "]", scopedNodeId.GetFabricIndex(),
ChipLogValueX64(scopedNodeId.GetNodeId()));

auto * device = BridgeDeviceMgr().GetDeviceByScopedNodeId(scopedNodeId);
if (device == nullptr)
{
ChipLogError(NotSpecified, "Could not find bridged device associated with Id=[%d:0x" ChipLogFormatX64 "]",
scopedNodeId.GetFabricIndex(), ChipLogValueX64(scopedNodeId.GetNodeId()));
return pw::Status::NotFound();
}

device->ReachableChanged(request.reachability);

return pw::OkStatus();
}

FabricBridge fabric_bridge_service;
#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE

Expand Down
Loading