Skip to content

Commit

Permalink
Add plumbing for BRBINFO reachability change (#36101)
Browse files Browse the repository at this point in the history
  • Loading branch information
tehampson authored Oct 17, 2024
1 parent e150e06 commit dead378
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
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

0 comments on commit dead378

Please sign in to comment.