按建议,继续完成后续工作

结论:将 Interp::synch() 当前/选中工具槽位读取接入 standalone tool adapter,并补充 native 验证。
This commit is contained in:
2026-06-08 00:02:15 +08:00
parent 335ab61a61
commit bdbe246a82
8 changed files with 57 additions and 10 deletions

View File

@@ -56,7 +56,7 @@ The validation fails if:
| `linuxcnc_namedparam_harness` | Validates LinuxCNC named parameter behavior, `_ini[...]`, and `_hal[...]` adapter resolution. | | `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_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_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_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_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. | | `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 `rs274`, while `UPDATE_TAG` events remain a standalone state-tag capture
boundary. `tool_semantics` now compares T/M6/G43/G49 canonical events with boundary. `tool_semantics` now compares T/M6/G43/G49 canonical events with
upstream `rs274`; M61 current-pocket host-state behavior remains covered by the 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 The kinematics probes currently cover LinuxCNC identity/trivial kinematics, the
switchable `5axiskins` XYZBCW bridge-mill model, TRT `xyzac`/`xyzbc` switchable `5axiskins` XYZBCW bridge-mill model, TRT `xyzac`/`xyzbc`

View File

@@ -27,6 +27,7 @@ semantic rewrites:
| INI lookup | Standalone INI adapter around vendored LinuxCNC INI parser behavior. | | INI lookup | Standalone INI adapter around vendored LinuxCNC INI parser behavior. |
| Canonical output | Canonical calls are captured as test events instead of driving hardware. | | 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-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. | | 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. | | 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. | | File flush | LinuxCNC `FINISH` is captured as a canonical test event on the vendored `%`-delimited file-reading path. |

View File

@@ -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 | | 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 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 | | 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` | | 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 ## Dependency Matrix

View File

@@ -8,6 +8,7 @@
#include <unistd.h> #include <unistd.h>
#include "canon_event_sink.hh" #include "canon_event_sink.hh"
#include "linuxcnc_tool_adapter.hh"
#include "nml_intf/emc.hh" #include "nml_intf/emc.hh"
namespace { namespace {
@@ -31,6 +32,7 @@ int main()
std::filesystem::current_path(temp_dir); std::filesystem::current_path(temp_dir);
emcStatus->motion.traj.linearUnits = 1.0; emcStatus->motion.traj.linearUnits = 1.0;
standalone::reset_tool_adapter();
Interp interp; Interp interp;
standalone::reset_canon_events(); standalone::reset_canon_events();
@@ -47,6 +49,7 @@ int main()
} }
emcStatus->motion.traj.linearUnits = 1.0 / 25.4; emcStatus->motion.traj.linearUnits = 1.0 / 25.4;
standalone::reset_tool_adapter();
Interp inch_interp; Interp inch_interp;
standalone::reset_canon_events(); standalone::reset_canon_events();
const int inch_rc = inch_interp.init(); const int inch_rc = inch_interp.init();
@@ -60,7 +63,24 @@ int main()
std::cout << "inch_canon_event=" << event << "\n"; 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; emcStatus->motion.traj.linearUnits = 1.0;
standalone::reset_tool_adapter();
std::filesystem::remove_all(temp_dir); 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;
} }

View File

@@ -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_UOFFSET() { return 0.0; }
double GET_EXTERNAL_TOOL_LENGTH_VOFFSET() { return 0.0; } double GET_EXTERNAL_TOOL_LENGTH_VOFFSET() { return 0.0; }
double GET_EXTERNAL_TOOL_LENGTH_WOFFSET() { return 0.0; } double GET_EXTERNAL_TOOL_LENGTH_WOFFSET() { return 0.0; }
int GET_EXTERNAL_TOOL_SLOT() { return 0; } int GET_EXTERNAL_TOOL_SLOT() { return standalone::current_tool_index(); }
int GET_EXTERNAL_SELECTED_TOOL_SLOT() { return -1; } int GET_EXTERNAL_SELECTED_TOOL_SLOT() { return standalone::selected_tool_index(); }
CANON_TOOL_TABLE GET_EXTERNAL_TOOL_TABLE(int index) CANON_TOOL_TABLE GET_EXTERNAL_TOOL_TABLE(int index)
{ {
CANON_TOOL_TABLE tool = standalone::tool_entry_init(); CANON_TOOL_TABLE tool = standalone::tool_entry_init();

View File

@@ -10,12 +10,18 @@ std::array<CANON_TOOL_TABLE, CANON_POCKETS_MAX> &tool_table()
return tools; return tools;
} }
int &selected_tool_index() int &selected_tool_index_ref()
{ {
static int index = -1; static int index = -1;
return index; return index;
} }
int &current_tool_index_ref()
{
static int index = 0;
return index;
}
CANON_TOOL_TABLE empty_tool() CANON_TOOL_TABLE empty_tool()
{ {
CANON_TOOL_TABLE tool{}; CANON_TOOL_TABLE tool{};
@@ -30,7 +36,8 @@ namespace standalone {
void reset_tool_adapter() void reset_tool_adapter()
{ {
selected_tool_index() = -1; selected_tool_index_ref() = -1;
current_tool_index_ref() = 0;
auto &tools = tool_table(); auto &tools = tool_table();
for (int index = 0; index < CANON_POCKETS_MAX; ++index) { for (int index = 0; index < CANON_POCKETS_MAX; ++index) {
tools[index] = empty_tool(); tools[index] = empty_tool();
@@ -76,9 +83,19 @@ int get_tool_entry(CANON_TOOL_TABLE *tool, int index)
return 0; 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) 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) void change_tool_number(int index)
@@ -91,11 +108,12 @@ void change_tool_number(int index)
CANON_TOOL_TABLE spindle_tool = tools[index]; CANON_TOOL_TABLE spindle_tool = tools[index];
spindle_tool.pocketno = 0; spindle_tool.pocketno = 0;
tools[0] = spindle_tool; tools[0] = spindle_tool;
current_tool_index_ref() = index;
} }
void change_selected_tool() void change_selected_tool()
{ {
change_tool_number(selected_tool_index()); change_tool_number(selected_tool_index_ref());
} }
} // namespace standalone } // namespace standalone

View File

@@ -9,6 +9,8 @@ void set_tool_entry(int index, const CANON_TOOL_TABLE &tool);
CANON_TOOL_TABLE tool_entry_init(); CANON_TOOL_TABLE tool_entry_init();
int find_tool_index_for_tool(int toolno); int find_tool_index_for_tool(int toolno);
int get_tool_entry(CANON_TOOL_TABLE *tool, int index); int get_tool_entry(CANON_TOOL_TABLE *tool, int index);
int current_tool_index();
int selected_tool_index();
void select_tool(int toolno); void select_tool(int toolno);
void change_selected_tool(); void change_selected_tool();
void change_tool_number(int index); void change_tool_number(int index);

View File

@@ -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_setup.length_units=1" "$INIT_HARNESS_STDOUT"
grep -Fq "inch_external_length_units=0.0393701" "$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 "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" INDEXER_HARNESS_STDOUT="$BUILD_DIR/linuxcnc_indexer_harness.run.stdout.log"
grep -Fq "execute=0" "$INDEXER_HARNESS_STDOUT" grep -Fq "execute=0" "$INDEXER_HARNESS_STDOUT"