android蓝牙介绍二蓝牙代码架构及其uart 到rfcomm流程

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Android bluetooth介绍(二)

android 蓝牙代码架构及其uart 到rfcomm 流程

一、Android Bluetooth Architecture蓝牙代码架构部分(google 官方蓝牙框架)

Android的蓝牙系统,自下而上包括以下一些内容如上图所示:

1、串口驱动

Linux的内核的蓝牙驱动程、Linux的内核的蓝牙协议的层

2、BlueZ的适配器

BlueZ的(蓝牙在用户空间的函式库)

bluez代码结构

Bluetooth协议栈BlueZ分为两部分:内核代码和用户态程序及工具集。(1)、内核代码:由BlueZ核心协议和驱动程序组成

Bluetooth协议实现在内核源代码 kernel/net/bluetooth中。包括

hci,l2cap,hid,rfcomm,sco,SDP,BNEP等协议的实现。

(2)、驱动程序:kernel/driver/bluetooth中,包含Linuxkernel对各种接口的

Bluetooth device的驱动,如:USB接口,串口等。

(3)、用户态程序及工具集:

包括应用程序接口和BlueZ工具集。BlueZ提供函数库以及应用程序接口,便于程序员开发bluetooth应用程序。BlueZ utils是主要工具集,实现对bluetooth设备的初始化和控制。

3、蓝牙相关的应用程序接口

Android.buletooth包中的各个Class(蓝牙在框架层的内容-----java)

同样下图也是一张比较经典的蓝牙代码架构图(google官方提供)

二、蓝牙通过Hciattach启动串口流程:

1、hciattach总体流程

2、展讯hciattach代码实现流程:

三、具体代码分析

1、initrc中定义

idh.code\device\sprd\sp8830ec_nwcn\init.sc8830.rc

[html]view plaincopy

1.service hciattach /system/bin/hciattach -n /dev/sttybt0 sp

rd_shark

2.socket bluetooth stream 660 bluetooth bluetooth

er bluetooth

4.group wifi bluetooth net_bt_admin net_bt inet net

_raw net_admin system

5.disabled

6.oneshot

adb 下/dev/ttybt0(不同平台有所不同)

PS 进程中:hicattch

2、/system/bin/hciattach 执行的Main函数

idh.code\external\bluetooth\bluez\tools\hciattach.c

service hciattach /system/bin/hciattach -n /dev/sttybt0sprd_shark 传进两个参数,/dev/sttybt0 和 sprd_shark

1.i nt main(int argc, char *argv[])

2.{

3.………………

4.for (n = 0; optind < argc; n++, optind++) {

5.char *opt;

6.

7.opt = argv[optind];

8.

9.switch(n) {

10. case 0://(1)、解析驱动的位置;

11. dev[0] = 0;

12. if (!strchr(opt, '/'))

13. strcpy(dev, "/dev/");

14. strcat(dev, opt);

15. break;

16.

17. case 1://(2)、解析串口的配置相关参数;

18. if (strchr(argv[optind], ',')) {

19. int m_id, p_id;

20. sscanf(argv[optind], "%x,%x",

&m_id, &p_id);

21. u = get_by_id(m_id, p_id);

22. } else {

23. u = get_by_type(opt);

24. }

25.

26. if (!u) {

27. fprintf(stderr, "Unknown devi

ce type or id\n");

28. exit(1);

29. }

30.

31. break;

32.

33. case 2://(3)、通过对前面参数的解析,把uart[i]

中的数值初始化;

34. u->speed = atoi(argv[optind]);

35. break;

36.

37. case 3:

38. if (!strcmp("flow", argv[optind]))

39. u->flags |= FLOW_CTL;

40. else

41. u->flags &= ~FLOW_CTL;

42. break;

43.

44. case 4:

45. if (!strcmp("sleep", argv[optind]))

46. u->pm = ENABLE_PM;

47. else

48. u->pm = DISABLE_PM;

49. break;

50.

51. case 5:

52. u->bdaddr = argv[optind];

53. break;

54. }

55. }

56.

57.………………

58. if (init_speed)//初始化串口速率;

59. u->init_speed = init_speed;

60.………………

相关文档
最新文档