赞
踩
经过几天的煎熬,终于把bluez移植到了ARM环境上,终于可以开始使用了,但是在运行hci_get_route接口后提示找不到对应的设备,后来发现是蓝牙设备没有启用,下面用到命令在交叉编译的时候应该已经生成了,直接使用即可。
1.先执行hciconfig
看到设备 hci0就是蓝牙模块了
2.执行hciconfig hci0 up,然后再调用hci_get_route就OK了。
下面是测试代码,注:这是测试经典蓝牙的代码,非低功耗蓝牙
- #include "./bluetooth/bluetooth.h"
- #include "./bluetooth/hci.h"
- #include "./bluetooth/hci_lib.h"
- #include "./bluetooth/l2cap.h"
- #include "./bluetooth/rfcomm.h"
- #include "sdp.h"
- #include "sdp_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);
- sleep(1);
- }
-
- free( ii );
- close( sock );
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。