Skip to content

Commit 3f69133

Browse files
committed
iio_attr: make dealing with devices with no name easier.
---------- I've been through libiio on devices with no name It felt good to be out of the rain In the libiio you don't need remember your name 'Cause there ain't no one for to give you no pain apologies Dewey Bunnell ----------- Some properly formed iio devices have no name attribute, so don't force people to use a name when refering to them. Now when you find devices like this (no name), you can refer to things by the ID. $ ./tests/iio_attr -u ip:192.168.1.120 -d IIO context has 7 devices: iio:device1, ad9361-phy: found 18 device attributes iio:device3, cf-ad9361-dds-core-lpc: found 0 device attributes iio:device4, cf-ad9361-lpc: found 0 device attributes iio_sysfs_trigger: found 2 device attributes trigger0, sysfstrig1: found 1 device attributes iio ID and name can be used interchangeably $ ./tests/iio_attr -u ip:192.168.1.120 -d iio:device2 dev 'xadc', attr 'sampling_frequency', value :'961538' $ ./tests/iio_attr -u ip:192.168.1.120 -d xadc dev 'xadc', attr 'sampling_frequency', value :'961538' And when there is no name at all, you can just use the ID. $ ./tests/iio_attr -u ip:192.168.1.120 -d iio_sysfs_trigger dev 'iio_sysfs_trigger', attr 'add_trigger', value :ERROR: Unknown error 13 (-13) dev 'iio_sysfs_trigger', attr 'remove_trigger', value :ERROR: Unknown error 13 (-13) devices which are triggers will show up as triggers: ./tests/iio_attr -u ip:192.168.1.120 -d sysfstrig1 trig 'sysfstrig1', attr 'trigger_now', value :ERROR: Unknown error 13 (-13) Signed-off-by: Robin Getz <[email protected]>
1 parent 3a202a5 commit 3f69133

File tree

1 file changed

+60
-24
lines changed

1 file changed

+60
-24
lines changed

