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.

应用层能否切换连接状态

Other Parts Discussed in Thread: CC2640R2F, CC2541

HI TI工程师

我使用CC2640R2F芯片,手机连接cc2640r2f,发送指令后,然后断开连接。实际使用过程中,蓝牙建立连接或者断开连接有可能会发生异常,底层要等十几二十秒才会发出超时GAPROLE_WAITING_AFTER_TIMEOUT消息,然后才有广播。这个等待时间太长了,在这十几二十秒的时间内APP无法再控制设备,我想问一下应用层能否强制改变gap状态,使其重新初始化,快速恢复广播

  • GAP_TerminateLinkReq 去断开连接。GapAdv_enable 使能广播
  • 我按照你说的方式操作,先断开连接,然后调用GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),&advertEnable)使能广播,但是实际并没有效果。
    等十多秒之后,底层还是会发出GAPROLE_WAITING_AFTER_TIMEOUT消息,然后才会进入广播状态
  • In simple_peripheral, you will get GAPROLE_WAITING state change event if either side initiates disconnection or you will get GAPROLE_WAITING_AFTER_TIMEOUT after supervision timeout has been reached due to not receiving any packet from the master. Therefore you could for example try to restart advertising in these states.
    你尝试先关闭然后再使能呢?
  • 我的应用场景是这样的,APP连接cc2640r2f设备,发送指令,设备端应答,然后APP端主动断开连接。正常情况下,这个流程一两秒内能完成,超过这个时间基本上就是连接过程或断开过程出问题了。我在应用层做了一个超时处理,从建立连接开始计时,超过3S发现没跑完上面说的流程,就调用GAP_TerminateLinkReq 断开连接。可是我发现调用GAP_TerminateLinkReq 并不生效,应用层没收收到GAPROLE_WAITING事件。也就是说,在这个异常期间,貌似不能强制改变底层的连接状态
  • 尝试减小连接间隔试试。

  • 请问连接之后,如何修改连接参数,是调用GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_REQ, sizeof(uint8_t), &enable)吗。现在主机那边设置的连接超时是20S,我想试一下从机能否修改连接参数,把超时时间设短一些
  • 如果第一次连接使用GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_REQ, sizeof(uint8_t), &enable) 协议栈会自动发起更新请求。
    后续也可以调用如下API:
    * @brief Update the link parameters to a Master or Slave device.
    *
    * @par Corresponding Events:
    * After the update procedure is complete, the calling task will receive a
    * @ref GAP_LINK_PARAM_UPDATE_EVENT of type @ref gapLinkUpdateEvent_t
    *
    * @param pParams link update parameters
    *
    * @return @ref SUCCESS : update request sent to stack
    * @return @ref INVALIDPARAMETER : one of the parameters were invalid
    * @return @ref bleIncorrectMode : invalid profile role
    * @return @ref bleAlreadyInRequestedMode : already updating link parameters
    * @return @ref bleNotConnected : not in a connection
    */
    extern bStatus_t GAP_UpdateLinkParamReq( gapUpdateLinkParamReq_t *pParams );
  • 请问你使用的什么APP,我是用ble scannner配合simple peripheral 无法复现你的问题。
  • 这个应该是TI协议栈底层BUG,我在cc2541上面也发现这个问题,有时会主机已经被关闭蓝牙,可是从机 CC2541很久才能接收GAPROLE_WAITING_AFTER_TIMEOUT指令,有时是十几分钟。复现过程:使用cc2541 SimpleBLEPeripheral例程,在cc2541收到GAPROLE_CONNECTED后,收到L2CAP_SIGNAL_EVENT之前,立即关闭主机蓝牙,cc2541就会有可能一直处于连接状态,过很久才能收到GAPROLE_WAITING_AFTER_TIMEOUT,然后CC2541才检测到连接断开。