import { SimScheduler, SCHEDULER_PHASES } from "./sim-scheduler.mjs"; import { fnv1a64 } from "./replay.mjs"; export const XYZAC_SCHEDULER_SCHEMA = "xyzac-scheduler.v1"; export const XYZAC_SCHEDULER_PHASES = Object.freeze([...SCHEDULER_PHASES]); export class XyzacScheduler extends SimScheduler { constructor(core, { budget = 1_000_000, cycleTime = 0.01 } = {}) { super(core, { budget }); this.cycle_time = cycleTime; this.authority = "linuxcnc-wasm-worker"; this.clock = "logical_tick"; this.machine = Object.freeze({ coordinates: "XYZAC", joint_count: 5, rotary_units: "degrees", kinematics: "xyzac-trt" }); } step(cycles, callbacks = {}) { if (!Number.isSafeInteger(cycles) || cycles < 0) throw new Error("xyzac_scheduler_cycles_invalid"); const result = super.step(cycles, callbacks); return this.export({ last_step_cycles: cycles, state_hash: result.state_hash }); } export(extra = {}) { const unsigned = { schema: XYZAC_SCHEDULER_SCHEMA, authority: this.authority, clock: this.clock, cycle_time: this.cycle_time, machine: this.machine, budget: this.budget, tick: this.tick, last_cycles: this.last_cycles, phase_trace: [...this.phase_trace], ...extra, }; delete unsigned.state_hash; return { ...unsigned, state_hash: fnv1a64(unsigned) }; } restore(value) { if (!value || value.schema !== XYZAC_SCHEDULER_SCHEMA || value.clock !== "logical_tick" || value.machine?.coordinates !== "XYZAC" || value.machine?.joint_count !== 5) throw new Error("xyzac_scheduler_restore_scope"); const base = { schema: "sim_scheduler.v1", budget: value.budget, last_cycles: value.last_cycles, phase_trace: value.phase_trace, tick: value.tick, state_hash: fnv1a64({ schema: "sim_scheduler.v1", budget: value.budget, phase_trace: value.phase_trace, tick: value.tick }) }; super.restore(base); return this.export(); } }