按规划继续工作

结论:接入 LinuxCNC iniFindBool 到 INI WASM/SDK,并让 machine-session bridge 通过 vendored INI 解析 [EMCIO]RANDOM_TOOLCHANGER 后透传给 tooldata;native、WASM、OPFS 和浏览器 smoke 验证已通过。
This commit is contained in:
2026-06-08 08:49:38 +08:00
parent 3f4eb06b47
commit cf0887e0e7
16 changed files with 151 additions and 20 deletions

View File

@@ -13,6 +13,19 @@ int lcini_get_string(const char *inipath,
return iniFindString(inipath, tag, section, buf, static_cast<size_t>(bufsize));
}
EMSCRIPTEN_KEEPALIVE
int lcini_get_bool(const char *inipath,
const char *section,
const char *tag,
int *result) {
bool value = false;
const int rc = iniFindBool(inipath, tag, section, &value);
if (rc == 0 && result) {
*result = value ? 1 : 0;
}
return rc;
}
EMSCRIPTEN_KEEPALIVE
int lcini_tilde_expand(const char *path, char *buf, int bufsize) {
return TildeExpansion(path, buf, static_cast<size_t>(bufsize));

View File

@@ -17,6 +17,17 @@ function requireSessionSdk(interp) {
}
}
function requireIniSdk(iniSdk) {
if (!iniSdk) {
return;
}
for (const method of ["writeTextFile", "getBool"]) {
if (typeof iniSdk[method] !== "function") {
throw new Error(`INI SDK is missing ${method}().`);
}
}
}
function resolveSessionPaths(machineId, options = {}) {
return {
iniOpfsPath: options.iniOpfsPath ?? machineIniPath(machineId, options.iniFilename),
@@ -30,11 +41,25 @@ function resolveSessionPaths(machineId, options = {}) {
};
}
function randomToolChangerFromIni(iniSdk, iniWasmPath, iniText) {
if (!iniSdk) {
return false;
}
iniSdk.writeTextFile(iniWasmPath, iniText);
return iniSdk.getBool(iniWasmPath, "EMCIO", "RANDOM_TOOLCHANGER") === true;
}
export async function loadMachineSessionFromOpfs(interp, machineId, options = {}) {
requireSessionSdk(interp);
requireIniSdk(options.iniSdk);
const paths = resolveSessionPaths(machineId, options);
const iniText = await loadTextFile(paths.iniOpfsPath, options.storage);
interp.writeTextFile(paths.iniWasmPath, iniText);
const randomToolChanger =
typeof options.randomToolChanger === "boolean"
? options.randomToolChanger
: randomToolChangerFromIni(options.iniSdk, paths.iniWasmPath, iniText);
const parameters = await restoreMachineParametersFromOpfs(interp, machineId, {
storage: options.storage,
@@ -45,7 +70,7 @@ export async function loadMachineSessionFromOpfs(interp, machineId, options = {}
storage: options.storage,
opfsPath: paths.toolTableOpfsPath,
wasmPath: paths.toolTableWasmPath,
randomToolChanger: options.randomToolChanger === true,
randomToolChanger,
});
return {

View File

@@ -29,7 +29,8 @@ import {
```
`createLinuxCncIniSdk()` wraps the INI parser module built from vendored
LinuxCNC `inifile.cc`.
LinuxCNC `inifile.cc` and exposes `getString()` plus `getBool()`. Boolean
conversion is performed by vendored LinuxCNC `iniFindBool()`.
`createLinuxCncInterpSdk()` wraps the interpreter-core module built from
vendored LinuxCNC RS274NGC sources and exposes:

View File

@@ -55,6 +55,23 @@ export async function createLinuxCncIniSdk(moduleOptions = {}) {
}
},
getBool(path, section, tag) {
const pathPtr = allocCString(mod, path);
const sectionPtr = allocCString(mod, section);
const tagPtr = allocCString(mod, tag);
const outPtr = mod._malloc(4);
try {
const rc = mod._lcini_get_bool(pathPtr, sectionPtr, tagPtr, outPtr);
return rc === 0 ? mod.HEAP32[outPtr >> 2] !== 0 : null;
} finally {
mod._free(pathPtr);
mod._free(sectionPtr);
mod._free(tagPtr);
mod._free(outPtr);
}
},
getFields(path, fields) {
return Object.fromEntries(
Object.entries(fields).map(([name, query]) => [

View File

@@ -204,7 +204,10 @@ document.getElementById("load-session").addEventListener("click", async () => {
loadedSession = await loadMachineSessionFromOpfs(
requireInterpSdk(),
MACHINE_ID,
SESSION_WASM_FILES,
{
...SESSION_WASM_FILES,
iniSdk: requireIniSdk(),
},
);
setField("sessionIni", loadedSession.ini.wasmPath);
setField("sessionParameters", loadedSession.parameters.wasmPath);

File diff suppressed because one or more lines are too long