-
Notifications
You must be signed in to change notification settings - Fork 320
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
Channel label support #1229
base: main
Are you sure you want to change the base?
Channel label support #1229
Conversation
603820a
to
3fb2071
Compare
V2:
|
Hi @dNechita, I plan to give a better review on this one next week. For now, some points from me:
|
reversing the order of the patches will cause build failures (won't it?) - since you will be using label, before it's added/initialized. I can see swapping the order of: so that local is filled out when you start using them - but it shouldn't really matter too much... |
I think the patch set is incomplete/wrong somewhere: running it I get (on iio_info):
the issue I want to point out is that the lable still shows up as an attribute, when it should be eaten as a label... We see:
rather than:
It doesn't make sense to expose the I think this just means it's missing an early return somewhere in local.c for example, this is what the early return does here:
|
I didn't meant literally. Likely, as you pointed out, it needs some rework in order to change the order. But it should be doable to code all the foundation and the last patch to just be exposing the API to the "outside world". As it stands, I do not think it makes to much sense to expose an API without being implemented. |
Yes, I have missed adding the implementation that would consider the label not to be a simple attribute. I will include it. Thanks! |
Regarding the order of the commits, this time I just used the order presented in issue that was requesting the feature. But if it wasn't for that order I would have still started with the end in mind, meaning adding API, and even updating the clients of the API and then going for the implementation. This is more of an order of how I would develop, and I can keep it while changing the commits order when creating a PR if that is easier to review. |
It's not it is easier to review. It just does not make sense to me to have a public API without being implemented. Naturally you're thinking on just having the complete PR merged and then this does not matter... I'm more looking at the series on a patch by patch basis and what makes sense to me. Sometimes, one also should have in mind things like All the above said, this is a nitpick and a minor detail |
3fb2071
to
384d318
Compare
V3:
|
I think the iio_info issue is fixed...
and main branch:
turns into:
which I think is what we are looking for... :) |
384d318
to
8abf207
Compare
V4:
|
Looks good to me - check on the issues Codacy is pointing out, and decide which ones you want to ignore/fix. |
8abf207
to
4acaafe
Compare
V5:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me. should tag this with #1222 to keep things in sync.
also helps |
Will add. Thanks for the code snippet. |
4acaafe
to
066d1ef
Compare
const char *dev_id; | ||
|
||
if (strlen(name) >= lbl_len && | ||
!strcmp(name + strlen(name) - lbl_len, "_label")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not convinced the above is not just doing something get_short_attr_name()
is already doing... You did not replied to my last comment but unless I'm missing something, if the channel name is in_voltage0_label, that function should return "label" and you can avoid all that pointer arithmetic. If you look at the implementation the whole point of the function is to give the channel short name, meaning, the name after the last _
. Is there any other subtle thing I'm missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to address your concern.
With these changes:
diff --git a/local.c b/local.c
index 2b28912c..28fe25b7 100644
--- a/local.c
+++ b/local.c
@@ -851,6 +851,8 @@ static int add_attr_to_channel(struct iio_channel *chn,
} else {
chn_perror(chn, ret, "Unable to read channel label");
}
+ fprintf(stderr, "initial_name: %s\n", name);
+ fprintf(stderr, "name_after_get_short: %s\n", get_short_attr_name(chn, name));
return 0;
}
I am getting the following:
analog@analog:~/workspace-dan/libiio/build_v1 $ utils/iio_info
initial_name: out_altvoltage1_TX1_I_F2_label
name_after_get_short: TX1_I_F2_label
initial_name: out_altvoltage0_TX1_I_F1_label
name_after_get_short: TX1_I_F1_label
initial_name: out_altvoltage7_TX2_Q_F2_label
name_after_get_short: TX2_Q_F2_label
initial_name: out_altvoltage6_TX2_Q_F1_label
name_after_get_short: TX2_Q_F1_label
initial_name: out_altvoltage3_TX1_Q_F2_label
name_after_get_short: TX1_Q_F2_label
initial_name: out_altvoltage2_TX1_Q_F1_label
name_after_get_short: TX1_Q_F1_label
initial_name: out_altvoltage5_TX2_I_F2_label
name_after_get_short: TX2_I_F2_label
initial_name: out_altvoltage4_TX2_I_F1_label
name_after_get_short: TX2_I_F1_label
initial_name: out_altvoltage1_TX_LO_label
name_after_get_short: TX_LO_label
initial_name: out_altvoltage0_RX_LO_label
name_after_get_short: RX_LO_label
initial_name: in_voltage7_vrefn_label
name_after_get_short: vrefn_label
initial_name: in_voltage1_vccaux_label
name_after_get_short: vccaux_label
initial_name: in_voltage2_vccbram_label
name_after_get_short: vccbram_label
initial_name: in_voltage3_vccpint_label
name_after_get_short: vccpint_label
initial_name: in_voltage0_vccint_label
name_after_get_short: vccint_label
initial_name: in_voltage6_vrefp_label
name_after_get_short: vrefp_label
initial_name: in_voltage5_vccoddr_label
name_after_get_short: vccoddr_label
initial_name: in_voltage4_vccpaux_label
name_after_get_short: vccpaux_label
Which seems that it strips away the input/output information and the channel id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was now just getting more familiar with libiio code for populating channels and attrs. Indeed for legacy devices which make use of extended_names (which are now exposed as labels) the short name function won't work.
out_altvoltage1_TX1_I_F2_label - TX1_I_F2 is the extended name and will be seen as the channel name by libiio. This stuff seems to be addressed later on in set_channel_name()
where we set the proper attr name. So, even if we handle things later and not in add_attr_to_channel()
, not sure it would be simpler. So yeah, looks good as-is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some minor nits...
local.c
Outdated
label, sizeof(label), IIO_ATTR_TYPE_CHANNEL); | ||
if (ret > 0) { | ||
chn_label_ptr = label; | ||
chn->label = iio_strdup(chn_label_ptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this simply be chn->label = iio_strdup(label);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can be. Thanks!
@@ -139,6 +139,7 @@ struct iio_channel * iio_device_find_channel(const struct iio_device *dev, | |||
continue; | |||
|
|||
if (!strcmp(chn->id, name) || | |||
(chn->label && !strcmp(chn->label, name)) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing wrong with the patch but commit subject does not match the style :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean that there is an extra tab on this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no.. the commit title itself. nothing wrong with the code. It's a nitpick but consistency across git log is a good thing. Also good for grepping the history
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I got it now. I need to grab another coffee.
When the "label" channel attribute is found, initialize the channel's label to its value. Signed-off-by: Dan Nechita <dan.nechita@analog.com>
This function can be used to retrieve the label for this IIO Channel, if it was specified in linux driver. Signed-off-by: Dan Nechita <dan.nechita@analog.com>
Make iio_device_find_channel() able to search not only by ID and name, but also by label. Signed-off-by: Dan Nechita <dan.nechita@analog.com>
Signed-off-by: Dan Nechita <dan.nechita@analog.com>
Signed-off-by: Dan Nechita <dan.nechita@analog.com>
Signed-off-by: Dan Nechita <dan.nechita@analog.com>
If a IIO channel has a label, display it after the name. Signed-off-by: Dan Nechita <dan.nechita@analog.com>
If a IIO channel has a label, display it and support matching against the label. Signed-off-by: Dan Nechita <dan.nechita@analog.com>
Signed-off-by: Dan Nechita <dan.nechita@analog.com>
066d1ef
to
d27b264
Compare
V6:
|
PR Description
Add support for labels in IIO channels, similar to IIO devices.
These changes add
iio_channel_get_label(const struct iio_channel *chn)
to the existing API.PR Type
PR Checklist