iio_attr: accept negative numbers as data to write to #577
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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]