GAP_RegisterConnEventCb()可以注册一个连接事件的callback,
那是否有API可以注册一个广播事件的callback ?
AndyChen:
连接断开之后是否会有事件通知?
在example中会有一个BLE状态改变的事件处理函数,里面会判断一下BLE状态:
typedef enum{ GAPROLE_INIT = 0, //!< Waiting to be started GAPROLE_STARTED, //!< Started but not advertising GAPROLE_ADVERTISING, //!< Currently Advertising GAPROLE_ADVERTISING_NONCONN, //!< Currently using non-connectable Advertising GAPROLE_WAITING, //!< Device is started but not advertising, is in waiting period before advertising again GAPROLE_WAITING_AFTER_TIMEOUT, //!< Device just timed out from a connection but is not yet advertising, is in waiting period before advertising again GAPROLE_CONNECTED, //!< In a connection GAPROLE_CONNECTED_ADV, //!< In a connection + advertising GAPROLE_ERROR //!< Error occurred – invalid state} gaprole_States_t;
我这边测试,连接断开时会触发GAPROLE_WAITING事件,但广播停止再开启(我要修改广播间隔)时也会触发这个事件,因此无法区分此事件是哪种情况触发的。
我该怎样来收到连接断开时的事件通知?
AndyChen:
回复 Viki Shi:
如果需要用户自己去查询连接状态,这样我就需要每次建立间接之后设置一个标志(表示“已连接”),当之后进入有GAPROLE_WAITING事件时,判断这个标志,如果是“已连接”,则表明此次GAPROLE_WAITING事件是“连接断开”触发的。
感觉这样稍微有点麻烦,“连接断开”这种事件时非常常用的, 为什么会没有一个专门的事件通知呢?