安卓4.3:BLE:startLeScan的筛选行为() [英] Android 4.3: BLE: Filtering behaviour of startLeScan()

查看:1708
本文介绍了安卓4.3:BLE:startLeScan的筛选行为()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个BluetoothLE传感器设备上,为此我需要形成的数据一个一对多的广播。根据该规范,外围设备可能只有一个主人,而由于芯片和协议栈我设计上的限制,主只能有三个奴隶。据我了解,Android无法成为BLE奴隶反正,所以有我的设备作为主是不是一种选择。

I'm working on a BluetoothLE sensor device, for which I need to form a one-to-many broadcast of data. As per the spec, peripherals may only have a single master, and due to limitations of the chip and stack I'm designing on, a master can only have three slaves. From what I understand, Android cannot become a BLE slave anyway, so having my device as a master is not an option.

这两个有关另一种工作模式,被称为广播模式的BT4规范和制造商的文档交谈。在广播模式中,连接永不制成,并且该应用程序数据被发送作为广告数据包的一部分。这将完全适合我的需求,为众多Android / iOS的手机可以同时扫描下来每个数据包。一种广告数据包发送多次在暴,所以我怀疑数据的接收更多的只是可靠。如果一个分组被在这里和那里丢失,可以容忍的。

Both the BT4 spec and manufacturer documentation talk about another mode of operation, referred to as Broadcast mode. In broadcast mode, a connection is never made, and the application data is transmitted as part of the advertising packet. This will exactly fit my needs, as many Android/iOS phones can simultaneously scan down each packet. An advertising packet is transmitted multiple times in bursts, so I suspect reception of data to be mostly reliable. If a packet is lost here and there, it can be tolerated.

如果这得到有趣的是,我想这些数据包进行实时传感器数据,在10-20Hz的速度更新。从例子我发现在网络上,BLE在这种模式主要是被用于iBeacon式的实现,在那里他们正在广播的静态数据。我找不到广告的报文是如何在Android栈中过滤任何信息。这可能是因为它们返回每一个结果的蓝牙硬件地址,或者它可以是地址和数据的独特的组合。第二种选择将工作于这种应用。如果启动和停止扫描重置过滤器,我可以做什么工作好。

Where this gets interesting, is that I want these packets to carry live sensor data, that updates at a rate of 10-20Hz. From examples I've found on the web, BLE in this mode is mostly being used for "iBeacon" type implementations, where they are broadcasting static data. I cannot find any information on how advertising packets are filtered within the Android stack. It could be that they return one result per Bluetooth hardware address, or it could be the unique combination of address and data. The second option would work for this application. If starting and stopping the scan resets the filter, I can make something work as well.

Android的文件没有提及如何在扫描方法设备过滤功能。我已经能够在网络上找到试图解决同样的问题,其中有一个悬而未决的回应一个帖子:的 BLE:同周边扫描时多的发现。在iOS系统中,我的同事告诉我,有一个可以传递给扫描功能,使这一切成为可能的一个参数。

The Android documentation mentions nothing about how device filtering in the scan method works. I've been able to find one post on the net attempting to solve this same problem, which has an unresolved response: BLE: Multiple discovery of the same peripheral during scan. In iOS, my colleague informs me that there is a parameter that can be passed to the scan function that makes this possible.

我已经尝试从Android源的startLeScan()调用追踪code复出,但code是相当复杂的,而且使用抽象使得难以确定实施包含它的对象。我已经得到了最远的距离BluetoothManagerService类方法getBluetoothGatt()到IBluetoothGatt对象返回。该对象接收到开始扫描的要求。它被实例围绕<一href="https://github.com/android/platform_frameworks_base/blob/dbc51de44fe4f9a7f81528204250de32ec405d39/services/java/com/android/server/BluetoothManagerService.java#L790">line BluetoothManagerService.java 790 中对当前版本住在GitHub上。对象正在从消息的结果投,所以我怀疑,也许结果是手机/驱动器特有的。这超出了我的专业知识,能够进一步跟踪它。

I've attempted to trace the code back from the startLeScan() call in the Android source, but the code is quite complex, and the use of abstraction has made it difficult to identify the implementation of the object that contains it. The farthest I've gotten is to an IBluetoothGatt object returned from the BluetoothManagerService class method getBluetoothGatt(). This object receives the request to start scanning. It is being instantiated around line 790 of BluetoothManagerService.java on the current revision live on github. The object is being cast from the result of a message, so I suspect maybe the result is phone/driver specific. It is beyond my expertise to be able to trace it any further.

还有一个问题,我想解决的是如何快速扫描可打开和关闭切换。扫描是一个能源密集型操作,但数据的广播将在一个相当precise,实时定时定期发生。其结果是,这将是一个伟大的优化如果扫描可以开启和关闭,以使得该广播和扫描是同步的,以关闭另一90%以上的时间扫描仪。这将有可能需要进行实验测试

