与bluez的同时经典的低功耗设备 [英] bluez with simultaneous classic and low energy devices

查看:469
本文介绍了与bluez的同时经典的低功耗设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能与Linux下的bluez在同一时间连接到多个经典的低功耗设备?该网站bluez的是不是非常有帮助这样的提供信息。

Is it possible with bluez under Linux to connect to multiple classic and low energy devices at the same time? The bluez site isn't very helpful providing information like this.

推荐答案

是的,我已经成功地在同一时间连接到7低功耗设备。最大的变化取决于您所使用的硬件。您也可以连接到多个经典的器件。

Yes, I've managed to connect to 7 low energy devices at the same time. The maximum varies depending on the hardware you're using. You can also connect to multiple classic devices as well.

下面是C第一用于通过L2CAP连接一些伪/片断:

Here's some pseudo/snippet of C I used for connecting via L2CAP:

#include <sys/types.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/l2cap.h>

char *bdaddr;
int cid = 0;
int psm = 0;
int bdaddr_type = BDADDR_LE_PUBLIC;
int err;
struct sockaddr_l2 addr;
int sock_fd = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)

memset(&addr, 0, sizeof(addr));
addr.l2_family = sock->sock_family;
str2ba(bdaddr, &addr.l2_bdaddr);

if (cid)
    addr.l2_cid = htobs(cid);
else
    addr.l2_psm = htobs(psm);

addr.l2_bdaddr_type = bdaddr_type;


err = connect(sock_fd, (struct sockaddr *) &addr, sizeof(addr));

我的code是C和Python的组合,所以我尝试重组它,所以它只是的C部分。一切都从阅读配合bluez源$ C ​​$ C,采取专门的 gatttool

更新:
有一个在Linux内核的bluez code在3.4和L2CAP插座打交道时,以前的版本中的错误。从本质上讲,如果你有多个连接,将它们混合起来,所以你得到你所做的最后一个连接上的所有数据。因此,code我给只能在3.4内核工作,之前,如果你只是做一个L2CAP连接。

UPDATE: There's a bug in the linux kernel's bluez code in versions 3.4 and prior when dealing with L2CAP sockets. Essentially, if you have more than one connection, it will mix them up so you get all your data on the last connection made. So, the code I gave will only work on kernels 3.4 and prior if you only make one L2CAP connection.

这篇关于与bluez的同时经典的低功耗设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