按规划继续工作
结论:接入 vendored LinuxCNC tooldata_common.cc 负责刀具表解析与保存,WASM/SDK/OPFS/UI 仅做运行时边界搬运;native、WASM、OPFS 和浏览器 smoke 验证已通过。
This commit is contained in:
46
wasm-port/runtime/opfs/linuxcnc-tool-table-bridge.js
Normal file
46
wasm-port/runtime/opfs/linuxcnc-tool-table-bridge.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import { loadTextFile, saveTextFile } from "./file-service.js";
|
||||
import { toolTablePath } from "./path-model.js";
|
||||
|
||||
const DEFAULT_WASM_TOOL_TABLE_PATH = "/work/tool.tbl";
|
||||
|
||||
function requireToolTableSdk(interp) {
|
||||
for (const method of ["writeTextFile", "readTextFile", "loadToolTable", "saveToolTable"]) {
|
||||
if (typeof interp?.[method] !== "function") {
|
||||
throw new Error(`interpreter SDK is missing ${method}().`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resolvePaths(machineId, options = {}) {
|
||||
const opfsPath = options.opfsPath ?? toolTablePath(machineId, options.filename);
|
||||
const wasmPath = options.wasmPath ?? DEFAULT_WASM_TOOL_TABLE_PATH;
|
||||
return { opfsPath, wasmPath };
|
||||
}
|
||||
|
||||
export async function loadMachineToolTableFromOpfs(interp, machineId, options = {}) {
|
||||
requireToolTableSdk(interp);
|
||||
const { opfsPath, wasmPath } = resolvePaths(machineId, options);
|
||||
const text = await loadTextFile(opfsPath, options.storage);
|
||||
interp.writeTextFile(wasmPath, text);
|
||||
return {
|
||||
opfsPath,
|
||||
wasmPath,
|
||||
result: interp.loadToolTable(wasmPath),
|
||||
};
|
||||
}
|
||||
|
||||
export async function saveMachineToolTableToOpfs(interp, machineId, options = {}) {
|
||||
requireToolTableSdk(interp);
|
||||
const { opfsPath, wasmPath } = resolvePaths(machineId, options);
|
||||
const result = interp.saveToolTable(wasmPath);
|
||||
const savedText = interp.readTextFile(wasmPath);
|
||||
|
||||
await saveTextFile(opfsPath, savedText, options.storage);
|
||||
|
||||
return {
|
||||
opfsPath,
|
||||
wasmPath,
|
||||
result,
|
||||
savedText,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user