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 //!< Reading this parameter will return GAP Role type. Read Only. Size is uint8_t.
#define GAPROLE_IRK 0x301 //!< 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_SRK 0x302 //!< 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_SIGNCOUNTER 0x303 //!< Sign Counter. Read/Write. Size is uint32_t. Default is 0.
#define GAPROLE_BD_ADDR 0x304 //!< Device's Address. Read Only. Size is uint8_t[B_ADDR_LEN]. This item is read from the controller.
#define GAPROLE_ADVERT_ENABLED 0x305 //!< Enable/Disable Advertising. Read/Write. Size is uint8_t. Default is TRUE=Enabled.
#define GAPROLE_ADVERT_DATA 0x306 //!< Advertisement Data. Read/Write. Max size is B_MAX_ADV_EXT_LEN. Default to all 0.
#define GAPROLE_SCAN_RSP_DATA 0x307 //!< Scan Response Data. Read/Write. Max size is B_MAX_ADV_EXT_LEN. Defaults to all 0.
#define GAPROLE_ADV_EVENT_TYPE 0x308 //!< Advertisement Type. Read/Write. Size is uint8_t. Default is GAP_ADTYPE_ADV_IND.
#define GAPROLE_ADV_DIRECT_TYPE 0x309 //!< Direct Advertisement Address Type. Read/Write. Size is uint8_t. Default is ADDRTYPE_PUBLIC.
#define GAPROLE_ADV_DIRECT_ADDR 0x30A //!< Direct Advertisement Address. Read/Write. Size is uint8_t[B_ADDR_LEN]. Default is NULL.
#define GAPROLE_ADV_CHANNEL_MAP 0x30B //!< Which channels to advertise on. Read/Write Size is uint8_t. Default is GAP_ADVCHAN_ALL
#define GAPROLE_ADV_FILTER_POLICY 0x30C //!< Filter Policy. Ignored when directed advertising is used. Read/Write. Size is uint8_t. Default is GAP_FILTER_POLICY_ALL.
#define GAPROLE_STATE 0x30D //!< Reading this parameter will return GAP Peripheral Role State. Read Only. Size is uint8_t.
#define GAPROLE_MAX_SCAN_RES 0x30E //!< Maximum number of discover scan results to receive. Default is 0 = unlimited.
#define GAPROLE_MIN_CONN_INTERVAL 0x311 //!< 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_INTERVAL 0x312 //!< 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_SUPPORTED 0x313 //!< The transmitter PHYs that the Host prefers the Controller to use.Default is GAP_PHY_BIT_ALL
#define GAPROLE_PHY_RX_SUPPORTED 0x314 //!< The receiver PHYs that the Host prefers the Controller to use.Default is GAP_PHY_BIT_ALL
#define GAPROLE_PERIODIC_ADVERT_DATA 0x315 //!< Periodic advertisement Data. Read/Write. Max size is B_MAX_ADV_PERIODIC_LEN. Default to all 0.
#define GAPROLE_PERIODIC_ADVERT_ENABLED 0x316 //!< 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

这段代码为TMOS事件,TMOS的讲解可以参照这篇博客WCH TMOS用法详解 - debugdabiaoge - 博客园 (cnblogs.com)
广播流程与状态函数,


