Skip to content

Commit

Permalink
Treat hex-formatted numbers in text update as "unsigned"
Browse files Browse the repository at this point in the history
  • Loading branch information
kasemir committed May 22, 2024
1 parent 178b9b8 commit 49d51e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ view.jsp?cache=false&display=file:/Path/to/Display+Builder/01_main.bob
<hr>

<div id="versions">
2024-05-22 Treat hex-formatted numbers in text update as "unsigned".<br>
2024-05-10 Text update handles 'string' format since PVWS now sends long strings as byte array<br>
2024-03-06 Support alpha for shape backgrounds. Polyline/gon default line color. Ellipse, arc default sizes.<br>
2024-02-26 Version: Treat missing as 0.0.0<br>
Expand Down
24 changes: 20 additions & 4 deletions src/main/webapp/widgets/textupdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ function format_engineering(number, precision)
return text;
}

/** Convert data from EPICS that might arrive as negative number
* into "unsigned" positive number
* @param number Any number
* @returns Number as "unsigned"
*/
function makeUnsigned(number)
{
// Truncate to int32
number = number | 0;
// Wrap around to positive
if (number < 0)
number += 0x100000000;
return number;
}

/** Format data as text (e.g. number with precision, units)
* @param widget Widget that has 'format' etc.
Expand Down Expand Up @@ -76,12 +90,12 @@ function format_pv_data_as_text(widget, data)
text = format_engineering(data.value, precision);
else if (widget.data("format") == "hex")
{
text = (data.value | 0).toString(16);
text = makeUnsigned(data.value).toString(16).toUpperCase();
text = "0x" + text;
}
else if (widget.data("format") == "binary")
{
text = (data.value | 0).toString(2);
text = makeUnsigned(data.value).toString(2);
text = "0b" + text;
}
else if (widget.data("format") == "string" && Array.isArray(data.value))
Expand All @@ -93,9 +107,11 @@ function format_pv_data_as_text(widget, data)
if (data.precision === undefined)
text = data.value.toString();
else
if (Array.isArray(data.value)) {
if (Array.isArray(data.value))
{
text = "";
for (let i = 0; i < data.value.length; i++){
for (let i = 0; i < data.value.length; i++)
{
if (typeof data.value[i].toFixed == 'function')
text = text.concat(data.value[i].toFixed(precision));
else
Expand Down

0 comments on commit 49d51e5

Please sign in to comment.