Skip to content

Commit 4540c71

Browse files
committed
Merge branch 'fix_ble_mesh_example_not_start' into 'main'
examples/common: fix ble not start in blemesh_bridge exmaple See merge request app-frameworks/esp-matter!1422
2 parents 6825f89 + f0c68e6 commit 4540c71

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

examples/common/blemesh_platform/platform/ESP32_custom/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ buildconfig_header("custom_buildconfig") {
7171
"CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER=true",
7272
"CHIP_DEVICE_LAYER_TARGET_ESP32=1",
7373
"CHIP_DEVICE_LAYER_TARGET=ESP32_custom",
74+
"CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE=${chip_enable_chipoble}",
7475
"BLE_PLATFORM_CONFIG_INCLUDE=<platform/ESP32_custom/BlePlatformConfig.h>",
7576
"CHIP_DEVICE_PLATFORM_CONFIG_INCLUDE=<platform/ESP32_custom/CHIPDevicePlatformConfig.h>",
7677
"CHIP_PLATFORM_CONFIG_INCLUDE=<platform/ESP32_custom/CHIPPlatformConfig.h>",

examples/common/blemesh_platform/platform/ESP32_custom/nimble/BLEManagerImpl.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ const ble_uuid128_t UUID_CHIPoBLEChar_C3 = {
140140
};
141141
#endif // CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
142142

143+
const struct ble_gatt_svc_def kNullSvc = { 0 };
144+
143145
SemaphoreHandle_t semaphoreHandle = NULL;
144146

145147
// LE Random Device Address
@@ -152,7 +154,7 @@ uint8_t own_addr_type = BLE_OWN_ADDR_RANDOM;
152154
ChipDeviceScanner & mDeviceScanner = Internal::ChipDeviceScanner::GetInstance();
153155
#endif
154156
BLEManagerImpl BLEManagerImpl::sInstance;
155-
const struct ble_gatt_svc_def BLEManagerImpl::CHIPoBLEGATTAttrs[] = {
157+
const struct ble_gatt_svc_def BLEManagerImpl::CHIPoBLEGATTSvc =
156158
{ .type = BLE_GATT_SVC_TYPE_PRIMARY,
157159
.uuid = (ble_uuid_t *) (&ShortUUID_CHIPoBLEService),
158160
.characteristics =
@@ -180,11 +182,7 @@ const struct ble_gatt_svc_def BLEManagerImpl::CHIPoBLEGATTAttrs[] = {
180182
{
181183
0, /* No more characteristics in this service */
182184
},
183-
} },
184-
185-
{
186-
0, /* No more services. */
187-
},
185+
}
188186
};
189187

190188
#ifdef CONFIG_ENABLE_ESP32_BLE_CONTROLLER
@@ -261,7 +259,7 @@ CHIP_ERROR BLEManagerImpl::_Init()
261259
mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled;
262260
memset(mDeviceName, 0, sizeof(mDeviceName));
263261

264-
PlatformMgr().ScheduleWork(DriveBLEState, 0);
262+
TEMPORARY_RETURN_IGNORED PlatformMgr().ScheduleWork(DriveBLEState, 0);
265263

266264
exit:
267265
return err;
@@ -277,7 +275,7 @@ void BLEManagerImpl::_Shutdown()
277275
mFlags.ClearAll().Set(Flags::kGATTServiceStarted);
278276
mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Disabled;
279277

280-
PlatformMgr().ScheduleWork(DriveBLEState, 0);
278+
TEMPORARY_RETURN_IGNORED PlatformMgr().ScheduleWork(DriveBLEState, 0);
281279
}
282280

283281
CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val)
@@ -294,7 +292,7 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val)
294292
mFlags.Set(Flags::kFastAdvertisingEnabled, val);
295293
mFlags.Set(Flags::kAdvertisingRefreshNeeded, 1);
296294
mFlags.Set(Flags::kAdvertisingEnabled, val);
297-
PlatformMgr().ScheduleWork(DriveBLEState, 0);
295+
TEMPORARY_RETURN_IGNORED PlatformMgr().ScheduleWork(DriveBLEState, 0);
298296

299297
exit:
300298
return err;
@@ -323,7 +321,7 @@ void BLEManagerImpl::BleAdvTimeoutHandler(System::Layer *, void *)
323321
BLEMgrImpl().mFlags.Set(Flags::kAdvertisingRefreshNeeded, 1);
324322
}
325323
#endif
326-
PlatformMgr().ScheduleWork(DriveBLEState, 0);
324+
TEMPORARY_RETURN_IGNORED PlatformMgr().ScheduleWork(DriveBLEState, 0);
327325
}
328326

