Esempio n. 1
0
static int dump_text(a4l_desc_t *dsc, unsigned char *buf, int size)
{
	int err = 0, width, tmp_size = 0;
	char *fmt;
	a4l_chinfo_t *chan;

	/* Retrieve the subdevice data size */
	err = a4l_get_chinfo(dsc, idx_subd, idx_chan, &chan);
	if (err < 0) {
		fprintf(stderr,
			"insn_read: info for channel %d "
			"on subdevice %d not available (err=%d)\n",
			idx_chan, idx_subd, err);
		goto out;
	}

	width = a4l_sizeof_chan(chan);
	if (width < 0) {
		fprintf(stderr,
			"insn_read: incoherent info for channel %d\n",
			idx_chan);
		err = width;
		goto out;
	}

	switch(width) {
	case 1:
		fmt = "0x%02x\n";
		break;
	case 2:
		fmt = "0x%04x\n";
		break;
	case 4:
	default:
		fmt = "0x%08x\n";
		break;
	}

	while (size - tmp_size > 0) {
		unsigned long values[64];
		int i, tmp_cnt = ((size - tmp_size) / width > 64) ?
			64 : ((size - tmp_size) / width);

		err = a4l_rawtoul(chan, values, buf + tmp_size, tmp_cnt);
		if (err < 0)
			goto out;

		for (i = 0; i < tmp_cnt; i++)
			fprintf(stdout, fmt, values[i]);

		tmp_size += tmp_cnt * width;
	}

out:
	return err;
}
Esempio n. 2
0
int dump_text(a4l_desc_t *dsc, a4l_cmd_t *cmd, unsigned char *buf, int size)
{
	static int cur_chan;

	int i, err = 0, tmp_size = 0;
	char *fmts[MAX_NB_CHAN];
	a4l_chinfo_t *chans[MAX_NB_CHAN];

	for (i = 0; i < cmd->nb_chan; i++) {
		int width;

		err = a4l_get_chinfo(dsc,
				     cmd->idx_subd,
				     cmd->chan_descs[i], &chans[i]);
		if (err < 0) {
			fprintf(stderr,
				"cmd_read: a4l_get_chinfo failed (ret=%d)\n",
				err);
			goto out;
		}

		width = a4l_sizeof_chan(chans[i]);
		if (width < 0) {
			fprintf(stderr,
				"cmd_read: incoherent info for channel %d\n",
				cmd->chan_descs[i]);
			err = width;
			goto out;
		}

		switch(width) {
		case 1:
			fmts[i] = "0x%02x ";
			break;
		case 2:
			fmts[i] = "0x%04x ";
			break;
		case 4:
		default:
			fmts[i] = "0x%08x ";
			break;
		}
	}

	while (tmp_size < size) {
		unsigned long value;

		err = a4l_rawtoul(chans[cur_chan], &value, buf + tmp_size, 1);
		if (err < 0)
			goto out;

		fprintf(stdout, fmts[cur_chan], value);

		/* We assume a4l_sizeof_chan() cannot return because
		   we already called it on the very same channel
		   descriptor */
		tmp_size += a4l_sizeof_chan(chans[cur_chan]);

		if(++cur_chan == cmd->nb_chan) {
			fprintf(stdout, "\n");
			cur_chan = 0;
		}
	}

	fflush(stdout);

out:
	return err;
}