From 71c61fca84c22e267d2e5732620285485932f30f Mon Sep 17 00:00:00 2001 From: cnc Date: Fri, 5 Jun 2026 22:40:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E9=BD=90=20tooldata=20=E9=9D=9E?= =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E5=90=8C=E6=AD=A5=20probe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tooldata/tooldata_common_probe_main.cc | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/core/wasm_shims/tooldata/tooldata_common_probe_main.cc b/core/wasm_shims/tooldata/tooldata_common_probe_main.cc index 4b06605..2d5b9eb 100644 --- a/core/wasm_shims/tooldata/tooldata_common_probe_main.cc +++ b/core/wasm_shims/tooldata/tooldata_common_probe_main.cc @@ -89,6 +89,42 @@ int main() { return 9; } + tooldata_init(false); + std::string nonrandom_path_template = make_temp_template("cnc_tooldata_common_nonrandom_probe_XXXXXX"); + std::vector nonrandom_path(nonrandom_path_template.begin(), nonrandom_path_template.end()); + nonrandom_path.push_back('\0'); + const int nonrandom_fd = mkstemp(nonrandom_path.data()); + if (nonrandom_fd < 0) { + return 16; + } + FILE *nonrandom_fp = fdopen(nonrandom_fd, "w"); + if (!nonrandom_fp) { + close(nonrandom_fd); + std::remove(nonrandom_path.data()); + return 17; + } + std::fputs("T-1 P5 Z4.25\n", nonrandom_fp); + std::fclose(nonrandom_fp); + + if (tooldata_load(nonrandom_path.data()) != 0) { + std::remove(nonrandom_path.data()); + return 18; + } + std::remove(nonrandom_path.data()); + + // LinuxCNC source basis: src/emc/tooldata/tooldata_common.cc + // tooldata_load() mirrors a matching nonrandom table entry into spindle + // pocket 0 after tooldata_read_entry() assigns fake pocket indices. + CANON_TOOL_TABLE nonrandom_spindle = tooldata_entry_init(); + if (tooldata_get(&nonrandom_spindle, 0) != IDX_OK) { + return 19; + } + if (nonrandom_spindle.toolno != -1 || nonrandom_spindle.pocketno != 5 || + nonrandom_spindle.offset.tran.z != 4.25) { + return 20; + } + + tooldata_init(true); tooldata_set_db(DB_ACTIVE); if (tooldata_load(path.data()) != -1) { return 10;