feat: wireview clear fault status/log
- WireViewSerialDevice.clear_faults() sends CMD_CLEAR_FAULTS (0x0E) with 16-bit keep masks (0x0000 clears, 0xFFFF keeps); all port access is now serialized with an RLock so the poller, the clear-fault endpoint and the watchdog cannot interleave on the port mid-transaction. - POST /api/wireview/clear-fault (serial transport only — in hwmon mode wireviewd owns the port and the masks are read-only); the sample is re-read immediately so clients see the cleared masks without waiting for the next poll tick. - WireView tab: Clear buttons on the fault status/log badges. - tests: protocol-level clear-fault tests via pty (byte-exact command framing, keep-mask semantics).
This commit is contained in:
1 parent
1e11a2c18b
commit
d9f5e34c80
5 files changed
+241
-7
No files matched your search
@@ -51,9 +51,13 @@ function pluck(history: WireViewSample[], key: keyof WireViewSample): number[] {
|
||||
function FaultBadge({
|
||||
label,
|
||||
mask,
|
||||
onClear,
|
||||
clearing,
|
||||
}: {
|
||||
label: string;
|
||||
mask: number;
|
||||
onClear?: () => void;
|
||||
clearing?: boolean;
|
||||
}) {
|
||||
const faults = decodeFaults(mask);
|
||||
return (
|
||||
@@ -68,13 +72,25 @@ function FaultBadge({
|
||||
<span className="text-xs text-zinc-500 uppercase tracking-wider">
|
||||
{label}
|
||||
</span>
|
||||
<span
|
||||
className={`text-xs font-mono ${
|
||||
faults.length > 0 ? "text-red-400" : "text-zinc-600"
|
||||
}`}
|
||||
>
|
||||
0x{mask.toString(16).toUpperCase().padStart(4, "0")}
|
||||
</span>
|
||||
<div className="flex items-center gap-2">
|
||||
{mask !== 0 && onClear && (
|
||||
<button
|
||||
onClick={onClear}
|
||||
disabled={clearing}
|
||||
className="px-2 py-0.5 rounded text-[11px] font-medium bg-red-500/20 border border-red-500/50 text-red-200 hover:bg-red-500/30 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
title={`Clear ${label.toLowerCase()}`}
|
||||
>
|
||||
{clearing ? "Clearing…" : "Clear"}
|
||||
</button>
|
||||
)}
|
||||
<span
|
||||
className={`text-xs font-mono ${
|
||||
faults.length > 0 ? "text-red-400" : "text-zinc-600"
|
||||
}`}
|
||||
>
|
||||
0x{mask.toString(16).toUpperCase().padStart(4, "0")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{faults.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
@@ -174,6 +190,7 @@ function InfoItem({
|
||||
}
|
||||
|
||||
export function WireViewPanel({ info, sample, history, flash }: Props) {
|
||||
const [clearing, setClearing] = useState<"status" | "log" | null>(null);
|
||||
const [firmware, setFirmware] = useState<WireViewFirmwareState | null>(null);
|
||||
const [firmwareError, setFirmwareError] = useState<string | null>(null);
|
||||
const [confirming, setConfirming] = useState<null | "update" | "override">(
|
||||
@@ -232,6 +249,26 @@ export function WireViewPanel({ info, sample, history, flash }: Props) {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleClear(which: "status" | "log") {
|
||||
setClearing(which);
|
||||
try {
|
||||
// Keep-mask semantics: 0x0000 clears, 0xFFFF keeps.
|
||||
await api.wireviewClearFault(
|
||||
which === "status" ? 0x0000 : 0xffff,
|
||||
which === "log" ? 0x0000 : 0xffff,
|
||||
);
|
||||
toast.success(
|
||||
which === "status" ? "Fault status cleared" : "Fault log cleared",
|
||||
);
|
||||
} catch (err) {
|
||||
toast.error(
|
||||
err instanceof Error ? err.message : "Failed to clear fault",
|
||||
);
|
||||
} finally {
|
||||
setClearing(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (!sample) {
|
||||
return (
|
||||
<div className="bg-zinc-900 rounded-lg p-10 text-center text-zinc-500 flex flex-col items-center gap-2">
|
||||
@@ -370,10 +407,14 @@ export function WireViewPanel({ info, sample, history, flash }: Props) {
|
||||
<FaultBadge
|
||||
label="Fault Status"
|
||||
mask={sample.fault_status}
|
||||
onClear={() => handleClear("status")}
|
||||
clearing={clearing === "status"}
|
||||
/>
|
||||
<FaultBadge
|
||||
label="Fault Log (latched)"
|
||||
mask={sample.fault_log}
|
||||
onClear={() => handleClear("log")}
|
||||
clearing={clearing === "log"}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-zinc-900 rounded-lg p-4">
|
||||
|
||||
Reference in new issue
Block a user