Other Parts Discussed in Thread: CC2540
主题中讨论的其他器件:CC2540
您好!
在 我的代码中、器件在连接之前开始扫描。 因此、在 BLE 高流量区域中、这会导致连接复杂化。 那么、现在我要做的是、在连接期间禁用扫描、并在连接后重新启用? 当连接开始和完成时、是否有从堆栈到应用的任何指示? s 我可以为此使用 GAPROLE_started 和 GAPROLE_Connected 吗?
非常感谢。
最棒的
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
您好!
感谢您的参与。
我认为您的方法是正确的。 但是、假设您处于中心位置、我认为您应该更考虑事件 GAP_DEVICE_DISCOVERY 和 GAP_LINK_established 事件。
有关其他详细信息、您可能希望访问 https://www.ti.com/lit/swru271
此致、
尊敬的 Varun:
对于其他请求、请您使用"插入代码"函数。
您可能需要为正在使用的查找过程(有限或一般)修改扫描窗口。 这可以使用 TGAP_GEN_DISC_SCAN_WIND 或 TGAP_LIM_DISC_SCAN_WIND 来完成。
我不确定我们是否真正相互理解:
-建立连接时会引发一个事件(GAP_LINK_established 事件)
-设备收到连接请求时不会引发事件
-当广播开始(GAP_make_DISCOVED_DONE_EVENT)和广播结束时(GAP_END_DISCOVERAY_DONE_EVENT)、会引发一个事件
所有这些信息均可在 https://www.ti.com/lit/swru271中找到
此致、
您好 Clement、
是的、我认为我们在同一页上。 感谢您的回复。 为了避免对讲机重叠、我希望在建立连接时禁用扫描。 但现在、我只能在建立连接并且连接没有问题之前禁用扫描。 但现在的问题是、扫描仅在建立连接后才开始。 但我们希望在后台进行扫描。 我要执行的操作与下图类似(在建立连接期间禁用、以红色表示)
因此、我使用以下事件在设备广播时取消扫描。 并在它不是时启动。 但不幸的是 、我再次遇到连接问题。
case GAP_MAKE_DISCOVERABLE_DONE_EVENT:
case GAP_END_DISCOVERABLE_DONE_EVENT:
{
gapMakeDiscoverableRspEvent_t *pPkt = (gapMakeDiscoverableRspEvent_t *)pMsg;
if ( pPkt->hdr.status == SUCCESS )
{
if ( pMsg->opcode == GAP_MAKE_DISCOVERABLE_DONE_EVENT )
{
gapRole_state = GAPROLE_ADVERTISING;
GAPObserverRole_CancelDiscovery();
}
else // GAP_END_DISCOVERABLE_DONE_EVENT
{
if ( gapRole_AdvertOffTime != 0 )
{
if ( ( gapRole_AdvEnabled ) )
{
GAPObserverRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,DEFAULT_DISCOVERY_ACTIVE_SCAN,DEFAULT_DISCOVERY_WHITE_LIST );
VOID osal_start_timerEx( gapRole_TaskID, START_ADVERTISING_EVT, gapRole_AdvertOffTime );
}
}
else
{
// Since gapRole_AdvertOffTime is set to 0, the device should not
// automatically become discoverable again after a period of time.
// Set enabler to FALSE; device will become discoverable again when
// this value gets set to TRUE
gapRole_AdvEnabled = FALSE;
}
// In the Advertising Off period
gapRole_state = GAPROLE_WAITING;
}
}
else
{
gapRole_state = GAPROLE_ERROR;
}
notify = TRUE;
}
break;
uint16 scanduration = 1000U;
uint16 advertOffTime = 5000U;
uint16 advertisingduration = 5000;
uint8 enable_update_request = FALSE;//TRUE;
uint16 desired_min_interval = 20U;
uint16 desired_max_interval = 20U;
uint16 desired_slave_latency = 0U;
uint16 desired_conn_timeout = 1000U;
uint16 rssi_read_rate = 500U;
uint8 initial_advertising_enable = TRUE;
// Set the GAP Role Parameters
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &advertOffTime );
GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, scanResponseLength, scanRspData );
GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );
GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request );
GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval );
GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval );
GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency );
GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout );
GAPRole_SetParameter( GAPROLE_RSSI_READ_RATE, sizeof( uint16 ), &rssi_read_rate );
//GAPRole_SetParameter( TGAP_LIM_DISC_SCAN, sizeof( uint16 ), &scanduration );
//GAPRole_SetParameter( TGAP_GEN_DISC_ADV_MIN, sizeof( uint16 ), &advertisingduration );
// Set the GAP Characteristics
GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_MIN, advertisingduration );
// Set up the advertising interval
static const uint16 advInt = 300U; //500 before
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );
// Initialise the observer
{
uint8 scanRes = 60;
GAPRole_SetParameter ( GAPOBSERVERROLE_MAX_SCAN_RES, sizeof( uint8 ), &scanRes );
}
// Setuo Scanning interval
GAP_SetParamValue( TGAP_LIM_DISC_SCAN, scanduration );
GAP_SetParamValue( TGAP_LIM_DISC_SCAN_INT, 160 ); //Interval between the start of two consecutive scan windows
GAP_SetParamValue( TGAP_LIM_DISC_SCAN_WIND, 128 ); // The duration in which the Link Layer scans on one channel
