gpt4 book ai didi

linux - Bluez/Linux - 连接 : Device or resource busy on gatt_connect

转载 作者:太空狗 更新时间:2023-10-29 12:32:21 26 4
gpt4 key购买 nike

环境:C、Linux、Bluez 5.4

第三个 gatt_connect 给出错误。似乎有一些资源没有关闭或关闭。不知道是什么。

Connect Device - gatt_connect
Disconnect Device - remove battery
Connect Device - gatt_connect
Disconnect Device - remove battery
Connect Device - gatt_connect

第三个连接设备出现此错误:

connect: Device or resource busy (16)
connect_cb connect error: Device or resource busy (16)

//每次 channel 断开时都会调用 Watcher。

static gboolean channel_watcher(GIOChannel *iochannel, GIOCondition cond, gpointer user_data)
{

int devid = (int) user_data;
g_io_channel_shutdown(iochannel, FALSE, NULL);
g_io_channel_unref(iochannel);

iochannel = NULL;
return FALSE;
}

建立 GATT 连接:

GIOChannel* GattConnect(int dev_id, char *hwid, int handle, char *value)
{
GIOChannel *chan;
opt_listen=TRUE;
opt_dst = hwid;
opt_handle = handle;
opt_value = value;

chan = gatt_connect(opt_src, opt_dst, opt_dst_type, opt_sec_level, opt_psm, opt_mtu, connect_cb);

if(chan == NULL) {
fprintf(logFile, "GattConnect - null channel\n");
}
else {
g_io_add_watch(chan, G_IO_HUP, channel_watcher, (void *)dev_id);
}
return chan;
}

请提供可能导致资源繁忙的原因

最佳答案

Bluez 通过(Unix 域)套接字访问 GATT 服务。如果连接失败,则在套接字超时之前有 20 秒的超时时间。

我在 GattLib 中实现示例 ble_scan 时遇到了类似的问题。 .为了修复它,我减少了套接字发送/接收的超时时间:

    if (setsockopt (sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
fprintf(stderr, "l2cap_connect: Failed to setsockopt for receive timeout.\n");
return -1;
}

if (setsockopt (sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
fprintf(stderr, "l2cap_connect: Failed to setsockopt for sending timeout.\n");
return -1;
}

我想 GattLib ble_scan 示例可以实现您想要实现的目标:https://github.com/labapart/gattlib/blob/master/examples/ble_scan/ble_scan.c

关于linux - Bluez/Linux - 连接 : Device or resource busy on gatt_connect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23083672/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com