【问题标题】:Bluez /Linux - connect: Device or resource busy on gatt_connectBluez /Linux - 连接:gatt_connect 上的设备或资源忙
【发布时间】:2014-04-15 12:24:19
【问题描述】:

环境: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

3rd Connect Device 出现此错误:

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

// 每次通道断开时调用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;
}

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

【问题讨论】:

    标签: linux bluetooth bluez


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 2017-09-02
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 2016-08-29
      • 2015-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多