From e875496fe0289c7ba05bdbf676d490571f500c12 Mon Sep 17 00:00:00 2001 From: cnc Date: Tue, 2 Jun 2026 19:36:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E6=8C=89=20align-linuxcnc=20?= =?UTF-8?q?=E7=BA=A6=E6=9D=9F=EF=BC=9A=E8=A1=A5=20convert=5Fm=20=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=94=99=E8=AF=AF=E6=BA=90=E7=A0=81=E8=A6=86=E7=9B=96?= =?UTF-8?q?=EF=BC=8C=E6=B5=8B=E8=AF=95=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/linuxcnc-porting.md | 6 ++-- test-linuxcnc-source-link.sh | 29 +++++++++++++++++++ tests/gcode/linuxcnc_m19_zero_q_error.ngc | 3 ++ tests/gcode/linuxcnc_m61_negative_q_error.ngc | 3 ++ .../linuxcnc_m62_missing_p_word_error.ngc | 3 ++ .../linuxcnc_m63_missing_p_word_error.ngc | 3 ++ .../linuxcnc_m64_missing_p_word_error.ngc | 3 ++ .../linuxcnc_m65_missing_p_word_error.ngc | 3 ++ .../gcode/linuxcnc_m66_analog_wait_error.ngc | 3 ++ .../gcode/linuxcnc_m66_both_inputs_error.ngc | 3 ++ .../linuxcnc_m66_missing_input_error.ngc | 3 ++ .../gcode/linuxcnc_m66_zero_timeout_error.ngc | 3 ++ .../linuxcnc_m67_missing_e_word_error.ngc | 3 ++ .../linuxcnc_m68_missing_e_word_error.ngc | 3 ++ 14 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 tests/gcode/linuxcnc_m19_zero_q_error.ngc create mode 100644 tests/gcode/linuxcnc_m61_negative_q_error.ngc create mode 100644 tests/gcode/linuxcnc_m62_missing_p_word_error.ngc create mode 100644 tests/gcode/linuxcnc_m63_missing_p_word_error.ngc create mode 100644 tests/gcode/linuxcnc_m64_missing_p_word_error.ngc create mode 100644 tests/gcode/linuxcnc_m65_missing_p_word_error.ngc create mode 100644 tests/gcode/linuxcnc_m66_analog_wait_error.ngc create mode 100644 tests/gcode/linuxcnc_m66_both_inputs_error.ngc create mode 100644 tests/gcode/linuxcnc_m66_missing_input_error.ngc create mode 100644 tests/gcode/linuxcnc_m66_zero_timeout_error.ngc create mode 100644 tests/gcode/linuxcnc_m67_missing_e_word_error.ngc create mode 100644 tests/gcode/linuxcnc_m68_missing_e_word_error.ngc diff --git a/docs/linuxcnc-porting.md b/docs/linuxcnc-porting.md index 1a45e35..e9a8493 100644 --- a/docs/linuxcnc-porting.md +++ b/docs/linuxcnc-porting.md @@ -197,12 +197,12 @@ This matrix tracks LinuxCNC feature coverage for the web/WASM simulator. A featu | Tool length offset `G43/G43.1/G43.2/G49` | covered with nonzero tool-table offset, dynamic replacement, additive axis offsets, `G43.2 H...`, and clear through LinuxCNC native/source backends | `tests/gcode/linuxcnc_tool_length.ngc`, `tests/gcode/linuxcnc_dynamic_tool_length.ngc` | | RTCP controls `G43.4/G43.5/G49` | covered as simulator-owned control lines | `tests/gcode/linuxcnc_rtcp_controls.ngc` | | Kinematics switch `M428/M429/M430` | covered as simulator-owned control lines | `tests/gcode/linuxcnc_rtcp_controls.ngc` | -| Spindle, coolant, program stops, and current tool number `M3/M4/M5`, `M7/M8/M9`, `M0/M1/M60/M30`, `M61 Q...` | covered through LinuxCNC native/source backends | `tests/gcode/linuxcnc_spindle_direction.ngc`, `tests/gcode/linuxcnc_coolant.ngc`, `tests/gcode/linuxcnc_program_stops.ngc`, `tests/gcode/linuxcnc_tool_number.ngc` | +| Spindle, coolant, program stops, and current tool number `M3/M4/M5`, `M7/M8/M9`, `M0/M1/M60/M30`, `M61 Q...` | covered through LinuxCNC native/source backends, including source-linked `convert_m()` rejection of negative `M61 Q` | `tests/gcode/linuxcnc_spindle_direction.ngc`, `tests/gcode/linuxcnc_coolant.ngc`, `tests/gcode/linuxcnc_program_stops.ngc`, `tests/gcode/linuxcnc_tool_number.ngc`, `tests/gcode/linuxcnc_m61_negative_q_error.ngc` | | Spindle speed mode `G96/G97` | covered with Canon `SET_SPINDLE_MODE` preserved as mode state events, including `G96 D...` max-RPM value | `tests/gcode/linuxcnc_spindle_modes.ngc` | -| Spindle orientation `M19 R... P... Q...` | covered with Canon `ORIENT_SPINDLE` and `WAIT_SPINDLE_ORIENT_COMPLETE` preserved as temporary mode state events | `tests/gcode/linuxcnc_spindle_orient.ngc` | +| Spindle orientation `M19 R... P... Q...` | covered with Canon `ORIENT_SPINDLE` and `WAIT_SPINDLE_ORIENT_COMPLETE` preserved as temporary mode state events, including source-linked `convert_m()` rejection of nonpositive `Q` waits | `tests/gcode/linuxcnc_spindle_orient.ngc`, `tests/gcode/linuxcnc_m19_zero_q_error.ngc` | | Spindle-synchronized feed and threading `G33/G33.1/G76` | covered through smoke, LinuxCNC native, and source-linked paths with Canon `START_SPEED_FEED_SYNCH`/`STOP_SPEED_FEED_SYNCH` preserved, rigid-tap line numbers normalized, and G76 multi-pass threading smoke-covered | `tests/gcode/linuxcnc_threading_sync.ngc`, `tests/gcode/linuxcnc_threading_cycle.ngc`, smoke API regression | | Lathe diameter/radius mode `G7/G8` | covered through LinuxCNC native/source backends for same-block X scaling, `G76` I/J/K threading geometry interaction, and `#<_lathe_diameter_mode>`/`#<_lathe_radius_mode>` readonly named-parameter state | `tests/gcode/linuxcnc_lathe_diameter_mode.ngc`, `tests/gcode/linuxcnc_lathe_diameter_g76.ngc` | -| Digital/analog I/O `M62`-`M68` | covered with Canon digital output, analog output, and input wait callbacks preserved as temporary state events | `tests/gcode/linuxcnc_io_controls.ngc` | +| Digital/analog I/O `M62`-`M68` | covered with Canon digital output, analog output, and input wait callbacks preserved as temporary state events, including source-linked `convert_m()` validation for required `P`/`E`, M66 input selection, M66 wait timeout, and analog wait restrictions | `tests/gcode/linuxcnc_io_controls.ngc`, `tests/gcode/linuxcnc_m62_missing_p_word_error.ngc`, `tests/gcode/linuxcnc_m63_missing_p_word_error.ngc`, `tests/gcode/linuxcnc_m64_missing_p_word_error.ngc`, `tests/gcode/linuxcnc_m65_missing_p_word_error.ngc`, `tests/gcode/linuxcnc_m66_missing_input_error.ngc`, `tests/gcode/linuxcnc_m66_both_inputs_error.ngc`, `tests/gcode/linuxcnc_m66_zero_timeout_error.ngc`, `tests/gcode/linuxcnc_m66_analog_wait_error.ngc`, `tests/gcode/linuxcnc_m67_missing_e_word_error.ngc`, `tests/gcode/linuxcnc_m68_missing_e_word_error.ngc` | | Override controls `M48`-`M53` | covered with Canon feed override, spindle speed override, adaptive feed, and feed hold callbacks preserved as temporary state events | `tests/gcode/linuxcnc_override_controls.ngc` | | Modal state save/restore `M70`-`M73` | covered for main-program save/invalidate/restore plus O-word subroutine autorestore in smoke parser, with native/source regressions checking restored distance mode, units, and XY plane motion | `tests/gcode/linuxcnc_modal_state.ngc`, `tests/gcode/linuxcnc_modal_autorestore.ngc` | | LinuxCNC read-only named parameters | common modal/unit/feed/spindle reads are covered through LinuxCNC native/source backends, with additional ccomp/spindle-mode readonly reads source-linked | `tests/gcode/linuxcnc_readonly_named_parameters.ngc`, `tests/gcode/linuxcnc_readonly_named_parameters_extra.ngc`, `tests/gcode/linuxcnc_lathe_diameter_mode.ngc` | diff --git a/test-linuxcnc-source-link.sh b/test-linuxcnc-source-link.sh index 7fd0fd0..be20565 100755 --- a/test-linuxcnc-source-link.sh +++ b/test-linuxcnc-source-link.sh @@ -199,6 +199,35 @@ CNC_SIM_RS274_VAR="$var_file" \ CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_io_controls.ngc \ >"$output_dir/cnc_sim_linuxcnc_source_io_controls.json" +# Source basis: LinuxCNC src/emc/rs274ngc/interp_convert.cc convert_m() +# validates M62-M68 input/output words, M61 Q tool numbers, and M19 Q wait +# values before issuing Canon output/input, tool, or spindle-orient calls. +convert_m_error_cases=( + "linuxcnc_m62_missing_p_word_error|No valid P word with M62" + "linuxcnc_m63_missing_p_word_error|No valid P word with M63" + "linuxcnc_m64_missing_p_word_error|No valid P word with M64" + "linuxcnc_m65_missing_p_word_error|No valid P word with M65" + "linuxcnc_m66_missing_input_error|Need to have either a valid P or a valid E word with M66" + "linuxcnc_m66_both_inputs_error|Invalid to select both a digital and an analog input with M66" + "linuxcnc_m66_zero_timeout_error|Zero timeout with wait type != immediate return" + "linuxcnc_m66_analog_wait_error|Can't select analog input with wait type != immediate return" + "linuxcnc_m67_missing_e_word_error|Invalid analog index with M67" + "linuxcnc_m68_missing_e_word_error|Invalid analog index with M68" + "linuxcnc_m19_zero_q_error|Q word with M19 requires a value > 0" + "linuxcnc_m61_negative_q_error|Need non-negative Q-word to specify tool number with M61" +) +for case in "${convert_m_error_cases[@]}"; do + fixture=${case%%|*} + expected=${case#*|} + if CNC_SIM_RS274_VAR="$var_file" \ + "$build_dir/linuxcnc_rs274_source_dump" "tests/gcode/$fixture.ngc" \ + >"$output_dir/cnc_sim_linuxcnc_source_$fixture.json" \ + 2>"$output_dir/cnc_sim_linuxcnc_source_$fixture.err"; then + echo "expected $fixture.ngc to fail" >&2 + exit 1 + fi + grep -Fq "$expected" "$output_dir/cnc_sim_linuxcnc_source_$fixture.err" +done CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_override_controls.ngc \ >"$output_dir/cnc_sim_linuxcnc_source_override_controls.json" diff --git a/tests/gcode/linuxcnc_m19_zero_q_error.ngc b/tests/gcode/linuxcnc_m19_zero_q_error.ngc new file mode 100644 index 0000000..87399fc --- /dev/null +++ b/tests/gcode/linuxcnc_m19_zero_q_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M19 R45 Q0 +M30 diff --git a/tests/gcode/linuxcnc_m61_negative_q_error.ngc b/tests/gcode/linuxcnc_m61_negative_q_error.ngc new file mode 100644 index 0000000..ac0f96f --- /dev/null +++ b/tests/gcode/linuxcnc_m61_negative_q_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M61 Q-1 +M30 diff --git a/tests/gcode/linuxcnc_m62_missing_p_word_error.ngc b/tests/gcode/linuxcnc_m62_missing_p_word_error.ngc new file mode 100644 index 0000000..125b133 --- /dev/null +++ b/tests/gcode/linuxcnc_m62_missing_p_word_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M62 +M30 diff --git a/tests/gcode/linuxcnc_m63_missing_p_word_error.ngc b/tests/gcode/linuxcnc_m63_missing_p_word_error.ngc new file mode 100644 index 0000000..646f78d --- /dev/null +++ b/tests/gcode/linuxcnc_m63_missing_p_word_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M63 +M30 diff --git a/tests/gcode/linuxcnc_m64_missing_p_word_error.ngc b/tests/gcode/linuxcnc_m64_missing_p_word_error.ngc new file mode 100644 index 0000000..745ef8e --- /dev/null +++ b/tests/gcode/linuxcnc_m64_missing_p_word_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M64 +M30 diff --git a/tests/gcode/linuxcnc_m65_missing_p_word_error.ngc b/tests/gcode/linuxcnc_m65_missing_p_word_error.ngc new file mode 100644 index 0000000..39b9552 --- /dev/null +++ b/tests/gcode/linuxcnc_m65_missing_p_word_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M65 +M30 diff --git a/tests/gcode/linuxcnc_m66_analog_wait_error.ngc b/tests/gcode/linuxcnc_m66_analog_wait_error.ngc new file mode 100644 index 0000000..5c512be --- /dev/null +++ b/tests/gcode/linuxcnc_m66_analog_wait_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M66 E0 L3 Q1 +M30 diff --git a/tests/gcode/linuxcnc_m66_both_inputs_error.ngc b/tests/gcode/linuxcnc_m66_both_inputs_error.ngc new file mode 100644 index 0000000..291506b --- /dev/null +++ b/tests/gcode/linuxcnc_m66_both_inputs_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M66 P0 E0 L0 +M30 diff --git a/tests/gcode/linuxcnc_m66_missing_input_error.ngc b/tests/gcode/linuxcnc_m66_missing_input_error.ngc new file mode 100644 index 0000000..60bbe2f --- /dev/null +++ b/tests/gcode/linuxcnc_m66_missing_input_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M66 L0 +M30 diff --git a/tests/gcode/linuxcnc_m66_zero_timeout_error.ngc b/tests/gcode/linuxcnc_m66_zero_timeout_error.ngc new file mode 100644 index 0000000..7559310 --- /dev/null +++ b/tests/gcode/linuxcnc_m66_zero_timeout_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M66 P0 L3 Q0 +M30 diff --git a/tests/gcode/linuxcnc_m67_missing_e_word_error.ngc b/tests/gcode/linuxcnc_m67_missing_e_word_error.ngc new file mode 100644 index 0000000..c18447d --- /dev/null +++ b/tests/gcode/linuxcnc_m67_missing_e_word_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M67 Q1.25 +M30 diff --git a/tests/gcode/linuxcnc_m68_missing_e_word_error.ngc b/tests/gcode/linuxcnc_m68_missing_e_word_error.ngc new file mode 100644 index 0000000..40a4df6 --- /dev/null +++ b/tests/gcode/linuxcnc_m68_missing_e_word_error.ngc @@ -0,0 +1,3 @@ +G21 G90 G17 +M68 Q2.5 +M30