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 +74 -0
- package/dist/__tests__/client.test.js +52 -10
- package/dist/__tests__/int64.test.d.ts +11 -0
- package/dist/__tests__/int64.test.js +135 -0
- package/dist/hal.d.ts +43 -19
- package/dist/hal.js +20 -7
- package/dist/linuxcnc.d.ts +490 -25
- package/dist/linuxcnc.js +1707 -92
- package/package.json +3 -3
- package/src/__tests__/client.test.ts +78 -10
- package/src/__tests__/int64.test.ts +183 -0
- package/src/hal.ts +64 -24
- package/src/linuxcnc.ts +2327 -118
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "linuxcnc-grpc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0-rc.1",
|
|
4
4
|
"description": "TypeScript/JavaScript gRPC client for LinuxCNC machine control and HAL",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"hal",
|
|
31
31
|
"typescript"
|
|
32
32
|
],
|
|
33
|
-
"author": "",
|
|
33
|
+
"author": "Doug Calobrisi",
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"homepage": "https://github.com/dougcalobrisi/linuxcnc-grpc#readme",
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@bufbuild/protobuf": "^2.0.0",
|
|
46
|
-
"@grpc/grpc-js": "~1.
|
|
46
|
+
"@grpc/grpc-js": "~1.13.6"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^20.0.0",
|
|
@@ -12,6 +12,8 @@ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
|
12
12
|
import {
|
|
13
13
|
LinuxCNCServiceClient,
|
|
14
14
|
GetStatusRequest,
|
|
15
|
+
GetServerInfoRequest,
|
|
16
|
+
ServerInfo,
|
|
15
17
|
LinuxCNCCommand,
|
|
16
18
|
WaitCompleteRequest,
|
|
17
19
|
StreamStatusRequest,
|
|
@@ -42,9 +44,10 @@ const halFixture = JSON.parse(
|
|
|
42
44
|
fs.readFileSync(path.join(fixturesPath, 'hal_status.json'), 'utf-8')
|
|
43
45
|
);
|
|
44
46
|
|
|
45
|
-
// Test configuration
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
// Test configuration. The mock server binds a free port (port 0) and names
|
|
48
|
+
// it in its READY line, so runs of this suite at the same time cannot meet
|
|
49
|
+
// each other's mock.
|
|
50
|
+
let mockServerAddress = '';
|
|
48
51
|
const MOCK_SERVER_SCRIPT = path.join(__dirname, '../../../../tests/mock_server.py');
|
|
49
52
|
|
|
50
53
|
let mockServer: ChildProcess;
|
|
@@ -66,18 +69,21 @@ function promisify<TReq, TRes>(
|
|
|
66
69
|
|
|
67
70
|
beforeAll(async () => {
|
|
68
71
|
// Start mock server
|
|
69
|
-
mockServer = spawn('python3', [MOCK_SERVER_SCRIPT, '--port',
|
|
72
|
+
mockServer = spawn('python3', [MOCK_SERVER_SCRIPT, '--port', '0'], {
|
|
70
73
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
71
74
|
});
|
|
72
75
|
|
|
73
|
-
// Wait for
|
|
74
|
-
await new Promise<
|
|
76
|
+
// Wait for the READY:<port> line
|
|
77
|
+
mockServerAddress = await new Promise<string>((resolve, reject) => {
|
|
75
78
|
const timeout = setTimeout(() => reject(new Error('Mock server startup timeout')), 10000);
|
|
79
|
+
let printedSoFar = '';
|
|
76
80
|
|
|
77
81
|
mockServer.stdout?.on('data', (data: Buffer) => {
|
|
78
|
-
|
|
82
|
+
printedSoFar += data.toString();
|
|
83
|
+
const ready = /READY:(\d+)/.exec(printedSoFar);
|
|
84
|
+
if (ready) {
|
|
79
85
|
clearTimeout(timeout);
|
|
80
|
-
resolve();
|
|
86
|
+
resolve(`localhost:${ready[1]}`);
|
|
81
87
|
}
|
|
82
88
|
});
|
|
83
89
|
|
|
@@ -85,12 +91,17 @@ beforeAll(async () => {
|
|
|
85
91
|
clearTimeout(timeout);
|
|
86
92
|
reject(err);
|
|
87
93
|
});
|
|
94
|
+
|
|
95
|
+
mockServer.on('exit', (code) => {
|
|
96
|
+
clearTimeout(timeout);
|
|
97
|
+
reject(new Error(`Mock server ended (exit code ${code}) without a READY:<port> line`));
|
|
98
|
+
});
|
|
88
99
|
});
|
|
89
100
|
|
|
90
101
|
// Create clients
|
|
91
102
|
const credentials = grpc.credentials.createInsecure();
|
|
92
|
-
linuxcncClient = new LinuxCNCServiceClient(
|
|
93
|
-
halClient = new HalServiceClient(
|
|
103
|
+
linuxcncClient = new LinuxCNCServiceClient(mockServerAddress, credentials);
|
|
104
|
+
halClient = new HalServiceClient(mockServerAddress, credentials);
|
|
94
105
|
});
|
|
95
106
|
|
|
96
107
|
afterAll(() => {
|
|
@@ -168,6 +179,49 @@ describe('LinuxCNCService', () => {
|
|
|
168
179
|
const response = await sendCommand(command);
|
|
169
180
|
expect(response.serial).toBe(101);
|
|
170
181
|
expect(response.status).toBe(RcsStatus.RCS_DONE);
|
|
182
|
+
expect(response.linuxcncSerial).toBeDefined();
|
|
183
|
+
expect(response.linuxcncSerial).not.toBe(response.serial);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('SendCommand reports that the task acknowledged the command', async () => {
|
|
187
|
+
const sendCommand = promisify<LinuxCNCCommand, any>(
|
|
188
|
+
linuxcncClient.sendCommand.bind(linuxcncClient)
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const response = await sendCommand(
|
|
192
|
+
LinuxCNCCommand.create({ serial: 103, mdi: { command: 'G0 X1' } })
|
|
193
|
+
);
|
|
194
|
+
expect(response.status).toBe(RcsStatus.RCS_DONE);
|
|
195
|
+
expect(response.acknowledged).toBe(true);
|
|
196
|
+
expect(response.notSent).toBe(false);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('SendCommand answers a stop like any command', async () => {
|
|
200
|
+
const sendCommand = promisify<LinuxCNCCommand, any>(
|
|
201
|
+
linuxcncClient.sendCommand.bind(linuxcncClient)
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const response = await sendCommand(
|
|
205
|
+
LinuxCNCCommand.create({ state: { state: TaskState.STATE_ESTOP } })
|
|
206
|
+
);
|
|
207
|
+
expect(response.status).toBe(RcsStatus.RCS_DONE);
|
|
208
|
+
// The mock's LinuxCNC takes every command at once.
|
|
209
|
+
expect(response.acknowledged).toBe(true);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('SendCommand marks a refused command as not sent', async () => {
|
|
213
|
+
const sendCommand = promisify<LinuxCNCCommand, any>(
|
|
214
|
+
linuxcncClient.sendCommand.bind(linuxcncClient)
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
// The mock machine has three joints, so joint 3 is refused before
|
|
218
|
+
// anything is sent.
|
|
219
|
+
const response = await sendCommand(
|
|
220
|
+
LinuxCNCCommand.create({ serial: 104, home: { joint: 3 } })
|
|
221
|
+
);
|
|
222
|
+
expect(response.status).toBe(RcsStatus.RCS_ERROR);
|
|
223
|
+
expect(response.notSent).toBe(true);
|
|
224
|
+
expect(response.acknowledged).toBeUndefined();
|
|
171
225
|
});
|
|
172
226
|
|
|
173
227
|
it('SendCommand with jog command succeeds', async () => {
|
|
@@ -205,6 +259,20 @@ describe('LinuxCNCService', () => {
|
|
|
205
259
|
expect(response.status).toBe(RcsStatus.RCS_DONE);
|
|
206
260
|
});
|
|
207
261
|
|
|
262
|
+
it('GetServerInfo returns the server version and the LinuxCNC connection', async () => {
|
|
263
|
+
const getServerInfo = promisify<GetServerInfoRequest, ServerInfo>(
|
|
264
|
+
linuxcncClient.getServerInfo.bind(linuxcncClient)
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
const serverInfo = await getServerInfo(GetServerInfoRequest.create());
|
|
268
|
+
|
|
269
|
+
expect(serverInfo.serverVersion).toBe('0.0.0-mock');
|
|
270
|
+
expect(serverInfo.linuxcncConnected).toBe(true);
|
|
271
|
+
expect(serverInfo.linuxcncVersion).toBe('2.9.0-mock');
|
|
272
|
+
expect(serverInfo.errorChannelMode).toBe('always');
|
|
273
|
+
expect(serverInfo.stopsNotTaken).toBe(0);
|
|
274
|
+
});
|
|
275
|
+
|
|
208
276
|
it('StreamStatus returns multiple updates', async () => {
|
|
209
277
|
const stream = linuxcncClient.streamStatus(
|
|
210
278
|
StreamStatusRequest.create({ intervalMs: 50 })
|
|
@@ -0,0 +1,183 @@
|
|
|
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
|
+
|
|
12
|
+
import { BinaryReader, BinaryWriter } from '@bufbuild/protobuf/wire';
|
|
13
|
+
import { describe, it, expect } from 'vitest';
|
|
14
|
+
import { HalSystemStatus, HalValue, ValueChange } from '../hal';
|
|
15
|
+
import { ErrorMessage, FileInfo, LinuxCNCStatus, ReadFileResponse } from '../linuxcnc';
|
|
16
|
+
|
|
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
|
+
|
|
22
|
+
function varintTag(fieldNumber: number): number {
|
|
23
|
+
return (fieldNumber << 3) | VARINT_WIRE_TYPE;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function encodeSigned(fieldNumber: number, decimalValue: string): Uint8Array {
|
|
27
|
+
return new BinaryWriter().uint32(varintTag(fieldNumber)).int64(decimalValue).finish();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function encodeUnsigned(fieldNumber: number, decimalValue: string): Uint8Array {
|
|
31
|
+
return new BinaryWriter().uint32(varintTag(fieldNumber)).uint64(decimalValue).finish();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function decodeS64(decimalValue: string): number | undefined {
|
|
35
|
+
return HalValue.decode(encodeSigned(HAL_VALUE_S64_FIELD, decimalValue)).s64Value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function decodeU64(decimalValue: string): number | undefined {
|
|
39
|
+
return HalValue.decode(encodeUnsigned(HAL_VALUE_U64_FIELD, decimalValue)).u64Value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('HAL 64-bit values', () => {
|
|
43
|
+
it('are exact up to Number.MAX_SAFE_INTEGER', () => {
|
|
44
|
+
expect(decodeS64('9007199254740991')).toBe(Number.MAX_SAFE_INTEGER);
|
|
45
|
+
expect(decodeS64('-9007199254740991')).toBe(Number.MIN_SAFE_INTEGER);
|
|
46
|
+
expect(decodeU64('9007199254740991')).toBe(Number.MAX_SAFE_INTEGER);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('just above 2^53 arrive as the nearest number, not divided by a million', () => {
|
|
50
|
+
// 2^53 + 1 has no exact number; the nearest one is 2^53.
|
|
51
|
+
expect(decodeS64('9007199254740993')).toBe(2 ** 53);
|
|
52
|
+
expect(decodeS64('-9007199254740993')).toBe(-(2 ** 53));
|
|
53
|
+
expect(decodeU64('9007199254740993')).toBe(2 ** 53);
|
|
54
|
+
// 2^53 + 2 is a number itself.
|
|
55
|
+
expect(decodeS64('9007199254740994')).toBe(9007199254740994);
|
|
56
|
+
expect(decodeU64('9007199254740994')).toBe(9007199254740994);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('well above 2^53 arrive unscaled', () => {
|
|
60
|
+
expect(decodeS64('1152921504606846976')).toBe(2 ** 60);
|
|
61
|
+
expect(decodeS64('-1152921504606846976')).toBe(-(2 ** 60));
|
|
62
|
+
expect(decodeU64('1152921504606846976')).toBe(2 ** 60);
|
|
63
|
+
expect(decodeU64('9223372036854775808')).toBe(2 ** 63);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('at the ends of the 64-bit range arrive as the nearest number', () => {
|
|
67
|
+
expect(decodeS64('-9223372036854775808')).toBe(-(2 ** 63));
|
|
68
|
+
expect(decodeS64('9223372036854775807')).toBe(2 ** 63);
|
|
69
|
+
expect(decodeU64('18446744073709551615')).toBe(2 ** 64);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('inside another message are decoded the same way', () => {
|
|
73
|
+
const change = ValueChange.decode(
|
|
74
|
+
new BinaryWriter()
|
|
75
|
+
.uint32((3 << 3) | 2)
|
|
76
|
+
.bytes(encodeSigned(HAL_VALUE_S64_FIELD, '-1152921504606846976'))
|
|
77
|
+
.uint32((4 << 3) | 2)
|
|
78
|
+
.bytes(encodeUnsigned(HAL_VALUE_U64_FIELD, '1152921504606846976'))
|
|
79
|
+
.finish()
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
expect(change.oldValue?.s64Value).toBe(-(2 ** 60));
|
|
83
|
+
expect(change.newValue?.u64Value).toBe(2 ** 60);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('are written to the wire unscaled', () => {
|
|
87
|
+
const signedReader = new BinaryReader(HalValue.encode({ s64Value: -(2 ** 60) }).finish());
|
|
88
|
+
expect(signedReader.uint32()).toBe(varintTag(HAL_VALUE_S64_FIELD));
|
|
89
|
+
expect(signedReader.int64().toString()).toBe('-1152921504606846976');
|
|
90
|
+
|
|
91
|
+
const unsignedReader = new BinaryReader(HalValue.encode({ u64Value: 2 ** 63 }).finish());
|
|
92
|
+
expect(unsignedReader.uint32()).toBe(varintTag(HAL_VALUE_U64_FIELD));
|
|
93
|
+
expect(unsignedReader.uint64().toString()).toBe('9223372036854775808');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('survive an encode and decode round trip', () => {
|
|
97
|
+
const largeValue = 2 ** 60;
|
|
98
|
+
expect(HalValue.decode(HalValue.encode({ s64Value: largeValue }).finish()).s64Value).toBe(
|
|
99
|
+
largeValue
|
|
100
|
+
);
|
|
101
|
+
expect(HalValue.decode(HalValue.encode({ u64Value: largeValue }).finish()).u64Value).toBe(
|
|
102
|
+
largeValue
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('pass through JSON unscaled', () => {
|
|
107
|
+
expect(HalValue.fromJSON({ s64Value: 2 ** 60 }).s64Value).toBe(2 ** 60);
|
|
108
|
+
expect(HalValue.toJSON({ u64Value: 2 ** 60 })).toEqual({ u64Value: 2 ** 60 });
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('other 64-bit fields that are not timestamps', () => {
|
|
113
|
+
it('ErrorMessage.sequence arrives unscaled', () => {
|
|
114
|
+
const message = ErrorMessage.decode(encodeSigned(4, '1152921504606846976'));
|
|
115
|
+
expect(message.sequence).toBe(2 ** 60);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('FileInfo.size_bytes arrives unscaled', () => {
|
|
119
|
+
const fileInfo = FileInfo.decode(encodeSigned(3, '9007199254740993'));
|
|
120
|
+
expect(fileInfo.sizeBytes).toBe(2 ** 53);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('ReadFileResponse.offset and total_size_bytes arrive unscaled', () => {
|
|
124
|
+
const response = ReadFileResponse.decode(
|
|
125
|
+
new BinaryWriter()
|
|
126
|
+
.uint32(varintTag(3))
|
|
127
|
+
.int64('1152921504606846976')
|
|
128
|
+
.uint32(varintTag(4))
|
|
129
|
+
.int64('2305843009213693952')
|
|
130
|
+
.finish()
|
|
131
|
+
);
|
|
132
|
+
expect(response.offset).toBe(2 ** 60);
|
|
133
|
+
expect(response.totalSizeBytes).toBe(2 ** 61);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('timestamps', () => {
|
|
138
|
+
// 2023-11-14T22:13:20.123456789Z in nanoseconds since the epoch.
|
|
139
|
+
const NANOSECOND_TIMESTAMP = '1700000000123456789';
|
|
140
|
+
const SAME_TIME_IN_MILLISECONDS = 1700000000123;
|
|
141
|
+
|
|
142
|
+
it('in nanoseconds arrive as milliseconds', () => {
|
|
143
|
+
expect(HalSystemStatus.decode(encodeSigned(1, NANOSECOND_TIMESTAMP)).timestamp).toBe(
|
|
144
|
+
SAME_TIME_IN_MILLISECONDS
|
|
145
|
+
);
|
|
146
|
+
expect(LinuxCNCStatus.decode(encodeSigned(1, NANOSECOND_TIMESTAMP)).timestamp).toBe(
|
|
147
|
+
SAME_TIME_IN_MILLISECONDS
|
|
148
|
+
);
|
|
149
|
+
expect(ErrorMessage.decode(encodeSigned(3, NANOSECOND_TIMESTAMP)).timestamp).toBe(
|
|
150
|
+
SAME_TIME_IN_MILLISECONDS
|
|
151
|
+
);
|
|
152
|
+
expect(ValueChange.decode(encodeSigned(1, NANOSECOND_TIMESTAMP)).timestamp).toBe(
|
|
153
|
+
SAME_TIME_IN_MILLISECONDS
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('make the date they stand for', () => {
|
|
158
|
+
const status = HalSystemStatus.decode(encodeSigned(1, NANOSECOND_TIMESTAMP));
|
|
159
|
+
expect(new Date(status.timestamp).toISOString()).toBe('2023-11-14T22:13:20.123Z');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('of files arrive as milliseconds too', () => {
|
|
163
|
+
expect(FileInfo.decode(encodeSigned(4, NANOSECOND_TIMESTAMP)).modifiedTimestamp).toBe(
|
|
164
|
+
SAME_TIME_IN_MILLISECONDS
|
|
165
|
+
);
|
|
166
|
+
expect(ReadFileResponse.decode(encodeSigned(6, NANOSECOND_TIMESTAMP)).modifiedTimestamp).toBe(
|
|
167
|
+
SAME_TIME_IN_MILLISECONDS
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('small enough to be an exact number arrive unchanged', () => {
|
|
172
|
+
expect(HalSystemStatus.decode(encodeSigned(1, '1700000000123')).timestamp).toBe(1700000000123);
|
|
173
|
+
expect(HalSystemStatus.decode(encodeSigned(1, '9007199254740991')).timestamp).toBe(
|
|
174
|
+
Number.MAX_SAFE_INTEGER
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('before the epoch are scaled toward zero', () => {
|
|
179
|
+
expect(HalSystemStatus.decode(encodeSigned(1, '-1700000000123456789')).timestamp).toBe(
|
|
180
|
+
-SAME_TIME_IN_MILLISECONDS
|
|
181
|
+
);
|
|
182
|
+
});
|
|
183
|
+
});
|
package/src/hal.ts
CHANGED
|
@@ -32,11 +32,11 @@ export enum HalType {
|
|
|
32
32
|
HAL_S32 = 3,
|
|
33
33
|
/** HAL_U32 - Unsigned 32-bit integer */
|
|
34
34
|
HAL_U32 = 4,
|
|
35
|
-
/** HAL_S64 - Signed
|
|
35
|
+
/** HAL_S64 - Signed integer; only reported for a value that does not fit 32 bits */
|
|
36
36
|
HAL_S64 = 5,
|
|
37
|
-
/** HAL_U64 - Unsigned
|
|
37
|
+
/** HAL_U64 - Unsigned integer; only reported for a value that does not fit 32 bits */
|
|
38
38
|
HAL_U64 = 6,
|
|
39
|
-
/** HAL_PORT - Port type (advanced) */
|
|
39
|
+
/** HAL_PORT - Port type (advanced); the server reports port pins with no value */
|
|
40
40
|
HAL_PORT = 7,
|
|
41
41
|
UNRECOGNIZED = -1,
|
|
42
42
|
}
|
|
@@ -264,12 +264,18 @@ export interface HalValue {
|
|
|
264
264
|
bitValue?: boolean | undefined;
|
|
265
265
|
floatValue?: number | undefined;
|
|
266
266
|
s32Value?: number | undefined;
|
|
267
|
-
u32Value?:
|
|
267
|
+
u32Value?:
|
|
268
|
+
| number
|
|
269
|
+
| undefined;
|
|
270
|
+
/**
|
|
271
|
+
* The two 64-bit values are numbers in the Node.js/TypeScript client:
|
|
272
|
+
* exact up to 2^53, the nearest number beyond that.
|
|
273
|
+
*/
|
|
268
274
|
s64Value?: number | undefined;
|
|
269
275
|
u64Value?:
|
|
270
276
|
| number
|
|
271
277
|
| undefined;
|
|
272
|
-
/** Port type (advanced) */
|
|
278
|
+
/** Port type (advanced); never set by the server */
|
|
273
279
|
portValue?: string | undefined;
|
|
274
280
|
}
|
|
275
281
|
|
|
@@ -289,9 +295,12 @@ export interface HalPinInfo {
|
|
|
289
295
|
value:
|
|
290
296
|
| HalValue
|
|
291
297
|
| undefined;
|
|
292
|
-
/**
|
|
298
|
+
/** Always empty: LinuxCNC's HAL Python module does not expose the connected signal */
|
|
293
299
|
signal: string;
|
|
294
|
-
/**
|
|
300
|
+
/**
|
|
301
|
+
* True if the pin's signal has a writer. In StreamStatus this is refreshed
|
|
302
|
+
* every 2 seconds, not with every update.
|
|
303
|
+
*/
|
|
295
304
|
hasWriter: boolean;
|
|
296
305
|
}
|
|
297
306
|
|
|
@@ -329,17 +338,22 @@ export interface HalParamInfo {
|
|
|
329
338
|
value: HalValue | undefined;
|
|
330
339
|
}
|
|
331
340
|
|
|
332
|
-
/**
|
|
341
|
+
/**
|
|
342
|
+
* Information about a HAL component. LinuxCNC's HAL Python module has no
|
|
343
|
+
* component list, so the server infers components from pin and parameter
|
|
344
|
+
* names (the part before the last dot). Only name, pins and params are filled
|
|
345
|
+
* in.
|
|
346
|
+
*/
|
|
333
347
|
export interface HalComponentInfo {
|
|
334
348
|
/** Component name */
|
|
335
349
|
name: string;
|
|
336
|
-
/** Component ID */
|
|
350
|
+
/** Component ID; always 0 */
|
|
337
351
|
id: number;
|
|
338
|
-
/**
|
|
352
|
+
/** Never set by the server */
|
|
339
353
|
ready: boolean;
|
|
340
|
-
/**
|
|
354
|
+
/** Never set by the server */
|
|
341
355
|
type: number;
|
|
342
|
-
/**
|
|
356
|
+
/** Never set by the server */
|
|
343
357
|
pid: number;
|
|
344
358
|
/** List of pin names */
|
|
345
359
|
pins: string[];
|
|
@@ -357,9 +371,9 @@ export interface HalSystemStatus {
|
|
|
357
371
|
signals: HalSignalInfo[];
|
|
358
372
|
/** All parameters */
|
|
359
373
|
params: HalParamInfo[];
|
|
360
|
-
/**
|
|
374
|
+
/** Components inferred from pin and parameter names */
|
|
361
375
|
components: HalComponentInfo[];
|
|
362
|
-
/**
|
|
376
|
+
/** RTAPI message level of the server process */
|
|
363
377
|
messageLevel: MessageLevel;
|
|
364
378
|
/** Running in simulation */
|
|
365
379
|
isSim: boolean;
|
|
@@ -367,7 +381,7 @@ export interface HalSystemStatus {
|
|
|
367
381
|
isRt: boolean;
|
|
368
382
|
/** Userspace HAL */
|
|
369
383
|
isUserspace: boolean;
|
|
370
|
-
/** Kernel version */
|
|
384
|
+
/** Kernel version as HAL reports it; "Not Available" on uspace builds */
|
|
371
385
|
kernelVersion: string;
|
|
372
386
|
}
|
|
373
387
|
|
|
@@ -564,7 +578,13 @@ export interface HalCommand {
|
|
|
564
578
|
disconnect?:
|
|
565
579
|
| DisconnectCommand
|
|
566
580
|
| undefined;
|
|
567
|
-
/**
|
|
581
|
+
/**
|
|
582
|
+
* Query commands. SendCommand answers only component_exists,
|
|
583
|
+
* component_ready and pin_has_writer. It refuses get_value and the
|
|
584
|
+
* query_* commands (its response cannot carry a result) and names the RPC
|
|
585
|
+
* to call instead: GetValue, QueryPins, QuerySignals, QueryParams or
|
|
586
|
+
* QueryComponents.
|
|
587
|
+
*/
|
|
568
588
|
getValue?: GetValueCommand | undefined;
|
|
569
589
|
queryPins?: QueryPinsCommand | undefined;
|
|
570
590
|
querySignals?: QuerySignalsCommand | undefined;
|
|
@@ -642,9 +662,12 @@ export interface QueryComponentsResponse {
|
|
|
642
662
|
|
|
643
663
|
/** Subscribe to value changes */
|
|
644
664
|
export interface WatchRequest {
|
|
645
|
-
/** Pin/signal/param names to watch */
|
|
665
|
+
/** Pin/signal/param names to watch; duplicates are ignored, at most 1000 names */
|
|
646
666
|
names: string[];
|
|
647
|
-
/**
|
|
667
|
+
/**
|
|
668
|
+
* Minimum update interval in milliseconds (default: 100). Values above
|
|
669
|
+
* 60000 are treated as 60000.
|
|
670
|
+
*/
|
|
648
671
|
intervalMs: number;
|
|
649
672
|
}
|
|
650
673
|
|
|
@@ -673,9 +696,12 @@ export interface GetSystemStatusRequest {
|
|
|
673
696
|
}
|
|
674
697
|
|
|
675
698
|
export interface HalStreamStatusRequest {
|
|
676
|
-
/**
|
|
699
|
+
/**
|
|
700
|
+
* Update interval in milliseconds (default: 100). Values above 60000 are
|
|
701
|
+
* treated as 60000.
|
|
702
|
+
*/
|
|
677
703
|
intervalMs: number;
|
|
678
|
-
/**
|
|
704
|
+
/** Currently ignored by the server: every component is included */
|
|
679
705
|
filter: string[];
|
|
680
706
|
}
|
|
681
707
|
|
|
@@ -1528,7 +1554,7 @@ export const HalSystemStatus: MessageFns<HalSystemStatus> = {
|
|
|
1528
1554
|
break;
|
|
1529
1555
|
}
|
|
1530
1556
|
|
|
1531
|
-
message.timestamp =
|
|
1557
|
+
message.timestamp = timestampToNumber(reader.int64());
|
|
1532
1558
|
continue;
|
|
1533
1559
|
}
|
|
1534
1560
|
case 2: {
|
|
@@ -3329,7 +3355,7 @@ export const HalCommand: MessageFns<HalCommand> = {
|
|
|
3329
3355
|
break;
|
|
3330
3356
|
}
|
|
3331
3357
|
|
|
3332
|
-
message.timestamp =
|
|
3358
|
+
message.timestamp = timestampToNumber(reader.int64());
|
|
3333
3359
|
continue;
|
|
3334
3360
|
}
|
|
3335
3361
|
case 2: {
|
|
@@ -4587,7 +4613,7 @@ export const ValueChange: MessageFns<ValueChange> = {
|
|
|
4587
4613
|
break;
|
|
4588
4614
|
}
|
|
4589
4615
|
|
|
4590
|
-
message.timestamp =
|
|
4616
|
+
message.timestamp = timestampToNumber(reader.int64());
|
|
4591
4617
|
continue;
|
|
4592
4618
|
}
|
|
4593
4619
|
case 2: {
|
|
@@ -4693,7 +4719,7 @@ export const ValueChangeBatch: MessageFns<ValueChangeBatch> = {
|
|
|
4693
4719
|
break;
|
|
4694
4720
|
}
|
|
4695
4721
|
|
|
4696
|
-
message.timestamp =
|
|
4722
|
+
message.timestamp = timestampToNumber(reader.int64());
|
|
4697
4723
|
continue;
|
|
4698
4724
|
}
|
|
4699
4725
|
case 2: {
|
|
@@ -5128,7 +5154,21 @@ type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
|
5128
5154
|
type Exact<P, I extends P> = P extends Builtin ? P
|
|
5129
5155
|
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
|
|
5130
5156
|
|
|
5157
|
+
/**
|
|
5158
|
+
* A 64-bit integer that is a value, not a timestamp. Beyond 2^53 the result
|
|
5159
|
+
* is the nearest number, so the low digits are lost; it is never scaled.
|
|
5160
|
+
* (Patched in by scripts/generate-protos.sh.)
|
|
5161
|
+
*/
|
|
5131
5162
|
function longToNumber(int64: { toString(): string }): number {
|
|
5163
|
+
return globalThis.Number(int64.toString());
|
|
5164
|
+
}
|
|
5165
|
+
|
|
5166
|
+
/**
|
|
5167
|
+
* A timestamp. The server sends nanoseconds, which do not fit a number, so a
|
|
5168
|
+
* value beyond the safe integer range is scaled to milliseconds.
|
|
5169
|
+
* (Patched in by scripts/generate-protos.sh.)
|
|
5170
|
+
*/
|
|
5171
|
+
function timestampToNumber(int64: { toString(): string }): number {
|
|
5132
5172
|
const num = globalThis.Number(int64.toString());
|
|
5133
5173
|
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
|
|
5134
5174
|
return Math.floor(num / 1e6);
|