Emit coolant state events

This commit is contained in:
CNC Local
2026-05-22 05:27:34 +08:00
parent db4a175944
commit 1d0acddf12
8 changed files with 174 additions and 9 deletions

View File

@@ -82,6 +82,10 @@ int main() {
bool saw_optional_stop = false;
bool saw_pallet_stop = false;
bool saw_final_end = false;
bool saw_mist_on = false;
bool saw_flood_on = false;
bool saw_mist_off = false;
bool saw_flood_off = 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;
@@ -207,6 +211,38 @@ int main() {
ok &= expect(saw_pallet_stop, "expected LinuxCNC M60 pallet shuttle event");
ok &= expect(saw_final_end, "expected LinuxCNC M30 final program end event");
const char coolant_program[] =
"G21 G90 G17\n"
"M7\n"
"M8\n"
"M9\n"
"M30\n";
events.clear();
ok &= expect(cnc_sim_parse_program(sim, coolant_program, sizeof(coolant_program) - 1) == 0,
cnc_sim_last_error(sim));
for (const auto &event : events) {
saw_mist_on = saw_mist_on ||
(event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 2 &&
event.reserved == 11);
saw_flood_on = saw_flood_on ||
(event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 3 &&
event.reserved == 21);
saw_mist_off = saw_mist_off ||
(event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 4 &&
event.reserved == 10);
saw_flood_off = saw_flood_off ||
(event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 4 &&
event.reserved == 20);
}
ok &= expect(saw_mist_on, "expected LinuxCNC M7 mist on state");
ok &= expect(saw_flood_on, "expected LinuxCNC M8 flood on state");
ok &= expect(saw_mist_off, "expected LinuxCNC M9 mist off state");
ok &= expect(saw_flood_off, "expected LinuxCNC M9 flood off state");
const char comment_program[] =
"G21 G90 G17\n"
"(operator note)\n"

View File

@@ -73,6 +73,10 @@ int main() {
bool saw_program_stop = false;
bool saw_optional_stop = false;
bool saw_pallet_stop = false;
bool saw_mist_on = false;
bool saw_flood_on = false;
bool saw_mist_off = false;
bool saw_flood_off = false;
bool saw_incremental_move = false;
bool saw_r_arc_center = false;
for (const auto &event : events) {
@@ -191,6 +195,37 @@ int main() {
ok &= expect(saw_optional_stop, "expected M1 optional stop event");
ok &= expect(saw_pallet_stop, "expected M60 pallet shuttle event");
const char coolant_program[] =
"G21\n"
"M7\n"
"M8\n"
"M9\n";
events.clear();
ok &= expect(cnc_sim_parse_program(sim, coolant_program, sizeof(coolant_program) - 1) == 0,
cnc_sim_last_error(sim));
for (const auto &event : events) {
saw_mist_on = saw_mist_on ||
(event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 2 &&
event.reserved == 11);
saw_flood_on = saw_flood_on ||
(event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 3 &&
event.reserved == 21);
saw_mist_off = saw_mist_off ||
(event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 4 &&
event.reserved == 10);
saw_flood_off = saw_flood_off ||
(event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 4 &&
event.reserved == 20);
}
ok &= expect(saw_mist_on, "expected M7 mist on state");
ok &= expect(saw_flood_on, "expected M8 flood on state");
ok &= expect(saw_mist_off, "expected M9 mist off state");
ok &= expect(saw_flood_off, "expected M9 flood off state");
const char linuxcnc_config[] = "{\"backend\":\"linuxcnc-rs274\"}";
config_rc = cnc_sim_load_config_json(sim, linuxcnc_config, sizeof(linuxcnc_config) - 1);
rc = cnc_sim_parse_program(sim, program, sizeof(program) - 1);

View File

@@ -51,6 +51,13 @@ int main() {
SET_XY_ROTATION(15.0);
cnc_sim_linuxcnc_set_current_line(20);
COMMENT("bridge comment");
cnc_sim_linuxcnc_set_current_line(24);
MIST_ON();
cnc_sim_linuxcnc_set_current_line(25);
FLOOD_ON();
cnc_sim_linuxcnc_set_current_line(26);
MIST_OFF();
FLOOD_OFF();
cnc_sim_linuxcnc_set_current_line(21);
PROGRAM_STOP();
cnc_sim_linuxcnc_set_current_line(22);
@@ -77,6 +84,10 @@ int main() {
bool saw_g92 = false;
bool saw_rotation = false;
bool saw_comment = false;
bool saw_mist_on = false;
bool saw_flood_on = false;
bool saw_mist_off = false;
bool saw_flood_off = false;
bool saw_program_stop = false;
bool saw_optional_stop = false;
bool saw_pallet_stop = false;
@@ -122,6 +133,18 @@ int main() {
event.feed == 15.0);
saw_comment = saw_comment || (event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 20);
saw_mist_on = saw_mist_on || (event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 24 &&
event.reserved == 11);
saw_flood_on = saw_flood_on || (event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 25 &&
event.reserved == 21);
saw_mist_off = saw_mist_off || (event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 26 &&
event.reserved == 10);
saw_flood_off = saw_flood_off || (event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 26 &&
event.reserved == 20);
saw_program_stop = saw_program_stop || (event.type == CNC_SIM_EVENT_PROGRAM_END &&
event.line == 21 &&
event.reserved == 1);
@@ -147,6 +170,10 @@ int main() {
ok &= expect(saw_g92, "expected G92 offset event");
ok &= expect(saw_rotation, "expected XY rotation event");
ok &= expect(saw_comment, "expected comment event line");
ok &= expect(saw_mist_on, "expected mist on state");
ok &= expect(saw_flood_on, "expected flood on state");
ok &= expect(saw_mist_off, "expected mist off state");
ok &= expect(saw_flood_off, "expected flood off state");
ok &= expect(saw_program_stop, "expected program stop event");
ok &= expect(saw_optional_stop, "expected optional stop event");
ok &= expect(saw_pallet_stop, "expected pallet shuttle stop event");