CH58X/CH57X/V208的Broadcaster(广播者)例程讲解
在对ble进行应用的时候,每个用户的需求可能不尽相同。这里着重介绍从机Broadcaster例程,只广播不连接。
使用该例程时可以在手机使用APP上对Broadcaster进行调试。
安卓端在应用市场搜索BLE调试助手下载使用,使用时要开启提示所需开启的权限。
将Broadcaster例程烧录到DEMO板中。
烧录后发现一个蓝牙名称为abc的设备没有connect(连接)的选项,只能广播我无法连接。
接下来主要的程序拆分讨论:相对于peripheral例程,Broadcaster是比较精简的。这里直接从扫描应答包开始讨论,在APP上我们看到设备的是名称是abc,对比一下peripheral的名称为Simple Peripheral。
此时我们应该会有个疑问Broadcaster扫描应答包中的名称应该是Broadcaster,为什么APP上显示的是abc呢?
这样就可以解释为什么设备名称不是Broadcaster而是abc,这个例程只有广播的功能,所以扫描应答包的设备名是不会显示出来的。
其中对 GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initial_advertising_enable);进行更多的讨论
/*------------------------------------------------------------------- * FUNCTIONS - GAPRole API */ /** * @brief Set a GAP Role parameter. * * @note You can call this function with a GAP Parameter ID and it will set a GAP Parameter. * * @param param - Profile parameter ID: @ref GAPROLE_PROFILE_PARAMETERS * @param len - length of data to write * @param pValue - pointer to data to write. This is dependent on the parameter ID and * WILL be cast to the appropriate data type (example: data type of uint16_t * will be cast to uint16_t pointer). * * @return SUCCESS or INVALIDPARAMETER (invalid paramID) */ extern bStatus_t GAPRole_SetParameter( uint16_t param, uint16_t len, void *pValue );
GAPRole_SetParameter后的三个参数值分别是配置文件参数 ID、要写入的数据长度、指向要写入的数据的指针。
配置文件参数在lib文件里。
#define GAPROLE_PROFILEROLE 0x300 //! #define GAPROLE_IRK 0x301 //! #define GAPROLE_SRK 0x302 //! #define GAPROLE_SIGNCOUNTER 0x303 //! #define GAPROLE_BD_ADDR 0x304 //! #define GAPROLE_ADVERT_ENABLED 0x305 //! #define GAPROLE_ADVERT_DATA 0x306 //! #define GAPROLE_SCAN_RSP_DATA 0x307 //! #define GAPROLE_ADV_EVENT_TYPE 0x308 //! #define GAPROLE_ADV_DIRECT_TYPE 0x309 //! #define GAPROLE_ADV_DIRECT_ADDR 0x30A //! #define GAPROLE_ADV_CHANNEL_MAP 0x30B //! #define GAPROLE_ADV_FILTER_POLICY 0x30C //! #define GAPROLE_STATE 0x30D //! #define GAPROLE_MAX_SCAN_RES 0x30E //! #define GAPROLE_MIN_CONN_INTERVAL 0x311 //! #define GAPROLE_MAX_CONN_INTERVAL 0x312 //! // v5.x #define GAPROLE_PHY_TX_SUPPORTED 0x313 //! #define GAPROLE_PHY_RX_SUPPORTED 0x314 //! #define GAPROLE_PERIODIC_ADVERT_DATA 0x315 //! #define GAPROLE_PERIODIC_ADVERT_ENABLED 0x316 //! //!
这段代码为TMOS事件,TMOS的讲解可以参照这篇博客WCH TMOS用法详解 - debugdabiaoge - 博客园 (cnblogs.com)
广播流程与状态函数,
GAPROLE_STARTED的定义可以在lib库中看到
#define GAPROLE_STATE_ADV_MASK (0xF) //! #define GAPROLE_STATE_ADV_SHIFT (0x0) //! #define GAPROLE_INIT 0 //! #define GAPROLE_STARTED 1 //! #define GAPROLE_ADVERTISING 2 //! #define GAPROLE_WAITING 3 //! #define GAPROLE_CONNECTED 4 //! #define GAPROLE_CONNECTED_ADV 5 //! #define GAPROLE_ERROR 6 //!
这只是最基础的讨论,如有问题请指正!
如转载请标明出处!文章可能被无良网站搬运。某些网站拿着别人的文章写着“我的编程学习分享”。
禁止写着我的编程学习分享的网站转载。
THE END
二维码