Another question I would like to resolve is how rapidly the scanning can be switched on and off. Scanning is a power intensive operation, yet the broadcast of data will happen periodically on a fairly precise, real time timer. As a result, it would be a great optimization if the scan can be switched on and off, such that the broadcast and scan are synchronized, with the scanner shut down the other 90%+ of the time. This will likely need to be tested experimentally.

我仍然在做可行性研究,看看这是否可能对我们的配件为Android。我的present手机还不能运行4.3版本,所以我没有办法检测/试验黑客这一点。

I'm still doing feasibility research to see if this is possible for our accessory for Android. My present phone cannot yet run version 4.3, so I have no way of testing/hacking this experimentally.

推荐答案

随着Android的4.3和4.4,到目前为止,这似乎是一个烂摊子:有些器件称 onLeScan(BluetoothDevice类设备,诠释RSSI,byte []的scanRecord)多次在一次扫描一台设备,有些则没有。有没有办法来配置过滤像iOS中(见的答案 的Arkadiusz Konior)。所以,我现在开始名单,因为我不能要求我的用户对他们的设备这样一个问题。

With Android 4.3 and 4.4 so far, it appears to be a mess: Some devices call onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) multiple times for one device in one scan, some don't. There is no way to configure the filtering like in iOS (see answer of Arkadiusz Konior). So, I now start a list, because I can't ask my users such a question about their device.

不过,在重新启动扫描大也对不过滤的设备没有问题。所以,我重新启动扫描大每个设备上了。

However, restarting scaning is also no problem on "not filtering" devices. So, I restart scaning on every device now.

没有过滤(连续调用onLeScan())

  • 三星Galaxy S4与4.2.2采用三星BLE SDK(我拥有的设备)
  • 的Nexus 5与4.4(按[vegarwe]增加,设备会不断给扫描记录附近的设备,同时扫描)
  • 在三星Galaxy S3 4.3(JSS15J.I9300XXUGMK6,我在测试该设备上)
  • 三星Galaxy S4与4.3和4.4.2采用Android SDK(由 arnaud.b ,没有建立补充提供)
  • 的HTC One 4.4.2 arnaud.b 的,没有提供任何版本号加) >
  • Samsung Galaxy S4 with 4.2.2 using Samsung BLE sdk (I owned that device)
  • Nexus 5 with 4.4 (added by [vegarwe]. The device will give scan records continuously for nearby devices while scanning)
  • Samsung Galaxy S3 with 4.3 (JSS15J.I9300XXUGMK6, I was testing on that device)
  • Samsung Galaxy S4 with 4.3 and 4.4.2 using Android SDK (added by arnaud.b, no build provided)
  • HTC One with 4.4.2 (added by arnaud.b, no build number provided)

过滤装置(适用于标准)

  • 的Nexus 4 4.3,4.4(我自己的设备)
  • 的Nexus 7 2013 4G 4.4.2(KOT49H,我在测试该设备上)
  • 在三星Galaxy S4的迷你与4.2.2(我在测试该设备上)
  • 摩托罗拉极限摩托(由 user1603602 ,没有对所提供的Andr​​oid版本信息加)
  • 摩托罗拉摩托摹4.3(falcon_umts,我的测试设备)
  • 在索尼Xperia平板Ž无线与Android 4.3(建设10.4.B.0.577,型号SGP311,我的测试设备)
  • OnePlus一个用5.0.1和5.1.1(氰12.1)
  • Nexus 4 with 4.3, 4.4 (I own that device)
  • Nexus 7 2013 4G with 4.4.2 (KOT49H, I was testing on that device)
  • Samsung Galaxy S4 mini with 4.2.2 (I was testing on this device)
  • Motorola Moto X (added by user1603602, no information about android version provided)
  • Motorola Moto G with 4.3 (falcon_umts, My testing device)
  • Sony Xperia Tablet Z Wifi with Android 4.3 (Build 10.4.B.0.577, Model SGP311, my testing device)
  • OnePlus One with 5.0.1 and 5.1.1 (Cyanogen 12.1)

未知筛选行为(请大家帮忙设备关联到某个组)

  • 的Nexus 7 2013 Jun 2013(不同的行为被报道像<一个href="http://stackoverflow.com/questions/20058450/how-to-continuously-get-rssi-without-connecting-to-the-ble-device#comment29883148_20058450">here.但我读更多报道说,它属于第一集团。)
  • 其他三星,HTC,摩托罗拉,...,设备
  • Nexus 7 2013 (Different behavior is reported like here. But I have read more reports that it's belonging to first group.)
  • Other SAMSUNG, HTC, Motorola, ..., devices

这篇关于安卓4.3:BLE:startLeScan的筛选行为()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