feat: wireview firmware check + DFU flash (bundled image, dfu-util)
Port of the wireview-linux firmware update feature: - nvcurve/wireview_firmware.py: Intel-HEX parser (checksum-verified), BuildStruct identity extraction (vendor/product/version/build string at image base + 192), compatibility verdicts (version then build date, Noctua Edition product alias + 2026-09-02 floor), and a dfu-util flasher (progress parsing, exit-74-after-:leave quirk, timeouts). - Bundle TG-WV-PRO2-FW.hex (v05, build 20260902_0741, base 0x08000000) in nvcurve/firmware/. - WireViewSerialDevice.enter_bootloader() sends the top-level 0xF1 command; vendor/product ids are exposed in info(). - GET /api/wireview/firmware (device vs. bundled verdict, dfu-util availability, flash state) and POST /api/wireview/firmware/flash (gates: serial transport, product match, Noctua floor, downgrade/ same require override). The flash runs as a background task (bootloader -> wait for 0483:df11 -> dfu-util) with progress streamed over /ws/wireview. - WireView tab: Firmware card with device vs. bundled firmware, verdict, dfu-util/hwmon warnings, confirm dialog, live progress bar; re-checks after the device reboots. - tests/test_wireview_firmware.py: 66 tests (HEX parser, checksum rejection, identity, all verdict paths, mocked flasher, bootloader command via pty); added to the Makefile test target. - Docs: firmware section in docs/WireView.md, README note.
This commit is contained in:
1 parent
bf00e1149a
commit
1e11a2c18b
13 files changed
+9702
-7
No files matched your search
@@ -1,11 +1,27 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { api } from "../../api/client.js";
|
||||
import { ConfirmDialog } from "../common/ConfirmDialog.js";
|
||||
import { GaugeCard } from "../Monitor/GaugeCard.js";
|
||||
import { fmt } from "../../utils/units.js";
|
||||
import type { WireViewInfo, WireViewSample } from "../../types.js";
|
||||
import type {
|
||||
WireViewFlashProgress,
|
||||
WireViewFirmwareState,
|
||||
WireViewInfo,
|
||||
WireViewSample,
|
||||
} from "../../types.js";
|
||||
|
||||
interface Props {
|
||||
info: WireViewInfo | null;
|
||||
sample: WireViewSample | null;
|
||||
history: WireViewSample[];
|
||||
flash: WireViewFlashProgress;
|
||||
}
|
||||
|
||||
// "v05 (TG-WV-PRO2-FW_20260902_0741)" — version padded like the official app.
|
||||
function formatFw(version: number | null, build: string | null): string {
|
||||
const v = version !== null ? `v${String(version).padStart(2, "0")}` : "?";
|
||||
return build ? `${v} (${build})` : v;
|
||||
}
|
||||
|
||||
// Per-pin current rating of the 12 VHPWR connector (A). The bar's
|
||||
@@ -157,7 +173,65 @@ function InfoItem({
|
||||
);
|
||||
}
|
||||
|
||||
export function WireViewPanel({ info, sample, history }: Props) {
|
||||
export function WireViewPanel({ info, sample, history, flash }: Props) {
|
||||
const [firmware, setFirmware] = useState<WireViewFirmwareState | null>(null);
|
||||
const [firmwareError, setFirmwareError] = useState<string | null>(null);
|
||||
const [confirming, setConfirming] = useState<null | "update" | "override">(
|
||||
null,
|
||||
);
|
||||
const [starting, setStarting] = useState(false);
|
||||
|
||||
const flashActive =
|
||||
flash.state === "bootloader" ||
|
||||
flash.state === "waiting" ||
|
||||
flash.state === "flashing";
|
||||
|
||||
async function refreshFirmware() {
|
||||
try {
|
||||
setFirmware(await api.wireviewFirmware());
|
||||
setFirmwareError(null);
|
||||
} catch (err) {
|
||||
setFirmwareError(
|
||||
err instanceof Error ? err.message : "Failed to load firmware state",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const hasSample = sample !== null;
|
||||
// Fetch the firmware check when a device appears (the panel early-returns
|
||||
// without a sample, so no reset is needed when the device goes away).
|
||||
useEffect(() => {
|
||||
// setState calls happen after the await, not synchronously in the effect
|
||||
// body (rule false-positive on async fetch).
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
if (hasSample) refreshFirmware();
|
||||
}, [hasSample]);
|
||||
|
||||
// After a flash the device reboots and re-enumerates; re-check once it is
|
||||
// back so the verdict reflects the new firmware.
|
||||
useEffect(() => {
|
||||
if (flash.state !== "done" && flash.state !== "failed") return;
|
||||
const t = setTimeout(() => {
|
||||
refreshFirmware();
|
||||
}, 3000);
|
||||
return () => clearTimeout(t);
|
||||
}, [flash.state]);
|
||||
|
||||
async function startFlash(override: boolean) {
|
||||
setConfirming(null);
|
||||
setStarting(true);
|
||||
try {
|
||||
await api.wireviewFlashFirmware(override);
|
||||
toast.success("Firmware update started");
|
||||
} catch (err) {
|
||||
toast.error(
|
||||
err instanceof Error ? err.message : "Failed to start firmware update",
|
||||
);
|
||||
} finally {
|
||||
setStarting(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!sample) {
|
||||
return (
|
||||
<div className="bg-zinc-900 rounded-lg p-10 text-center text-zinc-500 flex flex-col items-center gap-2">
|
||||
@@ -293,8 +367,14 @@ export function WireViewPanel({ info, sample, history }: Props) {
|
||||
{/* ── Faults + device info ───────────────────────────────────── */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="flex flex-col gap-3">
|
||||
<FaultBadge label="Fault Status" mask={sample.fault_status} />
|
||||
<FaultBadge label="Fault Log (latched)" mask={sample.fault_log} />
|
||||
<FaultBadge
|
||||
label="Fault Status"
|
||||
mask={sample.fault_status}
|
||||
/>
|
||||
<FaultBadge
|
||||
label="Fault Log (latched)"
|
||||
mask={sample.fault_log}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-zinc-900 rounded-lg p-4">
|
||||
<div className="text-xs text-zinc-500 uppercase tracking-wider font-semibold pb-3 border-b border-zinc-800">
|
||||
@@ -310,6 +390,141 @@ export function WireViewPanel({ info, sample, history }: Props) {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── Firmware ─────────────────────────────────────────── */}
|
||||
<div className="bg-zinc-900 rounded-lg p-4 border border-zinc-800">
|
||||
<div className="text-xs text-zinc-500 uppercase tracking-wider font-semibold pb-3 border-b border-zinc-800">
|
||||
Firmware
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-3 mt-3">
|
||||
<div className="flex flex-col gap-0.5 min-w-0">
|
||||
<span className="text-xs text-zinc-500">Device</span>
|
||||
<span className="text-sm font-mono text-zinc-200 truncate">
|
||||
{firmware?.device.connected
|
||||
? formatFw(firmware.device.version, firmware.device.build)
|
||||
: "not connected"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-col gap-0.5 min-w-0">
|
||||
<span className="text-xs text-zinc-500">Bundled image</span>
|
||||
<span className="text-sm font-mono text-zinc-200 truncate">
|
||||
{firmware?.image.available
|
||||
? formatFw(firmware.image.version, firmware.image.build)
|
||||
: firmware?.image.error ?? "missing"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{firmwareError && (
|
||||
<div className="mt-3 text-xs text-red-400">{firmwareError}</div>
|
||||
)}
|
||||
|
||||
{firmware && (
|
||||
<div className="mt-3 flex flex-col gap-2">
|
||||
{(() => {
|
||||
const v = firmware.verdict;
|
||||
const text =
|
||||
v === "newer"
|
||||
? { cls: "text-emerald-400", msg: "Newer firmware available." }
|
||||
: v === "same"
|
||||
? { cls: "text-zinc-400", msg: "Device already runs this firmware build." }
|
||||
: v === "unknown"
|
||||
? { cls: "text-zinc-400", msg: "Firmware comparison unknown (no build date)." }
|
||||
: v === "downgrade"
|
||||
? { cls: "text-amber-400", msg: "Bundled firmware is older than the device firmware." }
|
||||
: v === "product_mismatch"
|
||||
? { cls: "text-red-400", msg: "The bundled firmware does not match this device." }
|
||||
: v === "too_old_for_noctua"
|
||||
? { cls: "text-red-400", msg: "The bundled firmware predates Noctua Edition support." }
|
||||
: { cls: "text-zinc-500", msg: "" };
|
||||
return text.msg ? (
|
||||
<div className={`text-sm font-medium ${text.cls}`}>{text.msg}</div>
|
||||
) : null;
|
||||
})()}
|
||||
{firmware.device.connected &&
|
||||
firmware.device.transport !== "serial" && (
|
||||
<div className="text-xs text-zinc-500">
|
||||
Flashing requires the serial transport (wireviewd owns the
|
||||
port in hwmon mode).
|
||||
</div>
|
||||
)}
|
||||
{firmware.dfu_util === null && (
|
||||
<div className="text-xs text-amber-400">
|
||||
dfu-util not installed — install the "dfu-util" package to
|
||||
enable flashing.
|
||||
</div>
|
||||
)}
|
||||
|
||||
{flashActive || starting ? (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<div className="flex items-center justify-between text-xs text-zinc-400">
|
||||
<span>{flash.status || "Starting…"}</span>
|
||||
<span className="font-mono">
|
||||
{Math.round(flash.progress * 100)}%
|
||||
</span>
|
||||
</div>
|
||||
<div className="h-1.5 rounded-full bg-zinc-800 overflow-hidden">
|
||||
<div
|
||||
className="h-full rounded-full bg-violet-500 transition-all duration-300"
|
||||
style={{ width: `${flash.progress * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
firmware.device.connected &&
|
||||
firmware.device.transport === "serial" &&
|
||||
firmware.image.available &&
|
||||
firmware.dfu_util !== null &&
|
||||
firmware.verdict !== "product_mismatch" &&
|
||||
firmware.verdict !== "too_old_for_noctua" && (
|
||||
<button
|
||||
onClick={() =>
|
||||
setConfirming(
|
||||
firmware.verdict === "same" ||
|
||||
firmware.verdict === "downgrade"
|
||||
? "override"
|
||||
: "update",
|
||||
)
|
||||
}
|
||||
className={`self-start px-3 py-1.5 rounded text-xs font-semibold transition-colors ${
|
||||
firmware.verdict === "same" ||
|
||||
firmware.verdict === "downgrade"
|
||||
? "bg-amber-600 hover:bg-amber-500 text-white"
|
||||
: "bg-emerald-600 hover:bg-emerald-500 text-white"
|
||||
}`}
|
||||
>
|
||||
{firmware.verdict === "same" ||
|
||||
firmware.verdict === "downgrade"
|
||||
? "Flash anyway"
|
||||
: "Update firmware"}
|
||||
</button>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Confirm dialogs */}
|
||||
{confirming !== null && firmware && (
|
||||
<ConfirmDialog
|
||||
message={
|
||||
confirming === "override"
|
||||
? firmware.verdict === "downgrade"
|
||||
? "The bundled firmware is older than the device firmware. Flash it anyway?"
|
||||
: "The device already runs this firmware build. Flash it again?"
|
||||
: `Flash firmware ${formatFw(firmware.image.version, firmware.image.build)} to ${info?.device_name ?? "WireView Pro II"}?`
|
||||
}
|
||||
detail={`The device runs ${
|
||||
firmware.device.connected
|
||||
? formatFw(firmware.device.version, firmware.device.build)
|
||||
: "an unknown firmware version"
|
||||
}.\n\nThe device restarts into its bootloader and is flashed over USB DFU. Do not unplug it until the update finishes.\n\nThis is unofficial software, not affiliated with Thermal Grizzly — flashing is at your own risk.`}
|
||||
confirmLabel={confirming === "override" ? "Flash anyway" : "Flash"}
|
||||
isDestructive={confirming === "override"}
|
||||
onConfirm={() => startFlash(confirming === "override")}
|
||||
onCancel={() => setConfirming(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user