73 lines
3.0 KiB
JavaScript
73 lines
3.0 KiB
JavaScript
export async function runLinuxCncBrowserSections(context, simulator) {
|
|
const {
|
|
expectEvent,
|
|
expectMissingWasmPath,
|
|
near,
|
|
runSection,
|
|
} = context;
|
|
await runSection("linuxcnc browser basic parse", async () => {
|
|
const events = simulator.parse("G21 G90\nG0 X0\nG1 X5 F100\nM30\n", "linuxcnc", {
|
|
backend: "linuxcnc-rs274",
|
|
});
|
|
expectEvent(events, (event) => event.type === "linear-feed" && near(event.end.x, 5),
|
|
"missing expected LinuxCNC WASM browser linear-feed event");
|
|
expectEvent(events, (event) => event.type === "program-end",
|
|
"missing expected LinuxCNC WASM browser program-end event");
|
|
});
|
|
let configCases = [];
|
|
await runSection("linuxcnc generated switchkins cases load", async () => {
|
|
const configCaseResponse = await fetch("/public/linuxcnc_switchkins_remap_config_cases.json");
|
|
if (!configCaseResponse.ok) {
|
|
throw new Error(`failed to load LinuxCNC switchkins config cases: ${configCaseResponse.status}`);
|
|
}
|
|
configCases = await configCaseResponse.json();
|
|
if (!Array.isArray(configCases) || configCases.length === 0) {
|
|
throw new Error("missing LinuxCNC switchkins config cases");
|
|
}
|
|
});
|
|
for (const configCase of configCases) {
|
|
await runSection(`linuxcnc generated switchkins ${configCase.field}=${configCase.value}`, async () => {
|
|
const options = {
|
|
backend: "linuxcnc-rs274",
|
|
[configCase.field]: configCase.value,
|
|
};
|
|
const program = configCase.m430 >= 0 ? "M428\nM429\nM430\n" : "M428\nM429\n";
|
|
const configEvents = simulator.parse(program, "linuxcnc", options);
|
|
for (const [line, kinstype] of [
|
|
[1, configCase.m428],
|
|
[2, configCase.m429],
|
|
...(configCase.m430 >= 0 ? [[3, configCase.m430]] : []),
|
|
]) {
|
|
expectEvent(configEvents,
|
|
(event) => event.type === "kinematics-switch" && event.line === line && event.reserved === kinstype,
|
|
`missing LinuxCNC WASM browser generated ${configCase.field}=${configCase.value} line ${line} switchkins type ${kinstype}`,
|
|
);
|
|
}
|
|
});
|
|
}
|
|
await runSection("linuxcnc browser explicit scara switchkins", async () => {
|
|
const switchEvents = simulator.parse("M428\nM429\nM430\n", "linuxcnc", {
|
|
backend: "linuxcnc-rs274",
|
|
switchkins: "scara",
|
|
});
|
|
for (const [line, kinstype] of [
|
|
[1, 0],
|
|
[2, 1],
|
|
[3, 2],
|
|
]) {
|
|
expectEvent(switchEvents,
|
|
(event) => event.type === "kinematics-switch" && event.line === line && event.reserved === kinstype,
|
|
`missing LinuxCNC WASM browser M${427 + line} switchkins type ${kinstype}`,
|
|
);
|
|
}
|
|
});
|
|
await runSection("linuxcnc browser parse parameter scratch cleanup", async () => {
|
|
for (const parameterPath of ["rs274ngc.var", "rs274ngc.var.new", "rs274ngc.var.bak"]) {
|
|
expectMissingWasmPath(
|
|
() => simulator.fs.module.FS.stat(parameterPath),
|
|
`browser parse left LinuxCNC parameter state outside OPFS: ${parameterPath}`,
|
|
);
|
|
}
|
|
});
|
|
}
|