329327
CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode(BLEAdvertisingMode mode)
@@ -340,7 +338,7 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode(BLEAdvertisingMode mode)
340338
return CHIP_ERROR_INVALID_ARGUMENT;
341339
}
342340
mFlags.Set(Flags::kAdvertisingRefreshNeeded);
343-
PlatformMgr().ScheduleWork(DriveBLEState, 0);
341+
TEMPORARY_RETURN_IGNORED PlatformMgr().ScheduleWork(DriveBLEState, 0);
344342
return CHIP_NO_ERROR;
345343
}
346344

@@ -606,7 +604,7 @@ CHIP_ERROR BLEManagerImpl::CloseConnection(BLE_CONNECTION_OBJECT conId)
606604
// Force a refresh of the advertising state.
607605
mFlags.Set(Flags::kAdvertisingRefreshNeeded);
608606
mFlags.Clear(Flags::kAdvertisingConfigured);
609-
PlatformMgr().ScheduleWork(DriveBLEState, 0);
607+
TEMPORARY_RETURN_IGNORED PlatformMgr().ScheduleWork(DriveBLEState, 0);
610608
#endif
611609

612610
return err;
@@ -705,7 +703,7 @@ CHIP_ERROR BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const C
705703
void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId)
706704
{
707705
ChipLogDetail(Ble, "Received notification of closed CHIPoBLE connection (con %u)", conId);
708-
CloseConnection(conId);
706+
TEMPORARY_RETURN_IGNORED CloseConnection(conId);
709707
}
710708

711709
CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr)
@@ -1006,14 +1004,19 @@ CHIP_ERROR BLEManagerImpl::InitESPBleLayer(void)
10061004
ble_svc_gap_init();
10071005
ble_svc_gatt_init();
10081006

1009-
err = MapBLEError(ble_gatts_count_cfg(CHIPoBLEGATTAttrs));
1007+
if (mGattSvcs.size() == 0)
1008+
{
1009+
mGattSvcs.push_back(CHIPoBLEGATTSvc);
1010+
mGattSvcs.push_back(kNullSvc);
1011+
}
1012+
err = MapBLEError(ble_gatts_count_cfg(&mGattSvcs[0]));
10101013
if (err != CHIP_NO_ERROR)
10111014
{
10121015
ChipLogError(DeviceLayer, "ble_gatts_count_cfg failed: %s", ErrorStr(err));
10131016
ExitNow();
10141017
}
10151018

1016-
err = MapBLEError(ble_gatts_add_svcs(CHIPoBLEGATTAttrs));
1019+
err = MapBLEError(ble_gatts_add_svcs(&mGattSvcs[0]));
10171020
if (err != CHIP_NO_ERROR)
10181021
{
10191022
ChipLogError(DeviceLayer, "ble_gatts_add_svcs failed: %s", ErrorStr(err));
@@ -1616,7 +1619,7 @@ int BLEManagerImpl::ble_svr_gap_event(struct ble_gap_event * event, void * arg)
16161619
{
16171620
#endif
16181621
// Schedule DriveBLEState() to run.
1619-
PlatformMgr().ScheduleWork(DriveBLEState, 0);
1622+
TEMPORARY_RETURN_IGNORED PlatformMgr().ScheduleWork(DriveBLEState, 0);
16201623
#if CONFIG_BLE_MESH
16211624
}
16221625
#endif
@@ -1683,7 +1686,7 @@ int BLEManagerImpl::gatt_svr_chr_access_additional_data(uint16_t conn_handle, ui
16831686
break;
16841687
}
16851688

1686-
PlatformMgr().ScheduleWork(DriveBLEState, 0);
1689+
TEMPORARY_RETURN_IGNORED PlatformMgr().ScheduleWork(DriveBLEState, 0);
16871690

16881691
return err;
16891692
}
@@ -1729,7 +1732,7 @@ int BLEManagerImpl::gatt_svr_chr_access(uint16_t conn_handle, uint16_t attr_hand
17291732
break;
17301733
}
17311734

1732-
PlatformMgr().ScheduleWork(DriveBLEState, 0);
1735+
TEMPORARY_RETURN_IGNORED PlatformMgr().ScheduleWork(DriveBLEState, 0);
17331736

17341737
return err;
17351738
}
@@ -2010,7 +2013,7 @@ void BLEManagerImpl::NewConnection(BleLayer * bleLayer, void * appState, const S
20102013
mBLEScanConfig.mAppState = appState;
20112014

20122015
// Initiate async scan
2013-
PlatformMgr().ScheduleWork(InitiateScan, static_cast<intptr_t>(BleScanState::kScanForDiscriminator));
2016+
TEMPORARY_RETURN_IGNORED PlatformMgr().ScheduleWork(InitiateScan, static_cast<intptr_t>(BleScanState::kScanForDiscriminator));
20142017
}
20152018

20162019
CHIP_ERROR BLEManagerImpl::CancelConnection()

0 commit comments

Comments
 (0)