Skip to content

Commit

Permalink
Merge pull request #409 from larsclausen/iio_readdev_writedev_skip_wr…
Browse files Browse the repository at this point in the history
…ong_channels

iio_{read,write}dev: Skip channels with the wrong direction
  • Loading branch information
dNechita authored Mar 26, 2020
2 parents 4ce82fa + f27f04f commit 67d3c05
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
22 changes: 18 additions & 4 deletions tests/iio_readdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ static struct iio_context *scan(void)
int main(int argc, char **argv)
{
unsigned int i, nb_channels;
unsigned int nb_active_channels = 0;
unsigned int buffer_size = SAMPLES_PER_READ;
const char *arg_uri = NULL;
const char *arg_ip = NULL;
Expand Down Expand Up @@ -378,21 +379,34 @@ int main(int argc, char **argv)

if (argc == optind + 1) {
/* Enable all channels */
for (i = 0; i < nb_channels; i++)
iio_channel_enable(iio_device_get_channel(dev, i));
for (i = 0; i < nb_channels; i++) {
struct iio_channel *ch = iio_device_get_channel(dev, i);
if (!iio_channel_is_output(ch)) {
iio_channel_enable(ch);
nb_active_channels++;
}
}
} else {
for (i = 0; i < nb_channels; i++) {
unsigned int j;
struct iio_channel *ch = iio_device_get_channel(dev, i);
for (j = optind + 1; j < (unsigned int) argc; j++) {
const char *n = iio_channel_get_name(ch);
if (!strcmp(argv[j], iio_channel_get_id(ch)) ||
(n && !strcmp(n, argv[j])))
if ((!strcmp(argv[j], iio_channel_get_id(ch)) ||
(n && !strcmp(n, argv[j]))) &&
!iio_channel_is_output(ch)) {
iio_channel_enable(ch);
nb_active_channels++;
}
}
}
}

if (!nb_active_channels) {
fprintf(stderr, "No input channels found.\n");
return EXIT_FAILURE;
}

sample_size = iio_device_get_sample_size(dev);

buffer = iio_device_create_buffer(dev, buffer_size, false);
Expand Down
22 changes: 18 additions & 4 deletions tests/iio_writedev.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ static struct iio_context *scan(void)
int main(int argc, char **argv)
{
unsigned int i, nb_channels;
unsigned int nb_active_channels = 0;
unsigned int buffer_size = SAMPLES_PER_READ;
const char *arg_uri = NULL;
const char *arg_ip = NULL;
Expand Down Expand Up @@ -391,21 +392,34 @@ int main(int argc, char **argv)

if (argc == optind + 1) {
/* Enable all channels */
for (i = 0; i < nb_channels; i++)
iio_channel_enable(iio_device_get_channel(dev, i));
for (i = 0; i < nb_channels; i++) {
struct iio_channel *ch = iio_device_get_channel(dev, i);
if (iio_channel_is_output(ch)) {
iio_channel_enable(ch);
nb_active_channels++;
}
}
} else {
for (i = 0; i < nb_channels; i++) {
unsigned int j;
struct iio_channel *ch = iio_device_get_channel(dev, i);
for (j = optind + 1; j < (unsigned int) argc; j++) {
const char *n = iio_channel_get_name(ch);
if (!strcmp(argv[j], iio_channel_get_id(ch)) ||
(n && !strcmp(n, argv[j])))
if ((!strcmp(argv[j], iio_channel_get_id(ch)) ||
(n && !strcmp(n, argv[j]))) &&
iio_channel_is_output(ch)) {
iio_channel_enable(ch);
nb_active_channels++;
}
}
}
}

if (!nb_active_channels) {
fprintf(stderr, "No output channels found\n");
return EXIT_FAILURE;
}

sample_size = iio_device_get_sample_size(dev);

buffer = iio_device_create_buffer(dev, buffer_size, cyclic_buffer);
Expand Down

0 comments on commit 67d3c05

Please sign in to comment.