hoot-parser 0.0.0-stage → 0.0.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.
- package/LICENSE +21 -0
- package/README.md +34 -2
- package/dist/index.d.mts +26 -0
- package/dist/index.mjs +669 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +57 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jonah Snider
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# hoot-parser
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Read CTRE HOOT logs in JavaScript or TypeScript. The ESM package runs in browsers and Node.js without Owlet, native binaries, or a server.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Pass a `Uint8Array` or an `ArrayBuffer` to `parseHoot`. For a browser `File`, use `await file.arrayBuffer()`.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { parseHoot } from 'hoot-parser';
|
|
11
|
+
|
|
12
|
+
function readFile(bytes: ArrayBuffer) {
|
|
13
|
+
const records = parseHoot(bytes);
|
|
14
|
+
for (const record of records) {
|
|
15
|
+
if (record.kind === 'sample') {
|
|
16
|
+
console.log(record.timestamp, record.name, record.payload, record.unit);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return bytes.byteLength - records.bytesRead;
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The generator yields records in file order, not necessarily in timestamp order. Timestamps are in microseconds. Custom signal names are kept as recorded, and struct schema records contain parsed fields. If a file ends mid-record, the generator yields the complete records and leaves `bytesRead` at the end of the last complete record.
|
|
24
|
+
|
|
25
|
+
The parser supports C19 and C21 logs, including custom signals and selected TalonFX, CANcoder, and Pigeon2 telemetry. It skips signals whose layout it doesn't recognize. Custom `int64` values are returned as JavaScript numbers and may lose precision above `Number.MAX_SAFE_INTEGER`.
|
|
26
|
+
|
|
27
|
+
See the [API report](etc/hoot-parser.api.md) for the exported types.
|
|
28
|
+
|
|
29
|
+
## Benchmarks
|
|
30
|
+
|
|
31
|
+
Run `pnpm bench` to time reading C19, C21, and struct logs, either discarding each record or collecting the entire log. Struct benchmarks also run with dynamic code generation blocked, as it is under a strict browser Content Security Policy. The same suite runs in CodSpeed on pull requests and pushes to `main`.
|
|
32
|
+
|
|
33
|
+
Use `pnpm bench --reporter=verbose -t hoot-benchmark` to print timing details for just the larger fixture.
|
|
34
|
+
|
|
35
|
+
`pnpm test` also checks the V8 heap cost per retained record in a fresh Node process. The larger benchmark fixture contains 28,672 samples generated by [the Phoenix simulator fixture generator](tests/fixtures/GenerateBenchmark.java), not a team robot log.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StructDeclaration, StructPayload } from "wpilib-struct";
|
|
2
|
+
type HootValue = number | boolean | string | number[] | boolean[] | string[] | StructPayload | StructPayload[];
|
|
3
|
+
/** A decoded signal sample or struct schema, in file order. */
|
|
4
|
+
type HootRecord = {
|
|
5
|
+
kind: 'schema';
|
|
6
|
+
name: string;
|
|
7
|
+
fields: StructDeclaration[];
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'sample';
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
unit: string | undefined;
|
|
13
|
+
/** Time in microseconds. */
|
|
14
|
+
timestamp: number;
|
|
15
|
+
payload: HootValue;
|
|
16
|
+
};
|
|
17
|
+
type HootGenerator = Generator<HootRecord, void, unknown> & {
|
|
18
|
+
/**
|
|
19
|
+
* Byte offset after the last complete record or end marker, rounded up.
|
|
20
|
+
* This is zero until parsing starts and excludes any incomplete tail.
|
|
21
|
+
*/
|
|
22
|
+
readonly bytesRead: number;
|
|
23
|
+
};
|
|
24
|
+
/** Decode supported signals and struct schemas from an in-memory C19 or C21 HOOT file. */
|
|
25
|
+
export declare function parseHoot(input: Uint8Array | ArrayBuffer): HootGenerator;
|
|
26
|
+
export type { HootGenerator, HootRecord, HootValue };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
import { StructRegistry, parseStructSpecification } from "wpilib-struct";
|
|
2
|
+
// src/hoot-can.ts
|
|
3
|
+
const motorVoltage = [
|
|
4
|
+
"MotorVoltage",
|
|
5
|
+
"V",
|
|
6
|
+
2,
|
|
7
|
+
13,
|
|
8
|
+
.01
|
|
9
|
+
];
|
|
10
|
+
const currents = [
|
|
11
|
+
[
|
|
12
|
+
"StatorCurrent",
|
|
13
|
+
"A",
|
|
14
|
+
0,
|
|
15
|
+
15,
|
|
16
|
+
.02
|
|
17
|
+
],
|
|
18
|
+
[
|
|
19
|
+
"SupplyCurrent",
|
|
20
|
+
"A",
|
|
21
|
+
15,
|
|
22
|
+
15,
|
|
23
|
+
.02
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
"SupplyVoltage",
|
|
27
|
+
"V",
|
|
28
|
+
30,
|
|
29
|
+
10,
|
|
30
|
+
.025,
|
|
31
|
+
4
|
|
32
|
+
]
|
|
33
|
+
];
|
|
34
|
+
const motion = [[
|
|
35
|
+
"Velocity",
|
|
36
|
+
"rot/s",
|
|
37
|
+
2,
|
|
38
|
+
19,
|
|
39
|
+
1 / 512
|
|
40
|
+
], [
|
|
41
|
+
"Position",
|
|
42
|
+
"rotations",
|
|
43
|
+
21,
|
|
44
|
+
27,
|
|
45
|
+
1 / 4096
|
|
46
|
+
]];
|
|
47
|
+
function atOffset(fields, offset) {
|
|
48
|
+
return fields.map(([name, unit, bit, width, scale, unsignedOffset]) => [
|
|
49
|
+
name,
|
|
50
|
+
unit,
|
|
51
|
+
bit + offset,
|
|
52
|
+
width,
|
|
53
|
+
scale,
|
|
54
|
+
unsignedOffset
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
/** Verified layouts of public device signals. Masking the frame ID leaves out the logger flags and CAN device number. */
|
|
58
|
+
const hootCanFrames = /* @__PURE__ */ new Map([
|
|
59
|
+
[33827904, {
|
|
60
|
+
device: "TalonFX",
|
|
61
|
+
length: 8,
|
|
62
|
+
fields: [motorVoltage]
|
|
63
|
+
}],
|
|
64
|
+
[33828160, {
|
|
65
|
+
device: "TalonFX",
|
|
66
|
+
length: 8,
|
|
67
|
+
fields: currents
|
|
68
|
+
}],
|
|
69
|
+
[33828288, {
|
|
70
|
+
device: "TalonFX",
|
|
71
|
+
length: 8,
|
|
72
|
+
fields: motion
|
|
73
|
+
}],
|
|
74
|
+
[33827648, {
|
|
75
|
+
device: "TalonFX",
|
|
76
|
+
length: 64,
|
|
77
|
+
fields: [
|
|
78
|
+
motorVoltage,
|
|
79
|
+
...atOffset(currents, 64),
|
|
80
|
+
...atOffset(motion, 192)
|
|
81
|
+
]
|
|
82
|
+
}],
|
|
83
|
+
[84159424, {
|
|
84
|
+
device: "CANcoder",
|
|
85
|
+
length: 32,
|
|
86
|
+
fields: [
|
|
87
|
+
[
|
|
88
|
+
"Velocity",
|
|
89
|
+
"rot/s",
|
|
90
|
+
0,
|
|
91
|
+
19,
|
|
92
|
+
1 / 512
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
"Position",
|
|
96
|
+
"rotations",
|
|
97
|
+
19,
|
|
98
|
+
27,
|
|
99
|
+
1 / 4096
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
"SupplyVoltage",
|
|
103
|
+
"V",
|
|
104
|
+
128,
|
|
105
|
+
8,
|
|
106
|
+
.05,
|
|
107
|
+
4
|
|
108
|
+
]
|
|
109
|
+
]
|
|
110
|
+
}],
|
|
111
|
+
[352594944, {
|
|
112
|
+
device: "Pigeon2",
|
|
113
|
+
length: 64,
|
|
114
|
+
fields: [
|
|
115
|
+
[
|
|
116
|
+
"Yaw",
|
|
117
|
+
"deg",
|
|
118
|
+
0,
|
|
119
|
+
28,
|
|
120
|
+
360 / 131072
|
|
121
|
+
],
|
|
122
|
+
[
|
|
123
|
+
"AngularVelocityZWorld",
|
|
124
|
+
"deg/s",
|
|
125
|
+
360,
|
|
126
|
+
20,
|
|
127
|
+
1 / 256
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
"SupplyVoltage",
|
|
131
|
+
"V",
|
|
132
|
+
448,
|
|
133
|
+
12,
|
|
134
|
+
1 / 2048,
|
|
135
|
+
12
|
|
136
|
+
]
|
|
137
|
+
]
|
|
138
|
+
}]
|
|
139
|
+
]);
|
|
140
|
+
function readHootCanField(payload, [, , bit, width, scale, unsignedOffset]) {
|
|
141
|
+
const start = bit >> 3;
|
|
142
|
+
const end = bit + width - 1 >> 3;
|
|
143
|
+
let word = 0;
|
|
144
|
+
for (let i = end; i >= start; i--) word = word * 256 + payload[i];
|
|
145
|
+
const raw = Math.floor(word / (1 << (bit & 7))) & (1 << width) - 1;
|
|
146
|
+
if (unsignedOffset !== void 0) return raw * scale + unsignedOffset;
|
|
147
|
+
const sign = 1 << width - 1;
|
|
148
|
+
return ((raw ^ sign) - sign) * scale;
|
|
149
|
+
}
|
|
150
|
+
// src/hoot-compression.ts
|
|
151
|
+
const codes = [
|
|
152
|
+
3,
|
|
153
|
+
86,
|
|
154
|
+
349,
|
|
155
|
+
711,
|
|
156
|
+
47,
|
|
157
|
+
626,
|
|
158
|
+
586,
|
|
159
|
+
547,
|
|
160
|
+
701,
|
|
161
|
+
1419,
|
|
162
|
+
1405,
|
|
163
|
+
1354,
|
|
164
|
+
1489,
|
|
165
|
+
1327,
|
|
166
|
+
1307,
|
|
167
|
+
1322,
|
|
168
|
+
548,
|
|
169
|
+
1259,
|
|
170
|
+
1356,
|
|
171
|
+
176,
|
|
172
|
+
187,
|
|
173
|
+
1341,
|
|
174
|
+
1246,
|
|
175
|
+
1244,
|
|
176
|
+
1495,
|
|
177
|
+
1241,
|
|
178
|
+
1240,
|
|
179
|
+
1231,
|
|
180
|
+
1334,
|
|
181
|
+
1227,
|
|
182
|
+
1226,
|
|
183
|
+
1229,
|
|
184
|
+
658,
|
|
185
|
+
1228,
|
|
186
|
+
1180,
|
|
187
|
+
1181,
|
|
188
|
+
1320,
|
|
189
|
+
1178,
|
|
190
|
+
1183,
|
|
191
|
+
1488,
|
|
192
|
+
1418,
|
|
193
|
+
1174,
|
|
194
|
+
1168,
|
|
195
|
+
1167,
|
|
196
|
+
1306,
|
|
197
|
+
1162,
|
|
198
|
+
1151,
|
|
199
|
+
1158,
|
|
200
|
+
1350,
|
|
201
|
+
1143,
|
|
202
|
+
1132,
|
|
203
|
+
1138,
|
|
204
|
+
1284,
|
|
205
|
+
1139,
|
|
206
|
+
1136,
|
|
207
|
+
1127,
|
|
208
|
+
1392,
|
|
209
|
+
1117,
|
|
210
|
+
1131,
|
|
211
|
+
1120,
|
|
212
|
+
1277,
|
|
213
|
+
1108,
|
|
214
|
+
1109,
|
|
215
|
+
1166,
|
|
216
|
+
334,
|
|
217
|
+
1177,
|
|
218
|
+
92,
|
|
219
|
+
1150,
|
|
220
|
+
1289,
|
|
221
|
+
1145,
|
|
222
|
+
1155,
|
|
223
|
+
89,
|
|
224
|
+
1340,
|
|
225
|
+
1154,
|
|
226
|
+
1147,
|
|
227
|
+
1144,
|
|
228
|
+
1281,
|
|
229
|
+
1148,
|
|
230
|
+
1161,
|
|
231
|
+
1135,
|
|
232
|
+
1335,
|
|
233
|
+
1141,
|
|
234
|
+
1140,
|
|
235
|
+
1142,
|
|
236
|
+
1301,
|
|
237
|
+
1130,
|
|
238
|
+
1125,
|
|
239
|
+
1122,
|
|
240
|
+
1332,
|
|
241
|
+
1124,
|
|
242
|
+
1123,
|
|
243
|
+
1121,
|
|
244
|
+
1280,
|
|
245
|
+
1116,
|
|
246
|
+
1111,
|
|
247
|
+
1157,
|
|
248
|
+
628,
|
|
249
|
+
1100,
|
|
250
|
+
45,
|
|
251
|
+
1355,
|
|
252
|
+
1268,
|
|
253
|
+
1060,
|
|
254
|
+
1062,
|
|
255
|
+
1074,
|
|
256
|
+
1313,
|
|
257
|
+
1058,
|
|
258
|
+
1065,
|
|
259
|
+
1351,
|
|
260
|
+
1269,
|
|
261
|
+
1071,
|
|
262
|
+
1076,
|
|
263
|
+
1057,
|
|
264
|
+
1314,
|
|
265
|
+
1146,
|
|
266
|
+
1037,
|
|
267
|
+
1068,
|
|
268
|
+
1275,
|
|
269
|
+
1077,
|
|
270
|
+
1069,
|
|
271
|
+
1056,
|
|
272
|
+
1319,
|
|
273
|
+
2073,
|
|
274
|
+
1038,
|
|
275
|
+
1061,
|
|
276
|
+
1288,
|
|
277
|
+
1059,
|
|
278
|
+
1066,
|
|
279
|
+
1357,
|
|
280
|
+
128,
|
|
281
|
+
662,
|
|
282
|
+
654,
|
|
283
|
+
651,
|
|
284
|
+
674,
|
|
285
|
+
648,
|
|
286
|
+
647,
|
|
287
|
+
649,
|
|
288
|
+
697,
|
|
289
|
+
646,
|
|
290
|
+
643,
|
|
291
|
+
645,
|
|
292
|
+
672,
|
|
293
|
+
641,
|
|
294
|
+
639,
|
|
295
|
+
655,
|
|
296
|
+
1318,
|
|
297
|
+
1081,
|
|
298
|
+
1070,
|
|
299
|
+
1064,
|
|
300
|
+
1270,
|
|
301
|
+
1039,
|
|
302
|
+
1073,
|
|
303
|
+
1067,
|
|
304
|
+
1315,
|
|
305
|
+
1063,
|
|
306
|
+
1075,
|
|
307
|
+
1072,
|
|
308
|
+
1272,
|
|
309
|
+
1078,
|
|
310
|
+
1079,
|
|
311
|
+
1133,
|
|
312
|
+
559,
|
|
313
|
+
1110,
|
|
314
|
+
1080,
|
|
315
|
+
1082,
|
|
316
|
+
1273,
|
|
317
|
+
1087,
|
|
318
|
+
1084,
|
|
319
|
+
1083,
|
|
320
|
+
1326,
|
|
321
|
+
1086,
|
|
322
|
+
1102,
|
|
323
|
+
1085,
|
|
324
|
+
1271,
|
|
325
|
+
1092,
|
|
326
|
+
1088,
|
|
327
|
+
1104,
|
|
328
|
+
1321,
|
|
329
|
+
1098,
|
|
330
|
+
1093,
|
|
331
|
+
1089,
|
|
332
|
+
1274,
|
|
333
|
+
1091,
|
|
334
|
+
1090,
|
|
335
|
+
1099,
|
|
336
|
+
1333,
|
|
337
|
+
1101,
|
|
338
|
+
1103,
|
|
339
|
+
1107,
|
|
340
|
+
1276,
|
|
341
|
+
1105,
|
|
342
|
+
1106,
|
|
343
|
+
1175,
|
|
344
|
+
332,
|
|
345
|
+
152,
|
|
346
|
+
131,
|
|
347
|
+
148,
|
|
348
|
+
154,
|
|
349
|
+
149,
|
|
350
|
+
150,
|
|
351
|
+
1134,
|
|
352
|
+
1393,
|
|
353
|
+
1128,
|
|
354
|
+
1126,
|
|
355
|
+
1129,
|
|
356
|
+
1285,
|
|
357
|
+
151,
|
|
358
|
+
1137,
|
|
359
|
+
1149,
|
|
360
|
+
1347,
|
|
361
|
+
1152,
|
|
362
|
+
1153,
|
|
363
|
+
1156,
|
|
364
|
+
1300,
|
|
365
|
+
1159,
|
|
366
|
+
1160,
|
|
367
|
+
1163,
|
|
368
|
+
1404,
|
|
369
|
+
1165,
|
|
370
|
+
1164,
|
|
371
|
+
1169,
|
|
372
|
+
1312,
|
|
373
|
+
1170,
|
|
374
|
+
1171,
|
|
375
|
+
1247,
|
|
376
|
+
652,
|
|
377
|
+
1255,
|
|
378
|
+
1176,
|
|
379
|
+
1179,
|
|
380
|
+
1323,
|
|
381
|
+
1182,
|
|
382
|
+
1224,
|
|
383
|
+
1225,
|
|
384
|
+
1494,
|
|
385
|
+
1230,
|
|
386
|
+
1242,
|
|
387
|
+
1243,
|
|
388
|
+
1346,
|
|
389
|
+
1245,
|
|
390
|
+
1254,
|
|
391
|
+
1258,
|
|
392
|
+
746,
|
|
393
|
+
679,
|
|
394
|
+
671,
|
|
395
|
+
676,
|
|
396
|
+
710,
|
|
397
|
+
700,
|
|
398
|
+
703,
|
|
399
|
+
708,
|
|
400
|
+
312,
|
|
401
|
+
745,
|
|
402
|
+
258,
|
|
403
|
+
278,
|
|
404
|
+
315,
|
|
405
|
+
316,
|
|
406
|
+
130,
|
|
407
|
+
85,
|
|
408
|
+
2072
|
|
409
|
+
];
|
|
410
|
+
const prefixes = /* @__PURE__ */ new Uint16Array(2048);
|
|
411
|
+
for (const [symbol, code] of codes.entries()) {
|
|
412
|
+
let prefix = 0;
|
|
413
|
+
let length = 0;
|
|
414
|
+
for (let bits = code; bits > 1; bits >>= 1) {
|
|
415
|
+
prefix = prefix << 1 | bits & 1;
|
|
416
|
+
length++;
|
|
417
|
+
}
|
|
418
|
+
for (let i = prefix; i < prefixes.length; i += 1 << length) prefixes[i] = length << 9 | symbol;
|
|
419
|
+
}
|
|
420
|
+
/** Reads one Huffman symbol at a time without inflating the whole file into memory */
|
|
421
|
+
var HootBitReader = class {
|
|
422
|
+
bytes;
|
|
423
|
+
bitOffset;
|
|
424
|
+
constructor(bytes, offset) {
|
|
425
|
+
this.bytes = bytes;
|
|
426
|
+
this.bitOffset = offset * 8;
|
|
427
|
+
}
|
|
428
|
+
get remainingBits() {
|
|
429
|
+
return this.bytes.length * 8 - this.bitOffset;
|
|
430
|
+
}
|
|
431
|
+
/** Read a byte, the end-of-stream symbol, or -1 for truncated input */
|
|
432
|
+
read() {
|
|
433
|
+
const i = Math.floor(this.bitOffset / 8);
|
|
434
|
+
const shift = this.bitOffset & 7;
|
|
435
|
+
const bits = (this.bytes[i] | this.bytes[i + 1] << 8 | this.bytes[i + 2] << 16) >>> shift;
|
|
436
|
+
const match = prefixes[bits & prefixes.length - 1];
|
|
437
|
+
const length = match >> 9;
|
|
438
|
+
if (length > this.remainingBits) return -1;
|
|
439
|
+
this.bitOffset += length;
|
|
440
|
+
return match & 511;
|
|
441
|
+
}
|
|
442
|
+
readInto(target, offset, length) {
|
|
443
|
+
for (let i = offset; i < length; i++) {
|
|
444
|
+
const byte = this.read();
|
|
445
|
+
if (byte < 0 || byte === 256) return false;
|
|
446
|
+
target[i] = byte;
|
|
447
|
+
}
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
// src/parse-hoot.ts
|
|
452
|
+
const headerSize = 80;
|
|
453
|
+
const canLengths = [
|
|
454
|
+
0,
|
|
455
|
+
1,
|
|
456
|
+
2,
|
|
457
|
+
3,
|
|
458
|
+
4,
|
|
459
|
+
5,
|
|
460
|
+
6,
|
|
461
|
+
7,
|
|
462
|
+
8,
|
|
463
|
+
12,
|
|
464
|
+
16,
|
|
465
|
+
20,
|
|
466
|
+
24,
|
|
467
|
+
32,
|
|
468
|
+
48,
|
|
469
|
+
64
|
|
470
|
+
];
|
|
471
|
+
const text = new TextDecoder();
|
|
472
|
+
const valueTypes = [
|
|
473
|
+
"",
|
|
474
|
+
"boolean",
|
|
475
|
+
"int64",
|
|
476
|
+
"float",
|
|
477
|
+
"double",
|
|
478
|
+
"string",
|
|
479
|
+
"boolean[]",
|
|
480
|
+
"int64[]",
|
|
481
|
+
"float[]",
|
|
482
|
+
"double[]",
|
|
483
|
+
"string[]"
|
|
484
|
+
];
|
|
485
|
+
const valueRecord = 224;
|
|
486
|
+
const nameRecord = 225;
|
|
487
|
+
const unitRecord = 226;
|
|
488
|
+
const schemaRecord = 227;
|
|
489
|
+
const schemaType = 11;
|
|
490
|
+
const structType = 12;
|
|
491
|
+
const networkType = 13;
|
|
492
|
+
/** Decode supported signals and struct schemas from an in-memory C19 or C21 HOOT file. */
|
|
493
|
+
function parseHoot(input) {
|
|
494
|
+
const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
495
|
+
const progress = { bytesRead: 0 };
|
|
496
|
+
return Object.defineProperty(decode(bytes, progress), "bytesRead", { get: () => progress.bytesRead });
|
|
497
|
+
}
|
|
498
|
+
function decodeValue(type, payload) {
|
|
499
|
+
const { length } = payload;
|
|
500
|
+
if (type === 5) return text.decode(payload);
|
|
501
|
+
if (type === 1) return length === 1 ? payload[0] !== 0 : void 0;
|
|
502
|
+
if (type === 6) return Array.from(payload, (byte) => byte !== 0);
|
|
503
|
+
const view = new DataView(payload.buffer, payload.byteOffset, length);
|
|
504
|
+
if (type === 10) {
|
|
505
|
+
const values = [];
|
|
506
|
+
for (let i = 0; i < length;) {
|
|
507
|
+
if (length - i < 4) return;
|
|
508
|
+
const size = view.getUint32(i, true);
|
|
509
|
+
i += 4;
|
|
510
|
+
if (size > length - i) return;
|
|
511
|
+
values.push(text.decode(payload.subarray(i, i + size)));
|
|
512
|
+
i += size;
|
|
513
|
+
}
|
|
514
|
+
return values;
|
|
515
|
+
}
|
|
516
|
+
const scalar = type < 6 ? type : type - 5;
|
|
517
|
+
const width = scalar === 3 ? 4 : 8;
|
|
518
|
+
if (length % width !== 0 || type < 6 && length !== width) return;
|
|
519
|
+
const read = (i) => {
|
|
520
|
+
switch (scalar) {
|
|
521
|
+
case 2: return Number(view.getBigInt64(i, true));
|
|
522
|
+
case 3: return view.getFloat32(i, true);
|
|
523
|
+
default: return view.getFloat64(i, true);
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
return type < 6 ? read(0) : Array.from({ length: length / width }, (_, i) => read(i * width));
|
|
527
|
+
}
|
|
528
|
+
function* decode(bytes, progress) {
|
|
529
|
+
if (bytes.length <= headerSize) throw new Error("The HOOT header or data is missing.");
|
|
530
|
+
const version = bytes[70];
|
|
531
|
+
const layout = bytes[71];
|
|
532
|
+
if (!(version === 19 && layout === 1 || version === 21 && layout === 2)) throw new Error("Only HOOT versions C19 and C21 are supported.");
|
|
533
|
+
const reader = new HootBitReader(bytes, headerSize);
|
|
534
|
+
const header = new Uint8Array(layout === 2 ? 11 : 10);
|
|
535
|
+
const view = new DataView(header.buffer);
|
|
536
|
+
const extendedLength = /* @__PURE__ */ new Uint8Array(4);
|
|
537
|
+
const lengthView = new DataView(extendedLength.buffer);
|
|
538
|
+
const previous = /* @__PURE__ */ new Map();
|
|
539
|
+
const custom = /* @__PURE__ */ new Map();
|
|
540
|
+
const networks = /* @__PURE__ */ new Map();
|
|
541
|
+
const structs = new StructRegistry();
|
|
542
|
+
progress.bytesRead = headerSize;
|
|
543
|
+
for (;;) {
|
|
544
|
+
const first = reader.read();
|
|
545
|
+
if (first === 256) {
|
|
546
|
+
progress.bytesRead = Math.ceil(reader.bitOffset / 8);
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
if (first < 0 || !reader.readInto(header, 1, header.length)) break;
|
|
550
|
+
header[0] = first;
|
|
551
|
+
const id = view.getUint32(0, true);
|
|
552
|
+
const flags = view.getUint16(8, true);
|
|
553
|
+
const network = header[10] ?? 0;
|
|
554
|
+
const kind = id >>> 24;
|
|
555
|
+
const type = id >>> 18 & 63;
|
|
556
|
+
const signalId = id & 4095;
|
|
557
|
+
const signalKey = type << 12 | signalId;
|
|
558
|
+
let length = canLengths[flags >>> 12];
|
|
559
|
+
let exactLength = id >>> 12 & 63;
|
|
560
|
+
if (exactLength === 0 && length === 64) exactLength = 64;
|
|
561
|
+
if (kind >= valueRecord && kind <= unitRecord && (flags & 2048) !== 0) {
|
|
562
|
+
if (!reader.readInto(extendedLength, 0, 4)) break;
|
|
563
|
+
length = lengthView.getUint32(0, true);
|
|
564
|
+
exactLength = length;
|
|
565
|
+
}
|
|
566
|
+
if (length > reader.remainingBits) break;
|
|
567
|
+
const frame = hootCanFrames.get(id & 536870848);
|
|
568
|
+
const knownCan = kind < valueRecord && frame?.length === length;
|
|
569
|
+
const knownCustom = kind >= valueRecord && kind <= schemaRecord && type > 0 && type <= networkType && exactLength <= length;
|
|
570
|
+
let payload;
|
|
571
|
+
if (knownCan || knownCustom) {
|
|
572
|
+
const old = previous.get(id);
|
|
573
|
+
payload = old?.length === length ? old : new Uint8Array(length);
|
|
574
|
+
if (payload !== old) {
|
|
575
|
+
if (old) payload.set(old.subarray(0, length));
|
|
576
|
+
previous.set(id, payload);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
let complete = true;
|
|
580
|
+
for (let i = 0; i < length; i++) {
|
|
581
|
+
const byte = reader.read();
|
|
582
|
+
if (byte < 0 || byte === 256) {
|
|
583
|
+
complete = false;
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
if (payload) payload[i] = payload[i] + byte;
|
|
587
|
+
}
|
|
588
|
+
if (!complete) break;
|
|
589
|
+
progress.bytesRead = Math.ceil(reader.bitOffset / 8);
|
|
590
|
+
if (!payload) continue;
|
|
591
|
+
const timestamp = view.getUint32(4, true) + (flags & 2047) * 2 ** 32 + 1;
|
|
592
|
+
if (knownCan) {
|
|
593
|
+
const path = `/Phoenix6/${layout === 2 ? `${networks.get(network) ?? `CAN-${network}`}/` : ""}${frame.device}-${id & 63}`;
|
|
594
|
+
for (const field of frame.fields) yield {
|
|
595
|
+
kind: "sample",
|
|
596
|
+
name: `${path}/${field[0]}`,
|
|
597
|
+
type: "double",
|
|
598
|
+
unit: field[1],
|
|
599
|
+
timestamp,
|
|
600
|
+
payload: readHootCanField(payload, field)
|
|
601
|
+
};
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
const value = payload.subarray(0, exactLength);
|
|
605
|
+
if (type === networkType) {
|
|
606
|
+
if (kind === nameRecord) networks.set(signalId, text.decode(value));
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
let signal = custom.get(signalKey);
|
|
610
|
+
if (!signal) {
|
|
611
|
+
signal = {};
|
|
612
|
+
custom.set(signalKey, signal);
|
|
613
|
+
}
|
|
614
|
+
switch (kind) {
|
|
615
|
+
case nameRecord:
|
|
616
|
+
signal.name = text.decode(value);
|
|
617
|
+
continue;
|
|
618
|
+
case unitRecord:
|
|
619
|
+
signal.unit = text.decode(value);
|
|
620
|
+
continue;
|
|
621
|
+
case schemaRecord:
|
|
622
|
+
if (value.length === 2) signal.schema = value[0] | value[1] << 8;
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
if (signal.name === void 0 || signal.name === "") continue;
|
|
626
|
+
if (type === schemaType && signal.schema === 1 && value.length > 0) {
|
|
627
|
+
const schema = text.decode(value);
|
|
628
|
+
try {
|
|
629
|
+
structs.register(signal.name, schema);
|
|
630
|
+
yield {
|
|
631
|
+
kind: "schema",
|
|
632
|
+
name: signal.name,
|
|
633
|
+
fields: parseStructSpecification(schema)
|
|
634
|
+
};
|
|
635
|
+
} catch {}
|
|
636
|
+
continue;
|
|
637
|
+
}
|
|
638
|
+
const { name, unit } = signal;
|
|
639
|
+
const entryType = valueTypes[type];
|
|
640
|
+
if (entryType !== void 0 && entryType !== "") {
|
|
641
|
+
const decoded = decodeValue(type, value);
|
|
642
|
+
if (decoded !== void 0) yield {
|
|
643
|
+
kind: "sample",
|
|
644
|
+
name,
|
|
645
|
+
type: entryType,
|
|
646
|
+
unit,
|
|
647
|
+
timestamp,
|
|
648
|
+
payload: decoded
|
|
649
|
+
};
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
if (type === structType && signal.schema !== void 0) {
|
|
653
|
+
const schema = custom.get(45056 | signal.schema)?.name;
|
|
654
|
+
if (schema === void 0 || schema === "") continue;
|
|
655
|
+
try {
|
|
656
|
+
const decoded = schema.endsWith("[]") ? structs.decodeArray(schema.slice(0, -2), value) : structs.decode(schema, value);
|
|
657
|
+
if (typeof decoded !== "string") yield {
|
|
658
|
+
kind: "sample",
|
|
659
|
+
name,
|
|
660
|
+
type: `struct:${schema}`,
|
|
661
|
+
unit,
|
|
662
|
+
timestamp,
|
|
663
|
+
payload: decoded
|
|
664
|
+
};
|
|
665
|
+
} catch {}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
export { parseHoot };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.60.1"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "hoot-parser",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Read HOOT data log files in TypeScript and JavaScript",
|
|
5
|
+
"homepage": "https://github.com/jonahsnider/hoot-parser#readme",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Jonah Snider",
|
|
9
|
+
"email": "jonah@jonahsnider.com",
|
|
10
|
+
"url": "https://jonahsnider.com"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/jonahsnider/hoot-parser.git"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./dist/index.mjs",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"api:check": "api-extractor run",
|
|
29
|
+
"api:update": "api-extractor run --local",
|
|
30
|
+
"bench": "vp run build && vp test bench",
|
|
31
|
+
"build": "vp pack",
|
|
32
|
+
"check": "vp check",
|
|
33
|
+
"dev": "vp pack --watch",
|
|
34
|
+
"prepare": "vp config",
|
|
35
|
+
"prepublishOnly": "pnpm build && pnpm api:check",
|
|
36
|
+
"test": "vp test run"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"wpilib-struct": "^1.1.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@codspeed/vitest-plugin": "6.1.1",
|
|
43
|
+
"@microsoft/api-extractor": "7.60.1",
|
|
44
|
+
"@types/node": "26.6.6",
|
|
45
|
+
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
46
|
+
"typescript": "7.0.2",
|
|
47
|
+
"vite-plus": "1.7.0",
|
|
48
|
+
"vitest": "5.1.0"
|
|
49
|
+
},
|
|
50
|
+
"devEngines": {
|
|
51
|
+
"runtime": {
|
|
52
|
+
"name": "node",
|
|
53
|
+
"version": "26.x"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"packageManager": "pnpm@12.21.0",
|
|
57
|
+
"tsdocMetadata": "./dist/tsdoc-metadata.json"
|
|
58
|
+
}
|