Android系統Bluetooh移植簡要說明

一、Bluez編譯配置支持

在BoardConfig.mk中添加:
BOARD_HAVE_BLUETOOTH := true。

二、啓動hciattach
BlueZ核心子系統使用hciattach守護進程添加指定的硬件串口驅動。
修改init.rc來啓動hciattach:
service hciattach /system/bin/hciattch -n -s 115200 /dev/ttyS2 bcm2035 115200
user bluetooth
group bluetooth net_bt_admin
disabled

同時也要啓動dbus daemon,因爲bluez需要dbus與其它進程通訊的。
三、Bluez控制流程
class bluetoothsetting是UI的入口,通過按button scan進入搜索狀態,
applicaton層調用bluetoothdevice, 接着就是bluetoothservice的調用,
bluetoothservice調用native方法,到此全部的java程序結束了。
下面的調用都是JNI, cpp實現的。android_server_bluetoothservice.cpp裏面實現了native
方法,最終通過dbus封裝,調用 HCID deamon 的function DiscoverDevice。
Bluetooth的啓動流程是:
1. 打開藍牙電源,通過rfkill來enable;(system/bluetooth/bluedroid/bluetooth.c)
2. 啓動service hciattch -n -s 115200 /dev/ttyS2bcm2035 115200;
3. 檢測HCI是否成功(接受HCIDEVUP socket來判斷或hciconfig hci0 up);
4. hcid deamon start up。
四、Bluetooth結構
1、JAVA層
frameworks/base/core/java/android/bluetooth/
包含了bluetooth的JAVA類。
2、JNI層
frameworks/base/core/jni/android_bluetooth_開頭的文件
定義了bluez通過JNI到上層的接口。
frameworks/base/core/jni/android_server_bluetoothservice.cpp
調用硬件適配層的接口system/bluetooth/bluedroid/bluetooth.c
3、bluez庫
external/bluez/
這是bluez用戶空間的庫,開源的bluetooth代碼,包括很多協議,生成libbluetooth.so。
4、硬件適配層
system/bluetooth/bluedroid/bluetooth.c
包含了對硬件操作的接口
system/bluetooth/data/*
一些配置文件,複製到/etc/bluetooth/。
還有其他一些測試代碼和工具。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章