bluetooth handfree client test on console

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:修改蓝牙的名字

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(
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值