Enforce LinuxCNC WASM XYZAC command authority

This commit is contained in:
2026-08-28 13:04:47 +08:00
parent 1a7995fa9b
commit 78d884bc67
43 changed files with 567 additions and 186 deletions

View File

@@ -250,6 +250,7 @@ if(EMSCRIPTEN)
string(REPLACE "_sim_hal_set_pin" "_sim_hal_set_pin_scalar','_sim_hal_set_pin" _sim_module_link_flags "${_sim_module_link_flags}")
string(REPLACE "_sim_hal_set_param" "_sim_hal_set_param_scalar','_sim_hal_set_param" _sim_module_link_flags "${_sim_module_link_flags}")
string(REPLACE "_sim_io_init" "_sim_io_size','_sim_io_init" _sim_module_link_flags "${_sim_module_link_flags}")
string(REPLACE "_sim_io_set_estop','_sim_io_recover" "_sim_io_set_estop','_sim_io_set_power','_sim_io_recover" _sim_module_link_flags "${_sim_module_link_flags}")
string(REPLACE "_sim_device_init" "_sim_device_io_size','_sim_device_init" _sim_module_link_flags "${_sim_module_link_flags}")
string(REPLACE "_sim_motion_step','_sim_motion_read_state" "_sim_motion_step','_sim_motion_set_profile','_sim_motion_set_lookahead','_sim_motion_peek','_sim_motion_read_state" _sim_module_link_flags "${_sim_module_link_flags}")
string(REPLACE "_sim_motion_state_hash','_sim_motion_canonical" "_sim_motion_state_hash','_sim_motion_plan_hash','_sim_motion_canonical" _sim_module_link_flags "${_sim_module_link_flags}")

View File

@@ -140,6 +140,7 @@ int sim_io_probe_update(sim_io *io, const sim_posemath_pose *pose,
uint32_t input);
int sim_io_probe_disarm(sim_io *io);
int sim_io_set_estop(sim_io *io, uint32_t estop);
int sim_io_set_power(sim_io *io, uint32_t active);
int sim_io_recover(sim_io *io);
int sim_io_step(sim_io *io, uint32_t ticks);
int sim_io_read_state(const sim_io *io, sim_io_state *state);

View File

@@ -454,6 +454,33 @@ int sim_io_set_estop(sim_io *io, uint32_t estop) {
return SIM_IO_OK;
}
int sim_io_set_power(sim_io *io, uint32_t active) {
if (!valid_io(io) || active > 1U) return SIM_IO_ERR_ARGUMENT;
if (io->state.estop) { set_last(io, SIM_IO_ERR_ESTOP); return SIM_IO_ERR_ESTOP; }
if (!active) {
io->state.ready = 0;
io->state.tool_prepare = 0;
io->state.tool_change = 0;
io->state.tool_prepared = 0;
io->state.tool_changed = 0;
io->state.tool_state = SIM_IO_TOOL_ABORTED;
for (uint32_t index = 0; index < io->state.spindle_count; ++index) {
io->state.spindles[index].command_rpm = 0.0;
io->state.spindles[index].enabled = 0;
io->state.spindles[index].brake = 1;
}
} else {
if (io->state.fault || io->state.toolchanger_fault) { set_last(io, SIM_IO_ERR_FAULT); return SIM_IO_ERR_FAULT; }
if (!spindle_stopped(io)) { set_last(io, SIM_IO_ERR_BUSY); return SIM_IO_ERR_BUSY; }
io->state.ready = 1;
io->state.recovery_epoch += 1;
io->state.tool_state = SIM_IO_TOOL_IDLE;
}
set_last(io, SIM_IO_OK);
mirror_pins(io);
return SIM_IO_OK;
}
int sim_io_recover(sim_io *io) {
if (!valid_io(io)) return SIM_IO_ERR_ARGUMENT;
if (io->state.estop) return SIM_IO_ERR_ESTOP;

View File

@@ -63,6 +63,9 @@ int main(void) {
assert(sim_io_set_estop(&io, 0) == SIM_IO_OK);
recover_status = sim_io_recover(&io);
assert(recover_status == SIM_IO_OK && io.state.ready == 1 && io.state.recovery_epoch == 1);
assert(sim_io_set_power(&io, 0) == SIM_IO_OK && io.state.ready == 0);
assert(sim_io_spindle_command(&io, 0, 100.0, 1) == SIM_IO_ERR_NOT_READY);
assert(sim_io_set_power(&io, 1) == SIM_IO_OK && io.state.ready == 1 && io.state.recovery_epoch == 2);
assert(sim_io_tool_set_fault(&io, 1, 42) == SIM_IO_OK);
fault_clear_status = sim_io_tool_clear_fault(&io);