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

fix iio attr so it supports triggers better #482

Merged
merged 2 commits into from
May 5, 2020
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
84 changes: 60 additions & 24 deletions tests/iio_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ static void dump_device_attributes(const struct iio_device *dev,
{
ssize_t ret;
char *buf = xmalloc(BUF_SIZE, MY_NAME);
const char *name = iio_device_get_name(dev);

if (!wbuf || !quiet) {
if (!quiet)
printf("dev '%s', attr '%s', value :",
iio_device_get_name(dev), attr);
if (!quiet) {
printf("%s ", iio_device_is_trigger(dev) ? "trig" : "dev");
if(name)
printf("'%s'", name);
else
printf("'%s'", iio_device_get_id(dev));

printf(", attr '%s', value :", attr);
}
gen_function("device", "dev", attr, NULL);
ret = iio_device_attr_read(dev, attr, buf, BUF_SIZE);
if (ret > 0) {
Expand Down Expand Up @@ -136,14 +143,21 @@ static void dump_buffer_attributes(const struct iio_device *dev,
{
ssize_t ret;
char *buf = xmalloc(BUF_SIZE, MY_NAME);
const char *name = iio_device_get_name(dev);

if (!wbuf || !quiet) {
gen_function("device_buffer", "dev", attr, NULL);
ret = iio_device_buffer_attr_read(dev, attr, buf, BUF_SIZE);

if (!quiet)
printf("dev '%s', buffer attr '%s', value :",
iio_device_get_name(dev), attr);
if (!quiet) {
printf("%s ", iio_device_is_trigger(dev) ? "trig" : "dev");
if (name)
printf("'%s'", name);
else
printf("'%s'", iio_device_get_id(dev));

printf(", buffer attr '%s', value :", attr);
}

if (ret > 0) {
if (quiet)
Expand Down Expand Up @@ -178,14 +192,22 @@ static void dump_debug_attributes(const struct iio_device *dev,
{
ssize_t ret;
char *buf = xmalloc(BUF_SIZE, MY_NAME);
const char *name = iio_device_get_name(dev);

if (!wbuf || !quiet) {
gen_function("device_debug", "dev", attr, NULL);
ret = iio_device_debug_attr_read(dev, attr, buf, BUF_SIZE);

if (!quiet)
printf("dev '%s', debug attr '%s', value :",
iio_device_get_name(dev), attr);
if (!quiet) {
printf("%s ", iio_device_is_trigger(dev) ? "trig" : "dev");
if (name)
printf("'%s'", name);
else
printf("'%s'", iio_device_get_id(dev));

printf(", debug attr '%s', value :", attr);

}

if (ret > 0) {
if (quiet)
Expand Down Expand Up @@ -221,6 +243,7 @@ static void dump_channel_attributes(const struct iio_device *dev,
ssize_t ret;
char *buf = xmalloc(BUF_SIZE, MY_NAME);
const char *type_name;
const char *name = iio_device_get_name(dev);

if (!wbuf || !quiet) {
if (iio_channel_is_output(ch))
Expand All @@ -230,11 +253,17 @@ static void dump_channel_attributes(const struct iio_device *dev,

gen_function("channel", "ch", attr, NULL);
ret = iio_channel_attr_read(ch, attr, buf, BUF_SIZE);
if (!quiet)
printf("dev '%s', channel '%s' (%s), ",
iio_device_get_name(dev),
if (!quiet) {
printf("%s ", iio_device_is_trigger(dev) ? "trig" : "dev");
if (name)
printf("'%s'", name);
else
printf("'%s'", iio_device_get_id(dev));

printf(", channel '%s' (%s), ",
iio_channel_get_id(ch),
type_name);
}
if (iio_channel_get_name(ch) && !quiet)
printf("id '%s', ", iio_channel_get_name(ch));

Expand Down Expand Up @@ -576,18 +605,21 @@ int main(int argc, char **argv)
for (i = 0; i < nb_devices; i++) {
const struct iio_device *dev = iio_context_get_device(ctx, i);
const char *name = iio_device_get_name(dev);
const char *ch_name;
const char *dev_id = iio_device_get_id(dev);
unsigned int nb_attrs, nb_channels, j;


if (device_index && !str_match(name, argv[device_index], ignore_case))
if (device_index && !str_match(dev_id, argv[device_index], ignore_case)
&& !str_match(name, argv[device_index], ignore_case)) {
continue;
}

if ((search_device && !device_index) || (search_channel && !device_index) ||
(search_buffer && !device_index) || (search_debug && !device_index)) {
printf("\t%s:", iio_device_get_id(dev));
printf("\t%s", dev_id);
if (name)
printf(" %s", name);
printf(", ");
printf(", %s", name);
printf(": ");
}

if (search_channel && !device_index)
Expand Down Expand Up @@ -616,22 +648,26 @@ int main(int argc, char **argv)
else
type_name = "input";

name = iio_channel_get_name(ch);
ch_name = iio_channel_get_name(ch);
if (channel_index &&
!str_match(iio_channel_get_id(ch),
argv[channel_index], ignore_case) &&
(!name || (name &&
!str_match( name,argv[channel_index], ignore_case))))
(!ch_name || !str_match(ch_name,argv[channel_index], ignore_case)))
continue;

if ((!scan_only && !channel_index) ||
( scan_only && iio_channel_is_scan_element(ch))) {
printf("dev '%s', channel '%s'",
iio_device_get_name(dev),
printf("%s ", iio_device_is_trigger(dev) ? "trig" : "dev");
if (name)
printf("'%s', ", name);
else
printf("'%s', ", dev_id);

printf("channel '%s'",
iio_channel_get_id(ch));

if (name)
printf(", id '%s'", name);
if (ch_name)
printf(", id '%s'", ch_name);

printf(" (%s", type_name);

Expand Down
3 changes: 1 addition & 2 deletions tests/iio_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ char *cmn_strndup(const char *str, size_t n)
#else
size_t len = strnlen(str, n + 1);
char *buf = malloc(len + 1);

if (buf) {
/* len = size of buf, so memcpy is OK */
memcpy(buf, str, len); /* Flawfinder: ignore */
buf[len + 1] = 0;
buf[len] = 0;
}
return buf;
#endif
Expand Down