From 64f859b9854cd9139d3d790cfea05e313b69fab3 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Tue, 17 Sep 2024 06:36:06 -0700 Subject: [PATCH] [Fabric-Admin] Update the last used nodeId to avoid conflict (#35612) * Update the last used nodeId to avoid conflict * Fix lint error --- .../fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp | 2 ++ examples/fabric-admin/device_manager/DeviceManager.cpp | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp b/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp index 3c389c468f9485..85a3aada9f88ae 100644 --- a/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp +++ b/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp @@ -62,6 +62,7 @@ void FabricSyncAddBridgeCommand::OnCommissioningComplete(NodeId deviceId, CHIP_E ChipLogProgress(NotSpecified, "Successfully paired bridge device: NodeId: " ChipLogFormatX64, ChipLogValueX64(mBridgeNodeId)); + DeviceMgr().UpdateLastUsedNodeId(mBridgeNodeId); DeviceMgr().SubscribeRemoteFabricBridge(); if (DeviceMgr().IsLocalBridgeReady()) @@ -180,6 +181,7 @@ void FabricSyncAddLocalBridgeCommand::OnCommissioningComplete(NodeId deviceId, C if (err == CHIP_NO_ERROR) { DeviceMgr().SetLocalBridgeNodeId(mLocalBridgeNodeId); + DeviceMgr().UpdateLastUsedNodeId(mLocalBridgeNodeId); ChipLogProgress(NotSpecified, "Successfully paired local bridge device: NodeId: " ChipLogFormatX64, ChipLogValueX64(mLocalBridgeNodeId)); } diff --git a/examples/fabric-admin/device_manager/DeviceManager.cpp b/examples/fabric-admin/device_manager/DeviceManager.cpp index d8de362255dd81..ae8fa507ceaaa4 100644 --- a/examples/fabric-admin/device_manager/DeviceManager.cpp +++ b/examples/fabric-admin/device_manager/DeviceManager.cpp @@ -47,6 +47,10 @@ void DeviceManager::Init() { // TODO: (#34113) Init mLastUsedNodeId from chip config file mLastUsedNodeId = 1; + mInitialized = true; + + ChipLogProgress(NotSpecified, "DeviceManager initialized: last used nodeId " ChipLogFormatX64, + ChipLogValueX64(mLastUsedNodeId)); } NodeId DeviceManager::GetNextAvailableNodeId() @@ -61,8 +65,8 @@ void DeviceManager::UpdateLastUsedNodeId(NodeId nodeId) { if (nodeId > mLastUsedNodeId) { - ChipLogProgress(NotSpecified, "Updating last used NodeId to " ChipLogFormatX64, ChipLogValueX64(nodeId)); mLastUsedNodeId = nodeId; + ChipLogProgress(NotSpecified, "Updating last used NodeId to " ChipLogFormatX64, ChipLogValueX64(mLastUsedNodeId)); } }