@tsplc/tmp-debug 0.0.0-stage → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -2
- package/dist/api.js +744 -0
- package/dist/api.js.map +12 -0
- package/dist/constant.js +33 -0
- package/dist/constant.js.map +10 -0
- package/dist/explain-file.js +468 -0
- package/dist/explain-file.js.map +11 -0
- package/dist/explain.js +1310 -0
- package/dist/explain.js.map +19 -0
- package/dist/format.js +214 -0
- package/dist/format.js.map +12 -0
- package/dist/index.js +4066 -0
- package/dist/index.js.map +44 -0
- package/dist/manifest.js +240 -0
- package/dist/manifest.js.map +10 -0
- package/dist/paths.js +242 -0
- package/dist/paths.js.map +10 -0
- package/package.json +72 -4
- package/src/adapter.ts +77 -0
- package/src/api.ts +446 -0
- package/src/app-server.ts +151 -0
- package/src/build-files.ts +46 -0
- package/src/constant.ts +41 -0
- package/src/debugger.ts +237 -0
- package/src/errors.ts +13 -0
- package/src/explain-expressions.ts +484 -0
- package/src/explain-file.ts +325 -0
- package/src/explain-frames.ts +155 -0
- package/src/explain-loops.ts +151 -0
- package/src/explain-operations.ts +232 -0
- package/src/explain-tables.ts +345 -0
- package/src/explain-value.ts +203 -0
- package/src/explain-verdicts.ts +548 -0
- package/src/explain.ts +82 -0
- package/src/hardware.ts +159 -0
- package/src/http.ts +218 -0
- package/src/index.ts +44 -0
- package/src/jobs.ts +139 -0
- package/src/login-value.ts +165 -0
- package/src/login.ts +315 -0
- package/src/manifest.ts +328 -0
- package/src/opcua.ts +80 -0
- package/src/paths.ts +363 -0
- package/src/requests.ts +99 -0
- package/src/server-cursor.ts +22 -0
- package/src/shown.ts +229 -0
- package/src/telemetry.ts +125 -0
- package/src/timeline.ts +148 -0
- package/src/trace.ts +62 -0
- package/src/ui/bits.ts +48 -0
- package/src/ui/client.ts +87 -0
- package/src/ui/dom.ts +61 -0
- package/src/ui/explain-read.ts +105 -0
- package/src/ui/format.ts +261 -0
- package/src/ui/hardware.ts +425 -0
- package/src/ui/header.ts +207 -0
- package/src/ui/health.ts +64 -0
- package/src/ui/index.ts +27 -0
- package/src/ui/jobs.ts +263 -0
- package/src/ui/links.ts +59 -0
- package/src/ui/live-value.ts +85 -0
- package/src/ui/main.ts +76 -0
- package/src/ui/overview.ts +178 -0
- package/src/ui/page.ts +286 -0
- package/src/ui/pages.ts +64 -0
- package/src/ui/recent-window.ts +49 -0
- package/src/ui/recent.ts +355 -0
- package/src/ui/request-trace.ts +38 -0
- package/src/ui/requests.ts +80 -0
- package/src/ui/routes.ts +98 -0
- package/src/ui/store.ts +295 -0
- package/src/ui/success-cache.ts +11 -0
- package/src/ui/tree.ts +162 -0
- package/src/ui/variables.ts +597 -0
- package/src/ui/why-watch.ts +11 -0
- package/src/ui/why.ts +694 -0
- package/src/values.ts +170 -0
- package/src/watch.ts +32 -0
package/src/ui/format.ts
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import {
|
|
2
|
+
elementaryType,
|
|
3
|
+
isIntegerValued,
|
|
4
|
+
nanosecondsPerMillisecond,
|
|
5
|
+
} from "@tsplc/iec";
|
|
6
|
+
import type { Quality } from "@tsplc/opcua/contract";
|
|
7
|
+
import type { JobState, Session } from "../api";
|
|
8
|
+
import { decodeConstant } from "../constant";
|
|
9
|
+
import type { DebugJob, DebugManifest, SourceRange } from "../manifest";
|
|
10
|
+
import { typeOf } from "../paths";
|
|
11
|
+
|
|
12
|
+
/** How a value is shown: each state has its own styling and label, so none passes for live. */
|
|
13
|
+
export type ValueState =
|
|
14
|
+
| "live"
|
|
15
|
+
| "uncertain"
|
|
16
|
+
| "bad"
|
|
17
|
+
| "stale"
|
|
18
|
+
| "unavailable"
|
|
19
|
+
| "constant";
|
|
20
|
+
|
|
21
|
+
export const valueStateLabels: Record<ValueState, string> = {
|
|
22
|
+
live: "good",
|
|
23
|
+
uncertain: "uncertain",
|
|
24
|
+
bad: "bad",
|
|
25
|
+
stale: "stale",
|
|
26
|
+
unavailable: "unavailable",
|
|
27
|
+
constant: "constant",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** How old a sample read every `intervalMs` may be before it is stale. */
|
|
31
|
+
export const staleAfterMs = (intervalMs: number) => 3 * intervalMs;
|
|
32
|
+
|
|
33
|
+
export const valueState = (
|
|
34
|
+
quality: Quality,
|
|
35
|
+
ageMs: number,
|
|
36
|
+
context: { connected: boolean; intervalMs: number },
|
|
37
|
+
): ValueState => {
|
|
38
|
+
if (quality === "unavailable") {
|
|
39
|
+
return "unavailable";
|
|
40
|
+
}
|
|
41
|
+
if (!context.connected || ageMs > staleAfterMs(context.intervalMs)) {
|
|
42
|
+
return "stale";
|
|
43
|
+
}
|
|
44
|
+
if (quality === "bad") {
|
|
45
|
+
return "bad";
|
|
46
|
+
}
|
|
47
|
+
if (quality === "uncertain") {
|
|
48
|
+
return "uncertain";
|
|
49
|
+
}
|
|
50
|
+
return "live";
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** How long ago, in its largest whole unit: `now`, `2 s`, `2 min`, `2 h`. */
|
|
54
|
+
export const formatElapsed = (ms: number) => {
|
|
55
|
+
if (ms < 1000) {
|
|
56
|
+
return "now";
|
|
57
|
+
}
|
|
58
|
+
if (ms < 60_000) {
|
|
59
|
+
return `${Math.floor(ms / 1000)} s`;
|
|
60
|
+
}
|
|
61
|
+
if (ms < 3_600_000) {
|
|
62
|
+
return `${Math.floor(ms / 60_000)} min`;
|
|
63
|
+
}
|
|
64
|
+
return `${Math.floor(ms / 3_600_000)} h`;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const formatAge = (ms: number) =>
|
|
68
|
+
ms < 1000 ? formatElapsed(ms) : `${formatElapsed(ms)} ago`;
|
|
69
|
+
|
|
70
|
+
export const formatDuration = (ms: number) => {
|
|
71
|
+
if (ms < 1000) {
|
|
72
|
+
return `${Math.round(ms)} ms`;
|
|
73
|
+
}
|
|
74
|
+
if (ms < 60_000) {
|
|
75
|
+
return `${(ms / 1000).toFixed(1)} s`;
|
|
76
|
+
}
|
|
77
|
+
return `${Math.floor(ms / 60_000)} min ${Math.floor((ms % 60_000) / 1000)} s`;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** How often values are read: `250 ms`, `1 s`, `1.5 s`. */
|
|
81
|
+
export const formatInterval = (ms: number) =>
|
|
82
|
+
ms < 1000 ? `${ms} ms` : `${ms / 1000} s`;
|
|
83
|
+
|
|
84
|
+
/** How values are read, such as `engineering login · every 1 s`. */
|
|
85
|
+
export const readingLabel = ({ method, intervalMs }: Session["reading"]) =>
|
|
86
|
+
`${method} · every ${formatInterval(intervalMs)}`;
|
|
87
|
+
|
|
88
|
+
/** Local time of day with milliseconds, for ordering events by eye. */
|
|
89
|
+
export const formatClock = (iso: string) => {
|
|
90
|
+
const date = new Date(iso);
|
|
91
|
+
const pad = (value: number, width = 2) => String(value).padStart(width, "0");
|
|
92
|
+
return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}.${pad(date.getMilliseconds(), 3)}`;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** Local time of day to the second: `14:03:27`. */
|
|
96
|
+
export const formatTimeOfDay = (iso: string) => formatClock(iso).slice(0, 8);
|
|
97
|
+
|
|
98
|
+
/** When a value was read, to the second: `read 14:03:27`. */
|
|
99
|
+
export const formatReadAt = (iso: string) => `read ${formatTimeOfDay(iso)}`;
|
|
100
|
+
|
|
101
|
+
type Failure = Pick<NonNullable<JobState["failure"]>, "code" | "name">;
|
|
102
|
+
|
|
103
|
+
/** Failed while idle since its last unhandled failure: a later start that ended well clears it. */
|
|
104
|
+
export const failedWhileIdle = (job: JobState) =>
|
|
105
|
+
job.busy === false &&
|
|
106
|
+
job.failure !== undefined &&
|
|
107
|
+
(job.startedAt === undefined || job.failure.at >= job.startedAt);
|
|
108
|
+
|
|
109
|
+
export type JobStatus = "cancelling" | "busy" | "unknown" | "failed" | "idle";
|
|
110
|
+
|
|
111
|
+
export const jobStatus = (job: JobState): JobStatus => {
|
|
112
|
+
if (job.cancelling) {
|
|
113
|
+
return "cancelling";
|
|
114
|
+
}
|
|
115
|
+
if (job.busy) {
|
|
116
|
+
return "busy";
|
|
117
|
+
}
|
|
118
|
+
if (job.busy === null) {
|
|
119
|
+
return "unknown";
|
|
120
|
+
}
|
|
121
|
+
if (failedWhileIdle(job)) {
|
|
122
|
+
return "failed";
|
|
123
|
+
}
|
|
124
|
+
return "idle";
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const failureName = (manifest: DebugManifest, failure: Failure) =>
|
|
128
|
+
failure.name ??
|
|
129
|
+
manifest.errors[String(failure.code)] ??
|
|
130
|
+
`error ${failure.code}`;
|
|
131
|
+
|
|
132
|
+
/** Compiler-made jobs, such as each service call's own, are hidden unless asked for or linked to. */
|
|
133
|
+
export const isProgramJob = (job: DebugJob) => !job.generated;
|
|
134
|
+
|
|
135
|
+
/** A value of unknown type: booleans as IEC literals, strings quoted. */
|
|
136
|
+
export const formatScalar = (value: unknown): string => {
|
|
137
|
+
if (typeof value === "boolean") {
|
|
138
|
+
return value ? "TRUE" : "FALSE";
|
|
139
|
+
}
|
|
140
|
+
if (typeof value === "number") {
|
|
141
|
+
return Number.isInteger(value)
|
|
142
|
+
? String(value)
|
|
143
|
+
: String(Number(value.toPrecision(6)));
|
|
144
|
+
}
|
|
145
|
+
if (value === null || value === undefined) {
|
|
146
|
+
return "—";
|
|
147
|
+
}
|
|
148
|
+
return JSON.stringify(value);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* A value of an elementary type: a duration in milliseconds, read live as a number or written by
|
|
153
|
+
* `encodeConstant` as `250ms`, and an integer `encodeConstant` wrote as decimal text by its digits.
|
|
154
|
+
*/
|
|
155
|
+
const formatElementary = (iec: string, value: unknown): string => {
|
|
156
|
+
const type = elementaryType(iec);
|
|
157
|
+
const constant = decodeConstant(value);
|
|
158
|
+
if (type?.family === "duration" && typeof value === "number") {
|
|
159
|
+
return `${formatScalar(value)} ms`;
|
|
160
|
+
}
|
|
161
|
+
if (type?.family === "duration" && constant?.kind === "duration") {
|
|
162
|
+
return `${constant.nanoseconds / nanosecondsPerMillisecond} ms`;
|
|
163
|
+
}
|
|
164
|
+
if (
|
|
165
|
+
isIntegerValued(type) &&
|
|
166
|
+
typeof value === "string" &&
|
|
167
|
+
constant?.kind === "integer"
|
|
168
|
+
) {
|
|
169
|
+
return String(constant.value);
|
|
170
|
+
}
|
|
171
|
+
return formatScalar(value);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/** A value in the program's terms: enum members by name, whether the host decoded them already or not. */
|
|
175
|
+
export const formatValue = (
|
|
176
|
+
manifest: DebugManifest,
|
|
177
|
+
typeId: string,
|
|
178
|
+
value: unknown,
|
|
179
|
+
): string => {
|
|
180
|
+
const type = typeOf(manifest, typeId);
|
|
181
|
+
if (type.kind === "scalar") {
|
|
182
|
+
return formatElementary(type.iec, value);
|
|
183
|
+
}
|
|
184
|
+
if (type.kind !== "enum") {
|
|
185
|
+
return formatScalar(value);
|
|
186
|
+
}
|
|
187
|
+
if (typeof value === "string" && Object.hasOwn(type.members, value)) {
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
if (typeof value !== "number") {
|
|
191
|
+
return formatScalar(value);
|
|
192
|
+
}
|
|
193
|
+
const member = Object.entries(type.members).find(
|
|
194
|
+
([, number]) => number === value,
|
|
195
|
+
)?.[0];
|
|
196
|
+
return member ?? `${value} (not a ${type.name})`;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export const typeLabel = (manifest: DebugManifest, typeId: string): string => {
|
|
200
|
+
const type = typeOf(manifest, typeId);
|
|
201
|
+
switch (type.kind) {
|
|
202
|
+
case "scalar":
|
|
203
|
+
return type.iec;
|
|
204
|
+
case "enum":
|
|
205
|
+
case "record":
|
|
206
|
+
return type.name;
|
|
207
|
+
case "array":
|
|
208
|
+
return `${typeLabel(manifest, type.element)}[${type.length}]`;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const PROPERTY_TEXT = 16;
|
|
213
|
+
|
|
214
|
+
/** A record's properties as `tag=ITEM-0001-23… sensor=3`, long strings cut short. */
|
|
215
|
+
export const formatProperties = (properties: Record<string, unknown>) =>
|
|
216
|
+
Object.entries(properties)
|
|
217
|
+
.map(([key, value]) => {
|
|
218
|
+
const text = typeof value === "string" ? value : formatScalar(value);
|
|
219
|
+
return `${key}=${text.length > PROPERTY_TEXT ? `${text.slice(0, PROPERTY_TEXT)}…` : text}`;
|
|
220
|
+
})
|
|
221
|
+
.join(" ");
|
|
222
|
+
|
|
223
|
+
/** A VS Code link to a project file, when the project root on the debugger host is known. */
|
|
224
|
+
const fileHref = (
|
|
225
|
+
projectRoot: string | undefined,
|
|
226
|
+
file: string,
|
|
227
|
+
line: number,
|
|
228
|
+
column: number,
|
|
229
|
+
) => {
|
|
230
|
+
if (projectRoot === undefined) {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
const root = projectRoot.replaceAll("\\", "/").replace(/\/$/, "");
|
|
234
|
+
const absolute = `${root}/${file}`.replace(/^\/?/, "/");
|
|
235
|
+
return `vscode://file${absolute}:${line}:${column}`;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/** `file:line`, and a VS Code link when the project root on the debugger host is known. */
|
|
239
|
+
export const sourceLocation = (
|
|
240
|
+
manifest: DebugManifest,
|
|
241
|
+
projectRoot: string | undefined,
|
|
242
|
+
range: SourceRange,
|
|
243
|
+
) => {
|
|
244
|
+
const file = manifest.sources[range.file] ?? `source ${range.file}`;
|
|
245
|
+
const href = fileHref(projectRoot, file, range.line, range.column);
|
|
246
|
+
return { label: `${file}:${range.line}`, ...(href && { href }) };
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/** A record's project-relative `file:line` as `basename:line`, with the same VS Code link. */
|
|
250
|
+
export const recordLocation = (
|
|
251
|
+
projectRoot: string | undefined,
|
|
252
|
+
source: string,
|
|
253
|
+
) => {
|
|
254
|
+
const [, file = source, line] = /^(.*):(\d+)$/.exec(source) ?? [];
|
|
255
|
+
const label = `${file.slice(file.lastIndexOf("/") + 1)}${line ? `:${line}` : ""}`;
|
|
256
|
+
const href =
|
|
257
|
+
line === undefined
|
|
258
|
+
? undefined
|
|
259
|
+
: fileHref(projectRoot, file, Number(line), 1);
|
|
260
|
+
return { label, ...(href && { href }) };
|
|
261
|
+
};
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import type { Quality } from "@tsplc/opcua/contract";
|
|
2
|
+
import type { DebugChannel, DebugDevice } from "../manifest";
|
|
3
|
+
import { mapBits, readBits } from "./bits";
|
|
4
|
+
import { empty, fill, h, table, type View } from "./dom";
|
|
5
|
+
import {
|
|
6
|
+
formatScalar,
|
|
7
|
+
formatValue,
|
|
8
|
+
type ValueState,
|
|
9
|
+
valueStateLabels,
|
|
10
|
+
} from "./format";
|
|
11
|
+
import { deviceHealth, devicesWithHealth, healthBadge } from "./health";
|
|
12
|
+
import { pathLink, sourceLink, whyLink } from "./links";
|
|
13
|
+
import type { Page } from "./pages";
|
|
14
|
+
import { href, type Place } from "./routes";
|
|
15
|
+
import type { Store } from "./store";
|
|
16
|
+
|
|
17
|
+
const assemblySummary = (device: DebugDevice) =>
|
|
18
|
+
device.assemblies
|
|
19
|
+
.map(
|
|
20
|
+
(assembly) =>
|
|
21
|
+
`${assembly.direction === "input" ? "in" : "out"} ${assembly.bytes} B`,
|
|
22
|
+
)
|
|
23
|
+
.join(" · ");
|
|
24
|
+
|
|
25
|
+
/** Where an assembly's grid comes from, and how far to trust it. */
|
|
26
|
+
const rawBytesNote = (
|
|
27
|
+
bytes: number[] | null,
|
|
28
|
+
state: ValueState,
|
|
29
|
+
raw: string | undefined,
|
|
30
|
+
) => {
|
|
31
|
+
if (bytes) {
|
|
32
|
+
return state === "live"
|
|
33
|
+
? " · raw bytes"
|
|
34
|
+
: ` · raw bytes, ${valueStateLabels[state]}`;
|
|
35
|
+
}
|
|
36
|
+
if (raw) {
|
|
37
|
+
return " · raw bytes not read yet";
|
|
38
|
+
}
|
|
39
|
+
return " · no raw bytes in this build: it has no generated device tree";
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const deviceList = (store: Store, page: Page): View => {
|
|
43
|
+
const body = h("tbody");
|
|
44
|
+
const render = () =>
|
|
45
|
+
body.replaceChildren(
|
|
46
|
+
...store.manifest.devices.map((device) =>
|
|
47
|
+
h(
|
|
48
|
+
"tr",
|
|
49
|
+
{
|
|
50
|
+
class: "link-row",
|
|
51
|
+
onclick: () => {
|
|
52
|
+
location.hash = href({ route: "hardware", device: device.id });
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
h("td", {}, healthBadge(deviceHealth(store, device))),
|
|
56
|
+
h(
|
|
57
|
+
"td",
|
|
58
|
+
{},
|
|
59
|
+
h(
|
|
60
|
+
"a",
|
|
61
|
+
{
|
|
62
|
+
href: href({ route: "hardware", device: device.id }),
|
|
63
|
+
class: "mono",
|
|
64
|
+
},
|
|
65
|
+
device.id,
|
|
66
|
+
),
|
|
67
|
+
),
|
|
68
|
+
h(
|
|
69
|
+
"td",
|
|
70
|
+
{},
|
|
71
|
+
[device.vendor, device.product].filter(Boolean).join(" "),
|
|
72
|
+
),
|
|
73
|
+
h(
|
|
74
|
+
"td",
|
|
75
|
+
{ class: "mono" },
|
|
76
|
+
device.network
|
|
77
|
+
? `${device.network.address}${device.network.rpiMs === undefined ? "" : ` · RPI ${device.network.rpiMs} ms`}`
|
|
78
|
+
: "",
|
|
79
|
+
),
|
|
80
|
+
h("td", {}, device.connection ?? ""),
|
|
81
|
+
h("td", { class: "mono" }, assemblySummary(device)),
|
|
82
|
+
h("td", { class: "num" }, String(device.channels.length)),
|
|
83
|
+
),
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
render();
|
|
87
|
+
page.show({ health: devicesWithHealth(store) });
|
|
88
|
+
return {
|
|
89
|
+
element: h(
|
|
90
|
+
"div",
|
|
91
|
+
{ class: "page" },
|
|
92
|
+
h("h1", {}, "Hardware"),
|
|
93
|
+
store.manifest.devices.length
|
|
94
|
+
? table(
|
|
95
|
+
[
|
|
96
|
+
"Health",
|
|
97
|
+
"Device",
|
|
98
|
+
"Product",
|
|
99
|
+
"Network",
|
|
100
|
+
"Connection",
|
|
101
|
+
"Assemblies",
|
|
102
|
+
"Channels",
|
|
103
|
+
],
|
|
104
|
+
body,
|
|
105
|
+
)
|
|
106
|
+
: empty("This build configures no devices."),
|
|
107
|
+
),
|
|
108
|
+
update(topics) {
|
|
109
|
+
if (
|
|
110
|
+
topics.has("devices") ||
|
|
111
|
+
topics.has("stream") ||
|
|
112
|
+
topics.has("session")
|
|
113
|
+
) {
|
|
114
|
+
render();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const deviceDetail = (store: Store, page: Page, device: DebugDevice): View => {
|
|
121
|
+
const io = store.manifest.io.filter((entry) => entry.device === device.id);
|
|
122
|
+
const bound = new Map(
|
|
123
|
+
device.channels.map((channel) => [
|
|
124
|
+
channel.id,
|
|
125
|
+
io.filter((entry) => entry.channel === channel.id),
|
|
126
|
+
]),
|
|
127
|
+
);
|
|
128
|
+
const badge = h("span");
|
|
129
|
+
const status = h("dl", { class: "facts readings" });
|
|
130
|
+
const grids = h("div", { class: "assemblies" });
|
|
131
|
+
const channelBody = h("tbody");
|
|
132
|
+
|
|
133
|
+
const assemblyState = (direction: DebugChannel["direction"]) =>
|
|
134
|
+
store.devices
|
|
135
|
+
.get(device.id)
|
|
136
|
+
?.assemblies.find((assembly) => assembly.direction === direction);
|
|
137
|
+
|
|
138
|
+
const renderHealth = () => {
|
|
139
|
+
const health = deviceHealth(store, device);
|
|
140
|
+
badge.replaceChildren(
|
|
141
|
+
healthBadge(health),
|
|
142
|
+
health.detail ? h("span", { class: "dim" }, ` ${health.detail}`) : "",
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const reading = (quality: Quality, value: string) => {
|
|
147
|
+
const state = store.untimedState(quality);
|
|
148
|
+
return [
|
|
149
|
+
h("span", { class: `value s-${state}` }, value),
|
|
150
|
+
h("span", { class: `meta s-${state}` }, valueStateLabels[state]),
|
|
151
|
+
];
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const renderStatus = () => {
|
|
155
|
+
const values = store.devices.get(device.id)?.status ?? {};
|
|
156
|
+
fill(
|
|
157
|
+
status,
|
|
158
|
+
...Object.keys(device.status ?? {}).flatMap((label) => {
|
|
159
|
+
const entry = values[label];
|
|
160
|
+
return [
|
|
161
|
+
h("dt", {}, label),
|
|
162
|
+
h(
|
|
163
|
+
"dd",
|
|
164
|
+
{},
|
|
165
|
+
...(entry
|
|
166
|
+
? reading(entry.quality, formatScalar(entry.value))
|
|
167
|
+
: [h("span", { class: "value s-unavailable" }, "not read")]),
|
|
168
|
+
),
|
|
169
|
+
];
|
|
170
|
+
}),
|
|
171
|
+
);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const renderGrids = () =>
|
|
175
|
+
grids.replaceChildren(
|
|
176
|
+
...device.assemblies.map((assembly) => {
|
|
177
|
+
const assemblyNow = assemblyState(assembly.direction);
|
|
178
|
+
const bytes = assemblyNow?.bytes ?? null;
|
|
179
|
+
const channels = device.channels.filter(
|
|
180
|
+
(channel) => channel.direction === assembly.direction,
|
|
181
|
+
);
|
|
182
|
+
const bits = mapBits(assembly.bytes, channels, bound);
|
|
183
|
+
const state = store.untimedState(assemblyNow?.quality ?? "unavailable");
|
|
184
|
+
return h(
|
|
185
|
+
"section",
|
|
186
|
+
{ class: `panel assembly q-${state}` },
|
|
187
|
+
h(
|
|
188
|
+
"h3",
|
|
189
|
+
{},
|
|
190
|
+
`${assembly.direction === "input" ? "Input" : "Output"} assembly · ${assembly.bytes} bytes`,
|
|
191
|
+
assembly.address
|
|
192
|
+
? h("span", { class: "mono dim" }, ` ${assembly.address}`)
|
|
193
|
+
: "",
|
|
194
|
+
h(
|
|
195
|
+
"span",
|
|
196
|
+
{ class: "dim" },
|
|
197
|
+
rawBytesNote(bytes, state, assembly.raw),
|
|
198
|
+
),
|
|
199
|
+
),
|
|
200
|
+
h(
|
|
201
|
+
"div",
|
|
202
|
+
{ class: "bitgrid" },
|
|
203
|
+
h("span", { class: "bh" }, "byte"),
|
|
204
|
+
...Array.from({ length: 8 }, (_, bit) =>
|
|
205
|
+
h("span", { class: "bh" }, `.${bit}`),
|
|
206
|
+
),
|
|
207
|
+
h("span", { class: "bh" }, "hex"),
|
|
208
|
+
h("span", { class: "bh legend-head" }, "mapped"),
|
|
209
|
+
...Array.from({ length: assembly.bytes }, (_, byte) => {
|
|
210
|
+
const value = bytes?.[byte];
|
|
211
|
+
const starts = channels.filter(
|
|
212
|
+
(channel) => channel.offsetBits >> 3 === byte,
|
|
213
|
+
);
|
|
214
|
+
return [
|
|
215
|
+
h("span", { class: "byte mono" }, `+${byte}`),
|
|
216
|
+
...Array.from({ length: 8 }, (_, bit) => {
|
|
217
|
+
const mapped = bits[byte * 8 + bit];
|
|
218
|
+
const on =
|
|
219
|
+
value === undefined ? undefined : (value >> bit) & 1;
|
|
220
|
+
const where = `byte ${byte} bit ${bit}`;
|
|
221
|
+
return h(
|
|
222
|
+
"span",
|
|
223
|
+
{
|
|
224
|
+
class: `bit${mapped ? " mapped" : ""}${on === 1 ? " on" : ""}${on === undefined ? " none" : ""}`,
|
|
225
|
+
title: mapped
|
|
226
|
+
? `${where} · ${mapped.channel.name} (${mapped.channel.id})${mapped.paths.map((path) => `\n${path}`).join("")}`
|
|
227
|
+
: `${where} · not mapped`,
|
|
228
|
+
},
|
|
229
|
+
on === undefined ? "·" : String(on),
|
|
230
|
+
mapped && mapped.channel.offsetBits === byte * 8 + bit
|
|
231
|
+
? h("small", {}, mapped.channel.id)
|
|
232
|
+
: undefined,
|
|
233
|
+
);
|
|
234
|
+
}),
|
|
235
|
+
h(
|
|
236
|
+
"span",
|
|
237
|
+
{ class: "hex mono" },
|
|
238
|
+
value === undefined
|
|
239
|
+
? "··"
|
|
240
|
+
: value.toString(16).padStart(2, "0").toUpperCase(),
|
|
241
|
+
),
|
|
242
|
+
h(
|
|
243
|
+
"span",
|
|
244
|
+
{ class: "legend" },
|
|
245
|
+
...starts.map((channel) =>
|
|
246
|
+
h(
|
|
247
|
+
"span",
|
|
248
|
+
{ class: "legend-item" },
|
|
249
|
+
h("b", {}, channel.id),
|
|
250
|
+
...(bound.get(channel.id) ?? []).map((entry) =>
|
|
251
|
+
pathLink(
|
|
252
|
+
entry.path,
|
|
253
|
+
entry.path.split(".").slice(-3).join("."),
|
|
254
|
+
),
|
|
255
|
+
),
|
|
256
|
+
),
|
|
257
|
+
),
|
|
258
|
+
),
|
|
259
|
+
];
|
|
260
|
+
}).flat(),
|
|
261
|
+
),
|
|
262
|
+
);
|
|
263
|
+
}),
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
const renderChannels = () =>
|
|
267
|
+
channelBody.replaceChildren(
|
|
268
|
+
...device.channels.map((channel) => {
|
|
269
|
+
const bytes = assemblyState(channel.direction)?.bytes;
|
|
270
|
+
const raw = bytes
|
|
271
|
+
? readBits(bytes, channel.offsetBits, channel.bits)
|
|
272
|
+
: null;
|
|
273
|
+
const mapped = bound.get(channel.id) ?? [];
|
|
274
|
+
return h(
|
|
275
|
+
"tr",
|
|
276
|
+
{},
|
|
277
|
+
h("td", { class: "mono" }, channel.id),
|
|
278
|
+
h(
|
|
279
|
+
"td",
|
|
280
|
+
{},
|
|
281
|
+
channel.name,
|
|
282
|
+
channel.description
|
|
283
|
+
? h("div", { class: "dim" }, channel.description)
|
|
284
|
+
: "",
|
|
285
|
+
),
|
|
286
|
+
h("td", {}, channel.direction),
|
|
287
|
+
h(
|
|
288
|
+
"td",
|
|
289
|
+
{ class: "mono" },
|
|
290
|
+
`${channel.offsetBits >> 3}.${channel.offsetBits & 7} · ${channel.bits} bit${channel.bits === 1 ? "" : "s"}`,
|
|
291
|
+
),
|
|
292
|
+
h("td", { class: "mono" }, channel.address ?? ""),
|
|
293
|
+
h(
|
|
294
|
+
"td",
|
|
295
|
+
{ class: "mono num", title: "Decoded from the raw assembly bytes" },
|
|
296
|
+
raw === null ? "—" : String(raw),
|
|
297
|
+
channel.unit ? ` ${channel.unit}` : "",
|
|
298
|
+
),
|
|
299
|
+
h(
|
|
300
|
+
"td",
|
|
301
|
+
{},
|
|
302
|
+
...(mapped.length
|
|
303
|
+
? mapped.map((entry) => {
|
|
304
|
+
const value = store.devices
|
|
305
|
+
.get(device.id)
|
|
306
|
+
?.channels.find(
|
|
307
|
+
(candidate) =>
|
|
308
|
+
candidate.id === channel.id &&
|
|
309
|
+
candidate.path === entry.path,
|
|
310
|
+
);
|
|
311
|
+
const node = store.tree.resolve(entry.path);
|
|
312
|
+
return h(
|
|
313
|
+
"div",
|
|
314
|
+
{ class: "mapped-path" },
|
|
315
|
+
pathLink(entry.path),
|
|
316
|
+
entry.direction === "output" ? whyLink(entry.path) : "",
|
|
317
|
+
entry.inverted
|
|
318
|
+
? h("span", { class: "tag" }, "inverted")
|
|
319
|
+
: "",
|
|
320
|
+
...(value
|
|
321
|
+
? reading(
|
|
322
|
+
value.quality,
|
|
323
|
+
formatValue(store.manifest, entry.type, value.value),
|
|
324
|
+
)
|
|
325
|
+
: []),
|
|
326
|
+
node?.declaration
|
|
327
|
+
? sourceLink(store, node.declaration)
|
|
328
|
+
: "",
|
|
329
|
+
);
|
|
330
|
+
})
|
|
331
|
+
: [h("span", { class: "dim" }, "not mapped")]),
|
|
332
|
+
),
|
|
333
|
+
);
|
|
334
|
+
}),
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
renderHealth();
|
|
338
|
+
renderStatus();
|
|
339
|
+
renderGrids();
|
|
340
|
+
renderChannels();
|
|
341
|
+
page.show({ devices: [device.id] });
|
|
342
|
+
|
|
343
|
+
const identity: [string, string | undefined][] = [
|
|
344
|
+
["Vendor", device.vendor],
|
|
345
|
+
["Product", device.product],
|
|
346
|
+
["Product code", device.productCode],
|
|
347
|
+
["Address", device.network?.address],
|
|
348
|
+
[
|
|
349
|
+
"RPI",
|
|
350
|
+
device.network?.rpiMs === undefined
|
|
351
|
+
? undefined
|
|
352
|
+
: `${device.network.rpiMs} ms`,
|
|
353
|
+
],
|
|
354
|
+
["Connection", device.connection],
|
|
355
|
+
];
|
|
356
|
+
return {
|
|
357
|
+
element: h(
|
|
358
|
+
"div",
|
|
359
|
+
{ class: "page" },
|
|
360
|
+
h(
|
|
361
|
+
"div",
|
|
362
|
+
{ class: "crumbs" },
|
|
363
|
+
h("a", { href: href({ route: "hardware" }) }, "Hardware"),
|
|
364
|
+
" / ",
|
|
365
|
+
),
|
|
366
|
+
h("h1", { class: "mono" }, device.id, " ", badge),
|
|
367
|
+
h(
|
|
368
|
+
"dl",
|
|
369
|
+
{ class: "facts" },
|
|
370
|
+
...identity.flatMap(([label, value]) =>
|
|
371
|
+
value === undefined
|
|
372
|
+
? []
|
|
373
|
+
: [h("dt", {}, label), h("dd", { class: "mono" }, value)],
|
|
374
|
+
),
|
|
375
|
+
),
|
|
376
|
+
device.status && h("h2", {}, "Status"),
|
|
377
|
+
status,
|
|
378
|
+
grids,
|
|
379
|
+
h("h2", {}, "Channels"),
|
|
380
|
+
device.channels.length
|
|
381
|
+
? table(
|
|
382
|
+
["Id", "Name", "Dir", "Bits", "Address", "Raw", "TypeScript"],
|
|
383
|
+
channelBody,
|
|
384
|
+
)
|
|
385
|
+
: empty("No channels configured."),
|
|
386
|
+
),
|
|
387
|
+
update(topics) {
|
|
388
|
+
if (
|
|
389
|
+
topics.has("devices") ||
|
|
390
|
+
topics.has("stream") ||
|
|
391
|
+
topics.has("session")
|
|
392
|
+
) {
|
|
393
|
+
renderHealth();
|
|
394
|
+
renderStatus();
|
|
395
|
+
renderGrids();
|
|
396
|
+
renderChannels();
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
export const hardwareView = (
|
|
403
|
+
store: Store,
|
|
404
|
+
page: Page,
|
|
405
|
+
{ device: id }: Extract<Place, { route: "hardware" }>,
|
|
406
|
+
): View => {
|
|
407
|
+
if (id === undefined) {
|
|
408
|
+
return deviceList(store, page);
|
|
409
|
+
}
|
|
410
|
+
const device = store.manifest.devices.find(
|
|
411
|
+
(candidate) => candidate.id === id,
|
|
412
|
+
);
|
|
413
|
+
if (device) {
|
|
414
|
+
return deviceDetail(store, page, device);
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
element: h(
|
|
418
|
+
"div",
|
|
419
|
+
{ class: "page" },
|
|
420
|
+
h("h1", {}, "Hardware"),
|
|
421
|
+
empty(`No device ${id} in this build.`),
|
|
422
|
+
),
|
|
423
|
+
update() {},
|
|
424
|
+
};
|
|
425
|
+
};
|