发送请求时蓝牙适配器崩溃/冻结

时间:2016-08-05 07:42:12

标签: c bluetooth bluez gatt

我的蓝牙适配器在向LE蓝牙设备(Parrot Drone)发送第二个请求(实际上是一个命令,因为我没有处理响应)时冻结/崩溃。 Ubuntu工具栏中的蓝牙图标变为对其进行锁定,因此设备已配对,但应用程序在发送第二个请求时会挂起。

确定究竟出了什么问题是非常困难的。我可以使用Gattlib,Gatt,Bluez函数来查询蓝牙适配器的状态,设备日志和冻结的可能原因?知道会出现什么问题吗?

我已经尝试了hcidump但没有任何有用的输出,当适配器发生故障时它不会输出错误/文本。

以下是使用gattliblink)连接设备并与之通信的代码。发送第二个请求时应用程序冻结。

int main(int argc, char** argv)
{

    gatt_connection_t* connection = gattlib_connect(NULL, MY_MAC_ADDRESS, BDADDR_LE_PUBLIC, BT_IO_SEC_LOW, 0, 0);
    if (connection == NULL) {
        fprintf(stderr, "Failed to connect to the bluetooth device.\n");
        return 1;
    }

    printf("Connection Success\n\n");

    // Requests
    uint8_t buffer[100] = {0x01, 0x00};
    int ret = gattlib_write_char_by_handle(connection, 0x00c0, buffer, sizeof(buffer));
    printf("Send Cmd res %s: %d\n", (ret == 0) ? "Success":"Failed", ret);
    // Outputs: "Send Cmd res Success: 0"
    sleep(1); // Sleep for 1 second: incase I am flooding the device. Error occurs without sleeping aswell
    // Freeze/error occurs here and the bluetooth adapter icon shows a lock on it
    ret = gattlib_write_char_by_handle(connection, 0x00bd, buffer, sizeof(buffer));
    printf("Send Cmd res %s: %d\n", (ret == 0) ? "Success":"Failed", ret);
    sleep(1);

    ...

上面的代码与我验证过的gatttool命令完全相同,我可以向无人机发送移动命令。所以我想我可以确认这不是无人机问题,蓝牙适配器可以在它想要的时候工作。即;

  

sudo gatttool -b XX:XX:XX:XX:XX -I
  连接
  char-write-req 0x00c0 0100
  char-write-req 0x00bd 0100
  ......

Hcidump:

  

HCI嗅探器 - 蓝牙数据包分析器版本2.5
  设备:hci0 snap_len:1500过滤器:0xffffffffffffffff
   - HCI事件:命令状态(0x0f)plen 4
      LE创建连接(0x08 | 0x000d)状态0x00 ncmd 1
   - HCI事件:命令完成(0x0e)plen 4
      LE创建连接取消(0x08 | 0x000e)ncmd 1
   - HCI事件:命令状态(0x0f)plen 4
      LE创建连接(0x08 | 0x000d)状态0x00 ncmd 1
   - HCI事件:命令状态(0x0f)plen 4
      LE连接更新(0x08 | 0x0013)状态0x00 ncmd 1

0 个答案:

没有答案