Skip to content

Commit 6e08128

Browse files
authored
fix hex display of telemetry and event ids in gds gui (#288)
ids were showing decimal values with 0x prefix because js object keys are always strings and String.toString(16) ignores the radix. added formatHexId() utility and cast dict keys to Number on init. Fixes nasa/fprime#4717
1 parent c6cac11 commit 6e08128

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/fprime_gds/flask/static/js/datastore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class DataStore {
263263
// because rendering of edit-views is still possible.
264264
let channels = {};
265265
for (let key in _dictionaries.channels) {
266-
channels[key] = {id: key, time: null, datetime: null, val: null};
266+
channels[key] = {id: Number(key), time: null, datetime: null, val: null};
267267
}
268268
Object.assign(this.channels, channels); // Forces new channel map into Vue maintaining the original object
269269
this.commands = _dictionaries.commands;

src/fprime_gds/flask/static/js/vue-support/channel.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @author mstarch
88
*/
9-
import {listExistsAndItemNameNotInList, timeToString} from "./utils.js"
9+
import {listExistsAndItemNameNotInList, timeToString, formatHexId} from "./utils.js"
1010
import "./fptable.js";
1111
import {_datastore, _dictionaries} from "../datastore.js";
1212

@@ -66,9 +66,9 @@ Vue.component("channel-table", {
6666
columnify(item) {
6767
let template = _dictionaries.channels[item.id];
6868
if (item.time == null || item.val == null) {
69-
return ["", "0x" + item.id.toString(16), template.full_name, ""];
69+
return ["", formatHexId(item.id), template.full_name, ""];
7070
}
71-
return [timeToString(item.time), "0x" + item.id.toString(16), template.full_name,
71+
return [timeToString(item.time), formatHexId(item.id), template.full_name,
7272
(typeof(item.display_text) !== "undefined")? item.display_text : item.val]
7373
},
7474
/**
@@ -150,7 +150,7 @@ Vue.component("channel-table", {
150150
clearChannels() {
151151
let channels = {}
152152
for (let key in _dictionaries.channels) {
153-
channels[key] = {id: key, time: null, datetime: null, val: null};
153+
channels[key] = {id: Number(key), time: null, datetime: null, val: null};
154154
}
155155
Object.assign(_datastore.channels, channels);
156156
this.$refs.fptable.send([]);

src/fprime_gds/flask/static/js/vue-support/event.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @author mstarch
99
*/
10-
import {listExistsAndItemNameNotInList, timeToString} from "./utils.js";
10+
import {listExistsAndItemNameNotInList, timeToString, formatHexId} from "./utils.js";
1111
import {_datastore,_dictionaries} from "../datastore.js";
1212

1313
let OPREG = /Opcode (0x[0-9a-fA-F]+)/;
@@ -80,7 +80,7 @@ Vue.component("event-list", {
8080
const msg = '<span title="' + groups[0] + '">' + command_mnemonic + '</span>'
8181
display_text = display_text.replace(OPREG, msg);
8282
}
83-
return [timeToString(item.time), "0x" + item.id.toString(16), template.full_name,
83+
return [timeToString(item.time), formatHexId(item.id), template.full_name,
8484
template.severity.value.replace("EventSeverity.", ""), display_text];
8585
},
8686
/**

src/fprime_gds/flask/static/js/vue-support/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,13 @@ export class ScrollHandler {
444444
return user_scrolled;
445445
}
446446
}
447+
448+
// converts id to proper hex string, handles both number and string ids
449+
// since js object keys are always strings, .toString(16) on a string
450+
// just returns the string as-is wich causes the decimal-with-0x-prefix bug
451+
export function formatHexId(id) {
452+
if (id == null) {
453+
return "";
454+
}
455+
return "0x" + BigInt(id).toString(16);
456+
}

0 commit comments

Comments
 (0)