18
18
19
19
#pragma once
20
20
21
- #include " AppTask.h"
22
-
23
21
#include < app/server/Server.h>
24
22
#include < app/util/attribute-storage.h>
25
23
#ifdef CONFIG_CHIP_WIFI
@@ -42,36 +40,49 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
42
40
#ifndef CONFIG_CHIP_LAST_FABRIC_REMOVED_NONE
43
41
static AppFabricTableDelegate sAppFabricDelegate ;
44
42
chip::Server::GetInstance ().GetFabricTable ().AddFabricDelegate (&sAppFabricDelegate );
43
+ k_timer_init (&sFabricRemovedTimer , &OnFabricRemovedTimerCallback, nullptr );
45
44
#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_NONE
46
45
}
47
46
48
47
private:
49
48
void OnFabricRemoved (const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex)
49
+ {
50
+ k_timer_start (&sFabricRemovedTimer , K_MSEC (CONFIG_CHIP_LAST_FABRIC_REMOVED_ACTION_DELAY), K_NO_WAIT);
51
+ }
52
+
53
+ static void OnFabricRemovedTimerCallback (k_timer * timer)
50
54
{
51
55
#ifndef CONFIG_CHIP_LAST_FABRIC_REMOVED_NONE
52
56
if (chip::Server::GetInstance ().GetFabricTable ().FabricCount () == 0 )
53
57
{
58
+ chip::DeviceLayer::PlatformMgr ().ScheduleWork ([](intptr_t ) {
54
59
#ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
55
- chip::Server::GetInstance ().ScheduleFactoryReset ();
60
+ chip::Server::GetInstance ().ScheduleFactoryReset ();
56
61
#elif defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_ONLY) || defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START)
57
- chip::DeviceLayer::PlatformMgr ().ScheduleWork ([](intptr_t ) {
58
- /* Erase Matter data */
62
+ // Erase Matter data
59
63
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl ().DoFactoryReset ();
60
- /* Erase Network credentials and disconnect */
64
+ // Erase Network credentials and disconnect
61
65
chip::DeviceLayer::ConnectivityMgr ().ErasePersistentInfo ();
62
66
#ifdef CONFIG_CHIP_WIFI
63
67
chip::DeviceLayer::WiFiManager::Instance ().Disconnect ();
64
68
chip::DeviceLayer::ConnectivityMgr ().ClearWiFiStationProvision ();
65
69
#endif
66
70
#ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START
67
- /* Start the New BLE advertising */
68
- AppEvent event;
69
- event.Handler = AppTask::StartBLEAdvertisementHandler;
70
- AppTask::Instance ().PostEvent (event);
71
+ // Start the New BLE advertising
72
+ if (!chip::DeviceLayer::ConnectivityMgr ().IsBLEAdvertisingEnabled ())
73
+ {
74
+ if (CHIP_NO_ERROR == chip::Server::GetInstance ().GetCommissioningWindowManager ().OpenBasicCommissioningWindow ())
75
+ {
76
+ return ;
77
+ }
78
+ }
79
+ ChipLogError (FabricProvisioning, " Could not start Bluetooth LE advertising" );
71
80
#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START
72
- });
73
81
#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
82
+ });
74
83
}
75
84
#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_NONE
76
85
}
86
+
87
+ inline static k_timer sFabricRemovedTimer ;
77
88
};
0 commit comments