多插头漫画bl:Android平台开发-Bluez function porting-蓝牙功能移植

来源:百度文库 编辑:中财网 时间:2024/04/29 16:03:20
 一、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/ttyS2 bcm2035 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/。       还有其他一些测试代码和工具。