Skip to content

Commit

Permalink
ble multi adv
Browse files Browse the repository at this point in the history
  • Loading branch information
shchen-Lab committed Aug 30, 2023
1 parent 99cc5b9 commit 0bdc086
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/platform/bouffalolab/BL616/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static_library("BL616") {
]
defines = [ "BOUFFALOLAB_BLE_DATA_ENABLE" ]
defines +=["BOUFFALOLAB_BLE_PRO_ENABLE"]
defines +=["BOUFFALOLAB_BLE_MULTI_ADV"]
}

if (chip_enable_factory_data || chip_enable_factory_data_test) {
Expand Down
54 changes: 51 additions & 3 deletions src/platform/bouffalolab/common/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ extern "C" {
#else
#include <ble_lib_api.h>
#endif
#ifdef BOUFFALOLAB_BLE_MULTI_ADV
#include <multi_adv.h>
#endif
}

#include <bluetooth/addr.h>
Expand Down Expand Up @@ -268,7 +271,23 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
const bt_data scanResponseData[] = { BT_DATA(BT_DATA_NAME_COMPLETE, deviceName, deviceNameSize) };
const bt_data * scanResponseDataPtr = deviceNameSize > 0 ? scanResponseData : nullptr;
const size_t scanResponseDataLen = deviceNameSize > 0 ? sizeof(scanResponseData) / sizeof(scanResponseData[0]) : 0u;

#ifdef BOUFFALOLAB_BLE_MULTI_ADV
bt_le_adv_param advParams1;
ble_instant[0]=0;
ble_instant[1]=0;
advParams1.id = BT_ID_DEFAULT;
advParams1.options = BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME;
advParams1.interval_min = intervalMin;
advParams1.interval_max = intervalMax;
const char * device1Name = "shchen-dev";
const uint8_t device1NameSize = static_cast<uint8_t>(strlen(device1Name));
const uint8_t advFlags1 = BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR;
const bt_data advertisingData1[] = { BT_DATA(BT_DATA_FLAGS, &advFlags1, sizeof(advFlags1)),
BT_DATA(BT_DATA_NAME_COMPLETE, &device1Name, device1NameSize) };
const bt_data scanResponseData1[] = { BT_DATA(BT_DATA_NAME_COMPLETE, device1Name, device1NameSize) };
const bt_data * scanResponseDataPtr1 = device1NameSize > 0 ? scanResponseData1 : nullptr;
const size_t scanResponseDataLen1 = device1NameSize > 0 ? sizeof(scanResponseData1) / sizeof(scanResponseData1[0]) : 0u;
#endif
// Register dynamically CHIPoBLE GATT service
if (!mFlags.Has(Flags::kChipoBleGattServiceRegister))
{
Expand Down Expand Up @@ -304,11 +323,28 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
}

// Restart advertising
#ifdef BOUFFALOLAB_BLE_MULTI_ADV
if(true==bt_le_multi_adv_id_is_vaild(ble_instant[0]))
{
err = bt_le_multi_adv_stop(ble_instant[0]);
}
if(true==bt_le_multi_adv_id_is_vaild(ble_instant[1]))
{
err = bt_le_multi_adv_stop(ble_instant[1]);
}
#else
err = bt_le_adv_stop();
#endif
VerifyOrReturnError(err == 0, MapErrorZephyr(err));

#ifdef BOUFFALOLAB_BLE_MULTI_ADV
err = bt_le_multi_adv_start(&advParams, advertisingData, sizeof(advertisingData) / sizeof(advertisingData[0]), scanResponseDataPtr,
scanResponseDataLen,&ble_instant[0]);
err = bt_le_multi_adv_start(&advParams1, advertisingData1, sizeof(advertisingData1) / sizeof(advertisingData1[0]), scanResponseDataPtr1,
scanResponseDataLen1,&ble_instant[1]);
#else
err = bt_le_adv_start(&advParams, advertisingData, sizeof(advertisingData) / sizeof(advertisingData[0]), scanResponseDataPtr,
scanResponseDataLen);
#endif
VerifyOrReturnError(err == 0, MapErrorZephyr(err));

// Transition to the Advertising state...
Expand Down Expand Up @@ -340,7 +376,19 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)

CHIP_ERROR BLEManagerImpl::StopAdvertising(void)
{
int err = bt_le_adv_stop();
int err=0;
#ifdef BOUFFALOLAB_BLE_MULTI_ADV
if(true==bt_le_multi_adv_id_is_vaild(ble_instant[0]))
{
err = bt_le_multi_adv_stop(ble_instant[0]);
}
if(true==bt_le_multi_adv_id_is_vaild(ble_instant[1]))
{
err = bt_le_multi_adv_stop(ble_instant[1]);
}
#else
err= bt_le_adv_stop();
#endif
VerifyOrReturnError(err == 0, MapErrorZephyr(err));

// Transition to the not Advertising state...
Expand Down
3 changes: 3 additions & 0 deletions src/platform/bouffalolab/common/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
bool mSubscribedConns[CONFIG_BT_MAX_CONN];
bt_gatt_indicate_params mIndicateParams[CONFIG_BT_MAX_CONN];
bt_conn_cb mConnCallbacks;
#ifdef BOUFFALOLAB_BLE_MULTI_ADV
int ble_instant[2];
#endif
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
PacketBufferHandle c3CharDataBufferHandle;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
#include <FreeRTOS.h>
#if CHIP_DEVICE_LAYER_TARGET_BL616
#include <mem.h>
extern "C" size_t xPortGetFreeHeapSize(void)
{
return kfree_size();
}

extern "C" size_t xPortGetMinimumEverFreeHeapSize( void )
{
return kfree_size();
}
#endif
namespace chip {
namespace DeviceLayer {
Expand Down
3 changes: 3 additions & 0 deletions third_party/bouffalolab/bl616/bouffalo_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ template("bouffalo_sdk") {
"CONFIG_BT_BONDABLE",
"CONFIG_BT_ASSERT",
"CFG_BLE_STACK_DBG_PRINT",
"CONFIG_BLE_MULTI_ADV=1",
]

include_dirs = [
Expand Down Expand Up @@ -1014,6 +1015,7 @@ template("bouffalo_sdk") {
"CONFIG_BT_KEYS_SAVE_AGING_COUNTER_ON_PAIRING",
"CONFIG_BT_HCI_VS_EVT_USER",
"CONFIG_BT_SETTINGS_USE_PRINTK",
"CONFIG_BLE_MULTI_ADV=1",
]

libs = [ "${bouffalo_sdk_root}/components/wireless/bluetooth/btblecontroller/lib/libbtblecontroller_bl616_ble1m0s1bredr0.a" ]
Expand Down Expand Up @@ -1045,6 +1047,7 @@ template("bouffalo_sdk") {
"${bouffalo_sdk_root}/components/wireless/bluetooth/blestack/src/host/settings.c",
"${bouffalo_sdk_root}/components/wireless/bluetooth/blestack/src/host/uuid.c",
"${bouffalo_sdk_root}/components/wireless/bluetooth/blestack/src/port/bl_port.c",
"${bouffalo_sdk_root}/components/wireless/bluetooth/blestack/src/host/multi_adv.c"
]

cflags_c = [
Expand Down

0 comments on commit 0bdc086

Please sign in to comment.