@slastra/tsplib 0.1.0 → 0.2.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/FINDINGS.md +40 -14
- package/README.md +20 -14
- package/dist/web-bluetooth.d.ts +9 -0
- package/dist/web-bluetooth.d.ts.map +1 -1
- package/dist/web-bluetooth.js +5 -3
- package/dist/web-bluetooth.js.map +1 -1
- package/package.json +4 -2
- package/src/web-bluetooth.ts +18 -3
package/FINDINGS.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Findings: Labeer Y43BT over BLE
|
|
1
|
+
# Findings: Labeer Y43BT and Core Innovations CTP800BD over BLE
|
|
2
2
|
|
|
3
3
|
How the Y43BT's BLE interface was mapped, on 2026-11-03, with a Labeer Y43BT on the bench and [bleak](https://github.com/hbldh/bleak) on Linux (BlueZ). Every claim below was checked on paper or on the wire.
|
|
4
4
|
|
|
@@ -6,22 +6,22 @@ How the Y43BT's BLE interface was mapped, on 2026-11-03, with a Labeer Y43BT on
|
|
|
6
6
|
|
|
7
7
|
The printer is dual-mode and shows up twice:
|
|
8
8
|
|
|
9
|
-
| Name
|
|
10
|
-
|
|
11
|
-
| `Y43BT-69B2`
|
|
12
|
-
| `Y43BT-69B2_LE` | `E8:D4:1E:FA:69:B2` (random) | BLE
|
|
9
|
+
| Name | Address | Transport |
|
|
10
|
+
| --------------- | ---------------------------- | ----------------- |
|
|
11
|
+
| `Y43BT-69B2` | `28:D4:1E:FA:69:B2` | classic Bluetooth |
|
|
12
|
+
| `Y43BT-69B2_LE` | `E8:D4:1E:FA:69:B2` (random) | BLE |
|
|
13
13
|
|
|
14
14
|
The LE advertisement lists service UUIDs `18f0` and `fee7` (the Tencent/WeChat service), and manufacturer data carrying the classic MAC.
|
|
15
15
|
|
|
16
16
|
## The GATT table
|
|
17
17
|
|
|
18
|
-
| Service
|
|
19
|
-
|
|
20
|
-
| `18f0`
|
|
21
|
-
| `ff00`
|
|
22
|
-
| `ff80`
|
|
23
|
-
| `49535343-fe7d-…`
|
|
24
|
-
| `fff0`, `ff10`, `fee7` | assorted
|
|
18
|
+
| Service | Characteristics | What it turned out to be |
|
|
19
|
+
| ---------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
|
|
20
|
+
| `18f0` | `2af1` write, `2af0` notify | The usual home of TSPL on cheap BLE printers. **Accepts writes and does nothing.** No reply, no motor, no print. |
|
|
21
|
+
| `ff00` | `ff02` write, `ff01` notify, `ff03` notify | **The printer.** TSPL on `ff02`, credit flow on `ff03`. |
|
|
22
|
+
| `ff80` | `ff82` write, `ff81` notify | The BT module's AT command channel: anything else gets `\r\nERROR\r\n`. |
|
|
23
|
+
| `49535343-fe7d-…` | ISSC transparent UART | Answers every write with `00 00 00 f7 01`, whatever was sent. |
|
|
24
|
+
| `fff0`, `ff10`, `fee7` | assorted | Silent to everything tried. |
|
|
25
25
|
|
|
26
26
|
## Finding the channel
|
|
27
27
|
|
|
@@ -54,10 +54,36 @@ A 112 mm ruler printed under that `SIZE` stopped right after its 101 mm tick. Th
|
|
|
54
54
|
|
|
55
55
|
## Media
|
|
56
56
|
|
|
57
|
-
4 × 6 in gap stock prints cleanly. 2 × 1 in stock printed the start of a label and then jammed twice on adhesive in the paper path
|
|
57
|
+
4 × 6 in gap stock prints cleanly. 2 × 1 in stock first printed the start of a label and then jammed, twice, on adhesive left in the paper path. Once that was cleaned out it printed without issue from printrow, placed correctly with the raster at `x = 0`, so the printer positions a narrow label from `SIZE` itself.
|
|
58
58
|
|
|
59
59
|
## Still open
|
|
60
60
|
|
|
61
61
|
- The true head width, which needs a `SIZE` wider than 4 in.
|
|
62
62
|
- Any status query this printer answers, if one exists. The vendor app (Flashlabel Pro) would show it in an HCI snoop.
|
|
63
|
-
|
|
63
|
+
|
|
64
|
+
## Core Innovations CTP800BD
|
|
65
|
+
|
|
66
|
+
Probed on 2026-11-04, with raw LE ATT sockets on Linux (bluetoothd bypassed, for the reason below) and then from Chrome.
|
|
67
|
+
|
|
68
|
+
### Same module, different name
|
|
69
|
+
|
|
70
|
+
It advertises as `Shipping Printer-B863` on a **public** address, `02:3F:05:B8:B8:63`, with service UUIDs `e7810a71-73ae-499d-8c15-faa9aef0c3f2` and the classic SPP `1101`. The GATT table matches the Y43BT's where it matters: `ff00` with `ff02` write, `ff01` and `ff03` notify, and `18f0`/`2af1` again. It also carries `e7810a71-…` (characteristic `bef8d6c9-…`) and the ISSC UART service, but no `ff80` AT channel.
|
|
71
|
+
|
|
72
|
+
TSPL on `ff02` prints: first a hand-written `TEXT`/`BOX`/`BAR` job, then a full 4 × 6 in raster from `buildLabel` (816 × 1216, 124,133 bytes) with an edge border, a millimetre ruler and 1-, 2- and 4-dot checkerboards. It came out complete and clean, and the ruler burned past its 100 mm tick. The product page gives the print width as 4.01 in. None of `ESC !?`, `~!T`, `~!I`, `~!F`, `~HS`, `ESC !S` or `~!@` got a reply on any channel.
|
|
73
|
+
|
|
74
|
+
### It never returns credits
|
|
75
|
+
|
|
76
|
+
On subscribing, `ff03` notifies:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
01 0a 10 credits
|
|
80
|
+
02 b6 00 182: the largest write the module takes
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
After that it never sent anything else on `ff03`: no credit back after any write, during a job or in the seconds after it. The full raster went out as 683 back-to-back 182-byte writes with no gating at all, in 1.6 s from the host's side, and printed without loss. Metering it by credits would stall on the eleventh write, so `connect` takes `credits: false` for it.
|
|
84
|
+
|
|
85
|
+
### Linux: BlueZ connects over classic
|
|
86
|
+
|
|
87
|
+
The printer runs classic and LE on the same public address, and its advertising flags (`0x02`) do not mark BR/EDR as unsupported. For a device like that, BlueZ's `Device1.Connect` picks BR/EDR: a classic bond always wins, and otherwise the "last seen" tie between the two bearers breaks toward classic. A `btmon` capture of Chrome's `gatt.connect()` shows HCI `Create Connection` (the BR/EDR page, `0x01|0x0005`), then SDP on PSM 1, then a disconnect about five seconds later, because there is no GATT over classic. Chrome reports `NetworkError: Unknown error when connecting to the device`.
|
|
88
|
+
|
|
89
|
+
BlueZ 5.87 has a per-device `PreferredBearer` property, but only with `Experimental = true` in `/etc/bluetooth/main.conf`. With that on and the property set to `le` (and `Trusted` set to true), Chrome connected over LE and printed. A classic pairing from the desktop's Bluetooth settings also forces BR/EDR, so the printer should not be paired there.
|
package/README.md
CHANGED
|
@@ -11,13 +11,19 @@ TSPL itself is an open, documented language, and plenty of code already speaks i
|
|
|
11
11
|
|
|
12
12
|
## Hardware
|
|
13
13
|
|
|
14
|
-
Verified on a **Labeer Y43BT** over BLE, at 203 dpi (8 dots/mm), on 4 × 6 in stock: text, rasters, and a 1-dot checkerboard all print clean. A 60 KB full-width raster transfers in under 3 seconds. [printrow](https://printrow.lastra.us) drives it through this library, from Chrome.
|
|
14
|
+
Verified on a **Labeer Y43BT** over BLE, at 203 dpi (8 dots/mm), on 4 × 6 in and 2 × 1 in gap stock: text, rasters, and a 1-dot checkerboard all print clean. A 60 KB full-width raster transfers in under 3 seconds. [printrow](https://printrow.lastra.us) drives it through this library, from Chrome.
|
|
15
15
|
|
|
16
16
|
The module advertises twice, as `Y43BT-XXXX` (classic Bluetooth) and `Y43BT-XXXX_LE`. Only the `_LE` one has the GATT services, so that is the one to pick in Chrome's chooser.
|
|
17
17
|
|
|
18
|
-
The head prints at least the full 4 in (101.6 mm); its true width has not been measured past that.
|
|
18
|
+
The head prints at least the full 4 in (101.6 mm); its true width has not been measured past that. A narrow label needs no `x` offset: the printer places it under the head from `SIZE` alone.
|
|
19
19
|
|
|
20
|
-
**
|
|
20
|
+
Also verified on a **Core Innovations CTP800BD**, the same module family under the name `Shipping Printer-XXXX`, on 4 × 6 in gap stock with a full-width 124 KB raster. Two things differ. It grants ten credits on subscribing and never returns another, so it has to be driven with `credits: false`. And it runs classic and LE on one public address, which on Linux makes BlueZ connect over classic and fail; [FINDINGS.md](./FINDINGS.md#core-innovations-ctp800bd) has the BlueZ setting that fixes it.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
const link = await connect({ namePrefix: 'Shipping Printer', credits: false });
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**How to tell if your printer is this one.** Connect over BLE and look for service `ff00` with characteristics `ff02` (write) and `ff03` (notify). If subscribing to `ff03` immediately notifies a credit grant (`01 nn`) and a write limit (`02 lo hi`), it is this module, whatever the case says. If the credits never come back after writes, use `credits: false`.
|
|
21
27
|
|
|
22
28
|
## Install
|
|
23
29
|
|
|
@@ -45,17 +51,17 @@ await printJob(link, [async () => job], { onProgress: (done, total) => console.l
|
|
|
45
51
|
|
|
46
52
|
`buildLabel` options:
|
|
47
53
|
|
|
48
|
-
| Option
|
|
49
|
-
|
|
50
|
-
| `widthMm`, `heightMm` | required | Label size. TSPL clips anything drawn past the width.
|
|
51
|
-
| `media`
|
|
52
|
-
| `gapMm`
|
|
53
|
-
| `density`
|
|
54
|
-
| `copies`
|
|
55
|
-
| `direction`
|
|
56
|
-
| `x`, `y`
|
|
54
|
+
| Option | Default | |
|
|
55
|
+
| --------------------- | -------- | ------------------------------------------------------------------ |
|
|
56
|
+
| `widthMm`, `heightMm` | required | Label size. TSPL clips anything drawn past the width. |
|
|
57
|
+
| `media` | `'gap'` | `'gap'`, `'mark'` (black mark, sent as `BLINE`) or `'continuous'`. |
|
|
58
|
+
| `gapMm` | `3` | Gap or mark length. |
|
|
59
|
+
| `density` | `8` | Burn darkness, 0 to 15. |
|
|
60
|
+
| `copies` | `1` | Copies of this label, at no extra cost on the wire. |
|
|
61
|
+
| `direction` | `0` | TSPL `DIRECTION`: `1` turns the label half a turn. |
|
|
62
|
+
| `x`, `y` | `0` | Where the raster's top-left lands, in dots. |
|
|
57
63
|
|
|
58
|
-
`connect` options are `namePrefix` (default `'Y43BT'`), `maxChunk` (240), `creditTimeoutMs` (10000) and `onDisconnect`.
|
|
64
|
+
`connect` options are `namePrefix` (default `'Y43BT'`), `maxChunk` (240), `creditTimeoutMs` (10000), `credits` (`true`; `false` sends without waiting for credits, for printers that never return them) and `onDisconnect`.
|
|
59
65
|
|
|
60
66
|
Any transport with a `send(bytes)` that resolves once the bytes are accepted can drive `printJob`, so a USB `/dev/usb/lpN` writer works as well as Bluetooth.
|
|
61
67
|
|
|
@@ -66,7 +72,7 @@ Any transport with a `send(bytes)` that resolves once the bytes are accepted can
|
|
|
66
72
|
- **Credits are the backpressure.** Every GATT write costs one credit and earns one back, so writes go out exactly as fast as the printer takes them, with no pacing timer to tune.
|
|
67
73
|
- **The write size follows the printer.** It announces its limit (244 bytes) on the flow channel. If the browser's link never negotiated an MTU that big, the first large write fails, its credit is refunded, and the link drops to 20-byte writes for good.
|
|
68
74
|
- **Cancelling stops between labels, never inside one.** A half-sent `BITMAP` leaves the printer reading the next job's commands as image data.
|
|
69
|
-
- **There is no status.**
|
|
75
|
+
- **There is no status.** Neither printer answered any of TSPL's or ESC/POS's status queries on any channel. A credit that never comes back (10 s by default) is the only fault signal, and it fails the send rather than hanging it. With `credits: false` there is no fault signal at all.
|
|
70
76
|
|
|
71
77
|
## Development
|
|
72
78
|
|
package/dist/web-bluetooth.d.ts
CHANGED
|
@@ -15,6 +15,15 @@ export interface ConnectOptions {
|
|
|
15
15
|
maxChunk?: number;
|
|
16
16
|
/** How long to wait for the printer to return a credit before giving up. */
|
|
17
17
|
creditTimeoutMs?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to meter writes by the credits on the flow channel. The Y43BT
|
|
20
|
+
* returns one credit per write; the Core Innovations CTP800BD grants ten
|
|
21
|
+
* on subscribing and never returns another, so metering it stalls on the
|
|
22
|
+
* eleventh write. With `false` the writes go out back to back, which that
|
|
23
|
+
* printer takes without loss, but a jammed or empty printer then no longer
|
|
24
|
+
* fails the send: there is no fault signal left.
|
|
25
|
+
*/
|
|
26
|
+
credits?: boolean;
|
|
18
27
|
/** Fires if the printer drops the GATT link. */
|
|
19
28
|
onDisconnect?: () => void;
|
|
20
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-bluetooth.d.ts","sourceRoot":"","sources":["../src/web-bluetooth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAc3C,MAAM,WAAW,cAAc;IAC9B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED,mFAAmF;AACnF,MAAM,WAAW,aAAc,SAAQ,IAAI;IAC1C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,iDAAiD;IACjD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,UAAU,IAAI,IAAI,CAAC;CACnB;AAED,yEAAyE;AACzE,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED,4EAA4E;AAC5E,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED,6CAA6C;AAC7C,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAED;;;;;;;;;GASG;AACH,wBAAsB,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"web-bluetooth.d.ts","sourceRoot":"","sources":["../src/web-bluetooth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAc3C,MAAM,WAAW,cAAc;IAC9B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED,mFAAmF;AACnF,MAAM,WAAW,aAAc,SAAQ,IAAI;IAC1C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,iDAAiD;IACjD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,UAAU,IAAI,IAAI,CAAC;CACnB;AAED,yEAAyE;AACzE,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED,4EAA4E;AAC5E,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED,6CAA6C;AAC7C,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAED;;;;;;;;;GASG;AACH,wBAAsB,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,CA0ElF"}
|
package/dist/web-bluetooth.js
CHANGED
|
@@ -32,7 +32,7 @@ export function isSupported() {
|
|
|
32
32
|
* Must be called from a user gesture, per the Web Bluetooth spec.
|
|
33
33
|
*/
|
|
34
34
|
export async function connect(options = {}) {
|
|
35
|
-
const { namePrefix = 'Y43BT', maxChunk = 240, creditTimeoutMs = 10000, onDisconnect } = options;
|
|
35
|
+
const { namePrefix = 'Y43BT', maxChunk = 240, creditTimeoutMs = 10000, credits = true, onDisconnect } = options;
|
|
36
36
|
const device = await pickDevice(namePrefix);
|
|
37
37
|
if (!device.gatt)
|
|
38
38
|
throw new Error('device has no GATT server');
|
|
@@ -63,7 +63,8 @@ export async function connect(options = {}) {
|
|
|
63
63
|
async function sendNow(bytes) {
|
|
64
64
|
let at = 0;
|
|
65
65
|
while (at < bytes.length) {
|
|
66
|
-
|
|
66
|
+
if (credits)
|
|
67
|
+
await gate.take(creditTimeoutMs);
|
|
67
68
|
const size = chunk;
|
|
68
69
|
try {
|
|
69
70
|
await writeChar.writeValueWithoutResponse(bytes.slice(at, at + size));
|
|
@@ -71,7 +72,8 @@ export async function connect(options = {}) {
|
|
|
71
72
|
catch (err) {
|
|
72
73
|
// Nothing went out, so the credit is still ours. An oversized write
|
|
73
74
|
// is the one failure worth retrying, smaller; anything else is real.
|
|
74
|
-
|
|
75
|
+
if (credits)
|
|
76
|
+
gate.grant(1);
|
|
75
77
|
if (size <= SAFE_CHUNK)
|
|
76
78
|
throw err;
|
|
77
79
|
chunk = SAFE_CHUNK;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-bluetooth.js","sourceRoot":"","sources":["../src/web-bluetooth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGlD;;;;GAIG;AACH,MAAM,OAAO,GAAG,MAAM,CAAC;AACvB,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,MAAM,SAAS,GAAG,MAAM,CAAC;AAEzB,8EAA8E;AAC9E,MAAM,UAAU,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"web-bluetooth.js","sourceRoot":"","sources":["../src/web-bluetooth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGlD;;;;GAIG;AACH,MAAM,OAAO,GAAG,MAAM,CAAC;AACvB,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,MAAM,SAAS,GAAG,MAAM,CAAC;AAEzB,8EAA8E;AAC9E,MAAM,UAAU,GAAG,EAAE,CAAC;AAuCtB,yEAAyE;AACzE,MAAM,UAAU,YAAY;IAC3B,OAAO,OAAO,SAAS,KAAK,WAAW,IAAI,WAAW,IAAI,SAAS,CAAC;AACrE,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,eAAe;IAC9B,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,eAAe,CAAC;AAChE,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,WAAW;IAC1B,OAAO,YAAY,EAAE,IAAI,eAAe,EAAE,CAAC;AAC5C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,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"version": "0.
|
|
4
|
-
"description": "TSPL raster label printing over BLE for printers that hide TSPL behind a credit-metered GATT channel (Labeer Y43BT and
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "TSPL raster label printing over BLE for printers that hide TSPL behind a credit-metered GATT channel (Labeer Y43BT, Core Innovations CTP800BD, and their white-label siblings). Job builder, 1-bit raster, and a Web Bluetooth transport.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tspl",
|
|
7
7
|
"labeer",
|
|
8
8
|
"y43bt",
|
|
9
|
+
"ctp800bd",
|
|
10
|
+
"core-innovations",
|
|
9
11
|
"thermal-printer",
|
|
10
12
|
"label-printer",
|
|
11
13
|
"shipping-label",
|
package/src/web-bluetooth.ts
CHANGED
|
@@ -29,6 +29,15 @@ export interface ConnectOptions {
|
|
|
29
29
|
maxChunk?: number;
|
|
30
30
|
/** How long to wait for the printer to return a credit before giving up. */
|
|
31
31
|
creditTimeoutMs?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Whether to meter writes by the credits on the flow channel. The Y43BT
|
|
34
|
+
* returns one credit per write; the Core Innovations CTP800BD grants ten
|
|
35
|
+
* on subscribing and never returns another, so metering it stalls on the
|
|
36
|
+
* eleventh write. With `false` the writes go out back to back, which that
|
|
37
|
+
* printer takes without loss, but a jammed or empty printer then no longer
|
|
38
|
+
* fails the send: there is no fault signal left.
|
|
39
|
+
*/
|
|
40
|
+
credits?: boolean;
|
|
32
41
|
/** Fires if the printer drops the GATT link. */
|
|
33
42
|
onDisconnect?: () => void;
|
|
34
43
|
}
|
|
@@ -67,7 +76,13 @@ export function isSupported(): boolean {
|
|
|
67
76
|
* Must be called from a user gesture, per the Web Bluetooth spec.
|
|
68
77
|
*/
|
|
69
78
|
export async function connect(options: ConnectOptions = {}): Promise<BluetoothLink> {
|
|
70
|
-
const {
|
|
79
|
+
const {
|
|
80
|
+
namePrefix = 'Y43BT',
|
|
81
|
+
maxChunk = 240,
|
|
82
|
+
creditTimeoutMs = 10000,
|
|
83
|
+
credits = true,
|
|
84
|
+
onDisconnect
|
|
85
|
+
} = options;
|
|
71
86
|
|
|
72
87
|
const device = await pickDevice(namePrefix);
|
|
73
88
|
if (!device.gatt) throw new Error('device has no GATT server');
|
|
@@ -101,7 +116,7 @@ export async function connect(options: ConnectOptions = {}): Promise<BluetoothLi
|
|
|
101
116
|
async function sendNow(bytes: Uint8Array) {
|
|
102
117
|
let at = 0;
|
|
103
118
|
while (at < bytes.length) {
|
|
104
|
-
await gate.take(creditTimeoutMs);
|
|
119
|
+
if (credits) await gate.take(creditTimeoutMs);
|
|
105
120
|
const size = chunk;
|
|
106
121
|
try {
|
|
107
122
|
await writeChar.writeValueWithoutResponse(
|
|
@@ -110,7 +125,7 @@ export async function connect(options: ConnectOptions = {}): Promise<BluetoothLi
|
|
|
110
125
|
} catch (err) {
|
|
111
126
|
// Nothing went out, so the credit is still ours. An oversized write
|
|
112
127
|
// is the one failure worth retrying, smaller; anything else is real.
|
|
113
|
-
gate.grant(1);
|
|
128
|
+
if (credits) gate.grant(1);
|
|
114
129
|
if (size <= SAFE_CHUNK) throw err;
|
|
115
130
|
chunk = SAFE_CHUNK;
|
|
116
131
|
shrunk = true;
|