Expand LinuxCNC smoke coverage
This commit is contained in:
@@ -439,7 +439,19 @@ void USE_NO_SPINDLE_FORCE() {
|
||||
void SET_TOOL_TABLE_ENTRY(int, int, const EmcPose &, double, double, double, int) {
|
||||
}
|
||||
|
||||
void USE_TOOL_LENGTH_OFFSET(const EmcPose &) {
|
||||
void USE_TOOL_LENGTH_OFFSET(const EmcPose &offset) {
|
||||
if (!active_sink) {
|
||||
return;
|
||||
}
|
||||
CncSimEvent event{};
|
||||
event.version = 1;
|
||||
event.type = CNC_SIM_EVENT_COMMENT;
|
||||
event.line = event_line();
|
||||
event.reserved = 430;
|
||||
event.start = make_pose(offset.tran.x, offset.tran.y, offset.tran.z,
|
||||
offset.a, offset.b, offset.c,
|
||||
offset.u, offset.v, offset.w);
|
||||
active_sink->emit_raw(event);
|
||||
}
|
||||
|
||||
void CHANGE_TOOL_NUMBER(int number) {
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
|
||||
int _task = 0;
|
||||
char _parameter_file_name[LINELEN];
|
||||
@@ -88,6 +90,92 @@ std::string interp_error(InterpBase *interp, int status, const char *stage) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool file_mode_enabled() {
|
||||
return std::getenv("CNC_SIM_RS274_FILE_MODE") != nullptr;
|
||||
}
|
||||
|
||||
bool write_temp_program(const char *program,
|
||||
size_t program_len,
|
||||
std::string *path,
|
||||
std::string *error) {
|
||||
char tmpl[] = "/tmp/cnc_sim_api_XXXXXX.ngc";
|
||||
const int fd = mkstemps(tmpl, 4);
|
||||
if (fd < 0) {
|
||||
if (error) {
|
||||
*error = "failed to create temporary ngc file";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
size_t written = 0;
|
||||
while (written < program_len) {
|
||||
const ssize_t rc = write(fd, program + written, program_len - written);
|
||||
if (rc <= 0) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
written += static_cast<size_t>(rc);
|
||||
}
|
||||
if (close(fd) != 0) {
|
||||
ok = false;
|
||||
}
|
||||
if (!ok) {
|
||||
unlink(tmpl);
|
||||
if (error) {
|
||||
*error = "failed to write temporary ngc file";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*path = tmpl;
|
||||
return true;
|
||||
}
|
||||
|
||||
int execute_file_mode(InterpBase *interp,
|
||||
CanonEventSink &sink,
|
||||
const std::string &path,
|
||||
std::string *error) {
|
||||
int status = interp->open(path.c_str());
|
||||
if (status != INTERP_OK) {
|
||||
if (error) {
|
||||
*error = interp_error(interp, status, "open");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool program_done = false;
|
||||
while (!program_done) {
|
||||
status = interp->read();
|
||||
if (status == INTERP_EXIT || status == INTERP_ENDFILE) {
|
||||
break;
|
||||
}
|
||||
if (!normal_read_status(status)) {
|
||||
if (error) {
|
||||
*error = interp_error(interp, status, "read");
|
||||
}
|
||||
interp->close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
cnc_sim_linuxcnc_set_current_line(interp->line());
|
||||
status = interp->execute();
|
||||
if (!normal_execute_status(status, &program_done)) {
|
||||
if (error) {
|
||||
*error = interp_error(interp, status, "execute");
|
||||
}
|
||||
interp->close();
|
||||
return -1;
|
||||
}
|
||||
if (stop_if_callback_aborted(sink, error)) {
|
||||
interp->close();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
interp->close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int parse_linuxcnc_rs274_backend(CanonEventSink &sink,
|
||||
@@ -119,57 +207,82 @@ int parse_linuxcnc_rs274_backend(CanonEventSink &sink,
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string source(program, program + program_len);
|
||||
std::istringstream input(source);
|
||||
std::string line;
|
||||
bool program_done = false;
|
||||
int line_number = 0;
|
||||
while (!program_done && std::getline(input, line)) {
|
||||
++line_number;
|
||||
cnc_sim_linuxcnc_set_current_line(line_number);
|
||||
std::vector<SimulatorGcodeControlAction> control_actions;
|
||||
if (parse_simulator_gcode_control_line(line, &control_actions)) {
|
||||
for (const auto &action : control_actions) {
|
||||
emit_simulator_gcode_control_action(sink, action, line_number);
|
||||
if (stop_if_callback_aborted(sink, error)) {
|
||||
interp->exit();
|
||||
delete interp;
|
||||
cnc_sim_linuxcnc_set_canon_sink(nullptr);
|
||||
return -1;
|
||||
if (file_mode_enabled()) {
|
||||
std::string temp_path;
|
||||
if (!write_temp_program(program, program_len, &temp_path, error)) {
|
||||
interp->exit();
|
||||
delete interp;
|
||||
cnc_sim_linuxcnc_set_canon_sink(nullptr);
|
||||
return -1;
|
||||
}
|
||||
const int rc = execute_file_mode(interp, sink, temp_path, error);
|
||||
unlink(temp_path.c_str());
|
||||
if (rc != 0) {
|
||||
interp->exit();
|
||||
delete interp;
|
||||
cnc_sim_linuxcnc_set_canon_sink(nullptr);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
std::string source(program, program + program_len);
|
||||
std::istringstream input(source);
|
||||
std::string line;
|
||||
bool program_done = false;
|
||||
int line_number = 0;
|
||||
while (!program_done && std::getline(input, line)) {
|
||||
++line_number;
|
||||
cnc_sim_linuxcnc_set_current_line(line_number);
|
||||
std::vector<SimulatorGcodeControlAction> control_actions;
|
||||
if (parse_simulator_gcode_control_line(line, &control_actions)) {
|
||||
bool simulator_only_line = true;
|
||||
for (const auto &action : control_actions) {
|
||||
emit_simulator_gcode_control_action(sink, action, line_number);
|
||||
if (action.kind == SimulatorGcodeControlKind::RtcpState &&
|
||||
!action.rtcp_enabled) {
|
||||
simulator_only_line = false;
|
||||
}
|
||||
if (stop_if_callback_aborted(sink, error)) {
|
||||
interp->exit();
|
||||
delete interp;
|
||||
cnc_sim_linuxcnc_set_canon_sink(nullptr);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (simulator_only_line) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
status = interp->read(line.c_str());
|
||||
if (!normal_read_status(status)) {
|
||||
if (error) {
|
||||
*error = interp_error(interp, status, "read");
|
||||
status = interp->read(line.c_str());
|
||||
if (!normal_read_status(status)) {
|
||||
if (error) {
|
||||
*error = interp_error(interp, status, "read");
|
||||
}
|
||||
interp->exit();
|
||||
delete interp;
|
||||
cnc_sim_linuxcnc_set_canon_sink(nullptr);
|
||||
return -1;
|
||||
}
|
||||
if (status == INTERP_EXIT || status == INTERP_ENDFILE) {
|
||||
break;
|
||||
}
|
||||
interp->exit();
|
||||
delete interp;
|
||||
cnc_sim_linuxcnc_set_canon_sink(nullptr);
|
||||
return -1;
|
||||
}
|
||||
if (status == INTERP_EXIT || status == INTERP_ENDFILE) {
|
||||
break;
|
||||
}
|
||||
|
||||
status = interp->execute();
|
||||
if (!normal_execute_status(status, &program_done)) {
|
||||
if (error) {
|
||||
*error = interp_error(interp, status, "execute");
|
||||
status = interp->execute();
|
||||
if (!normal_execute_status(status, &program_done)) {
|
||||
if (error) {
|
||||
*error = interp_error(interp, status, "execute");
|
||||
}
|
||||
interp->exit();
|
||||
delete interp;
|
||||
cnc_sim_linuxcnc_set_canon_sink(nullptr);
|
||||
return -1;
|
||||
}
|
||||
if (stop_if_callback_aborted(sink, error)) {
|
||||
interp->exit();
|
||||
delete interp;
|
||||
cnc_sim_linuxcnc_set_canon_sink(nullptr);
|
||||
return -1;
|
||||
}
|
||||
interp->exit();
|
||||
delete interp;
|
||||
cnc_sim_linuxcnc_set_canon_sink(nullptr);
|
||||
return -1;
|
||||
}
|
||||
if (stop_if_callback_aborted(sink, error)) {
|
||||
interp->exit();
|
||||
delete interp;
|
||||
cnc_sim_linuxcnc_set_canon_sink(nullptr);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,5 +14,16 @@ public:
|
||||
private:
|
||||
CanonEventSink &sink_;
|
||||
bool absolute_ = true;
|
||||
int canned_cycle_ = 0;
|
||||
bool canned_return_to_initial_ = false;
|
||||
bool canned_has_r_ = false;
|
||||
bool canned_has_z_ = false;
|
||||
bool canned_has_p_ = false;
|
||||
bool canned_has_q_ = false;
|
||||
bool canned_has_d_ = false;
|
||||
double canned_r_ = 0.0;
|
||||
double canned_z_ = 0.0;
|
||||
double canned_p_ = 0.0;
|
||||
double canned_q_ = 0.0;
|
||||
double canned_d_ = 1.0;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user