继续把 interp_execute.cc、interp_queue.cc、interp_find.cc 等 LinuxCNC 源文件纳入直接编译/链接路径,逐步删除临时 convert_g() wrapper 行为
结论:已将核心 LinuxCNC interpreter 源接入 standalone native 编译链接路径,移除 minimal runtime 中的手写 convert_g 行为,并通过 native probe 验证。
This commit is contained in:
206
wasm-port/runtime/ui/ini-panel/app.js
Normal file
206
wasm-port/runtime/ui/ini-panel/app.js
Normal file
@@ -0,0 +1,206 @@
|
||||
import createLinuxCncIniModule from "./linuxcnc_ini.js";
|
||||
|
||||
const SAMPLE_PATH =
|
||||
"../../../linuxcnc/configs/sim/axis/vismach/5axis/table-dual-rotary/xyzab-tdr.ini";
|
||||
const OPFS_FILE = "linuxcnc/xyzab-tdr.ini";
|
||||
const WASM_FILE = "/work/xyzab-tdr.ini";
|
||||
|
||||
const editor = document.getElementById("ini-editor");
|
||||
const logNode = document.getElementById("log");
|
||||
const wasmBadge = document.getElementById("wasm-badge");
|
||||
const opfsBadge = document.getElementById("opfs-badge");
|
||||
|
||||
const fields = {
|
||||
machine: document.getElementById("field-machine"),
|
||||
display: document.getElementById("field-display"),
|
||||
kinematics: document.getElementById("field-kinematics"),
|
||||
joints: document.getElementById("field-joints"),
|
||||
coordinates: document.getElementById("field-coordinates"),
|
||||
parameterFile: document.getElementById("field-parameter-file"),
|
||||
};
|
||||
|
||||
let moduleInstance = null;
|
||||
|
||||
function setBadge(node, text, className = "badge") {
|
||||
node.className = className;
|
||||
node.textContent = text;
|
||||
}
|
||||
|
||||
function setLog(message, isError = false) {
|
||||
logNode.textContent = message;
|
||||
logNode.className = `log${isError ? " danger" : ""}`;
|
||||
}
|
||||
|
||||
function setField(name, value) {
|
||||
fields[name].textContent = value ?? "-";
|
||||
}
|
||||
|
||||
function requireModule() {
|
||||
if (!moduleInstance) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
async function getOpfsRoot() {
|
||||
if (!navigator.storage?.getDirectory) {
|
||||
throw new Error("OPFS is not available in this browser.");
|
||||
}
|
||||
return navigator.storage.getDirectory();
|
||||
}
|
||||
|
||||
async function ensureParentDir(root, path) {
|
||||
const parts = path.split("/");
|
||||
let current = root;
|
||||
for (const part of parts.slice(0, -1)) {
|
||||
current = await current.getDirectoryHandle(part, { create: true });
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
async function saveToOpfs(path, text) {
|
||||
const root = await getOpfsRoot();
|
||||
const dir = await ensureParentDir(root, path);
|
||||
const filename = path.split("/").at(-1);
|
||||
const fileHandle = await dir.getFileHandle(filename, { create: true });
|
||||
const writable = await fileHandle.createWritable();
|
||||
await writable.write(text);
|
||||
await writable.close();
|
||||
}
|
||||
|
||||
async function loadFromOpfs(path) {
|
||||
const root = await getOpfsRoot();
|
||||
const parts = path.split("/");
|
||||
let current = root;
|
||||
for (const part of parts.slice(0, -1)) {
|
||||
current = await current.getDirectoryHandle(part);
|
||||
}
|
||||
const fileHandle = await current.getFileHandle(parts.at(-1));
|
||||
const file = await fileHandle.getFile();
|
||||
return file.text();
|
||||
}
|
||||
|
||||
function syncEditorToWasmFs() {
|
||||
const mod = requireModule();
|
||||
try {
|
||||
mod.FS.mkdir("/work");
|
||||
} catch {
|
||||
// already exists
|
||||
}
|
||||
mod.FS.writeFile(WASM_FILE, editor.value, { encoding: "utf8" });
|
||||
}
|
||||
|
||||
async function loadSample() {
|
||||
setLog(`Fetching ${SAMPLE_PATH}`);
|
||||
const response = await fetch(SAMPLE_PATH);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Cannot fetch sample INI (${response.status})`);
|
||||
}
|
||||
editor.value = await response.text();
|
||||
setLog("Loaded LinuxCNC sample INI into the standalone editor.");
|
||||
}
|
||||
|
||||
async function boot() {
|
||||
try {
|
||||
moduleInstance = await createLinuxCncIniModule();
|
||||
setBadge(wasmBadge, "WASM: ready");
|
||||
} catch (error) {
|
||||
setBadge(wasmBadge, "WASM: failed", "badge danger");
|
||||
setLog(`WASM init failed: ${error.message}`, true);
|
||||
throw error;
|
||||
}
|
||||
|
||||
try {
|
||||
await getOpfsRoot();
|
||||
setBadge(opfsBadge, "OPFS: ready");
|
||||
} catch (error) {
|
||||
setBadge(opfsBadge, "OPFS: unavailable", "badge danger");
|
||||
setLog(`OPFS check failed: ${error.message}`, true);
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById("load-sample").addEventListener("click", async () => {
|
||||
try {
|
||||
await loadSample();
|
||||
} catch (error) {
|
||||
setLog(error.message, true);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById("save-opfs").addEventListener("click", async () => {
|
||||
try {
|
||||
await saveToOpfs(OPFS_FILE, editor.value);
|
||||
setLog(`Saved current INI text to OPFS at ${OPFS_FILE}`);
|
||||
} catch (error) {
|
||||
setLog(`OPFS save failed: ${error.message}`, true);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById("load-opfs").addEventListener("click", async () => {
|
||||
try {
|
||||
editor.value = await loadFromOpfs(OPFS_FILE);
|
||||
setLog(`Loaded INI text from OPFS path ${OPFS_FILE}`);
|
||||
} catch (error) {
|
||||
setLog(`OPFS load failed: ${error.message}`, true);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById("sync-wasm").addEventListener("click", () => {
|
||||
try {
|
||||
syncEditorToWasmFs();
|
||||
setLog(`Synced editor contents to WASM filesystem at ${WASM_FILE}`);
|
||||
} catch (error) {
|
||||
setLog(`WASM sync failed: ${error.message}`, true);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById("query").addEventListener("click", async () => {
|
||||
try {
|
||||
syncEditorToWasmFs();
|
||||
const mod = requireModule();
|
||||
|
||||
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"),
|
||||
);
|
||||
|
||||
setLog("Queried LinuxCNC INI fields through the standalone WASM parser.");
|
||||
} catch (error) {
|
||||
setLog(`Query failed: ${error.message}`, true);
|
||||
}
|
||||
});
|
||||
|
||||
boot().catch(() => {});
|
||||
189
wasm-port/runtime/ui/ini-panel/index.html
Normal file
189
wasm-port/runtime/ui/ini-panel/index.html
Normal file
@@ -0,0 +1,189 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>LinuxCNC WASM INI Panel</title>
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: light;
|
||||
--bg: #eef3f7;
|
||||
--panel: #ffffff;
|
||||
--border: #c9d5df;
|
||||
--text: #182430;
|
||||
--muted: #566676;
|
||||
--accent: #1263a3;
|
||||
--accent-2: #0f8a70;
|
||||
--danger: #b04040;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: "Segoe UI", "Noto Sans", sans-serif;
|
||||
background: linear-gradient(180deg, rgba(18, 99, 163, 0.08), transparent 24rem), var(--bg);
|
||||
color: var(--text);
|
||||
}
|
||||
main {
|
||||
max-width: 1180px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
.header, .panel {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 10px 30px rgba(17, 34, 51, 0.06);
|
||||
}
|
||||
.header { padding: 20px 24px; }
|
||||
h1, h2 { margin: 0; font-weight: 600; }
|
||||
p { margin: 0; color: var(--muted); line-height: 1.5; }
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
|
||||
gap: 16px;
|
||||
}
|
||||
.panel {
|
||||
padding: 16px;
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
.controls {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
button {
|
||||
border: 1px solid var(--border);
|
||||
background: #f6f9fb;
|
||||
color: var(--text);
|
||||
padding: 10px 14px;
|
||||
border-radius: 6px;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
button.primary {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
color: #fff;
|
||||
}
|
||||
button.secondary {
|
||||
background: var(--accent-2);
|
||||
border-color: var(--accent-2);
|
||||
color: #fff;
|
||||
}
|
||||
textarea {
|
||||
width: 100%;
|
||||
min-height: 420px;
|
||||
resize: vertical;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
padding: 12px;
|
||||
font: 13px/1.5 "SFMono-Regular", "Consolas", monospace;
|
||||
color: var(--text);
|
||||
background: #fbfdff;
|
||||
}
|
||||
.status { display: grid; gap: 8px; }
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 4px 8px;
|
||||
border-radius: 999px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
background: #dbe8f3;
|
||||
color: var(--accent);
|
||||
}
|
||||
.kv {
|
||||
display: grid;
|
||||
grid-template-columns: 132px 1fr;
|
||||
gap: 8px 12px;
|
||||
align-items: start;
|
||||
border-top: 1px solid #edf2f6;
|
||||
padding-top: 12px;
|
||||
}
|
||||
.kv dt {
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
.kv dd {
|
||||
margin: 0;
|
||||
font-family: "SFMono-Regular", "Consolas", monospace;
|
||||
font-size: 13px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.log {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
background: #fbfdff;
|
||||
padding: 12px;
|
||||
min-height: 120px;
|
||||
font: 13px/1.5 "SFMono-Regular", "Consolas", monospace;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.danger { color: var(--danger); }
|
||||
@media (max-width: 960px) {
|
||||
.grid { grid-template-columns: 1fr; }
|
||||
textarea { min-height: 320px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<section class="header">
|
||||
<h1>LinuxCNC WASM INI Panel</h1>
|
||||
<p>
|
||||
This standalone panel uses LinuxCNC's native <code>IniFile</code> parser
|
||||
compiled to WASM. It is managed under <code>wasm-port/</code> and reads
|
||||
upstream LinuxCNC-style machine configs through the browser host.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="grid">
|
||||
<section class="panel">
|
||||
<h2>Configuration File</h2>
|
||||
<div class="controls">
|
||||
<button id="load-sample" class="primary">Load LinuxCNC Sample</button>
|
||||
<button id="save-opfs">Save To OPFS</button>
|
||||
<button id="load-opfs">Load From OPFS</button>
|
||||
<button id="sync-wasm">Sync To WASM FS</button>
|
||||
<button id="query" class="secondary">Query LinuxCNC Fields</button>
|
||||
</div>
|
||||
<textarea id="ini-editor" spellcheck="false"></textarea>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<h2>Control Panel</h2>
|
||||
<div class="status">
|
||||
<div><span id="wasm-badge" class="badge">WASM: loading</span></div>
|
||||
<div><span id="opfs-badge" class="badge">OPFS: checking</span></div>
|
||||
</div>
|
||||
|
||||
<dl class="kv">
|
||||
<dt>Machine</dt>
|
||||
<dd id="field-machine">-</dd>
|
||||
<dt>Display</dt>
|
||||
<dd id="field-display">-</dd>
|
||||
<dt>Kinematics</dt>
|
||||
<dd id="field-kinematics">-</dd>
|
||||
<dt>Joints</dt>
|
||||
<dd id="field-joints">-</dd>
|
||||
<dt>Coordinates</dt>
|
||||
<dd id="field-coordinates">-</dd>
|
||||
<dt>Parameter File</dt>
|
||||
<dd id="field-parameter-file">-</dd>
|
||||
<dt>OPFS Path</dt>
|
||||
<dd id="field-opfs-path">linuxcnc/xyzab-tdr.ini</dd>
|
||||
<dt>WASM Path</dt>
|
||||
<dd id="field-wasm-path">/work/xyzab-tdr.ini</dd>
|
||||
</dl>
|
||||
|
||||
<div class="log" id="log"></div>
|
||||
</section>
|
||||
</section>
|
||||
</main>
|
||||
<script type="module" src="./app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
16
wasm-port/runtime/ui/ini-panel/linuxcnc_ini.js
Normal file
16
wasm-port/runtime/ui/ini-panel/linuxcnc_ini.js
Normal file
File diff suppressed because one or more lines are too long
BIN
wasm-port/runtime/ui/ini-panel/linuxcnc_ini.wasm
Executable file
BIN
wasm-port/runtime/ui/ini-panel/linuxcnc_ini.wasm
Executable file
Binary file not shown.
Reference in New Issue
Block a user