tests/iio_attr.c

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,18 @@ static void dump_device_attributes(const struct iio_device *dev,
9898
{
9999
ssize_t ret;
100100
char *buf = xmalloc(BUF_SIZE, MY_NAME);
101+
const char *name = iio_device_get_name(dev);
101102

102103
if (!wbuf || !quiet) {
103-
if (!quiet)
104-
printf("dev '%s', attr '%s', value :",
105-
iio_device_get_name(dev), attr);
104+
if (!quiet) {
105+
printf("%s ", iio_device_is_trigger(dev) ? "trig" : "dev");
106+
if(name)
107+
printf("'%s'", name);
108+
else
109+
printf("'%s'", iio_device_get_id(dev));
110+
111+
printf(", attr '%s', value :", attr);
112+
}
106113
gen_function("device", "dev", attr, NULL);
107114
ret = iio_device_attr_read(dev, attr, buf, BUF_SIZE);
108115
if (ret > 0) {
@@ -136,14 +143,21 @@ static void dump_buffer_attributes(const struct iio_device *dev,
136143
{
137144
ssize_t ret;
138145
char *buf = xmalloc(BUF_SIZE, MY_NAME);
146+
const char *name = iio_device_get_name(dev);
139147

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

144-
if (!quiet)
145-
printf("dev '%s', buffer attr '%s', value :",
146-
iio_device_get_name(dev), attr);
152+
if (!quiet) {
153+
printf("%s ", iio_device_is_trigger(dev) ? "trig" : "dev");
154+
if (name)
155+
printf("'%s'", name);
156+
else
157+
printf("'%s'", iio_device_get_id(dev));
158+
159+
printf(", buffer attr '%s', value :", attr);
160+
}
147161

148162
if (ret > 0) {
149163
if (quiet)
@@ -178,14 +192,22 @@ static void dump_debug_attributes(const struct iio_device *dev,
178192
{
179193
ssize_t ret;
180194
char *buf = xmalloc(BUF_SIZE, MY_NAME);
195+
const char *name = iio_device_get_name(dev);
181196

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

186-
if (!quiet)
187-
printf("dev '%s', debug attr '%s', value :",
188-
iio_device_get_name(dev), attr);
201+
if (!quiet) {
202+
printf("%s ", iio_device_is_trigger(dev) ? "trig" : "dev");
203+
if (name)
204+
printf("'%s'", name);
205+
else
206+
printf("'%s'", iio_device_get_id(dev));
207+
208+
printf(", debug attr '%s', value :", attr);
209+
210+
}
189211

190212
if (ret > 0) {
191213
if (quiet)
@@ -221,6 +243,7 @@ static void dump_channel_attributes(const struct iio_device *dev,
221243
ssize_t ret;
222244
char *buf = xmalloc(BUF_SIZE, MY_NAME);
223245
const char *type_name;
246+
const char *name = iio_device_get_name(dev);
224247

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

231254
gen_function("channel", "ch", attr, NULL);
232255
ret = iio_channel_attr_read(ch, attr, buf, BUF_SIZE);
233-
if (!quiet)
234-
printf("dev '%s', channel '%s' (%s), ",
235-
iio_device_get_name(dev),
256+
if (!quiet) {
257+
printf("%s ", iio_device_is_trigger(dev) ? "trig" : "dev");
258+
if (name)
259+
printf("'%s'", name);
260+
else
261+
printf("'%s'", iio_device_get_id(dev));
262+
263+
printf(", channel '%s' (%s), ",
236264
iio_channel_get_id(ch),
237265
type_name);
266+
}
238267
if (iio_channel_get_name(ch) && !quiet)
239268
printf("id '%s', ", iio_channel_get_name(ch));
240269

@@ -576,18 +605,21 @@ int main(int argc, char **argv)
576605
for (i = 0; i < nb_devices; i++) {
577606
const struct iio_device *dev = iio_context_get_device(ctx, i);
578607
const char *name = iio_device_get_name(dev);
608+
const char *ch_name;
609+
const char *dev_id = iio_device_get_id(dev);
579610
unsigned int nb_attrs, nb_channels, j;
580611

581-
582-
if (device_index && !str_match(name, argv[device_index], ignore_case))
612+
if (device_index && !str_match(dev_id, argv[device_index], ignore_case)
613+
&& !str_match(name, argv[device_index], ignore_case)) {
583614
continue;
615+
}
584616

585617
if ((search_device && !device_index) || (search_channel && !device_index) ||
586618
(search_buffer && !device_index) || (search_debug && !device_index)) {
587-
printf("\t%s:", iio_device_get_id(dev));
619+
printf("\t%s", dev_id);
588620
if (name)
589-
printf(" %s", name);
590-
printf(", ");
621+
printf(", %s", name);
622+
printf(": ");
591623
}
592624

593625
if (search_channel && !device_index)
@@ -616,22 +648,26 @@ int main(int argc, char **argv)
616648
else
617649
type_name = "input";
618650

619-
name = iio_channel_get_name(ch);
651+
ch_name = iio_channel_get_name(ch);
620652
if (channel_index &&
621653
!str_match(iio_channel_get_id(ch),
622654
argv[channel_index], ignore_case) &&
623-
(!name || (name &&
624-
!str_match( name,argv[channel_index], ignore_case))))
655+
(!ch_name || !str_match(ch_name,argv[channel_index], ignore_case)))
625656
continue;
626657

627658
if ((!scan_only && !channel_index) ||
628659
( scan_only && iio_channel_is_scan_element(ch))) {
629-
printf("dev '%s', channel '%s'",
630-
iio_device_get_name(dev),
660+
printf("%s ", iio_device_is_trigger(dev) ? "trig" : "dev");
661+
if (name)
662+
printf("'%s', ", name);
663+
else
664+
printf("'%s', ", dev_id);
665+
666+
printf("channel '%s'",
631667
iio_channel_get_id(ch));
632668

633-
if (name)
634-
printf(", id '%s'", name);
669+
if (ch_name)
670+
printf(", id '%s'", ch_name);
635671

636672
printf(" (%s", type_name);
637673

0 commit comments

Comments
 (0)