From 335ab61a61674092b12d503619af8d328477ae61 Mon Sep 17 00:00:00 2001 From: wangdequan Date: Sun, 7 Jun 2026 23:51:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E5=BB=BA=E8=AE=AE=EF=BC=8C=E7=BB=A7?= =?UTF-8?q?=E7=BB=AD=E5=AE=8C=E6=88=90=E5=90=8E=E7=BB=AD=E5=B7=A5=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 结论:将解释器外部长度单位读取接入共享 emcStatus 状态边界,并补充 inch/mm 初始化验证。 --- wasm-port/docs/compatibility-validation.md | 4 ++-- wasm-port/docs/drift-report.md | 2 +- wasm-port/docs/source-reuse-map.md | 2 +- .../linuxcnc_emc_status_probe.cpp | 3 --- .../linuxcnc_emc_status_runtime.cpp | 4 ++++ .../linuxcnc_interp_init_harness.cpp | 19 ++++++++++++++++++- .../linuxcnc_interp_minimal_runtime.cpp | 8 ++++++-- .../tests/native/verify_native_probes.sh | 4 ++++ wasm-port/tools/build_native_probes.sh | 2 ++ 9 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_emc_status_runtime.cpp diff --git a/wasm-port/docs/compatibility-validation.md b/wasm-port/docs/compatibility-validation.md index aa0bb40..f317e28 100644 --- a/wasm-port/docs/compatibility-validation.md +++ b/wasm-port/docs/compatibility-validation.md @@ -52,11 +52,11 @@ The validation fails if: | --- | --- | | `linuxcnc_ini_probe` | Validates vendored LinuxCNC INI parsing can be used standalone. | | `linuxcnc_interp_state_probe` | Validates interpreter state constants and structs compile under the standalone boundary. | -| `linuxcnc_emc_status_probe` | Validates the standalone `emcStatus` machine-units status boundary used by vendored interpreter conversion code. | +| `linuxcnc_emc_status_probe` | Validates the standalone `emcStatus` machine-units status boundary used by vendored interpreter conversion and initialization code. | | `linuxcnc_namedparam_harness` | Validates LinuxCNC named parameter behavior, `_ini[...]`, and `_hal[...]` adapter resolution. | | `linuxcnc_interp_minimal_harness` | Runs G-code fixtures through vendored LinuxCNC parser/execution/conversion code and captures canonical events. | | `linuxcnc_parameter_file_harness` | Validates LinuxCNC parameter file restore/save behavior and required/read-only parameter handling. | -| `linuxcnc_interp_init_harness` | Validates vendored LinuxCNC `Interp::init()` emits canonical initialization boundaries through the standalone event sink. | +| `linuxcnc_interp_init_harness` | Validates vendored LinuxCNC `Interp::init()` emits canonical initialization boundaries and reads metric/inch machine units through the standalone event/status boundary. | | `linuxcnc_indexer_harness` | Validates vendored LinuxCNC single-axis rotary indexer dispatch emits lock/unlock and motion boundaries through the standalone event sink. | | `linuxcnc_tp_api_probe` | Validates vendored LinuxCNC trajectory planner calls for linear, arc, and queued motion paths. | | `linuxcnc_kinematics_probe` | Validates vendored LinuxCNC `trivkins.c` plus `kins_util.c` initialize and perform identity forward/inverse mapping through the standalone HAL/RTAPI boundary. | diff --git a/wasm-port/docs/drift-report.md b/wasm-port/docs/drift-report.md index 8123696..72faf18 100644 --- a/wasm-port/docs/drift-report.md +++ b/wasm-port/docs/drift-report.md @@ -33,7 +33,7 @@ semantic rewrites: | Interpreter reset | LinuxCNC `ON_RESET` is captured as a canonical test event on the vendored interpreter reset/file-open path. | | Interpreter init | LinuxCNC `INIT_CANON` and the canonical initialization sequence from vendored `Interp::init()` are captured as test events. | | Comment logging | LinuxCNC `LOGOPEN`, `LOG`, `LOGAPPEND`, and `LOGCLOSE` callbacks are captured as canonical test events instead of writing host log files. | -| EMC status machine units | A narrow standalone `emcStatus` shim exposes the machine-units field used by vendored interpreter conversion code; `linuxcnc_emc_status_probe` guards the inch/mm boundary. | +| EMC status machine units | A narrow standalone `emcStatus` shim exposes the machine-units field used by vendored interpreter conversion and initialization code; `linuxcnc_emc_status_probe` and `linuxcnc_interp_init_harness` guard the inch/mm boundary. | | Python/remap | Python/remap hooks are stubbed at the runtime edge. | | Dynamic interpreter path | `interp_base.cc` probe uses standalone `EMC2_HOME` compile-time path boundary. | | Realtime scheduler | TP probes seed deterministic status/config data instead of running LinuxCNC realtime process topology. | diff --git a/wasm-port/docs/source-reuse-map.md b/wasm-port/docs/source-reuse-map.md index 924633f..866da6f 100644 --- a/wasm-port/docs/source-reuse-map.md +++ b/wasm-port/docs/source-reuse-map.md @@ -33,7 +33,7 @@ Current validation is intentionally mechanical: | --- | --- | --- | --- | --- | | INI parsing | `src/emc/ini/inifile.cc`, `inifile.h`, `inifile.hh` | Copy unchanged | Native file IO remains LinuxCNC-style in the vendored parser; browser OPFS integration remains outside this layer | Vendor byte sync, `linuxcnc_ini_probe`, `linuxcnc_inifile_source_probe` | | RTAPI compatibility headers | `src/rtapi/rtapi_*.h` in the manifest | Copy unchanged plus standalone shim include path | `runtime/core/shims/rtapi.h` supplies the minimal standalone RTAPI surface needed by vendored code | Vendor byte sync, compile coverage through dependent source probes | -| Canon/NML-facing interpreter types | `src/emc/nml_intf/canon*.hh`, `emctool.h`, `interp_return.hh`, `motion_types.h`, `emcpose.*`, `emcpos.h`, `debugflags.h`, `src/emc/linuxcnc.h` | Copy unchanged plus narrow standalone status shim | NML transport is not ported; `runtime/core/shims/nml_intf/emc.hh` exposes only the `emcStatus` machine-units status edge currently needed by vendored interpreter conversion code | Vendor byte sync, dependent source probes, `linuxcnc_emc_status_probe`, `linuxcnc_tp_api_probe`, interpreter harnesses | +| Canon/NML-facing interpreter types | `src/emc/nml_intf/canon*.hh`, `emctool.h`, `interp_return.hh`, `motion_types.h`, `emcpose.*`, `emcpos.h`, `debugflags.h`, `src/emc/linuxcnc.h` | Copy unchanged plus narrow standalone status shim | NML transport is not ported; `runtime/core/shims/nml_intf/emc.hh` exposes only the `emcStatus` machine-units status edge currently needed by vendored interpreter conversion and initialization code | Vendor byte sync, dependent source probes, `linuxcnc_emc_status_probe`, `linuxcnc_tp_api_probe`, interpreter harnesses | | Motion state headers | `src/emc/motion/state_tag.h`, `emcmotcfg.h`, `simple_tp.h`, `motion.h`, `mot_priv.h`, `axis.h` | Copy unchanged | Realtime motion process is not ported; standalone probes seed the small motion status/config state required by TP calls | Vendor byte sync, `linuxcnc_tp_api_probe` | | Identity/trivial kinematics | `src/emc/kinematics/kinematics.h`, `cubic.h`, `kins_util.c`, `trivkins.c` | Copy unchanged | HAL component lifecycle and RTAPI module metadata are replaced by standalone shims; forward/inverse mapping behavior remains LinuxCNC source | Vendor byte sync, per-file source probes, `linuxcnc_kinematics_probe` | | Switchable 5-axis bridge kinematics | `src/emc/kinematics/5axiskins.c`, `switchkins.c`, `switchkins.h`, `userkfuncs.c`, plus `src/rtapi/rtapi_ctype.h` | Copy unchanged | HAL pin allocation, HAL component lifecycle, and RTAPI module metadata are standalone runtime edges; switchable 5-axis forward/inverse behavior remains LinuxCNC source | Vendor byte sync, per-file source probes, `linuxcnc_5axis_kinematics_probe` | diff --git a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_emc_status_probe.cpp b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_emc_status_probe.cpp index 8338117..9f36ca4 100644 --- a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_emc_status_probe.cpp +++ b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_emc_status_probe.cpp @@ -2,9 +2,6 @@ #include -static EMC_STAT standalone_emc_status; -EMC_STAT *emcStatus = &standalone_emc_status; - int main() { const bool default_units_visible = emcStatus->motion.traj.linearUnits == 1.0; diff --git a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_emc_status_runtime.cpp b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_emc_status_runtime.cpp new file mode 100644 index 0000000..3b56762 --- /dev/null +++ b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_emc_status_runtime.cpp @@ -0,0 +1,4 @@ +#include "nml_intf/emc.hh" + +static EMC_STAT standalone_emc_status; +EMC_STAT *emcStatus = &standalone_emc_status; diff --git a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_interp_init_harness.cpp b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_interp_init_harness.cpp index 66e3678..607402f 100644 --- a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_interp_init_harness.cpp +++ b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_interp_init_harness.cpp @@ -8,6 +8,7 @@ #include #include "canon_event_sink.hh" +#include "nml_intf/emc.hh" namespace { @@ -29,6 +30,7 @@ int main() const auto temp_dir = make_temp_dir(); std::filesystem::current_path(temp_dir); + emcStatus->motion.traj.linearUnits = 1.0; Interp interp; standalone::reset_canon_events(); @@ -44,6 +46,21 @@ int main() std::cout << "canon_event=" << event << "\n"; } + emcStatus->motion.traj.linearUnits = 1.0 / 25.4; + Interp inch_interp; + standalone::reset_canon_events(); + const int inch_rc = inch_interp.init(); + std::cout << "inch_init=" << inch_rc << "\n"; + std::cout << "inch_setup.length_units=" + << static_cast(inch_interp._setup.length_units) << "\n"; + std::cout << "inch_external_length_units=" + << GET_EXTERNAL_LENGTH_UNITS() << "\n"; + std::cout << "inch_canon_event_count=" << standalone::canon_events().size() << "\n"; + for (const auto &event : standalone::canon_events()) { + std::cout << "inch_canon_event=" << event << "\n"; + } + + emcStatus->motion.traj.linearUnits = 1.0; std::filesystem::remove_all(temp_dir); - return rc == INTERP_OK ? 0 : 1; + return (rc == INTERP_OK && inch_rc == INTERP_OK) ? 0 : 1; } diff --git a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_interp_minimal_runtime.cpp b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_interp_minimal_runtime.cpp index 20dde0d..1775fb5 100644 --- a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_interp_minimal_runtime.cpp +++ b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_interp_minimal_runtime.cpp @@ -13,6 +13,7 @@ #include "emc/rs274ngc/rs274ngc_return.hh" #include "canon_event_sink.hh" #include "linuxcnc_tool_adapter.hh" +#include "nml_intf/emc.hh" namespace standalone { @@ -448,8 +449,11 @@ void CANON_ERROR(const char *fmt, ...) double GET_EXTERNAL_FEED_RATE() { return 0.0; } int GET_EXTERNAL_FLOOD() { return 0; } -CANON_UNITS GET_EXTERNAL_LENGTH_UNIT_TYPE() { return CANON_UNITS_MM; } -double GET_EXTERNAL_LENGTH_UNITS() { return 1.0; } +CANON_UNITS GET_EXTERNAL_LENGTH_UNIT_TYPE() +{ + return (emcStatus->motion.traj.linearUnits > 0.5) ? CANON_UNITS_MM : CANON_UNITS_INCHES; +} +double GET_EXTERNAL_LENGTH_UNITS() { return emcStatus->motion.traj.linearUnits; } double GET_EXTERNAL_ANGLE_UNITS() { return 1.0; } int GET_EXTERNAL_MIST() { return 0; } CANON_MOTION_MODE GET_EXTERNAL_MOTION_CONTROL_MODE() { return CANON_EXACT_STOP; } diff --git a/wasm-port/tests/native/verify_native_probes.sh b/wasm-port/tests/native/verify_native_probes.sh index 9e35f57..e071131 100755 --- a/wasm-port/tests/native/verify_native_probes.sh +++ b/wasm-port/tests/native/verify_native_probes.sh @@ -265,6 +265,10 @@ grep -Fq "canon_event=SET_G5X_OFFSET index=1" "$INIT_HARNESS_STDOUT" grep -Fq "canon_event=SET_G92_OFFSET x=0 y=0 z=0" "$INIT_HARNESS_STDOUT" grep -Fq "canon_event=SET_XY_ROTATION rotation=0" "$INIT_HARNESS_STDOUT" grep -Fq "canon_event=SET_FEED_REFERENCE reference=2" "$INIT_HARNESS_STDOUT" +grep -Fq "inch_init=0" "$INIT_HARNESS_STDOUT" +grep -Fq "inch_setup.length_units=1" "$INIT_HARNESS_STDOUT" +grep -Fq "inch_external_length_units=0.0393701" "$INIT_HARNESS_STDOUT" +grep -Fq "inch_canon_event=USE_LENGTH_UNITS units=1" "$INIT_HARNESS_STDOUT" INDEXER_HARNESS_STDOUT="$BUILD_DIR/linuxcnc_indexer_harness.run.stdout.log" grep -Fq "execute=0" "$INDEXER_HARNESS_STDOUT" diff --git a/wasm-port/tools/build_native_probes.sh b/wasm-port/tools/build_native_probes.sh index 4b7ac6f..f0e810d 100755 --- a/wasm-port/tools/build_native_probes.sh +++ b/wasm-port/tools/build_native_probes.sh @@ -343,6 +343,7 @@ STATE_PROBE_SOURCES=( ) EMC_STATUS_PROBE_SOURCES=( + "$WRAP_DIR/linuxcnc_emc_status_runtime.cpp" "$WRAP_DIR/linuxcnc_emc_status_probe.cpp" ) @@ -611,6 +612,7 @@ INTERP_CORE_SOURCES=( "$VENDOR_DIR/src/emc/rs274ngc/interp_o_word.cc" "$VENDOR_DIR/src/emc/rs274ngc/rs274ngc_pre.cc" "$WRAP_DIR/linuxcnc_hal_adapter.cpp" + "$WRAP_DIR/linuxcnc_emc_status_runtime.cpp" "$WRAP_DIR/linuxcnc_interp_edge_stubs.cpp" "$WRAP_DIR/linuxcnc_runtime_state_stubs.cpp" "$WRAP_DIR/linuxcnc_tool_adapter.cpp"