wpilog-parser 2.5.0 → 3.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/README.md +3 -1
- package/dist/{catalog-CfUKQI7-.mjs → catalog-AwcdBV3I.mjs} +40 -33
- package/dist/cli.mjs +2 -2
- package/dist/index.d.mts +6 -8
- package/dist/index.mjs +1 -22
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +9 -3
- package/skills/analyze-wpilog/SKILL.md +2 -2
package/README.md
CHANGED
|
@@ -25,9 +25,11 @@ for (const record of parseDataLog(bytes)) {
|
|
|
25
25
|
|
|
26
26
|
Use `readRecords()` and `decodeRecords()` separately when you need access to raw records or want to transform the record stream before decoding it. Both approaches produce the same decoded records.
|
|
27
27
|
|
|
28
|
-
Struct schemas are compiled lazily into reusable decoders, and struct payloads are returned as
|
|
28
|
+
Struct schemas are compiled lazily into reusable decoders, and struct payloads are returned as plain objects, including nested structs and arrays of structs.
|
|
29
29
|
In environments where Content Security Policy blocks runtime code generation, structs are decoded by the interpreter automatically.
|
|
30
30
|
|
|
31
|
+
A summary of the full API is available in [wpilog-parser.api.md](./etc/wpilog-parser.api.md).
|
|
32
|
+
|
|
31
33
|
## CLI
|
|
32
34
|
|
|
33
35
|
List every entry available in a log before writing an analysis script:
|
|
@@ -355,10 +355,10 @@ const KnownStructTypeName = {
|
|
|
355
355
|
Uint32: "uint32",
|
|
356
356
|
Uint64: "uint64",
|
|
357
357
|
Float32: "float32",
|
|
358
|
-
/** Equivalent to {@link KnownStructTypeName.Float32} */
|
|
358
|
+
/** Equivalent to {@link (KnownStructTypeName:variable).Float32} */
|
|
359
359
|
Float: "float",
|
|
360
360
|
Float64: "float64",
|
|
361
|
-
/** Equivalent to {@link KnownStructTypeName.Float64} */
|
|
361
|
+
/** Equivalent to {@link (KnownStructTypeName:variable).Float64} */
|
|
362
362
|
Double: "double"
|
|
363
363
|
};
|
|
364
364
|
//#endregion
|
|
@@ -599,6 +599,7 @@ function compileStruct(registry, name) {
|
|
|
599
599
|
const functionName = `s${functions.size}`;
|
|
600
600
|
functions.set(structName, functionName);
|
|
601
601
|
const statements = [];
|
|
602
|
+
const fields = [];
|
|
602
603
|
const bitFields = new BitFieldTracker();
|
|
603
604
|
let offset = 0;
|
|
604
605
|
for (const [index, member] of registry.getDefinition(structName).entries()) {
|
|
@@ -617,12 +618,12 @@ function compileStruct(registry, name) {
|
|
|
617
618
|
offset += memberSize;
|
|
618
619
|
}
|
|
619
620
|
const key = JSON.stringify(member.name);
|
|
620
|
-
statements.push(`
|
|
621
|
+
statements.push(`const v${index} = ${expression};`);
|
|
622
|
+
fields.push(`[${key}]: v${index}`);
|
|
621
623
|
}
|
|
622
624
|
sources.push(`function ${functionName}(view, bytes, base) {
|
|
623
|
-
const result = new Map();
|
|
624
625
|
${statements.join("\n")}
|
|
625
|
-
return
|
|
626
|
+
return {${fields.join(",")}};
|
|
626
627
|
}`);
|
|
627
628
|
return functionName;
|
|
628
629
|
}
|
|
@@ -950,15 +951,21 @@ var StructRegistry = class StructRegistry {
|
|
|
950
951
|
decodeInterpreted(structName, payload, offset = new ByteOffset()) {
|
|
951
952
|
if (!this.definitions.has(structName)) return structName;
|
|
952
953
|
const specification = this.getDefinition(structName);
|
|
953
|
-
const result =
|
|
954
|
+
const result = {};
|
|
954
955
|
const view = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
|
|
955
956
|
const bitFields = new BitFieldTracker();
|
|
956
957
|
for (const member of specification) {
|
|
958
|
+
if (member.name === "__proto__") Object.defineProperty(result, member.name, {
|
|
959
|
+
value: void 0,
|
|
960
|
+
enumerable: true,
|
|
961
|
+
writable: true,
|
|
962
|
+
configurable: true
|
|
963
|
+
});
|
|
957
964
|
const memberByteLength = this.calculateByteLength(member);
|
|
958
965
|
const bitField = typeof memberByteLength === "number" ? bitFields.next(member, memberByteLength) : void 0;
|
|
959
966
|
if (bitField) {
|
|
960
967
|
offset.advance(bitField.bytesToAdvance);
|
|
961
|
-
result
|
|
968
|
+
result[member.name] = decodeBitField(view, offset.get(), member, bitField);
|
|
962
969
|
continue;
|
|
963
970
|
}
|
|
964
971
|
offset.advance(bitFields.flush());
|
|
@@ -970,9 +977,9 @@ var StructRegistry = class StructRegistry {
|
|
|
970
977
|
array.push(Boolean(view.getUint8(offset.get())));
|
|
971
978
|
offset.advance8();
|
|
972
979
|
}
|
|
973
|
-
result
|
|
980
|
+
result[member.name] = array;
|
|
974
981
|
} else {
|
|
975
|
-
result
|
|
982
|
+
result[member.name] = Boolean(view.getUint8(offset.get()));
|
|
976
983
|
offset.advance8();
|
|
977
984
|
}
|
|
978
985
|
break;
|
|
@@ -983,9 +990,9 @@ var StructRegistry = class StructRegistry {
|
|
|
983
990
|
array.push(view.getInt8(offset.get()));
|
|
984
991
|
offset.advance8();
|
|
985
992
|
}
|
|
986
|
-
result
|
|
993
|
+
result[member.name] = array;
|
|
987
994
|
} else {
|
|
988
|
-
result
|
|
995
|
+
result[member.name] = view.getInt8(offset.get());
|
|
989
996
|
offset.advance8();
|
|
990
997
|
}
|
|
991
998
|
break;
|
|
@@ -996,9 +1003,9 @@ var StructRegistry = class StructRegistry {
|
|
|
996
1003
|
array.push(view.getInt16(offset.get(), true));
|
|
997
1004
|
offset.advance16();
|
|
998
1005
|
}
|
|
999
|
-
result
|
|
1006
|
+
result[member.name] = array;
|
|
1000
1007
|
} else {
|
|
1001
|
-
result
|
|
1008
|
+
result[member.name] = view.getInt16(offset.get(), true);
|
|
1002
1009
|
offset.advance16();
|
|
1003
1010
|
}
|
|
1004
1011
|
break;
|
|
@@ -1009,9 +1016,9 @@ var StructRegistry = class StructRegistry {
|
|
|
1009
1016
|
array.push(view.getInt32(offset.get(), true));
|
|
1010
1017
|
offset.advance32();
|
|
1011
1018
|
}
|
|
1012
|
-
result
|
|
1019
|
+
result[member.name] = array;
|
|
1013
1020
|
} else {
|
|
1014
|
-
result
|
|
1021
|
+
result[member.name] = view.getInt32(offset.get(), true);
|
|
1015
1022
|
offset.advance32();
|
|
1016
1023
|
}
|
|
1017
1024
|
break;
|
|
@@ -1022,9 +1029,9 @@ var StructRegistry = class StructRegistry {
|
|
|
1022
1029
|
array.push(view.getBigInt64(offset.get(), true));
|
|
1023
1030
|
offset.advance64();
|
|
1024
1031
|
}
|
|
1025
|
-
result
|
|
1032
|
+
result[member.name] = array;
|
|
1026
1033
|
} else {
|
|
1027
|
-
result
|
|
1034
|
+
result[member.name] = view.getBigInt64(offset.get(), true);
|
|
1028
1035
|
offset.advance64();
|
|
1029
1036
|
}
|
|
1030
1037
|
break;
|
|
@@ -1035,9 +1042,9 @@ var StructRegistry = class StructRegistry {
|
|
|
1035
1042
|
array.push(view.getUint8(offset.get()));
|
|
1036
1043
|
offset.advance8();
|
|
1037
1044
|
}
|
|
1038
|
-
result
|
|
1045
|
+
result[member.name] = array;
|
|
1039
1046
|
} else {
|
|
1040
|
-
result
|
|
1047
|
+
result[member.name] = view.getUint8(offset.get());
|
|
1041
1048
|
offset.advance8();
|
|
1042
1049
|
}
|
|
1043
1050
|
break;
|
|
@@ -1048,9 +1055,9 @@ var StructRegistry = class StructRegistry {
|
|
|
1048
1055
|
array.push(view.getUint16(offset.get(), true));
|
|
1049
1056
|
offset.advance16();
|
|
1050
1057
|
}
|
|
1051
|
-
result
|
|
1058
|
+
result[member.name] = array;
|
|
1052
1059
|
} else {
|
|
1053
|
-
result
|
|
1060
|
+
result[member.name] = view.getUint16(offset.get(), true);
|
|
1054
1061
|
offset.advance16();
|
|
1055
1062
|
}
|
|
1056
1063
|
break;
|
|
@@ -1061,9 +1068,9 @@ var StructRegistry = class StructRegistry {
|
|
|
1061
1068
|
array.push(view.getUint32(offset.get(), true));
|
|
1062
1069
|
offset.advance32();
|
|
1063
1070
|
}
|
|
1064
|
-
result
|
|
1071
|
+
result[member.name] = array;
|
|
1065
1072
|
} else {
|
|
1066
|
-
result
|
|
1073
|
+
result[member.name] = view.getUint32(offset.get(), true);
|
|
1067
1074
|
offset.advance32();
|
|
1068
1075
|
}
|
|
1069
1076
|
break;
|
|
@@ -1074,9 +1081,9 @@ var StructRegistry = class StructRegistry {
|
|
|
1074
1081
|
array.push(view.getBigUint64(offset.get(), true));
|
|
1075
1082
|
offset.advance64();
|
|
1076
1083
|
}
|
|
1077
|
-
result
|
|
1084
|
+
result[member.name] = array;
|
|
1078
1085
|
} else {
|
|
1079
|
-
result
|
|
1086
|
+
result[member.name] = view.getBigUint64(offset.get(), true);
|
|
1080
1087
|
offset.advance64();
|
|
1081
1088
|
}
|
|
1082
1089
|
break;
|
|
@@ -1088,9 +1095,9 @@ var StructRegistry = class StructRegistry {
|
|
|
1088
1095
|
array.push(view.getFloat32(offset.get(), true));
|
|
1089
1096
|
offset.advance32();
|
|
1090
1097
|
}
|
|
1091
|
-
result
|
|
1098
|
+
result[member.name] = array;
|
|
1092
1099
|
} else {
|
|
1093
|
-
result
|
|
1100
|
+
result[member.name] = view.getFloat32(offset.get(), true);
|
|
1094
1101
|
offset.advance32();
|
|
1095
1102
|
}
|
|
1096
1103
|
break;
|
|
@@ -1102,15 +1109,15 @@ var StructRegistry = class StructRegistry {
|
|
|
1102
1109
|
array.push(view.getFloat64(offset.get(), true));
|
|
1103
1110
|
offset.advance64();
|
|
1104
1111
|
}
|
|
1105
|
-
result
|
|
1112
|
+
result[member.name] = array;
|
|
1106
1113
|
} else {
|
|
1107
|
-
result
|
|
1114
|
+
result[member.name] = view.getFloat64(offset.get(), true);
|
|
1108
1115
|
offset.advance64();
|
|
1109
1116
|
}
|
|
1110
1117
|
break;
|
|
1111
1118
|
case KnownStructTypeName.Character:
|
|
1112
|
-
if (member.arraySize !== void 0) result
|
|
1113
|
-
else result
|
|
1119
|
+
if (member.arraySize !== void 0) result[member.name] = StructRegistry.TEXT_DECODER.decode(payload.subarray(offset.get(), offset.advance(member.arraySize).get()));
|
|
1120
|
+
else result[member.name] = StructRegistry.TEXT_DECODER.decode(payload.subarray(offset.get(), offset.advance8().get()));
|
|
1114
1121
|
break;
|
|
1115
1122
|
default: if (member.arraySize !== void 0) {
|
|
1116
1123
|
const array = [];
|
|
@@ -1119,11 +1126,11 @@ var StructRegistry = class StructRegistry {
|
|
|
1119
1126
|
if (typeof decoded === "string") return decoded;
|
|
1120
1127
|
array.push(decoded);
|
|
1121
1128
|
}
|
|
1122
|
-
result
|
|
1129
|
+
result[member.name] = array;
|
|
1123
1130
|
} else {
|
|
1124
1131
|
const decoded = this.decodeInterpreted(member.value, payload, offset);
|
|
1125
1132
|
if (typeof decoded === "string") return decoded;
|
|
1126
|
-
result
|
|
1133
|
+
result[member.name] = decoded;
|
|
1127
1134
|
}
|
|
1128
1135
|
}
|
|
1129
1136
|
}
|
package/dist/cli.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { o as readRecords, t as catalogEntries, u as diagnostics } from "./catalog-
|
|
2
|
+
import { o as readRecords, t as catalogEntries, u as diagnostics } from "./catalog-AwcdBV3I.mjs";
|
|
3
3
|
import { Diagnostic, formatDiagnostic } from "nostics";
|
|
4
4
|
import { cac } from "cac";
|
|
5
5
|
import oscStatus from "osc-status";
|
|
6
6
|
import { readFile } from "node:fs/promises";
|
|
7
7
|
import { encode } from "@toon-format/toon";
|
|
8
8
|
//#region package.json
|
|
9
|
-
var version = "
|
|
9
|
+
var version = "3.0.0";
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/cli/catalog.ts
|
|
12
12
|
async function catalogFile(filePath) {
|
package/dist/index.d.mts
CHANGED
|
@@ -60,8 +60,10 @@ export declare const RecordType: {
|
|
|
60
60
|
readonly Raw: 'raw';
|
|
61
61
|
};
|
|
62
62
|
export type RecordType = (typeof RecordType)[keyof typeof RecordType];
|
|
63
|
-
/** Decoded struct payload
|
|
64
|
-
type StructPayload =
|
|
63
|
+
/** Decoded struct payload. Fields, including nested structs, are own properties of a plain object. */
|
|
64
|
+
type StructPayload = {
|
|
65
|
+
[key: string]: number | boolean | bigint | string | StructPayload | number[] | boolean[] | bigint[] | StructPayload[] | undefined;
|
|
66
|
+
};
|
|
65
67
|
/** A decoded data record (excludes control records). */
|
|
66
68
|
type DataRecord = Extract<DecodedRecord, {
|
|
67
69
|
name: string;
|
|
@@ -180,10 +182,6 @@ export declare function decodeRecords(records: Iterable<ReadRecord>, options?: D
|
|
|
180
182
|
*/
|
|
181
183
|
export declare function parseDataLog(input: DataLogInput, options?: DecodeRecordsOptions): Generator<DecodedRecord>;
|
|
182
184
|
//#endregion
|
|
183
|
-
//#region src/struct-payload-to-json.d.ts
|
|
184
|
-
/** Convert a {@link StructPayload} Map to a plain JSON-compatible object. */
|
|
185
|
-
export declare function structPayloadToJson(payload: StructPayload): object;
|
|
186
|
-
//#endregion
|
|
187
185
|
//#region src/catalog.d.ts
|
|
188
186
|
/** An entry definition from the WPILOG catalog. */
|
|
189
187
|
type CatalogEntry = {
|
|
@@ -214,10 +212,10 @@ export declare const KnownStructTypeName: {
|
|
|
214
212
|
readonly Uint32: 'uint32';
|
|
215
213
|
readonly Uint64: 'uint64';
|
|
216
214
|
readonly Float32: 'float32';
|
|
217
|
-
/** Equivalent to {@link KnownStructTypeName.Float32} */
|
|
215
|
+
/** Equivalent to {@link (KnownStructTypeName:variable).Float32} */
|
|
218
216
|
readonly Float: 'float';
|
|
219
217
|
readonly Float64: 'float64';
|
|
220
|
-
/** Equivalent to {@link KnownStructTypeName.Float64} */
|
|
218
|
+
/** Equivalent to {@link (KnownStructTypeName:variable).Float64} */
|
|
221
219
|
readonly Double: 'double';
|
|
222
220
|
};
|
|
223
221
|
export type KnownStructTypeName = (typeof KnownStructTypeName)[keyof typeof KnownStructTypeName];
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/struct-payload-to-json.ts
|
|
3
|
-
/** Convert a {@link StructPayload} Map to a plain JSON-compatible object. */
|
|
4
|
-
function structPayloadToJson(payload) {
|
|
5
|
-
const result = {};
|
|
6
|
-
for (const [key, value] of payload) {
|
|
7
|
-
let converted;
|
|
8
|
-
if (value instanceof Map) converted = structPayloadToJson(value);
|
|
9
|
-
else if (Array.isArray(value) && value.length > 0 && value[0] instanceof Map) converted = value.map((v) => structPayloadToJson(v));
|
|
10
|
-
else converted = value;
|
|
11
|
-
if (key === "__proto__") Object.defineProperty(result, key, {
|
|
12
|
-
value: converted,
|
|
13
|
-
enumerable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
configurable: true
|
|
16
|
-
});
|
|
17
|
-
else result[key] = converted;
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
export { ControlRecordType, KnownStructTypeName, RecordType, catalogEntries, decodeRecords, isDataRecord, parseDataLog, parseStructSpecification, readRecords, structPayloadToJson };
|
|
1
|
+
export { s as ControlRecordType, a as KnownStructTypeName, c as RecordType, t as catalogEntries, n as decodeRecords, l as isDataRecord, r as parseDataLog, i as parseStructSpecification, o as readRecords } from "./catalog-AwcdBV3I.mjs";
|
|
@@ -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.59.4"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wpilog-parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
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",
|
|
@@ -29,13 +29,17 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
+
"api:check": "api-extractor run",
|
|
33
|
+
"api:update": "api-extractor run --local",
|
|
32
34
|
"bench": "vp test bench",
|
|
33
35
|
"build": "vp pack",
|
|
34
36
|
"check": "vp check",
|
|
35
37
|
"dev": "vp pack --watch",
|
|
36
38
|
"generate": "node ./src/struct/codegen.ts",
|
|
39
|
+
"preapi:check": "vp run build",
|
|
40
|
+
"preapi:update": "vp run build",
|
|
37
41
|
"prepare": "vp config",
|
|
38
|
-
"prepublishOnly": "vp run
|
|
42
|
+
"prepublishOnly": "vp run api:check",
|
|
39
43
|
"start": "node ./src/cli.ts",
|
|
40
44
|
"test": "vp test"
|
|
41
45
|
},
|
|
@@ -48,6 +52,7 @@
|
|
|
48
52
|
},
|
|
49
53
|
"devDependencies": {
|
|
50
54
|
"@codspeed/vitest-plugin": "6.1.0",
|
|
55
|
+
"@microsoft/api-extractor": "7.59.4",
|
|
51
56
|
"@types/node": "26.6.5",
|
|
52
57
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
53
58
|
"typescript": "7.0.2",
|
|
@@ -60,5 +65,6 @@
|
|
|
60
65
|
"version": "26.x"
|
|
61
66
|
}
|
|
62
67
|
},
|
|
63
|
-
"packageManager": "pnpm@12.14.0"
|
|
68
|
+
"packageManager": "pnpm@12.14.0",
|
|
69
|
+
"tsdocMetadata": "./dist/tsdoc-metadata.json"
|
|
64
70
|
}
|
|
@@ -42,11 +42,11 @@ for (const record of parseDataLog(bytes)) {
|
|
|
42
42
|
### Decoding structs
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
|
-
import { parseDataLog, RecordType
|
|
45
|
+
import { parseDataLog, RecordType } from 'wpilog-parser';
|
|
46
46
|
|
|
47
47
|
for (const record of parseDataLog(bytes)) {
|
|
48
48
|
if (record.type === RecordType.Struct && record.name === '/Robot/Localization/EstimatedPose') {
|
|
49
|
-
console.log(record.timestamp,
|
|
49
|
+
console.log(record.timestamp, record.payload);
|
|
50
50
|
// 18688018n {
|
|
51
51
|
// translation: { x: 10.289, y: 0.47 },
|
|
52
52
|
// rotation: { value: 1.5707961072652017 },
|