Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iio_{read,write}dev: Skip channels with the wrong direction #409

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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