Enforce LinuxCNC WASM XYZAC command authority

This commit is contained in:
2026-08-28 13:04:47 +08:00
parent 1a7995fa9b
commit 78d884bc67
43 changed files with 567 additions and 186 deletions

View File

@@ -28,8 +28,15 @@ export function normalizeAxisState(input = {}) {
const program = input.program ?? input.snapshot?.program ?? {};
const motion = input.motion ?? input.snapshot?.motion ?? {};
const devices = input.devices ?? input.snapshot?.devices ?? {};
const ioSource = input.io ?? input.snapshot?.io ?? input.device_io ?? input.deviceIo ?? input.snapshot?.device_io ?? {};
const ioState = ioSource?.state ?? ioSource ?? {};
const rawTaskState = string(task.state ?? input.task_state ?? input.state, "OFF");
const taskState = rawTaskState === "ESTOP" ? "ESTOP" : ["READY", "RUNNING", "PAUSED", "STOPPED", "ON"].includes(rawTaskState) ? "ON" : "OFF";
const ioHasEstop = typeof ioState.estop === "boolean" || typeof ioState.estop === "number";
const ioEstop = ioHasEstop && Boolean(ioState.estop);
const ioHasReady = typeof ioState.ready === "boolean" || typeof ioState.ready === "number";
const ioReady = ioHasReady && Boolean(ioState.ready);
const ioEstopReset = ioHasEstop && !ioEstop && ioHasReady && !ioReady && Number(ioState.last_error) === -904;
const taskState = ioEstop ? "ESTOP" : ioEstopReset ? "ESTOP_RESET" : ioHasReady && !ioReady ? "OFF" : rawTaskState === "ESTOP" ? "ESTOP" : ["READY", "RUNNING", "PAUSED", "STOPPED", "ON"].includes(rawTaskState) ? "ON" : "OFF";
const inferredInterp = rawTaskState === "RUNNING" ? "READING" : rawTaskState === "PAUSED" ? "PAUSED" : "IDLE";
const interpState = string(task.interp_state ?? input.interp_state ?? input.interpreter_state, inferredInterp);
const mode = string(task.mode ?? input.task_mode ?? input.mode, "MANUAL");
@@ -47,7 +54,7 @@ export function normalizeAxisState(input = {}) {
? [true, true, true]
: [];
const limits = input.on_any_limit ?? motion.on_any_limit ?? motion.limit ?? false;
const fault = rawTaskState === "FAULT" || Boolean(motion.fault || devices.fault || input.fault);
const fault = rawTaskState === "FAULT" || Boolean(motion.fault || devices.fault || ioState.fault || input.fault);
const tool = devices.tool ?? input.tool ?? {};
const toolNumber = number(tool.current ?? input.tool_in_spindle);
const taskFile = Boolean(input.taskfile ?? program.path ?? program.source_hash ?? program.loaded ?? (program.program_status && String(program.program_status).toLowerCase() !== "idle"));
@@ -73,7 +80,12 @@ export function axisGate(action, input = {}) {
switch (action) {
case "estop": enabled = true; reason = estop ? "axis_estop_reset_available" : "axis_estop_available"; break;
case "recover": enabled = true; reason = "axis_recover_available"; break;
case "power": enabled = state.taskState !== "ESTOP"; reason = enabled ? "axis_power_available" : "axis_estop_active"; break;
case "power": {
const requested = input.payload?.active;
enabled = requested === false ? machineOn && !running : requested === true ? !estop && !machineOn && !running : !estop && !running;
reason = estop ? "axis_estop_active" : running ? "axis_interp_running" : enabled ? "axis_power_available" : requested === false ? "axis_machine_off" : "axis_machine_on";
break;
}
case "override": enabled = machineOn && !estop; reason = enabled ? "axis_override_available" : estop ? "axis_estop_active" : "axis_machine_off"; break;
case "reset": enabled = machineOn && !running && !state.onAnyLimit; reason = enabled ? "axis_reset_available" : state.onAnyLimit ? "axis_limit_active" : "axis_reset_state_gate"; break;
case "open": enabled = idle; reason = enabled ? "axis_interp_idle" : "axis_interp_running"; break;