Unblock native XYZAC TP oracle

This commit is contained in:
2026-08-31 20:08:00 +08:00
parent 18436149a2
commit 6015293ee9
17 changed files with 49339 additions and 61 deletions

View File

@@ -253,6 +253,45 @@ static int switch_mcode(const char *block, uint32_t length) {
return 0;
}
static int parse_motion_control(sim_program *program, const char *block, uint32_t length) {
const char *cursor = block;
const char *end = block + length;
int active = 0;
double path = 0.0;
double naive = 0.0;
while (cursor < end) {
char letter;
char *number_end;
double value;
while (cursor < end && isspace((unsigned char)*cursor)) ++cursor;
if (cursor >= end || *cursor == ';') break;
if (*cursor == '(') { while (cursor < end && *cursor++ != ')') {} continue; }
if (!isalpha((unsigned char)*cursor)) { ++cursor; continue; }
letter = (char)toupper((unsigned char)*cursor++);
value = strtod(cursor, &number_end);
if (number_end == cursor) continue;
cursor = number_end;
if (letter == 'G') {
if (fabs(value - 61.0) <= 1e-12) active = SIM_PROGRAM_MOTION_EXACT_PATH;
else if (fabs(value - 61.1) <= 1e-12) active = SIM_PROGRAM_MOTION_EXACT_STOP;
else if (fabs(value - 64.0) <= 1e-12) active = SIM_PROGRAM_MOTION_CONTINUOUS;
else active = 0;
if (active != 0 || fabs(value - 64.0) <= 1e-12) {
program->motion_control_mode = active;
path = 0.0;
naive = 0.0;
}
} else if (active == SIM_PROGRAM_MOTION_CONTINUOUS && (letter == 'P' || letter == 'Q')) {
if (!isfinite(value) || value < 0.0) return SIM_PROGRAM_ERR_RANGE;
if (letter == 'P') path = value;
else naive = value;
program->path_tolerance = path;
program->naive_cam_tolerance = naive;
}
}
return SIM_PROGRAM_OK;
}
static void reset_runtime(sim_program *program) {
sim_interpreter_reset(&program->interpreter);
program->source_length = 0;
@@ -268,6 +307,9 @@ static void reset_runtime(sim_program *program) {
program->has_control = 0;
program->control_code = 0;
program->rapid_velocity = 35.0;
program->motion_control_mode = SIM_PROGRAM_MOTION_CONTINUOUS;
program->path_tolerance = 0.0;
program->naive_cam_tolerance = 0.0;
memset(&program->motion, 0, sizeof(program->motion));
memset(program->subroutines, 0, sizeof(program->subroutines));
memset(program->call_stack, 0, sizeof(program->call_stack));
@@ -356,6 +398,8 @@ int32_t sim_program_execute_block(sim_program *program, const char *block, uint3
int result;
if (program == NULL || block == NULL || length == 0) return SIM_PROGRAM_ERR_ARGUMENT;
if (control_line(block)) return SIM_PROGRAM_ERR_CONTROL;
result = parse_motion_control(program, block, length);
if (result != SIM_PROGRAM_OK) return result;
program->has_control = 0;
program->control_code = switch_mcode(block, length);
if (program->control_code != 0) program->has_control = 1;
@@ -449,8 +493,8 @@ uint32_t sim_program_canonical(const sim_program *program, char *output, uint32_
int written;
if (program == NULL) return 0;
written = snprintf(destination, destination_capacity,
"{\"call_depth\":%u,\"control_code\":%d,\"current_line\":%u,\"error_line\":%u,\"feed\":%.17g,\"has_control\":%u,\"has_motion\":%u,\"last_error\":%d,\"line_count\":%u,\"main_line_count\":%u,\"motion_mode\":%d,\"plane\":%d,\"rapid_velocity\":%.17g,\"schema\":\"sim_program.v1\",\"speed\":%.17g,\"spindle_mode\":%d,\"status\":%u,\"subroutine_count\":%u,\"source_length\":%u,\"units\":%d,\"distance_mode\":%d,\"interpreter_state_hash\":\"%llu\"}",
program->call_depth, program->control_code, program->current_line, program->error_line, program->interpreter.state.feed, program->has_control, program->has_motion, program->last_error, program->line_count, program->main_line_count, program->interpreter.state.motion_mode, program->interpreter.state.plane, program->rapid_velocity, program->interpreter.state.speed, program->interpreter.state.spindle_mode, program->status, program->subroutine_count, program->source_length, program->interpreter.state.units, program->interpreter.state.distance_mode,
"{\"call_depth\":%u,\"control_code\":%d,\"current_line\":%u,\"error_line\":%u,\"feed\":%.17g,\"has_control\":%u,\"has_motion\":%u,\"last_error\":%d,\"line_count\":%u,\"main_line_count\":%u,\"motion_control_mode\":%d,\"path_tolerance\":%.17g,\"naive_cam_tolerance\":%.17g,\"motion_mode\":%d,\"plane\":%d,\"rapid_velocity\":%.17g,\"schema\":\"sim_program.v1\",\"speed\":%.17g,\"spindle_mode\":%d,\"status\":%u,\"subroutine_count\":%u,\"source_length\":%u,\"units\":%d,\"distance_mode\":%d,\"interpreter_state_hash\":\"%llu\"}",
program->call_depth, program->control_code, program->current_line, program->error_line, program->interpreter.state.feed, program->has_control, program->has_motion, program->last_error, program->line_count, program->main_line_count, program->motion_control_mode, program->path_tolerance, program->naive_cam_tolerance, program->interpreter.state.motion_mode, program->interpreter.state.plane, program->rapid_velocity, program->interpreter.state.speed, program->interpreter.state.spindle_mode, program->status, program->subroutine_count, program->source_length, program->interpreter.state.units, program->interpreter.state.distance_mode,
(unsigned long long)sim_interpreter_state_hash(&program->interpreter));
return written < 0 ? 0 : (uint32_t)written + 1u;
}