[yocto] bluetooth 移植使用手册

1. porting driver

各个厂商有个各厂商的driver, 配置方式, 拿过来,照着porting guide 去porting okay 就行, 有什么问题,问厂商就行!

2. 关于bluez5

yocto 中有著名的connman,用于管理Ethernet, wifi,bluetooth,和VPN。但经过实测发现,yocto3.0 中的connman 并不能管理bt。(扫描不了)所以我们得使用更低层一点的组件-bluez5.
zeus 默认搭载了bluez5, 它是linux蓝牙管理&使用的一个基础套件。

bluez5 包含以下工具:
(1)bluetoothd
   1)是BlueZ的中央守护进程,蓝牙的扫描,链接,管理都得经过它。
   2)提供用于UI和其他子系统的D-Bus接口
   3)减少暴露底层细节
   4)可以通过插件扩展(例如通过neard支持NFC,通过sixaxis支持DS3)
(2)obexd
   1)是OBEX协议的守护进程
   2)提供用于UI的D-Bus接口
   3)具有与bluetoothd类似的架构
   4)文件传输的守护进程
(3)底层工具(tools)
   1)bluetoothctl - bluetoothd的客户端工具,命令行下操作蓝牙,大部分得靠它。
   2)obexctl - obexd 的客户端工具
   3)btmon - HCl信息跟踪
   4)hciconfig 等其他用于测试,开发和跟踪的命令行工具集
(4)上层协议
   1)Audio and media (A2DP, AVRCP)
   2)Telephony (HFP, HSP)
   3)Networking (PAN, 6LoWPAN)
   4)Input device (HID, HoG)
   5)OBEX (FTP, OPP, MAP, PBAP)
   6)Others

3. 查看蓝牙设备状态

使用 hciconfig 查看当前系统的 bluetooth devices 的状态. 也用于检测蓝牙device driver 是否Work。

root@Qing:~# hciconfig
hci0:   Type: BR/EDR  Bus: USB
BD Address: 00:1A:7D:DA:71:13  ACL MTU: 310:10  SCO MTU: 64:8
UP RUNNING
RX bytes:574 acl:0 sco:0 events:30 errors:0
TX bytes:368 acl:0 sco:0 commands:30 errors:0

如果没有对应的设备, 就是没有driver, 或者device not work.

4. 开启bluetoothd 服务

bluetoothd 是蓝牙的核心服务,必须开启它。

systemctl status bluetooth
## 如果没有active, 你需要执行以下指令, 否则,无须执行
systemctl enable bluetooth.service
systemctl start bluetooth

5. 使能蓝牙协议

connman 可以使能bluetooth 协议栈。

connmanctl enable bluetooth
#or
# hciconfig hci0 up

6. 开启bluetoothctl

开启bluetoothctl, 并执行下面命令:

bluetoothctl

    [bluetooth]# power on
    [bluetooth]# pairable on

7. 扫描蓝牙设备

  ## 扫描设备
    [bluetooth]# scan on
Discovery started
[CHG] Controller 00:19:88:5E:10:B1 Discovering: yes
[NEW] Device 98:39:8E:1B:D8:88 Galaxy A5 (2016)
[CHG] Device 98:39:8E:1B:D8:88 RSSI: -86
Now, Copy the MAC Address of your PC

扫描出来的时设备的MAC 地址+名字, 后续需要使用MAC 地址进行各种操作。扫描知道发现你想要的设备

## 结束扫描
[bluetooth]# scan off

如果之前已经配对过,直接执行以下命令:

[bluetooth]# devices

8. 配对蓝牙设备

[bluetooth]# pair 98:39:8E:1B:D8:88
Attempting to pair with 98:39:8E:1B:D8:88
[CHG] Device 98:39:8E:1B:D8:88 Connected: yes
Request confirmation
[agent] Confirm passkey 117022 (yes/no):

同时执行以下操作, 如果已经配对,直接执行connect

[bluetooth]# connect 98:39:8E:1B:D8:88
Attempting to connect to 98:39:8E:1B:D8:88
[CHG] Device 98:39:8E:1B:D8:88 Connected: yes
Connection successful
[CHG] Device 98:39:8E:1B:D8:88 ServicesResolved: yes

9. 选择信任设备

[bluetooth]# trust 98:39:8E:1B:D8:88

10. 链接成功

至此, bluetooth 配对链接成功,执行以下命令退出bluetoothctl 交互模式:

[bluetooth]# quit

11. 使用Obex profile测试蓝牙的文件传输

obexd 是bluez 套件的一部分,它位于**/usr/libexec/bluetooth/obexd**

11.1 开启obexd 守护进程

$ echo "helloworld" > /home/root/test.txt
$ export $(dbus-launch)
$ /usr/libexec/bluetooth/obexd -r /home/root -a -d & 

11.2 链接&传送文件

执行obexctl 进行以下交互命令:

obexctl
[obex]# connect 98:39:8E:1B:D8:88
[obex]# send <file>
[obex]# quit

测试完成。

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值