结论:接入 vendored LinuxCNC tooldata_common.cc 负责刀具表解析与保存,WASM/SDK/OPFS/UI 仅做运行时边界搬运;native、WASM、OPFS 和浏览器 smoke 验证已通过。
60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
import { loadTextFile } from "./file-service.js";
|
|
import {
|
|
machineIniPath,
|
|
parameterFilePath,
|
|
toolTablePath,
|
|
} from "./path-model.js";
|
|
import { restoreMachineParametersFromOpfs } from "./linuxcnc-parameter-bridge.js";
|
|
import { loadMachineToolTableFromOpfs } from "./linuxcnc-tool-table-bridge.js";
|
|
|
|
const DEFAULT_WASM_INI_PATH = "/work/machine.ini";
|
|
const DEFAULT_WASM_PARAMETER_PATH = "/work/linuxcnc.var";
|
|
const DEFAULT_WASM_TOOL_TABLE_PATH = "/work/tool.tbl";
|
|
|
|
function requireSessionSdk(interp) {
|
|
if (typeof interp?.writeTextFile !== "function") {
|
|
throw new Error("interpreter SDK is missing writeTextFile().");
|
|
}
|
|
}
|
|
|
|
function resolveSessionPaths(machineId, options = {}) {
|
|
return {
|
|
iniOpfsPath: options.iniOpfsPath ?? machineIniPath(machineId, options.iniFilename),
|
|
iniWasmPath: options.iniWasmPath ?? DEFAULT_WASM_INI_PATH,
|
|
parameterOpfsPath:
|
|
options.parameterOpfsPath ?? parameterFilePath(machineId, options.parameterFilename),
|
|
parameterWasmPath: options.parameterWasmPath ?? DEFAULT_WASM_PARAMETER_PATH,
|
|
toolTableOpfsPath:
|
|
options.toolTableOpfsPath ?? toolTablePath(machineId, options.toolTableFilename),
|
|
toolTableWasmPath: options.toolTableWasmPath ?? DEFAULT_WASM_TOOL_TABLE_PATH,
|
|
};
|
|
}
|
|
|
|
export async function loadMachineSessionFromOpfs(interp, machineId, options = {}) {
|
|
requireSessionSdk(interp);
|
|
const paths = resolveSessionPaths(machineId, options);
|
|
const iniText = await loadTextFile(paths.iniOpfsPath, options.storage);
|
|
interp.writeTextFile(paths.iniWasmPath, iniText);
|
|
|
|
const parameters = await restoreMachineParametersFromOpfs(interp, machineId, {
|
|
storage: options.storage,
|
|
opfsPath: paths.parameterOpfsPath,
|
|
wasmPath: paths.parameterWasmPath,
|
|
});
|
|
const toolTable = await loadMachineToolTableFromOpfs(interp, machineId, {
|
|
storage: options.storage,
|
|
opfsPath: paths.toolTableOpfsPath,
|
|
wasmPath: paths.toolTableWasmPath,
|
|
});
|
|
|
|
return {
|
|
machineId,
|
|
ini: {
|
|
opfsPath: paths.iniOpfsPath,
|
|
wasmPath: paths.iniWasmPath,
|
|
},
|
|
parameters,
|
|
toolTable,
|
|
};
|
|
}
|