diff --git a/wasm-port/docs/compatibility-validation.md b/wasm-port/docs/compatibility-validation.md index f317e28..a2690ec 100644 --- a/wasm-port/docs/compatibility-validation.md +++ b/wasm-port/docs/compatibility-validation.md @@ -56,7 +56,7 @@ The validation fails if: | `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 and reads metric/inch machine units through the standalone event/status boundary. | +| `linuxcnc_interp_init_harness` | Validates vendored LinuxCNC `Interp::init()` emits canonical initialization boundaries, reads metric/inch machine units, and synchronizes current/selected tool slots through standalone status adapters. | | `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. | @@ -140,7 +140,8 @@ resolution. `state_tag_motion` now compares its motion events with upstream `rs274`, while `UPDATE_TAG` events remain a standalone state-tag capture boundary. `tool_semantics` now compares T/M6/G43/G49 canonical events with upstream `rs274`; M61 current-pocket host-state behavior remains covered by the -standalone fixture expectation. +standalone fixture expectation, and `Interp::synch()` current/selected tool +slot reads are covered by the native init harness. The kinematics probes currently cover LinuxCNC identity/trivial kinematics, the switchable `5axiskins` XYZBCW bridge-mill model, TRT `xyzac`/`xyzbc` diff --git a/wasm-port/docs/drift-report.md b/wasm-port/docs/drift-report.md index 72faf18..5a52076 100644 --- a/wasm-port/docs/drift-report.md +++ b/wasm-port/docs/drift-report.md @@ -27,6 +27,7 @@ semantic rewrites: | INI lookup | Standalone INI adapter around vendored LinuxCNC INI parser behavior. | | Canonical output | Canonical calls are captured as test events instead of driving hardware. | | Tool-data reload | LinuxCNC `RELOAD_TOOLDATA` is captured as a canonical test event; browser/native tool-table reload plumbing remains a future host/runtime adapter. | +| Tool slot status | Standalone tool adapter state supplies `GET_EXTERNAL_TOOL_SLOT()` and `GET_EXTERNAL_SELECTED_TOOL_SLOT()` for vendored `Interp::synch()`; `linuxcnc_interp_init_harness` guards current/selected slot synchronization. | | Interpreter state tags | LinuxCNC `UPDATE_TAG` callbacks are captured from the state tags packed by vendored interpreter code; standalone code does not derive modal state. | | Rotary indexer lock state | LinuxCNC `UNLOCK_ROTARY` and `LOCK_ROTARY` callbacks are captured from the vendored single-axis indexer path; standalone code does not implement rotary-indexing semantics. | | File flush | LinuxCNC `FINISH` is captured as a canonical test event on the vendored `%`-delimited file-reading path. | diff --git a/wasm-port/docs/source-reuse-map.md b/wasm-port/docs/source-reuse-map.md index 866da6f..39c08f5 100644 --- a/wasm-port/docs/source-reuse-map.md +++ b/wasm-port/docs/source-reuse-map.md @@ -44,7 +44,7 @@ Current validation is intentionally mechanical: | Posemath | `src/libnml/posemath/posemath.cc`, `_posemath.c`, `gomath.c`, `sincos.c`, and matching headers | Copy unchanged | `gomath.c` is compiled as C; `rtapi.h` shim is C/C++ compatible for this boundary | Vendor byte sync, per-file source probes, TP probe | | RS274 interpreter state and parser | `src/emc/rs274ngc/modal_state.*`, `interp_internal.*`, `interp_read.cc`, `interp_check.cc`, `interp_execute.cc`, `interp_find.cc`, `interp_array.cc`, `interp_queue.*`, `rs274ngc*`, `units.h` | Copy unchanged | Python/remap/runtime edges are isolated in standalone wrappers and shims; parser and execution logic remain LinuxCNC source | Vendor byte sync, per-file source probes, interpreter harness fixtures | | RS274 conversion semantics | `src/emc/rs274ngc/interp_convert.cc`, `interp_arc.cc`, `interp_inverse.cc`, `interp_cycles.cc`, `interp_g7x.cc`, `interp_o_word.cc`, `interp_write.cc` | Copy unchanged | Canonical calls are captured by standalone event sink functions; conversion behavior stays in vendored LinuxCNC files | Vendor byte sync, per-file source probes, canonical fixture suite, no standalone `Interp::convert_g()` guard | -| Named parameters | `src/emc/rs274ngc/interp_namedparams.cc`, related interpreter headers | Copy unchanged | `_ini[...]` and `_hal[...]` resolve through standalone INI/HAL adapters while lookup order stays LinuxCNC-derived | Vendor byte sync, source probe, `linuxcnc_namedparam_harness` | +| Named parameters and tool slot status | `src/emc/rs274ngc/interp_namedparams.cc`, related interpreter headers | Copy unchanged | `_ini[...]` and `_hal[...]` resolve through standalone INI/HAL adapters while lookup order stays LinuxCNC-derived; current/selected tool slot reads for vendored `Interp::synch()` come from the standalone tool adapter | Vendor byte sync, source probe, `linuxcnc_namedparam_harness`, `linuxcnc_interp_init_harness` | | Dynamic interpreter base | `src/emc/rs274ngc/interp_base.*` | Copy unchanged | `interp_base.cc` source probe uses standalone `EMC2_HOME` compile-time path boundary for LinuxCNC dynamic interpreter lookup | Vendor byte sync, `linuxcnc_interp_base_source_probe` | ## Dependency Matrix 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 607402f..a13b8a3 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 "linuxcnc_tool_adapter.hh" #include "nml_intf/emc.hh" namespace { @@ -31,6 +32,7 @@ int main() std::filesystem::current_path(temp_dir); emcStatus->motion.traj.linearUnits = 1.0; + standalone::reset_tool_adapter(); Interp interp; standalone::reset_canon_events(); @@ -47,6 +49,7 @@ int main() } emcStatus->motion.traj.linearUnits = 1.0 / 25.4; + standalone::reset_tool_adapter(); Interp inch_interp; standalone::reset_canon_events(); const int inch_rc = inch_interp.init(); @@ -60,7 +63,24 @@ int main() std::cout << "inch_canon_event=" << event << "\n"; } + standalone::reset_tool_adapter(); + CANON_TOOL_TABLE tool = standalone::tool_entry_init(); + tool.toolno = 2; + tool.pocketno = 2; + standalone::set_tool_entry(2, tool); + standalone::select_tool(2); + standalone::change_selected_tool(); + + Interp synch_interp; + const int synch_rc = synch_interp.synch(); + std::cout << "synch=" << synch_rc << "\n"; + std::cout << "synch.current_pocket=" << synch_interp._setup.current_pocket << "\n"; + std::cout << "synch.selected_pocket=" << synch_interp._setup.selected_pocket << "\n"; + std::cout << "synch.tool_0=" << synch_interp._setup.tool_table[0].toolno << "\n"; + std::cout << "synch.tool_2=" << synch_interp._setup.tool_table[2].toolno << "\n"; + emcStatus->motion.traj.linearUnits = 1.0; + standalone::reset_tool_adapter(); std::filesystem::remove_all(temp_dir); - return (rc == INTERP_OK && inch_rc == INTERP_OK) ? 0 : 1; + return (rc == INTERP_OK && inch_rc == INTERP_OK && synch_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 1775fb5..fd44400 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 @@ -505,8 +505,8 @@ double GET_EXTERNAL_TOOL_LENGTH_COFFSET() { return 0.0; } double GET_EXTERNAL_TOOL_LENGTH_UOFFSET() { return 0.0; } double GET_EXTERNAL_TOOL_LENGTH_VOFFSET() { return 0.0; } double GET_EXTERNAL_TOOL_LENGTH_WOFFSET() { return 0.0; } -int GET_EXTERNAL_TOOL_SLOT() { return 0; } -int GET_EXTERNAL_SELECTED_TOOL_SLOT() { return -1; } +int GET_EXTERNAL_TOOL_SLOT() { return standalone::current_tool_index(); } +int GET_EXTERNAL_SELECTED_TOOL_SLOT() { return standalone::selected_tool_index(); } CANON_TOOL_TABLE GET_EXTERNAL_TOOL_TABLE(int index) { CANON_TOOL_TABLE tool = standalone::tool_entry_init(); diff --git a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_tool_adapter.cpp b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_tool_adapter.cpp index 9f2bdbe..7a0ec98 100644 --- a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_tool_adapter.cpp +++ b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_tool_adapter.cpp @@ -10,12 +10,18 @@ std::array &tool_table() return tools; } -int &selected_tool_index() +int &selected_tool_index_ref() { static int index = -1; return index; } +int ¤t_tool_index_ref() +{ + static int index = 0; + return index; +} + CANON_TOOL_TABLE empty_tool() { CANON_TOOL_TABLE tool{}; @@ -30,7 +36,8 @@ namespace standalone { void reset_tool_adapter() { - selected_tool_index() = -1; + selected_tool_index_ref() = -1; + current_tool_index_ref() = 0; auto &tools = tool_table(); for (int index = 0; index < CANON_POCKETS_MAX; ++index) { tools[index] = empty_tool(); @@ -76,9 +83,19 @@ int get_tool_entry(CANON_TOOL_TABLE *tool, int index) return 0; } +int current_tool_index() +{ + return current_tool_index_ref(); +} + +int selected_tool_index() +{ + return selected_tool_index_ref(); +} + void select_tool(int toolno) { - selected_tool_index() = find_tool_index_for_tool(toolno); + selected_tool_index_ref() = find_tool_index_for_tool(toolno); } void change_tool_number(int index) @@ -91,11 +108,12 @@ void change_tool_number(int index) CANON_TOOL_TABLE spindle_tool = tools[index]; spindle_tool.pocketno = 0; tools[0] = spindle_tool; + current_tool_index_ref() = index; } void change_selected_tool() { - change_tool_number(selected_tool_index()); + change_tool_number(selected_tool_index_ref()); } } // namespace standalone diff --git a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_tool_adapter.hh b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_tool_adapter.hh index 9c89d92..831a058 100644 --- a/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_tool_adapter.hh +++ b/wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_tool_adapter.hh @@ -9,6 +9,8 @@ void set_tool_entry(int index, const CANON_TOOL_TABLE &tool); CANON_TOOL_TABLE tool_entry_init(); int find_tool_index_for_tool(int toolno); int get_tool_entry(CANON_TOOL_TABLE *tool, int index); +int current_tool_index(); +int selected_tool_index(); void select_tool(int toolno); void change_selected_tool(); void change_tool_number(int index); diff --git a/wasm-port/tests/native/verify_native_probes.sh b/wasm-port/tests/native/verify_native_probes.sh index e071131..cd21c00 100755 --- a/wasm-port/tests/native/verify_native_probes.sh +++ b/wasm-port/tests/native/verify_native_probes.sh @@ -269,6 +269,11 @@ 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" +grep -Fq "synch=0" "$INIT_HARNESS_STDOUT" +grep -Fq "synch.current_pocket=2" "$INIT_HARNESS_STDOUT" +grep -Fq "synch.selected_pocket=2" "$INIT_HARNESS_STDOUT" +grep -Fq "synch.tool_0=2" "$INIT_HARNESS_STDOUT" +grep -Fq "synch.tool_2=2" "$INIT_HARNESS_STDOUT" INDEXER_HARNESS_STDOUT="$BUILD_DIR/linuxcnc_indexer_harness.run.stdout.log" grep -Fq "execute=0" "$INDEXER_HARNESS_STDOUT"