求助: CC2540 是否支持同时(分时也可以) 扮演多个角色 Broadcaster & Observer & Peripheral ?
各位好:
我们现在有一种特殊的需求:平时要不断的广播信息,向周围告知自己的存在(Broadcaster),同时还要观察周围有没有类似的设备存在(Observer ),这个主要是为了相互发现,还要做为 Peripheral 这个主要与手机APP通信,交换数据 。请问 CC2540 是否支持同时支持扮演这些角色,如果是,大概应该怎么设定,如果不支持,有没有可以变通的办法?
–Broadcaster –an advertiser that is non-connectable
–Observer –scans for advertisements, but cannot initiate connections.
–Peripheral –an advertiser that is connectable and can operate as a slave in a single link layer connection.
–Central –scans for advertisements and initiates connections; operates as a master in a single or multiple link layer connections.
这多个角色是否可以同时(分时)使用,比喻 1s为 Broadcaster , 1s 为 Observer ,再1s为Peripheral ?
The BLE specification allows for a few different possible multiple-role configurations:
–Peripheral and Broadcaster –device operates as a slave in a single link layer connection, but meanwhile also can send out non-connectable advertisements (supported in Beta stack)
–Peripheral and Observer –device operates as a slave in a single link layer connection, but meanwhile also can scan for advertisements without initiating a connection (not supported in Beta stack)
–Central and Broadcaster –device scans for advertisements and initiates connections as a master, but also can broadcast non-connectable advertisements (not supported in Beta stack)
不能同时支持 Broadcaster 和 Observer ,那分时可以吧?
我们现在打算分时处理,先Broadcaster 1s,然后 Observer 1s ,但发现如下问题:
1、只有在第一次 Broadcaster 时,手机能找到 此 BLE设备 ,以后一直找不到
2、第一次切换到 Observer ,找不到我另外一台 Broadcaster 设备(实验时一直有一台BLE 充当 Broadcaster)
3、在Observer 1s 后切换回 Broadcaster 时,手机无法再找到此设备,此后无论怎么切换都再也不能被找不到了,只在第一次能被找到
4、在 Broadcaster 1s后切换回 Observer时,可以找到另外一台实验用的Broadcaster设备,以后切换也可一直找到,只在第一次时不能找到Broadcaster
代码是这样处理的:
创建 Observer Task 和 Broadcaster ,但都不启动,
1、启动Broadcaster 如下:
a、设置参数:GAPROLE_ADVERT_OFF_TIME & GAPROLE_SCAN_RSP_DATA & GAPROLE_ADVERT_DATA & GAPROLE_ADV_EVENT_TYPE & TGAP_LIM_DISC_ADV_INT_MIN ...
b、设置角色 : GAPRole_StartDevice
c、启动 Broadcaster GAPROLE_ADVERT_ENABLED
d、启动 1s 定时器,用以切换角色
2、Broadcaster 启动 1s 后,定时切换角色,关闭Broadcaster ,启动 Observer ,具体过程如下:
a、关闭定时器,停止Broadcaster : GAPROLE_ADVERT_ENABLED
b、启动 Observer( 设置 GAPOBSERVERROLE_MAX_SCAN_RES & TGAP_GEN_DISC_SCAN & TGAP_LIM_DISC_SCAN , 启动角色 GAPObserverRole_StartDevice , 启动 Observer : GAPObserverRole_StartDiscovery )
c、启动定 1s 定时器,用以切换角色。
3、Observer 启动1s后,定时器启动,进行切换 Broadcaster
a、关闭 Observer ( GAPObserverRole_CancelDiscovery ) ,进入 步骤 1
分时 Broadcaster Peripheral Observer amp 相关文章: