Skip to content

Commit

Permalink
Refactor BLE ManagerImpl ShutDown Function
Browse files Browse the repository at this point in the history
  • Loading branch information
shchen-Lab committed Aug 9, 2023
1 parent 104d93a commit b465eaf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/platform/bouffalolab/common/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ CHIP_ERROR BLEManagerImpl::_Init()

void BLEManagerImpl::_Shutdown()
{
bt_disable();
// Release BLE Stack resources
mFlags.Set(Flags::kChipoBleShutDown);

}

void BLEManagerImpl::DriveBLEState(intptr_t arg)
{
BLEMgrImpl().DriveBLEState();
Expand Down Expand Up @@ -461,6 +464,20 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(const ChipDeviceEvent * event)
ChipDeviceEvent disconnectEvent;
disconnectEvent.Type = DeviceEventType::kCHIPoBLEConnectionClosed;
ReturnErrorOnFailure(PlatformMgr().PostEvent(&disconnectEvent));

if (mFlags.Has(Flags::kChipoBleShutDown))
{
int ret = bt_disable();
if(ret)
{
ChipLogError(DeviceLayer, "CHIPoBLE Shutdown faild =%d",ret);
}
else
{
mFlags.Clear(Flags::kChipoBleShutDown);
}
return CHIP_NO_ERROR;
}
// Force a reconfiguration of advertising in case we switched to non-connectable mode when
// the BLE connection was established.
mFlags.Set(Flags::kAdvertisingRefreshNeeded);
Expand Down
1 change: 1 addition & 0 deletions src/platform/bouffalolab/common/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
kAdvertisingRefreshNeeded =
0x0010, /**< The advertising state/configuration has changed, but the SoftDevice has yet to be updated. */
kChipoBleGattServiceRegister = 0x0020, /**< The system has currently CHIPoBLE GATT service registered. */
kChipoBleShutDown= 0x0040, /**< The system has disable ble stack. */
};

struct ServiceData;
Expand Down

0 comments on commit b465eaf

Please sign in to comment.