工具与软件:
您好、Clement、
我们需要支持2个不同的广播间隔。 我们需要一个持续时间为30s 的广播间隔、然后如果没有建立连接、我们需要将广播间隔更改为持续时间为4分钟。 我们修改了下面的结构以设置持续时间。 原始值如下所示(来自 app_peripheral.c)。
static const BLEAppUtil_AdvStart_t advSetStartParamsSet_1 = { /* Use the maximum possible value. This is the spec-defined maximum for */ /* directed advertising and infinite advertising for all other types */ .enableOptions = GAP_ADV_ENABLE_OPTIONS_USE_MAX, .durationOrMaxEvents = 0 };
我们将结构更改为:
static BLEAppUtil_AdvStart_t advSetStartParamsSet_1 = { /* Use the maximum possible value. This is the spec-defined maximum for */ /* directed advertising and infinite advertising for all other types */ .enableOptions = GAP_ADV_ENABLE_OPTIONS_USE_DURATION, /* Duration is in 10 msec ticks */ .durationOrMaxEvents = (30u * 100u) };
原始广播间隔 按预期工作30秒。 30秒后,BLEAPPUTIL_ADV_END_AFTER_DISABLE 事件在 Peripheral_Adv Handler()中被触发和处理。 在处理程序中、我们设置了新的广播间隔、然后尝试将持续时间更新为240秒(即、设置 durationOrMaxEvents =(240u * 100u)。 但是,将 duration 设置为此值会导致 BLEAppUtil_advStart()返回错误–0x18 ,即 bleInvalidRange: a parameter is out of range. 如果将值更改为180 * 100、则成功开始广播。 幸运的是、对于我们的应用、无论设置是180秒还是240秒都无关紧要
我想提醒您注意这一点、因为根据 bleapputil_api.h 中的注释显示、持续时间应该支持大于180秒的值。
/** * @brief BLEAppUtil Adv Start Structure * * Should be created by the application and passed to * @ref BLEAppUtil_advStart. */ typedef struct { GapAdv_enableOptions_t enableOptions; //!< whether to advertise for the max possible time, for a user-specified duration, or for a user-specified number of advertising events /** * If enableOptions is set to @ref GAP_ADV_ENABLE_OPTIONS_USE_DURATION, this is the time (in 10 ms ticks) to advertise before stopping where the range is 10 ms - 655,540 ms * If enableOptions is set to @ref GAP_ADV_ENABLE_OPTIONS_USE_MAX_EVENTS, this is the maximum number of advertisements to send before stopping, where the range is 1-256 * If enableOptions is set to @ref GAP_ADV_ENABLE_OPTIONS_USE_MAX, this parameter is not used * If enableOptions is set to @ref GAP_ADV_ENABLE_OPTIONS_USE_DURATION, this is the time (in 10 ms ticks) to advertise before stopping where the range is 10 ms - 655,540 ms */ uint16_t durationOrMaxEvents; } BLEAppUtil_AdvStart_t;
谢谢!
Luke