TI中文支持网
TI专业的中文技术问题搜集分享网站

CC2640R2F multi_role工程扫描一段时间后自动停止扫描

问题1:在使用最新SDK2.4里的multi_role工程,广播和扫描功能同时开启,在每次扫描完成事件后重新开启扫描,但是扫描过了大概十几二十分钟后停止扫描了,但是设备还在广播,还可以被连接。

问题2:在GAP_DEVICE_INFO_EVENT中,如果默认ENABLE_UNLIMITED_SCAN_RES = TRUE时,无法获得扫描结果,要把它改成默认初始值是FLASE再进行FALSE判断才有扫描结果,这是为什么???

Alvin Chen:

请看FAQ 第三条:
e2e.ti.com/…/770322

Enable Unlimited Scanning
Certain applications require the ability to scan for an unknown number (i.e. unlimited) of devices. The Unlimited Scanning feature was developed for this reason. When enabling the unlimited scan feature, the stack passes the scan result to the application whenever a broadcaster/advertiser device is found. The BLE-Stack will not save the result in the stack and thus further save RAM usage. The application layer will then receive the scan result one by one under GAP_DEVICE_INFO_EVENT state.

To enable this feature, simply set ENABLE_UNLIMITED_SCAN_RES to TRUE. This allows scanning without an upper limit of discovered devices.

Similar to indefinite scanning, the number of scanned results is governed by DEFAULT_MAX_SCAN_RES as shown below.
我是不是扫描结果太多错过,因为没有保存,而且建议你设置为FLASE

user5905601:

回复 Alvin Chen:

所以你的建议是开启一个定时器不断去做扫描,还是开一个定时器去周期关掉广播?

Alvin Chen:

回复 user5905601:

用一个定时器定期的关闭广播。FAQ写的很清楚的。

user5905601:

回复 Alvin Chen:

首先我没有找到这个宏GAP_ADV_ENABLE_OPTIONS_USE_DURATION 。然后我在开机广播,产生GAP_MAKE_DISCOVERABLE_DONE_EVENT事件的时候开启定时器,定时30秒后,关闭广播。然后在产生GAP_END_DISCOVERABLE_DONE_EVENT的时候又开启广播。实验结果20分钟后,扫描又停止了,按键重启扫描也无效,但是设备还可以广播和被连接。请问我该如何用一个定时器定期的关闭广播???

Alvin Chen:

回复 user5905601:

我没有复现你这个问题,你在使用下面两个控制也有问题?

/* Actions for Menu: Init – Advertise */
bool mr_doAdvertise(uint8_t index)
{(void) index;uint8_t adv;uint8_t adv_status;
// Get current advertising statusGAPRole_GetParameter(GAPROLE_ADVERT_ENABLED, &adv_status, NULL);
// If we're currently advertisingif (adv_status){// Turn off advertisingadv = FALSE;GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &adv, NULL);}// If we're not currently advertisingelse{// Turn on advertisingadv = TRUE;GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &adv, NULL);}
return TRUE;
}

bool mr_doScan(uint8_t index)
{(void) index;
// If we can connect to another deviceif (linkDB_NumActive() < maxNumBleConns){// If we're not already scanningif (!scanningStarted){// Set scannin started flagscanningStarted = TRUE;
// Start scanningGAPRole_StartDiscovery(DEFAULT_DISCOVERY_MODE,DEFAULT_DISCOVERY_ACTIVE_SCAN, DEFAULT_DISCOVERY_WHITE_LIST);
Display_print0(dispHandle, MR_ROW_STATUS1, 0, "Discovering…");}// We're already scanning…so do nothing}return TRUE;
}

user5905601:

回复 Alvin Chen:

是的,使用这两个函数进行控制。
在GAP_DEVICE_INIT_DONE_EVENT事件中,调用mr_doScan(0)进行扫描。

在GAP_MAKE_DISCOVERABLE_DONE_EVENT事件中,调用Util_startClock()开启定时器,时间30秒。到达时间后进入回调函数,关闭广播
uint8 adv = FALSE;
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &adv, NULL);

在GAP_END_DISCOVERABLE_DONE_EVENT事件中,开启广播
uint8 adv = TRUE;
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &adv, NULL);

在GAP_DEVICE_DISCOVERY_EVENT事件中,调用mr_doScan(0)进行再次扫描。

Alvin Chen:

回复 user5905601:

看上去没有什么问题。
一开始提到的GAP_ADV_ENABLE_OPTIONS_USE_DURATION 这个是针对BLE5 stack的一个已知问题。你在2.30上面测试有问题吗?
下面是对ENABLE_UNLIMITED_SCAN_RES 的解释。
Enable Unlimited Scanning
Certain applications require the ability to scan for an unknown number (i.e. unlimited) of devices. The Unlimited Scanning feature was developed for this reason. When enabling the unlimited scan feature, the stack passes the scan result to the application whenever a broadcaster/advertiser device is found. The BLE-Stack will not save the result in the stack and thus further save RAM usage. The application layer will then receive the scan result one by one under GAP_DEVICE_INFO_EVENT state.

To enable this feature, simply set ENABLE_UNLIMITED_SCAN_RES to TRUE. This allows scanning without an upper limit of discovered devices.

Similar to indefinite scanning, the number of scanned results is governed by DEFAULT_MAX_SCAN_RES as shown below.

赞(0)
未经允许不得转载:TI中文支持网 » CC2640R2F multi_role工程扫描一段时间后自动停止扫描
分享到: 更多 (0)