星期三, 05. 九月 2018 02:03上午 – beautifulzzzz

Daydream

Key Terms And Concepts

澳门金沙国际 1

android.bluttooth

第一术语和概念

Here is a summary of key BLE terms and concepts:
以下是有关BLE的要害术语和概念的摘要

  • Generic Attribute Profile (GATT)—The GATT profile is a general
    specification for sending and receiving short pieces of data known
    as “attributes” over a BLE link. All current Low Energy application
    profiles are based on GATT.
    通用属性配置文件(GATT)–通用属性配置文件是一个通过BLE链接发送或接受短小一些数据或被称作“属性”的通用标准。当前颇具的低功耗应用配置文件都根据GATT。

    • The Bluetooth SIG defines many profiles for Low Energy devices.
      A profile is a specification for how a device works in a
      particular application. Note that a device can implement more
      than one profile. For example, a device could contain a heart
      rate monitor and a battery level detector.
    • 蓝牙( 蓝牙( Bluetooth® )® )技术联盟为低功耗设备定义了广大专属文件。配置文件是一个在特定应用中装置肿么办事的标准。请留心,一个配备得以兑现多少个布局文件。例如:一个装备可以分包一个心跳检测器和一个电量检测器
  • Attribute Protocol (ATT)—GATT is built on top of the Attribute
    Protocol (ATT). This is also referred to as GATT/ATT. ATT is
    optimized to run on BLE devices. To this end, it uses as few bytes
    as possible. Each attribute is uniquely identified by a Universally
    Unique Identifier (UUID), which is a standardized 128-bit format for
    a string ID used to uniquely identify information. The attributes
    transported by ATT are formatted as characteristics and services.
    特性协议(ATT)——GATT建立在性能协议(ATT)之上。那也被称为GATT/ATT。ATT经过优化,可在BLE设备上运行。为此,它利用尽可能少的字节。每个属性由通用唯一标识符(UUID)唯一标识,该标识符是用于唯一标识新闻的规则128-bit格式的字符串ID。由ATT传输的性质被格式化为特征和服务

  • Characteristic—A characteristic contains a single value and 0-n
    descriptors that describe the characteristic’s value. A
    characteristic can be thought of as a type, analogous to a class.
    特性——一个表征包括一个值和0至八个描述特征的叙述符。一个特征可以被认为是一种档次,类似于一个类。

  • Descriptor—Descriptors are defined attributes that describe a
    characteristic value. For example, a descriptor might specify a
    human-readable description, an acceptable range for a
    characteristic’s value, or a unit of measure that is specific to a
    characteristic’s value.
    叙述符——描述符是描述特征值的概念属性。例如:描述符也许可以指定一个人类可读的讲述,特征值的可承受范围,或特征值特有的单位

  • Service—A service is a collection of characteristics. For example,
    you could have a service called “Heart Rate Monitor” that includes
    characteristics such as “heart rate measurement.” You can find a
    list of existing GATT-based profiles and services on
    bluetooth.org.
    劳务——服务是一个表征的汇聚。例如:你可以使用一个誉为“心跳检测器”的服务,其中囊括“心跳测量”等特征。你可以在bluetooth.org上找到一个早已存在的依照GATT的配置文件和服务的列表

使能notify蓝牙( 蓝牙( Bluetooth® )® )低功耗设备,开发资源汇总。1、前言

上一篇讲了怎么编译安装BlueZ-5,本篇主要在于玩BlueZ,用命令行去操作BLE设备:

  • [BlueZ] 1、Download install and use the BlueZ and hcitool on PI
    3B+

澳门金沙国际 2

Virtual
Reality High
Performance

提供管理蓝牙( 蓝牙( Bluetooth® )® )功用的类,比如对设备的扫视,连接装置,和管理设施之间的传输数据。蓝牙( 蓝牙( Bluetooth® )® )API支持经典蓝牙5.0和低功耗蓝牙( 蓝牙( Bluetooth® )® )。

Roles and Responsibilities

2、gatttool —— 老工具趟坑

刚伊始接着 Get Started with Bluetooth Low Energy on
Linux
操作gatttool,发现坑太多(首要原因是工具老了):

