can-opener-js 1.0.0 → 2.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 +105 -14
- package/dist/index.cjs +2224 -236
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +323 -38
- package/dist/index.d.ts +323 -38
- package/dist/index.js +2214 -236
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,19 +39,95 @@ const car = await vv.connect({
|
|
|
39
39
|
const rpmSubscribed = await car.subscribe("ENGINE_RPM"); // true
|
|
40
40
|
|
|
41
41
|
// Or subscribe to related signals at once.
|
|
42
|
-
const bodySubscribed = await car.subscribe(["TURN_SIGNAL_LEFT", "
|
|
42
|
+
const bodySubscribed = await car.subscribe(["TURN_SIGNAL_LEFT", "Vehicle.Body.Lights.Beam.High.IsOn"]); // true
|
|
43
43
|
const activeSubscriptions = car.subscriptionCount();
|
|
44
44
|
|
|
45
45
|
const speed = await car.query("VEHICLE_SPEED");
|
|
46
46
|
const rpm = car.state.engine_rpm;
|
|
47
47
|
const alsoRpm = car.state.get<number>("ENGINE_RPM");
|
|
48
48
|
|
|
49
|
-
await car.
|
|
49
|
+
await car.set("Vehicle.Body.Horn.IsActive", true);
|
|
50
50
|
|
|
51
51
|
await car.unsubscribe("ENGINE_RPM");
|
|
52
|
-
await car.unsubscribe(["TURN_SIGNAL_LEFT", "
|
|
52
|
+
await car.unsubscribe(["TURN_SIGNAL_LEFT", "Vehicle.Body.Lights.Beam.High.IsOn"]);
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
## Profile formats
|
|
56
|
+
|
|
57
|
+
Format 2 of the Vehicle Profile Standard is the default. The canonical
|
|
58
|
+
specification, the VSS catalog, the keyword vocabulary, and example packages
|
|
59
|
+
live in [the-can-opener/vehicle-profile-spec](https://github.com/the-can-opener/vehicle-profile-spec).
|
|
60
|
+
|
|
61
|
+
A format 2 package is a manifest (`manifest: 1`, `format: 2`) with the
|
|
62
|
+
documents and DBC files it lists. Pass the manifest as `content` and each
|
|
63
|
+
listed document under `documents`, named by the path the manifest gives it:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const car = await vv.connect({
|
|
67
|
+
id: "versa",
|
|
68
|
+
transport,
|
|
69
|
+
profiles: [{
|
|
70
|
+
name: "org.canopener.nissan.versa",
|
|
71
|
+
content: manifestYaml,
|
|
72
|
+
documents: [
|
|
73
|
+
{ name: "base.yaml", content: baseYaml },
|
|
74
|
+
{ name: "body.yaml", content: bodyYaml },
|
|
75
|
+
],
|
|
76
|
+
dbcFiles: [{ name: "signals.dbc", content: signalsDbc }],
|
|
77
|
+
}],
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
A loaded vehicle exposes properties keyed by VSS path, plus named queries and
|
|
82
|
+
named actions for what has no VSS path. The VSS methods take VSS paths only:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
await car.subscribe("Vehicle.Speed");
|
|
86
|
+
car.state.get<number>("Vehicle.Speed");
|
|
87
|
+
|
|
88
|
+
await car.read<number>("Vehicle.Speed"); // asks the ECU when the property has a query
|
|
89
|
+
await car.set("Vehicle.Cabin.IsCentralLockEngaged", true); // "acknowledged" | "sent" | "rejected" | "unknown"
|
|
90
|
+
await car.invoke("SIGNAL_OFF"); // named action
|
|
91
|
+
await car.query("SUPPORTED_PIDS_01_20"); // named query
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
A write never changes `car.state`; only an observation of the property does.
|
|
95
|
+
Setting a target the package has no request for throws and sends nothing.
|
|
96
|
+
|
|
97
|
+
The alias methods take legacy keywords only, never a VSS path. A property
|
|
98
|
+
alias names a path (`SPEED`, `LOCKED`). A command alias names one write target
|
|
99
|
+
(`LOCK` writes `true`, `UNLOCK` writes `false`, `HORN` writes `true`) or a
|
|
100
|
+
named action (`SIGNAL_OFF`):
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
await car.alias.read("SPEED");
|
|
104
|
+
await car.alias.subscribe("SPEED"); // the value lands in state under "Vehicle.Speed"
|
|
105
|
+
await car.alias.set("DRIVER_TEMP_SETTING", 22);
|
|
106
|
+
await car.alias.command("LOCK"); // same request as set("Vehicle.Cabin.IsCentralLockEngaged", true)
|
|
107
|
+
car.alias.list(); // every alias the loaded profiles answer to
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Passing `SPEED` or `LOCK` to a VSS method throws, and so does passing a VSS
|
|
111
|
+
path or a command alias to `alias.read`, `alias.subscribe`, or `alias.set`.
|
|
112
|
+
|
|
113
|
+
`allowedKeys` on a profile source limits what loads from it: `signals` and
|
|
114
|
+
`queries` list the property paths (and named queries) to keep, `actions` lists
|
|
115
|
+
the writable paths and named actions. A write case name such as
|
|
116
|
+
`Vehicle.Cabin.IsCentralLockEngaged=true` in `actions` keeps that one case of
|
|
117
|
+
the property. An omitted list keeps everything of that kind.
|
|
118
|
+
|
|
119
|
+
Format 1 (`version: 1` and `version: 1.1`) is legacy and still loads. The
|
|
120
|
+
loader maps its keywords onto VSS paths with the spec vocabulary: a `SPEED`
|
|
121
|
+
query becomes the query of `Vehicle.Speed`, `DOORS.lock` becomes the `true`
|
|
122
|
+
target of `Vehicle.Cabin.IsCentralLockEngaged`. A keyword the vocabulary gives
|
|
123
|
+
no path keeps its original name, so `ENGINE_RPM` and `VEHICLE_SPEED` in the
|
|
124
|
+
examples below still work as written. The rest of this README describes format
|
|
125
|
+
1 profiles.
|
|
126
|
+
|
|
127
|
+
Not supported yet in format 2: a `repeat` write and a request longer than one
|
|
128
|
+
ISO-TP frame load as unavailable and throw with the reason when used. A
|
|
129
|
+
package whose `depends` id is not loaded before it is skipped with a warning.
|
|
130
|
+
|
|
55
131
|
## Core Ideas
|
|
56
132
|
|
|
57
133
|
- Treat the vehicle like app state: subscribe to signals, read the latest values
|
|
@@ -110,7 +186,7 @@ legacy tests. In profile-backed vehicles, executable names come from YAML
|
|
|
110
186
|
`queries`, `actions`, and `signals` declarations.
|
|
111
187
|
|
|
112
188
|
See the [Vehicle Profile and Library Specification](docs/vehicle-profile-spec.md)
|
|
113
|
-
for YAML profiles, DBC files, capabilities, and the library contract, and
|
|
189
|
+
for legacy format 1 YAML profiles, DBC files, capabilities, and the library contract, and
|
|
114
190
|
[Vehicle Keywords](docs/vehicle-keywords.md) for the common capability names
|
|
115
191
|
profiles should use. See the
|
|
116
192
|
[BLE Transport Protocol](docs/can-opener-se-ble-protocol.md) and
|
|
@@ -179,10 +255,10 @@ await car.unsubscribe("ENGINE_RPM");
|
|
|
179
255
|
You can also declare related subscriptions together:
|
|
180
256
|
|
|
181
257
|
```ts
|
|
182
|
-
const subscribed = await car.subscribe(["TURN_SIGNAL_LEFT", "
|
|
258
|
+
const subscribed = await car.subscribe(["TURN_SIGNAL_LEFT", "Vehicle.Body.Lights.Beam.High.IsOn"]); // true
|
|
183
259
|
const activeCount = car.subscriptionCount(); // 2
|
|
184
260
|
|
|
185
|
-
await car.unsubscribe(["TURN_SIGNAL_LEFT", "
|
|
261
|
+
await car.unsubscribe(["TURN_SIGNAL_LEFT", "Vehicle.Body.Lights.Beam.High.IsOn"]);
|
|
186
262
|
```
|
|
187
263
|
|
|
188
264
|
Profile-backed subscriptions use names declared under YAML `signals`. Without
|
|
@@ -216,10 +292,13 @@ car.unsubscribeQuery(speedSubscription);
|
|
|
216
292
|
|
|
217
293
|
## Queries
|
|
218
294
|
|
|
219
|
-
Use `
|
|
295
|
+
Use `read()` for a property with a query binding, and `query()` for a named
|
|
296
|
+
query, which is a name declared under profile `queries` that has no VSS path:
|
|
220
297
|
|
|
221
298
|
```ts
|
|
222
|
-
const speed = await car.
|
|
299
|
+
const speed = await car.read<number>("Vehicle.Speed");
|
|
300
|
+
const sameSpeed = await car.alias.read<number>("SPEED");
|
|
301
|
+
const supported = await car.query("SUPPORTED_PIDS_01_20");
|
|
223
302
|
```
|
|
224
303
|
|
|
225
304
|
The YAML profile describes the endpoint, request bytes, accepted response IDs,
|
|
@@ -233,15 +312,17 @@ signal error.
|
|
|
233
312
|
|
|
234
313
|
## Actions
|
|
235
314
|
|
|
236
|
-
Use `
|
|
315
|
+
Use `set()` to write a property and `invoke()` for a named action, which is a
|
|
316
|
+
name declared under profile `actions` that has no single VSS actuator:
|
|
237
317
|
|
|
238
318
|
```ts
|
|
239
|
-
await car.
|
|
319
|
+
await car.set("Vehicle.Body.Horn.IsActive", true);
|
|
320
|
+
await car.invoke("FLASH_LIGHTS");
|
|
240
321
|
```
|
|
241
322
|
|
|
242
323
|
Actions can be request-only, verified request/response, or multi-step flows.
|
|
243
|
-
|
|
244
|
-
encoded frame signals.
|
|
324
|
+
Raw DBC-only vehicles, with no profile loaded, can still use `action()` with
|
|
325
|
+
action options to send encoded frame signals.
|
|
245
326
|
|
|
246
327
|
## Vehicle State
|
|
247
328
|
|
|
@@ -259,7 +340,8 @@ dispose();
|
|
|
259
340
|
```
|
|
260
341
|
|
|
261
342
|
State keys are stored by the subscribed name. In profile-backed vehicles, that
|
|
262
|
-
is the YAML `signals` or `queries` key
|
|
343
|
+
is the VSS path, or the YAML `signals` or `queries` key for a format 1 keyword
|
|
344
|
+
outside the vocabulary. Property access also accepts common
|
|
263
345
|
camelCase or snake_case variants by converting them to upper snake case.
|
|
264
346
|
|
|
265
347
|
## Transport
|
|
@@ -409,7 +491,16 @@ npm run build
|
|
|
409
491
|
```
|
|
410
492
|
|
|
411
493
|
The test suite uses `MockTransport` to simulate PID responses, action sends,
|
|
412
|
-
subscription registration, and incoming CAN frames.
|
|
494
|
+
subscription registration, and incoming CAN frames. The example packages of
|
|
495
|
+
the vehicle-profile-spec repository are copied under `tests/fixtures/spec` and
|
|
496
|
+
their fixture files run as tests.
|
|
497
|
+
|
|
498
|
+
The keyword vocabulary and the VSS leaf map under `src/profile/loaders` are
|
|
499
|
+
generated from a checkout of the spec repository:
|
|
500
|
+
|
|
501
|
+
```sh
|
|
502
|
+
node scripts/generate-vss-leaves.mjs ../vehicle-profile-spec
|
|
503
|
+
```
|
|
413
504
|
|
|
414
505
|
## Out of scope for v1
|
|
415
506
|
|