按建议,继续完成后续工作

结论:已新增 INI WASM JS SDK 封装,把 UI 和 Node smoke test 改为通过 SDK 调用 vendored LinuxCNC inifile.cc 的导出 C ABI,并同步更新兼容性、复用和漂移文档。
This commit is contained in:
2026-06-08 00:23:48 +08:00
parent 9a9fb5d4c1
commit 0d78849d80
7 changed files with 121 additions and 103 deletions

View File

@@ -1,4 +1,4 @@
import createLinuxCncIniModule from "./linuxcnc_ini.js";
import { createLinuxCncIniSdk } from "../../sdk/src/linuxcnc-ini.js";
import {
getOpfsRoot,
loadTextFile,
@@ -24,7 +24,7 @@ const fields = {
parameterFile: document.getElementById("field-parameter-file"),
};
let moduleInstance = null;
let iniSdk = null;
function setBadge(node, text, className = "badge") {
node.className = className;
@@ -40,49 +40,15 @@ function setField(name, value) {
fields[name].textContent = value ?? "-";
}
function requireModule() {
if (!moduleInstance) {
function requireIniSdk() {
if (!iniSdk) {
throw new Error("WASM module is not ready yet.");
}
return moduleInstance;
}
function allocCString(mod, value) {
const bytes = mod.lengthBytesUTF8(value) + 1;
const ptr = mod._malloc(bytes);
mod.stringToUTF8(value, ptr, bytes);
return ptr;
}
function iniQuery(mod, wasmPath, section, tag) {
const pathPtr = allocCString(mod, wasmPath);
const sectionPtr = allocCString(mod, section);
const tagPtr = allocCString(mod, tag);
const outSize = 2048;
const outPtr = mod._malloc(outSize);
try {
const rc = mod._lcini_get_string(pathPtr, sectionPtr, tagPtr, outPtr, outSize);
if (rc !== 0) {
return null;
}
return mod.UTF8ToString(outPtr);
} finally {
mod._free(pathPtr);
mod._free(sectionPtr);
mod._free(tagPtr);
mod._free(outPtr);
}
return iniSdk;
}
function syncEditorToWasmFs() {
const mod = requireModule();
try {
mod.FS.mkdir("/work");
} catch {
// already exists
}
mod.FS.writeFile(WASM_FILE, editor.value, { encoding: "utf8" });
requireIniSdk().writeTextFile(WASM_FILE, editor.value);
}
async function loadSample() {
@@ -97,7 +63,7 @@ async function loadSample() {
async function boot() {
try {
moduleInstance = await createLinuxCncIniModule();
iniSdk = await createLinuxCncIniSdk();
setBadge(wasmBadge, "WASM: ready");
} catch (error) {
setBadge(wasmBadge, "WASM: failed", "badge danger");
@@ -152,17 +118,18 @@ document.getElementById("sync-wasm").addEventListener("click", () => {
document.getElementById("query").addEventListener("click", async () => {
try {
syncEditorToWasmFs();
const mod = requireModule();
const values = requireIniSdk().getFields(WASM_FILE, {
machine: { section: "EMC", tag: "MACHINE" },
display: { section: "DISPLAY", tag: "DISPLAY" },
kinematics: { section: "KINS", tag: "KINEMATICS" },
joints: { section: "KINS", tag: "JOINTS" },
coordinates: { section: "TRAJ", tag: "COORDINATES" },
parameterFile: { section: "RS274NGC", tag: "PARAMETER_FILE" },
});
setField("machine", iniQuery(mod, WASM_FILE, "EMC", "MACHINE"));
setField("display", iniQuery(mod, WASM_FILE, "DISPLAY", "DISPLAY"));
setField("kinematics", iniQuery(mod, WASM_FILE, "KINS", "KINEMATICS"));
setField("joints", iniQuery(mod, WASM_FILE, "KINS", "JOINTS"));
setField("coordinates", iniQuery(mod, WASM_FILE, "TRAJ", "COORDINATES"));
setField(
"parameterFile",
iniQuery(mod, WASM_FILE, "RS274NGC", "PARAMETER_FILE"),
);
for (const [name, value] of Object.entries(values)) {
setField(name, value);
}
setLog("Queried LinuxCNC INI fields through the standalone WASM parser.");
} catch (error) {