简体   繁体   English

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

[英]BlueNRG Bluetooth: read central device name

I'm using the STM BlueNRG-MS chip on my peripheral device and after connection I'd like to read the name of the connected central device (android phone).我在外围设备上使用 STM BlueNRG-MS 芯片,连接后我想读取连接的中央设备(Android 手机)的名称。

I thought I can do this directly in my user_notify routine which is registered as hci callback我以为我可以直接在注册为user_notify回调的user_notify例程中执行此操作

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

So on the EVT_LE_CONN_COMPLETE event, I take the provided handle for the central device and I use aci_gatt_read_using_charac_uuid() to read what I thought is the characteristic with the device name (uuid 0x2a00).因此,在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, 0, 1, UUID_TYPE_16, (uint8_t*)&uuid);
                    LOG("GATT read status: %d", resp);

          enqueEvent(EVENT_BLE_CONNECTED);
        }
        break;
      }
    }

Long story short, it doesn't work.长话短说,它不起作用。 First thing I'm not sure about is, what is the start_handle and end_handle parameter of aci_gatt_read_using_charac_uuid() , it returns ERR_INVALID_HCI_CMD_PARAMS .我不确定的第一件事是, aci_gatt_read_using_charac_uuid()start_handleend_handle参数是aci_gatt_read_using_charac_uuid() ,它返回ERR_INVALID_HCI_CMD_PARAMS

Can someone shed some light here?有人可以在这里解释一下吗?

update更新
What also puzzles me is that the function aci_gatt_read_using_charac_uuid() is nowehere referenced in the BlueNRG-MS Programming Guidelines .同样令我困惑的是,函数aci_gatt_read_using_charac_uuid()BlueNRG-MS Programming Guidelines 中没有任何地方被引用。

update2更新2
I changed the function call to aci_gatt_read_using_charac_uuid(cc->handle, 0x0001, 0xffff, UUID_TYPE_16, (uint8_t*)&uuid);我将函数调用更改为aci_gatt_read_using_charac_uuid(cc->handle, 0x0001, 0xffff, UUID_TYPE_16, (uint8_t*)&uuid); but I still get the ERR_INVALID_HCI_CMD_PARAMS .但我仍然得到ERR_INVALID_HCI_CMD_PARAMS What which paramter could even be invalid?哪个参数甚至可能无效? The uuid exists, I can read the device name if I use the BlueNRG GUI with a bluetooth dongle. uuid 存在,如果我使用带有蓝牙加密狗的 BlueNRG GUI,我可以读取设备名称。

update3更新3
Has anyone ever used this function or somehow managed to read a characteristic from a central device?有没有人使用过这个功能或以某种方式设法从中央设备读取特征? I'd highly appreciate any help or hint.我非常感谢任何帮助或提示。

Here you go, The BlueNRG-MS Bluetooth® LE stack application command interface (ACI) - User manual在这里, BlueNRG-MS 蓝牙® LE 堆栈应用程序命令接口 (ACI) - 用户手册

page 75 - 4.6.25 Aci_Gatt_Read_Charac_Using_UUID() and make sure you have called Aci_Gatt_Init()75页 - 4.6.25 Aci_Gatt_Read_Charac_Using_UUID()并确保您已调用Aci_Gatt_Init()

The user manual is last revised July 2019, the document you link to is from 2018, don't know if this is why ?用户手册是2019年7月最新修订的,你链接的文档是2018年的,不知道是不是这个原因?

The start_handle and end_handle is the range of handles in your service as pictured here - start_handleend_handle是您的服务中的句柄范围,如图所示 -

在此处输入图片说明

Here is a discussion to the closest thing I could find to match your question.这里有一个讨论,以我能找到匹配您的问题最接近的事情。

As it turned out there are two bugs in the BlueNRG API.事实证明,BlueNRG API 中有两个错误。

In bluenrg_aci_const.h file the OCF code OCF_GATT_READ_USING_CHARAC_UUID shall be 0x119 instead of 0x109 .bluenrg_aci_const.h文件中,OCF 代码OCF_GATT_READ_USING_CHARAC_UUID应为0x119而不是0x109 And in the implementation of the aci_gatt_read_using_charac_uuid() function, there is a missing setting on event:在 aci_gatt_read_using_charac_uuid() 函数的实现中,缺少事件设置:

rq.event = EVT_CMD_STATUS;

Patching them fixed the issue.修补它们解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM