covenant-protocol 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ /**
2
+ * G-Code Protocol Definition
3
+ *
4
+ * Defines the typed contract for G-Code parsing using LinuxCNC's rs274ngc interpreter.
5
+ */
6
+
7
+ import type { ChannelProtocol } from "@edenapp/types";
8
+ import type { GCodeParseResult, ParseProgress } from "@linuxcnc-node/types";
9
+
10
+ // ============================================================================
11
+ // G-Code Types (re-export for convenience)
12
+ // ============================================================================
13
+
14
+ export type { GCodeParseResult, ParseProgress };
15
+
16
+ // ============================================================================
17
+ // Protocol Definition
18
+ // ============================================================================
19
+
20
+ /**
21
+ * Protocol for G-Code parsing over AppBus.
22
+ */
23
+ export interface GCodeProtocol extends ChannelProtocol {
24
+ hostMessages: {
25
+ /** Parse progress update */
26
+ "parse-progress": ParseProgress;
27
+
28
+ /** Error occurred */
29
+ error: {
30
+ code: string;
31
+ message: string;
32
+ };
33
+ };
34
+
35
+ peerMessages: {};
36
+
37
+ hostHandles: {
38
+ /** Parse a G-code file */
39
+ parse: {
40
+ args: {
41
+ filepath: string;
42
+ iniPath: string;
43
+ progressUpdates?: number;
44
+ };
45
+ result: GCodeParseResult;
46
+ };
47
+
48
+ ping: {
49
+ args: {};
50
+ result: { timestamp: number };
51
+ };
52
+ };
53
+
54
+ peerHandles: {};
55
+ }
@@ -0,0 +1,285 @@
1
+ /**
2
+ * HAL Protocol Definition
3
+ *
4
+ * Defines the typed contract for HAL (Hardware Abstraction Layer) communication.
5
+ *
6
+ * This protocol enables real-time monitoring and control of LinuxCNC HAL.
7
+ */
8
+
9
+ import type { ChannelProtocol } from "@edenapp/types";
10
+ import type {
11
+ HalType,
12
+ HalPinDir,
13
+ HalParamDir,
14
+ RtapiMsgLevel,
15
+ HalPinInfo,
16
+ HalParamInfo,
17
+ HalSignalInfo,
18
+ } from "@linuxcnc-node/types";
19
+
20
+ // ============================================================================
21
+ // HAL Types (re-export for convenience)
22
+ // ============================================================================
23
+
24
+ export type {
25
+ HalType,
26
+ HalPinDir,
27
+ HalParamDir,
28
+ RtapiMsgLevel,
29
+ HalPinInfo,
30
+ HalParamInfo,
31
+ HalSignalInfo,
32
+ };
33
+
34
+ export type HalValue = boolean | number;
35
+
36
+ /** Delta update structure for HAL items */
37
+ export interface HalDelta {
38
+ /** Changed items as flat array of name-value pairs */
39
+ changes: Array<{ name: string; value: HalValue }>;
40
+ /** Monotonic cursor for sync verification */
41
+ cursor: number;
42
+ /** Timestamp of update */
43
+ timestamp: number;
44
+ }
45
+
46
+ // ============================================================================
47
+ // Protocol Definition
48
+ // ============================================================================
49
+ /**
50
+ * Protocol for HAL communication over AppBus.
51
+ *
52
+ * Host = HAL service provider (manages HAL component)
53
+ * Peer = HAL service consumer (controls/monitors HAL)
54
+ *
55
+ * Each connection is bound to a single HAL component. The component is created
56
+ * when component/init is called and disposed when the connection closes.
57
+ */
58
+ export interface HalProtocol extends ChannelProtocol {
59
+ // -------------------------------------------------------------------------
60
+ // Messages sent by host, received by peer
61
+ // -------------------------------------------------------------------------
62
+ hostMessages: {
63
+ /** HAL component is ready */
64
+ "hal-ready": {
65
+ componentName: string;
66
+ prefix: string;
67
+ };
68
+
69
+ /** Flat delta: only changed items with their new values */
70
+ "items-delta": HalDelta;
71
+
72
+ /** Error occurred in backend */
73
+ error: {
74
+ code: string;
75
+ message: string;
76
+ };
77
+ };
78
+
79
+ // -------------------------------------------------------------------------
80
+ // Messages sent by peer, received by host
81
+ // -------------------------------------------------------------------------
82
+ peerMessages: {};
83
+
84
+ // -------------------------------------------------------------------------
85
+ // Requests that peer sends, host handles
86
+ // -------------------------------------------------------------------------
87
+ hostHandles: {
88
+ // Component Operations (bound to this connection)
89
+ /** Initialize the HAL component for this connection. Must be called first. */
90
+ "component/init": {
91
+ args: { name: string; prefix?: string };
92
+ result: { success: boolean; componentName: string; error?: string };
93
+ };
94
+
95
+ /** Mark the bound component as ready */
96
+ "component/ready": {
97
+ args: {};
98
+ result: { success: boolean; error?: string };
99
+ };
100
+
101
+ /** Mark the bound component as not ready */
102
+ "component/unready": {
103
+ args: {};
104
+ result: { success: boolean; error?: string };
105
+ };
106
+
107
+ /** Create a pin on the bound component */
108
+ "pin/create": {
109
+ args: {
110
+ name: string;
111
+ type: HalType;
112
+ direction: HalPinDir;
113
+ };
114
+ result: { success: boolean; fullName: string; error?: string };
115
+ };
116
+
117
+ /** Create a parameter on the bound component */
118
+ "param/create": {
119
+ args: {
120
+ name: string;
121
+ type: HalType;
122
+ direction: HalParamDir;
123
+ };
124
+ result: { success: boolean; fullName: string; error?: string };
125
+ };
126
+
127
+ /** Get value of a pin or parameter on the bound component */
128
+ "item/get-value": {
129
+ args: { name: string };
130
+ result: { value: HalValue };
131
+ };
132
+
133
+ /** Set value of a pin or parameter on the bound component */
134
+ "item/set-value": {
135
+ args: { name: string; value: HalValue };
136
+ result: { success: boolean; error?: string };
137
+ };
138
+
139
+ /**
140
+ * Get all current item values.
141
+ * @returns All item values plus current cursor
142
+ */
143
+ "items/sync": {
144
+ args: {};
145
+ result: {
146
+ /** All current item values */
147
+ items: Record<string, HalValue>;
148
+ /** Current cursor for delta updates */
149
+ cursor: number;
150
+ };
151
+ };
152
+
153
+ // =========================================================================
154
+ // GLOBAL: System-wide HAL operations (not tied to bound component)
155
+ // =========================================================================
156
+
157
+ /** Check if any component exists by name */
158
+ "global/component-exists": {
159
+ args: { componentName: string };
160
+ result: { exists: boolean };
161
+ };
162
+
163
+ /** Check if any component is ready by name */
164
+ "global/component-is-ready": {
165
+ args: { componentName: string };
166
+ result: { ready: boolean };
167
+ };
168
+
169
+ /** Create a new HAL signal */
170
+ "global/signal-create": {
171
+ args: { name: string; type: HalType };
172
+ result: { success: boolean; error?: string };
173
+ };
174
+
175
+ /** Get value of any signal by name */
176
+ "global/signal-get-value": {
177
+ args: { signalName: string };
178
+ result: { value: HalValue };
179
+ };
180
+
181
+ /** Set value of any signal by name */
182
+ "global/signal-set-value": {
183
+ args: { signalName: string; value: HalValue };
184
+ result: { success: boolean; error?: string };
185
+ };
186
+
187
+ /** Connect any pin to a signal */
188
+ "global/signal-connect": {
189
+ args: { pinName: string; signalName: string };
190
+ result: { success: boolean; error?: string };
191
+ };
192
+
193
+ /** Disconnect any pin from its signal */
194
+ "global/signal-disconnect": {
195
+ args: { pinName: string };
196
+ result: { success: boolean; error?: string };
197
+ };
198
+
199
+ /** Check if any pin has a writer */
200
+ "global/pin-has-writer": {
201
+ args: { pinName: string };
202
+ result: { hasWriter: boolean };
203
+ };
204
+
205
+ /** Get value of any pin, param, or signal by full name */
206
+ "global/get-value": {
207
+ args: { name: string };
208
+ result: { value: HalValue; type: "pin" | "param" | "signal" };
209
+ };
210
+
211
+ /** List all pins in HAL */
212
+ "global/list-pins": {
213
+ args: { filter?: string };
214
+ result: { pins: HalPinInfo[] };
215
+ };
216
+
217
+ /** List all parameters in HAL */
218
+ "global/list-params": {
219
+ args: { filter?: string };
220
+ result: { params: HalParamInfo[] };
221
+ };
222
+
223
+ /** List all signals in HAL */
224
+ "global/list-signals": {
225
+ args: { filter?: string };
226
+ result: { signals: HalSignalInfo[] };
227
+ };
228
+
229
+ /** List all pins, params, and signals in HAL */
230
+ "global/list-all": {
231
+ args: {};
232
+ result: {
233
+ pins: HalPinInfo[];
234
+ params: HalParamInfo[];
235
+ signals: HalSignalInfo[];
236
+ };
237
+ };
238
+
239
+ /** Get RTAPI message level */
240
+ "global/msg-level-get": {
241
+ args: {};
242
+ result: { level: RtapiMsgLevel };
243
+ };
244
+
245
+ /** Set RTAPI message level */
246
+ "global/msg-level-set": {
247
+ args: { level: RtapiMsgLevel };
248
+ result: { success: boolean; previousLevel: RtapiMsgLevel };
249
+ };
250
+
251
+ // =========================================================================
252
+ // CONNECTION: Status and health for this connection
253
+ // =========================================================================
254
+
255
+ /** Health check */
256
+ ping: {
257
+ args: {};
258
+ result: { timestamp: number };
259
+ };
260
+
261
+ /** Get backend status for this connection */
262
+ "get-status": {
263
+ args: {};
264
+ result: {
265
+ connected: boolean;
266
+ componentName: string;
267
+ componentReady: boolean;
268
+ pinCount: number;
269
+ paramCount: number;
270
+ uptime: number;
271
+ };
272
+ };
273
+ };
274
+
275
+ // -------------------------------------------------------------------------
276
+ // Requests that host sends, peer handles
277
+ // -------------------------------------------------------------------------
278
+ peerHandles: {
279
+ /** Host requests peer to confirm it's alive */
280
+ "health-check": {
281
+ args: {};
282
+ result: { alive: boolean; timestamp: number };
283
+ };
284
+ };
285
+ }
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./gcode-protocol";
2
+ export * from "./hal-protocol";
3
+ export * from "./linuxcnc-protocol";
4
+ export * from "./position-logger-protocol";
@@ -0,0 +1,444 @@
1
+ /**
2
+ * LinuxCNC Core Protocol Definition
3
+ *
4
+ * Defines the typed contract for LinuxCNC communication over AppBus.
5
+ * Wraps StatChannel, CommandChannel, and ErrorChannel.
6
+ */
7
+
8
+ import type { ChannelProtocol } from "@edenapp/types";
9
+ import type {
10
+ LinuxCNCStat,
11
+ LinuxCNCStatPaths,
12
+ LinuxCNCError,
13
+ RcsStatus,
14
+ TaskMode,
15
+ TaskState,
16
+ TrajMode,
17
+ DebugFlags,
18
+ ToolEntry,
19
+ RecursivePartial,
20
+ StatChange,
21
+ } from "@linuxcnc-node/types";
22
+
23
+ // ============================================================================
24
+ // Types (re-export for convenience)
25
+ // ============================================================================
26
+
27
+ export type {
28
+ LinuxCNCStat,
29
+ LinuxCNCStatPaths,
30
+ LinuxCNCError,
31
+ RcsStatus,
32
+ TaskMode,
33
+ TaskState,
34
+ TrajMode,
35
+ DebugFlags,
36
+ ToolEntry,
37
+ StatChange,
38
+ };
39
+
40
+ // ============================================================================
41
+ // Protocol Definition
42
+ // ============================================================================
43
+
44
+ /**
45
+ * Protocol for LinuxCNC core operations over AppBus.
46
+ */
47
+ export interface LinuxCNCProtocol extends ChannelProtocol {
48
+ hostMessages: {
49
+ /** Flat delta: only changed paths with their new values */
50
+ "stat-delta": {
51
+ /** Changed paths and values */
52
+ changes: StatChange[];
53
+ /** Monotonic cursor for sync verification */
54
+ cursor: number;
55
+ timestamp: number;
56
+ };
57
+
58
+ /** Error/message from LinuxCNC */
59
+ "error-channel-event": LinuxCNCError;
60
+
61
+ /** Backend error */
62
+ error: {
63
+ code: string;
64
+ message: string;
65
+ };
66
+ };
67
+
68
+ peerMessages: {};
69
+
70
+ hostHandles: {
71
+ // =========================================================================
72
+ // STAT: Status monitoring
73
+ // =========================================================================
74
+
75
+ /**
76
+ * Get full LinuxCNC stat snapshot.
77
+ * @returns Full stat plus current cursor
78
+ */
79
+ "stat/sync": {
80
+ args: {};
81
+ result: {
82
+ stat: LinuxCNCStat;
83
+ cursor: number;
84
+ };
85
+ };
86
+
87
+ /** Get specific stat value by path */
88
+ "stat/get-value": {
89
+ args: { path: LinuxCNCStatPaths };
90
+ result: { value: unknown };
91
+ };
92
+
93
+ // =========================================================================
94
+ // COMMAND: Task control
95
+ // =========================================================================
96
+
97
+ /** Set task mode (MDI, MANUAL, AUTO) */
98
+ "cmd/set-task-mode": {
99
+ args: { mode: TaskMode };
100
+ result: RcsStatus;
101
+ };
102
+
103
+ /** Set machine state (ESTOP, ESTOP_RESET, OFF, ON) */
104
+ "cmd/set-state": {
105
+ args: { state: TaskState };
106
+ result: RcsStatus;
107
+ };
108
+
109
+ /** Execute MDI command */
110
+ "cmd/mdi": {
111
+ args: { command: string };
112
+ result: RcsStatus;
113
+ };
114
+
115
+ /** Abort current task */
116
+ "cmd/abort": {
117
+ args: {};
118
+ result: RcsStatus;
119
+ };
120
+
121
+ /** Sync VAR file to disk */
122
+ "cmd/task-plan-synch": {
123
+ args: {};
124
+ result: RcsStatus;
125
+ };
126
+
127
+ /** Reset G-code interpreter */
128
+ "cmd/reset-interpreter": {
129
+ args: {};
130
+ result: RcsStatus;
131
+ };
132
+
133
+ // =========================================================================
134
+ // COMMAND: Program control
135
+ // =========================================================================
136
+
137
+ /** Open G-code program file */
138
+ "cmd/program-open": {
139
+ args: { filePath: string };
140
+ result: RcsStatus;
141
+ };
142
+
143
+ /** Run program from line */
144
+ "cmd/program-run": {
145
+ args: { startLine?: number };
146
+ result: RcsStatus;
147
+ };
148
+
149
+ /** Pause program execution */
150
+ "cmd/program-pause": {
151
+ args: {};
152
+ result: RcsStatus;
153
+ };
154
+
155
+ /** Resume paused program */
156
+ "cmd/program-resume": {
157
+ args: {};
158
+ result: RcsStatus;
159
+ };
160
+
161
+ /** Step one line */
162
+ "cmd/program-step": {
163
+ args: {};
164
+ result: RcsStatus;
165
+ };
166
+
167
+ /** Reverse execution direction */
168
+ "cmd/program-reverse": {
169
+ args: {};
170
+ result: RcsStatus;
171
+ };
172
+
173
+ /** Forward execution direction */
174
+ "cmd/program-forward": {
175
+ args: {};
176
+ result: RcsStatus;
177
+ };
178
+
179
+ // =========================================================================
180
+ // COMMAND: Motion control
181
+ // =========================================================================
182
+
183
+ /** Set feedrate override scale (1.0 = 100%) */
184
+ "cmd/set-feed-rate": {
185
+ args: { scale: number };
186
+ result: RcsStatus;
187
+ };
188
+
189
+ /** Set rapid override scale (1.0 = 100%) */
190
+ "cmd/set-rapid-rate": {
191
+ args: { scale: number };
192
+ result: RcsStatus;
193
+ };
194
+
195
+ /** Set max trajectory velocity */
196
+ "cmd/set-max-velocity": {
197
+ args: { velocity: number };
198
+ result: RcsStatus;
199
+ };
200
+
201
+ /** Set trajectory mode (FREE, COORD, TELEOP) */
202
+ "cmd/set-traj-mode": {
203
+ args: { mode: TrajMode };
204
+ result: RcsStatus;
205
+ };
206
+
207
+ /** Enable/disable teleop mode */
208
+ "cmd/teleop-enable": {
209
+ args: { enable: boolean };
210
+ result: RcsStatus;
211
+ };
212
+
213
+ /** Enable/disable feedrate override */
214
+ "cmd/set-feed-override-enable": {
215
+ args: { enable: boolean };
216
+ result: RcsStatus;
217
+ };
218
+
219
+ /** Enable/disable feed hold */
220
+ "cmd/set-feed-hold-enable": {
221
+ args: { enable: boolean };
222
+ result: RcsStatus;
223
+ };
224
+
225
+ /** Enable/disable adaptive feed */
226
+ "cmd/set-adaptive-feed-enable": {
227
+ args: { enable: boolean };
228
+ result: RcsStatus;
229
+ };
230
+
231
+ // =========================================================================
232
+ // COMMAND: Jogging
233
+ // =========================================================================
234
+
235
+ /** Start continuous jog */
236
+ "cmd/jog-continuous": {
237
+ args: { axis: number; speed: number; isJoint?: boolean };
238
+ result: RcsStatus;
239
+ };
240
+
241
+ /** Jog a fixed increment */
242
+ "cmd/jog-increment": {
243
+ args: {
244
+ axis: number;
245
+ speed: number;
246
+ increment: number;
247
+ isJoint?: boolean;
248
+ };
249
+ result: RcsStatus;
250
+ };
251
+
252
+ /** Stop jogging */
253
+ "cmd/jog-stop": {
254
+ args: { axis: number; isJoint?: boolean };
255
+ result: RcsStatus;
256
+ };
257
+
258
+ // =========================================================================
259
+ // COMMAND: Homing
260
+ // =========================================================================
261
+
262
+ /** Home a joint (-1 for all) */
263
+ "cmd/home": {
264
+ args: { joint: number };
265
+ result: RcsStatus;
266
+ };
267
+
268
+ /** Unhome a joint (-1 for all) */
269
+ "cmd/unhome": {
270
+ args: { joint: number };
271
+ result: RcsStatus;
272
+ };
273
+
274
+ /** Set joint min position limit */
275
+ "cmd/set-min-position-limit": {
276
+ args: { joint: number; limit: number };
277
+ result: RcsStatus;
278
+ };
279
+
280
+ /** Set joint max position limit */
281
+ "cmd/set-max-position-limit": {
282
+ args: { joint: number; limit: number };
283
+ result: RcsStatus;
284
+ };
285
+
286
+ // =========================================================================
287
+ // COMMAND: Spindle
288
+ // =========================================================================
289
+
290
+ /** Turn spindle on at RPM (positive=CW, negative=CCW) */
291
+ "cmd/spindle-on": {
292
+ args: { speed: number; spindle?: number; wait?: boolean };
293
+ result: RcsStatus;
294
+ };
295
+
296
+ /** Turn spindle off */
297
+ "cmd/spindle-off": {
298
+ args: { spindle?: number };
299
+ result: RcsStatus;
300
+ };
301
+
302
+ /** Set spindle override scale (1.0 = 100%) */
303
+ "cmd/spindle-override": {
304
+ args: { scale: number; spindle?: number };
305
+ result: RcsStatus;
306
+ };
307
+
308
+ /** Engage/release spindle brake */
309
+ "cmd/spindle-brake": {
310
+ args: { engage: boolean; spindle?: number };
311
+ result: RcsStatus;
312
+ };
313
+
314
+ /** Increase spindle speed */
315
+ "cmd/spindle-increase": {
316
+ args: { spindle?: number };
317
+ result: RcsStatus;
318
+ };
319
+
320
+ /** Decrease spindle speed */
321
+ "cmd/spindle-decrease": {
322
+ args: { spindle?: number };
323
+ result: RcsStatus;
324
+ };
325
+
326
+ /** Enable/disable spindle override */
327
+ "cmd/set-spindle-override-enable": {
328
+ args: { enable: boolean; spindle?: number };
329
+ result: RcsStatus;
330
+ };
331
+
332
+ // =========================================================================
333
+ // COMMAND: Coolant
334
+ // =========================================================================
335
+
336
+ /** Turn mist coolant on/off */
337
+ "cmd/set-mist": {
338
+ args: { on: boolean };
339
+ result: RcsStatus;
340
+ };
341
+
342
+ /** Turn flood coolant on/off */
343
+ "cmd/set-flood": {
344
+ args: { on: boolean };
345
+ result: RcsStatus;
346
+ };
347
+
348
+ // =========================================================================
349
+ // COMMAND: Tool
350
+ // =========================================================================
351
+
352
+ /** Reload tool table from disk */
353
+ "cmd/load-tool-table": {
354
+ args: {};
355
+ result: RcsStatus;
356
+ };
357
+
358
+ /** Set tool data */
359
+ "cmd/set-tool": {
360
+ args: { tool: RecursivePartial<ToolEntry> & { toolNo: number } };
361
+ result: RcsStatus;
362
+ };
363
+
364
+ // =========================================================================
365
+ // COMMAND: I/O
366
+ // =========================================================================
367
+
368
+ /** Set digital output pin */
369
+ "cmd/set-digital-output": {
370
+ args: { index: number; value: boolean };
371
+ result: RcsStatus;
372
+ };
373
+
374
+ /** Set analog output value */
375
+ "cmd/set-analog-output": {
376
+ args: { index: number; value: number };
377
+ result: RcsStatus;
378
+ };
379
+
380
+ // =========================================================================
381
+ // COMMAND: Misc
382
+ // =========================================================================
383
+
384
+ /** Override soft limits for recovery */
385
+ "cmd/override-limits": {
386
+ args: {};
387
+ result: RcsStatus;
388
+ };
389
+
390
+ /** Enable/disable optional stop (M1) */
391
+ "cmd/set-optional-stop": {
392
+ args: { enable: boolean };
393
+ result: RcsStatus;
394
+ };
395
+
396
+ /** Enable/disable block delete (/) */
397
+ "cmd/set-block-delete": {
398
+ args: { enable: boolean };
399
+ result: RcsStatus;
400
+ };
401
+
402
+ /** Set debug flags */
403
+ "cmd/set-debug-level": {
404
+ args: { level: DebugFlags };
405
+ result: RcsStatus;
406
+ };
407
+
408
+ /** Send error to operator display */
409
+ "cmd/send-operator-error": {
410
+ args: { message: string };
411
+ result: RcsStatus;
412
+ };
413
+
414
+ /** Send text to operator display */
415
+ "cmd/send-operator-text": {
416
+ args: { message: string };
417
+ result: RcsStatus;
418
+ };
419
+
420
+ /** Send message to operator display */
421
+ "cmd/send-operator-display": {
422
+ args: { message: string };
423
+ result: RcsStatus;
424
+ };
425
+
426
+ // =========================================================================
427
+ // CONNECTION
428
+ // =========================================================================
429
+
430
+ /** Health check */
431
+ ping: {
432
+ args: {};
433
+ result: { timestamp: number };
434
+ };
435
+ };
436
+
437
+ peerHandles: {
438
+ /** Host requests peer to confirm it's alive */
439
+ "health-check": {
440
+ args: {};
441
+ result: { alive: boolean; timestamp: number };
442
+ };
443
+ };
444
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "covenant-protocol",
3
+ "version": "0.1.0",
4
+ "description": "Protocol definitions for communicating with LinuxCNC through Eden's AppBus",
5
+ "types": "index.d.ts",
6
+ "scripts": {},
7
+ "author": "Dariusz Majnert",
8
+ "license": "MIT",
9
+ "dependencies": {
10
+ "@edenapp/types": "^0.2.1",
11
+ "@linuxcnc-node/types": "^2.1.1"
12
+ },
13
+ "peerDependencies": {
14
+ "typescript": "*"
15
+ },
16
+ "files": [
17
+ "*.d.ts",
18
+ "README.md"
19
+ ],
20
+ "keywords": [
21
+ "covenant",
22
+ "protocol",
23
+ "ipc",
24
+ "linuxcnc",
25
+ "hal",
26
+ "typescript"
27
+ ]
28
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Position Logger Protocol Definition
3
+ *
4
+ * Defines the typed contract for machine position logging and streaming.
5
+ * Used for toolpath visualization and motion history.
6
+ */
7
+
8
+ import type { ChannelProtocol } from "@edenapp/types";
9
+ import type { PositionLoggerIndex } from "@linuxcnc-node/types";
10
+
11
+ // ============================================================================
12
+ // Types (re-export for convenience)
13
+ // ============================================================================
14
+
15
+ export type { PositionLoggerIndex };
16
+
17
+ // Note: POSITION_STRIDE constant should be imported directly from @linuxcnc-node/types
18
+
19
+ // ============================================================================
20
+ // Protocol Definition
21
+ // ============================================================================
22
+
23
+ /**
24
+ * Protocol for position logging over AppBus.
25
+ *
26
+ * Tracks machine tool path over time. All positions are returned as Float64Array
27
+ * with 10 elements per point: [x, y, z, a, b, c, u, v, w, motionType]
28
+ *
29
+ * Use PositionLoggerIndex enum and POSITION_STRIDE constant for array access.
30
+ */
31
+ export interface PositionLoggerProtocol extends ChannelProtocol {
32
+ hostMessages: {
33
+ /**
34
+ * Delta position update (pushed at configured interval)
35
+ * Contains only NEW points since the last update for this connection.
36
+ */
37
+ "position-update": {
38
+ /** New points since last update (Float64Array with POSITION_STRIDE per point) */
39
+ points: Float64Array;
40
+ /** Number of new points in this update */
41
+ count: number;
42
+ /** Server-side cursor after this update (monotonic, for sync verification) */
43
+ cursor: number;
44
+ };
45
+
46
+ /** Backend error */
47
+ error: {
48
+ code: string;
49
+ message: string;
50
+ };
51
+ };
52
+
53
+ peerMessages: {};
54
+
55
+ hostHandles: {
56
+ /**
57
+ * Start position logging
58
+ * @param interval - Logging interval in seconds (default: 0.01)
59
+ * @param maxHistory - Maximum number of points to keep in history (default: 10000)
60
+ */
61
+ start: {
62
+ args: { interval?: number; maxHistory?: number };
63
+ result: { success: boolean; cursor: number };
64
+ };
65
+
66
+ /** Stop position logging */
67
+ stop: {
68
+ args: {};
69
+ result: { success: boolean };
70
+ };
71
+
72
+ /** Clear the position history (invalidates all previous cursors) */
73
+ clear: {
74
+ args: {};
75
+ result: { success: boolean };
76
+ };
77
+
78
+ /**
79
+ * Get full position history.
80
+ * @returns Complete history as Float64Array plus point count and cursor
81
+ */
82
+ sync: {
83
+ args: {};
84
+ result: {
85
+ /** Full position history */
86
+ history: Float64Array;
87
+ /** Number of points in history */
88
+ count: number;
89
+ /** Current cursor for delta updates */
90
+ cursor: number;
91
+ };
92
+ };
93
+
94
+ /**
95
+ * Get the current position as a Float64Array
96
+ * Layout: [x, y, z, a, b, c, u, v, w, motionType]
97
+ * @returns Float64Array with 10 values, or null if no position available
98
+ */
99
+ "get-current": {
100
+ args: {};
101
+ result: { position: Float64Array | null };
102
+ };
103
+
104
+ /** Get current cursor position without any data */
105
+ "get-cursor": {
106
+ args: {};
107
+ result: { cursor: number };
108
+ };
109
+
110
+ /** Health check */
111
+ ping: {
112
+ args: {};
113
+ result: { timestamp: number };
114
+ };
115
+ };
116
+
117
+ peerHandles: {};
118
+ }