コード例 #1
0
ファイル: main.c プロジェクト: lwehmeier/zephyr
static int cmd_gatt_unsubscribe(int argc, char *argv[])
{
	int err;

	if (!default_conn) {
		printk("Not connected\n");
		return 0;
	}

	if (!subscribe_params.value_handle) {
		printk("No subscription found\n");
		return 0;
	}

	err = bt_gatt_unsubscribe(default_conn, &subscribe_params);
	if (err) {
		printk("Unsubscribe failed (err %d)\n", err);
	} else {
		printk("Unsubscribe success\n");
	}

	/* Clear subscribe_params to reuse it */
	memset(&subscribe_params, 0, sizeof(subscribe_params));

	return 0;
}
コード例 #2
0
ファイル: gatt.c プロジェクト: PchZhang/testgit
void bt_gatt_notification(struct bt_conn *conn, uint16_t handle,
			  const void *data, uint16_t length)
{
	struct bt_gatt_subscribe_params *params;

	BT_DBG("handle 0x%04x length %u", handle, length);

	for (params = subscriptions; params; params = params->_next) {
		if (handle != params->value_handle) {
			continue;
		}

		if (params->func(conn, 0, data, length) == BT_GATT_ITER_STOP) {
			bt_gatt_unsubscribe(conn, params);
		}
	}
}
コード例 #3
0
bool BLECharacteristicImp::unsubscribe(void)
{
    int retval = 0;
    bt_conn_t* conn = NULL;
    
    if (true == BLEUtils::isLocalBLE(_ble_device))
    {
        // GATT server can't subscribe
        return false;
    }
    
    if (false == _subscribed)
    {
        return true;
    }
    
    _sub_params.value = 0;
    
    if (0 == (_gatt_chrc.properties & (BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_INDICATE)))
    {
        // The characteristic not support the Notify and Indicate
        return false;
    }
    
    conn = bt_conn_lookup_addr_le(_ble_device.bt_le_address());
    if (NULL == conn)
    {
        return false;
    }
    
    bt_addr_le_copy(&_sub_params._peer, bt_conn_get_dst(conn));
    _sub_params.ccc_handle = _cccd_handle;
    _sub_params.value_handle = _value_handle;
    
    // Enable CCCD to allow peripheral send Notification/Indication
    retval = bt_gatt_unsubscribe(conn, &_sub_params);
    bt_conn_unref(conn);
    if (0 == retval)
    {
        _subscribed = false;
    }
    return _subscribed;
}