#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" LINUXCNC_ROOT="${LINUXCNC_ROOT:-$ROOT_DIR/../linuxcnc}" UPSTREAM="$LINUXCNC_ROOT/src/emc/task/emccanon.cc" SUBSET_SRC="$ROOT_DIR/vendor/linuxcnc/src/emc/task/emccanon_wasm_subset.cc" SUBSET_HDR="$ROOT_DIR/vendor/linuxcnc/src/emc/task/emccanon_wasm_subset.hh" TASK_WRAPPER="$ROOT_DIR/runtime/core/linuxcnc_wrap/linuxcnc_task_hal_wasm.cpp" WASM_TEST="$ROOT_DIR/tests/wasm/node/verify_task_hal_wasm.mjs" MATRIX="$ROOT_DIR/working/04-任务矩阵.md" fail() { printf 'task_emccanon_spindle_tool_status=fail\n' printf 'task_emccanon_spindle_tool_error=%s\n' "$1" exit 1 } require_file() { local label="$1" local file="$2" [[ -f "$file" ]] || fail "$label missing: $file" printf 'task_emccanon_spindle_tool_%s=ok\n' "$label" } require_text() { local label="$1" local file="$2" local text="$3" grep -Fq "$text" "$file" || fail "$label missing" printf 'task_emccanon_spindle_tool_%s=ok\n' "$label" } require_file upstream "$UPSTREAM" require_file subset_source "$SUBSET_SRC" require_file subset_header "$SUBSET_HDR" require_file task_wrapper "$TASK_WRAPPER" require_file wasm_test "$WASM_TEST" require_file matrix "$MATRIX" for fn in \ SET_SPINDLE_SPEED \ START_SPINDLE_CLOCKWISE \ START_SPINDLE_COUNTERCLOCKWISE \ STOP_SPINDLE_TURNING \ SELECT_TOOL \ CHANGE_TOOL \ CHANGE_TOOL_NUMBER \ RELOAD_TOOLDATA do require_text "upstream_$fn" "$UPSTREAM" "$fn" done for msg in \ EMC_SPINDLE_SPEED \ EMC_SPINDLE_ON \ EMC_SPINDLE_OFF \ EMC_TOOL_PREPARE \ EMC_TOOL_LOAD \ EMC_TOOL_SET_NUMBER \ EMC_TOOL_LOAD_TOOL_TABLE do require_text "upstream_$msg" "$UPSTREAM" "$msg" done require_text upstream_interp_list "$UPSTREAM" "interp_list.append" require_text subset_spindle_type "$SUBSET_HDR" "LcEmcCanonSubsetSpindleCommand" require_text subset_tool_type "$SUBSET_HDR" "LcEmcCanonSubsetToolCommand" require_text subset_spindle_speed_decl "$SUBSET_HDR" "lc_emccanon_subset_set_spindle_speed" require_text subset_start_cw_decl "$SUBSET_HDR" "lc_emccanon_subset_start_spindle_clockwise" require_text subset_start_ccw_decl "$SUBSET_HDR" "lc_emccanon_subset_start_spindle_counterclockwise" require_text subset_stop_decl "$SUBSET_HDR" "lc_emccanon_subset_stop_spindle_turning" require_text subset_select_tool_decl "$SUBSET_HDR" "lc_emccanon_subset_select_tool" require_text subset_change_tool_decl "$SUBSET_HDR" "lc_emccanon_subset_change_tool" require_text subset_change_number_decl "$SUBSET_HDR" "lc_emccanon_subset_change_tool_number" require_text subset_reload_decl "$SUBSET_HDR" "lc_emccanon_subset_reload_tooldata" require_text subset_anchor_decl "$SUBSET_HDR" "lc_emccanon_subset_spindle_tool_anchor_list" require_text subset_anchor "$SUBSET_SRC" "EMC_SPINDLE_SPEED,EMC_SPINDLE_ON,EMC_SPINDLE_OFF" require_text subset_tool_anchor "$SUBSET_SRC" "EMC_TOOL_PREPARE,EMC_TOOL_LOAD,EMC_TOOL_SET_NUMBER,EMC_TOOL_LOAD_TOOL_TABLE,interp_list" require_text wrapper_spindle_count "$TASK_WRAPPER" "spindleCommandCount" require_text wrapper_spindle_append "$TASK_WRAPPER" "spindleAppendCount" require_text wrapper_tool_count "$TASK_WRAPPER" "toolCommandCount" require_text wrapper_tool_append "$TASK_WRAPPER" "toolAppendCount" require_text wrapper_exact_m_code "$TASK_WRAPPER" "line_has_m_code" require_text wrapper_m3 "$TASK_WRAPPER" "line_has_m_code(line, 3)" require_text wrapper_m61 "$TASK_WRAPPER" "line_has_m_code(line, 61)" require_text wrapper_anchor "$TASK_WRAPPER" "lc_emccanon_subset_spindle_tool_anchor_list" require_text wasm_test_status "$WASM_TEST" "emccanon_spindle_tool_status=ok" require_text wasm_test_s_m3 "$WASM_TEST" "S1200 M3" require_text wasm_test_m5 "$WASM_TEST" "M5" require_text wasm_test_t_m6 "$WASM_TEST" "T7 M6" require_text wasm_test_m61 "$WASM_TEST" "M61 Q8" require_text wasm_test_spindle_count "$WASM_TEST" "spindleCommandCount" require_text wasm_test_tool_count "$WASM_TEST" "toolCommandCount" require_text wasm_test_anchor "$WASM_TEST" "spindleToolAnchors" require_text matrix_t044_done "$MATRIX" '| T-044 | `emccanon.cc` spindle/tool command 子集 | 完成 |' require_text matrix_t045_done "$MATRIX" '| T-045 | `emccanon.cc` motion output/switchkins 子集 | 完成 |' printf 'task_emccanon_spindle_tool_status=ok\n'