采用sudo gatttool -b 4D:69:98:0E:91:5E -I去连接
发现会报错:Error: connect error: Connection refused (111)
终极参考LINK-11发现须要加random选项([\#1](https://stackoverflow.com/questions/32947807/cannot-connect-to-ble-device-on-raspberry-pi))

➜  ~  sudo gatttool -b 4D:69:98:0E:91:5E -I
[4D:69:98:0E:91:5E][LE]> connect
Attempting to connect to 4D:69:98:0E:91:5E
Error: connect error: Connection refused (111)
[4D:69:98:0E:91:5E][LE]> exit
➜  ~  sudo gatttool  -t random  -b 4D:69:98:0E:91:5E -I
[4D:69:98:0E:91:5E][LE]> connect
Attempting to connect to 4D:69:98:0E:91:5E
Connection successful
[4D:69:98:0E:91:5E][LE]> 
(gatttool:3104): GLib-WARNING **: Invalid file descriptor.

过几回会10S电动断开,网上说那一个工具老了,不提出用了([\#2](https://www.spinics.net/lists/linux-bluetooth/msg67617.html)):

There are new tools to use with GATT, bluetoothctl/bluetoothd is the preferred since with that you have GAP, etc, 
but if want to use a stand alone tool then I suggest you use btgatt-client.

澳门金沙国际 3

googlevr

Provides classes that manage Bluetooth functionality, such as scanning
for devices, connecting with devices, and managing data transfer between
devices. The Bluetooth API supports both “Classic Bluetooth” and
Bluetooth Low Energy.

角色和职分

Here are the roles and responsibilities that apply when an Android
device interacts with a BLE device:
此处是Android设备与BLE设备交互时适用的角色和义务:

  • Central vs. peripheral. This applies to the BLE connection itself.
    The device in the central role scans, looking for advertisement, and
    the device in the peripheral role makes the advertisement.
    主题和外设。那适用于BLE连接本身。中心设备角色扫描,寻找广告,同时外角色设备创造广告。

  • GATT server vs. GATT client. This determines how two devices talk to
    each other once they’ve established the connection.
    GATT服务器和GATT客户端。那决定了三个设备建立连接之后什么通讯。

To understand the distinction, imagine that you have an Android phone
and an activity tracker that is a BLE device. The phone supports the
central role; the activity tracker supports the peripheral role (to
establish a BLE connection you need one of each—two things that only
support peripheral couldn’t talk to each other, nor could two things
that only support central).
为了驾驭那个特点,若是你有所一个Android手机和一个BLE活动追踪器设备。手机担任大旨角色;活动追踪器担任外设角色(为了树立BLE连接,你需求部分的那样的装置。只支持外设角色的四个装备不能够互相通讯,同样,仅协理要旨角色的八个设施也不能相互通讯)

Once the phone and the activity tracker have established a connection,
they start transferring GATT metadata to one another. Depending on the
kind of data they transfer, one or the other might act as the server.
For example, if the activity tracker wants to report sensor data to the
phone, it might make sense for the activity tracker to act as the
server. If the activity tracker wants to receive updates from the phone,
then it might make sense for the phone to act as the server.
手机和运动追踪器一旦创制了延续,他们就起来互相传输GATT元数据。依赖于她们传输的多寡,其中的一个方始担任服务器。例如:假诺运动跟踪器希望将传感器数据报告给手机,那么活动跟踪器可能会担任服务器。怎么样运动追踪器想要从手机接收更新,那么手机可能会担任服务器。

In the example used in this document, the Android app (running on an
Android device) is the GATT client. The app gets data from the GATT
server, which is a BLE heart rate monitor that supports the Heart Rate
Profile. But you could alternatively design your Android app to play the
GATT server role. See BluetoothGattServer for more information.
其一文档中动用的例子中,Android
APP(运行在Android设备上)是GATT客户端。App从一个GATT服务器中获取数据,GATT服务器是一个提供心跳配置文件的BLE心跳检测器。然则你也得以设计你的安卓App充当GATT服务器的角色。有关详细音讯,请查看蓝牙5.0GattServer。

3、bluetoothctl——NB的新工具

指令行进入bluetoothctl操作环境([\#6](https://mcuoneclipse.com/2016/12/19/tutorial-ble-pairing-the-raspberry-pi-3-model-b-with-hexiwear/))

bluetoothctl

本人在表弟大上用lightblue模拟一个BLE设备ty_prod,之后对其service举行修改,调用scan
on举办搜索仍旧老的,
终极发现要先用remove移除以前的设备,之后再scan就相会世[NEW] Device 72:3B:E1:81:4E:4F ty_prod设备
注: 用lightblue模拟的装备的MAC不是一定的
注:
我发觉在lightblue中不管怎么模拟BLE设备,一旦被连上搜索到的service都是IPone的

[bluetooth]# devices
Device 28:ED:6A:A0:26:B7 ty_prod
Device 58:71:33:00:00:24 Bluetooth Keyboard
Device 00:1A:7D:DA:71:0A SHEN-PC
Device 94:87:E0:B3:AC:6F Mi Phone
[bluetooth]# remove 28:ED:6A:A0:26:B7 
...
[bluetooth]# scan on
Discovery started
[NEW] Device 72:3B:E1:81:4E:4F ty_prod
[bluetooth]# scan off
...
Discovery stopped
[bluetooth]# connect 72:3B:E1:81:4E:4F
Attempting to connect to 72:3B:E1:81:4E:4F
[CHG] Device 72:3B:E1:81:4E:4F Connected: yes
Connection successful
[ty_prod]

索性就用三星手机自带的劳动做测试了~

[ty_prod]# info
Device 28:ED:6A:A0:26:B7 (public)
    Name: tuya_mdev_test
    Alias: tuya_mdev_test
    Appearance: 0x0040
    Icon: phone
    Paired: yes
    Trusted: no
    Blocked: no
    Connected: yes
    LegacyPairing: no
    UUID: Fax                       (00001111-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: Current Time Service      (00001805-0000-1000-8000-00805f9b34fb)
    UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
    UUID: Battery Service           (0000180f-0000-1000-8000-00805f9b34fb)
    UUID: Vendor specific           (7905f431-b5ce-4e99-a40f-4b1e122d00d0)
    UUID: Vendor specific           (89d3502b-0f36-433a-8ef4-c502ad55f8dc)
    UUID: Vendor specific           (9fa480e0-4967-4542-9390-d343dc5d04ae)
    UUID: Vendor specific           (d0611e78-bbb4-4591-a5f8-487910ae4366)
[CHG] Device 28:ED:6A:A0:26:B7 ServicesResolved: no
[CHG] Device 28:ED:6A:A0:26:B7 Connected: no

俺们用Current 提姆(Tim)e 瑟维斯(Service)(Service),列出装有attributes操作如下:

[tuya_mdev_test]# menu gatt
[tuya_mdev_test]# list-attributes 28:ED:6A:A0:26:B7
...
Primary Service
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041
    00001805-0000-1000-8000-00805f9b34fb
    Current Time Service
Characteristic
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0045
    00002a0f-0000-1000-8000-00805f9b34fb
    Local Time Information
Characteristic
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042
    00002a2b-0000-1000-8000-00805f9b34fb
    Current Time
Descriptor
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042/desc0044
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
...

上面Current Time Service相应的劳务如下图:

澳门金沙国际 4

俺们挑选Current 提姆e举行操作UUID:0x2A2B

[ty_prod]# select-attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042
[tuya_mdev_test:/service0041/char0042]# read
Attempting to read /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042
[CHG] Attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042 Value:
  e2 07 09 05 01 24 11 03 f1 02                    .....$....      
  e2 07 09 05 01 24 11 03 f1 02                    .....$.... 
[tuya_mdev_test:/service0041/char0042]# attribute-info
Characteristic - Current Time
    UUID: 00002a2b-0000-1000-8000-00805f9b34fb
    Service: /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041
    Value:
  e2 07 09 05 01 2e 01 03 f5 02                    ..........      
    Notifying: yes
    Flags: read
    Flags: notify

读出结果大约意思应该是:2018-9/5-1:36:17 周三

读取一下0x180A的Device Information:

[tuya_mdev_test:/service0006/char0007]# select-attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047/char004a
[tuya_mdev_test:/service0047/char004a]# attribute-info
Characteristic - Model Number String
    UUID: 00002a24-0000-1000-8000-00805f9b34fb
    Service: /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047
    Flags: read
[tuya_mdev_test:/service0047/char004a]# read
Attempting to read /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047/char004a
[CHG] Attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047/char004a Value:
  69 50 68 6f 6e 65 36 2c 32                       iPhone6,2       
  69 50 68 6f 6e 65 36 2c 32                       iPhone6,2    

自然写、使能notify也很简短,看help即可。最终断开连接、并脱离!!!

[tuya_mdev_test:/service0047/char004a]# disconnect 28:ED:6A:A0:26:B7
Attempting to disconnect from 28:ED:6A:A0:26:B7
[CHG] Device 28:ED:6A:A0:26:B7 ServicesResolved: no
Successful disconnected
[CHG] Device 28:ED:6A:A0:26:B7 Connected: no
[bluetooth]# quit

澳门金沙国际 5

Google
VR for Android

有关很多别的的经典蓝牙( 蓝牙® )音信。可以看蓝牙5.0指南。有关很多别样的低功耗蓝牙5.0的新闻,可以看BLE指南。

BLE 权限


In order to use Bluetooth features in your application, you must declare
the Bluetooth permission BLUETOOTH. You need this permission to perform
any Bluetooth communication, such as requesting a connection, accepting
a connection, and transferring data.
为了在你的行使中动用蓝牙5.0风味,你不可以不要讲明蓝牙( 蓝牙® )权限 BLUETOOTH
。你要此权限才能举行别的蓝牙5.0通信,如:请求一个连连,接收一个连连,和传输数据。

If you want your app to initiate device discovery or manipulate
Bluetooth settings, you must also declare the BLUETOOTH_ADMIN
permission. Note: If you use the BLUETOOTH_ADMIN permission, then you
must also have the BLUETOOTH permission.
假如你想要你的app启动设备发现或控制蓝牙( 蓝牙® )设置,你必须也要表明BLUETOOTH_ADMIN 权限。注意:若是你用了 BLUETOOTH_ADMIN
权限,则还必须有 BLUETOOTH 权限。

Declare the Bluetooth permission(s) in your application manifest file.
For example:
声称蓝牙5.0权限在你的运用manifest文件,例如:

<uses-permission android:name=”android.permission.BLUETOOTH”/>
<uses-permission
android:name=”android.permission.BLUETOOTH_ADMIN”/>

If you want to declare that your app is available to BLE-capable devices
only, include the following in your app’s manifest:
只要您想要声明你的app仅援救有BLE成效的设施,在您的app的manifest中填上如下内容:

<uses-feature android:name=”android.hardware.bluetooth_le”
android:required=”true”/>
However, if you want to make your app available to devices that don’t
support BLE, you should still include this element in your app’s
manifest, but set required=”false”. Then at run-time you can determine
BLE availability by using PackageManager.hasSystemFeature():
下一场,借使你想要你的app可以被不帮忙BLE的装置获得,你依旧亟待包罗这一个因素在你的app的manifest文件中,不过,须要设置required为false。然后在您的代码运行时,你可以透过利用确认PackageManager.hasSystemFeature()方法来认同BLE是或不是可取得。

// Use this check to determine whether BLE is supported on the device. Then
// you can selectively disable BLE-related features.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
    Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
    finish();
}

Note: LE Beacons are often associated with location. In order to use
BluetoothLeScanner without a filter, you must request the user’s
permission by declaring either the ACCESS_COARSE_LOCATION or
ACCESS_FINE_LOCATION permission in your app’s manifest file. Without
these permissions, scans won’t return any results.

专注:LE信标平日与地方相关联。
为了在未曾过滤器的情形下利用蓝牙5.0LeScanner,您必须经过注脚应用程序的清单文件中的ACCESS_COARSE_LOCATION或ACCESS_FINE_LOCATION权限来呼吁用户的权力。

LINKS

[1].Cannot connect to BLE device on Raspberry
Pi
[2].Invalid file descriptor gatttool of bluez
5.32
[3].Get Started with Bluetooth Low Energy on
Linux
[4].Reverse Engineering a Bluetooth Low Energy Light
Bulb
[5].Doing Bluetooth Low Energy on
Linux
[6].Tutorial: BLE Pairing the Raspberry Pi 3 Model B with
Hexiwear

澳门金沙国际 6

@beautifulzzzz
智能硬件、物联网,热爱技术,关注产品
博客:http://blog.beautifulzzzz.com
园友交流群:414948975

GVR SDK
and NDK Release
Notes

For more information about Classic Bluetooth, see
the Bluetooth guide.
For more information about Bluetooth Low Energy, see the Bluetooth Low
Energy (BLE)
guide.

Setting Up BLE

设置BLE
Before your application can communicate over BLE, you need to verify
that BLE is supported on the device, and if so, ensure that it is
enabled. Note that this check is only necessary if
<uses-feature…/> is set to false.
在你利用可以通过BLE通讯从前,你必要证实这些装置是或不是帮忙BLE,若是可以,确认BLE是使能的。需求专注的是唯有当<uses-feature…/>设置为false那些是检查需求的

If BLE is not supported, then you should gracefully disable any BLE
features. If BLE is supported, but disabled, then you can request that
the user enable Bluetooth without leaving your application. This setup
is accomplished in two steps, using the BluetoothAdapter.
若果BLE不被协助,则你需求优雅的除能所有的BLE特性。若是BLE被协理,不过被除能了,则你须求请求用户使能蓝牙( 蓝牙( Bluetooth® )® )而不偏离的选取。该装置使用蓝牙Adapter在七个步骤中形成。

  1. Get the BluetoothAdapter
    获取BluetoothAdapter
    The BluetoothAdapter is required for any and all Bluetooth activity.
    The BluetoothAdapter represents the device’s own Bluetooth adapter
    (the Bluetooth radio). There’s one Bluetooth adapter for the entire
    system, and your application can interact with it using this object.
    The snippet below shows how to get the adapter. Note that this
    approach uses getSystemService() to return an instance of
    BluetoothManager, which is then used to get the adapter. Android 4.3
    (API Level 18) introduces BluetoothManager:
    富有的蓝牙Activity中都急需蓝牙5.0适配器。蓝牙5.0适配器表示了这么些设备自带的蓝牙( 蓝牙5.0® )适配器(蓝牙有线电)。整个连串有一个蓝牙5.0适配器,你的施用能够通过这几个目的和它交互。上面的代码片段浮现了怎么得到这些适配器。需要小心的是以此格局运用getSystem瑟维斯(Service)()去获取蓝牙Manager的一个实例,然后用于获取适配器。Android
    4.3(API Level 18)介绍了蓝牙( Bluetooth® )Manager。

    private BluetoothAdapter mBluetoothAdapter;
    ...
    // Initializes Bluetooth adapter.
    final BluetoothManager bluetoothManager =
            (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = bluetoothManager.getAdapter();
    
  2. Enable Bluetooth
    使能蓝牙5.0
    Next, you need to ensure that Bluetooth is enabled. Call isEnabled()
    to check whether Bluetooth is currently enabled. If this method
    returns false, then Bluetooth is disabled. The following snippet
    checks whether Bluetooth is enabled. If it isn’t, the snippet
    displays an error prompting the user to go to Settings to enable
    Bluetooth:
    接下去,你须求认可蓝牙( Bluetooth® )是使能的。调用isEnable()去反省是不是蓝牙5.0脚下是还是不是使能。若是那一个办法重回false,则蓝牙5.0是除能的。接下来的代码片段检查是或不是蓝牙( 蓝牙5.0® )是是能的。若是没有使能,代码片段会展现一个用户去设置开启蓝牙( Bluetooth® )的不当提醒。

    // Ensures Bluetooth is available on the device and it is enabled. If not,
    // displays a dialog requesting user permission to enable Bluetooth.
    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }
    

Note: The REQUEST_ENABLE_BT constant passed to
startActivityForResult(android.content.Intent, int) is a
locally-defined integer (which must be greater than 0) that the system
passes back to you in your onActivityResult(int, int,
android.content.Intent) implementation as the requestCode parameter.

注意:传送给startActivityForResult()的常量REQUEST_ENABLE_BT是一个地面定义的平头(必须大于0),这么些平头系统会落实为requestCode参数,在您的onActivityResult()方法中,回传给您。

http://www.apkmirror.com/apk/google-inc

蓝牙( Bluetooth® ) APIs 可以使得应用拥有上边功用:

Finding BLE Devices

寻找BLE设备

To find BLE devices, you use the startLeScan() method. This method takes
a BluetoothAdapter.LeScanCallback as a parameter. You must implement
this callback, because that is how scan results are returned. Because
scanning is battery-intensive, you should observe the following
guidelines:
要寻找BLE设备,你可以拔取startLeScan()方法。那些主意包罗一个蓝牙5.0Adapter.LeScanCallback作为参数。你必要求兑现那几个回调,因为那是何等回到扫描结果的(因为扫描结果是由此这么些重回的)。因为扫描是电池密集型的,你必要依据以下的清规戒律:

  • As soon as you find the desired device, stop scanning.
    若果您一找到了想要的装备,就停下扫描
  • Never scan on a loop, and set a time limit on your scan. A device
    that was previously available may have moved out of range, and
    continuing to scan drains the battery.
    切勿在循环里扫描,且要设置一个扫描时间限制。
    一个事先可以取得的配备可能已经移出了限定,持续围观消耗电池。

The following snippet shows how to start and stop a scan:
下边的代码片段显示了哪些开头和终止扫描:

/**
 * Activity for scanning and displaying available BLE devices.
 */
public class DeviceScanActivity extends ListActivity {

    private BluetoothAdapter mBluetoothAdapter;
    private boolean mScanning;
    private Handler mHandler;

    // Stops scanning after 10 seconds.
    private static final long SCAN_PERIOD = 10000;
    ...
    private void scanLeDevice(final boolean enable) {
        if (enable) {
            // Stops scanning after a pre-defined scan period.
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mScanning = false;
                    mBluetoothAdapter.stopLeScan(mLeScanCallback);
                }
            }, SCAN_PERIOD);

            mScanning = true;
            mBluetoothAdapter.startLeScan(mLeScanCallback);
        } else {
            mScanning = false;
            mBluetoothAdapter.stopLeScan(mLeScanCallback);
        }
        ...
    }
...
}

If you want to scan for only specific types of peripherals, you can
instead call startLeScan(UUID[], BluetoothAdapter.LeScanCallback),
providing an array of UUID objects that specify the GATT services your
app supports.
即使您想扫描特定项目标外设,你可以轮换调用startLeScan(UUID[],
蓝牙5.0Adapter.LeScanCallback),提供一个特定的您的app扶助的GATT服务UUID设备数组。

Here is an implementation of the BluetoothAdapter.LeScanCallback, which
is the interface used to deliver BLE scan results:
那里有一个蓝牙艾达(Ada)pter.LeScanCallback的贯彻,它是一个接口,用来传输BLE扫描结果:

private LeDeviceListAdapter mLeDeviceListAdapter;
...
// Device scan callback.
private BluetoothAdapter.LeScanCallback mLeScanCallback =
        new BluetoothAdapter.LeScanCallback() {
    @Override
    public void onLeScan(final BluetoothDevice device, int rssi,
            byte[] scanRecord) {
        runOnUiThread(new Runnable() {
           @Override
           public void run() {
               mLeDeviceListAdapter.addDevice(device);
               mLeDeviceListAdapter.notifyDataSetChanged();
           }
       });
   }
};

Note: You can only scan for Bluetooth LE devices or scan for Classic
Bluetooth devices, as described in Bluetooth. You cannot scan for both
Bluetooth LE and classic devices at the same time.

在意:你可以扫描低功耗蓝牙( 蓝牙® )设备或经典蓝牙设备,如蓝牙5.0所述。你无法而且扫视低功耗蓝牙设备和经文蓝牙5.0设备。

com.google.vr.vrcore

1.对此其余的蓝牙5.0设备的围观(包蕴BLE设备)

Connecting to a GATT Server

连接GATT服务器

The first step in interacting with a BLE device is connecting to it—
more specifically, connecting to the GATT server on the device. To
connect to a GATT server on a BLE device, you use the connectGatt()
method. This method takes three parameters: a Context object,
autoConnect (boolean indicating whether to automatically connect to the
BLE device as soon as it becomes available), and a reference to a
BluetoothGattCallback:
与BLE设备的交互的率先步是连接受它-更现实的说,连接在那些BLE设备上的GATT服务器。为了连接上在这一个BLE设备上的GATT服务器,你可以使用connectGatt()方法。这几个法子有七个参数:一个上下文对象,是或不是自动连接(一个布尔值,表明只要那个BLE设备是足以博得的,是不是自动的延续上它),一个指向蓝牙( Bluetooth® )GattCallback的引用。

mBluetoothGatt = device.connectGatt(this, false, mGattCallback);

This connects to the GATT server hosted by the BLE device, and returns a
BluetoothGatt instance, which you can then use to conduct GATT client
operations. The caller (the Android app) is the GATT client. The
BluetoothGattCallback is used to deliver results to the client, such as
connection status, as well as any further GATT client operations.
那会连接受由BLE设备管理的GATT服务器,并回到一个蓝牙( Bluetooth® )Gatt实例,然后您能够采纳它来进行GATT客户端操作。调用者(Android
app)是GATT客户端。蓝牙5.0GattCallback用来传送结果给客户端,例如连接景况,以及其余更进一步的GATT客户端操作。

In this example, the BLE app provides an activity
(DeviceControlActivity) to connect, display data, and display GATT
services and characteristics supported by the device. Based on user
input, this activity communicates with a Service called
BluetoothLeService, which interacts with the BLE device via the Android
BLE API:
以此事例中,那些BLE应用提供一个平移(DeviceControlActivity)用于连接装置,呈现由装备提供的多少,GATT服务和特点。基于用户输入,那一个活动与一个名为蓝牙( Bluetooth® )LeService(Service)的劳务通讯,该服务通过Android
BLE API与BLE设备开展相互:

// A service that interacts with the BLE device via the Android BLE API.
public class BluetoothLeService extends Service {
    private final static String TAG = BluetoothLeService.class.getSimpleName();

    private BluetoothManager mBluetoothManager;
    private BluetoothAdapter mBluetoothAdapter;
    private String mBluetoothDeviceAddress;
    private BluetoothGatt mBluetoothGatt;
    private int mConnectionState = STATE_DISCONNECTED;

    private static final int STATE_DISCONNECTED = 0;
    private static final int STATE_CONNECTING = 1;
    private static final int STATE_CONNECTED = 2;

    public final static String ACTION_GATT_CONNECTED =
            "com.example.bluetooth.le.ACTION_GATT_CONNECTED";
    public final static String ACTION_GATT_DISCONNECTED =
            "com.example.bluetooth.le.ACTION_GATT_DISCONNECTED";
    public final static String ACTION_GATT_SERVICES_DISCOVERED =
            "com.example.bluetooth.le.ACTION_GATT_SERVICES_DISCOVERED";
    public final static String ACTION_DATA_AVAILABLE =
            "com.example.bluetooth.le.ACTION_DATA_AVAILABLE";
    public final static String EXTRA_DATA =
            "com.example.bluetooth.le.EXTRA_DATA";

    public final static UUID UUID_HEART_RATE_MEASUREMENT =
            UUID.fromString(SampleGattAttributes.HEART_RATE_MEASUREMENT);

    // Various callback methods defined by the BLE API.
    private final BluetoothGattCallback mGattCallback =
            new BluetoothGattCallback() {
        @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status,
                int newState) {
            String intentAction;
            if (newState == BluetoothProfile.STATE_CONNECTED) {
                intentAction = ACTION_GATT_CONNECTED;
                mConnectionState = STATE_CONNECTED;
                broadcastUpdate(intentAction);
                Log.i(TAG, "Connected to GATT server.");
                Log.i(TAG, "Attempting to start service discovery:" +
                        mBluetoothGatt.discoverServices());

            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                intentAction = ACTION_GATT_DISCONNECTED;
                mConnectionState = STATE_DISCONNECTED;
                Log.i(TAG, "Disconnected from GATT server.");
                broadcastUpdate(intentAction);
            }
        }

        @Override
        // New services discovered
        public void onServicesDiscovered(BluetoothGatt gatt, int status) {
            if (status == BluetoothGatt.GATT_SUCCESS) {
                broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
            } else {
                Log.w(TAG, "onServicesDiscovered received: " + status);
            }
        }

        @Override
        // Result of a characteristic read operation
        public void onCharacteristicRead(BluetoothGatt gatt,
                BluetoothGattCharacteristic characteristic,
                int status) {
            if (status == BluetoothGatt.GATT_SUCCESS) {
                broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
            }
        }
     ...
    };
...
}

When a particular callback is triggered, it calls the appropriate
broadcastUpdate() helper method and passes it an action. Note that the
data parsing in this section is performed in accordance with the
Bluetooth Heart Rate Measurement profile specifications:
当特定的回调被触发时,它调用相应的broadcastUpdate()支持方法并传递一个动作。请留意,本节中的数据解析是根据蓝牙5.0心率测量配置文件规范执行的:

private void broadcastUpdate(final String action) {
    final Intent intent = new Intent(action);
    sendBroadcast(intent);
}

private void broadcastUpdate(final String action,
                             final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // This is special handling for the Heart Rate Measurement profile. Data
    // parsing is carried out as per profile specifications.
    if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
        int flag = characteristic.getProperties();
        int format = -1;
        if ((flag & 0x01) != 0) {
            format = BluetoothGattCharacteristic.FORMAT_UINT16;
            Log.d(TAG, "Heart rate format UINT16.");
        } else {
            format = BluetoothGattCharacteristic.FORMAT_UINT8;
            Log.d(TAG, "Heart rate format UINT8.");
        }
        final int heartRate = characteristic.getIntValue(format, 1);
        Log.d(TAG, String.format("Received heart rate: %d", heartRate));
        intent.putExtra(EXTRA_DATA, String.valueOf(heartRate));
    } else {
        // For all other profiles, writes the data formatted in HEX.
        final byte[] data = characteristic.getValue();
        if (data != null && data.length > 0) {
            final StringBuilder stringBuilder = new StringBuilder(data.length);
            for(byte byteChar : data)
                stringBuilder.append(String.format("%02X ", byteChar));
            intent.putExtra(EXTRA_DATA, new String(data) + "\n" +
                    stringBuilder.toString());
        }
    }
    sendBroadcast(intent);
}

Back in DeviceControlActivity, these events are handled by a
BroadcastReceiver:
归来DeviceControlActivity,这几个事件都被一个布罗德(Broad)castReceiver接收处理:

// Handles various events fired by the Service.
// ACTION_GATT_CONNECTED: connected to a GATT server.
// ACTION_GATT_DISCONNECTED: disconnected from a GATT server.
// ACTION_GATT_SERVICES_DISCOVERED: discovered GATT services.
// ACTION_DATA_AVAILABLE: received data from the device. This can be a
// result of read or notification operations.
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
            mConnected = true;
            updateConnectionState(R.string.connected);
            invalidateOptionsMenu();
        } else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
            mConnected = false;
            updateConnectionState(R.string.disconnected);
            invalidateOptionsMenu();
            clearUI();
        } else if (BluetoothLeService.
                ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
            // Show all the supported services and characteristics on the
            // user interface.
            displayGattServices(mBluetoothLeService.getSupportedGattServices());
        } else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
            displayData(intent.getStringExtra(BluetoothLeService.EXTRA_DATA));
        }
    }
};

