From 74ae2538a39249f1205e65ee729bd84f7d4affb2 Mon Sep 17 00:00:00 2001 From: wangdequan Date: Sat, 29 Aug 2026 07:03:43 +0800 Subject: [PATCH] Show live LinuxCNC G-code execution progress --- wasm-core/src/sim_program.c | 4 ++-- web/react/src/App.tsx | 9 ++++++--- web/react/src/styles.css | 3 +++ web/worker/sim-session.mjs | 3 +++ web/worker/wasm-program-runtime.mjs | 20 ++++++++++++++++++-- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/wasm-core/src/sim_program.c b/wasm-core/src/sim_program.c index 6e48d3a..8c7ca20 100644 --- a/wasm-core/src/sim_program.c +++ b/wasm-core/src/sim_program.c @@ -397,8 +397,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,\"has_control\":%u,\"has_motion\":%u,\"last_error\":%d,\"line_count\":%u,\"main_line_count\":%u,\"motion_mode\":%d,\"rapid_velocity\":%.17g,\"schema\":\"sim_program.v1\",\"status\":%u,\"subroutine_count\":%u,\"source_length\":%u,\"interpreter_state_hash\":\"%llu\"}", - program->call_depth, program->control_code, program->current_line, program->error_line, program->has_control, program->has_motion, program->last_error, program->line_count, program->main_line_count, program->interpreter.state.motion_mode, program->rapid_velocity, program->status, program->subroutine_count, program->source_length, + "{\"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, (unsigned long long)sim_interpreter_state_hash(&program->interpreter)); return written < 0 ? 0 : (uint32_t)written + 1u; } diff --git a/web/react/src/App.tsx b/web/react/src/App.tsx index e4a6aa1..f2913f7 100644 --- a/web/react/src/App.tsx +++ b/web/react/src/App.tsx @@ -87,9 +87,10 @@ function DroView({ axes, state, coordType, displayType, metric, setCoordType, se return
Position
DisplayedActualRelative
{labels.map((label, index) => { const actual = Number(axes[index] ?? 0); const target = Number(commanded[index] ?? actual); const relativeValue = Number(relative[index] ?? actual); const displayed = displayType === "commanded" ? target : actual; return
{label}{format(coordType === "relative" ? relativeValue : displayed, index)}{format(actual, index)}{format(relativeValue, index)}
; })}
Units: {metric ? "mm" : "inch"} / deg{coordType} / {displayType}Tick: {state.tick}Hash: {state.snapshot?.state_hash?.slice(0, 12) || "-"}
; } -function ProgramPane({ text, setText, activeGcodes, onLoad, onRun, onStep, onOpenFile, canLoad, canRun, canStep, currentLine, diagnostic }: { text: string; setText: (text: string) => void; activeGcodes: string; onLoad: () => void; onRun: () => void; onStep: () => void; onOpenFile: () => void; canLoad: boolean; canRun: boolean; canStep: boolean; currentLine: number | null; diagnostic: string | null }) { +function ProgramPane({ text, setText, activeGcodes, onLoad, onRun, onStep, onOpenFile, canLoad, canRun, canStep, currentLine, executionLine, executionLineText, diagnostic }: { text: string; setText: (text: string) => void; activeGcodes: string; onLoad: () => void; onRun: () => void; onStep: () => void; onOpenFile: () => void; canLoad: boolean; canRun: boolean; canStep: boolean; currentLine: number | null; executionLine: number | null; executionLineText: string; diagnostic: string | null }) { const lines = text.split("\n"); - return
{lines.map((_, index) => {index + 1})}