Brillo: Bluetooth on DragonBoard 410c @ brillo-m10-dev

今天看一下Brillo系统中的bluetooth模块。

  • Brillo系统Bluetooth框架

由于Brillo系统复用了Android系统相当一部代码,与Bluetooth相关的代码也基本上复用了。在brillo-m10-dev分支中,Bluetooth协议栈的代码存放在system/bt目录下,而bluetoothtbd系统服务相关的代码也是在这个目录中,具体位于system/bt/service目录下,同时在这个目录下,会生成下面这几个模块:

1. bluetoothtbd

2. bluetooth-cli

3. bt-example-hr-server – Heart Rate GATT service example

Android系统bluetooth框架:

图片来自:https://source.android.com/devices/bluetooth.html

2016_03_29_ape_fwk_bluetooth

由于Brillo系统只有native的代码,所以在图中其实只包含Bluetooth Stack与Vendor Extensions这两个部份。另外还包含bluetoothtbd模块,用于配置bluetooth模块,建立GATT service或者GATT client。

  • Bluetooth相关的一些命令

1. 相关的帮助信息:

$ adb shell
# bluetooth-cli                                                                                                                                                                                                   
Fluoride Command-Line Interface

Type "help" to see possible commands.

[FCLI] help

	help			Display this message
	disable			Disable Bluetooth
	enable			Enable Bluetooth
	get-state		Get the current adapter state
	is-enabled		Return if Bluetooth is enabled
	get-local-address	Get the local adapter address
	set-local-name		Set the local adapter name
	get-local-name		Get the local adapter name
	adapter-info		Print adapter properties
	supports-multi-adv	Whether multi-advertisement is currently supported
	register-ble		Register with the Bluetooth Low Energy interface
	unregister-ble		Unregister from the Bluetooth Low Energy interface
	unregister-all-ble	Unregister all clients from the Bluetooth Low Energy interface
	register-gatt		Register with the Bluetooth GATT Client interface
	unregister-gatt		Unregister from the Bluetooth GATT Client interface
	connect-le		Connect to LE device (-h for options)
	disconnect-le		Disconnect LE device (-h for options)
	set-mtu		Set MTU (-h for options)
	start-adv		Start advertising (-h for options)
	stop-adv		Stop advertising
	start-le-scan		Start LE device scan (-h for options)
	stop-le-scan		Stop LE device scan

2. 查看Bluetooth adapter的相关信息:

[FCLI] adapter-info
Adapter Properties: 
	Address: 00:00:00:00:A5:AD
	State: ADAPTER_STATE_ON
	Name: QCOM-BTD
	Multi-Adv. supported: true

可以看到设设备是支持Multi-Adv的。

3. 作为一个Bluetooth – Central

通过bluetooth-cli提供的start-le-scan, stop-le-scan, connect-le, disconnect-le去扫描、关连相关的ble外设:

[FCLI] start-le-scan
Command status: success
[FCLI] stop-le-scan
Command status: success
[FCLI] start-le-scan -d
Command status: success
Scan result: [FC:CD:6E:4B:8D:24] - RSSI: -57 - Record: 0201060A0947616C61787920413903030D18[FCLI] 
[FCLI] connect-le FC:CD:6E:4B:8D:24
Command status: success
Connection state: [FC:CD:6E:4B:8D:24 connected: true ] - status: 0 - client_id: 5[FCLI]

4. 能否作为一个Bluetooth Perheral呢:

[FCLI] register-ble
Command status: success
Registered BLE client with ID: 4[FCLI]
[FCLI] start-adv -n -t -c
Command status: success
Advertising start status: success

如果你的手机支持BLE,可以在蓝牙列表中找到一个名为QCOM_BTD的一个设备。

  • 运行sample app – bt-example-hr-server

在system/bt/service/下面有一个bt-example-hr-server的sample app,可以通过它来学习如何开发一个简单的BLE server app。先编译出来push到DragonBoard 410c中看看效果:

$ mmm system/bt/service
$ adb remount
$ adb sync system
$ adb shell bt-example-hr-server
[0321/155621:INFO:server_main.cpp(92)] Starting GATT Heart Rate Service sample
[0321/155621:INFO:heart_rate_server.cpp(228)] Heart Rate server registered - server_if: 4
[0321/155621:INFO:heart_rate_server.cpp(229)] Populating attributes
[0321/155621:INFO:heart_rate_server.cpp(302)] Initiated EndServiceDeclaration request
[0321/155621:INFO:heart_rate_server.cpp(325)] Heart Rate service added
[0321/155621:INFO:server_main.cpp(128)] Heart Rate service started successfully

做完这些之后,你还需要通过bluetooth-cli开启ble adv(start-adv),不然手机没办法扫描到这个ble外设。

手机相关的app可以使用development/samples/browseable/BluetoothLeGatt @ android-5.1.1_r15中的代码。通过这个App,你可以连接ble设备,查看设备所提供的服务(Heart Rate Service):

2016_03_29_dragonboard_410c_ble

  • 相关的参考文档:
  1. https://source.android.com/devices/bluetooth.html

《Brillo: Bluetooth on DragonBoard 410c @ brillo-m10-dev》有10个想法

      1. Transfer file using bluetooth need Object Push Profile(OPP), currently it seems only support ble Generic Attribute Profile (GATT) which does not support transfer file directly. You may implement your own file transfer protocol。

        1. Then how we can test bluetooth functinality of brillo?
          please can you share me any document about this if availble.

          1. There is an example in the “system/bt/service/example/heart_rate” which will make the bluetooth device acts as a peripheral role(https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothOverview/CoreBluetoothOverview.html#//apple_ref/doc/uid/TP40013257-CH2-SW1). Then you can use the bluetooth-cli command to enable the bluetooth adapter & do advise (adb shell bluetooth-cli),
            [FCLI] enable
            [FCLI] register-ble
            [FCLI] start-adv -n -t -c
            As you can see, this will make the brillo device act as a heart rate monitor device, you can use the standard heart rate monitor app to establish connection.

  1. Since google did not public announce release Brillo system, and I am not sure the Brillo Device Manager is available now on the google Play. The Brillo Device Manager may able to setup the device.
    You can also follow this instructions from https://android.googlesource.com/platform/external/libweave/+/brillo-m10-dev/examples/daemon/README.md to get gcd then setup the brillo device by access http:///privet/v3/setup.

  2. Have you tried run bluetooth-cli on Android devices platform adb command?
    seems that the native app bluetooth-cli not works on LA devices.

发表评论

电子邮件地址不会被公开。 必填项已用*标注