【问题标题】:Alternative to BlueZ?BlueZ 的替代品?
【发布时间】:2013-10-20 04:18:21
【问题描述】:

我一直在尝试让 BlueZ 在我的 Ubuntu 桌面上运行一天的大部分时间。它只是行不通。我可以通过系统对话成功地将我的设备与我的计算机配对,但 BlueZ 扫描从未找到任何东西。 BlueZ 有替代品吗?如果设备已经配对,有没有办法在没有 BlueZ 的情况下操作蓝牙设备?

为了更好的衡量,这是我一直在运行的代码 (http://people.csail.mit.edu/albert/bluez-intro/c404.html#simplescan.c):

 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/socket.h>
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
 #include <bluetooth/hci_lib.h>

 int main(int argc, char **argv)
 {
     inquiry_info *ii = NULL;
     int max_rsp, num_rsp;
     int dev_id, sock, len, flags;
     int i;
     char addr[19] = { 0 };
     char name[248] = { 0 };

     dev_id = hci_get_route(NULL);
     sock = hci_open_dev( dev_id );
     if (dev_id < 0 || sock < 0) {
         perror("opening socket");
         exit(1);
     }

     len  = 8;
     max_rsp = 255;
     flags = IREQ_CACHE_FLUSH;
     ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));

     num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
     if( num_rsp < 0 ) perror("hci_inquiry");

     for (i = 0; i < num_rsp; i++) {
         ba2str(&(ii+i)->bdaddr, addr);
         memset(name, 0, sizeof(name));
         if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), 
             name, 0) < 0)
         strcpy(name, "[unknown]");
         printf("%s  %s\n", addr, name);
     }

     free( ii );
     close( sock );
     return 0;
 }

【问题讨论】:

  • bluez 库主要是围绕驱动程序 ioctl 调用的一个非常薄的包装器。您可以直接进行 ioctl 调用。我用python做到了。如果出现故障,则可能是驱动程序的错误,或者是硬件的限制(某些设备的扫描功能有限)。
  • 你试过像 hcitool scan 这样的命令来搜索设备

标签: c linux bluetooth bluez


【解决方案1】:

我正在使用相同的代码。我进入了我的手机设置并切换了允许我的手机对其他设备可见的设置。然后再次运行该程序,它会显示在列表中。希望这至少有助于验证代码是否正常工作。

【讨论】:

    【解决方案2】:

    尝试使用蓝牙内部库。由 btmgmt 使用。它比 hcixxx 工具直接 hci_xx ioctls 更结构化。

    只需打开 src/btmhmt.c 并搜索扫描(或连接或任何你想要的)。

    虽然在这两种情况下都会存在许可问题。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 2012-01-25
      • 2015-08-05
      • 2011-01-01
      • 2011-10-24
      相关资源
      最近更新 更多