wpilog-parser 4.1.0 → 4.2.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.
|
@@ -208,7 +208,7 @@ function readTimestamp(view, offset, length) {
|
|
|
208
208
|
case 5: return view.getUint32(offset, true) + view.getUint8(offset + 4) * 2 ** 32;
|
|
209
209
|
case 6: return view.getUint32(offset, true) + view.getUint16(offset + 4, true) * 2 ** 32;
|
|
210
210
|
case 7: return view.getUint32(offset, true) + (view.getUint16(offset + 4, true) + view.getUint8(offset + 6) * 2 ** 16) * 2 ** 32;
|
|
211
|
-
case 8: return view.getUint32(offset, true) + view.
|
|
211
|
+
case 8: return view.getUint32(offset, true) + view.getInt32(offset + 4, true) * 2 ** 32;
|
|
212
212
|
default: throw new RangeError(`Invalid timestamp length ${length}`);
|
|
213
213
|
}
|
|
214
214
|
}
|
|
@@ -223,6 +223,8 @@ var RecordCursor = class {
|
|
|
223
223
|
payloadSize = 0;
|
|
224
224
|
/** Byte offset of the next record. */
|
|
225
225
|
offset;
|
|
226
|
+
/** Whether the input ended partway through a record. */
|
|
227
|
+
truncated = false;
|
|
226
228
|
constructor(input) {
|
|
227
229
|
const source = openDataLog(input);
|
|
228
230
|
this.bytes = source.bytes;
|
|
@@ -241,6 +243,7 @@ var RecordCursor = class {
|
|
|
241
243
|
const timestampLength = 1 + (bitfield >> 4 & 7);
|
|
242
244
|
if (offset + entryIdLength + payloadSizeLength + timestampLength > total) {
|
|
243
245
|
this.offset = total;
|
|
246
|
+
this.truncated = true;
|
|
244
247
|
return false;
|
|
245
248
|
}
|
|
246
249
|
const entryId = readVarInt(view, offset, entryIdLength);
|
|
@@ -251,6 +254,7 @@ var RecordCursor = class {
|
|
|
251
254
|
offset += timestampLength;
|
|
252
255
|
if (offset + payloadSize > total) {
|
|
253
256
|
this.offset = total;
|
|
257
|
+
this.truncated = true;
|
|
254
258
|
return false;
|
|
255
259
|
}
|
|
256
260
|
this.entryId = entryId;
|
|
@@ -264,9 +268,12 @@ var RecordCursor = class {
|
|
|
264
268
|
return this.bytes.subarray(this.payloadOffset, this.payloadOffset + this.payloadSize);
|
|
265
269
|
}
|
|
266
270
|
};
|
|
267
|
-
/** Expose a parser's
|
|
268
|
-
function
|
|
269
|
-
return Object.
|
|
271
|
+
/** Expose a parser's progress on its generator without adding work to the per-record loop. */
|
|
272
|
+
function withProgress(records, getBytesRead, getTruncated) {
|
|
273
|
+
return Object.defineProperties(records, {
|
|
274
|
+
bytesRead: { get: getBytesRead },
|
|
275
|
+
truncated: { get: getTruncated }
|
|
276
|
+
});
|
|
270
277
|
}
|
|
271
278
|
function* readRawRecords(input, progress) {
|
|
272
279
|
const { bytes, view, header, recordsOffset } = openDataLog(input);
|
|
@@ -284,6 +291,7 @@ function* readRawRecords(input, progress) {
|
|
|
284
291
|
const timestampLength = 1 + (bitfield >> 4 & 7);
|
|
285
292
|
if (offset + entryIdLength + payloadSizeLength + timestampLength > total) {
|
|
286
293
|
progress.offset = total;
|
|
294
|
+
progress.truncated = true;
|
|
287
295
|
return;
|
|
288
296
|
}
|
|
289
297
|
const entryId = readVarInt(view, offset, entryIdLength);
|
|
@@ -294,6 +302,7 @@ function* readRawRecords(input, progress) {
|
|
|
294
302
|
offset += timestampLength;
|
|
295
303
|
if (offset + payloadSize > total) {
|
|
296
304
|
progress.offset = total;
|
|
305
|
+
progress.truncated = true;
|
|
297
306
|
return;
|
|
298
307
|
}
|
|
299
308
|
const payload = bytes.subarray(offset, offset + payloadSize);
|
|
@@ -323,8 +332,11 @@ function* readRawRecords(input, progress) {
|
|
|
323
332
|
* or an intermediate transformation are not needed.
|
|
324
333
|
*/
|
|
325
334
|
function readRecords(input) {
|
|
326
|
-
const progress = {
|
|
327
|
-
|
|
335
|
+
const progress = {
|
|
336
|
+
offset: 0,
|
|
337
|
+
truncated: false
|
|
338
|
+
};
|
|
339
|
+
return withProgress(readRawRecords(input, progress), () => progress.offset, () => progress.truncated);
|
|
328
340
|
}
|
|
329
341
|
// src/struct/diagnostics.ts
|
|
330
342
|
/** Preserve the published WPILOG diagnostics at the protocol boundary. */
|
|
@@ -552,7 +564,7 @@ function* decodeRecords(records, options = { strict: false }) {
|
|
|
552
564
|
*/
|
|
553
565
|
function parseDataLog(input, options = { strict: false }) {
|
|
554
566
|
const state = {};
|
|
555
|
-
return
|
|
567
|
+
return withProgress(decodeCursorRecords(input, options, state), () => state.cursor?.offset ?? 0, () => state.cursor?.truncated ?? false);
|
|
556
568
|
}
|
|
557
569
|
function* decodeCursorRecords(input, options, state) {
|
|
558
570
|
const cursor = new RecordCursor(input);
|
|
@@ -587,7 +599,7 @@ function decodeNonScalarPayload(raw, entry, view, structRegistry, structDecodeQu
|
|
|
587
599
|
}
|
|
588
600
|
case "int64[]": {
|
|
589
601
|
const payload = [];
|
|
590
|
-
for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.
|
|
602
|
+
for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.getBigInt64(i, true));
|
|
591
603
|
return dataRecord(entry, timestamp, RecordType.Int64Array, payload);
|
|
592
604
|
}
|
|
593
605
|
case "float[]": {
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as readRecords, l as diagnostics, t as catalogEntries } from "./catalog-
|
|
2
|
+
import { a as readRecords, l as diagnostics, t as catalogEntries } from "./catalog-BP1qf30c.mjs";
|
|
3
3
|
import { Diagnostic, formatDiagnostic } from "nostics";
|
|
4
4
|
import { RootCommand, script } from "@bomb.sh/tab";
|
|
5
5
|
import { boolean, command, commandsInfo, positional, run } from "@drizzle-team/brocli";
|
|
@@ -7,7 +7,7 @@ import oscStatus from "osc-status";
|
|
|
7
7
|
import { readFile } from "node:fs/promises";
|
|
8
8
|
import { encode } from "@toon-format/toon";
|
|
9
9
|
// package.json
|
|
10
|
-
var version = "4.1
|
|
10
|
+
var version = "4.2.1";
|
|
11
11
|
var description = "Read WPILib wpilog data log files in TypeScript & JavaScript";
|
|
12
12
|
// src/cli/catalog.ts
|
|
13
13
|
async function catalogFile(filePath) {
|
package/dist/index.d.mts
CHANGED
|
@@ -45,7 +45,10 @@ type CatalogEntry = {
|
|
|
45
45
|
/** A raw (undecoded) data log record from the binary format. */
|
|
46
46
|
type RawRecord = {
|
|
47
47
|
entryId: number;
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Timestamp in microseconds. Can be negative for values set before logging started,
|
|
50
|
+
* such as NetworkTables values published before the log was opened.
|
|
51
|
+
*/
|
|
49
52
|
timestamp: number;
|
|
50
53
|
payload: Uint8Array;
|
|
51
54
|
};
|
|
@@ -79,7 +82,10 @@ type ControlRecord = Extract<DecodedRecord, {
|
|
|
79
82
|
export declare function isDataRecord(record: DecodedRecord): record is DataRecord;
|
|
80
83
|
/** A decoded data log record. */
|
|
81
84
|
type DecodedRecord = {
|
|
82
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Timestamp in microseconds. Can be negative for values set before logging started,
|
|
87
|
+
* such as NetworkTables values published before the log was opened.
|
|
88
|
+
*/
|
|
83
89
|
timestamp: number;
|
|
84
90
|
} & ({
|
|
85
91
|
entryId: number;
|
|
@@ -155,6 +161,11 @@ type DataLogGenerator<T> = Generator<T> & {
|
|
|
155
161
|
* Divide by the input's `byteLength` to estimate progress; it equals `byteLength` once parsing finishes.
|
|
156
162
|
*/
|
|
157
163
|
readonly bytesRead: number;
|
|
164
|
+
/**
|
|
165
|
+
* Whether the input ended partway through a record, such as a log cut off by a power loss.
|
|
166
|
+
* The incomplete record is not yielded. This is `false` until the parser reaches the end of the input.
|
|
167
|
+
*/
|
|
168
|
+
readonly truncated: boolean;
|
|
158
169
|
};
|
|
159
170
|
/**
|
|
160
171
|
* Read raw WPILOG records from an in-memory buffer.
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as readRecords, c as isDataRecord, i as withStructDiagnostics, n as decodeRecords, o as ControlRecordType, r as parseDataLog, s as RecordType, t as catalogEntries } from "./catalog-
|
|
1
|
+
import { a as readRecords, c as isDataRecord, i as withStructDiagnostics, n as decodeRecords, o as ControlRecordType, r as parseDataLog, s as RecordType, t as catalogEntries } from "./catalog-BP1qf30c.mjs";
|
|
2
2
|
import { KnownStructTypeName, parseStructSpecification as parseStructSpecification$1 } from "wpilib-struct";
|
|
3
3
|
// src/struct/parse-struct.ts
|
|
4
4
|
/** Parse a WPILib struct specification string into declarations. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wpilog-parser",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Read WPILib wpilog data log files in TypeScript & JavaScript",
|
|
5
5
|
"homepage": "https://github.com/jonahsnider/wpilog-parser#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@bomb.sh/tab": "^0.0.
|
|
33
|
+
"@bomb.sh/tab": "^0.0.23",
|
|
34
34
|
"@drizzle-team/brocli": "^0.12.1",
|
|
35
35
|
"@toon-format/toon": "^4.1.1",
|
|
36
36
|
"nostics": "^1.3.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@microsoft/api-extractor": "7.60.1",
|
|
42
|
-
"vite-plus": "1.
|
|
42
|
+
"vite-plus": "1.7.0",
|
|
43
43
|
"vitest": "5.1.0"
|
|
44
44
|
},
|
|
45
45
|
"tsdocMetadata": "./dist/tsdoc-metadata.json",
|
|
@@ -74,7 +74,7 @@ When DriverStation logging is on, every WPILOG has these `boolean` entries:
|
|
|
74
74
|
| `/DS:test` | `true` during test mode. |
|
|
75
75
|
| `/DS:estop` | `true` if e-stopped. |
|
|
76
76
|
|
|
77
|
-
The mode flags (`autonomous`, `test`) reflect what the DS _would_ run if enabled, so check `/DS:enabled` together with them. Timestamps are microseconds (`number`).
|
|
77
|
+
The mode flags (`autonomous`, `test`) reflect what the DS _would_ run if enabled, so check `/DS:enabled` together with them. Timestamps are microseconds (`number`). They can be negative for values set before logging started, such as NetworkTables values published before the log was opened.
|
|
78
78
|
|
|
79
79
|
### Tracking enable/mode durations
|
|
80
80
|
|