fix: address PR review — flash state race, error paths, test robustness, nits
- server.py: claim the flash (state=bootloader) before spawning the task so the concurrent-request guard is effective immediately; guard the bundled image existence in the flash endpoint; single device.info() call per endpoint; 400 for refused flashes (409 stays for already-running); remove stale nvcurve-wireview-fw-*.bin temp files at startup - wireview_firmware.py: drain stderr in its own reader thread (a full pipe buffer would have hung the flash until timeout); chunked stdout reads instead of per-character read(2); BuildStruct field checks in dataclass order - wireview.py: document the intentional 0xF1 overlap between CMD_BOOTLOADER and SCREEN_RESUME_UPDATES (different command namespaces) - tests: check() now fails loudly under pytest (optional import, standalone runs unaffected); explicit reader-thread sync in test_enter_bootloader; less brittle flash-progress assertion; self-documenting checksum corruption in test_hex_parser - frontend: refreshFirmware in useCallback + effect deps; NaN% guard on flash.progress; explicit clear/keep masks in handleClear; WS firmware message reuses WireViewFlashProgress via Pick - docs: clarify that the dfu-util :leave modifier is what makes the device exit the bootloader and reboot; document the 400 vs 409 API contract; README now mentions per-pin readings, pin-imbalance gauge and fault clearing
This commit is contained in:
1 parent
dbb6856a6d
commit
6e87dcf862
8 files changed
+111
-55
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { api } from "../../api/client.js";
|
||||
import { ConfirmDialog } from "../common/ConfirmDialog.js";
|
||||
@@ -203,7 +203,7 @@ export function WireViewPanel({ info, sample, history, flash }: Props) {
|
||||
flash.state === "waiting" ||
|
||||
flash.state === "flashing";
|
||||
|
||||
async function refreshFirmware() {
|
||||
const refreshFirmware = useCallback(async () => {
|
||||
try {
|
||||
setFirmware(await api.wireviewFirmware());
|
||||
setFirmwareError(null);
|
||||
@@ -212,7 +212,7 @@ export function WireViewPanel({ info, sample, history, flash }: Props) {
|
||||
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
|
||||
@@ -222,7 +222,7 @@ export function WireViewPanel({ info, sample, history, flash }: Props) {
|
||||
// body (rule false-positive on async fetch).
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
if (hasSample) refreshFirmware();
|
||||
}, [hasSample]);
|
||||
}, [hasSample, refreshFirmware]);
|
||||
|
||||
// After a flash the device reboots and re-enumerates; re-check once it is
|
||||
// back so the verdict reflects the new firmware.
|
||||
@@ -232,7 +232,7 @@ export function WireViewPanel({ info, sample, history, flash }: Props) {
|
||||
refreshFirmware();
|
||||
}, 3000);
|
||||
return () => clearTimeout(t);
|
||||
}, [flash.state]);
|
||||
}, [flash.state, refreshFirmware]);
|
||||
|
||||
async function startFlash(override: boolean) {
|
||||
setConfirming(null);
|
||||
@@ -253,10 +253,10 @@ export function WireViewPanel({ info, sample, history, flash }: Props) {
|
||||
setClearing(which);
|
||||
try {
|
||||
// Keep-mask semantics: 0x0000 clears, 0xFFFF keeps.
|
||||
await api.wireviewClearFault(
|
||||
which === "status" ? 0x0000 : 0xffff,
|
||||
which === "log" ? 0x0000 : 0xffff,
|
||||
);
|
||||
const clear = 0x0000, keep = 0xffff;
|
||||
const statusMask = which === "status" ? clear : keep;
|
||||
const logMask = which === "status" ? keep : clear;
|
||||
await api.wireviewClearFault(statusMask, logMask);
|
||||
toast.success(
|
||||
which === "status" ? "Fault status cleared" : "Fault log cleared",
|
||||
);
|
||||
@@ -508,7 +508,7 @@ export function WireViewPanel({ info, sample, history, flash }: Props) {
|
||||
<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)}%
|
||||
{Math.round((flash.progress ?? 0) * 100)}%
|
||||
</span>
|
||||
</div>
|
||||
<div className="h-1.5 rounded-full bg-zinc-800 overflow-hidden">
|
||||
|
||||
@@ -249,9 +249,7 @@ export interface WireViewFirmwareState {
|
||||
export type WireViewWsMessage =
|
||||
| { type: "unavailable" }
|
||||
| { type: "sample"; info: WireViewInfo; sample: WireViewSample }
|
||||
| {
|
||||
type: "firmware";
|
||||
state: WireViewFlashProgress["state"];
|
||||
progress: number;
|
||||
status: string;
|
||||
};
|
||||
// Flat payload: the flash progress fields are re-declared (not nested) to
|
||||
// match the WS message shape; keep in sync with WireViewFlashProgress.
|
||||
| ({ type: "firmware" } &
|
||||
Pick<WireViewFlashProgress, "state" | "progress" | "status">);
|
||||
Reference in new issue
Block a user