com.google.android.vr.home

2.为配对的蓝牙5.0设备查询当地蓝牙5.0适配器

Reading BLE Attributes

读取BLE属性

Once your Android app has connected to a GATT server and discovered
services, it can read and write attributes, where supported. For
example, this snippet iterates through the server’s services and
characteristics and displays them in the UI:
假诺您的Android应用连接到GATT服务器并发现了劳务,如若GATT服务器支持,它就足以读取和写入属性了。例如:这一片段代码遍历了这些服务器的劳务和特色,,并将其出示在UI中:

public class DeviceControlActivity extends Activity {
    ...
    // Demonstrates how to iterate through the supported GATT
    // Services/Characteristics.
    // In this sample, we populate the data structure that is bound to the
    // ExpandableListView on the UI.
    private void displayGattServices(List<BluetoothGattService> gattServices) {
        if (gattServices == null) return;
        String uuid = null;
        String unknownServiceString = getResources().
                getString(R.string.unknown_service);
        String unknownCharaString = getResources().
                getString(R.string.unknown_characteristic);
        ArrayList<HashMap<String, String>> gattServiceData =
                new ArrayList<HashMap<String, String>>();
        ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData
                = new ArrayList<ArrayList<HashMap<String, String>>>();
        mGattCharacteristics =
                new ArrayList<ArrayList<BluetoothGattCharacteristic>>();

        // Loops through available GATT Services.
        for (BluetoothGattService gattService : gattServices) {
            HashMap<String, String> currentServiceData =
                    new HashMap<String, String>();
            uuid = gattService.getUuid().toString();
            currentServiceData.put(
                    LIST_NAME, SampleGattAttributes.
                            lookup(uuid, unknownServiceString));
            currentServiceData.put(LIST_UUID, uuid);
            gattServiceData.add(currentServiceData);

            ArrayList<HashMap<String, String>> gattCharacteristicGroupData =
                    new ArrayList<HashMap<String, String>>();
            List<BluetoothGattCharacteristic> gattCharacteristics =
                    gattService.getCharacteristics();
            ArrayList<BluetoothGattCharacteristic> charas =
                    new ArrayList<BluetoothGattCharacteristic>();
           // Loops through available Characteristics.
            for (BluetoothGattCharacteristic gattCharacteristic :
                    gattCharacteristics) {
                charas.add(gattCharacteristic);
                HashMap<String, String> currentCharaData =
                        new HashMap<String, String>();
                uuid = gattCharacteristic.getUuid().toString();
                currentCharaData.put(
                        LIST_NAME, SampleGattAttributes.lookup(uuid,
                                unknownCharaString));
                currentCharaData.put(LIST_UUID, uuid);
                gattCharacteristicGroupData.add(currentCharaData);
            }
            mGattCharacteristics.add(charas);
            gattCharacteristicData.add(gattCharacteristicGroupData);
         }
    ...
    }
...
}

