-
Notifications
You must be signed in to change notification settings - Fork 115
CSSTUDIO-3605 Always use the type "long" when converting to hexadecimal notation #3674
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
base: master
Are you sure you want to change the base?
Conversation
georgweiss
left a comment
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.
A unit test would maybe make sense?
|
Might be OK to always use Long in the conversion. A precision of 2 should show numbers 0x00 to 0xFF. That's because hex notation tends to be used on lower-level device displays to show register values, and the precision is used to match the size of the register: 2 digits for 8 bit byte, 4 digits for 16 bit word, 6 for 24 bit word (rare, but that's what we have in our timing system), 8 for 32 bit words. A precision of 16 should show numbers 0x0000000000000000 to 0xFFFFFFFFFFFFFFFF. Beware of sign extension. |
I have added tests: 82cebbd
That's a very good point; that was a bug! (And on the Two open questions:
|
|
I'm afraid there's no perfect answer ...
When you read a number from an ai, mbbi, longIn, .. record, you always get a "signed" number, even if the intent was to treat the number as unsigned. So unfortunately we can't easily figure out what to do... Maybe it's best to treat all numbers as unsigned for the hex format?
I would show 0xFFAA because that's the value. We'll use the precision as a hint to format values. With a precision of 2, a value 5 is shown as 0x05; 0xAA is shown as 0xAA. But a value that needs more digits will use them, better than showing the wrong value. |
The correct method to convert the received value to an unsigned phoebus/core/ui/src/main/java/org/phoebus/ui/vtype/FormatOptionHandler.java Lines 227 to 249 in 82cebbd
|
This pull request changes the method
FormatOptionHandler.formatNumber()so that the typelongis always used when converting a number to hexadecimal notation.FormatOptionHandler.formatNumber()is used by the Text Entry widget and the Text Update widget when the widget property "Format" is set to "Hexadecimal". If, furthermore, the widget property "Precision" is set to-1(the default value), thenFormatOptionHandler.formatNumber()will be called with its argumentprecisionset to3when called with a value of typedouble, with the consequence that, prior to this pull request, the type (signed)intwould be used to convert a number represented by adoubleto hexadecimal notation, potentially truncating the input.To me, it seems incorrect that the argument
precisionis used to determine the number of digits. For the decimal notation, the parameter refers to the number of digits after the period, and in this context, the default value of3makes sense for a value of typedouble. I think that for the property to mean something different for the hexadecimal notation is confusing, and I think the default (if any) should be a different value. Should this be changed, e.g., by introducing a new widget property for the number of digits before the period to display?