GAPROLE_STARTED的定义可以在lib库中看到
#define GAPROLE_STATE_ADV_MASK (0xF) //!< advertising states mask
#define GAPROLE_STATE_ADV_SHIFT (0x0) //!< advertising states shift
#define GAPROLE_INIT 0 //!< Waiting to be started
#define GAPROLE_STARTED 1 //!< Started but not advertising
#define GAPROLE_ADVERTISING 2 //!< Currently Advertising
#define GAPROLE_WAITING 3 //!< Device is started but not advertising, is in waiting period before advertising again
#define GAPROLE_CONNECTED 4 //!< In a connection
#define GAPROLE_CONNECTED_ADV 5 //!< In a connection + advertising
#define GAPROLE_ERROR 6 //!< Error occurred - invalid state
这只是最基础的讨论,如有问题请指正!
如转载请标明出处!文章可能被无良网站搬运。某些网站拿着别人的文章写着“我的编程学习分享”。
禁止写着我的编程学习分享的网站转载。
CH58X/CH57X/V208的Broadcaster(广播者)例程讲解的更多相关文章
- CH58X/CH57X/V208 Observer(观察者)例程讨论讲解
使用的是沁恒的CH582M的Observer例程与官方的demo板. 本例程的功能是主机扫描到从机的MAC地址并打印出来. 先对宏定义进行理解讨论. 最大响应扫描数为8,在串口调试助手那里可以看到打印 ...
- 6、CC2541修改按键调节广播发送功率例程为持续发送4DB的蓝牙基站
一.目的 在 OSAL操作系统-实验31 从机广播功率修改-(20141029更新).zip 基础上进行修改,该工程是通过5向按键的上下按键来控制广播功率的加减,总共有4个档位.我们的目的是直接用最高 ...
- 说说M451例程讲解之LED
/**************************************************************************//** * @file main.c * @ve ...
- 说说M451例程讲解之串口
/**************************************************************************//** * @file main.c * @ve ...
- 说说M451例程讲解之定时器
关于定时器 相信很多人都不会陌生,无论是51还是32,任何微控制器,都会有定时器 定时器控制器包含 4 组 32-位定时器,TIMER0~TIMER3,提供用户便捷的计数定时功能.定时器可执行很多功能 ...
- M451例程讲解之GPIO.H
到了CORTEX-M4,几乎每一快都有很大的知识量,单单GPIO库文件这一项就有很长的章节要描述,加油吧 GPIO.h.是最基础的一个库文件,下面结合数据手册来一一进行讲解: 先把库文件粘上,方便一一 ...
- M451例程讲解之按键
/**************************************************************************//** * @file main.c * @ve ...
- Rocket - util - Broadcaster
https://mp.weixin.qq.com/s/ohBVNAXZUA538qSxfBGMKA 简单介绍Broadcaster的实现. 1. Broadcaster 广播即是 ...
- 【iCore2 模块相关资料】iM_LAN 100M 以太网模块UDP例程
============================== 技术论坛:http://www.eeschool.org 博客地址:http://xiaomagee.cnblogs.com 官方网店:h ...
随机推荐
- 「雅礼集训 2017 Day2」线段游戏(线段树懒标记“启发式下传”,李超树)
题面 题解 加入一条线段,可以把它转化为在[L,R]区间内加一条线 y=ax+b (如果原线段与y轴平行,就相当于在{x1}处加一条线 y=max(y1,y2)) 我们可以把它加到线段树上,线段树上每 ...
- 【java】学习路径29-异常捕捉实例
import java.util.ArrayList;public class ExceptionCatchDemo { public static void main(String[] args) ...
- 记一次 .NET 某金融企业 WPF 程序卡死分析
一:背景 1. 讲故事 前段时间遇到了一个难度比较高的 dump,经过几个小时的探索,终于给找出来了,在这里做一下整理,希望对大家有所帮助,对自己也是一个总结,好了,老规矩,上 WinDBG 说话. ...
- 虚拟机里做LUN映射(RHEL系统和centos系统皆可)(Linux版)
紧接着Windows的LUN映射之后 参考 (https://www.cnblogs.com/zhengyan6/p/16121268.html) 先删除部分配置(没有做之前的LUN映射则不用) 进网 ...
- KingbaseES V8R6C5 通过securecmdd工具手工脚本部署集群
案例说明: 对于KingbaseES V8R6C5版本在部集群时,需要建立kingbase.root用户在节点间的ssh互信,如果在生产环境禁用root用户ssh登录,则通过ssh部署会失败:V8R6 ...
- immutable 与 stable 函数的差异
Stable 函数不能修改数据库,单个Query中所有行给定同样的参数确保返回相同的结果.这种稳定级别允许优化器将多次函数调用转换为一次.在索引扫描的条件中使用这种函数是可行的,因为索引扫描只计算一次 ...
- mac_VMWare安装总结
MacOS 安装VmWare 总结 如果之前安装过virtualBox,virtualBox的内核扩展会影响到VmWare的使用 *比如会导致VMWare虽然可以安装,却无法创建虚拟机 这是需要执行以 ...
- 通过IIS部署Flask项目
本文主要介绍在Windows Server 2012R2上通过IIS部署Flask项目的过程,以及对TTFB延迟大问题的思考.关于如何申请云服务器,注册(子)域名,备案,开放云服务器端口,获取SS ...
- 这份数据安全自查checklist请拿好,帮你补齐安全短板的妙招全在里面!
企业数据安全自查Checklist! 快来对照表单,看看你的数据安全及格了吗? 一.京东云安全Checklist建议 京东云安全拥有业界领先的安全研究团队,经过多年实践与经验积累,京东云已面向不同业务 ...
- 消息队列的一些场景及源码分析,RocketMQ使用相关问题及性能优化
前文目录链接参考: 消息队列的一些场景及源码分析,RocketMQ使用相关问题及性能优化 https://www.cnblogs.com/yizhiamumu/p/16694126.html 消息队列 ...