Skip to content

Commit 2531376

Browse files
s07641069mishadeshrestyled-commits
authored andcommitted
[Telink]: Shut down BLE after commissioning window closes (#26786)
* [Telink]: Added delegate to shut down BLE after commissioning window timed out Signed-off-by: Misha Tkachenko <misha.tkachenko@telink-semi.com> * Restyled by clang-format * [Telink]: Fixed wrong behavior on Commissioning window close Signed-off-by: Misha Tkachenko <misha.tkachenko@telink-semi.com> * Restyled by whitespace * Restyled by clang-format --------- Signed-off-by: Misha Tkachenko <misha.tkachenko@telink-semi.com> Co-authored-by: Misha Tkachenko <misha.tkachenko@telink-semi.com> Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Misha Tkachenko <36621698+mishadesh@users.noreply.github.com>
1 parent 380eb6e commit 2531376

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

examples/platform/telink/common/src/AppTaskCommon.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "AppTaskCommon.h"
2020
#include "AppTask.h"
2121

22+
#include "BLEManagerImpl.h"
2223
#include "ButtonManager.h"
2324

2425
#include "ThreadUtil.h"
@@ -131,6 +132,22 @@ Identify sIdentify = {
131132
uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
132133
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
133134
#endif
135+
136+
class AppCallbacks : public AppDelegate
137+
{
138+
bool isComissioningStarted;
139+
140+
public:
141+
void OnCommissioningSessionStarted() override { isComissioningStarted = true; }
142+
void OnCommissioningSessionStopped() override { isComissioningStarted = false; }
143+
void OnCommissioningWindowClosed() override
144+
{
145+
if (!isComissioningStarted)
146+
chip::DeviceLayer::Internal::BLEMgr().Shutdown();
147+
}
148+
};
149+
150+
AppCallbacks sCallbacks;
134151
} // namespace
135152

136153
class AppFabricTableDelegate : public FabricTable::Delegate
@@ -276,6 +293,7 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void)
276293
// Init ZCL Data Model and start server
277294
static CommonCaseDeviceServerInitParams initParams;
278295
(void) initParams.InitializeStaticResourcesBeforeServerInit();
296+
initParams.appDelegate = &sCallbacks;
279297
ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams));
280298

281299
#if APP_SET_DEVICE_INFO_PROVIDER

src/platform/telink/BLEManagerImpl.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ CHIP_ERROR BLEManagerImpl::_Init(void)
176176
return CHIP_NO_ERROR;
177177
}
178178

179+
void BLEManagerImpl::_Shutdown()
180+
{
181+
bt_disable();
182+
mBLERadioInitialized = false;
183+
}
184+
179185
void BLEManagerImpl::DriveBLEState(intptr_t arg)
180186
{
181187
BLEMgrImpl().DriveBLEState();

src/platform/telink/BLEManagerImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
5454
// ===== Members that implement the BLEManager internal interface.
5555

5656
CHIP_ERROR _Init(void);
57-
void _Shutdown() {}
57+
void _Shutdown();
5858
bool _IsAdvertisingEnabled(void);
5959
CHIP_ERROR _SetAdvertisingEnabled(bool val);
6060
bool _IsAdvertising(void);

0 commit comments

Comments
 (0)