Google
Inc. Daydream
(Daydream)

3.建立RFCOMM channels/sockets.

Receiving GATT Notifications

Google
Inc. Google VR Services
(Daydream)

4.连接在其余设施上指定的sockets

接收GATT通知

It’s common for BLE apps to ask to be notified when a particular
characteristic changes on the device. This snippet shows how to set a
notification for a characteristic, using the
setCharacteristicNotification() method:
当设备上一个特定的性状爆发转移时,BLE应用去要求被通报很广阔。那段代码体现了怎么通过行使setCharacteristicNotification()方法,去为一个特色设置一个通知:

private BluetoothGatt mBluetoothGatt;
BluetoothGattCharacteristic characteristic;
boolean enabled;
...
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
...
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
        UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);

Once notifications are enabled for a characteristic, an
onCharacteristicChanged() callback is triggered if the characteristic
changes on the remote device:
假定一个特点被使能通告,假若远程设备上的那几个特点暴发了改动,一个onCharacteristicChanged()回调被触发。

@Override
// Characteristic notification
public void onCharacteristicChanged(BluetoothGatt gatt,
        BluetoothGattCharacteristic characteristic) {
    broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
}

What is
Google
Daydream

5.与其余装备之间数据传输

Closing the Client App

Daydream Performance
HUD

