Ejemplo n.º 1
0
static void att_prepare_write_rsp(struct bt_conn *conn, uint8_t err,
				  const void *pdu, uint16_t length,
				  void *user_data)
{
	struct prepare_write_data *data = user_data;
	bt_gatt_rsp_func_t func = data->func;

	BT_DBG("err 0x%02x", err);

	/* Reset func so next prepare don't fail */
	data->func = NULL;

	/* Don't continue in case of error */
	if (err) {
		func(conn, err);
		return;
	}

	/* If there is no more data execute */
	if (!data->length) {
		gatt_exec_write(conn, func);
		return;
	}

	/* Write next chunk */
	bt_gatt_write(conn, data->handle, data->offset, data->data,
		      data->length, func);
}
Ejemplo n.º 2
0
static int cmd_gatt_write(int argc, char *argv[])
{
	int err;
	uint16_t handle, offset;
	uint8_t buf[100];
	uint8_t data;

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

	if (argc < 4) {
		return -EINVAL;
	}

	handle = strtoul(argv[1], NULL, 16);
	/* TODO: Add support for longer data */
	offset = strtoul(argv[2], NULL, 16);
	data = strtoul(argv[3], NULL, 16);

	if (argc == 5) {
		size_t len = min(strtoul(argv[4], NULL, 16), sizeof(buf));
		int i;

		for (i = 0; i < len; i++) {
			buf[i] = data;
		}

		write_params.data = buf;
		write_params.length = len;
	} else {
		write_params.data = &data;
		write_params.length = sizeof(data);
	}

	write_params.handle = handle;
	write_params.offset = offset;
	write_params.func = write_func;

	err = bt_gatt_write(default_conn, &write_params);
	if (err) {
		printk("Write failed (err %d)\n", err);
	} else {
		printk("Write pending\n");
	}

	return 0;
}