Safer self-update: staged next to build/ (two renames, not a copy from RAM), waits for the new revision on /api/health and rolls back to build.old if it doesn't come up, a repeated request is a no-op, maptool-recover puts build/ back after a power cut mid-swap; the dashboard dark under the page's night mode; /can.html: frames in a second column on wide screens, changed bytes highlighted (fading, bits in the tooltip), the node state column a fixed width
This commit is contained in:
1 parent
27313b3101
commit
d58f7efc41
4 files changed
+111
-22
No files matched your search
+34
-2
@@ -23,6 +23,14 @@
|
||||
.stale td { opacity: 0.5; }
|
||||
input { padding: 6px 8px; font-size: 0.9rem; width: 220px; max-width: 100%; box-sizing: border-box; }
|
||||
.empty { color: var(--muted); font-size: 0.85rem; }
|
||||
/* side by side when there's room, the frames under the rest on a phone */
|
||||
.cols { display: grid; gap: 0 32px; }
|
||||
.cols > div { min-width: 0; }
|
||||
@media (min-width: 1100px) { .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
|
||||
/* a byte that just changed, fading out over CHANGED_FOR */
|
||||
/* a fixed width: the column doesn't jump when a node goes "silent" */
|
||||
#nodes th:nth-child(2), #nodes td:nth-child(2) { width: 9em; min-width: 9em; }
|
||||
.chg { background: color-mix(in srgb, #ffb300 calc(var(--fresh) * 70%), transparent); border-radius: 3px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -31,6 +39,7 @@
|
||||
<span id="status">loading…</span>
|
||||
</header>
|
||||
|
||||
<div class="cols"><div>
|
||||
<h2>Interfaces</h2>
|
||||
<div class="scroll"><table id="interfaces"><thead><tr><th>Interface</th><th>State</th><th class="num">Frames</th><th>Last frame</th><th>Error</th></tr></thead><tbody></tbody></table></div>
|
||||
|
||||
@@ -40,12 +49,34 @@
|
||||
<h2>Signals</h2>
|
||||
<div class="scroll"><table id="signals"><thead><tr><th>Signal</th><th class="num">Value</th><th>Unit</th><th>Updated</th></tr></thead><tbody></tbody></table></div>
|
||||
|
||||
</div><div>
|
||||
<h2>Frames <input id="filter" type="search" placeholder="Filter id, role, node…"></h2>
|
||||
<div class="scroll"><table id="frames"><thead><tr><th>Interface</th><th>COB-ID</th><th>Role</th><th>Node</th><th class="num">Count</th><th class="num">Rate</th><th>Data</th><th>Last</th></tr></thead><tbody></tbody></table></div>
|
||||
</div></div>
|
||||
|
||||
<script>
|
||||
// Polls GET /api/can (lib/maptool/can.rb's Store) once a second.
|
||||
const STALE_AFTER = 10; // s without a frame: greyed out
|
||||
const CHANGED_FOR = 3; // s a changed byte stays highlighted
|
||||
const seen = new Map(); // "iface:cob" → { bytes: [..], changedAt: [..] }
|
||||
|
||||
// The frame's bytes, each one that changed in the last CHANGED_FOR s
|
||||
// highlighted (fading), its tooltip saying which bits and from what.
|
||||
function dataHtml(f, key, now) {
|
||||
const bytes = (f.data.match(/../g) || []).map((b) => parseInt(b, 16));
|
||||
const before = seen.get(key);
|
||||
const changedAt = bytes.map((b, i) => (before && before.bytes[i] !== undefined && before.bytes[i] !== b ? now : before?.changedAt[i] ?? 0));
|
||||
const from = bytes.map((b, i) => (before && before.bytes[i] !== b ? before.bytes[i] : before?.from?.[i]));
|
||||
seen.set(key, { bytes, changedAt, from });
|
||||
return bytes.map((b, i) => {
|
||||
const hex = b.toString(16).toUpperCase().padStart(2, "0");
|
||||
const age = now - changedAt[i];
|
||||
if (!changedAt[i] || age > CHANGED_FOR || from[i] === undefined) return hex;
|
||||
const bits = [...Array(8).keys()].filter((bit) => ((b ^ from[i]) >> bit) & 1);
|
||||
const title = `byte ${i}: ${from[i].toString(2).padStart(8, "0")} → ${b.toString(2).padStart(8, "0")} (bit ${bits.join(", ")})`;
|
||||
return `<span class="chg" style="--fresh:${(1 - age / CHANGED_FOR).toFixed(2)}" title="${title}">${hex}</span>`;
|
||||
}).join(" ");
|
||||
}
|
||||
const esc = (s) => String(s ?? "").replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
||||
const hex = (n, width) => "0x" + n.toString(16).toUpperCase().padStart(width, "0");
|
||||
const nodeName = (n) => `${n} <code>${hex(Number(n), 2)}</code>`;
|
||||
@@ -74,7 +105,7 @@
|
||||
for (const f of data.frames) if (f.node != null) (roles[f.node] ||= new Set()).add(f.role);
|
||||
fill("nodes", Object.entries(data.nodes).sort((a, b) => a[0] - b[0]).map(([id, n]) => {
|
||||
const emcy = n.emcy ? `<code>${hex(n.emcy.code, 4)}</code> reg <code>${hex(n.emcy.register, 2)}</code> ${n.emcy.code === 0 ? "(reset)" : ""} · ${age(n.emcy.at)}` : "—";
|
||||
return `<tr class="${stale(n.seen_at) && !n.silent ? "stale" : ""}"><td>${nodeName(id)}</td><td class="${n.silent ? "bad" : STATE_CLASS[n.state] || ""}">${n.silent ? "silent (heartbeat stopped)" : esc(n.state || "no heartbeat")}</td><td>${age(n.seen_at)}</td><td class="${n.emcy?.code ? "bad" : ""}">${emcy}</td><td>${[...(roles[id] || [])].sort().map(esc).join(", ")}</td></tr>`;
|
||||
return `<tr class="${stale(n.seen_at) && !n.silent ? "stale" : ""}"><td>${nodeName(id)}</td><td class="${n.silent ? "bad" : STATE_CLASS[n.state] || ""}"${n.silent ? ' title="3 heartbeats missed"' : ""}>${n.silent ? "silent" : esc(n.state || "no heartbeat")}</td><td>${age(n.seen_at)}</td><td class="${n.emcy?.code ? "bad" : ""}">${emcy}</td><td>${[...(roles[id] || [])].sort().map(esc).join(", ")}</td></tr>`;
|
||||
}), "No CANopen node heard yet.", 5);
|
||||
|
||||
fill("signals", Object.entries(data.signals).sort().map(([name, s]) =>
|
||||
@@ -86,8 +117,9 @@
|
||||
.map((f) => ({ ...f, cob: f.extended ? hex(f.id, 8) : hex(f.id, 3) }))
|
||||
.filter((f) => !filter || [f.interface, f.cob, f.role, f.node].join(" ").toLowerCase().includes(filter))
|
||||
.sort((a, b) => a.interface.localeCompare(b.interface) || a.id - b.id);
|
||||
const now = Date.now() / 1000;
|
||||
fill("frames", frames.map((f) =>
|
||||
`<tr class="${stale(f.at) ? "stale" : ""}"><td>${esc(f.interface)}</td><td><code>${f.cob}</code>${f.extended ? " ext" : ""}</td><td>${esc(f.role || "")}</td><td>${f.node ?? ""}</td><td class="num">${f.count}</td><td class="num">${f.interval ? (1 / f.interval).toFixed(f.interval > 1 ? 2 : 1) + " Hz" : ""}</td><td><code>${(f.data.match(/../g) || []).join(" ")}</code></td><td>${age(f.at)}</td></tr>`),
|
||||
`<tr class="${stale(f.at) ? "stale" : ""}"><td>${esc(f.interface)}</td><td><code>${f.cob}</code>${f.extended ? " ext" : ""}</td><td>${esc(f.role || "")}</td><td>${f.node ?? ""}</td><td class="num">${f.count}</td><td class="num">${f.interval ? (1 / f.interval).toFixed(f.interval > 1 ? 2 : 1) + " Hz" : ""}</td><td><code>${dataHtml(f, `${f.interface}:${f.cob}`, now)}</code></td><td>${age(f.at)}</td></tr>`),
|
||||
filter ? "No frame matches." : "No frame yet.", 8);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user