按规划继续工作

结论:接入 vendored LinuxCNC tooldata_common.cc 负责刀具表解析与保存,WASM/SDK/OPFS/UI 仅做运行时边界搬运;native、WASM、OPFS 和浏览器 smoke 验证已通过。
This commit is contained in:
2026-06-08 08:31:10 +08:00
parent 5ea07606d7
commit a16f3605fa
24 changed files with 1302 additions and 53 deletions

View File

@@ -13,6 +13,7 @@
#include "canon_event_sink.hh"
#include "linuxcnc_hal_adapter.hh"
#include "linuxcnc_tool_adapter.hh"
#include "tooldata.hh"
namespace {
@@ -145,6 +146,35 @@ void append_parameter_state(std::ostringstream &output, const Interp &interp)
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)
{
if (rc > INTERP_MIN_ERROR) {
@@ -317,6 +347,30 @@ char *lcinterp_save_parameters(const char *path, const char *assignments)
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
void lcinterp_free_string(char *value)
{

View File

@@ -2,6 +2,8 @@
#include <array>
#include "tooldata.hh"
namespace {
std::array<CANON_TOOL_TABLE, CANON_POCKETS_MAX> &tool_table()
@@ -22,6 +24,12 @@ int &current_tool_index_ref()
return index;
}
int &last_tool_index_ref()
{
static int index = 0;
return index;
}
CANON_TOOL_TABLE empty_tool()
{
CANON_TOOL_TABLE tool{};
@@ -30,6 +38,20 @@ CANON_TOOL_TABLE empty_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 standalone {
@@ -117,3 +139,63 @@ void change_selected_tool()
}
} // 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"

View 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);
}

View File

@@ -1,23 +1,3 @@
#pragma once
#include "emc/nml_intf/emctool.h"
#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;
}
#include "../tooldata.hh"