From c81f9d01112dc2b60df47504856999c36b463c54 Mon Sep 17 00:00:00 2001 From: cnc Date: Sat, 6 Jun 2026 13:10:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E6=BA=90=E9=AA=8C=E8=AF=81API?= =?UTF-8?q?=E7=99=BE=E5=88=86=E5=8F=B7=E6=96=87=E4=BB=B6=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 源依据:LinuxCNC src/emc/rs274ngc/rs274ngc_pre.cc 的 Interp::open() 在首个非空行是 % 时启用 percent-file mode,src/emc/rs274ngc/interp_read.cc read_text() 在匹配 % 处结束读取并忽略后续文本。 结论:native API source-linked smoke 增加 CNC_SIM_RS274_FILE_MODE 下的百分号文件断言,确认 cnc_sim API 文件模式走 LinuxCNC open/read 语义而非逐行桥接或 smoke fallback。 检查:./test-linuxcnc-api-native.sh;./test-native.sh;./test-linuxcnc-source-link.sh。 --- .../cnc_sim_api_linuxcnc_rs274_smoke.cpp | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp b/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp index a1e89d8..cacc225 100644 --- a/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp +++ b/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp @@ -303,6 +303,45 @@ int main() { } } + { + std::vector percent_events; + CncSimHandle *percent_sim = cnc_sim_create(); + cnc_sim_set_event_callback(percent_sim, collect_event, &percent_events); + ScopedEnv file_mode_env("CNC_SIM_RS274_FILE_MODE", "1"); + const char percent_program[] = + "%\n" + "G21 G90\n" + "F100\n" + "G1 X1\n" + "%\n" + "G1 X99\n"; + bool percent_ok = true; + percent_ok &= expect(cnc_sim_parse_program(percent_sim, + percent_program, + sizeof(percent_program) - 1) == 0, + cnc_sim_last_error(percent_sim)); + std::vector feed_lines; + std::vector feed_x; + for (const auto &event : percent_events) { + if (event.type == CNC_SIM_EVENT_LINEAR_FEED) { + feed_lines.push_back(event.line); + feed_x.push_back(event.end.x); + } + } + // LinuxCNC source basis: rs274ngc_pre.cc open() enables percent-file + // mode when the first nonblank line is '%'; interp_read.cc read_text() + // stops at the matching '%', so later program text is ignored. + percent_ok &= expect(feed_lines.size() == 1 && + feed_lines[0] == 4 && + feed_x.size() == 1 && + near(feed_x[0], 1.0), + "expected LinuxCNC percent-file mode to ignore trailing text"); + cnc_sim_destroy(percent_sim); + if (!percent_ok) { + return 1; + } + } + const char config[] = "{\"backend\":\"linuxcnc-rs274\",\"rtcp\":{\"enabled\":true,\"toolLength\":100,\"toolLengths\":{\"7\":125}}}"; const char program[] =