6.与BLE设备调换。比如类似传感器,心率监视器,健身设施,等等

关门客户端app

Once your app has finished using a BLE device, it should call close() so
the system can release resources appropriately:
假诺您的应用程序已毕使用BLE设备,它应当调用close(),以便系统能够正确释放资源:

public void close() {
    if (mBluetoothGatt == null) {
        return;
    }
    mBluetoothGatt.close();
    mBluetoothGatt = null;
}

后记:本文翻译自google开发者网站。链接如下:
https://developer.android.google.cn/guide/topics/connectivity/bluetooth-le.html
欢迎转发,但请尊重小编工作,留下本文后记
作者:Jaesoon
邮箱:jayyuz@163.com
日期:2017-09-17

Daydream
Controller手柄数据的辨析

7.作为GATTclient或GATT服务端

How do I
fix my Daydream
controller

接纳那个APIs来终结蓝牙( 蓝牙5.0® )之间的调换,一个应用程序必须注明BLUETOOTH权力。对于一些杰出的成效。如请求设备发现,也非得BLUETOOTH_ADMIN权限。

Google
Daydream Controller
Teardown

提示:不是全方位的Android设备都提供了蓝牙( Bluetooth® )作用。

Daydream
controller : Comprehensive
guide

The Bluetooth APIs let applications:

