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

Add offset to iio_data_format, rework scale #1084

Merged
merged 5 commits into from
Nov 21, 2023
Merged

Conversation

pcercuei
Copy link
Contributor

Add an offset field in the iio_data_format structure alongside the "scale". Make sure those two are initialized properly for all channels, not just the scan-element ones.

Copy link
Contributor

@nunojsa nunojsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits that you ignore if you want...


/** @brief Contains a value to be added to the raw sample before
* applying the scale. */
double offset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a side note... structs in header files are always nice to get some ABI breakage down the road. I wonder if we shouldn't have some reserved bits in here? At least for when v1.0 is out...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was thinking that this is not a problem because old applications won't try to access the "offset" field. Apps built with Libiio > 1.0 may try to access new fields that are yet to be added, but we never really cared about forward compatibility.

With that said - I can add some padding, it's not that much more work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if the new fields are always added in the end of the struct but we will always leave the door open for subtle things and like you said... it's not much work at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, as a separate commit. Thanks for the review btw.

context.c Outdated
int err;

if (!ctx->ops->read_attr) {
/* read_attr callback not implemented - nothing to do. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't think the comment adds much value. The code is very self explanatory...

&chn->format.offset);
if (err) {
chn_perror(chn, err, "Unable to read offset");
return err;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't checked the code so just sanity checking... There's really no with_offset like in the scale case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there's no need, having no offset is the same as having offset == 0.0 (just like having no scale is the same as having scale == 1.0, but it's too late for that).

@pcercuei pcercuei force-pushed the pcercuei/scale-offset branch from 7554f94 to 17fd469 Compare November 20, 2023 15:55
Add an 'offset' field, which contains the offset that should be added to
the raw sample values.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Add padding after the iio_data_format, which will be cleared to zero
during initialization. The total of (iio_data_format + padding) will be
128 bytes which should be plenty. The point of this, is to make sure
that we can have forward compatibility with any apps built with a newer
version of Libiio that may have more fields added to the iio_data_format
structure.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
The iio_data_format.scale field was previously only set for scan-element
channels. This was wrong, as regular channels can have a scale as well.
Both can also have an offset, which is added to the raw value before
applying the scale; this offset was not present in the iio_data_format
structure.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Remove the code reading the scale into the format structure. This is now
done better by iio_context_update_scale_offset(), which is called at the
end of iio_create_context(), and has the added advantage of reading the
scale for all channels (not just the scan-elements) and also read the
offsets.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Add an 'offset' field, which contains the offset that should be added to
the raw sample values.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
@pcercuei pcercuei force-pushed the pcercuei/scale-offset branch from 17fd469 to 78bf1e3 Compare November 21, 2023 13:10
@pcercuei pcercuei merged commit 65a5a5f into main Nov 21, 2023
19 of 25 checks passed
@pcercuei pcercuei deleted the pcercuei/scale-offset branch November 21, 2023 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants