Initial LinuxCNC WebAssembly workspace snapshot

This commit is contained in:
2026-08-20 18:21:15 +08:00
commit 5dd614c335
92 changed files with 200203 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
#ifndef LINUXCNC_WEB_WASM_SIM_API_H
#define LINUXCNC_WEB_WASM_SIM_API_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
enum sim_result {
SIM_OK = 0,
SIM_ERR_INVALID_ARGUMENT = -1,
SIM_ERR_NOT_CREATED = -2,
SIM_ERR_BUFFER_TOO_SMALL = -3,
SIM_ERR_INVALID_STATE = -4,
SIM_ERR_UNSUPPORTED = -5,
};
/* Bootstrap ABI only. LinuxCNC behavior is added behind this stable boundary. */
int32_t sim_create(const uint8_t *config, uint32_t config_len);
int32_t sim_load_workspace(const char *root_path);
int32_t sim_command(const uint8_t *command, uint32_t command_len);
int32_t sim_step(uint32_t cycles);
uint32_t sim_read_snapshot(uint8_t *out, uint32_t capacity);
uint32_t sim_read_event(uint8_t *out, uint32_t capacity);
int32_t sim_export_state(uint8_t *out, uint32_t capacity);
int32_t sim_import_state(const uint8_t *data, uint32_t len);
void sim_destroy(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,42 @@
#ifndef LINUXCNC_WEB_WASM_SIM_EVENT_H
#define LINUXCNC_WEB_WASM_SIM_EVENT_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SIM_EVENT_KIND_CAPACITY 32U
#define SIM_EVENT_CAPACITY 256U
enum sim_event_result {
SIM_EVENT_OK = 0,
SIM_EVENT_ERR_SEQUENCE = -200,
SIM_EVENT_ERR_TICK = -201,
SIM_EVENT_ERR_ARGUMENT = -202,
SIM_EVENT_ERR_FULL = -203,
SIM_EVENT_ERR_BUFFER = -204,
};
typedef struct sim_event_record {
uint32_t seq;
uint32_t tick;
uint64_t payload_hash;
char kind[SIM_EVENT_KIND_CAPACITY];
} sim_event_record;
void sim_event_reset(void);
int32_t sim_event_append(uint32_t seq, uint32_t tick, const char *kind,
const uint8_t *payload, uint32_t payload_len);
uint32_t sim_event_count(void);
uint32_t sim_event_cursor(void);
uint32_t sim_event_read(uint32_t index, uint8_t *out, uint32_t capacity);
uint32_t sim_event_export(uint8_t *out, uint32_t capacity);
int32_t sim_event_import(const uint8_t *data, uint32_t len);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,64 @@
#ifndef LINUXCNC_WEB_WASM_SIM_HAL_H
#define LINUXCNC_WEB_WASM_SIM_HAL_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SIM_HAL_NAME_CAPACITY 48U
#define SIM_HAL_PIN_CAPACITY 64U
#define SIM_HAL_THREAD_CAPACITY 16U
#define SIM_HAL_FUNCTION_CAPACITY 64U
enum sim_hal_result {
SIM_HAL_OK = 0,
SIM_HAL_ERR_ARGUMENT = -300,
SIM_HAL_ERR_FULL = -301,
SIM_HAL_ERR_DUPLICATE = -302,
SIM_HAL_ERR_NOT_FOUND = -303,
SIM_HAL_ERR_TYPE = -304,
SIM_HAL_ERR_RANGE = -305,
SIM_HAL_ERR_CONNECTION = -306,
SIM_HAL_ERR_FUNCTION = -307,
SIM_HAL_ERR_REAL_EXCLUDED = -308,
};
enum sim_hal_type {
SIM_HAL_BIT = 1,
SIM_HAL_S32 = 2,
SIM_HAL_U32 = 3,
SIM_HAL_FLOAT = 4,
};
typedef struct sim_hal_value {
uint32_t type;
union {
uint32_t bit;
int32_t s32;
uint32_t u32;
float real;
} value;
} sim_hal_value;
void sim_hal_reset(void);
int32_t sim_hal_register_pin(const char *name, uint32_t type);
int32_t sim_hal_set_pin(const char *name, sim_hal_value value);
int32_t sim_hal_get_pin(const char *name, sim_hal_value *out);
int32_t sim_hal_connect(const char *source, const char *target);
int32_t sim_hal_register_thread(const char *name, uint32_t period_ticks);
int32_t sim_hal_register_function(const char *thread, const char *name);
int32_t sim_hal_set_function_failure(const char *name, uint32_t fail);
int32_t sim_hal_step(uint32_t ticks);
uint32_t sim_hal_tick(void);
uint32_t sim_hal_function_calls(const char *name);
uint32_t sim_hal_pin_count(void);
uint32_t sim_hal_thread_count(void);
uint32_t sim_hal_function_count(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,32 @@
#ifndef LINUXCNC_WEB_WASM_SIM_POSEMATH_H
#define LINUXCNC_WEB_WASM_SIM_POSEMATH_H
#ifdef __cplusplus
extern "C" {
#endif
enum sim_posemath_result {
SIM_POSEMATH_OK = 0,
SIM_POSEMATH_ERR_ARGUMENT = -400,
SIM_POSEMATH_ERR_NONFINITE = -401,
SIM_POSEMATH_ERR_DEGENERATE = -402,
SIM_POSEMATH_ERR_RANGE = -403,
};
typedef struct sim_posemath_cartesian {
double x;
double y;
double z;
} sim_posemath_cartesian;
int sim_posemath_normalize(const sim_posemath_cartesian *input, sim_posemath_cartesian *output);
int sim_posemath_dot(const sim_posemath_cartesian *left, const sim_posemath_cartesian *right, double *output);
int sim_posemath_line_point(const sim_posemath_cartesian *start, const sim_posemath_cartesian *end,
double fraction, sim_posemath_cartesian *output);
int sim_posemath_is_finite(const sim_posemath_cartesian *value);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,46 @@
#ifndef LINUXCNC_WEB_WASM_SIM_PROTOCOL_H
#define LINUXCNC_WEB_WASM_SIM_PROTOCOL_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
enum sim_protocol_result {
SIM_PROTOCOL_OK = 0,
SIM_PROTOCOL_ERR_SCHEMA = -100,
SIM_PROTOCOL_ERR_SEQUENCE = -101,
SIM_PROTOCOL_ERR_STATE = -102,
SIM_PROTOCOL_ERR_OPERATION_ID = -103,
SIM_PROTOCOL_ERR_KIND = -104,
SIM_PROTOCOL_ERR_ARGUMENT = -105,
SIM_PROTOCOL_ERR_TICK = -106,
};
enum sim_protocol_state {
SIM_PROTOCOL_NEW = 0,
SIM_PROTOCOL_HELLO = 1,
SIM_PROTOCOL_ATTACHED = 2,
SIM_PROTOCOL_READY = 3,
SIM_PROTOCOL_PAUSED = 4,
SIM_PROTOCOL_DESTROYED = 5,
};
/* The protocol validator is deliberately independent of JSON and malloc. */
void sim_protocol_reset(void);
int32_t sim_protocol_accept(uint32_t schema_version, uint32_t seq,
const char *kind, const char *operation_id,
uint32_t simulation_tick);
int32_t sim_protocol_pause(void);
int32_t sim_protocol_resume(void);
int32_t sim_protocol_state_value(void);
uint32_t sim_protocol_last_seq(void);
uint32_t sim_protocol_tick(void);
int32_t sim_protocol_set_tick(uint32_t simulation_tick);
#ifdef __cplusplus
}
#endif
#endif