Use the
Daydream View controller and
headset

  • Scan for other Bluetooth devices (including BLE devices).
  • Query the local Bluetooth adapter for paired Bluetooth devices.
  • Establish RFCOMM channels/sockets.
  • Connect to specified sockets on other devices.
  • Transfer data to and from other devices.
  • Communicate with BLE devices, such as proximity sensors, heart rate
    monitors, fitness devices, and so on.
  • Act as a GATT client or a GATT server (BLE).

谷歌Daydream
VR平台应用必要:怎样规划VR应用

To perform Bluetooth communication using these APIs, an application must
declare the BLUETOOTH permission. Some additional functionality, such
as requesting device discovery, also requires
the BLUETOOTH_ADMIN permission.

 

Note: Not all Android-powered devices provide Bluetooth
functionality.

Algorithm

接口:

BluetoothAdapter.LeScanCallback
:用来提供LE扫描结果的回调接口

BluetoothProfile:Bluetooth
Profiles的公共APIs

BluetoothProfile.ServiceListener:蓝牙( Bluetooth® )Profile
IPC client与service的总是和断开时的一个布告接口

Conversion
Quaternion to
Euler

Interfaces


BluetoothAdapter.LeScanCallback Callback interface used to deliver LE scan results. 
BluetoothProfile Public APIs for the Bluetooth Profiles. 
BluetoothProfile.ServiceListener An interface for notifying BluetoothProfile IPC clients when they have been connected or disconnected to the service. 

