@emdzej/bimmerz-rpc-can 0.1.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 +131 -0
- package/README.md +66 -0
- package/dist/client.d.ts +41 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +71 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# PolyForm Noncommercial License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
In order to get any license under these terms, you must agree
|
|
8
|
+
to them as both strict obligations and conditions to all
|
|
9
|
+
your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the
|
|
14
|
+
software to do everything you might do with the software
|
|
15
|
+
that would otherwise infringe the licensor's copyright
|
|
16
|
+
in it for any permitted purpose. However, you may
|
|
17
|
+
only distribute the software according to [Distribution
|
|
18
|
+
License](#distribution-license) and make changes or new works
|
|
19
|
+
based on the software according to [Changes and New Works
|
|
20
|
+
License](#changes-and-new-works-license).
|
|
21
|
+
|
|
22
|
+
## Distribution License
|
|
23
|
+
|
|
24
|
+
The licensor grants you an additional copyright license
|
|
25
|
+
to distribute copies of the software. Your license
|
|
26
|
+
to distribute covers distributing the software with
|
|
27
|
+
changes and new works permitted by [Changes and New Works
|
|
28
|
+
License](#changes-and-new-works-license).
|
|
29
|
+
|
|
30
|
+
## Notices
|
|
31
|
+
|
|
32
|
+
You must ensure that anyone who gets a copy of any part of
|
|
33
|
+
the software from you also gets a copy of these terms or the
|
|
34
|
+
URL for them above, as well as copies of any plain-text lines
|
|
35
|
+
beginning with `Required Notice:` that the licensor provided
|
|
36
|
+
with the software. For example:
|
|
37
|
+
|
|
38
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
39
|
+
|
|
40
|
+
## Changes and New Works License
|
|
41
|
+
|
|
42
|
+
The licensor grants you an additional copyright license to
|
|
43
|
+
make changes and new works based on the software for any
|
|
44
|
+
permitted purpose.
|
|
45
|
+
|
|
46
|
+
## Patent License
|
|
47
|
+
|
|
48
|
+
The licensor grants you a patent license for the software that
|
|
49
|
+
covers patent claims the licensor can license, or becomes able
|
|
50
|
+
to license, that you would infringe by using the software.
|
|
51
|
+
|
|
52
|
+
## Noncommercial Purposes
|
|
53
|
+
|
|
54
|
+
Any noncommercial purpose is a permitted purpose.
|
|
55
|
+
|
|
56
|
+
## Personal Uses
|
|
57
|
+
|
|
58
|
+
Personal use for research, experiment, and testing for
|
|
59
|
+
the benefit of public knowledge, personal study, private
|
|
60
|
+
entertainment, hobby projects, amateur pursuits, or religious
|
|
61
|
+
observance, without any anticipated commercial application,
|
|
62
|
+
is use for a permitted purpose.
|
|
63
|
+
|
|
64
|
+
## Noncommercial Organizations
|
|
65
|
+
|
|
66
|
+
Use by any charitable organization, educational institution,
|
|
67
|
+
public research organization, public safety or health
|
|
68
|
+
organization, environmental protection organization,
|
|
69
|
+
or government institution is use for a permitted purpose
|
|
70
|
+
regardless of the source of funding or obligations resulting
|
|
71
|
+
from the funding.
|
|
72
|
+
|
|
73
|
+
## Fair Use
|
|
74
|
+
|
|
75
|
+
You may have "fair use" rights for the software under the
|
|
76
|
+
law. These terms do not limit them.
|
|
77
|
+
|
|
78
|
+
## No Other Rights
|
|
79
|
+
|
|
80
|
+
These terms do not allow you to sublicense or transfer any of
|
|
81
|
+
your licenses to anyone else, or prevent the licensor from
|
|
82
|
+
granting licenses to anyone else. These terms do not imply
|
|
83
|
+
any other licenses.
|
|
84
|
+
|
|
85
|
+
## Patent Defense
|
|
86
|
+
|
|
87
|
+
If you make any written claim that the software infringes or
|
|
88
|
+
contributes to infringement of any patent, your patent license
|
|
89
|
+
for the software granted under these terms ends immediately. If
|
|
90
|
+
your company makes such a claim, your patent license ends
|
|
91
|
+
immediately for work on behalf of your company.
|
|
92
|
+
|
|
93
|
+
## Violations
|
|
94
|
+
|
|
95
|
+
The first time you are notified in writing that you have
|
|
96
|
+
violated any of these terms, or done anything with the software
|
|
97
|
+
not covered by your licenses, your licenses can nonetheless
|
|
98
|
+
continue if you come into full compliance with these terms,
|
|
99
|
+
and take practical steps to correct past violations, within
|
|
100
|
+
32 days of receiving notice. Otherwise, all your licenses
|
|
101
|
+
end immediately.
|
|
102
|
+
|
|
103
|
+
## No Liability
|
|
104
|
+
|
|
105
|
+
***As far as the law allows, the software comes as is, without
|
|
106
|
+
any warranty or condition, and the licensor will not be liable
|
|
107
|
+
to you for any damages arising out of these terms or the use
|
|
108
|
+
or nature of the software, under any kind of legal claim.***
|
|
109
|
+
|
|
110
|
+
## Definitions
|
|
111
|
+
|
|
112
|
+
The **licensor** is the individual or entity offering these
|
|
113
|
+
terms, and the **software** is the software the licensor makes
|
|
114
|
+
available under these terms.
|
|
115
|
+
|
|
116
|
+
**You** refers to the individual or entity agreeing to these
|
|
117
|
+
terms.
|
|
118
|
+
|
|
119
|
+
**Your company** is any legal entity, sole proprietorship,
|
|
120
|
+
or other kind of organization that you work for, plus all
|
|
121
|
+
organizations that have control over, are under the control of,
|
|
122
|
+
or are under common control with that organization. **Control**
|
|
123
|
+
means ownership of substantially all the assets of an entity,
|
|
124
|
+
or the power to direct its management and policies by vote,
|
|
125
|
+
contract, or otherwise. Control can be direct or indirect.
|
|
126
|
+
|
|
127
|
+
**Your licenses** are all the licenses granted to you for the
|
|
128
|
+
software under these terms.
|
|
129
|
+
|
|
130
|
+
**Use** means anything you do with the software requiring one
|
|
131
|
+
of your licenses.
|
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @emdzej/bimmerz-rpc-can
|
|
2
|
+
|
|
3
|
+
Typed client for the bimmerz-box dongle's `/rpc/can/<n>` endpoint
|
|
4
|
+
(`n = 0` and `n = 1` are the two TJA1051T transceivers on the custom
|
|
5
|
+
PCB). Built on `@emdzej/bimmerz-rpc-core`.
|
|
6
|
+
|
|
7
|
+
Classical CAN only — the dongle's TJA1051T transceivers don't support
|
|
8
|
+
CAN-FD. Payloads are capped at 8 bytes.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pnpm add @emdzej/bimmerz-rpc-can
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Use
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { connectCan } from "@emdzej/bimmerz-rpc-can";
|
|
20
|
+
|
|
21
|
+
const { can } = await connectCan("ws://172.16.7.1/rpc/can/0", {
|
|
22
|
+
autoReconnect: true,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await can.open({ bitrate: 500_000, mode: "normal" });
|
|
26
|
+
|
|
27
|
+
can.onRx((frame) => {
|
|
28
|
+
console.log(
|
|
29
|
+
`[${frame.ts}] ${frame.id.toString(16).padStart(3, "0")}: ${
|
|
30
|
+
Array.from(frame.data, (b) => b.toString(16).padStart(2, "0")).join(" ")
|
|
31
|
+
}`,
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Send a frame
|
|
36
|
+
await can.send({
|
|
37
|
+
id: 0x6F1,
|
|
38
|
+
data: new Uint8Array([0x12, 0x21, 0x01]),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await can.close();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## API mirror
|
|
45
|
+
|
|
46
|
+
Method → server call:
|
|
47
|
+
|
|
48
|
+
| Method | Server endpoint |
|
|
49
|
+
|---------------------------------|------------------|
|
|
50
|
+
| `can.open(opts)` | `can.open` |
|
|
51
|
+
| `can.configure(opts)` | `can.configure` |
|
|
52
|
+
| `can.send(frame)` | `can.send` |
|
|
53
|
+
| `can.sendBatch(frames)` | `can.sendBatch` |
|
|
54
|
+
| `can.recover()` | `can.recover` |
|
|
55
|
+
| `can.close()` | `can.close` |
|
|
56
|
+
| `can.onRx(handler)` | subscribes to `can.rx` |
|
|
57
|
+
| `can.onRevoked(handler)` | subscribes to `can.revoked` |
|
|
58
|
+
|
|
59
|
+
`CanFrame` data is `Uint8Array`; base64 encoding for the wire is
|
|
60
|
+
handled internally.
|
|
61
|
+
|
|
62
|
+
## See also
|
|
63
|
+
|
|
64
|
+
- [bimmerz-box API reference](https://github.com/emdzej/bimmerz-box/blob/main/docs/api.md#rpccann)
|
|
65
|
+
- `@emdzej/bimmerz-rpc-core` — the JSON-RPC transport this builds on
|
|
66
|
+
- `@emdzej/bimmerz-rpc-uart` — sibling client for the UART endpoint
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed facade over the dongle's `/rpc/can/<n>` endpoint.
|
|
3
|
+
*
|
|
4
|
+
* Wraps a connected `RpcClient` and exposes each `can.*` method with
|
|
5
|
+
* its proper TypeScript shape, converting CAN frame payloads to/from
|
|
6
|
+
* `Uint8Array` so callers never have to deal with base64.
|
|
7
|
+
*/
|
|
8
|
+
import { RpcClient, type RpcClientOptions, type Unsubscribe } from "@emdzej/bimmerz-rpc-core";
|
|
9
|
+
import type { CanOpenOptions, CanConfigureOptions, CanOpenResult, CanFrame, CanSendBatchResult, CanRxEvent, CanRevokedEvent } from "./types.js";
|
|
10
|
+
export declare class CanClient {
|
|
11
|
+
readonly rpc: RpcClient;
|
|
12
|
+
constructor(rpc: RpcClient);
|
|
13
|
+
/** Claim the controller, install the TWAI driver, start the RX stream. */
|
|
14
|
+
open(opts: CanOpenOptions): Promise<CanOpenResult>;
|
|
15
|
+
/** Change bitrate / mode. The driver is uninstalled + reinstalled. */
|
|
16
|
+
configure(opts: CanConfigureOptions): Promise<CanOpenResult>;
|
|
17
|
+
/** Transmit a single CAN frame. */
|
|
18
|
+
send(frame: CanFrame): Promise<{
|
|
19
|
+
ok: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
/** Transmit up to 32 frames in one call. Stops on first failure. */
|
|
22
|
+
sendBatch(frames: CanFrame[]): Promise<CanSendBatchResult>;
|
|
23
|
+
/** Explicit bus-off recovery. */
|
|
24
|
+
recover(): Promise<{
|
|
25
|
+
ok: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
/** Release the lock, uninstall the driver, drive the transceiver's S pin high. */
|
|
28
|
+
close(): Promise<{
|
|
29
|
+
ok: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
/** Subscribe to streamed CAN frames. Returns an unsubscribe function. */
|
|
32
|
+
onRx(handler: (frame: CanRxEvent) => void): Unsubscribe;
|
|
33
|
+
/** Subscribe to revocation events (cooperative `open` from another client). */
|
|
34
|
+
onRevoked(handler: (ev: CanRevokedEvent) => void): Unsubscribe;
|
|
35
|
+
}
|
|
36
|
+
/** Convenience: build the WS URL, open it, and wrap in a CanClient. */
|
|
37
|
+
export declare function connectCan(url: string, options?: RpcClientOptions): Promise<{
|
|
38
|
+
can: CanClient;
|
|
39
|
+
rpc: RpcClient;
|
|
40
|
+
}>;
|
|
41
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAGjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,QAAQ,EACR,kBAAkB,EAClB,UAAU,EACV,eAAe,EAChB,MAAM,YAAY,CAAC;AA0BpB,qBAAa,SAAS;aACQ,GAAG,EAAE,SAAS;gBAAd,GAAG,EAAE,SAAS;IAE1C,0EAA0E;IACpE,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAIxD,sEAAsE;IAChE,SAAS,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;IAIlE,mCAAmC;IAC7B,IAAI,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE,CAAC;IAIrD,oEAAoE;IAC9D,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAMhE,iCAAiC;IAC3B,OAAO,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE,CAAC;IAIzC,kFAAkF;IAC5E,KAAK,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE,CAAC;IAIvC,yEAAyE;IACzE,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,GAAG,WAAW;IAYvD,+EAA+E;IAC/E,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,eAAe,KAAK,IAAI,GAAG,WAAW;CAG/D;AAED,uEAAuE;AACvE,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,GAAG,EAAE,SAAS,CAAA;CAAE,CAAC,CAI7C"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed facade over the dongle's `/rpc/can/<n>` endpoint.
|
|
3
|
+
*
|
|
4
|
+
* Wraps a connected `RpcClient` and exposes each `can.*` method with
|
|
5
|
+
* its proper TypeScript shape, converting CAN frame payloads to/from
|
|
6
|
+
* `Uint8Array` so callers never have to deal with base64.
|
|
7
|
+
*/
|
|
8
|
+
import { RpcClient, encodeBase64, decodeBase64, } from "@emdzej/bimmerz-rpc-core";
|
|
9
|
+
function frameToWire(f) {
|
|
10
|
+
return {
|
|
11
|
+
id: f.id,
|
|
12
|
+
ext: f.ext ?? false,
|
|
13
|
+
rtr: f.rtr ?? false,
|
|
14
|
+
data: encodeBase64(f.data),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export class CanClient {
|
|
18
|
+
rpc;
|
|
19
|
+
constructor(rpc) {
|
|
20
|
+
this.rpc = rpc;
|
|
21
|
+
}
|
|
22
|
+
/** Claim the controller, install the TWAI driver, start the RX stream. */
|
|
23
|
+
async open(opts) {
|
|
24
|
+
return this.rpc.request("can.open", opts);
|
|
25
|
+
}
|
|
26
|
+
/** Change bitrate / mode. The driver is uninstalled + reinstalled. */
|
|
27
|
+
async configure(opts) {
|
|
28
|
+
return this.rpc.request("can.configure", opts);
|
|
29
|
+
}
|
|
30
|
+
/** Transmit a single CAN frame. */
|
|
31
|
+
async send(frame) {
|
|
32
|
+
return this.rpc.request("can.send", frameToWire(frame));
|
|
33
|
+
}
|
|
34
|
+
/** Transmit up to 32 frames in one call. Stops on first failure. */
|
|
35
|
+
async sendBatch(frames) {
|
|
36
|
+
return this.rpc.request("can.sendBatch", {
|
|
37
|
+
frames: frames.map(frameToWire),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** Explicit bus-off recovery. */
|
|
41
|
+
async recover() {
|
|
42
|
+
return this.rpc.request("can.recover", {});
|
|
43
|
+
}
|
|
44
|
+
/** Release the lock, uninstall the driver, drive the transceiver's S pin high. */
|
|
45
|
+
async close() {
|
|
46
|
+
return this.rpc.request("can.close", {});
|
|
47
|
+
}
|
|
48
|
+
/** Subscribe to streamed CAN frames. Returns an unsubscribe function. */
|
|
49
|
+
onRx(handler) {
|
|
50
|
+
return this.rpc.on("can.rx", (params) => {
|
|
51
|
+
handler({
|
|
52
|
+
id: params.id,
|
|
53
|
+
ext: params.ext,
|
|
54
|
+
rtr: params.rtr,
|
|
55
|
+
data: decodeBase64(params.data),
|
|
56
|
+
ts: params.ts,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** Subscribe to revocation events (cooperative `open` from another client). */
|
|
61
|
+
onRevoked(handler) {
|
|
62
|
+
return this.rpc.on("can.revoked", handler);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Convenience: build the WS URL, open it, and wrap in a CanClient. */
|
|
66
|
+
export async function connectCan(url, options) {
|
|
67
|
+
const rpc = new RpcClient(url, options);
|
|
68
|
+
await rpc.connect();
|
|
69
|
+
return { can: new CanClient(rpc), rpc };
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,SAAS,EAGT,YAAY,EACZ,YAAY,GACb,MAAM,0BAA0B,CAAC;AA2BlC,SAAS,WAAW,CAAC,CAAW;IAC9B,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,GAAG,EAAE,CAAC,CAAC,GAAG,IAAI,KAAK;QACnB,GAAG,EAAE,CAAC,CAAC,GAAG,IAAI,KAAK;QACnB,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;KAC3B,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,SAAS;IACQ;IAA5B,YAA4B,GAAc;QAAd,QAAG,GAAH,GAAG,CAAW;IAAG,CAAC;IAE9C,0EAA0E;IAC1E,KAAK,CAAC,IAAI,CAAC,IAAoB;QAC7B,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAgB,UAAU,EAAE,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED,sEAAsE;IACtE,KAAK,CAAC,SAAS,CAAC,IAAyB;QACvC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAgB,eAAe,EAAE,IAAI,CAAC,CAAC;IAChE,CAAC;IAED,mCAAmC;IACnC,KAAK,CAAC,IAAI,CAAC,KAAe;QACxB,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAkB,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED,oEAAoE;IACpE,KAAK,CAAC,SAAS,CAAC,MAAkB;QAChC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAqB,eAAe,EAAE;YAC3D,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC;SAChC,CAAC,CAAC;IACL,CAAC;IAED,iCAAiC;IACjC,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAkB,aAAa,EAAE,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,kFAAkF;IAClF,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAkB,WAAW,EAAE,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,yEAAyE;IACzE,IAAI,CAAC,OAAoC;QACvC,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAY,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE;YACjD,OAAO,CAAC;gBACN,EAAE,EAAE,MAAM,CAAC,EAAE;gBACb,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC;gBAC/B,EAAE,EAAE,MAAM,CAAC,EAAE;aACd,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,+EAA+E;IAC/E,SAAS,CAAC,OAAsC;QAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAkB,aAAa,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;CACF;AAED,uEAAuE;AACvE,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAW,EACX,OAA0B;IAE1B,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACxC,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;IACpB,OAAO,EAAE,GAAG,EAAE,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC;AAC1C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@emdzej/bimmerz-rpc-can` — typed client for the bimmerz-box dongle's
|
|
3
|
+
* `/rpc/can/<n>` endpoint. Wraps `@emdzej/bimmerz-rpc-core`.
|
|
4
|
+
*
|
|
5
|
+
* Classical CAN only (no CAN-FD on the dongle's TJA1051T transceivers).
|
|
6
|
+
* See `bimmerz-box/docs/api.md` for the full server-side contract.
|
|
7
|
+
*/
|
|
8
|
+
export { CanClient, connectCan } from "./client.js";
|
|
9
|
+
export type { CanMode, CanBitrate, CanOpenOptions, CanConfigureOptions, CanOpenResult, CanFrame, CanSendBatchResult, CanRxEvent, CanRevokedEvent, } from "./types.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,YAAY,EACV,OAAO,EACP,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,QAAQ,EACR,kBAAkB,EAClB,UAAU,EACV,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@emdzej/bimmerz-rpc-can` — typed client for the bimmerz-box dongle's
|
|
3
|
+
* `/rpc/can/<n>` endpoint. Wraps `@emdzej/bimmerz-rpc-core`.
|
|
4
|
+
*
|
|
5
|
+
* Classical CAN only (no CAN-FD on the dongle's TJA1051T transceivers).
|
|
6
|
+
* See `bimmerz-box/docs/api.md` for the full server-side contract.
|
|
7
|
+
*/
|
|
8
|
+
export { CanClient, connectCan } from "./client.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CAN RPC method param + result shapes. Classical CAN only (no FD;
|
|
3
|
+
* the dongle's TJA1051T transceivers and the firmware's TWAI driver
|
|
4
|
+
* caps payload at 8 bytes). Mirrors the server contract in
|
|
5
|
+
* `bimmerz-box/docs/api.md` (`/rpc/can/<n>` section).
|
|
6
|
+
*/
|
|
7
|
+
export type CanMode = "normal" | "listen-only" | "no-ack";
|
|
8
|
+
/** Standard CAN bitrates the dongle supports. */
|
|
9
|
+
export type CanBitrate = 25_000 | 50_000 | 100_000 | 125_000 | 250_000 | 500_000 | 800_000 | 1_000_000;
|
|
10
|
+
export interface CanOpenOptions {
|
|
11
|
+
/** True → reject open if held; false (default) → revoke prior holder. */
|
|
12
|
+
exclusive?: boolean;
|
|
13
|
+
/** Bit-rate in bps. Must be one of the standard values. */
|
|
14
|
+
bitrate: CanBitrate;
|
|
15
|
+
/** Default `"normal"`. `"listen-only"` is read-only; `"no-ack"` doesn't ACK frames. */
|
|
16
|
+
mode?: CanMode;
|
|
17
|
+
}
|
|
18
|
+
export interface CanConfigureOptions {
|
|
19
|
+
bitrate?: CanBitrate;
|
|
20
|
+
mode?: CanMode;
|
|
21
|
+
}
|
|
22
|
+
export interface CanOpenResult {
|
|
23
|
+
ok: boolean;
|
|
24
|
+
bitrate: number;
|
|
25
|
+
mode: CanMode;
|
|
26
|
+
exclusive: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** A single CAN frame as the client sees it. */
|
|
29
|
+
export interface CanFrame {
|
|
30
|
+
/** 11-bit (when `ext` is false) or 29-bit (when `ext` is true) identifier. */
|
|
31
|
+
id: number;
|
|
32
|
+
/** Extended-frame format flag. Default false. */
|
|
33
|
+
ext?: boolean;
|
|
34
|
+
/** Remote Transmission Request flag. Default false. */
|
|
35
|
+
rtr?: boolean;
|
|
36
|
+
/** Payload (0..8 bytes for classical CAN). Required even for RTR — pass an empty Uint8Array. */
|
|
37
|
+
data: Uint8Array;
|
|
38
|
+
}
|
|
39
|
+
export interface CanSendBatchResult {
|
|
40
|
+
sent: number;
|
|
41
|
+
requested: number;
|
|
42
|
+
}
|
|
43
|
+
/** Received frame, as emitted by `can.rx`. */
|
|
44
|
+
export interface CanRxEvent {
|
|
45
|
+
id: number;
|
|
46
|
+
ext: boolean;
|
|
47
|
+
rtr: boolean;
|
|
48
|
+
data: Uint8Array;
|
|
49
|
+
/** Microseconds since the dongle's boot (`esp_timer_get_time()`). */
|
|
50
|
+
ts: number;
|
|
51
|
+
}
|
|
52
|
+
export interface CanRevokedEvent {
|
|
53
|
+
by: string;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,aAAa,GAAG,QAAQ,CAAC;AAE1D,iDAAiD;AACjD,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,MAAM,GACN,OAAO,GACP,OAAO,GACP,OAAO,GACP,OAAO,GACP,OAAO,GACP,SAAS,CAAC;AAEd,MAAM,WAAW,cAAc;IAC7B,yEAAyE;IACzE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2DAA2D;IAC3D,OAAO,EAAE,UAAU,CAAC;IACpB,uFAAuF;IACvF,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,gDAAgD;AAChD,MAAM,WAAW,QAAQ;IACvB,8EAA8E;IAC9E,EAAE,EAAE,MAAM,CAAC;IACX,iDAAiD;IACjD,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,uDAAuD;IACvD,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,gGAAgG;IAChG,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,8CAA8C;AAC9C,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;CACZ"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CAN RPC method param + result shapes. Classical CAN only (no FD;
|
|
3
|
+
* the dongle's TJA1051T transceivers and the firmware's TWAI driver
|
|
4
|
+
* caps payload at 8 bytes). Mirrors the server contract in
|
|
5
|
+
* `bimmerz-box/docs/api.md` (`/rpc/can/<n>` section).
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@emdzej/bimmerz-rpc-can",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Typed client for the bimmerz-box dongle's /rpc/can/<n> endpoint. Classical CAN frames, no FD. Built on @emdzej/bimmerz-rpc-core.",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@emdzej/bimmerz-rpc-core": "0.1.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^22.13.1",
|
|
23
|
+
"typescript": "^5.7.3"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/emdzej/bimmerz.git",
|
|
31
|
+
"directory": "packages/rpc-can"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"dev": "tsc --watch",
|
|
36
|
+
"lint": "eslint .",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"clean": "rm -rf dist .turbo *.tsbuildinfo"
|
|
39
|
+
}
|
|
40
|
+
}
|