Emit coolant state events
This commit is contained in:
@@ -15,6 +15,8 @@ namespace {
|
||||
|
||||
CanonEventSink *active_sink = nullptr;
|
||||
int active_line = 0;
|
||||
bool flood_on = false;
|
||||
bool mist_on = false;
|
||||
std::string parameter_file_name = "rs274ngc.var";
|
||||
|
||||
CncSimPose make_pose(double x, double y, double z,
|
||||
@@ -86,12 +88,26 @@ int event_line(int lineno = 0) {
|
||||
return lineno > 0 ? lineno : active_line;
|
||||
}
|
||||
|
||||
void emit_state_event(CncSimEventType type, int reserved) {
|
||||
if (!active_sink) {
|
||||
return;
|
||||
}
|
||||
CncSimEvent event{};
|
||||
event.version = 1;
|
||||
event.type = type;
|
||||
event.line = event_line();
|
||||
event.reserved = reserved;
|
||||
active_sink->emit_raw(event);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void cnc_sim_linuxcnc_set_canon_sink(CanonEventSink *sink) {
|
||||
trace_call("cnc_sim_linuxcnc_set_canon_sink");
|
||||
active_sink = sink;
|
||||
active_line = 0;
|
||||
flood_on = false;
|
||||
mist_on = false;
|
||||
}
|
||||
|
||||
CanonEventSink *cnc_sim_linuxcnc_get_canon_sink() {
|
||||
@@ -107,6 +123,8 @@ void INIT_CANON() {
|
||||
if (active_sink) {
|
||||
active_sink->reset();
|
||||
}
|
||||
flood_on = false;
|
||||
mist_on = false;
|
||||
}
|
||||
|
||||
void USE_LENGTH_UNITS(CANON_UNITS units) {
|
||||
@@ -410,13 +428,7 @@ void CLAMP_AXIS(CANON_AXIS) {
|
||||
}
|
||||
|
||||
void COMMENT(const char *) {
|
||||
if (active_sink) {
|
||||
CncSimEvent event{};
|
||||
event.version = 1;
|
||||
event.type = CNC_SIM_EVENT_COMMENT;
|
||||
event.line = event_line();
|
||||
active_sink->emit_raw(event);
|
||||
}
|
||||
emit_state_event(CNC_SIM_EVENT_COMMENT, 0);
|
||||
}
|
||||
|
||||
void DISABLE_ADAPTIVE_FEED() {
|
||||
@@ -444,9 +456,13 @@ void ENABLE_FEED_HOLD() {
|
||||
}
|
||||
|
||||
void FLOOD_OFF() {
|
||||
flood_on = false;
|
||||
emit_state_event(CNC_SIM_EVENT_COMMENT, 20);
|
||||
}
|
||||
|
||||
void FLOOD_ON() {
|
||||
flood_on = true;
|
||||
emit_state_event(CNC_SIM_EVENT_COMMENT, 21);
|
||||
}
|
||||
|
||||
void MESSAGE(char *) {
|
||||
@@ -465,9 +481,13 @@ void LOGCLOSE() {
|
||||
}
|
||||
|
||||
void MIST_OFF() {
|
||||
mist_on = false;
|
||||
emit_state_event(CNC_SIM_EVENT_COMMENT, 10);
|
||||
}
|
||||
|
||||
void MIST_ON() {
|
||||
mist_on = true;
|
||||
emit_state_event(CNC_SIM_EVENT_COMMENT, 11);
|
||||
}
|
||||
|
||||
void PALLET_SHUTTLE() {
|
||||
@@ -555,7 +575,7 @@ double GET_EXTERNAL_FEED_RATE() {
|
||||
}
|
||||
|
||||
int GET_EXTERNAL_FLOOD() {
|
||||
return 0;
|
||||
return flood_on ? 1 : 0;
|
||||
}
|
||||
|
||||
CANON_UNITS GET_EXTERNAL_LENGTH_UNIT_TYPE() {
|
||||
@@ -571,7 +591,7 @@ double GET_EXTERNAL_ANGLE_UNITS() {
|
||||
}
|
||||
|
||||
int GET_EXTERNAL_MIST() {
|
||||
return 0;
|
||||
return mist_on ? 1 : 0;
|
||||
}
|
||||
|
||||
CANON_MOTION_MODE GET_EXTERNAL_MOTION_CONTROL_MODE() {
|
||||
|
||||
@@ -230,6 +230,15 @@ bool stop_if_callback_aborted(CanonEventSink &sink, std::string *error) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void emit_comment_state(CanonEventSink &sink, int line, int reserved) {
|
||||
CncSimEvent event{};
|
||||
event.version = 1;
|
||||
event.type = CNC_SIM_EVENT_COMMENT;
|
||||
event.line = line;
|
||||
event.reserved = reserved;
|
||||
sink.emit_raw(event);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int SmokeGcodeParser::parse(const char *program, size_t program_len, std::string *error) {
|
||||
@@ -366,6 +375,25 @@ int SmokeGcodeParser::parse(const char *program, size_t program_len, std::string
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (m == 7) {
|
||||
emit_comment_state(sink_, line_number, 11);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (m == 8) {
|
||||
emit_comment_state(sink_, line_number, 21);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (m == 9) {
|
||||
emit_comment_state(sink_, line_number, 10);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
emit_comment_state(sink_, line_number, 20);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (m == 428) {
|
||||
sink_.switch_kinematics(1, true, line_number);
|
||||
if (stop_if_callback_aborted(sink_, error)) {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user