Conversion
Euler to
Quaternion

类:

BluetoothA2dp:这么些类提供控制蓝牙5.0A2DP profile的公共APIs

BluetoothAdapter:代表当地设备的蓝牙adapter.
BluetoothAssignedNumbers:蓝牙5.0分配号码

BluetoothClass:代表一个蓝牙( Bluetooth® )类。它形容叙述了配备的形似特征(characteristics)和能力(capabilities)

BluetoothClass.Device:定义全体装备类的常量

BluetoothClass.Device.Major:定义全体重大装备类的常量

BluetoothClass.Service:定义全体服务类的常量

BluetoothDevice:代表一个中距离蓝牙5.0设备

=============================================================================================

BluetoothGatt:蓝牙GATT
Profile的公共APIs

BluetoothGattCallback:那几个抽象类用于落到实处蓝牙5.0Gatt回调

BluetoothGattCharacteristic:代表一个蓝牙GATT Characteristic.

                                              一个GATT
Characteristic是用来协会一个GATT
service,BluetoothGattService的主干数据元素

BluetoothGattDescriptor:代表一个蓝牙GATT Descriptor.

                                           GATT Descriptor包蕴一个GATT
characteristic,BluetoothGattCharacteristic的额外新闻和属性.

Classes


BluetoothA2dp This class provides the public APIs to control the Bluetooth A2DP profile. 
BluetoothAdapter Represents the local device Bluetooth adapter. 
BluetoothAssignedNumbers Bluetooth Assigned Numbers. 
BluetoothClass Represents a Bluetooth class, which describes general characteristics and capabilities of a device. 
BluetoothClass.Device Defines all device class constants. 
BluetoothClass.Device.Major Defines all major device class constants. 
BluetoothClass.Service Defines all service class constants. 
BluetoothDevice Represents a remote Bluetooth device. 
BluetoothGatt Public API for the Bluetooth GATT Profile. 
BluetoothGattCallback This abstract class is used to implement BluetoothGatt callbacks. 
BluetoothGattCharacteristic Represents a Bluetooth GATT Characteristic

