簡體   English   中英

替代BlueZ?

[英]Alternative to BlueZ?

我一直試圖讓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;
 }

我正在使用相同的代碼。 我進入了手機設置,然后切換了允許我的手機在其他設備上顯示的設置。 然后再次運行該程序,它會顯示在列表中。 希望這至少有助於驗證代碼是否正常。

嘗試使用藍牙內部庫。 由btmgmt使用。 它比hcixxx工具直接的hci_xx ioctls更具結構化。

只需打開src / btmhmt.c並搜索掃描(或連接或任何您想要的內容)。

盡管在兩種情況下都會存在許可問題。

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM