Harden LinuxCNC wasm and native probe workflows
This commit is contained in:
@@ -39,6 +39,8 @@ void CanonEventSink::reset() {
|
||||
feed_hold_ = false;
|
||||
mist_on_ = false;
|
||||
flood_on_ = false;
|
||||
has_pending_motion_start_ = false;
|
||||
pending_motion_start_ = {};
|
||||
}
|
||||
|
||||
void CanonEventSink::set_callback(CncSimEventCallback callback, void *user_data) {
|
||||
@@ -55,6 +57,10 @@ bool CanonEventSink::callback_aborted() const {
|
||||
return callback_status_ != 0;
|
||||
}
|
||||
|
||||
void CanonEventSink::set_block_delete(bool enabled) {
|
||||
block_delete_ = enabled;
|
||||
}
|
||||
|
||||
void CanonEventSink::configure_rtcp(bool enabled, double tool_length) {
|
||||
rtcp_enabled_ = enabled;
|
||||
default_rtcp_tool_length_ = tool_length;
|
||||
@@ -80,6 +86,10 @@ void CanonEventSink::set_tool_length_offset(const CncSimPose &offset) {
|
||||
}
|
||||
|
||||
void CanonEventSink::apply_tool_length_offset(const CncSimPose &offset) {
|
||||
if (!has_pending_motion_start_) {
|
||||
pending_motion_start_ = position_;
|
||||
has_pending_motion_start_ = true;
|
||||
}
|
||||
double dx = tool_length_offset_.x - offset.x;
|
||||
double dy = tool_length_offset_.y - offset.y;
|
||||
rotate_xy(&dx, &dy, -xy_rotation_degrees_);
|
||||
@@ -305,41 +315,45 @@ void CanonEventSink::change_tool(int line) {
|
||||
|
||||
void CanonEventSink::straight_traverse(int line, const CncSimPose &end) {
|
||||
CncSimEvent event = base_event(CNC_SIM_EVENT_RAPID, line);
|
||||
event.start = position_;
|
||||
event.start = has_pending_motion_start_ ? pending_motion_start_ : position_;
|
||||
event.end = end;
|
||||
emit(event);
|
||||
emit_rtcp_pivot(line, position_, end);
|
||||
emit_rtcp_pivot(line, event.start, end);
|
||||
has_pending_motion_start_ = false;
|
||||
position_ = end;
|
||||
}
|
||||
|
||||
void CanonEventSink::straight_feed(int line, const CncSimPose &end) {
|
||||
CncSimEvent event = base_event(CNC_SIM_EVENT_LINEAR_FEED, line);
|
||||
event.start = position_;
|
||||
event.start = has_pending_motion_start_ ? pending_motion_start_ : position_;
|
||||
event.end = end;
|
||||
emit(event);
|
||||
emit_rtcp_pivot(line, position_, end);
|
||||
emit_rtcp_pivot(line, event.start, end);
|
||||
has_pending_motion_start_ = false;
|
||||
position_ = end;
|
||||
}
|
||||
|
||||
void CanonEventSink::arc_feed(int line, const CncSimPose &end, const CncSimPose ¢er, int turns) {
|
||||
CncSimEvent event = base_event(CNC_SIM_EVENT_ARC_FEED, line);
|
||||
event.start = position_;
|
||||
event.start = has_pending_motion_start_ ? pending_motion_start_ : position_;
|
||||
event.end = end;
|
||||
event.center = center;
|
||||
event.arc_turns = turns;
|
||||
emit(event);
|
||||
emit_rtcp_pivot(line, position_, end);
|
||||
emit_rtcp_pivot(line, event.start, end);
|
||||
has_pending_motion_start_ = false;
|
||||
position_ = end;
|
||||
}
|
||||
|
||||
void CanonEventSink::straight_probe(int line, const CncSimPose &end, int probe_type) {
|
||||
CncSimEvent event = base_event(CNC_SIM_EVENT_PROBE, line);
|
||||
event.start = position_;
|
||||
event.start = has_pending_motion_start_ ? pending_motion_start_ : position_;
|
||||
event.end = end;
|
||||
event.reserved = probe_type;
|
||||
emit(event);
|
||||
probe_position_ = end;
|
||||
probe_tripped_ = (probe_type & 2) == 0;
|
||||
has_pending_motion_start_ = false;
|
||||
position_ = end;
|
||||
}
|
||||
|
||||
@@ -446,6 +460,10 @@ bool CanonEventSink::flood_on() const {
|
||||
return flood_on_;
|
||||
}
|
||||
|
||||
bool CanonEventSink::block_delete() const {
|
||||
return block_delete_;
|
||||
}
|
||||
|
||||
void CanonEventSink::set_mist_on(bool enabled) {
|
||||
mist_on_ = enabled;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ public:
|
||||
void set_callback(CncSimEventCallback callback, void *user_data);
|
||||
void clear_callback_status();
|
||||
bool callback_aborted() const;
|
||||
void set_block_delete(bool enabled);
|
||||
void configure_rtcp(bool enabled, double tool_length);
|
||||
void set_tool_length(int h_code, double tool_length);
|
||||
void set_tool_length_offset(const CncSimPose &offset);
|
||||
@@ -70,6 +71,7 @@ public:
|
||||
bool feed_hold() const;
|
||||
bool mist_on() const;
|
||||
bool flood_on() const;
|
||||
bool block_delete() const;
|
||||
void set_mist_on(bool enabled);
|
||||
void set_flood_on(bool enabled);
|
||||
|
||||
@@ -104,5 +106,8 @@ private:
|
||||
bool feed_hold_ = false;
|
||||
bool mist_on_ = false;
|
||||
bool flood_on_ = false;
|
||||
bool block_delete_ = false;
|
||||
std::unordered_map<int, double> tool_lengths_;
|
||||
bool has_pending_motion_start_ = false;
|
||||
CncSimPose pending_motion_start_{};
|
||||
};
|
||||
|
||||
@@ -152,6 +152,11 @@ int apply_config(CncSimHandle *handle, const std::string &json) {
|
||||
if (has_rtcp_enabled || has_tool_length) {
|
||||
handle->sink.configure_rtcp(rtcp_enabled, tool_length);
|
||||
}
|
||||
bool block_delete = false;
|
||||
if (contains_bool_value(compact, "blockdelete", &block_delete) ||
|
||||
contains_bool_value(compact, "block_delete", &block_delete)) {
|
||||
handle->sink.set_block_delete(block_delete);
|
||||
}
|
||||
apply_tool_length_table(handle->sink, compact);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -77,8 +77,12 @@ 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);
|
||||
const char *tmpdir = std::getenv("TMPDIR");
|
||||
std::string tmpl = std::string(tmpdir ? tmpdir : "/tmp") + "/cnc_sim_api_XXXXXX.ngc";
|
||||
std::vector<char> tmpl_buffer(tmpl.begin(), tmpl.end());
|
||||
tmpl_buffer.push_back('\0');
|
||||
|
||||
const int fd = mkstemps(tmpl_buffer.data(), 4);
|
||||
if (fd < 0) {
|
||||
if (error) {
|
||||
*error = "failed to create temporary ngc file";
|
||||
@@ -100,13 +104,13 @@ bool write_temp_program(const char *program,
|
||||
ok = false;
|
||||
}
|
||||
if (!ok) {
|
||||
unlink(tmpl);
|
||||
unlink(tmpl_buffer.data());
|
||||
if (error) {
|
||||
*error = "failed to write temporary ngc file";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*path = tmpl;
|
||||
*path = tmpl_buffer.data();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -185,6 +189,7 @@ int parse_linuxcnc_rs274_backend(CanonEventSink &sink,
|
||||
cnc_sim_linuxcnc_set_canon_sink(nullptr);
|
||||
return -1;
|
||||
}
|
||||
SET_BLOCK_DELETE(sink.block_delete());
|
||||
|
||||
if (file_mode_enabled()) {
|
||||
std::string temp_path;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@
|
||||
#include "canon_event_sink.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
class SmokeGcodeParser {
|
||||
@@ -12,6 +13,14 @@ public:
|
||||
int parse(const char *program, size_t program_len, std::string *error);
|
||||
|
||||
private:
|
||||
struct SmokeToolTableEntry {
|
||||
CncSimPose offset{};
|
||||
double diameter = 0.0;
|
||||
double frontangle = 0.0;
|
||||
double backangle = 0.0;
|
||||
double orientation = 0.0;
|
||||
};
|
||||
|
||||
CanonEventSink &sink_;
|
||||
bool absolute_ = true;
|
||||
bool arc_absolute_ = false;
|
||||
@@ -55,4 +64,5 @@ private:
|
||||
double oword_return_value_ = 0.0;
|
||||
bool oword_value_returned_ = false;
|
||||
int selected_tool_id_ = 0;
|
||||
std::unordered_map<int, SmokeToolTableEntry> tool_table_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user