Preserve LinuxCNC M61 tool-number line

This commit is contained in:
CNC Local
2026-05-22 05:15:58 +08:00
parent d69b536d1d
commit bd04af8d8e
6 changed files with 40 additions and 1 deletions

View File

@@ -77,6 +77,7 @@ int main() {
bool saw_spindle_ccw = false;
bool saw_spindle_stop = false;
bool saw_comment_line = false;
bool saw_tool_number_line = false;
for (const auto &event : events) {
saw_tool = saw_tool || event.type == CNC_SIM_EVENT_TOOL_CHANGE;
saw_rapid = saw_rapid || event.type == CNC_SIM_EVENT_RAPID;
@@ -155,6 +156,21 @@ int main() {
ok &= expect(saw_spindle_ccw, "expected LinuxCNC M4 counterclockwise spindle state");
ok &= expect(saw_spindle_stop, "expected LinuxCNC M5 stopped spindle state");
const char tool_number_program[] =
"G21 G90 G17\n"
"M61 Q1\n"
"M30\n";
events.clear();
ok &= expect(cnc_sim_parse_program(sim, tool_number_program, sizeof(tool_number_program) - 1) == 0,
cnc_sim_last_error(sim));
for (const auto &event : events) {
saw_tool_number_line = saw_tool_number_line ||
(event.type == CNC_SIM_EVENT_TOOL_CHANGE &&
event.line == 2 &&
event.tool == 1);
}
ok &= expect(saw_tool_number_line, "expected LinuxCNC M61 tool-number event line");
const char comment_program[] =
"G21 G90 G17\n"
"(operator note)\n"

View File

@@ -40,6 +40,8 @@ int main() {
STOP_SPINDLE_TURNING(0);
SELECT_TOOL(7);
CHANGE_TOOL();
cnc_sim_linuxcnc_set_current_line(8);
CHANGE_TOOL_NUMBER(9);
STRAIGHT_TRAVERSE(10, 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
STRAIGHT_FEED(11, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
ARC_FEED(12, 10.0, 10.0, 10.0, 5.0, 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
@@ -57,6 +59,7 @@ int main() {
ok &= expect(events[1].type == CNC_SIM_EVENT_SET_PLANE, "expected plane event");
bool saw_tool = false;
bool saw_tool_number = false;
bool saw_rapid = false;
bool saw_feed = false;
bool saw_spindle_cw = false;
@@ -71,6 +74,9 @@ int main() {
bool saw_end = false;
for (const auto &event : events) {
saw_tool = saw_tool || (event.type == CNC_SIM_EVENT_TOOL_CHANGE && event.tool == 7);
saw_tool_number = saw_tool_number || (event.type == CNC_SIM_EVENT_TOOL_CHANGE &&
event.line == 8 &&
event.tool == 9);
saw_spindle_cw = saw_spindle_cw || (event.type == CNC_SIM_EVENT_SET_SPINDLE &&
event.spindle == 1200.0 &&
event.reserved == 1);
@@ -111,6 +117,7 @@ int main() {
}
ok &= expect(saw_tool, "expected tool change");
ok &= expect(saw_tool_number, "expected tool number change line");
ok &= expect(saw_spindle_cw, "expected clockwise spindle state");
ok &= expect(saw_spindle_ccw, "expected counterclockwise spindle state");
ok &= expect(saw_spindle_stop, "expected stopped spindle state");