完善虚拟HAL仿真替代能力
This commit is contained in:
@@ -1,5 +1,42 @@
|
||||
export { createLinuxCncIniSdk } from "./linuxcnc-ini.js";
|
||||
export { createLinuxCncInterpSdk } from "./linuxcnc-interp.js";
|
||||
export {
|
||||
VIRTUAL_HAL_AXES,
|
||||
VIRTUAL_HAL_AXISUI_PINS,
|
||||
VIRTUAL_HAL_COVERAGE_STATES,
|
||||
VIRTUAL_HAL_PROJECT_PIN_GROUPS,
|
||||
VIRTUAL_HAL_SIMULATION_REPLACEMENT_TARGETS,
|
||||
VIRTUAL_HAL_SIMULATION_RUNTIME_CAPABILITIES,
|
||||
VIRTUAL_HAL_SOURCE_FILES,
|
||||
VIRTUAL_HAL_SYSTEM_PIN_FAMILIES,
|
||||
VIRTUAL_HAL_WASM_BRIDGE_FUNCTIONS,
|
||||
applyVirtualHalToInterpSdk,
|
||||
applyVirtualHalAction,
|
||||
applyVirtualHalPinUpdates,
|
||||
cloneVirtualHalState,
|
||||
createLinuxCncVirtualHalRuntime,
|
||||
createVirtualHalBridgeActionPlan,
|
||||
createVirtualHalBridgeReadiness,
|
||||
createVirtualHalDroState,
|
||||
createVirtualHalLimitsHomeState,
|
||||
createVirtualHalMachineStatusState,
|
||||
createVirtualHalIntegrityReport,
|
||||
createVirtualHalPinInventory,
|
||||
createVirtualHalPinRegistry,
|
||||
createVirtualHalProjectReport,
|
||||
createVirtualHalSimulationReplacementReport,
|
||||
createVirtualHalSimulationRuntimeReport,
|
||||
createVirtualHalState,
|
||||
createVirtualHalSystemCoverageReport,
|
||||
createVirtualHalWasmBridgeSnapshot,
|
||||
executeVirtualHalCommand,
|
||||
executeVirtualHalcmd,
|
||||
parseVirtualHalJogIncrement,
|
||||
readVirtualHalPin,
|
||||
stepVirtualHalMotionController,
|
||||
stepVirtualHalMotion,
|
||||
writeVirtualHalPin,
|
||||
} from "./linuxcnc-hal.js";
|
||||
export {
|
||||
createProjectBatchAcceptanceActionPlan,
|
||||
createProjectBatchAcceptanceCapabilityMatrix,
|
||||
|
||||
2315
wasm-port/runtime/sdk/src/linuxcnc-hal.js
Normal file
2315
wasm-port/runtime/sdk/src/linuxcnc-hal.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
||||
import createLinuxCncInterpModule from "../../../build/wasm/core/linuxcnc_interp.js";
|
||||
import { createVirtualHalWasmBridgeSnapshot } from "./linuxcnc-hal.js";
|
||||
|
||||
function allocCString(mod, value) {
|
||||
const bytes = mod.lengthBytesUTF8(value) + 1;
|
||||
@@ -43,12 +44,36 @@ function callStringResult(mod, functionName, ...values) {
|
||||
}
|
||||
}
|
||||
|
||||
function requireWasmFunction(mod, functionName) {
|
||||
const fn = mod[`_${functionName}`];
|
||||
if (typeof fn !== "function") {
|
||||
throw new Error(`linuxcnc interpreter WASM missing ${functionName}; rebuild wasm-port/tools/build_wasm_core.sh`);
|
||||
}
|
||||
return fn;
|
||||
}
|
||||
|
||||
function callVoidWithStringsAndNumbers(mod, functionName, strings, numbers = []) {
|
||||
const fn = requireWasmFunction(mod, functionName);
|
||||
const ptrs = strings.map((value) => allocCString(mod, value));
|
||||
try {
|
||||
return fn(...ptrs, ...numbers);
|
||||
} finally {
|
||||
for (const ptr of ptrs) {
|
||||
mod._free(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function createLinuxCncInterpSdk(moduleOptions = {}) {
|
||||
const mod = await createLinuxCncInterpModule(moduleOptions);
|
||||
|
||||
return {
|
||||
module: mod,
|
||||
|
||||
hasWasmFunction(functionName) {
|
||||
return typeof mod[`_${functionName}`] === "function";
|
||||
},
|
||||
|
||||
writeTextFile(path, text) {
|
||||
ensureParentPath(mod, path);
|
||||
mod.FS.writeFile(path, text, { encoding: "utf8" });
|
||||
@@ -160,5 +185,44 @@ export async function createLinuxCncInterpSdk(moduleOptions = {}) {
|
||||
probeNamedParameters(iniPath) {
|
||||
return callStringResult(mod, "lcinterp_probe_named_parameters", iniPath);
|
||||
},
|
||||
|
||||
resetHal() {
|
||||
requireWasmFunction(mod, "lcinterp_hal_reset")();
|
||||
},
|
||||
|
||||
setHalValue({ kind = "pin", name, type = "HAL_FLOAT", value = 0, connected = true }) {
|
||||
if (!name) {
|
||||
throw new Error("setHalValue requires a HAL name");
|
||||
}
|
||||
return callVoidWithStringsAndNumbers(
|
||||
mod,
|
||||
"lcinterp_hal_set_value",
|
||||
[kind, name, type],
|
||||
[Number(value) || 0, connected === false ? 0 : 1],
|
||||
);
|
||||
},
|
||||
|
||||
applyVirtualHalSnapshot(snapshot, options = {}) {
|
||||
if (options.reset !== false) {
|
||||
this.resetHal();
|
||||
}
|
||||
for (const value of snapshot?.values ?? []) {
|
||||
this.setHalValue(value);
|
||||
}
|
||||
return {
|
||||
apiName: "linuxcnc-wasm-hal-apply-result",
|
||||
applied: snapshot?.values?.length ?? 0,
|
||||
reset: options.reset !== false,
|
||||
source: snapshot?.source ?? "unknown",
|
||||
};
|
||||
},
|
||||
|
||||
applyVirtualHalState(halState, options = {}) {
|
||||
return this.applyVirtualHalSnapshot(createVirtualHalWasmBridgeSnapshot(halState), options);
|
||||
},
|
||||
|
||||
probeHalNamed(name) {
|
||||
return callStringResult(mod, "lcinterp_probe_hal_named", name);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user