#define GAPROLE_ADVERT_ENABLED 0x305 //!< Enable/Disable Advertising. Read/Write. Size is uint8. Default is TRUE=Enabled.
#define GAPROLE_ADVERT_OFF_TIME 0x306 //!< Advertising Off Time for Limited advertisements (in milliseconds). Read/Write. Size is uint16. Default is 30 seconds.

GAPROLE_ADVERT_OFF_TIME—表示外设关闭广播持续时间,该值为零表示无限期关闭广播直到下一次广播使能信号到来。

GAPROLE_ADVERT_OFF_TIME – This parameter is used when the device is put into limited discoverable mode. It sets how long the device should wait before becoming discoverable again at the end of the limited discovery period. By setting this value to 0, the device will not become discoverable again until the GAPROLE_ADVERT_ENABLED is set back to TRUE.

上面来自TI论坛

#if defined( CC2540_MINIDK )
// For the CC2540DK-MINI keyfob, device doesn't start advertising until button is pressed
uint8 initial_advertising_enable = FALSE;
#else
// For other hardware platforms, device starts advertising upon initialization
uint8 initial_advertising_enable = TRUE;
#endif

// By setting this to zero, the device will go into the waiting state after
// being discoverable for 30.72 second, and will not being advertising again
// until the enabler is set back to TRUE
uint16 gapRole_AdvertOffTime = 0;

   // Set advertising interval
{
uint16 advInt = DEFAULT_ADVERTISING_INTERVAL; //100ms GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );
}

Set advertising interval

// Set the GAP Role Parameters

GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime );

设置扫描应答数据和广播数据

GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( scanRspData ), scanRspData );
GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );

 // GAP - SCAN RSP data (max size = 31 bytes)
static uint8 scanRspData[] =
{
// complete name
0x14, // length of this data
GAP_ADTYPE_LOCAL_NAME_COMPLETE,
0x53, // 'S'
0x69, // 'i'
0x6d, // 'm'
0x70, // 'p'
0x6c, // 'l'
0x65, // 'e'
0x42, // 'B'
0x4c, // 'L'
0x45, // 'E'
0x50, // 'P'
0x65, // 'e'
0x72, // 'r'
0x69, // 'i'
0x70, // 'p'
0x68, // 'h'
0x65, // 'e'
0x72, // 'r'
0x61, // 'a'
0x6c, // 'l' // connection interval range
0x05, // length of this data
GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
LO_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL ), // 100ms
HI_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL ),
LO_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL ), // 1s
HI_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL ), // Tx power level
0x02, // length of this data
GAP_ADTYPE_POWER_LEVEL,
// 0dBm
};

SCAN RSP data

 // GAP - Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertisting)
static uint8 advertData[] =
{
// Flags; this sets the device to use limited discoverable
// mode (advertises for 30 seconds at a time) instead of general
// discoverable mode (advertises indefinitely)
0x02, // length of this data
GAP_ADTYPE_FLAGS,
DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED, // service UUID, to notify central devices what services are included
// in this peripheral
0x03, // length of this data
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
LO_UINT16( SIMPLEPROFILE_SERV_UUID ),
HI_UINT16( SIMPLEPROFILE_SERV_UUID ), };

Advertisement data

广播模式在数组中定义

// Flags; this sets the device to use limited discoverable
// mode (advertises for 30 seconds at a time) instead of general
// discoverable mode (advertises indefinitely)

#if defined ( CC2540_MINIDK )
#define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_LIMITED
#else
#define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_GENERAL
#endif // defined ( CC2540_MINIDK )

除了模式外也声明是否支持标准蓝牙或者只是BLE

DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,

实验:当 GAP_ADTYPE_FLAGS_GENERAL时候确实为一直广播

GAP_ADTYPE_FLAGS_LIMITED为一次性广播,。

修改模式

#if defined ( CC2540_MINIDK )
#define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_LIMITED
#else
//#define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_GENERAL
#define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_LIMITED
#endif // defined ( CC2540_MINIDK )

GAP_ADTYPE_FLAGS_LIMITED模式下广播间隙由GAPROLE_ADVERT_OFF_TIME来设置,ms单位,如果GAPROLE_ADVERT_OFF_TIME为0则不再广播直到收到

GAP_SetParamValue(TGAP_LIM_ADV_TIMEOUT, 60);设置每次的广播时长,单位s ,这里广播60秒

当GAPROLE_ADVERT_OFF_TIME=0,广播一次60s停下,直到用下面的开关打开

   uint8 current_adv_enabled_status;
