97 lines
3.6 KiB
JavaScript
97 lines
3.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import { dirname, resolve } from "node:path";
|
|
|
|
import { createLinuxCncTaskHalSdk } from "../../../wasm-port/runtime/sdk/src/linuxcnc-task-hal.js";
|
|
import { wrapTaskHalSdk } from "../../app/src/runtime/linuxcnc-task-hal-runtime.js";
|
|
import { createSimulationStore } from "../../app/src/state/store.js";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
const rootDir = resolve(__dirname, "../../..");
|
|
const wasmPath = resolve(rootDir, "wasm-port/build/wasm/task-hal/linuxcnc_task_hal.wasm");
|
|
|
|
const sdk = await createLinuxCncTaskHalSdk({
|
|
wasmBinary: readFileSync(wasmPath),
|
|
print() {},
|
|
printErr(message) {
|
|
console.error(message);
|
|
},
|
|
});
|
|
const runtime = wrapTaskHalSdk(sdk);
|
|
const store = createSimulationStore({
|
|
programLines: [
|
|
"G0 X1 Y2 Z-3 A10 C20",
|
|
"G1 X2 Y3 Z-4 A11 C21",
|
|
"M428",
|
|
"G1 X3 Y4 Z-5 A12 C22",
|
|
],
|
|
activeProgram: "task-hal-store-smoke.ngc",
|
|
});
|
|
|
|
store.dispatch({ type: "ATTACH_TASK_HAL_RUNTIME", runtime });
|
|
assert.equal(store.getState().taskHalRuntimeReadiness.taskRuntimeReady, true);
|
|
assert.equal(store.getState().taskHalRuntimeReadiness.motionRuntimeReady, true);
|
|
assert.equal(store.getState().taskHalRuntimeReadiness.halRuntimeReady, true);
|
|
|
|
store.dispatch({ type: "TOGGLE_POWER" });
|
|
await waitForTaskHal(store);
|
|
store.dispatch({ type: "HOME" });
|
|
store.dispatch({ type: "SET_MODE", mode: "auto" });
|
|
await waitForTaskHal(store);
|
|
store.dispatch({ type: "RUN" });
|
|
await waitForTaskHal(store);
|
|
|
|
let state = store.getState();
|
|
assert.equal(state.taskHalStatus.summary.taskRuntimeReady, true);
|
|
assert.equal(state.taskHalStatus.summary.halSyncReady, true);
|
|
assert.equal(state.taskHalStatus.ui.activeLine >= 1, true);
|
|
assert.equal(state.axisPose.x >= 1, true);
|
|
assert.equal(state.programExecutionSourceMode, "linuxcnc-task-motion-hal-wasm");
|
|
assert.equal(state.fullExecutionBoundary.nativeTaskReady, true);
|
|
assert.equal(state.fullExecutionBoundary.nativeHalSyncReady, true);
|
|
|
|
store.dispatch({ type: "SET_MODE", mode: "mdi" });
|
|
await waitForTaskHal(store);
|
|
store.dispatch({ type: "RUN_MDI", command: "M428" });
|
|
await waitForTaskHal(store);
|
|
state = store.getState();
|
|
assert.equal(state.taskHalStatus.ui.switchkinsType, 1);
|
|
assert.equal(state.kinsType, "tcp-xyzac");
|
|
assert.equal(state.rtcpState, "on");
|
|
|
|
store.dispatch({ type: "SET_MODE", mode: "manual" });
|
|
await waitForTaskHal(store);
|
|
store.dispatch({ type: "JOG", axis: "x", direction: 1, increment: 0.5 });
|
|
await waitForTaskHal(store);
|
|
state = store.getState();
|
|
assert.equal(state.taskHalStatus.motionStatus.motion.teleopMode, 1);
|
|
assert.equal(state.programRuntimeFeedback.sourceMode, "linuxcnc-task-motion-hal-wasm");
|
|
|
|
store.dispatch({ type: "SET_MODE", mode: "auto" });
|
|
await waitForTaskHal(store);
|
|
store.dispatch({ type: "PAUSE" });
|
|
await waitForTaskHal(store);
|
|
assert.equal(store.getState().machine.interpState, "paused");
|
|
|
|
store.dispatch({ type: "RESUME" });
|
|
await waitForTaskHal(store);
|
|
assert.equal(store.getState().machine.interpState, "reading");
|
|
|
|
console.log("linuxcnc_task_hal_runtime_smoke=ok");
|
|
console.log("task_hal_machine_file_smoke=ok");
|
|
console.log("switchkins_remap_hal_sync_smoke=ok");
|
|
console.log("browser_task_hal_worker_smoke=ok");
|
|
|
|
async function waitForTaskHal(store) {
|
|
for (let attempt = 0; attempt < 30; attempt += 1) {
|
|
if (!store.getState().taskHalExecutionPending) {
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
if (!store.getState().taskHalExecutionPending) return store.getState();
|
|
}
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
}
|
|
throw new Error("task/HAL store command did not settle");
|
|
}
|