广播者 CH58X/CH57X/V208的Broadcaster例程讲解

在对ble进行应用的时候,每个用户的需求可能不尽相同 。这里着重介绍从机Broadcaster例程,只广播不连接 。
使用该例程时可以在手机使用APP上对Broadcaster进行调试 。
安卓端在应用市场搜索BLE调试助手下载使用,使用时要开启提示所需开启的权限 。
将Broadcaster例程烧录到DEMO板中 。

广播者 CH58X/CH57X/V208的Broadcaster例程讲解

文章插图
广播者 CH58X/CH57X/V208的Broadcaster例程讲解

文章插图
烧录后发现一个蓝牙名称为abc的设备没有connect(连接)的选项,只能广播我无法连接 。
接下来主要的程序拆分讨论:相对于peripheral例程 , Broadcaster是比较精简的 。这里直接从扫描应答包开始讨论,在APP上我们看到设备的是名称是abc,对比一下peripheral的名称为Simple Peripheral 。
广播者 CH58X/CH57X/V208的Broadcaster例程讲解

文章插图
此时我们应该会有个疑问Broadcaster扫描应答包中的名称应该是Broadcaster,为什么APP上显示的是abc呢?
广播者 CH58X/CH57X/V208的Broadcaster例程讲解

文章插图
这样就可以解释为什么设备名称不是Broadcaster而是abc,这个例程只有广播的功能,所以扫描应答包的设备名是不会显示出来的 。
广播者 CH58X/CH57X/V208的Broadcaster例程讲解

文章插图
其中对 GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initial_advertising_enable);进行更多的讨论
/*------------------------------------------------------------------- * FUNCTIONS - GAPRole API *//** * @briefSet a GAP Role parameter. * * @noteYou can call this function with a GAP Parameter ID and it will set a GAP Parameter. * * @paramparam - Profile parameter ID: @ref GAPROLE_PROFILE_PARAMETERS * @paramlen - length of data to write * @parampValue - 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). * * @returnSUCCESS or INVALIDPARAMETER (invalid paramID) */extern bStatus_t GAPRole_SetParameter( uint16_t param, uint16_t len, void *pValue );GAPRole_SetParameter后的三个参数值分别是配置文件参数 ID、要写入的数据长度、指向要写入的数据的指针 。配置文件参数在lib文件里 。#define GAPROLE_PROFILEROLE0x300//!< Reading this parameter will return GAP Role type. Read Only. Size is uint8_t.#define GAPROLE_IRK0x301//!< Identity Resolving Key. Read/Write. Size is uint8_t[KEYLEN]. Default is all 0, which means that the IRK will be randomly generated.#define GAPROLE_SRK0x302//!< Signature Resolving Key. Read/Write. Size is uint8_t[KEYLEN]. Default is all 0, which means that the SRK will be randomly generated.#define GAPROLE_SIGNCOUNTER0x303//!< Sign Counter. Read/Write. Size is uint32_t. Default is 0.#define GAPROLE_BD_ADDR0x304//!< Device's Address. Read Only. Size is uint8_t[B_ADDR_LEN]. This item is read from the controller.#define GAPROLE_ADVERT_ENABLED0x305//!< Enable/Disable Advertising. Read/Write. Size is uint8_t. Default is TRUE=Enabled.#define GAPROLE_ADVERT_DATA0x306//!< Advertisement Data. Read/Write. Max size is B_MAX_ADV_EXT_LEN. Default to all 0.#define GAPROLE_SCAN_RSP_DATA0x307//!< Scan Response Data. Read/Write. Max size is B_MAX_ADV_EXT_LEN. Defaults to all 0.#define GAPROLE_ADV_EVENT_TYPE0x308//!< Advertisement Type. Read/Write. Size is uint8_t.Default is GAP_ADTYPE_ADV_IND.#define GAPROLE_ADV_DIRECT_TYPE0x309//!< Direct Advertisement Address Type. Read/Write. Size is uint8_t. Default is ADDRTYPE_PUBLIC.#define GAPROLE_ADV_DIRECT_ADDR0x30A//!< Direct Advertisement Address. Read/Write. Size is uint8_t[B_ADDR_LEN]. Default is NULL.#define GAPROLE_ADV_CHANNEL_MAP0x30B//!< Which channels to advertise on. Read/Write Size is uint8_t. Default is GAP_ADVCHAN_ALL#define GAPROLE_ADV_FILTER_POLICY0x30C//!< Filter Policy. Ignored when directed advertising is used. Read/Write. Size is uint8_t. Default is GAP_FILTER_POLICY_ALL.#define GAPROLE_STATE0x30D//!< Reading this parameter will return GAP Peripheral Role State. Read Only. Size is uint8_t.#define GAPROLE_MAX_SCAN_RES0x30E//!< Maximum number of discover scan results to receive. Default is 0 = unlimited.#define GAPROLE_MIN_CONN_INTERVAL0x311//!< Minimum Connection Interval to allow (n * 1.25ms).Range: 7.5 msec to 4 seconds (0x0006 to 0x0C80). Read/Write. Size is uint16_t. Default is 7.5 milliseconds (0x0006).#define GAPROLE_MAX_CONN_INTERVAL0x312//!< Maximum Connection Interval to allow (n * 1.25ms).Range: 7.5 msec to 4 seconds (0x0006 to 0x0C80). Read/Write. Size is uint16_t. Default is 4 seconds (0x0C80).// v5.x#define GAPROLE_PHY_TX_SUPPORTED0x313//!< The transmitter PHYs that the Host prefers the Controller to use.Default is GAP_PHY_BIT_ALL#define GAPROLE_PHY_RX_SUPPORTED0x314//!< The receiver PHYs that the Host prefers the Controller to use.Default is GAP_PHY_BIT_ALL#define GAPROLE_PERIODIC_ADVERT_DATA0x315//!< Periodic advertisement Data. Read/Write. Max size is B_MAX_ADV_PERIODIC_LEN. Default to all 0.#define GAPROLE_PERIODIC_ADVERT_ENABLED0x316//!< bit0:Enable/Disable Periodic Advertising. Read/Write. Size is uint8_t. Default is FALSE=Disable.//!< bit1:Include the ADI field in AUX_SYNC_IND PDUs

推荐阅读