![]()
我想用Android设备获得BLE信标的发射功率.
我在这里定义了Tx电源的分配编号.
public class Assignednumbers { ... public static final byte TXPOWER = 0x0A; ...}然后,我做了一个函数来在这里获得发射功率.
public class AdvertisingData { ... public static Integer getTxPowerLevel(byte[] scanRecord) { // Check for BLE 4.0 TX power int pos = findCodeInBuffer(scanRecord, Assignednumbers.TXPOWER); if (pos > 0) { return Integer.valueOf(scanRecord[pos]); } return null; } ... private static int findCodeInBuffer(byte[] buffer, byte code) { final int length = buffer.length; int i = 0; while (i < length - 2) { int len = buffer[i]; if (len < 0) { return -1; } if (i + len >= length) { return -1; } byte tcode = buffer[i + 1]; if (tcode == code) { return i + 2; } i += len + 1; } return -1; } ...}最后,我放置了一行代码来检查Tx功率.
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { ... System.out.println("TxPower: " + AdvertisingData.getTxPowerLevel(scanRecord)); ...};但是,结果如下所示.
04-22 16:34:14.249: I/System.out(29133): TxPower: null
onScanResult()的日志是
04-22 16:34:14.247: D/BluetoothLeScanner(29133): onScanResult() –
ScanResult{mDevice=90:59:AF:0F:31:01, mScanRecord=ScanRecord
[mAdvertiseFlags=6, mServiceUuIDs=null, mManufacturerSpecificdata={76=[2, 21,
-43, 117, 98, 71, 87, -94, 67, 68, -111, 93, -107, -103, 73, 121, 64, -89, 0,
0, 0, 0, -60]}, mServiceData={0000180a-0000-1000-8000-00805f9b34fb=[1, 49, 15,
-81, 89, -112, -60, 0, 0, 0, 0]}, mTxPowerLevel=-2147483648,
mDevicename=pebBLE], mRSSi=-79, mTimestampNanos=8204624857836}
如何获得正确的发射功率值?该值应为4、0或-23(dBm).
解决方法:
您在上面说了信标-我认为您实际上是在尝试获得iBeacon校准的传输功率,这与GAP 0x0A不同. iBeacon TxPower只是广告中制造数据的一部分.这里的广告包有完整的细分-What is the iBeacon Bluetooth Profile
您可以看到scanRecord中有两个可变大小的部分,并且TxPower是最后一个字节(不跟0A一样,在这个例子中,fitbit就是http://j2abro.blogspot.com/2014/06/analyzing-bluetooth-advertising-with.html).
查看您的onScanResult,我相信校准后的TxPower为-60,这是1米处的RSSi测量值.这篇文章中有一个逆向工程TxPower以米为单位的距离的示例-Understanding ibeacon distancing
总结以上是内存溢出为你收集整理的在Android中获取BLE Beacon的Tx功能全部内容,希望文章能够帮你解决在Android中获取BLE Beacon的Tx功能所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)