A GATT characteristic is a basic data element used to construct a GATT service,BluetoothGattService

BluetoothGattDescriptor Represents a Bluetooth GATT Descriptor

GATT Descriptors contain additional information and attributes of a GATT characteristic,BluetoothGattCharacteristic

BluetoothGattServer Public API for the Bluetooth GATT Profile server role. 
BluetoothGattServerCallback This abstract class is used to implement BluetoothGattServer callbacks. 
BluetoothGattService Represents a Bluetooth GATT Service

Gatt Service contains a collection of BluetoothGattCharacteristic, as well as referenced services. 

BluetoothHeadset Public API for controlling the Bluetooth Headset Service. 
BluetoothHealth Public API for Bluetooth Health Profile. 
BluetoothHealthAppConfiguration The Bluetooth Health Application Configuration that is used in conjunction with the BluetoothHealthclass. 
BluetoothHealthCallback This abstract class is used to implement BluetoothHealth callbacks. 
BluetoothManager High level manager used to obtain an instance of an BluetoothAdapter and to conduct overall Bluetooth Management. 
BluetoothServerSocket A listening Bluetooth socket. 
BluetoothSocket A connected or connecting Bluetooth socket. 

BluetoothGattServer:蓝牙5.0GATT Profileserver角色的公共APIs.

BluetoothGattServerCallback:这几个抽象类用于落实BluetoothGattServer回调.

BluetoothGattService:代表一个BluetoothGATT Service.

================================================================================

BluetoothHeadset:控制蓝牙( 蓝牙® )耳麦(Headset)服务的公共API.

BluetoothHealth:蓝牙Health
Profile的公共API.

BluetoothHealthAppConfiguration:The
Bluetooth Health Application
Configuration(配置)用来与BluetoothHealth类结合.

BluetoothHealthCallback:用于落到实处BluetoothHealth回调的抽象类

BluetoothManager:用来收获BluetoothAdapter的实例的管理者,举行周全的蓝牙( 蓝牙5.0® )管理

BluetoothServerSocket:一个监听蓝牙( 蓝牙( Bluetooth® )® )的socket

BluetoothSocket:一个已连续或正在连接的蓝牙( 蓝牙5.0® )socket.

 

ATW

Timewarp

Asynchronous
timewarp

How Does
Time Warping Work

Difference_between_ATW_ASW_and_Reprojection 

 

Bluetooth

Bluetooth Core
Specification

HID-over-GATT

NordicSemiconductor

Dialog-semiconductor

SmartBond™
DA14681

Android
Bluetooth Low
Energy

Nordic SDK and
Documentation

Calculate
throughput for a BLE
link

Introduction to
Bluetooth Low
Energy

Android
Lollipop: Bluetooth LE
Matures

Bluetooth Low
Energy vs. Classic
Bluetooth

Getting
Started with Bluetooth Low
Energy

Maximizing BLE
Throughput on iOS and
Android

How
different BLE packet types influence
throughput

Analysis
of Latency Performance of Bluetooth Low Energy (BLE)
Networks

FTS4BT™
Bluetooth® Protocol Analyzer and Packet
Sniffer

CPAS-11(Frontline_16.10.12321.12610)

 

Latency

Front
Buffer
Rendering

Reducing
latency in mobile VR by using single buffered strip
rendering

The
importance of fine-grained GPU preemption support for
VR

 

Tools

dotPeek

 

Touch

IQS525-B000

 

澳门金沙国际 ,Unity

Unity
Editor and Android Runtime for
Daydream

Unity
Download

GVR-Unity-SDK

Unity3d
Quaternion

Unity优化技巧

四元数(Quaternion)和旋转

 

Qualcomm

基于骁龙
VR SDK的VR图形优化

 

EGL

EGL10

Tracer
for OpenGL
ES

相关文章