uint8 new_adv_enabled_status; //Find the current GAP advertisement status
GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, &current_adv_enabled_status ); if( current_adv_enabled_status == FALSE )
{
new_adv_enabled_status = TRUE;
}
else
{
new_adv_enabled_status = FALSE;
}

ADV 开关

当GAPROLE_ADVERT_OFF_TIME=30000,广播一次60s停下,停下30秒之后自动又再次广播见下图,60秒停下90秒又开始广播

TI BLE: Advertisement的更多相关文章

  1. TI BLE协议栈软件框架分析

    看源代码的时候,一般都是从整个代码的入口处开始,TI  BLE 协议栈源码也不例外.它的入口main()函数就是整个程序的入口,由系统上电时自动调用. 它主要做了以下几件事情: (一)底层硬件初始化配 ...

  2. TI BLE STACK - OSAL

    TI 的OSAL做的很不错,不过看起来也挺费劲可能自己水平太差吧,网上买的谷雨的开发板觉得确实挺不错的. 做点学习笔记,首先是记录OSAL里执行的顺序流程,主要是task ,event,message ...

  3. TI BLE:SCAN

    主机会运行SCAN来搜寻广播中的设备 运行函数: GAPCentralRole_StartDiscovery( DEFAULT_DISCOVERY_MODE, DEFAULT_DISCOVERY_AC ...

  4. TI BLE CC2541的通讯协议.

    包类型: 01命令/02数据/03应答消息 开始标志FF/本数据包长度(注意是16进制)/校验码/包ID/包类型01: 表示是命令/01表示下面要开始传输/03字符串编号/字符串长度/结束位FEFF  ...

  5. TI BLE CC2541的I2C主模式

    由于要写TM1680, 写命令跟写数据, 所以需要使用CC2541的I2C, 2541是有硬件I2C的. tm1680.c: #include "tm1680.h" //TM168 ...

  6. TI BLE CC2541的SPI主模式

    SPI就是用4条线来串行传输数据, 2541只能用模拟的方式用GPIO来做. //*********************************************************** ...

  7. TI BLE:读本机地址

    uint8 ownAddress[B_ADDR_LEN];  //B_ADDR_LEN=6GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress); #def ...

  8. TI BLE : GAP Bond Manager

    // Setup the GAP Bond Manager { uint32 passkey = 0; // passkey "000000" uint8 pairMode = G ...

  9. 让BLE设备的名称包含MAC地址

    对于研发和测试BLE来说,经常看到同名的设备,是极为不方便的,一大堆设备同时上电会让同事不知道哪一个设备才是自己真正想操作的目标.再说一下小米手环,家中有三支小米手环,打开设备搜索全是“MI”,都不知 ...

随机推荐

  1. vue项目编译配置 用于结合Django项目

  2. 关于解决ssh的"Write failed: Broken pipe"问题

    操作环境: 服务器:微软云 Linux CentOS 虚拟机 客户端:MAC OSX terminal 问题描述: 登录虚拟机短时间内不操作就会断开连接并报该“Write failed: Broken ...

  3. CodeForcesGym 100512D Dynamic LCA

    Dynamic LCA Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForcesGym. ...

  4. oracle 互锁的sql查询

    SELECT DECODE(request, 0, 'Holder: ', 'Waiter: ') || sid sess,       id1,       id2,       lmode,    ...

  5. [luoguP1970] 花匠(DP)

    传送门 n2 过不了惨啊 70分做法 f[i][0] 表示第 i 个作为高的,的最优解 f[i][0] 表示第 i 个作为低的,的最优解 (且第 i 个一定选) 那么 f[i+1][1]=max(f[ ...

  6. POJ3352-Road Construction(边连通分量)

    It's almost summer time, and that means that it's almost summer construction time! This year, the go ...

  7. 接龙游戏(codevs 1051)

    1051 接龙游戏  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 给出了N个单词,已经按长度排好了序 ...

  8. Errors running builder 'JavaScript Validator' on

    eclipse编译提示Errors running builder 'JavaScript Validator' on 解决方法见下图 去掉 'JavaScript Validator' 即可

  9. scp、paramiko、rsync复制文件的区别

    1.paramiko只能复制文件,而不能复制目录,复制时,已经存在的会被覆盖;要想复制目录,只能把目录里的文件一个一个复制过去 2.scp可以复制文件.目录,复制时,已经存在的会被覆盖:可以模糊匹配: ...

  10. symfony 使用原始sql

    $this->get('database_connection')->fetchAll('select * from book where book.id=3')