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_attr: accept negative numbers as data to write to #577

Merged
merged 1 commit into from
Jul 29, 2020

Conversation

rgetz
Copy link
Contributor

@rgetz rgetz commented Jul 28, 2020

getopt doesn't understand the difference between the '-' before an
option and the '-' before a negative number. It can not - they are both
the same, and in some applications option zero (-0) might be valid.

in iio_attr this causes problems when we try to write negative numbers

root@analog:~# iio_attr -o -c adrv9002-phy voltage0 hardwaregain -10
iio_attr: invalid option -- '1'

Since the only time we do this in in iio_attr, handle the last option
differently (if the last option is a negative number).

This does mean we still don't pass -foo to an attribute to be written,
since iio_attr thinks that is an unknown "-f" option.

./tests/iio_attr -v -a usb -o -c ad9361-phy voltage0 hardwaregain -foo
Using auto-detected IIO context at URI "usb:3.39.5"
./tests/iio_attr: invalid option -- 'f'

but this does fix the reported bug #573

./tests/iio_attr -v -a usb -o -c ad9361-phy voltage0 hardwaregain -1
Using auto-detected IIO context at URI "usb:3.39.5"
dev 'ad9361-phy', channel 'voltage0' (output), attr 'hardwaregain', value '-10.000000 dB'
wrote 3 bytes to hardwaregain
dev 'ad9361-phy', channel 'voltage0' (output), attr 'hardwaregain', value '-1.000000 dB'

Signed-off-by: Robin Getz [email protected]

getopt doesn't understand the difference between the '-' before an
option and the '-' before a negative number. It can not - they are both
the same, and in some applications option zero (-0) might be valid.

in iio_attr this causes problems when we try to write negative numbers

root@analog:~# iio_attr -o -c adrv9002-phy voltage0 hardwaregain -10
iio_attr: invalid option -- '1'

Since the only time we do this in in iio_attr, handle the last option
differently (if the last option is a negative number).

This does mean we still don't pass -foo to an attribute to be written,
since iio_attr thinks that is an unknown "-f" option.

./tests/iio_attr -v -a usb -o -c ad9361-phy voltage0 hardwaregain -foo
Using auto-detected IIO context at URI "usb:3.39.5"
./tests/iio_attr: invalid option -- 'f'

but this does fix the reported bug #573

./tests/iio_attr -v -a usb -o -c ad9361-phy voltage0 hardwaregain -1
Using auto-detected IIO context at URI "usb:3.39.5"
dev 'ad9361-phy', channel 'voltage0' (output), attr 'hardwaregain', value '-10.000000 dB'
wrote 3 bytes to hardwaregain
dev 'ad9361-phy', channel 'voltage0' (output), attr 'hardwaregain', value '-1.000000 dB'

Signed-off-by: Robin Getz <[email protected]>
@rgetz rgetz force-pushed the rgetz-fix-negative-numbers-in-iio_attr branch from f1bfe53 to b5bc289 Compare July 29, 2020 14:55
@rgetz
Copy link
Contributor Author

rgetz commented Jul 29, 2020

this was a simple rebase on master, to make sure that the windows version works.

@rgetz rgetz merged commit f0089b5 into master Jul 29, 2020
@rgetz rgetz deleted the rgetz-fix-negative-numbers-in-iio_attr branch July 29, 2020 22:07
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.

4 participants