44 lines
1.7 KiB
JavaScript
44 lines
1.7 KiB
JavaScript
import { SimSession, CONTEXT_ID, PROTOCOL_SCHEMA } from "./sim-session.mjs";
|
|
import { XyzacCommandLedger, XYZAC_COMMAND_LEDGER_SCHEMA } from "./xyzac-command-ledger.mjs";
|
|
import { XyzacScheduler, XYZAC_SCHEDULER_SCHEMA } from "./xyzac-scheduler.mjs";
|
|
|
|
export const XYZAC_SESSION_SCHEMA = "xyzac-session.v1";
|
|
|
|
export class XyzacSession extends SimSession {
|
|
constructor(core, options = {}) {
|
|
super(core, options);
|
|
this.ledger = new XyzacCommandLedger();
|
|
this.scheduler = new XyzacScheduler(core);
|
|
this.session_scope = "selected_xyzac_simulation";
|
|
}
|
|
|
|
authority() {
|
|
return {
|
|
schema: XYZAC_SESSION_SCHEMA,
|
|
authority: "linuxcnc-wasm-worker",
|
|
context_id: this.contextId,
|
|
session_id: this.sessionId,
|
|
scope: this.session_scope,
|
|
protocol_schema: PROTOCOL_SCHEMA,
|
|
ledger_schema: XYZAC_COMMAND_LEDGER_SCHEMA,
|
|
scheduler_schema: XYZAC_SCHEDULER_SCHEMA,
|
|
machine: { coordinates: "XYZAC", joint_count: 5, kinematics: "xyzac-trt", rotary_units: "degrees" },
|
|
};
|
|
}
|
|
|
|
accept(input) {
|
|
const response = super.accept(input);
|
|
if (!response?.payload || typeof response.payload !== "object") return response;
|
|
// super.accept stores the response in the operation ledger. Enrich a
|
|
// shallow client copy so the next ledger audit cannot recursively embed
|
|
// every previous response inside the stored response object.
|
|
const payload = { ...response.payload };
|
|
payload.xyzac_session = this.authority();
|
|
payload.xyzac_ledger = this.ledger.audit({ includeResponses: input.kind !== "SIM_STEP", maxEntries: input.kind === "SIM_STEP" ? 32 : 2048 });
|
|
payload.xyzac_scheduler = this.scheduler.export();
|
|
return { ...response, payload };
|
|
}
|
|
}
|
|
|
|
export { CONTEXT_ID, PROTOCOL_SCHEMA };
|