Android4.2关于bluetooth在HAL层的分析
来源:互联网 发布:java技术面试官 编辑:程序博客网 时间:2024/05/19 13:14
1.一些常用的数据结构
struct hw_device_t common; const bt_interface_t* (*get_bluetooth_interface)();
.tag = HARDWARE_MODULE_TAG, .version_major = 1, .version_minor = 0, .id = BT_HARDWARE_MODULE_ID, .name = "Bluetooth Stack", .author = "The Android Open Source Project", .methods = & bt_stack_module_methods bluetooth_device_t *stack = malloc(sizeof(bluetooth_device_t) ); memset(stack, 0, sizeof(bluetooth_device_t) ); stack->common.tag = HARDWARE_DEVICE_TAG; stack->common.version = 0; stack->common.module = (struct hw_module_t*)module; stack->common.close = close_bluetooth_stack; stack->get_bluetooth_interface = bluetooth__get_bluetooth_interface; *abstraction = (struct hw_device_t*)stack; //GJ:强制转换,bluetooth_device_t的第一个成员为hw_device_t,传到上层 return 0; .open = open_bluetooth_stack,
char value[PROPERTY_VALUE_MAX]; property_get("bluetooth.mock_stack", value, ""); // const char *id = (strcmp(value, "1")? BT_STACK_MODULE_ID : BT_STACK_TEST_MODULE_ID); //JNI获取HAL层模块的通用方式,根据模块ID获得hw_module_t对象 err = hw_get_module(id, (hw_module_t const**)&module); if (err == 0) { hw_device_t* abstraction; err = module->methods->open(module, id, &abstraction); if (err == 0) { //强制转换,bluetooth_module_t的第一个成员为abstraction bluetooth_module_t* btStack = (bluetooth_module_t *)abstraction; sBluetoothInterface = btStack->get_bluetooth_interface(); //GJ:JAVA层的sBuletooth获得bluedroid中实现的bluetoothInterface }
hardware/libhardware/include/hardware.h中
定义了三个重要的结构:
struct hw_module_t; //模块类型
struct hw_module_methods_t; //模块方法
struct hw_device_t; //设备类型
hw_module_t中包含结构hw_module_methods_t
hw_module_methods_t只有一个唯一的Open方法,如下:
int (*open)(const struct hw_module_t* module, const char* id,struct hw_device_t** device);
struct hw_device_t中包含hw_module_t结构和一个close方法如下:
int (*close)(struct hw_device_t* device);
这几个结构十分关键,是HAL层向上暴露的接口。
2.定义蓝牙HAL层结构
在hardware/libhardware/include/bluetooth.h中定义以下关键结构
首先是定义的蓝牙模块ID
#define BT_HARDWARE_MODULE_ID "bluetooth"
#define BT_STACK_MODULE_ID "bluetooth"
#define BT_STACK_TEST_MODULE_ID "bluetooth_test"
其次是定义的蓝牙硬件设备接口
//要求自定义xxx_device_t的第一个成员必须是hw_device_t类型,其次才是其它的一些接口信息.
typedef struct {
} bluetooth_device_t;
除了这个结构,还必须定义关hw_module_t类型的实例HAL_MODULE_INFO_SYM。这个结构在Bluedroid的bluetooth.c中定义。
//变量名必须为HAL_MODULE_INFO_SYM,这是强制要求的,你要写Android的HAL就得遵循这个游戏规则
struct hw_module_t HAL_MODULE_INFO_SYM = {
};
定义的bt_stack_module_methods如下:
static int open_bluetooth_stack (const struct hw_module_t* module, char const* name,struct hw_device_t** abstraction)
{
}
static struct hw_module_methods_t bt_stack_module_methods= {
};
在/packages/apps/Bluetooth/jni/com_android_bluetooth_btservice_AdapterService.cpp中实现的是bluetooth的JNI代码,是上层Java与下层Bluedroid的接口。
在static void classInitNative(JNIEnv* env, jclass clazz)函数中有以下部分code:
0 0
- Android4.2关于bluetooth在HAL层的分析
- Android4.2关于bluetooth在HAL层的分析
- Android4.2关于bluetooth在HAL层的分析(1)
- Android4.2关于bluetooth在HAL层的分析(1)
- android关于GPS hal层的分析
- android关于GPS hal层的分析
- android关于GPS hal层的分析
- android关于GPS hal层的分析
- android关于GPS hal层的分析
- android4.2.2---1. hal层与framework层的调用
- AlarmManagerService的hal层分析
- gps模块协议NMEA-0183的解析----android4.2下的gps hal层
- HAL向上层提供接口的分析
- android4.4 bluetooth 配置文件分析
- android4.4 bluetooth 配置文件分析
- Camera HAL层代码分析2
- Android HAL层分析
- android4.0.3 HAl层open文件思考
- 为什么很多程序员、Geek 都喜欢熬夜,而且在后半夜工作效率异常高?
- VC对硬件创业为何看得多、投得少?
- CSS Sprites(CSS精灵)技术及其优化经验分享
- 在线图片处理api接口
- java 字符串的比较
- Android4.2关于bluetooth在HAL层的分析
- 20140328收盘小结
- 天气预报 你玩过吗?
- iPad进入DUF恢复模式
- Android长按Power键弹出关机Dialog框GlobalActions解析
- Java异常总结(运行期出现的错误)
- 高速数据采集系统 10bit 5GSPS
- SIFT和SURF的比较(转)
- Linux下调整ext3分区大小