linuxcnc-grpc 1.0.0-beta.4 → 1.1.0-rc.1

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.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ <!-- AUTO-GENERATED from root README.md — do not edit directly -->
2
+ <!-- Regenerate with: ./scripts/generate-package-readmes.sh -->
3
+
4
+ # linuxcnc-grpc
5
+
6
+ [![PyPI](https://img.shields.io/pypi/v/linuxcnc-grpc)](https://pypi.org/project/linuxcnc-grpc/)
7
+ [![npm](https://img.shields.io/npm/v/linuxcnc-grpc)](https://www.npmjs.com/package/linuxcnc-grpc)
8
+ [![crates.io](https://img.shields.io/crates/v/linuxcnc-grpc)](https://crates.io/crates/linuxcnc-grpc)
9
+ [![Go Reference](https://pkg.go.dev/badge/github.com/dougcalobrisi/linuxcnc-grpc.svg)](https://pkg.go.dev/github.com/dougcalobrisi/linuxcnc-grpc)
10
+
11
+ gRPC interface for LinuxCNC machine control and HAL (Hardware Abstraction Layer).
12
+
13
+ ## Why gRPC?
14
+
15
+ LinuxCNC's native Python API only works locally. This project exposes it over gRPC, enabling:
16
+
17
+ - **Remote monitoring** - Build web dashboards, mobile apps, or desktop GUIs
18
+ - **Multi-machine management** - Monitor a fleet of CNC machines from one place
19
+ - **Any-language integration** - Use Go, Node.js, Rust, or any gRPC-supported language
20
+ - **Real-time streaming** - Subscribe to status updates instead of polling
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install linuxcnc-grpc
26
+ ```
27
+
28
+ > [npm package](https://www.npmjs.com/package/linuxcnc-grpc)
29
+
30
+ ```typescript
31
+ import * as grpc from "@grpc/grpc-js";
32
+ import { LinuxCNCServiceClient, GetStatusRequest } from "linuxcnc-grpc";
33
+
34
+ const client = new LinuxCNCServiceClient("localhost:50051", grpc.credentials.createInsecure());
35
+
36
+ client.getStatus(GetStatusRequest.create(), (err, status) => {
37
+ if (err) throw err;
38
+ const pos = status!.position!.actualPosition!;
39
+ console.log(`Position: X=${pos.x.toFixed(3)} Y=${pos.y.toFixed(3)} Z=${pos.z.toFixed(3)}`);
40
+ });
41
+ ```
42
+
43
+ ## Examples
44
+
45
+ See the [examples directory](https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/examples/node) for complete Node.js/TypeScript examples:
46
+
47
+ - `get_status` — Poll machine status
48
+ - `stream_status` — Real-time status streaming
49
+ - `jog_axis` — Jog axes with keyboard
50
+ - `mdi_command` — Execute G-code via MDI
51
+ - `hal_query` — Query HAL pins/signals
52
+ - `upload_file` — Upload, list, delete G-code files
53
+
54
+ ## Services
55
+
56
+ - **LinuxCNCService** — Machine control: status, jogging, MDI, program execution, file management
57
+ - **HalService** — HAL introspection: query pins, signals, parameters (read-only)
58
+
59
+ ## Documentation
60
+
61
+ See the [full documentation](https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/docs) for server setup, API reference, and tutorials.
62
+
63
+ ## Safety Warning
64
+
65
+ This package communicates with a gRPC server that controls real CNC machinery. Ensure proper safety measures:
66
+
67
+ - Use only on trusted networks
68
+ - Implement authentication in production (gRPC supports TLS/mTLS)
69
+ - Never leave machines unattended during remote operation
70
+ - Verify E-stop and safety systems are functional
71
+
72
+ ## License
73
+
74
+ [MIT](https://github.com/dougcalobrisi/linuxcnc-grpc/blob/main/LICENSE)
@@ -49,9 +49,10 @@ const hal_1 = require("../hal");
49
49
  const fixturesPath = path.join(__dirname, '../../../../tests/fixtures');
50
50
  const linuxcncFixture = JSON.parse(fs.readFileSync(path.join(fixturesPath, 'linuxcnc_status.json'), 'utf-8'));
51
51
  const halFixture = JSON.parse(fs.readFileSync(path.join(fixturesPath, 'hal_status.json'), 'utf-8'));
52
- // Test configuration
53
- const MOCK_SERVER_PORT = 50097;
54
- const MOCK_SERVER_ADDRESS = `localhost:${MOCK_SERVER_PORT}`;
52
+ // Test configuration. The mock server binds a free port (port 0) and names
53
+ // it in its READY line, so runs of this suite at the same time cannot meet
54
+ // each other's mock.
55
+ let mockServerAddress = '';
55
56
  const MOCK_SERVER_SCRIPT = path.join(__dirname, '../../../../tests/mock_server.py');
56
57
  let mockServer;
57
58
  let linuxcncClient;
@@ -69,27 +70,34 @@ function promisify(fn) {
69
70
  }
70
71
  (0, vitest_1.beforeAll)(async () => {
71
72
  // Start mock server
72
- mockServer = (0, child_process_1.spawn)('python3', [MOCK_SERVER_SCRIPT, '--port', String(MOCK_SERVER_PORT)], {
73
+ mockServer = (0, child_process_1.spawn)('python3', [MOCK_SERVER_SCRIPT, '--port', '0'], {
73
74
  stdio: ['pipe', 'pipe', 'pipe'],
74
75
  });
75
- // Wait for ready signal
76
- await new Promise((resolve, reject) => {
76
+ // Wait for the READY:<port> line
77
+ mockServerAddress = await new Promise((resolve, reject) => {
77
78
  const timeout = setTimeout(() => reject(new Error('Mock server startup timeout')), 10000);
79
+ let printedSoFar = '';
78
80
  mockServer.stdout?.on('data', (data) => {
79
- if (data.toString().includes('READY:')) {
81
+ printedSoFar += data.toString();
82
+ const ready = /READY:(\d+)/.exec(printedSoFar);
83
+ if (ready) {
80
84
  clearTimeout(timeout);
81
- resolve();
85
+ resolve(`localhost:${ready[1]}`);
82
86
  }
83
87
  });
84
88
  mockServer.on('error', (err) => {
85
89
  clearTimeout(timeout);
86
90
  reject(err);
87
91
  });
92
+ mockServer.on('exit', (code) => {
93
+ clearTimeout(timeout);
94
+ reject(new Error(`Mock server ended (exit code ${code}) without a READY:<port> line`));
95
+ });
88
96
  });
89
97
  // Create clients
90
98
  const credentials = grpc.credentials.createInsecure();
91
- linuxcncClient = new linuxcnc_1.LinuxCNCServiceClient(MOCK_SERVER_ADDRESS, credentials);
92
- halClient = new hal_1.HalServiceClient(MOCK_SERVER_ADDRESS, credentials);
99
+ linuxcncClient = new linuxcnc_1.LinuxCNCServiceClient(mockServerAddress, credentials);
100
+ halClient = new hal_1.HalServiceClient(mockServerAddress, credentials);
93
101
  });
94
102
  (0, vitest_1.afterAll)(() => {
95
103
  // Close clients
@@ -146,6 +154,31 @@ function promisify(fn) {
146
154
  const response = await sendCommand(command);
147
155
  (0, vitest_1.expect)(response.serial).toBe(101);
148
156
  (0, vitest_1.expect)(response.status).toBe(linuxcnc_1.RcsStatus.RCS_DONE);
157
+ (0, vitest_1.expect)(response.linuxcncSerial).toBeDefined();
158
+ (0, vitest_1.expect)(response.linuxcncSerial).not.toBe(response.serial);
159
+ });
160
+ (0, vitest_1.it)('SendCommand reports that the task acknowledged the command', async () => {
161
+ const sendCommand = promisify(linuxcncClient.sendCommand.bind(linuxcncClient));
162
+ const response = await sendCommand(linuxcnc_1.LinuxCNCCommand.create({ serial: 103, mdi: { command: 'G0 X1' } }));
163
+ (0, vitest_1.expect)(response.status).toBe(linuxcnc_1.RcsStatus.RCS_DONE);
164
+ (0, vitest_1.expect)(response.acknowledged).toBe(true);
165
+ (0, vitest_1.expect)(response.notSent).toBe(false);
166
+ });
167
+ (0, vitest_1.it)('SendCommand answers a stop like any command', async () => {
168
+ const sendCommand = promisify(linuxcncClient.sendCommand.bind(linuxcncClient));
169
+ const response = await sendCommand(linuxcnc_1.LinuxCNCCommand.create({ state: { state: linuxcnc_1.TaskState.STATE_ESTOP } }));
170
+ (0, vitest_1.expect)(response.status).toBe(linuxcnc_1.RcsStatus.RCS_DONE);
171
+ // The mock's LinuxCNC takes every command at once.
172
+ (0, vitest_1.expect)(response.acknowledged).toBe(true);
173
+ });
174
+ (0, vitest_1.it)('SendCommand marks a refused command as not sent', async () => {
175
+ const sendCommand = promisify(linuxcncClient.sendCommand.bind(linuxcncClient));
176
+ // The mock machine has three joints, so joint 3 is refused before
177
+ // anything is sent.
178
+ const response = await sendCommand(linuxcnc_1.LinuxCNCCommand.create({ serial: 104, home: { joint: 3 } }));
179
+ (0, vitest_1.expect)(response.status).toBe(linuxcnc_1.RcsStatus.RCS_ERROR);
180
+ (0, vitest_1.expect)(response.notSent).toBe(true);
181
+ (0, vitest_1.expect)(response.acknowledged).toBeUndefined();
149
182
  });
150
183
  (0, vitest_1.it)('SendCommand with jog command succeeds', async () => {
151
184
  const sendCommand = promisify(linuxcncClient.sendCommand.bind(linuxcncClient));
@@ -172,6 +205,15 @@ function promisify(fn) {
172
205
  (0, vitest_1.expect)(response.serial).toBe(50);
173
206
  (0, vitest_1.expect)(response.status).toBe(linuxcnc_1.RcsStatus.RCS_DONE);
174
207
  });
208
+ (0, vitest_1.it)('GetServerInfo returns the server version and the LinuxCNC connection', async () => {
209
+ const getServerInfo = promisify(linuxcncClient.getServerInfo.bind(linuxcncClient));
210
+ const serverInfo = await getServerInfo(linuxcnc_1.GetServerInfoRequest.create());
211
+ (0, vitest_1.expect)(serverInfo.serverVersion).toBe('0.0.0-mock');
212
+ (0, vitest_1.expect)(serverInfo.linuxcncConnected).toBe(true);
213
+ (0, vitest_1.expect)(serverInfo.linuxcncVersion).toBe('2.9.0-mock');
214
+ (0, vitest_1.expect)(serverInfo.errorChannelMode).toBe('always');
215
+ (0, vitest_1.expect)(serverInfo.stopsNotTaken).toBe(0);
216
+ });
175
217
  (0, vitest_1.it)('StreamStatus returns multiple updates', async () => {
176
218
  const stream = linuxcncClient.streamStatus(linuxcnc_1.StreamStatusRequest.create({ intervalMs: 50 }));
177
219
  const updates = [];
@@ -0,0 +1,11 @@
1
+ /**
2
+ * How 64-bit integers arrive in the generated TypeScript.
3
+ *
4
+ * Every int64 and uint64 field is a JavaScript number. Timestamps are sent in
5
+ * nanoseconds, which do not fit a number exactly, and arrive as milliseconds.
6
+ * Every other 64-bit field arrives unscaled, as the nearest number.
7
+ *
8
+ * The messages are built from decimal strings with the wire writer, so the
9
+ * bytes hold the exact 64-bit value whatever a number could carry.
10
+ */
11
+ export {};
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ /**
3
+ * How 64-bit integers arrive in the generated TypeScript.
4
+ *
5
+ * Every int64 and uint64 field is a JavaScript number. Timestamps are sent in
6
+ * nanoseconds, which do not fit a number exactly, and arrive as milliseconds.
7
+ * Every other 64-bit field arrives unscaled, as the nearest number.
8
+ *
9
+ * The messages are built from decimal strings with the wire writer, so the
10
+ * bytes hold the exact 64-bit value whatever a number could carry.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ const wire_1 = require("@bufbuild/protobuf/wire");
14
+ const vitest_1 = require("vitest");
15
+ const hal_1 = require("../hal");
16
+ const linuxcnc_1 = require("../linuxcnc");
17
+ // Field numbers from the proto files.
18
+ const HAL_VALUE_S64_FIELD = 5;
19
+ const HAL_VALUE_U64_FIELD = 6;
20
+ const VARINT_WIRE_TYPE = 0;
21
+ function varintTag(fieldNumber) {
22
+ return (fieldNumber << 3) | VARINT_WIRE_TYPE;
23
+ }
24
+ function encodeSigned(fieldNumber, decimalValue) {
25
+ return new wire_1.BinaryWriter().uint32(varintTag(fieldNumber)).int64(decimalValue).finish();
26
+ }
27
+ function encodeUnsigned(fieldNumber, decimalValue) {
28
+ return new wire_1.BinaryWriter().uint32(varintTag(fieldNumber)).uint64(decimalValue).finish();
29
+ }
30
+ function decodeS64(decimalValue) {
31
+ return hal_1.HalValue.decode(encodeSigned(HAL_VALUE_S64_FIELD, decimalValue)).s64Value;
32
+ }
33
+ function decodeU64(decimalValue) {
34
+ return hal_1.HalValue.decode(encodeUnsigned(HAL_VALUE_U64_FIELD, decimalValue)).u64Value;
35
+ }
36
+ (0, vitest_1.describe)('HAL 64-bit values', () => {
37
+ (0, vitest_1.it)('are exact up to Number.MAX_SAFE_INTEGER', () => {
38
+ (0, vitest_1.expect)(decodeS64('9007199254740991')).toBe(Number.MAX_SAFE_INTEGER);
39
+ (0, vitest_1.expect)(decodeS64('-9007199254740991')).toBe(Number.MIN_SAFE_INTEGER);
40
+ (0, vitest_1.expect)(decodeU64('9007199254740991')).toBe(Number.MAX_SAFE_INTEGER);
41
+ });
42
+ (0, vitest_1.it)('just above 2^53 arrive as the nearest number, not divided by a million', () => {
43
+ // 2^53 + 1 has no exact number; the nearest one is 2^53.
44
+ (0, vitest_1.expect)(decodeS64('9007199254740993')).toBe(2 ** 53);
45
+ (0, vitest_1.expect)(decodeS64('-9007199254740993')).toBe(-(2 ** 53));
46
+ (0, vitest_1.expect)(decodeU64('9007199254740993')).toBe(2 ** 53);
47
+ // 2^53 + 2 is a number itself.
48
+ (0, vitest_1.expect)(decodeS64('9007199254740994')).toBe(9007199254740994);
49
+ (0, vitest_1.expect)(decodeU64('9007199254740994')).toBe(9007199254740994);
50
+ });
51
+ (0, vitest_1.it)('well above 2^53 arrive unscaled', () => {
52
+ (0, vitest_1.expect)(decodeS64('1152921504606846976')).toBe(2 ** 60);
53
+ (0, vitest_1.expect)(decodeS64('-1152921504606846976')).toBe(-(2 ** 60));
54
+ (0, vitest_1.expect)(decodeU64('1152921504606846976')).toBe(2 ** 60);
55
+ (0, vitest_1.expect)(decodeU64('9223372036854775808')).toBe(2 ** 63);
56
+ });
57
+ (0, vitest_1.it)('at the ends of the 64-bit range arrive as the nearest number', () => {
58
+ (0, vitest_1.expect)(decodeS64('-9223372036854775808')).toBe(-(2 ** 63));
59
+ (0, vitest_1.expect)(decodeS64('9223372036854775807')).toBe(2 ** 63);
60
+ (0, vitest_1.expect)(decodeU64('18446744073709551615')).toBe(2 ** 64);
61
+ });
62
+ (0, vitest_1.it)('inside another message are decoded the same way', () => {
63
+ const change = hal_1.ValueChange.decode(new wire_1.BinaryWriter()
64
+ .uint32((3 << 3) | 2)
65
+ .bytes(encodeSigned(HAL_VALUE_S64_FIELD, '-1152921504606846976'))
66
+ .uint32((4 << 3) | 2)
67
+ .bytes(encodeUnsigned(HAL_VALUE_U64_FIELD, '1152921504606846976'))
68
+ .finish());
69
+ (0, vitest_1.expect)(change.oldValue?.s64Value).toBe(-(2 ** 60));
70
+ (0, vitest_1.expect)(change.newValue?.u64Value).toBe(2 ** 60);
71
+ });
72
+ (0, vitest_1.it)('are written to the wire unscaled', () => {
73
+ const signedReader = new wire_1.BinaryReader(hal_1.HalValue.encode({ s64Value: -(2 ** 60) }).finish());
74
+ (0, vitest_1.expect)(signedReader.uint32()).toBe(varintTag(HAL_VALUE_S64_FIELD));
75
+ (0, vitest_1.expect)(signedReader.int64().toString()).toBe('-1152921504606846976');
76
+ const unsignedReader = new wire_1.BinaryReader(hal_1.HalValue.encode({ u64Value: 2 ** 63 }).finish());
77
+ (0, vitest_1.expect)(unsignedReader.uint32()).toBe(varintTag(HAL_VALUE_U64_FIELD));
78
+ (0, vitest_1.expect)(unsignedReader.uint64().toString()).toBe('9223372036854775808');
79
+ });
80
+ (0, vitest_1.it)('survive an encode and decode round trip', () => {
81
+ const largeValue = 2 ** 60;
82
+ (0, vitest_1.expect)(hal_1.HalValue.decode(hal_1.HalValue.encode({ s64Value: largeValue }).finish()).s64Value).toBe(largeValue);
83
+ (0, vitest_1.expect)(hal_1.HalValue.decode(hal_1.HalValue.encode({ u64Value: largeValue }).finish()).u64Value).toBe(largeValue);
84
+ });
85
+ (0, vitest_1.it)('pass through JSON unscaled', () => {
86
+ (0, vitest_1.expect)(hal_1.HalValue.fromJSON({ s64Value: 2 ** 60 }).s64Value).toBe(2 ** 60);
87
+ (0, vitest_1.expect)(hal_1.HalValue.toJSON({ u64Value: 2 ** 60 })).toEqual({ u64Value: 2 ** 60 });
88
+ });
89
+ });
90
+ (0, vitest_1.describe)('other 64-bit fields that are not timestamps', () => {
91
+ (0, vitest_1.it)('ErrorMessage.sequence arrives unscaled', () => {
92
+ const message = linuxcnc_1.ErrorMessage.decode(encodeSigned(4, '1152921504606846976'));
93
+ (0, vitest_1.expect)(message.sequence).toBe(2 ** 60);
94
+ });
95
+ (0, vitest_1.it)('FileInfo.size_bytes arrives unscaled', () => {
96
+ const fileInfo = linuxcnc_1.FileInfo.decode(encodeSigned(3, '9007199254740993'));
97
+ (0, vitest_1.expect)(fileInfo.sizeBytes).toBe(2 ** 53);
98
+ });
99
+ (0, vitest_1.it)('ReadFileResponse.offset and total_size_bytes arrive unscaled', () => {
100
+ const response = linuxcnc_1.ReadFileResponse.decode(new wire_1.BinaryWriter()
101
+ .uint32(varintTag(3))
102
+ .int64('1152921504606846976')
103
+ .uint32(varintTag(4))
104
+ .int64('2305843009213693952')
105
+ .finish());
106
+ (0, vitest_1.expect)(response.offset).toBe(2 ** 60);
107
+ (0, vitest_1.expect)(response.totalSizeBytes).toBe(2 ** 61);
108
+ });
109
+ });
110
+ (0, vitest_1.describe)('timestamps', () => {
111
+ // 2023-11-14T22:13:20.123456789Z in nanoseconds since the epoch.
112
+ const NANOSECOND_TIMESTAMP = '1700000000123456789';
113
+ const SAME_TIME_IN_MILLISECONDS = 1700000000123;
114
+ (0, vitest_1.it)('in nanoseconds arrive as milliseconds', () => {
115
+ (0, vitest_1.expect)(hal_1.HalSystemStatus.decode(encodeSigned(1, NANOSECOND_TIMESTAMP)).timestamp).toBe(SAME_TIME_IN_MILLISECONDS);
116
+ (0, vitest_1.expect)(linuxcnc_1.LinuxCNCStatus.decode(encodeSigned(1, NANOSECOND_TIMESTAMP)).timestamp).toBe(SAME_TIME_IN_MILLISECONDS);
117
+ (0, vitest_1.expect)(linuxcnc_1.ErrorMessage.decode(encodeSigned(3, NANOSECOND_TIMESTAMP)).timestamp).toBe(SAME_TIME_IN_MILLISECONDS);
118
+ (0, vitest_1.expect)(hal_1.ValueChange.decode(encodeSigned(1, NANOSECOND_TIMESTAMP)).timestamp).toBe(SAME_TIME_IN_MILLISECONDS);
119
+ });
120
+ (0, vitest_1.it)('make the date they stand for', () => {
121
+ const status = hal_1.HalSystemStatus.decode(encodeSigned(1, NANOSECOND_TIMESTAMP));
122
+ (0, vitest_1.expect)(new Date(status.timestamp).toISOString()).toBe('2023-11-14T22:13:20.123Z');
123
+ });
124
+ (0, vitest_1.it)('of files arrive as milliseconds too', () => {
125
+ (0, vitest_1.expect)(linuxcnc_1.FileInfo.decode(encodeSigned(4, NANOSECOND_TIMESTAMP)).modifiedTimestamp).toBe(SAME_TIME_IN_MILLISECONDS);
126
+ (0, vitest_1.expect)(linuxcnc_1.ReadFileResponse.decode(encodeSigned(6, NANOSECOND_TIMESTAMP)).modifiedTimestamp).toBe(SAME_TIME_IN_MILLISECONDS);
127
+ });
128
+ (0, vitest_1.it)('small enough to be an exact number arrive unchanged', () => {
129
+ (0, vitest_1.expect)(hal_1.HalSystemStatus.decode(encodeSigned(1, '1700000000123')).timestamp).toBe(1700000000123);
130
+ (0, vitest_1.expect)(hal_1.HalSystemStatus.decode(encodeSigned(1, '9007199254740991')).timestamp).toBe(Number.MAX_SAFE_INTEGER);
131
+ });
132
+ (0, vitest_1.it)('before the epoch are scaled toward zero', () => {
133
+ (0, vitest_1.expect)(hal_1.HalSystemStatus.decode(encodeSigned(1, '-1700000000123456789')).timestamp).toBe(-SAME_TIME_IN_MILLISECONDS);
134
+ });
135
+ });
package/dist/hal.d.ts CHANGED
@@ -11,11 +11,11 @@ export declare enum HalType {
11
11
  HAL_S32 = 3,
12
12
  /** HAL_U32 - Unsigned 32-bit integer */
13
13
  HAL_U32 = 4,
14
- /** HAL_S64 - Signed 64-bit integer */
14
+ /** HAL_S64 - Signed integer; only reported for a value that does not fit 32 bits */
15
15
  HAL_S64 = 5,
16
- /** HAL_U64 - Unsigned 64-bit integer */
16
+ /** HAL_U64 - Unsigned integer; only reported for a value that does not fit 32 bits */
17
17
  HAL_U64 = 6,
18
- /** HAL_PORT - Port type (advanced) */
18
+ /** HAL_PORT - Port type (advanced); the server reports port pins with no value */
19
19
  HAL_PORT = 7,
20
20
  UNRECOGNIZED = -1
21
21
  }
@@ -70,9 +70,13 @@ export interface HalValue {
70
70
  floatValue?: number | undefined;
71
71
  s32Value?: number | undefined;
72
72
  u32Value?: number | undefined;
73
+ /**
74
+ * The two 64-bit values are numbers in the Node.js/TypeScript client:
75
+ * exact up to 2^53, the nearest number beyond that.
76
+ */
73
77
  s64Value?: number | undefined;
74
78
  u64Value?: number | undefined;
75
- /** Port type (advanced) */
79
+ /** Port type (advanced); never set by the server */
76
80
  portValue?: string | undefined;
77
81
  }
78
82
  /** Information about a HAL pin */
@@ -89,9 +93,12 @@ export interface HalPinInfo {
89
93
  direction: PinDirection;
90
94
  /** Current value */
91
95
  value: HalValue | undefined;
92
- /** Connected signal name (empty if none) */
96
+ /** Always empty: LinuxCNC's HAL Python module does not expose the connected signal */
93
97
  signal: string;
94
- /** True if pin has a writer */
98
+ /**
99
+ * True if the pin's signal has a writer. In StreamStatus this is refreshed
100
+ * every 2 seconds, not with every update.
101
+ */
95
102
  hasWriter: boolean;
96
103
  }
97
104
  /** Information about a HAL signal */
@@ -124,17 +131,22 @@ export interface HalParamInfo {
124
131
  /** Current value */
125
132
  value: HalValue | undefined;
126
133
  }
127
- /** Information about a HAL component */
134
+ /**
135
+ * Information about a HAL component. LinuxCNC's HAL Python module has no
136
+ * component list, so the server infers components from pin and parameter
137
+ * names (the part before the last dot). Only name, pins and params are filled
138
+ * in.
139
+ */
128
140
  export interface HalComponentInfo {
129
141
  /** Component name */
130
142
  name: string;
131
- /** Component ID */
143
+ /** Component ID; always 0 */
132
144
  id: number;
133
- /** True if component is ready */
145
+ /** Never set by the server */
134
146
  ready: boolean;
135
- /** Component type (RT, user, etc) */
147
+ /** Never set by the server */
136
148
  type: number;
137
- /** Process ID (for userspace components) */
149
+ /** Never set by the server */
138
150
  pid: number;
139
151
  /** List of pin names */
140
152
  pins: string[];
@@ -151,9 +163,9 @@ export interface HalSystemStatus {
151
163
  signals: HalSignalInfo[];
152
164
  /** All parameters */
153
165
  params: HalParamInfo[];
154
- /** All components */
166
+ /** Components inferred from pin and parameter names */
155
167
  components: HalComponentInfo[];
156
- /** Current message level */
168
+ /** RTAPI message level of the server process */
157
169
  messageLevel: MessageLevel;
158
170
  /** Running in simulation */
159
171
  isSim: boolean;
@@ -161,7 +173,7 @@ export interface HalSystemStatus {
161
173
  isRt: boolean;
162
174
  /** Userspace HAL */
163
175
  isUserspace: boolean;
164
- /** Kernel version */
176
+ /** Kernel version as HAL reports it; "Not Available" on uspace builds */
165
177
  kernelVersion: string;
166
178
  }
167
179
  /** Create a new HAL component */
@@ -325,7 +337,13 @@ export interface HalCommand {
325
337
  /** Connection commands */
326
338
  connect?: ConnectCommand | undefined;
327
339
  disconnect?: DisconnectCommand | undefined;
328
- /** Query commands */
340
+ /**
341
+ * Query commands. SendCommand answers only component_exists,
342
+ * component_ready and pin_has_writer. It refuses get_value and the
343
+ * query_* commands (its response cannot carry a result) and names the RPC
344
+ * to call instead: GetValue, QueryPins, QuerySignals, QueryParams or
345
+ * QueryComponents.
346
+ */
329
347
  getValue?: GetValueCommand | undefined;
330
348
  queryPins?: QueryPinsCommand | undefined;
331
349
  querySignals?: QuerySignalsCommand | undefined;
@@ -391,9 +409,12 @@ export interface QueryComponentsResponse {
391
409
  }
392
410
  /** Subscribe to value changes */
393
411
  export interface WatchRequest {
394
- /** Pin/signal/param names to watch */
412
+ /** Pin/signal/param names to watch; duplicates are ignored, at most 1000 names */
395
413
  names: string[];
396
- /** Minimum update interval in milliseconds (default: 100) */
414
+ /**
415
+ * Minimum update interval in milliseconds (default: 100). Values above
416
+ * 60000 are treated as 60000.
417
+ */
397
418
  intervalMs: number;
398
419
  }
399
420
  /** Value change notification */
@@ -416,9 +437,12 @@ export interface ValueChangeBatch {
416
437
  export interface GetSystemStatusRequest {
417
438
  }
418
439
  export interface HalStreamStatusRequest {
419
- /** Update interval in milliseconds (default: 100) */
440
+ /**
441
+ * Update interval in milliseconds (default: 100). Values above 60000 are
442
+ * treated as 60000.
443
+ */
420
444
  intervalMs: number;
421
- /** Optional: only include these components */
445
+ /** Currently ignored by the server: every component is included */
422
446
  filter: string[];
423
447
  }
424
448
  export declare const HalValue: MessageFns<HalValue>;
package/dist/hal.js CHANGED
@@ -29,11 +29,11 @@ var HalType;
29
29
  HalType[HalType["HAL_S32"] = 3] = "HAL_S32";
30
30
  /** HAL_U32 - Unsigned 32-bit integer */
31
31
  HalType[HalType["HAL_U32"] = 4] = "HAL_U32";
32
- /** HAL_S64 - Signed 64-bit integer */
32
+ /** HAL_S64 - Signed integer; only reported for a value that does not fit 32 bits */
33
33
  HalType[HalType["HAL_S64"] = 5] = "HAL_S64";
34
- /** HAL_U64 - Unsigned 64-bit integer */
34
+ /** HAL_U64 - Unsigned integer; only reported for a value that does not fit 32 bits */
35
35
  HalType[HalType["HAL_U64"] = 6] = "HAL_U64";
36
- /** HAL_PORT - Port type (advanced) */
36
+ /** HAL_PORT - Port type (advanced); the server reports port pins with no value */
37
37
  HalType[HalType["HAL_PORT"] = 7] = "HAL_PORT";
38
38
  HalType[HalType["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
39
39
  })(HalType || (exports.HalType = HalType = {}));
@@ -1029,7 +1029,7 @@ exports.HalSystemStatus = {
1029
1029
  if (tag !== 8) {
1030
1030
  break;
1031
1031
  }
1032
- message.timestamp = longToNumber(reader.int64());
1032
+ message.timestamp = timestampToNumber(reader.int64());
1033
1033
  continue;
1034
1034
  }
1035
1035
  case 2: {
@@ -2646,7 +2646,7 @@ exports.HalCommand = {
2646
2646
  if (tag !== 8) {
2647
2647
  break;
2648
2648
  }
2649
- message.timestamp = longToNumber(reader.int64());
2649
+ message.timestamp = timestampToNumber(reader.int64());
2650
2650
  continue;
2651
2651
  }
2652
2652
  case 2: {
@@ -3796,7 +3796,7 @@ exports.ValueChange = {
3796
3796
  if (tag !== 8) {
3797
3797
  break;
3798
3798
  }
3799
- message.timestamp = longToNumber(reader.int64());
3799
+ message.timestamp = timestampToNumber(reader.int64());
3800
3800
  continue;
3801
3801
  }
3802
3802
  case 2: {
@@ -3892,7 +3892,7 @@ exports.ValueChangeBatch = {
3892
3892
  if (tag !== 8) {
3893
3893
  break;
3894
3894
  }
3895
- message.timestamp = longToNumber(reader.int64());
3895
+ message.timestamp = timestampToNumber(reader.int64());
3896
3896
  continue;
3897
3897
  }
3898
3898
  case 2: {
@@ -4134,7 +4134,20 @@ exports.HalServiceService = {
4134
4134
  },
4135
4135
  };
4136
4136
  exports.HalServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.HalServiceService, "hal.HalService");
4137
+ /**
4138
+ * A 64-bit integer that is a value, not a timestamp. Beyond 2^53 the result
4139
+ * is the nearest number, so the low digits are lost; it is never scaled.
4140
+ * (Patched in by scripts/generate-protos.sh.)
4141
+ */
4137
4142
  function longToNumber(int64) {
4143
+ return globalThis.Number(int64.toString());
4144
+ }
4145
+ /**
4146
+ * A timestamp. The server sends nanoseconds, which do not fit a number, so a
4147
+ * value beyond the safe integer range is scaled to milliseconds.
4148
+ * (Patched in by scripts/generate-protos.sh.)
4149
+ */
4150
+ function timestampToNumber(int64) {
4138
4151
  const num = globalThis.Number(int64.toString());
4139
4152
  if (num > globalThis.Number.MAX_SAFE_INTEGER) {
4140
4153
  return Math.floor(num / 1e6);