1 测试环境
- 硬件环境: wmt8880行车记录仪+mtk6622 bt + iphone手机
- 软件环境: android4.4.2+ bluedroid5.0 + kernel3.4.5
- 系统组件的连接框图:
![]()
2 测试代码编码
- step1:通过hw_get_module接口来获取蓝牙HAL层提供的蓝牙接口:bt_interface,并调用他的初始化函数:bt_interface->init(callbacks) 来设置对应的应用层回调函数:callbacks
bool hal_open(bt_callbacks_t *callbacks) {
hw_module_t *module;
if (hw_get_module(BT_STACK_MODULE_ID, (hw_module_t const **)&module)) {
return false;
}
hw_device_t *device;
if (module->methods->open(module, BT_STACK_MODULE_ID, &device)) {
return false;
}
bt_device = (bluetooth_device_t *)device;
bt_interface = bt_device->get_bluetooth_interface();
if (!bt_interface) {
bt_device->common.close((hw_device_t *)&bt_device->common);
bt_device = NULL;
return false;
}
bool success = (bt_interface->init(callbacks) == BT_STATUS_SUCCESS);
success = success && (bt_interface->set_os_callouts(&callouts) == BT_STATUS_SUCCESS);
return success;
step2:使能蓝牙:bt_interface->enable()
step3:修改蓝牙的名字
step3:修改蓝牙的名字
bt_property_t *property_new_name(const char *name) {
bt_bdname_t *bdname = calloc(sizeof(bt_bdname_t), 1);
bt_property_t *property = calloc(sizeof(bt_property_t), 1);
property->type = BT_PROPERTY_BDNAME;
property->val = bdname;
property->len = sizeof(bt_bdname_t);
strlcpy((char *)bdname->name, name, sizeof(