BlueNRG 蓝牙:读取中央设备名称

问题描述

我在外围设备上使用 STM BlueNRG-MS 芯片,连接后我想读取连接的中央设备(安卓手机)的名称

我想我可以直接在注册为 hci 回调的 user_notify 例程中执行此操作

  /* Initialize the Host-Controller Interface */
  hci_init(user_notify,NULL);

因此,在 EVT_LE_CONN_COMPLETE 事件中,我使用为中央设备提供的句柄,并使用 aci_gatt_read_using_charac_uuid() 读取我认为具有设备名称 (uuid 0x2a00) 的特征。

case EVT_LE_Meta_EVENT:
    {
      evt_le_Meta_event *evt = (void *)event_pckt->data;
      switch(evt->subevent){
      case EVT_LE_CONN_COMPLETE:
        {
          evt_le_connection_complete *cc = (void *)evt->data;
                    GAP_ConnectionComplete_CB(cc->peer_bdaddr,cc->handle);
                    uint16_t uuid = 0x2a00;
                    resp = aci_gatt_read_using_charac_uuid(cc->handle,1,UUID_TYPE_16,(uint8_t*)&uuid);
                    LOG("GATT read status: %d",resp);

          enqueEvent(EVENT_BLE_CONNECTED);
        }
        break;
      }
    }

长话短说,它不起作用。我不确定的第一件事是,start_handleend_handleaci_gatt_read_using_charac_uuid() 参数是什么,它返回 ERR_INVALID_HCI_CMD_ParaMS

有人可以在这里解释一下吗?

更新
同样令我感到困惑的是,函数 aci_gatt_read_using_charac_uuid()BlueNRG-MS Programming Guidelines 中没有任何地方被引用。

update2
我将函数调用更改为 aci_gatt_read_using_charac_uuid(cc->handle,0x0001,0xffff,(uint8_t*)&uuid);,但我仍然得到 ERR_INVALID_HCI_CMD_ParaMS。哪个参数甚至可能无效? uuid 存在,如果我使用带有蓝牙加密狗的 BlueNRG GUI,我可以读取设备名称

解决方法

给你,The BlueNRG-MS Bluetooth® LE stack application command interface (ACI) - User manual

页面 75 - 4.6.25 Ctrl + a + d 并确保您已致电 Aci_Gatt_Read_Charac_Using_UUID()

用户手册是2019年7月最新修订的,你链接的文档是2018年的,不知道是不是这个原因?

Aci_Gatt_Init()start_handle 是您的服务中的句柄范围,如图所示 -

enter image description here

这是我能找到的最接近您的问题的discussion