按规划继续工作
结论:接入 vendored LinuxCNC tooldata_common.cc 负责刀具表解析与保存,WASM/SDK/OPFS/UI 仅做运行时边界搬运;native、WASM、OPFS 和浏览器 smoke 验证已通过。
This commit is contained in:
@@ -173,9 +173,9 @@ The validation fails if:
|
|||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `tests/wasm/node/verify_ini_wasm.sh` | Validates the browser-facing INI WASM module can be built from vendored LinuxCNC `inifile.cc`, loaded through the JS SDK in Node, and queried through the exported C ABI. |
|
| `tests/wasm/node/verify_ini_wasm.sh` | Validates the browser-facing INI WASM module can be built from vendored LinuxCNC `inifile.cc`, loaded through the JS SDK in Node, and queried through the exported C ABI. |
|
||||||
| `tests/wasm/node/verify_interp_wasm.sh` | Validates the initial interpreter-core WASM module can be built from vendored LinuxCNC interpreter source, loaded through the interpreter JS SDK, run the first fixture group through `Interp::execute()` and selected file fixtures through `Interp::open()`/`read()`/`execute()`, match the native canonical event plus required state readback fixtures, and run parameter-file restore/save through vendored LinuxCNC `Interp::restore_parameters()` and `Interp::save_parameters()`. |
|
| `tests/wasm/node/verify_interp_wasm.sh` | Validates the initial interpreter-core WASM module can be built from vendored LinuxCNC interpreter source, loaded through the interpreter JS SDK, run the first fixture group through `Interp::execute()` and selected file fixtures through `Interp::open()`/`read()`/`execute()`, match the native canonical event plus required state readback fixtures, and run parameter-file restore/save through vendored LinuxCNC `Interp::restore_parameters()` and `Interp::save_parameters()`. |
|
||||||
| `tests/opfs/node/verify_file_service.sh` | Validates the host-owned OPFS text-file adapter, path model, session snapshot store, machine file store, G-code text store, and OPFS-to-WASM parameter-file bridge without moving file persistence or parameter semantics into the WASM core. |
|
| `tests/opfs/node/verify_file_service.sh` | Validates the host-owned OPFS text-file adapter, path model, session snapshot store, machine file store, G-code text store, OPFS-to-WASM parameter/tool-table bridges, and grouped machine-session loading without moving file persistence, parameter semantics, or tool-table semantics into the WASM core. |
|
||||||
| `tests/browser/verify_ini_panel_browser.sh` | Validates the INI SDK, WASM module loading, OPFS text-file round trip, generic session snapshot round trip, machine file text round trip, and G-code text round trip in a real browser runtime. |
|
| `tests/browser/verify_ini_panel_browser.sh` | Validates the INI SDK, INI/interpreter WASM module loading, OPFS text-file round trip, generic session snapshot round trip, machine file text round trip, G-code text round trip, and the INI panel UI's machine-session load, G-code run, and canonical-event display paths in a real browser runtime. |
|
||||||
| `tests/browser/verify_interp_browser.sh` | Validates the interpreter-core WASM module loads through the interpreter JS SDK in a real browser runtime and runs selected positive and negative canonical fixtures through vendored LinuxCNC `Interp::execute()` plus `Interp::open()`/`read()`/`execute()` via the exported C ABI, including OPFS-backed parameter-file restore/save through vendored LinuxCNC source. |
|
| `tests/browser/verify_interp_browser.sh` | Validates the interpreter-core WASM module loads through the interpreter JS SDK in a real browser runtime and runs selected positive and negative canonical fixtures through vendored LinuxCNC `Interp::execute()` plus `Interp::open()`/`read()`/`execute()` via the exported C ABI, including OPFS-backed parameter-file restore/save and tool-table load/save through vendored LinuxCNC source. |
|
||||||
| `tests/host/verify_host_smokes.sh` | Runs the current host-side Node, WASM interpreter-core, OPFS, and browser smoke validation with shared WASM builds. |
|
| `tests/host/verify_host_smokes.sh` | Runs the current host-side Node, WASM interpreter-core, OPFS, and browser smoke validation with shared WASM builds. |
|
||||||
|
|
||||||
## Fixture Coverage
|
## Fixture Coverage
|
||||||
@@ -242,12 +242,18 @@ The Node WASM interpreter smoke also covers LinuxCNC parameter-file
|
|||||||
restore/save behavior through the exported C ABI, including out-of-order file
|
restore/save behavior through the exported C ABI, including out-of-order file
|
||||||
rejection, missing-file success, required numeric parameter writeback, removal
|
rejection, missing-file success, required numeric parameter writeback, removal
|
||||||
of named-parameter-only lines from saved output, and the `.bak` backup produced
|
of named-parameter-only lines from saved output, and the `.bak` backup produced
|
||||||
by vendored `save_parameters()`.
|
by vendored `save_parameters()`. It also covers LinuxCNC tool-table
|
||||||
|
load/save behavior through vendored `tooldata_common.cc`, with the SDK only
|
||||||
|
copying text into the Emscripten filesystem and calling the exported C ABI.
|
||||||
OPFS validation covers the JavaScript host-boundary adapter, the INI browser
|
OPFS validation covers the JavaScript host-boundary adapter, the INI browser
|
||||||
smoke harness, and a browser interpreter smoke that copies OPFS-backed
|
smoke harness, the INI panel UI's machine-session load and G-code run buttons,
|
||||||
parameter text through the SDK into vendored LinuxCNC parameter-file
|
the raw canonical-event display fed directly by LinuxCNC interpreter WASM
|
||||||
restore/save. Full browser coverage, full SDK coverage, and full
|
output, the Node parameter/tool-table bridges that copy OPFS text through the
|
||||||
machine-session validation remain future work.
|
SDK into vendored LinuxCNC file APIs, the Node machine-session bridge that
|
||||||
|
groups INI, parameter, and tool-table loading, and a browser interpreter smoke
|
||||||
|
that uses the same session bridge before saving OPFS-backed parameter and
|
||||||
|
tool-table text through vendored LinuxCNC file APIs. Full browser coverage,
|
||||||
|
full SDK coverage, and richer machine-state validation remain future work.
|
||||||
|
|
||||||
## WASM/Browser Fixture Matrix
|
## WASM/Browser Fixture Matrix
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ semantic rewrites:
|
|||||||
| Canonical output | Canonical calls are captured as test events instead of driving hardware. |
|
| Canonical output | Canonical calls are captured as test events instead of driving hardware. |
|
||||||
| Feed-rate state | `SET_FEED_RATE` updates standalone canonical runtime state so vendored `convert_length_units()` can read it back through `GET_EXTERNAL_FEED_RATE()` during G20/G21 changes. |
|
| Feed-rate state | `SET_FEED_RATE` updates standalone canonical runtime state so vendored `convert_length_units()` can read it back through `GET_EXTERNAL_FEED_RATE()` during G20/G21 changes. |
|
||||||
| Tool-data reload | LinuxCNC `RELOAD_TOOLDATA` is captured as a canonical test event; browser/native tool-table reload plumbing remains a future host/runtime adapter. |
|
| Tool-data reload | LinuxCNC `RELOAD_TOOLDATA` is captured as a canonical test event; browser/native tool-table reload plumbing remains a future host/runtime adapter. |
|
||||||
|
| Tool table storage | Vendored LinuxCNC `tooldata_common.cc` owns tool-table parsing and formatting; the standalone boundary only supplies the in-memory `tooldata_get()`/`tooldata_put()` callbacks and exposes load/save through the WASM C ABI. |
|
||||||
| Tool slot status | Standalone tool adapter state supplies `GET_EXTERNAL_TOOL_SLOT()` and `GET_EXTERNAL_SELECTED_TOOL_SLOT()` for vendored `Interp::synch()`; `linuxcnc_interp_init_harness` guards current/selected slot synchronization. |
|
| Tool slot status | Standalone tool adapter state supplies `GET_EXTERNAL_TOOL_SLOT()` and `GET_EXTERNAL_SELECTED_TOOL_SLOT()` for vendored `Interp::synch()`; `linuxcnc_interp_init_harness` guards current/selected slot synchronization. |
|
||||||
| Interpreter state tags | LinuxCNC `UPDATE_TAG` callbacks are captured from the state tags packed by vendored interpreter code; standalone code does not derive modal state. |
|
| Interpreter state tags | LinuxCNC `UPDATE_TAG` callbacks are captured from the state tags packed by vendored interpreter code; standalone code does not derive modal state. |
|
||||||
| Rotary indexer lock state | LinuxCNC `UNLOCK_ROTARY` and `LOCK_ROTARY` callbacks are captured from the vendored single-axis indexer path; standalone code does not implement rotary-indexing semantics. |
|
| Rotary indexer lock state | LinuxCNC `UNLOCK_ROTARY` and `LOCK_ROTARY` callbacks are captured from the vendored single-axis indexer path; standalone code does not implement rotary-indexing semantics. |
|
||||||
@@ -43,7 +44,7 @@ semantic rewrites:
|
|||||||
| Kinematics component lifecycle | Kinematics modules are initialized through LinuxCNC module entry points where native runtime probes exist, while HAL component init/ready/exit, HAL pin allocation, and RTAPI module metadata are handled by standalone shims. |
|
| Kinematics component lifecycle | Kinematics modules are initialized through LinuxCNC module entry points where native runtime probes exist, while HAL component init/ready/exit, HAL pin allocation, and RTAPI module metadata are handled by standalone shims. |
|
||||||
| Go math C/C++ linkage | `genserkins` runtime probing compiles vendored `gomath.c` through a narrow C++ wrapper so LinuxCNC `genserfuncs.c` can link to the upstream Go math symbols without editing vendored source. |
|
| Go math C/C++ linkage | `genserkins` runtime probing compiles vendored `gomath.c` through a narrow C++ wrapper so LinuxCNC `genserfuncs.c` can link to the upstream Go math symbols without editing vendored source. |
|
||||||
| Switchkins iterative forward | `genhexkins` runtime probing follows LinuxCNC switchkins iterative-forward behavior, including the first-call warmup path before asserting roundtrip convergence. |
|
| Switchkins iterative forward | `genhexkins` runtime probing follows LinuxCNC switchkins iterative-forward behavior, including the first-call warmup path before asserting roundtrip convergence. |
|
||||||
| Browser storage | OPFS remains outside the native core; `runtime/opfs/file-service.js` owns browser text-file persistence, `runtime/opfs/path-model.js` owns host-side storage paths for INI, tool table, parameter, G-code, preview-cache, and session-snapshot content, `runtime/opfs/snapshot-store.js` owns generic JSON session snapshot persistence, `runtime/opfs/machine-file-store.js` owns pure-text machine-file and G-code persistence, and `runtime/opfs/linuxcnc-parameter-bridge.js` only copies parameter files between OPFS text storage and the LinuxCNC-backed WASM parameter-file ABI. |
|
| Browser storage | OPFS remains outside the native core; `runtime/opfs/file-service.js` owns browser text-file persistence, `runtime/opfs/path-model.js` owns host-side storage paths for INI, tool table, parameter, G-code, preview-cache, and session-snapshot content, `runtime/opfs/snapshot-store.js` owns generic JSON session snapshot persistence, `runtime/opfs/machine-file-store.js` owns pure-text machine-file and G-code persistence, `runtime/opfs/linuxcnc-parameter-bridge.js` only copies parameter files between OPFS text storage and the LinuxCNC-backed WASM parameter-file ABI, `runtime/opfs/linuxcnc-tool-table-bridge.js` only copies tool tables between OPFS text storage and the LinuxCNC-backed WASM tool-table ABI, and `runtime/opfs/linuxcnc-machine-session-bridge.js` groups INI, parameter, and tool-table loading without interpreting their CNC semantics. |
|
||||||
|
|
||||||
## Enforced Non-Drift Rules
|
## Enforced Non-Drift Rules
|
||||||
|
|
||||||
@@ -63,11 +64,13 @@ semantic rewrites:
|
|||||||
- JS SDK validation now covers the INI WASM wrapper around vendored LinuxCNC
|
- JS SDK validation now covers the INI WASM wrapper around vendored LinuxCNC
|
||||||
`inifile.cc` and the interpreter-core SDK wrapper around the existing
|
`inifile.cc` and the interpreter-core SDK wrapper around the existing
|
||||||
exported C ABI. The interpreter SDK only manages strings, Emscripten file
|
exported C ABI. The interpreter SDK only manages strings, Emscripten file
|
||||||
writes, and calls into vendored LinuxCNC execution paths.
|
writes, and calls into vendored LinuxCNC execution paths, including
|
||||||
|
parameter-file restore/save and tool-table load/save.
|
||||||
- OPFS validation covers a Node mock of the file-service adapter, the
|
- OPFS validation covers a Node mock of the file-service adapter, the
|
||||||
host-side path model, generic session snapshot storage, pure-text machine
|
host-side path model, generic session snapshot storage, pure-text machine
|
||||||
file and G-code storage, and a Chromium localhost round trip for those
|
file and G-code storage, parameter/tool-table bridge copying into the
|
||||||
persistence paths.
|
interpreter SDK filesystem, grouped machine-session loading, and a Chromium
|
||||||
|
localhost round trip for those persistence paths.
|
||||||
- Host-side smoke validation is aggregated by
|
- Host-side smoke validation is aggregated by
|
||||||
`tests/host/verify_host_smokes.sh` so Node, WASM, OPFS, and browser checks
|
`tests/host/verify_host_smokes.sh` so Node, WASM, OPFS, and browser checks
|
||||||
run from one command.
|
run from one command.
|
||||||
|
|||||||
@@ -47,13 +47,14 @@ Current validation is intentionally mechanical:
|
|||||||
| RS274 interpreter state and parser | `src/emc/rs274ngc/modal_state.*`, `interp_internal.*`, `interp_read.cc`, `interp_check.cc`, `interp_execute.cc`, `interp_find.cc`, `interp_array.cc`, `interp_queue.*`, `rs274ngc*`, `units.h` | Copy unchanged | Python/remap/runtime edges are isolated in standalone wrappers and shims; parser and execution logic remain LinuxCNC source | Vendor byte sync, per-file source probes, interpreter harness fixtures |
|
| RS274 interpreter state and parser | `src/emc/rs274ngc/modal_state.*`, `interp_internal.*`, `interp_read.cc`, `interp_check.cc`, `interp_execute.cc`, `interp_find.cc`, `interp_array.cc`, `interp_queue.*`, `rs274ngc*`, `units.h` | Copy unchanged | Python/remap/runtime edges are isolated in standalone wrappers and shims; parser and execution logic remain LinuxCNC source | Vendor byte sync, per-file source probes, interpreter harness fixtures |
|
||||||
| RS274 conversion semantics | `src/emc/rs274ngc/interp_convert.cc`, `interp_arc.cc`, `interp_inverse.cc`, `interp_cycles.cc`, `interp_g7x.cc`, `interp_o_word.cc`, `interp_write.cc` | Copy unchanged | Canonical calls are captured by standalone event sink functions; conversion behavior stays in vendored LinuxCNC files; feed-rate state is read back through the canonical runtime boundary during length-unit conversion | Vendor byte sync, per-file source probes, canonical fixture suite, no standalone `Interp::convert_g()` guard |
|
| RS274 conversion semantics | `src/emc/rs274ngc/interp_convert.cc`, `interp_arc.cc`, `interp_inverse.cc`, `interp_cycles.cc`, `interp_g7x.cc`, `interp_o_word.cc`, `interp_write.cc` | Copy unchanged | Canonical calls are captured by standalone event sink functions; conversion behavior stays in vendored LinuxCNC files; feed-rate state is read back through the canonical runtime boundary during length-unit conversion | Vendor byte sync, per-file source probes, canonical fixture suite, no standalone `Interp::convert_g()` guard |
|
||||||
| Named parameters and tool slot status | `src/emc/rs274ngc/interp_namedparams.cc`, related interpreter headers | Copy unchanged | `_ini[...]` and `_hal[...]` resolve through standalone INI/HAL adapters while lookup order stays LinuxCNC-derived; current/selected tool slot reads for vendored `Interp::synch()` come from the standalone tool adapter | Vendor byte sync, source probe, `linuxcnc_namedparam_harness`, `linuxcnc_interp_init_harness` |
|
| Named parameters and tool slot status | `src/emc/rs274ngc/interp_namedparams.cc`, related interpreter headers | Copy unchanged | `_ini[...]` and `_hal[...]` resolve through standalone INI/HAL adapters while lookup order stays LinuxCNC-derived; current/selected tool slot reads for vendored `Interp::synch()` come from the standalone tool adapter | Vendor byte sync, source probe, `linuxcnc_namedparam_harness`, `linuxcnc_interp_init_harness` |
|
||||||
|
| Tool table parsing and formatting | `src/emc/tooldata/tooldata_common.cc` | Copy unchanged plus standalone storage callbacks | Native file parsing/formatting stays in vendored LinuxCNC source; the standalone tool adapter supplies `tooldata_get()`/`tooldata_put()` storage and index lookup, while OPFS remains a host-side persistence boundary | Vendor byte sync, `linuxcnc_tooldata_common_source_probe`, `tests/wasm/node/verify_interp_wasm.sh` load/save tool-table assertions |
|
||||||
| Dynamic interpreter base | `src/emc/rs274ngc/interp_base.*` | Copy unchanged | `interp_base.cc` source probe uses standalone `EMC2_HOME` compile-time path boundary for LinuxCNC dynamic interpreter lookup | Vendor byte sync, `linuxcnc_interp_base_source_probe` |
|
| Dynamic interpreter base | `src/emc/rs274ngc/interp_base.*` | Copy unchanged | `interp_base.cc` source probe uses standalone `EMC2_HOME` compile-time path boundary for LinuxCNC dynamic interpreter lookup | Vendor byte sync, `linuxcnc_interp_base_source_probe` |
|
||||||
|
|
||||||
## Dependency Matrix
|
## Dependency Matrix
|
||||||
|
|
||||||
| Dependency | LinuxCNC files that expose it | Standalone treatment |
|
| Dependency | LinuxCNC files that expose it | Standalone treatment |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| Native file IO | `inifile.cc`, `rs274ngc_pre.cc`, parameter file paths | Allowed in native probes; the interpreter WASM C ABI validates parameter-file restore/save by calling vendored `Interp::restore_parameters()` and `Interp::save_parameters()` against Emscripten filesystem paths; browser OPFS remains a host-side adapter under `runtime/opfs/`, with path ownership in `runtime/opfs/path-model.js`, generic snapshot persistence in `runtime/opfs/snapshot-store.js`, pure-text machine-file persistence in `runtime/opfs/machine-file-store.js`, and OPFS-to-WASM parameter-file copying in `runtime/opfs/linuxcnc-parameter-bridge.js` |
|
| Native file IO | `inifile.cc`, `rs274ngc_pre.cc`, `tooldata_common.cc`, parameter file paths, tool table paths | Allowed in native probes; the interpreter WASM C ABI validates parameter-file restore/save by calling vendored `Interp::restore_parameters()` and `Interp::save_parameters()` and tool-table load/save by calling vendored `tooldata_load()` and `tooldata_save()` against Emscripten filesystem paths; browser OPFS remains a host-side adapter under `runtime/opfs/`, with path ownership in `runtime/opfs/path-model.js`, generic snapshot persistence in `runtime/opfs/snapshot-store.js`, pure-text machine-file persistence in `runtime/opfs/machine-file-store.js`, OPFS-to-WASM parameter-file copying in `runtime/opfs/linuxcnc-parameter-bridge.js`, OPFS-to-WASM tool-table copying in `runtime/opfs/linuxcnc-tool-table-bridge.js`, and grouped INI/parameter/tool-table session loading in `runtime/opfs/linuxcnc-machine-session-bridge.js` |
|
||||||
| RTAPI | `rtapi_*.h`, TP, posemath, motion headers | Minimal standalone shim in `runtime/core/shims/rtapi.h` |
|
| RTAPI | `rtapi_*.h`, TP, posemath, motion headers | Minimal standalone shim in `runtime/core/shims/rtapi.h` |
|
||||||
| NML transport | `emc.hh`, motion/NML type headers | Transport is not ported; only the status/type edges needed by vendored compute code are exposed through standalone shims and probes |
|
| NML transport | `emc.hh`, motion/NML type headers | Transport is not ported; only the status/type edges needed by vendored compute code are exposed through standalone shims and probes |
|
||||||
| HAL runtime | named parameter lookup, kinematics component lifecycle, and runtime status edges | Standalone HAL adapter under `runtime/core/linuxcnc_wrap/` |
|
| HAL runtime | named parameter lookup, kinematics component lifecycle, and runtime status edges | Standalone HAL adapter under `runtime/core/linuxcnc_wrap/` |
|
||||||
@@ -74,8 +75,9 @@ Current validation is intentionally mechanical:
|
|||||||
the current interpreter-core smoke scope. The interpreter SDK is a thin
|
the current interpreter-core smoke scope. The interpreter SDK is a thin
|
||||||
allocation, filesystem, and C ABI wrapper over vendored LinuxCNC execution
|
allocation, filesystem, and C ABI wrapper over vendored LinuxCNC execution
|
||||||
paths, including parameter-file restore/save through vendored
|
paths, including parameter-file restore/save through vendored
|
||||||
`rs274ngc_pre.cc`; it does not define G-code or parameter semantics. Full
|
`rs274ngc_pre.cc` and tool-table load/save through vendored
|
||||||
planner/session SDK coverage remains future work.
|
`tooldata_common.cc`; it does not define G-code, parameter, or tool-table
|
||||||
|
semantics. Full planner/session SDK coverage remains future work.
|
||||||
- OPFS persistence is connected to the INI panel through the host-side
|
- OPFS persistence is connected to the INI panel through the host-side
|
||||||
`runtime/opfs/file-service.js` adapter. `runtime/opfs/path-model.js` now
|
`runtime/opfs/file-service.js` adapter. `runtime/opfs/path-model.js` now
|
||||||
defines paths for INI, tool table, parameter file, G-code program,
|
defines paths for INI, tool table, parameter file, G-code program,
|
||||||
@@ -85,6 +87,10 @@ Current validation is intentionally mechanical:
|
|||||||
table, parameter file, and G-code program content.
|
table, parameter file, and G-code program content.
|
||||||
`runtime/opfs/linuxcnc-parameter-bridge.js` copies OPFS-backed parameter
|
`runtime/opfs/linuxcnc-parameter-bridge.js` copies OPFS-backed parameter
|
||||||
files into the interpreter SDK filesystem and writes back the LinuxCNC-saved
|
files into the interpreter SDK filesystem and writes back the LinuxCNC-saved
|
||||||
parameter file plus backup; UI-level session plumbing, semantic loading for
|
parameter file plus backup. `runtime/opfs/linuxcnc-tool-table-bridge.js`
|
||||||
tool tables, and machine-state restoration remain future work.
|
copies OPFS-backed tool tables into the interpreter SDK filesystem and writes
|
||||||
|
back the LinuxCNC-saved tool table.
|
||||||
|
`runtime/opfs/linuxcnc-machine-session-bridge.js` groups INI, parameter, and
|
||||||
|
tool-table loading into one host-side session load boundary. Full
|
||||||
|
machine-state restoration remains future work.
|
||||||
- Native LinuxCNC GUI code remains out of scope for implementation.
|
- Native LinuxCNC GUI code remains out of scope for implementation.
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "canon_event_sink.hh"
|
#include "canon_event_sink.hh"
|
||||||
#include "linuxcnc_hal_adapter.hh"
|
#include "linuxcnc_hal_adapter.hh"
|
||||||
#include "linuxcnc_tool_adapter.hh"
|
#include "linuxcnc_tool_adapter.hh"
|
||||||
|
#include "tooldata.hh"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -145,6 +146,35 @@ void append_parameter_state(std::ostringstream &output, const Interp &interp)
|
|||||||
output << "parameter_5399=" << interp._setup.parameters[5399] << "\n";
|
output << "parameter_5399=" << interp._setup.parameters[5399] << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void append_tool_entry(std::ostringstream &output, const char *prefix, const CANON_TOOL_TABLE &tool)
|
||||||
|
{
|
||||||
|
output << prefix << ".toolno=" << tool.toolno << "\n";
|
||||||
|
output << prefix << ".pocketno=" << tool.pocketno << "\n";
|
||||||
|
output << prefix << ".z=" << tool.offset.tran.z << "\n";
|
||||||
|
output << prefix << ".diameter=" << tool.diameter << "\n";
|
||||||
|
output << prefix << ".frontangle=" << tool.frontangle << "\n";
|
||||||
|
output << prefix << ".backangle=" << tool.backangle << "\n";
|
||||||
|
output << prefix << ".orientation=" << tool.orientation << "\n";
|
||||||
|
output << prefix << ".comment=" << tool.comment << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void append_tool_table_state(std::ostringstream &output)
|
||||||
|
{
|
||||||
|
output << "tooldata_last_index=" << tooldata_last_index_get() << "\n";
|
||||||
|
|
||||||
|
CANON_TOOL_TABLE tool = standalone::tool_entry_init();
|
||||||
|
if (standalone::get_tool_entry(&tool, 0) == 0) {
|
||||||
|
append_tool_entry(output, "tool_0", tool);
|
||||||
|
}
|
||||||
|
if (standalone::get_tool_entry(&tool, 1) == 0) {
|
||||||
|
append_tool_entry(output, "tool_1", tool);
|
||||||
|
}
|
||||||
|
if (standalone::get_tool_entry(&tool, 2) == 0) {
|
||||||
|
append_tool_entry(output, "tool_2", tool);
|
||||||
|
}
|
||||||
|
output << "tool_index_for_tool_2=" << standalone::find_tool_index_for_tool(2) << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
void append_error_text(std::ostringstream &output, Interp &interp, const char *prefix, int rc)
|
void append_error_text(std::ostringstream &output, Interp &interp, const char *prefix, int rc)
|
||||||
{
|
{
|
||||||
if (rc > INTERP_MIN_ERROR) {
|
if (rc > INTERP_MIN_ERROR) {
|
||||||
@@ -317,6 +347,30 @@ char *lcinterp_save_parameters(const char *path, const char *assignments)
|
|||||||
return copy_result(output.str());
|
return copy_result(output.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EMSCRIPTEN_KEEPALIVE
|
||||||
|
char *lcinterp_load_tool_table(const char *path)
|
||||||
|
{
|
||||||
|
standalone::reset_tool_adapter();
|
||||||
|
tooldata_init(false);
|
||||||
|
tooldata_set_db(DB_NOTUSED);
|
||||||
|
|
||||||
|
std::ostringstream output;
|
||||||
|
const int rc = tooldata_load(path);
|
||||||
|
output << "tooldata_load=" << rc << "\n";
|
||||||
|
append_tool_table_state(output);
|
||||||
|
return copy_result(output.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
EMSCRIPTEN_KEEPALIVE
|
||||||
|
char *lcinterp_save_tool_table(const char *path)
|
||||||
|
{
|
||||||
|
std::ostringstream output;
|
||||||
|
const int rc = tooldata_save(path);
|
||||||
|
output << "tooldata_save=" << rc << "\n";
|
||||||
|
append_tool_table_state(output);
|
||||||
|
return copy_result(output.str());
|
||||||
|
}
|
||||||
|
|
||||||
EMSCRIPTEN_KEEPALIVE
|
EMSCRIPTEN_KEEPALIVE
|
||||||
void lcinterp_free_string(char *value)
|
void lcinterp_free_string(char *value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
#include "tooldata.hh"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::array<CANON_TOOL_TABLE, CANON_POCKETS_MAX> &tool_table()
|
std::array<CANON_TOOL_TABLE, CANON_POCKETS_MAX> &tool_table()
|
||||||
@@ -22,6 +24,12 @@ int ¤t_tool_index_ref()
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int &last_tool_index_ref()
|
||||||
|
{
|
||||||
|
static int index = 0;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
CANON_TOOL_TABLE empty_tool()
|
CANON_TOOL_TABLE empty_tool()
|
||||||
{
|
{
|
||||||
CANON_TOOL_TABLE tool{};
|
CANON_TOOL_TABLE tool{};
|
||||||
@@ -30,6 +38,20 @@ CANON_TOOL_TABLE empty_tool()
|
|||||||
return tool;
|
return tool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CANON_TOOL_TABLE linuxcnc_empty_tool()
|
||||||
|
{
|
||||||
|
CANON_TOOL_TABLE tool{};
|
||||||
|
tool.toolno = -1;
|
||||||
|
tool.pocketno = -1;
|
||||||
|
tool.diameter = 0;
|
||||||
|
tool.frontangle = 0;
|
||||||
|
tool.backangle = 0;
|
||||||
|
tool.orientation = 0;
|
||||||
|
ZERO_EMC_POSE(tool.offset);
|
||||||
|
tool.comment[0] = 0;
|
||||||
|
return tool;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace standalone {
|
namespace standalone {
|
||||||
@@ -117,3 +139,63 @@ void change_selected_tool()
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace standalone
|
} // namespace standalone
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
toolidx_t tooldata_put(CANON_TOOL_TABLE tdata, int idx)
|
||||||
|
{
|
||||||
|
if ((idx < 0) || (idx >= CANON_POCKETS_MAX)) {
|
||||||
|
return IDX_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &tools = tool_table();
|
||||||
|
const bool is_new = tools[idx].toolno == -1;
|
||||||
|
tools[idx] = tdata;
|
||||||
|
if (idx > last_tool_index_ref()) {
|
||||||
|
last_tool_index_ref() = idx;
|
||||||
|
}
|
||||||
|
return is_new ? IDX_NEW : IDX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
toolidx_t tooldata_get(CANON_TOOL_TABLE *pdata, int idx)
|
||||||
|
{
|
||||||
|
if ((pdata == nullptr) || (idx < 0) || (idx >= CANON_POCKETS_MAX)) {
|
||||||
|
return IDX_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pdata = tool_table()[idx];
|
||||||
|
return IDX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tooldata_reset(void)
|
||||||
|
{
|
||||||
|
auto &tools = tool_table();
|
||||||
|
for (int idx = 0; idx < CANON_POCKETS_MAX; ++idx) {
|
||||||
|
tools[idx] = linuxcnc_empty_tool();
|
||||||
|
}
|
||||||
|
selected_tool_index_ref() = -1;
|
||||||
|
current_tool_index_ref() = 0;
|
||||||
|
last_tool_index_ref() = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tooldata_last_index_set(int idx)
|
||||||
|
{
|
||||||
|
last_tool_index_ref() = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tooldata_last_index_get(void)
|
||||||
|
{
|
||||||
|
return last_tool_index_ref();
|
||||||
|
}
|
||||||
|
|
||||||
|
int tooldata_find_index_for_tool(int toolno)
|
||||||
|
{
|
||||||
|
return standalone::find_tool_index_for_tool(toolno);
|
||||||
|
}
|
||||||
|
|
||||||
|
int tooldata_db_getall(void)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // extern "C"
|
||||||
|
|||||||
50
wasm-port/runtime/core/shims/tooldata.hh
Normal file
50
wasm-port/runtime/core/shims/tooldata.hh
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "emc/nml_intf/canon.hh"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
IDX_OK = 0,
|
||||||
|
IDX_NEW,
|
||||||
|
IDX_FAIL,
|
||||||
|
} toolidx_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
DB_NOTUSED = 0,
|
||||||
|
DB_ACTIVE,
|
||||||
|
} tooldb_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SPINDLE_LOAD,
|
||||||
|
SPINDLE_UNLOAD,
|
||||||
|
TOOL_OFFSET,
|
||||||
|
} tool_notify_t;
|
||||||
|
|
||||||
|
struct CANON_TOOL_TABLE tooldata_entry_init(void);
|
||||||
|
toolidx_t tooldata_put(struct CANON_TOOL_TABLE tdata, int idx);
|
||||||
|
toolidx_t tooldata_get(CANON_TOOL_TABLE *pdata, int idx);
|
||||||
|
|
||||||
|
void tooldata_init(bool random_tool_changer);
|
||||||
|
void tooldata_reset(void);
|
||||||
|
void tooldata_last_index_set(int idx);
|
||||||
|
int tooldata_last_index_get(void);
|
||||||
|
int tooldata_find_index_for_tool(int toolno);
|
||||||
|
|
||||||
|
void tooldata_format_toolline(int idx,
|
||||||
|
bool ignore_zero_values,
|
||||||
|
CANON_TOOL_TABLE tdata,
|
||||||
|
char formatted_line[CANON_TOOL_ENTRY_LEN]);
|
||||||
|
|
||||||
|
void tooldata_add_init(int nonrandom_start_idx);
|
||||||
|
int tooldata_read_entry(const char *input_line);
|
||||||
|
|
||||||
|
void tooldata_set_db(tooldb_t mode);
|
||||||
|
int tooldata_load(const char *filename);
|
||||||
|
int tooldata_save(const char *filename);
|
||||||
|
|
||||||
|
#define DB_SPINDLE_SAVE "./db_spindle.tbl"
|
||||||
|
|
||||||
|
int tooldata_db_getall(void);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,23 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "emc/nml_intf/emctool.h"
|
#include "../tooldata.hh"
|
||||||
#include "linuxcnc_tool_adapter.hh"
|
|
||||||
|
|
||||||
enum {
|
|
||||||
IDX_OK = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
inline CANON_TOOL_TABLE tooldata_entry_init()
|
|
||||||
{
|
|
||||||
return standalone::tool_entry_init();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int tooldata_find_index_for_tool(int toolno)
|
|
||||||
{
|
|
||||||
return standalone::find_tool_index_for_tool(toolno);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int tooldata_get(CANON_TOOL_TABLE *tool, int index)
|
|
||||||
{
|
|
||||||
return standalone::get_tool_entry(tool, index) == 0 ? IDX_OK : -1;
|
|
||||||
}
|
|
||||||
|
|||||||
59
wasm-port/runtime/opfs/linuxcnc-machine-session-bridge.js
Normal file
59
wasm-port/runtime/opfs/linuxcnc-machine-session-bridge.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import { loadTextFile } from "./file-service.js";
|
||||||
|
import {
|
||||||
|
machineIniPath,
|
||||||
|
parameterFilePath,
|
||||||
|
toolTablePath,
|
||||||
|
} from "./path-model.js";
|
||||||
|
import { restoreMachineParametersFromOpfs } from "./linuxcnc-parameter-bridge.js";
|
||||||
|
import { loadMachineToolTableFromOpfs } from "./linuxcnc-tool-table-bridge.js";
|
||||||
|
|
||||||
|
const DEFAULT_WASM_INI_PATH = "/work/machine.ini";
|
||||||
|
const DEFAULT_WASM_PARAMETER_PATH = "/work/linuxcnc.var";
|
||||||
|
const DEFAULT_WASM_TOOL_TABLE_PATH = "/work/tool.tbl";
|
||||||
|
|
||||||
|
function requireSessionSdk(interp) {
|
||||||
|
if (typeof interp?.writeTextFile !== "function") {
|
||||||
|
throw new Error("interpreter SDK is missing writeTextFile().");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveSessionPaths(machineId, options = {}) {
|
||||||
|
return {
|
||||||
|
iniOpfsPath: options.iniOpfsPath ?? machineIniPath(machineId, options.iniFilename),
|
||||||
|
iniWasmPath: options.iniWasmPath ?? DEFAULT_WASM_INI_PATH,
|
||||||
|
parameterOpfsPath:
|
||||||
|
options.parameterOpfsPath ?? parameterFilePath(machineId, options.parameterFilename),
|
||||||
|
parameterWasmPath: options.parameterWasmPath ?? DEFAULT_WASM_PARAMETER_PATH,
|
||||||
|
toolTableOpfsPath:
|
||||||
|
options.toolTableOpfsPath ?? toolTablePath(machineId, options.toolTableFilename),
|
||||||
|
toolTableWasmPath: options.toolTableWasmPath ?? DEFAULT_WASM_TOOL_TABLE_PATH,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loadMachineSessionFromOpfs(interp, machineId, options = {}) {
|
||||||
|
requireSessionSdk(interp);
|
||||||
|
const paths = resolveSessionPaths(machineId, options);
|
||||||
|
const iniText = await loadTextFile(paths.iniOpfsPath, options.storage);
|
||||||
|
interp.writeTextFile(paths.iniWasmPath, iniText);
|
||||||
|
|
||||||
|
const parameters = await restoreMachineParametersFromOpfs(interp, machineId, {
|
||||||
|
storage: options.storage,
|
||||||
|
opfsPath: paths.parameterOpfsPath,
|
||||||
|
wasmPath: paths.parameterWasmPath,
|
||||||
|
});
|
||||||
|
const toolTable = await loadMachineToolTableFromOpfs(interp, machineId, {
|
||||||
|
storage: options.storage,
|
||||||
|
opfsPath: paths.toolTableOpfsPath,
|
||||||
|
wasmPath: paths.toolTableWasmPath,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
machineId,
|
||||||
|
ini: {
|
||||||
|
opfsPath: paths.iniOpfsPath,
|
||||||
|
wasmPath: paths.iniWasmPath,
|
||||||
|
},
|
||||||
|
parameters,
|
||||||
|
toolTable,
|
||||||
|
};
|
||||||
|
}
|
||||||
46
wasm-port/runtime/opfs/linuxcnc-tool-table-bridge.js
Normal file
46
wasm-port/runtime/opfs/linuxcnc-tool-table-bridge.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { loadTextFile, saveTextFile } from "./file-service.js";
|
||||||
|
import { toolTablePath } from "./path-model.js";
|
||||||
|
|
||||||
|
const DEFAULT_WASM_TOOL_TABLE_PATH = "/work/tool.tbl";
|
||||||
|
|
||||||
|
function requireToolTableSdk(interp) {
|
||||||
|
for (const method of ["writeTextFile", "readTextFile", "loadToolTable", "saveToolTable"]) {
|
||||||
|
if (typeof interp?.[method] !== "function") {
|
||||||
|
throw new Error(`interpreter SDK is missing ${method}().`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolvePaths(machineId, options = {}) {
|
||||||
|
const opfsPath = options.opfsPath ?? toolTablePath(machineId, options.filename);
|
||||||
|
const wasmPath = options.wasmPath ?? DEFAULT_WASM_TOOL_TABLE_PATH;
|
||||||
|
return { opfsPath, wasmPath };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loadMachineToolTableFromOpfs(interp, machineId, options = {}) {
|
||||||
|
requireToolTableSdk(interp);
|
||||||
|
const { opfsPath, wasmPath } = resolvePaths(machineId, options);
|
||||||
|
const text = await loadTextFile(opfsPath, options.storage);
|
||||||
|
interp.writeTextFile(wasmPath, text);
|
||||||
|
return {
|
||||||
|
opfsPath,
|
||||||
|
wasmPath,
|
||||||
|
result: interp.loadToolTable(wasmPath),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveMachineToolTableToOpfs(interp, machineId, options = {}) {
|
||||||
|
requireToolTableSdk(interp);
|
||||||
|
const { opfsPath, wasmPath } = resolvePaths(machineId, options);
|
||||||
|
const result = interp.saveToolTable(wasmPath);
|
||||||
|
const savedText = interp.readTextFile(wasmPath);
|
||||||
|
|
||||||
|
await saveTextFile(opfsPath, savedText, options.storage);
|
||||||
|
|
||||||
|
return {
|
||||||
|
opfsPath,
|
||||||
|
wasmPath,
|
||||||
|
result,
|
||||||
|
savedText,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -40,5 +40,7 @@ vendored LinuxCNC RS274NGC sources and exposes:
|
|||||||
- `runFileWithIni(path, iniPath)`
|
- `runFileWithIni(path, iniPath)`
|
||||||
- `restoreParameters(path)`
|
- `restoreParameters(path)`
|
||||||
- `saveParameters(path, values)`
|
- `saveParameters(path, values)`
|
||||||
|
- `loadToolTable(path)`
|
||||||
|
- `saveToolTable(path)`
|
||||||
- `writeTextFile(path, text)`
|
- `writeTextFile(path, text)`
|
||||||
- `readTextFile(path)`
|
- `readTextFile(path)`
|
||||||
|
|||||||
@@ -84,5 +84,13 @@ export async function createLinuxCncInterpSdk(moduleOptions = {}) {
|
|||||||
.join("\n");
|
.join("\n");
|
||||||
return callStringResult(mod, "lcinterp_save_parameters", path, assignments);
|
return callStringResult(mod, "lcinterp_save_parameters", path, assignments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
loadToolTable(path) {
|
||||||
|
return callStringResult(mod, "lcinterp_load_tool_table", path);
|
||||||
|
},
|
||||||
|
|
||||||
|
saveToolTable(path) {
|
||||||
|
return callStringResult(mod, "lcinterp_save_tool_table", path);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,58 @@
|
|||||||
import { createLinuxCncIniSdk } from "../../sdk/src/index.js";
|
import {
|
||||||
|
createLinuxCncIniSdk,
|
||||||
|
createLinuxCncInterpSdk,
|
||||||
|
} from "../../sdk/src/index.js";
|
||||||
import {
|
import {
|
||||||
getOpfsRoot,
|
getOpfsRoot,
|
||||||
loadTextFile,
|
loadTextFile,
|
||||||
saveTextFile,
|
saveTextFile,
|
||||||
} from "../../opfs/file-service.js";
|
} from "../../opfs/file-service.js";
|
||||||
|
import {
|
||||||
|
loadGcodeProgram,
|
||||||
|
loadMachineTextFiles,
|
||||||
|
machineFilePaths,
|
||||||
|
saveGcodeProgram,
|
||||||
|
saveMachineTextFiles,
|
||||||
|
} from "../../opfs/machine-file-store.js";
|
||||||
|
import {
|
||||||
|
loadMachineSessionFromOpfs,
|
||||||
|
} from "../../opfs/linuxcnc-machine-session-bridge.js";
|
||||||
|
|
||||||
const SAMPLE_PATH =
|
const SAMPLE_PATH =
|
||||||
"../../../linuxcnc/configs/sim/axis/vismach/5axis/table-dual-rotary/xyzab-tdr.ini";
|
"../../../linuxcnc/configs/sim/axis/vismach/5axis/table-dual-rotary/xyzab-tdr.ini";
|
||||||
const OPFS_FILE = "linuxcnc/xyzab-tdr.ini";
|
const MACHINE_ID = "xyzab-tdr";
|
||||||
|
const MACHINE_PATHS = machineFilePaths(MACHINE_ID);
|
||||||
|
const OPFS_FILE = MACHINE_PATHS.ini;
|
||||||
const WASM_FILE = "/work/xyzab-tdr.ini";
|
const WASM_FILE = "/work/xyzab-tdr.ini";
|
||||||
|
const SESSION_WASM_FILES = {
|
||||||
|
iniWasmPath: "/work/session-machine.ini",
|
||||||
|
parameterWasmPath: "/work/session-linuxcnc.var",
|
||||||
|
toolTableWasmPath: "/work/session-tool.tbl",
|
||||||
|
};
|
||||||
|
const GCODE_FILENAME = "ui-session.ngc";
|
||||||
|
const GCODE_WASM_FILE = "/work/ui-session.ngc";
|
||||||
|
const DEFAULT_TOOL_TABLE = "T2 P7 Z3.125 D1.5 I12 J34 Q4 ;ui session tool\n";
|
||||||
|
const DEFAULT_PARAMETERS = [
|
||||||
|
"5161 0.0",
|
||||||
|
"5162 0.0",
|
||||||
|
"5220 1",
|
||||||
|
"5221 0.0",
|
||||||
|
"5399 0.0",
|
||||||
|
"",
|
||||||
|
].join("\n");
|
||||||
|
const DEFAULT_GCODE = [
|
||||||
|
"G0 X1.0 Y2.0 (Comment)",
|
||||||
|
"G1 X3.0 Y4.0 F120.0",
|
||||||
|
"",
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
const editor = document.getElementById("ini-editor");
|
const editor = document.getElementById("ini-editor");
|
||||||
const logNode = document.getElementById("log");
|
const logNode = document.getElementById("log");
|
||||||
|
const eventNode = document.getElementById("canon-events");
|
||||||
|
const eventFilterNode = document.getElementById("event-filter");
|
||||||
|
const eventCountNode = document.getElementById("event-count");
|
||||||
const wasmBadge = document.getElementById("wasm-badge");
|
const wasmBadge = document.getElementById("wasm-badge");
|
||||||
|
const interpBadge = document.getElementById("interp-badge");
|
||||||
const opfsBadge = document.getElementById("opfs-badge");
|
const opfsBadge = document.getElementById("opfs-badge");
|
||||||
|
|
||||||
const fields = {
|
const fields = {
|
||||||
@@ -22,9 +62,17 @@ const fields = {
|
|||||||
joints: document.getElementById("field-joints"),
|
joints: document.getElementById("field-joints"),
|
||||||
coordinates: document.getElementById("field-coordinates"),
|
coordinates: document.getElementById("field-coordinates"),
|
||||||
parameterFile: document.getElementById("field-parameter-file"),
|
parameterFile: document.getElementById("field-parameter-file"),
|
||||||
|
sessionIni: document.getElementById("field-session-ini"),
|
||||||
|
sessionParameters: document.getElementById("field-session-parameters"),
|
||||||
|
sessionToolTable: document.getElementById("field-session-tool-table"),
|
||||||
|
sessionGcode: document.getElementById("field-session-gcode"),
|
||||||
|
runStatus: document.getElementById("field-run-status"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let iniSdk = null;
|
let iniSdk = null;
|
||||||
|
let interpSdk = null;
|
||||||
|
let loadedSession = null;
|
||||||
|
let canonicalEventText = "";
|
||||||
|
|
||||||
function setBadge(node, text, className = "badge") {
|
function setBadge(node, text, className = "badge") {
|
||||||
node.className = className;
|
node.className = className;
|
||||||
@@ -36,17 +84,40 @@ function setLog(message, isError = false) {
|
|||||||
logNode.className = `log${isError ? " danger" : ""}`;
|
logNode.className = `log${isError ? " danger" : ""}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setCanonicalEvents(text) {
|
||||||
|
canonicalEventText = text || "";
|
||||||
|
renderCanonicalEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderCanonicalEvents() {
|
||||||
|
const lines = canonicalEventText.split("\n").filter(Boolean);
|
||||||
|
const filter = eventFilterNode.value.trim().toLowerCase();
|
||||||
|
const visibleLines = filter
|
||||||
|
? lines.filter((line) => line.toLowerCase().includes(filter))
|
||||||
|
: lines;
|
||||||
|
|
||||||
|
eventNode.textContent = visibleLines.join("\n");
|
||||||
|
eventCountNode.textContent = `${visibleLines.length} / ${lines.length}`;
|
||||||
|
}
|
||||||
|
|
||||||
function setField(name, value) {
|
function setField(name, value) {
|
||||||
fields[name].textContent = value ?? "-";
|
fields[name].textContent = value ?? "-";
|
||||||
}
|
}
|
||||||
|
|
||||||
function requireIniSdk() {
|
function requireIniSdk() {
|
||||||
if (!iniSdk) {
|
if (!iniSdk) {
|
||||||
throw new Error("WASM module is not ready yet.");
|
throw new Error("INI WASM module is not ready yet.");
|
||||||
}
|
}
|
||||||
return iniSdk;
|
return iniSdk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function requireInterpSdk() {
|
||||||
|
if (!interpSdk) {
|
||||||
|
throw new Error("Interpreter WASM module is not ready yet.");
|
||||||
|
}
|
||||||
|
return interpSdk;
|
||||||
|
}
|
||||||
|
|
||||||
function syncEditorToWasmFs() {
|
function syncEditorToWasmFs() {
|
||||||
requireIniSdk().writeTextFile(WASM_FILE, editor.value);
|
requireIniSdk().writeTextFile(WASM_FILE, editor.value);
|
||||||
}
|
}
|
||||||
@@ -64,10 +135,19 @@ async function loadSample() {
|
|||||||
async function boot() {
|
async function boot() {
|
||||||
try {
|
try {
|
||||||
iniSdk = await createLinuxCncIniSdk();
|
iniSdk = await createLinuxCncIniSdk();
|
||||||
setBadge(wasmBadge, "WASM: ready");
|
setBadge(wasmBadge, "INI WASM: ready");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setBadge(wasmBadge, "WASM: failed", "badge danger");
|
setBadge(wasmBadge, "INI WASM: failed", "badge danger");
|
||||||
setLog(`WASM init failed: ${error.message}`, true);
|
setLog(`INI WASM init failed: ${error.message}`, true);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
interpSdk = await createLinuxCncInterpSdk();
|
||||||
|
setBadge(interpBadge, "Interpreter WASM: ready");
|
||||||
|
} catch (error) {
|
||||||
|
setBadge(interpBadge, "Interpreter WASM: failed", "badge danger");
|
||||||
|
setLog(`Interpreter WASM init failed: ${error.message}`, true);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +177,78 @@ document.getElementById("save-opfs").addEventListener("click", async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById("save-machine-files").addEventListener("click", async () => {
|
||||||
|
try {
|
||||||
|
const paths = await saveMachineTextFiles(MACHINE_ID, {
|
||||||
|
ini: editor.value,
|
||||||
|
toolTable: DEFAULT_TOOL_TABLE,
|
||||||
|
parameters: DEFAULT_PARAMETERS,
|
||||||
|
});
|
||||||
|
const gcodePath = await saveGcodeProgram(GCODE_FILENAME, DEFAULT_GCODE);
|
||||||
|
setLog(
|
||||||
|
[
|
||||||
|
"Saved machine text files to OPFS.",
|
||||||
|
`INI: ${paths.ini}`,
|
||||||
|
`Tool table: ${paths.toolTable}`,
|
||||||
|
`Parameters: ${paths.parameters}`,
|
||||||
|
`G-code: ${gcodePath}`,
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
setLog(`Machine file save failed: ${error.message}`, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("load-session").addEventListener("click", async () => {
|
||||||
|
try {
|
||||||
|
loadedSession = await loadMachineSessionFromOpfs(
|
||||||
|
requireInterpSdk(),
|
||||||
|
MACHINE_ID,
|
||||||
|
SESSION_WASM_FILES,
|
||||||
|
);
|
||||||
|
setField("sessionIni", loadedSession.ini.wasmPath);
|
||||||
|
setField("sessionParameters", loadedSession.parameters.wasmPath);
|
||||||
|
setField("sessionToolTable", loadedSession.toolTable.wasmPath);
|
||||||
|
setLog(
|
||||||
|
[
|
||||||
|
"Loaded machine session into the interpreter WASM filesystem.",
|
||||||
|
`INI: ${loadedSession.ini.opfsPath} -> ${loadedSession.ini.wasmPath}`,
|
||||||
|
`Parameters: ${loadedSession.parameters.result.trim()}`,
|
||||||
|
`Tool table: ${loadedSession.toolTable.result.trim()}`,
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
setLog(`Machine session load failed: ${error.message}`, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("run-gcode").addEventListener("click", async () => {
|
||||||
|
try {
|
||||||
|
if (!loadedSession) {
|
||||||
|
throw new Error("Load a machine session before running G-code.");
|
||||||
|
}
|
||||||
|
const interp = requireInterpSdk();
|
||||||
|
const programText = await loadGcodeProgram(GCODE_FILENAME);
|
||||||
|
interp.writeTextFile(GCODE_WASM_FILE, programText);
|
||||||
|
const result = interp.runFileWithIni(GCODE_WASM_FILE, loadedSession.ini.wasmPath);
|
||||||
|
setField("sessionGcode", GCODE_WASM_FILE);
|
||||||
|
setField("runStatus", "ok");
|
||||||
|
setCanonicalEvents(result.trim());
|
||||||
|
setLog(
|
||||||
|
[
|
||||||
|
"Ran G-code through LinuxCNC interpreter WASM.",
|
||||||
|
`Program: ${GCODE_WASM_FILE}`,
|
||||||
|
`INI: ${loadedSession.ini.wasmPath}`,
|
||||||
|
result.trim(),
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
setField("runStatus", "failed");
|
||||||
|
setCanonicalEvents("");
|
||||||
|
setLog(`G-code run failed: ${error.message}`, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("load-opfs").addEventListener("click", async () => {
|
document.getElementById("load-opfs").addEventListener("click", async () => {
|
||||||
try {
|
try {
|
||||||
editor.value = await loadTextFile(OPFS_FILE);
|
editor.value = await loadTextFile(OPFS_FILE);
|
||||||
@@ -137,4 +289,25 @@ document.getElementById("query").addEventListener("click", async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById("load-machine-files").addEventListener("click", async () => {
|
||||||
|
try {
|
||||||
|
const files = await loadMachineTextFiles(MACHINE_ID);
|
||||||
|
editor.value = files.ini;
|
||||||
|
setLog(
|
||||||
|
[
|
||||||
|
"Loaded machine text files from OPFS.",
|
||||||
|
`INI bytes: ${files.ini.length}`,
|
||||||
|
`Tool table bytes: ${files.toolTable.length}`,
|
||||||
|
`Parameter bytes: ${files.parameters.length}`,
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
setLog(`Machine file load failed: ${error.message}`, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
eventFilterNode.addEventListener("input", () => {
|
||||||
|
renderCanonicalEvents();
|
||||||
|
});
|
||||||
|
|
||||||
boot().catch(() => {});
|
boot().catch(() => {});
|
||||||
|
|||||||
@@ -123,6 +123,32 @@
|
|||||||
font: 13px/1.5 "SFMono-Regular", "Consolas", monospace;
|
font: 13px/1.5 "SFMono-Regular", "Consolas", monospace;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
.events {
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fbfdff;
|
||||||
|
padding: 12px;
|
||||||
|
min-height: 180px;
|
||||||
|
max-height: 320px;
|
||||||
|
overflow: auto;
|
||||||
|
font: 12px/1.5 "SFMono-Regular", "Consolas", monospace;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
.event-tools {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) auto;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
input {
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 9px 10px;
|
||||||
|
font: 13px/1.4 "SFMono-Regular", "Consolas", monospace;
|
||||||
|
color: var(--text);
|
||||||
|
background: #fbfdff;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
.danger { color: var(--danger); }
|
.danger { color: var(--danger); }
|
||||||
@media (max-width: 960px) {
|
@media (max-width: 960px) {
|
||||||
.grid { grid-template-columns: 1fr; }
|
.grid { grid-template-columns: 1fr; }
|
||||||
@@ -148,8 +174,12 @@
|
|||||||
<button id="load-sample" class="primary">Load LinuxCNC Sample</button>
|
<button id="load-sample" class="primary">Load LinuxCNC Sample</button>
|
||||||
<button id="save-opfs">Save To OPFS</button>
|
<button id="save-opfs">Save To OPFS</button>
|
||||||
<button id="load-opfs">Load From OPFS</button>
|
<button id="load-opfs">Load From OPFS</button>
|
||||||
|
<button id="save-machine-files">Save Machine Files</button>
|
||||||
|
<button id="load-machine-files">Load Machine Files</button>
|
||||||
<button id="sync-wasm">Sync To WASM FS</button>
|
<button id="sync-wasm">Sync To WASM FS</button>
|
||||||
<button id="query" class="secondary">Query LinuxCNC Fields</button>
|
<button id="query" class="secondary">Query LinuxCNC Fields</button>
|
||||||
|
<button id="load-session" class="secondary">Load Machine Session</button>
|
||||||
|
<button id="run-gcode" class="secondary">Run G-code</button>
|
||||||
</div>
|
</div>
|
||||||
<textarea id="ini-editor" spellcheck="false"></textarea>
|
<textarea id="ini-editor" spellcheck="false"></textarea>
|
||||||
</section>
|
</section>
|
||||||
@@ -157,7 +187,8 @@
|
|||||||
<section class="panel">
|
<section class="panel">
|
||||||
<h2>Control Panel</h2>
|
<h2>Control Panel</h2>
|
||||||
<div class="status">
|
<div class="status">
|
||||||
<div><span id="wasm-badge" class="badge">WASM: loading</span></div>
|
<div><span id="wasm-badge" class="badge">INI WASM: loading</span></div>
|
||||||
|
<div><span id="interp-badge" class="badge">Interpreter WASM: loading</span></div>
|
||||||
<div><span id="opfs-badge" class="badge">OPFS: checking</span></div>
|
<div><span id="opfs-badge" class="badge">OPFS: checking</span></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -175,12 +206,29 @@
|
|||||||
<dt>Parameter File</dt>
|
<dt>Parameter File</dt>
|
||||||
<dd id="field-parameter-file">-</dd>
|
<dd id="field-parameter-file">-</dd>
|
||||||
<dt>OPFS Path</dt>
|
<dt>OPFS Path</dt>
|
||||||
<dd id="field-opfs-path">linuxcnc/xyzab-tdr.ini</dd>
|
<dd id="field-opfs-path">linuxcnc/machines/xyzab-tdr/machine.ini</dd>
|
||||||
<dt>WASM Path</dt>
|
<dt>WASM Path</dt>
|
||||||
<dd id="field-wasm-path">/work/xyzab-tdr.ini</dd>
|
<dd id="field-wasm-path">/work/xyzab-tdr.ini</dd>
|
||||||
|
<dt>Session INI</dt>
|
||||||
|
<dd id="field-session-ini">-</dd>
|
||||||
|
<dt>Session Params</dt>
|
||||||
|
<dd id="field-session-parameters">-</dd>
|
||||||
|
<dt>Session Tools</dt>
|
||||||
|
<dd id="field-session-tool-table">-</dd>
|
||||||
|
<dt>Session G-code</dt>
|
||||||
|
<dd id="field-session-gcode">-</dd>
|
||||||
|
<dt>Run Status</dt>
|
||||||
|
<dd id="field-run-status">-</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<div class="log" id="log"></div>
|
<div class="log" id="log"></div>
|
||||||
|
|
||||||
|
<h2>Canonical Events</h2>
|
||||||
|
<div class="event-tools">
|
||||||
|
<input id="event-filter" type="search" placeholder="Filter event text">
|
||||||
|
<span id="event-count" class="badge">0 / 0</span>
|
||||||
|
</div>
|
||||||
|
<pre class="events" id="canon-events"></pre>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -29,6 +29,33 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delay(ms) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitFor(predicate, label) {
|
||||||
|
const deadline = performance.now() + 8000;
|
||||||
|
while (performance.now() < deadline) {
|
||||||
|
const value = predicate();
|
||||||
|
if (value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
await delay(50);
|
||||||
|
}
|
||||||
|
throw new Error(`Timed out waiting for ${label}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadUiFrame() {
|
||||||
|
const frame = document.createElement("iframe");
|
||||||
|
frame.src = "../../runtime/ui/ini-panel/index.html";
|
||||||
|
document.body.appendChild(frame);
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
frame.addEventListener("load", resolve, { once: true });
|
||||||
|
frame.addEventListener("error", reject, { once: true });
|
||||||
|
});
|
||||||
|
return frame.contentDocument;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ini = await createLinuxCncIniSdk();
|
const ini = await createLinuxCncIniSdk();
|
||||||
const wasmPath = "/work/browser-smoke.ini";
|
const wasmPath = "/work/browser-smoke.ini";
|
||||||
@@ -90,6 +117,95 @@ JOINTS = 3
|
|||||||
await saveGcodeProgram("browser-smoke.ngc", "G0 X0 Y0\nM2\n");
|
await saveGcodeProgram("browser-smoke.ngc", "G0 X0 Y0\nM2\n");
|
||||||
assertEqual(await loadGcodeProgram("browser-smoke.ngc"), "G0 X0 Y0\nM2\n", "gcode text");
|
assertEqual(await loadGcodeProgram("browser-smoke.ngc"), "G0 X0 Y0\nM2\n", "gcode text");
|
||||||
|
|
||||||
|
const uiDocument = await loadUiFrame();
|
||||||
|
await waitFor(
|
||||||
|
() => uiDocument.getElementById("wasm-badge")?.textContent.includes("ready"),
|
||||||
|
"INI panel INI WASM readiness",
|
||||||
|
);
|
||||||
|
await waitFor(
|
||||||
|
() => uiDocument.getElementById("interp-badge")?.textContent.includes("ready"),
|
||||||
|
"INI panel interpreter WASM readiness",
|
||||||
|
);
|
||||||
|
await waitFor(
|
||||||
|
() => uiDocument.getElementById("opfs-badge")?.textContent.includes("ready"),
|
||||||
|
"INI panel OPFS readiness",
|
||||||
|
);
|
||||||
|
|
||||||
|
uiDocument.getElementById("ini-editor").value = iniText;
|
||||||
|
uiDocument.getElementById("save-machine-files").click();
|
||||||
|
await waitFor(
|
||||||
|
() => uiDocument.getElementById("log")?.textContent.includes("Saved machine text files"),
|
||||||
|
"machine file save",
|
||||||
|
);
|
||||||
|
uiDocument.getElementById("load-session").click();
|
||||||
|
await waitFor(
|
||||||
|
() => uiDocument.getElementById("log")?.textContent.includes("Loaded machine session"),
|
||||||
|
"machine session load",
|
||||||
|
);
|
||||||
|
assertEqual(
|
||||||
|
uiDocument.getElementById("field-session-ini").textContent,
|
||||||
|
"/work/session-machine.ini",
|
||||||
|
"UI session INI path",
|
||||||
|
);
|
||||||
|
assertEqual(
|
||||||
|
uiDocument.getElementById("field-session-parameters").textContent,
|
||||||
|
"/work/session-linuxcnc.var",
|
||||||
|
"UI session parameter path",
|
||||||
|
);
|
||||||
|
assertEqual(
|
||||||
|
uiDocument.getElementById("field-session-tool-table").textContent,
|
||||||
|
"/work/session-tool.tbl",
|
||||||
|
"UI session tool table path",
|
||||||
|
);
|
||||||
|
const uiLog = uiDocument.getElementById("log").textContent;
|
||||||
|
if (!uiLog.includes("restore_parameters=0") || !uiLog.includes("tooldata_load=0")) {
|
||||||
|
throw new Error(`UI session log missing LinuxCNC load result: ${uiLog}`);
|
||||||
|
}
|
||||||
|
uiDocument.getElementById("run-gcode").click();
|
||||||
|
await waitFor(
|
||||||
|
() => uiDocument.getElementById("log")?.textContent.includes("Ran G-code"),
|
||||||
|
"G-code run",
|
||||||
|
);
|
||||||
|
assertEqual(
|
||||||
|
uiDocument.getElementById("field-session-gcode").textContent,
|
||||||
|
"/work/ui-session.ngc",
|
||||||
|
"UI session G-code path",
|
||||||
|
);
|
||||||
|
assertEqual(
|
||||||
|
uiDocument.getElementById("field-run-status").textContent,
|
||||||
|
"ok",
|
||||||
|
"UI G-code run status",
|
||||||
|
);
|
||||||
|
const runLog = uiDocument.getElementById("log").textContent;
|
||||||
|
if (
|
||||||
|
!runLog.includes("canon_event=STRAIGHT_TRAVERSE") ||
|
||||||
|
!runLog.includes("canon_event=STRAIGHT_FEED")
|
||||||
|
) {
|
||||||
|
throw new Error(`UI G-code run missing LinuxCNC canonical events: ${runLog}`);
|
||||||
|
}
|
||||||
|
const eventText = uiDocument.getElementById("canon-events").textContent;
|
||||||
|
if (
|
||||||
|
!eventText.includes("canon_event=STRAIGHT_TRAVERSE") ||
|
||||||
|
!eventText.includes("canon_event=STRAIGHT_FEED")
|
||||||
|
) {
|
||||||
|
throw new Error(`UI canonical event panel missing LinuxCNC events: ${eventText}`);
|
||||||
|
}
|
||||||
|
const eventFilter = uiDocument.getElementById("event-filter");
|
||||||
|
eventFilter.value = "STRAIGHT_FEED";
|
||||||
|
eventFilter.dispatchEvent(new Event("input", { bubbles: true }));
|
||||||
|
const filteredEventText = uiDocument.getElementById("canon-events").textContent;
|
||||||
|
if (
|
||||||
|
filteredEventText.includes("canon_event=STRAIGHT_TRAVERSE") ||
|
||||||
|
!filteredEventText.includes("canon_event=STRAIGHT_FEED")
|
||||||
|
) {
|
||||||
|
throw new Error(`UI canonical event filter did not preserve raw LinuxCNC lines: ${filteredEventText}`);
|
||||||
|
}
|
||||||
|
assertEqual(
|
||||||
|
uiDocument.getElementById("event-count").textContent,
|
||||||
|
"1 / 4",
|
||||||
|
"UI canonical event count",
|
||||||
|
);
|
||||||
|
|
||||||
status.textContent = "browser_ini_opfs_smoke=ok";
|
status.textContent = "browser_ini_opfs_smoke=ok";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
status.textContent = `browser_ini_opfs_smoke=fail ${error.stack || error.message}`;
|
status.textContent = `browser_ini_opfs_smoke=fail ${error.stack || error.message}`;
|
||||||
|
|||||||
@@ -9,9 +9,14 @@
|
|||||||
<script type="module">
|
<script type="module">
|
||||||
import { createLinuxCncInterpSdk } from "../../runtime/sdk/src/index.js";
|
import { createLinuxCncInterpSdk } from "../../runtime/sdk/src/index.js";
|
||||||
import {
|
import {
|
||||||
restoreMachineParametersFromOpfs,
|
|
||||||
saveMachineParametersToOpfs,
|
saveMachineParametersToOpfs,
|
||||||
} from "../../runtime/opfs/linuxcnc-parameter-bridge.js";
|
} from "../../runtime/opfs/linuxcnc-parameter-bridge.js";
|
||||||
|
import {
|
||||||
|
saveMachineToolTableToOpfs,
|
||||||
|
} from "../../runtime/opfs/linuxcnc-tool-table-bridge.js";
|
||||||
|
import {
|
||||||
|
loadMachineSessionFromOpfs,
|
||||||
|
} from "../../runtime/opfs/linuxcnc-machine-session-bridge.js";
|
||||||
import {
|
import {
|
||||||
loadMachineTextFiles,
|
loadMachineTextFiles,
|
||||||
saveMachineTextFiles,
|
saveMachineTextFiles,
|
||||||
@@ -118,7 +123,7 @@
|
|||||||
|
|
||||||
await saveMachineTextFiles("browser-interp", {
|
await saveMachineTextFiles("browser-interp", {
|
||||||
ini: "[EMC]\nMACHINE = browser-interp\n",
|
ini: "[EMC]\nMACHINE = browser-interp\n",
|
||||||
toolTable: "T0 P0 ; no tool\n",
|
toolTable: "T2 P7 Z3.125 D1.5 I12 J34 Q4 ;browser finish tool\n",
|
||||||
parameters: [
|
parameters: [
|
||||||
"5161 10.5",
|
"5161 10.5",
|
||||||
"5162 20.25",
|
"5162 20.25",
|
||||||
@@ -129,14 +134,18 @@
|
|||||||
"",
|
"",
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
});
|
});
|
||||||
const restoredParameters = await restoreMachineParametersFromOpfs(
|
const loadedSession = await loadMachineSessionFromOpfs(
|
||||||
interp,
|
interp,
|
||||||
"browser-interp",
|
"browser-interp",
|
||||||
{ wasmPath: "/work/browser-linuxcnc.var" },
|
{
|
||||||
|
iniWasmPath: "/work/browser-machine.ini",
|
||||||
|
parameterWasmPath: "/work/browser-linuxcnc.var",
|
||||||
|
toolTableWasmPath: "/work/browser-tool.tbl",
|
||||||
|
},
|
||||||
);
|
);
|
||||||
verifyExpectedOutput(
|
verifyExpectedOutput(
|
||||||
"opfs_restore_parameters",
|
"opfs_restore_parameters",
|
||||||
restoredParameters.result,
|
loadedSession.parameters.result,
|
||||||
[
|
[
|
||||||
"restore_parameters=0",
|
"restore_parameters=0",
|
||||||
"parameter_5161=10.5",
|
"parameter_5161=10.5",
|
||||||
@@ -145,6 +154,22 @@
|
|||||||
"parameter_5399=44",
|
"parameter_5399=44",
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
);
|
);
|
||||||
|
verifyExpectedOutput(
|
||||||
|
"opfs_load_tool_table",
|
||||||
|
loadedSession.toolTable.result,
|
||||||
|
[
|
||||||
|
"tooldata_load=0",
|
||||||
|
"tool_1.toolno=2",
|
||||||
|
"tool_1.pocketno=7",
|
||||||
|
"tool_1.z=3.125",
|
||||||
|
"tool_1.diameter=1.5",
|
||||||
|
"tool_1.frontangle=12",
|
||||||
|
"tool_1.backangle=34",
|
||||||
|
"tool_1.orientation=4",
|
||||||
|
"tool_1.comment=browser finish tool",
|
||||||
|
"tool_index_for_tool_2=1",
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
const savedParameters = await saveMachineParametersToOpfs(
|
const savedParameters = await saveMachineParametersToOpfs(
|
||||||
interp,
|
interp,
|
||||||
"browser-interp",
|
"browser-interp",
|
||||||
@@ -180,6 +205,35 @@
|
|||||||
"absent=<_named_param>",
|
"absent=<_named_param>",
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
);
|
);
|
||||||
|
const savedToolTable = await saveMachineToolTableToOpfs(
|
||||||
|
interp,
|
||||||
|
"browser-interp",
|
||||||
|
{ wasmPath: "/work/browser-tool.tbl" },
|
||||||
|
);
|
||||||
|
verifyExpectedOutput(
|
||||||
|
"opfs_save_tool_table",
|
||||||
|
savedToolTable.result,
|
||||||
|
[
|
||||||
|
"tooldata_save=0",
|
||||||
|
"tool_1.toolno=2",
|
||||||
|
"tool_1.pocketno=7",
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
const savedMachineFiles = await loadMachineTextFiles("browser-interp");
|
||||||
|
verifyExpectedOutput(
|
||||||
|
"opfs_saved_tool_table_text",
|
||||||
|
savedMachineFiles.toolTable,
|
||||||
|
[
|
||||||
|
"T2",
|
||||||
|
"P7",
|
||||||
|
"Z+3.125000",
|
||||||
|
"D+1.500000",
|
||||||
|
"I+12.000000",
|
||||||
|
"J+34.000000",
|
||||||
|
"Q4",
|
||||||
|
";browser finish tool",
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
|
||||||
status.textContent = "browser_interp_smoke=ok";
|
status.textContent = "browser_interp_smoke=ok";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ fi
|
|||||||
if [[ "${SKIP_INI_BUILD:-0}" != "1" ]]; then
|
if [[ "${SKIP_INI_BUILD:-0}" != "1" ]]; then
|
||||||
"$ROOT_DIR/tools/build_ini_panel.sh"
|
"$ROOT_DIR/tools/build_ini_panel.sh"
|
||||||
fi
|
fi
|
||||||
|
if [[ "${SKIP_INTERP_BUILD:-0}" != "1" ]]; then
|
||||||
|
"$ROOT_DIR/tools/build_wasm_core.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
TMP_DIR="$(mktemp -d)"
|
TMP_DIR="$(mktemp -d)"
|
||||||
PORT_FILE="$TMP_DIR/port"
|
PORT_FILE="$TMP_DIR/port"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
|
|||||||
SKIP_INI_BUILD=1 "$ROOT_DIR/tests/wasm/node/verify_ini_wasm.sh"
|
SKIP_INI_BUILD=1 "$ROOT_DIR/tests/wasm/node/verify_ini_wasm.sh"
|
||||||
SKIP_INTERP_BUILD=1 "$ROOT_DIR/tests/wasm/node/verify_interp_wasm.sh"
|
SKIP_INTERP_BUILD=1 "$ROOT_DIR/tests/wasm/node/verify_interp_wasm.sh"
|
||||||
"$ROOT_DIR/tests/opfs/node/verify_file_service.sh"
|
"$ROOT_DIR/tests/opfs/node/verify_file_service.sh"
|
||||||
SKIP_INI_BUILD=1 "$ROOT_DIR/tests/browser/verify_ini_panel_browser.sh"
|
SKIP_INI_BUILD=1 SKIP_INTERP_BUILD=1 "$ROOT_DIR/tests/browser/verify_ini_panel_browser.sh"
|
||||||
SKIP_INTERP_BUILD=1 "$ROOT_DIR/tests/browser/verify_interp_browser.sh"
|
SKIP_INTERP_BUILD=1 "$ROOT_DIR/tests/browser/verify_interp_browser.sh"
|
||||||
|
|
||||||
echo "host_wasm_opfs_browser_smokes=ok"
|
echo "host_wasm_opfs_browser_smokes=ok"
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ check_exitcode linuxcnc_interp_o_word_source_probe
|
|||||||
check_exitcode linuxcnc_rs274ngc_pre_source_probe
|
check_exitcode linuxcnc_rs274ngc_pre_source_probe
|
||||||
check_exitcode linuxcnc_interp_base_source_probe
|
check_exitcode linuxcnc_interp_base_source_probe
|
||||||
check_exitcode linuxcnc_gomath_source_probe
|
check_exitcode linuxcnc_gomath_source_probe
|
||||||
|
check_exitcode linuxcnc_tooldata_common_source_probe
|
||||||
|
|
||||||
EMC_STATUS_STDOUT="$BUILD_DIR/linuxcnc_emc_status_probe.run.stdout.log"
|
EMC_STATUS_STDOUT="$BUILD_DIR/linuxcnc_emc_status_probe.run.stdout.log"
|
||||||
grep -Fq "emc_status_default_linear_units=1" "$EMC_STATUS_STDOUT"
|
grep -Fq "emc_status_default_linear_units=1" "$EMC_STATUS_STDOUT"
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ import {
|
|||||||
restoreMachineParametersFromOpfs,
|
restoreMachineParametersFromOpfs,
|
||||||
saveMachineParametersToOpfs,
|
saveMachineParametersToOpfs,
|
||||||
} from "../../../runtime/opfs/linuxcnc-parameter-bridge.js";
|
} from "../../../runtime/opfs/linuxcnc-parameter-bridge.js";
|
||||||
|
import {
|
||||||
|
loadMachineToolTableFromOpfs,
|
||||||
|
saveMachineToolTableToOpfs,
|
||||||
|
} from "../../../runtime/opfs/linuxcnc-tool-table-bridge.js";
|
||||||
|
import {
|
||||||
|
loadMachineSessionFromOpfs,
|
||||||
|
} from "../../../runtime/opfs/linuxcnc-machine-session-bridge.js";
|
||||||
|
|
||||||
class MockFileHandle {
|
class MockFileHandle {
|
||||||
constructor(name) {
|
constructor(name) {
|
||||||
@@ -176,6 +183,13 @@ const bridgeInterp = {
|
|||||||
bridgeFiles.set(`${path}.bak`, "5161 0.0\n5162 0.0\n");
|
bridgeFiles.set(`${path}.bak`, "5161 0.0\n5162 0.0\n");
|
||||||
return `save_parameters=0\nsave_path=${path}\nvalues=${Object.keys(values).join(",")}\n`;
|
return `save_parameters=0\nsave_path=${path}\nvalues=${Object.keys(values).join(",")}\n`;
|
||||||
},
|
},
|
||||||
|
loadToolTable(path) {
|
||||||
|
return `tooldata_load=0\nload_tool_path=${path}\n`;
|
||||||
|
},
|
||||||
|
saveToolTable(path) {
|
||||||
|
bridgeFiles.set(path, "T2 P2 Z+1.250000 D+0.250000 ;loaded by LinuxCNC\n");
|
||||||
|
return `tooldata_save=0\nsave_tool_path=${path}\n`;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const restoredParameters = await restoreMachineParametersFromOpfs(
|
const restoredParameters = await restoreMachineParametersFromOpfs(
|
||||||
@@ -208,6 +222,65 @@ assert.equal(
|
|||||||
"5161 0.0\n5162 0.0\n",
|
"5161 0.0\n5162 0.0\n",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const loadedToolTable = await loadMachineToolTableFromOpfs(
|
||||||
|
bridgeInterp,
|
||||||
|
"xyzab-tdr",
|
||||||
|
{ storage, wasmPath: "/work/bridge-tool.tbl" },
|
||||||
|
);
|
||||||
|
assert.deepEqual(loadedToolTable, {
|
||||||
|
opfsPath: "linuxcnc/machines/xyzab-tdr/tool.tbl",
|
||||||
|
wasmPath: "/work/bridge-tool.tbl",
|
||||||
|
result: "tooldata_load=0\nload_tool_path=/work/bridge-tool.tbl\n",
|
||||||
|
});
|
||||||
|
assert.equal(bridgeFiles.get("/work/bridge-tool.tbl"), "T0 P0 ; no tool\nT2 P2 Z1.25 D0.25\n");
|
||||||
|
|
||||||
|
const savedToolTable = await saveMachineToolTableToOpfs(
|
||||||
|
bridgeInterp,
|
||||||
|
"xyzab-tdr",
|
||||||
|
{ storage, wasmPath: "/work/bridge-tool.tbl" },
|
||||||
|
);
|
||||||
|
assert.equal(savedToolTable.opfsPath, "linuxcnc/machines/xyzab-tdr/tool.tbl");
|
||||||
|
assert.equal(savedToolTable.wasmPath, "/work/bridge-tool.tbl");
|
||||||
|
assert.equal(savedToolTable.result.includes("tooldata_save=0"), true);
|
||||||
|
assert.equal(
|
||||||
|
await loadTextFile("linuxcnc/machines/xyzab-tdr/tool.tbl", storage),
|
||||||
|
"T2 P2 Z+1.250000 D+0.250000 ;loaded by LinuxCNC\n",
|
||||||
|
);
|
||||||
|
|
||||||
|
const loadedSession = await loadMachineSessionFromOpfs(
|
||||||
|
bridgeInterp,
|
||||||
|
"xyzab-tdr",
|
||||||
|
{
|
||||||
|
storage,
|
||||||
|
iniWasmPath: "/work/session.ini",
|
||||||
|
parameterWasmPath: "/work/session.var",
|
||||||
|
toolTableWasmPath: "/work/session-tool.tbl",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
assert.deepEqual(loadedSession, {
|
||||||
|
machineId: "xyzab-tdr",
|
||||||
|
ini: {
|
||||||
|
opfsPath: "linuxcnc/machines/xyzab-tdr/machine.ini",
|
||||||
|
wasmPath: "/work/session.ini",
|
||||||
|
},
|
||||||
|
parameters: {
|
||||||
|
opfsPath: "linuxcnc/machines/xyzab-tdr/linuxcnc.var",
|
||||||
|
wasmPath: "/work/session.var",
|
||||||
|
result: "restore_parameters=0\nrestore_path=/work/session.var\n",
|
||||||
|
},
|
||||||
|
toolTable: {
|
||||||
|
opfsPath: "linuxcnc/machines/xyzab-tdr/tool.tbl",
|
||||||
|
wasmPath: "/work/session-tool.tbl",
|
||||||
|
result: "tooldata_load=0\nload_tool_path=/work/session-tool.tbl\n",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
assert.equal(bridgeFiles.get("/work/session.ini"), "[EMC]\nMACHINE = xyzab-tdr\n");
|
||||||
|
assert.equal(bridgeFiles.get("/work/session.var"), "5161\t12.340000\n5162\t56.780000\n");
|
||||||
|
assert.equal(
|
||||||
|
bridgeFiles.get("/work/session-tool.tbl"),
|
||||||
|
"T2 P2 Z+1.250000 D+0.250000 ;loaded by LinuxCNC\n",
|
||||||
|
);
|
||||||
|
|
||||||
await assert.rejects(
|
await assert.rejects(
|
||||||
() => loadTextFile("linuxcnc/machines/missing.ini", storage),
|
() => loadTextFile("linuxcnc/machines/missing.ini", storage),
|
||||||
/missing file/,
|
/missing file/,
|
||||||
|
|||||||
@@ -203,4 +203,57 @@ assert.equal(savedParameterFile.includes("5221\t9.870000"), true);
|
|||||||
assert.equal(savedParameterFile.includes("5399\t66.600000"), true);
|
assert.equal(savedParameterFile.includes("5399\t66.600000"), true);
|
||||||
assert.equal(savedParameterFile.includes("_named_param"), false);
|
assert.equal(savedParameterFile.includes("_named_param"), false);
|
||||||
assert.equal(backupParameterFile.includes("5161 10.5"), true);
|
assert.equal(backupParameterFile.includes("5161 10.5"), true);
|
||||||
|
|
||||||
|
const toolTablePath = "/work/tool.tbl";
|
||||||
|
interp.writeTextFile(
|
||||||
|
toolTablePath,
|
||||||
|
[
|
||||||
|
"T2 P7 Z3.125 D1.5 I12 J34 Q4 ;finish tool",
|
||||||
|
"T5 P9 X1 Y2 Z3 ;rough tool",
|
||||||
|
"",
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
verifyExpectedOutput(
|
||||||
|
"load_tool_table",
|
||||||
|
interp.loadToolTable(toolTablePath),
|
||||||
|
[
|
||||||
|
"tooldata_load=0",
|
||||||
|
"tooldata_last_index=2",
|
||||||
|
"tool_0.toolno=-1",
|
||||||
|
"tool_1.toolno=2",
|
||||||
|
"tool_1.pocketno=7",
|
||||||
|
"tool_1.z=3.125",
|
||||||
|
"tool_1.diameter=1.5",
|
||||||
|
"tool_1.frontangle=12",
|
||||||
|
"tool_1.backangle=34",
|
||||||
|
"tool_1.orientation=4",
|
||||||
|
"tool_1.comment=finish tool",
|
||||||
|
"tool_2.toolno=5",
|
||||||
|
"tool_2.pocketno=9",
|
||||||
|
"tool_2.z=3",
|
||||||
|
"tool_2.comment=rough tool",
|
||||||
|
"tool_index_for_tool_2=1",
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
verifyExpectedOutput(
|
||||||
|
"save_tool_table",
|
||||||
|
interp.saveToolTable(toolTablePath),
|
||||||
|
[
|
||||||
|
"tooldata_save=0",
|
||||||
|
"tool_1.toolno=2",
|
||||||
|
"tool_2.toolno=5",
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
const savedToolTable = interp.readTextFile(toolTablePath);
|
||||||
|
assert.equal(savedToolTable.includes("T2"), true);
|
||||||
|
assert.equal(savedToolTable.includes("P7"), true);
|
||||||
|
assert.equal(savedToolTable.includes("D+1.500000"), true);
|
||||||
|
assert.equal(savedToolTable.includes("Z+3.125000"), true);
|
||||||
|
assert.equal(savedToolTable.includes("I+12.000000"), true);
|
||||||
|
assert.equal(savedToolTable.includes("J+34.000000"), true);
|
||||||
|
assert.equal(savedToolTable.includes("Q4"), true);
|
||||||
|
assert.equal(savedToolTable.includes(";finish tool"), true);
|
||||||
|
assert.equal(savedToolTable.includes("T5"), true);
|
||||||
|
assert.equal(savedToolTable.includes("P9"), true);
|
||||||
|
assert.equal(savedToolTable.includes(";rough tool"), true);
|
||||||
console.log("interp_wasm_node_smoke=ok");
|
console.log("interp_wasm_node_smoke=ok");
|
||||||
|
|||||||
@@ -611,6 +611,7 @@ INTERP_CORE_SOURCES=(
|
|||||||
"$VENDOR_DIR/src/emc/rs274ngc/interp_write.cc"
|
"$VENDOR_DIR/src/emc/rs274ngc/interp_write.cc"
|
||||||
"$VENDOR_DIR/src/emc/rs274ngc/interp_o_word.cc"
|
"$VENDOR_DIR/src/emc/rs274ngc/interp_o_word.cc"
|
||||||
"$VENDOR_DIR/src/emc/rs274ngc/rs274ngc_pre.cc"
|
"$VENDOR_DIR/src/emc/rs274ngc/rs274ngc_pre.cc"
|
||||||
|
"$VENDOR_DIR/src/emc/tooldata/tooldata_common.cc"
|
||||||
"$WRAP_DIR/linuxcnc_hal_adapter.cpp"
|
"$WRAP_DIR/linuxcnc_hal_adapter.cpp"
|
||||||
"$WRAP_DIR/linuxcnc_emc_status_runtime.cpp"
|
"$WRAP_DIR/linuxcnc_emc_status_runtime.cpp"
|
||||||
"$WRAP_DIR/linuxcnc_interp_edge_stubs.cpp"
|
"$WRAP_DIR/linuxcnc_interp_edge_stubs.cpp"
|
||||||
@@ -1471,4 +1472,10 @@ build_c_object_target \
|
|||||||
"$VENDOR_DIR/src/libnml/posemath/gomath.c" \
|
"$VENDOR_DIR/src/libnml/posemath/gomath.c" \
|
||||||
C_FLAGS
|
C_FLAGS
|
||||||
|
|
||||||
|
build_object_target \
|
||||||
|
linuxcnc_tooldata_common_source_probe \
|
||||||
|
"$BUILD_DIR/linuxcnc_tooldata_common_source_probe.o" \
|
||||||
|
"$VENDOR_DIR/src/emc/tooldata/tooldata_common.cc" \
|
||||||
|
MINIMAL_FLAGS
|
||||||
|
|
||||||
echo "native probes complete"
|
echo "native probes complete"
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ INTERP_CORE_SOURCES=(
|
|||||||
"$VENDOR_DIR/src/emc/rs274ngc/interp_write.cc"
|
"$VENDOR_DIR/src/emc/rs274ngc/interp_write.cc"
|
||||||
"$VENDOR_DIR/src/emc/rs274ngc/interp_o_word.cc"
|
"$VENDOR_DIR/src/emc/rs274ngc/interp_o_word.cc"
|
||||||
"$VENDOR_DIR/src/emc/rs274ngc/rs274ngc_pre.cc"
|
"$VENDOR_DIR/src/emc/rs274ngc/rs274ngc_pre.cc"
|
||||||
|
"$VENDOR_DIR/src/emc/tooldata/tooldata_common.cc"
|
||||||
"$WRAP_DIR/linuxcnc_hal_adapter.cpp"
|
"$WRAP_DIR/linuxcnc_hal_adapter.cpp"
|
||||||
"$WRAP_DIR/linuxcnc_emc_status_runtime.cpp"
|
"$WRAP_DIR/linuxcnc_emc_status_runtime.cpp"
|
||||||
"$WRAP_DIR/linuxcnc_interp_edge_stubs.cpp"
|
"$WRAP_DIR/linuxcnc_interp_edge_stubs.cpp"
|
||||||
@@ -95,5 +96,5 @@ link_wasm_module \
|
|||||||
-s STACK_SIZE=2MB \
|
-s STACK_SIZE=2MB \
|
||||||
-s NO_EXIT_RUNTIME=1 \
|
-s NO_EXIT_RUNTIME=1 \
|
||||||
-s FORCE_FILESYSTEM=1 \
|
-s FORCE_FILESYSTEM=1 \
|
||||||
-s EXPORTED_FUNCTIONS='["_malloc","_free","_lcinterp_run_program","_lcinterp_run_program_with_ini","_lcinterp_run_file","_lcinterp_run_file_with_ini","_lcinterp_restore_parameters","_lcinterp_save_parameters","_lcinterp_free_string"]' \
|
-s EXPORTED_FUNCTIONS='["_malloc","_free","_lcinterp_run_program","_lcinterp_run_program_with_ini","_lcinterp_run_file","_lcinterp_run_file_with_ini","_lcinterp_restore_parameters","_lcinterp_save_parameters","_lcinterp_load_tool_table","_lcinterp_save_tool_table","_lcinterp_free_string"]' \
|
||||||
-s EXPORTED_RUNTIME_METHODS='["FS","UTF8ToString","stringToUTF8","lengthBytesUTF8"]'
|
-s EXPORTED_RUNTIME_METHODS='["FS","UTF8ToString","stringToUTF8","lengthBytesUTF8"]'
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ src/emc/nml_intf/emc.hh
|
|||||||
src/emc/nml_intf/emctool.h
|
src/emc/nml_intf/emctool.h
|
||||||
src/emc/nml_intf/debugflags.h
|
src/emc/nml_intf/debugflags.h
|
||||||
src/emc/nml_intf/interp_return.hh
|
src/emc/nml_intf/interp_return.hh
|
||||||
|
src/emc/tooldata/tooldata_common.cc
|
||||||
src/emc/motion/state_tag.h
|
src/emc/motion/state_tag.h
|
||||||
src/emc/motion/emcmotcfg.h
|
src/emc/motion/emcmotcfg.h
|
||||||
src/emc/motion/simple_tp.h
|
src/emc/motion/simple_tp.h
|
||||||
|
|||||||
423
wasm-port/vendor/linuxcnc/src/emc/tooldata/tooldata_common.cc
vendored
Normal file
423
wasm-port/vendor/linuxcnc/src/emc/tooldata/tooldata_common.cc
vendored
Normal file
@@ -0,0 +1,423 @@
|
|||||||
|
/*
|
||||||
|
** This file is part of a refactor of internal tool data management
|
||||||
|
** and incorporates work from removed files:
|
||||||
|
** src/emc/ini/initool.cc
|
||||||
|
** src/emc/rs274ngc/tool_parse.cc
|
||||||
|
**
|
||||||
|
** Copyright: 2021
|
||||||
|
** Author: Dewey Garrett <dgarrett@panix.com>
|
||||||
|
**
|
||||||
|
** This program is free software; you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** This program is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with this program; if not, write to the Free Software
|
||||||
|
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <rtapi_string.h>
|
||||||
|
#include "tooldata.hh"
|
||||||
|
|
||||||
|
#define UNEXPECTED_MSG fprintf(stderr,"UNEXPECTED %s %d\n",__FILE__,__LINE__);
|
||||||
|
|
||||||
|
static bool is_random_toolchanger = 0;
|
||||||
|
static int nonrandom_idx = 0; // 'fakepocket' counter
|
||||||
|
static bool add_init_initialized = 0;
|
||||||
|
static tooldb_t db_mode = DB_NOTUSED;
|
||||||
|
|
||||||
|
void tooldata_init(bool random_toolchanger)
|
||||||
|
{
|
||||||
|
is_random_toolchanger = random_toolchanger;
|
||||||
|
} // tooldata_init
|
||||||
|
|
||||||
|
struct CANON_TOOL_TABLE tooldata_entry_init()
|
||||||
|
{
|
||||||
|
struct CANON_TOOL_TABLE tdata;
|
||||||
|
tdata.toolno = -1;
|
||||||
|
tdata.pocketno = -1;
|
||||||
|
tdata.diameter = 0;
|
||||||
|
tdata.frontangle = 0;
|
||||||
|
tdata.backangle = 0;
|
||||||
|
tdata.orientation = 0;
|
||||||
|
ZERO_EMC_POSE(tdata.offset);
|
||||||
|
tdata.comment[0] = 0;
|
||||||
|
|
||||||
|
return tdata;
|
||||||
|
} // tooldata_entry_init()
|
||||||
|
|
||||||
|
void tooldata_set_db(tooldb_t mode)
|
||||||
|
{
|
||||||
|
db_mode = mode;
|
||||||
|
return;
|
||||||
|
} //tooldata_set_db()
|
||||||
|
|
||||||
|
void tooldata_add_init(int nonrandom_start_idx)
|
||||||
|
{
|
||||||
|
// initialize file-static vars need for tooldata_add_line()
|
||||||
|
nonrandom_idx = nonrandom_start_idx;
|
||||||
|
add_init_initialized = 1;
|
||||||
|
return;
|
||||||
|
} // tooldata_add_init()
|
||||||
|
|
||||||
|
int tooldata_read_entry(const char *input_line)
|
||||||
|
{
|
||||||
|
char work_line[CANON_TOOL_ENTRY_LEN];
|
||||||
|
const char *token;
|
||||||
|
char *buff, *comment;
|
||||||
|
int toolno,orientation,valid=1;
|
||||||
|
EmcPose offset; //tlo
|
||||||
|
double diameter, frontangle, backangle;
|
||||||
|
int idx = 0;
|
||||||
|
int realpocket = 0;
|
||||||
|
|
||||||
|
if (!add_init_initialized) {
|
||||||
|
fprintf(stderr,"!!! PROBLEM no init %s\n",__FILE__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (input_line[0] == ';') {return 0;} //ignore leading ';'
|
||||||
|
strncpy(work_line, input_line, sizeof(work_line)-1);
|
||||||
|
work_line[sizeof(work_line)-1] = 0;
|
||||||
|
|
||||||
|
CANON_TOOL_TABLE empty = tooldata_entry_init();
|
||||||
|
toolno = empty.toolno;
|
||||||
|
diameter = empty.diameter;
|
||||||
|
frontangle = empty.frontangle;
|
||||||
|
backangle = empty.backangle;
|
||||||
|
orientation = empty.orientation;
|
||||||
|
offset = empty.offset;
|
||||||
|
|
||||||
|
char* saveptr;
|
||||||
|
buff = strtok_r(work_line, ";", &saveptr);
|
||||||
|
if (strlen(buff) <=1) {
|
||||||
|
//fprintf(stderr,"skip blankline %s\n",__FILE__);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
comment = strtok_r(NULL, "\n", &saveptr);
|
||||||
|
|
||||||
|
token = strtok_r(buff, " ", &saveptr);
|
||||||
|
while (token != NULL) {
|
||||||
|
switch (toupper(token[0])) {
|
||||||
|
case 'T':
|
||||||
|
if (sscanf(&token[1], "%d", &toolno) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
if (sscanf(&token[1], "%d", &idx) != 1) {
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
realpocket = idx; //random toolchanger
|
||||||
|
if (!is_random_toolchanger) {
|
||||||
|
if ( (nonrandom_idx <= 0)
|
||||||
|
|| (nonrandom_idx >= CANON_POCKETS_MAX) ) {
|
||||||
|
printf("Out-of-range nonrandom_idx=%d. Skipping tool=%d\n",
|
||||||
|
nonrandom_idx,toolno);
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
idx = nonrandom_idx; // nonrandom toolchanger
|
||||||
|
(nonrandom_idx)++;
|
||||||
|
}
|
||||||
|
if (idx < 0 || idx >= CANON_POCKETS_MAX) {
|
||||||
|
printf("max pocket number is %d. skipping tool %d\n",
|
||||||
|
CANON_POCKETS_MAX - 1, toolno);
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
if (sscanf(&token[1], "%lf", &diameter) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'X':
|
||||||
|
if (sscanf(&token[1], "%lf", &offset.tran.x) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'Y':
|
||||||
|
if (sscanf(&token[1], "%lf", &offset.tran.y) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'Z':
|
||||||
|
if (sscanf(&token[1], "%lf", &offset.tran.z) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'A':
|
||||||
|
if (sscanf(&token[1], "%lf", &offset.a) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'B':
|
||||||
|
if (sscanf(&token[1], "%lf", &offset.b) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'C':
|
||||||
|
if (sscanf(&token[1], "%lf", &offset.c) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
if (sscanf(&token[1], "%lf", &offset.u) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'V':
|
||||||
|
if (sscanf(&token[1], "%lf", &offset.v) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'W':
|
||||||
|
if (sscanf(&token[1], "%lf", &offset.w) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'I':
|
||||||
|
if (sscanf(&token[1], "%lf", &frontangle) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'J':
|
||||||
|
if (sscanf(&token[1], "%lf", &backangle) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
case 'Q':
|
||||||
|
if (sscanf(&token[1], "%d", &orientation) != 1)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (strncmp(token, "\n", 1) != 0)
|
||||||
|
valid = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
token = strtok_r(NULL, " ", &saveptr);
|
||||||
|
} // while token
|
||||||
|
|
||||||
|
if (valid) {
|
||||||
|
CANON_TOOL_TABLE tdata = tooldata_entry_init();
|
||||||
|
// verify no prior tool in pocket
|
||||||
|
if (tooldata_get(&tdata,idx) != IDX_OK) { UNEXPECTED_MSG; }
|
||||||
|
if (is_random_toolchanger && tdata.toolno != -1) {
|
||||||
|
fprintf(stderr,"WARNING: Attempt to assign multiple toolno.s to pocket %d\n",realpocket);
|
||||||
|
fprintf(stderr," %s %s()\n",__FILE__,__FUNCTION__);
|
||||||
|
fprintf(stderr," WAS: pocket=%3d toolno=%3d\n",tdata.pocketno,tdata.toolno);
|
||||||
|
fprintf(stderr," IS: pocket=%3d toolno=%3d\n",realpocket,toolno);
|
||||||
|
}
|
||||||
|
tdata.toolno = toolno;
|
||||||
|
tdata.pocketno = realpocket;
|
||||||
|
tdata.offset = offset;
|
||||||
|
tdata.diameter = diameter;
|
||||||
|
tdata.frontangle = frontangle;
|
||||||
|
tdata.backangle = backangle;
|
||||||
|
tdata.orientation = orientation;
|
||||||
|
if (comment) {
|
||||||
|
strncpy(tdata.comment,comment,CANON_TOOL_COMMENT_SIZE-1);
|
||||||
|
tdata.comment[CANON_TOOL_COMMENT_SIZE-1] = 0;
|
||||||
|
if (strlen(comment) > (CANON_TOOL_COMMENT_SIZE-1) ) {
|
||||||
|
fprintf(stderr,"%s():comment for toolno %d truncated to %d chars:\n <%s>\n"
|
||||||
|
,__FUNCTION__
|
||||||
|
,tdata.toolno
|
||||||
|
,CANON_TOOL_COMMENT_SIZE-1
|
||||||
|
,tdata.comment
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tooldata_put(tdata,idx) == IDX_FAIL) {
|
||||||
|
UNEXPECTED_MSG;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return idx;
|
||||||
|
} // tooldata_read_entry()
|
||||||
|
|
||||||
|
void tooldata_format_toolline (int idx,
|
||||||
|
bool ignore_zero_values,
|
||||||
|
CANON_TOOL_TABLE tdata,
|
||||||
|
char formatted_line[CANON_TOOL_ENTRY_LEN]
|
||||||
|
)
|
||||||
|
{
|
||||||
|
char tmp[CANON_TOOL_ENTRY_LEN-1] = {0};
|
||||||
|
int space = sizeof(tmp);
|
||||||
|
int len;
|
||||||
|
len = snprintf(tmp,sizeof(tmp),"T%-3d P%-3d"
|
||||||
|
,tdata.toolno
|
||||||
|
,is_random_toolchanger ? idx : tdata.pocketno);
|
||||||
|
strncat(formatted_line,tmp,space);
|
||||||
|
space -= len;
|
||||||
|
// format zero float values as %.0f for brevity
|
||||||
|
#define F_ITEM(item,letter) if (!ignore_zero_values || tdata.item) { \
|
||||||
|
char local_tmp[64] = {}; \
|
||||||
|
if (tdata.item) { \
|
||||||
|
len = snprintf(local_tmp,sizeof(local_tmp)," " letter "%+f", tdata.item); \
|
||||||
|
} else { \
|
||||||
|
len = snprintf(local_tmp,sizeof(local_tmp)," " letter "%.0f",tdata.item); \
|
||||||
|
} \
|
||||||
|
strncat(formatted_line,local_tmp,space); \
|
||||||
|
space -= len; \
|
||||||
|
}
|
||||||
|
#define I_ITEM(item,letter) if (!ignore_zero_values || tdata.item) { \
|
||||||
|
len = snprintf(tmp,sizeof(tmp)," " letter "%d",tdata.item); \
|
||||||
|
strncat(formatted_line,tmp,space); \
|
||||||
|
space -= len; \
|
||||||
|
}
|
||||||
|
|
||||||
|
F_ITEM(diameter, "D");
|
||||||
|
F_ITEM(offset.tran.x, "X");
|
||||||
|
F_ITEM(offset.tran.y, "Y");
|
||||||
|
F_ITEM(offset.tran.z, "Z");
|
||||||
|
F_ITEM(offset.a, "A");
|
||||||
|
F_ITEM(offset.b, "B");
|
||||||
|
F_ITEM(offset.c, "C");
|
||||||
|
F_ITEM(offset.u, "U");
|
||||||
|
F_ITEM(offset.v, "V");
|
||||||
|
F_ITEM(offset.w, "W");
|
||||||
|
F_ITEM(frontangle, "I");
|
||||||
|
F_ITEM(backangle, "J");
|
||||||
|
I_ITEM(orientation, "Q");
|
||||||
|
#undef F_ITEM
|
||||||
|
#undef I_ITEM
|
||||||
|
// Stop tracking len and space here for current tool table format
|
||||||
|
if (tdata.comment[0]) {
|
||||||
|
snprintf(tmp,space," ;%s\n",tdata.comment);
|
||||||
|
} else {
|
||||||
|
snprintf(tmp,space,"\n");
|
||||||
|
}
|
||||||
|
strncat(formatted_line,tmp,space);
|
||||||
|
return;
|
||||||
|
} // tooldata_format_toolline()
|
||||||
|
|
||||||
|
int tooldata_load(const char *filename)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
char input_line[CANON_TOOL_ENTRY_LEN];
|
||||||
|
char orig_line[CANON_TOOL_ENTRY_LEN];
|
||||||
|
|
||||||
|
if (db_mode == DB_ACTIVE) { //expect data loaded from db
|
||||||
|
if (tooldata_db_getall()) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"\ntooldata_load: Failed to load tooldata from database\n\n");
|
||||||
|
db_mode = DB_NOTUSED;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!filename) return -1;
|
||||||
|
|
||||||
|
// clear out tool table
|
||||||
|
// (Set vars to indicate no tool in pocket):
|
||||||
|
tooldata_reset();
|
||||||
|
|
||||||
|
// open tool table file
|
||||||
|
if (NULL == (fp = fopen(filename, "r"))) {
|
||||||
|
fprintf(stderr, "%s, %d: Failed to open tool table file '%s': %s\n",
|
||||||
|
__FILE__, __LINE__, filename, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// after initializing all available pockets,
|
||||||
|
// subsequent read from filename will update the last_index
|
||||||
|
// which becomes available by tooldata_last_index_get()
|
||||||
|
tooldata_last_index_set(0); // (only mmap uses)
|
||||||
|
|
||||||
|
const int nonrandom_start_idx = 1; // when reading file start at 0
|
||||||
|
tooldata_add_init(nonrandom_start_idx);
|
||||||
|
|
||||||
|
while (!feof(fp)) {
|
||||||
|
// for nonrandom machines, just read the tools into pockets 1..n
|
||||||
|
// no matter their tool numbers. NB leave the spindle pocket 0
|
||||||
|
// unchanged/empty.
|
||||||
|
if (NULL == fgets(input_line, CANON_TOOL_ENTRY_LEN, fp)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
strcpy(orig_line, input_line);
|
||||||
|
|
||||||
|
// parse and store one line from tool table file
|
||||||
|
int entry_idx = tooldata_read_entry(input_line);
|
||||||
|
if (entry_idx <0) {
|
||||||
|
printf("File: %s Unrecognized line skipped:\n %s",filename, orig_line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_random_toolchanger) {
|
||||||
|
CANON_TOOL_TABLE spindletool;
|
||||||
|
if (tooldata_get(&spindletool,0) != IDX_OK) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
CANON_TOOL_TABLE edata; // just added
|
||||||
|
if (tooldata_get(&edata,entry_idx) != IDX_OK) {
|
||||||
|
UNEXPECTED_MSG;
|
||||||
|
}
|
||||||
|
if (!is_random_toolchanger && spindletool.toolno == edata.toolno) {
|
||||||
|
spindletool = edata;
|
||||||
|
tooldata_put(spindletool,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // while
|
||||||
|
|
||||||
|
// close the file
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
} // tooldata_load()
|
||||||
|
|
||||||
|
static void write_tool_line(FILE* fp,int idx)
|
||||||
|
{
|
||||||
|
CANON_TOOL_TABLE tdata;
|
||||||
|
if (tooldata_get(&tdata,idx) != IDX_OK) {return;}
|
||||||
|
if (db_mode == DB_ACTIVE && idx != 0 ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tdata.toolno != -1) {
|
||||||
|
char theline[CANON_TOOL_ENTRY_LEN] = {0};
|
||||||
|
tooldata_format_toolline (idx,
|
||||||
|
1, // ignore_zero_values
|
||||||
|
tdata,theline);
|
||||||
|
fprintf(fp,"%s",theline);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} // write_tool_line()
|
||||||
|
|
||||||
|
int tooldata_save(const char *filename)
|
||||||
|
{
|
||||||
|
int idx;
|
||||||
|
FILE *fp;
|
||||||
|
int start_idx;
|
||||||
|
|
||||||
|
if (db_mode == DB_ACTIVE) {
|
||||||
|
if (!is_random_toolchanger) {return 0;}
|
||||||
|
filename = DB_SPINDLE_SAVE; //one entry tbl (nonran only)
|
||||||
|
} else {
|
||||||
|
// filename == NULL happens without ini entry [EMCIO]TOOL_TABLE
|
||||||
|
// and a Task::emcToolSetOffset is performed.
|
||||||
|
if (!filename) {
|
||||||
|
fprintf(stderr, "%s: No filename. Are you missing INI-entry [EMCIO]TOOL_TABLE?\n",
|
||||||
|
__PRETTY_FUNCTION__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (filename[0] == 0) {
|
||||||
|
UNEXPECTED_MSG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// open tool table file
|
||||||
|
if (NULL == (fp = fopen(filename, "w"))) {
|
||||||
|
fprintf(stderr, "%s, %d: Failed to open tool table file '%s': %s\n",
|
||||||
|
__FILE__, __LINE__, filename, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (db_mode == DB_ACTIVE) {
|
||||||
|
int spindle_idx = 0;
|
||||||
|
write_tool_line(fp,spindle_idx);
|
||||||
|
} else {
|
||||||
|
start_idx = is_random_toolchanger ? 0 : 1;
|
||||||
|
for (idx = start_idx; idx < CANON_POCKETS_MAX; idx++) {
|
||||||
|
write_tool_line(fp,idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
} //tooldata_save()
|
||||||
Reference in New Issue
Block a user