Skip to content

Commit 77ca3d2

Browse files
authored
[Telink] Fix device re-pairing (#24364)
1 parent 83c3b6b commit 77ca3d2

File tree

7 files changed

+638
-509
lines changed

7 files changed

+638
-509
lines changed

examples/all-clusters-app/telink/src/AppTask.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ using namespace ::chip::DeviceLayer::Internal;
110110

111111
AppTask AppTask::sAppTask;
112112

113+
class AppFabricTableDelegate : public FabricTable::Delegate
114+
{
115+
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex)
116+
{
117+
if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0)
118+
{
119+
chip::Server::GetInstance().ScheduleFactoryReset();
120+
}
121+
}
122+
};
123+
113124
constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;
114125

115126
CHIP_ERROR AppTask::Init()
@@ -176,6 +187,13 @@ CHIP_ERROR AppTask::Init()
176187
return ret;
177188
}
178189

190+
ret = chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(new AppFabricTableDelegate);
191+
if (ret != CHIP_NO_ERROR)
192+
{
193+
LOG_ERR("AppFabricTableDelegate fail");
194+
return ret;
195+
}
196+
179197
return CHIP_NO_ERROR;
180198
}
181199

examples/all-clusters-minimal-app/telink/src/AppTask.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ using namespace ::chip::DeviceLayer::Internal;
7373

7474
AppTask AppTask::sAppTask;
7575

76+
class AppFabricTableDelegate : public FabricTable::Delegate
77+
{
78+
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex)
79+
{
80+
if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0)
81+
{
82+
chip::Server::GetInstance().ScheduleFactoryReset();
83+
}
84+
}
85+
};
86+
7687
constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;
7788

7889
CHIP_ERROR AppTask::Init()
@@ -136,6 +147,13 @@ CHIP_ERROR AppTask::Init()
136147
return ret;
137148
}
138149

150+
ret = chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(new AppFabricTableDelegate);
151+
if (ret != CHIP_NO_ERROR)
152+
{
153+
LOG_ERR("AppFabricTableDelegate fail");
154+
return ret;
155+
}
156+
139157
return CHIP_NO_ERROR;
140158
}
141159

0 commit comments

Comments
 (0)