|
1 | 1 | import { Transform, TransformCallback, TransformOptions } from 'stream' |
2 | 2 |
|
3 | 3 | export interface SlipEncoderOptions extends TransformOptions { |
| 4 | + /** Custom start byte */ |
4 | 5 | START?: number |
| 6 | + /** Custom start escape byte */ |
| 7 | + ESC_START?: number |
| 8 | + /** custom escape byte */ |
5 | 9 | ESC?: number |
| 10 | + /** custom end byte */ |
6 | 11 | END?: number |
7 | | - ESC_START?: number |
| 12 | + /** custom escape end byte */ |
8 | 13 | ESC_END?: number |
| 14 | + /** custom escape escape byte */ |
9 | 15 | ESC_ESC?: number |
| 16 | + /** Adds an END character at the beginning of each packet per the Bluetooth Core Specification 4.0, Volume 4, Part D, Chapter 3 "SLIP Layer" and allowed by RFC 1055 */ |
10 | 17 | bluetoothQuirk?: boolean |
11 | 18 | } |
12 | 19 |
|
13 | 20 | /** |
14 | | -* A transform stream that emits SLIP-encoded data for each incoming packet. |
15 | | -* @extends Transform |
16 | | -* @summary Runs in O(n) time, adding a 0xC0 character at the end of each |
17 | | -* received packet and escaping characters, according to RFC 1055. Adds another |
18 | | -* 0xC0 character at the beginning if the `bluetoothQuirk` option is truthy (as |
19 | | -* per the Bluetooth Core Specification 4.0, Volume 4, Part D, Chapter 3 "SLIP Layer"). |
20 | | -* Optionally, custom slip escape and delimiters can be provided. |
21 | | -* @example |
22 | | -// Read lines from a text file, then SLIP-encode each and send them to a serial port |
23 | | -const SerialPort = require('serialport') |
24 | | -const { SlipEncoder } = require('@serialport/parser-slip-encoder') |
25 | | -const Readline = require('parser-readline') |
26 | | -const fileReader = require('fs').createReadStream('/tmp/some-file.txt'); |
27 | | -const port = new SerialPort('/dev/tty-usbserial1') |
28 | | -const lineParser = fileReader.pipe(new Readline({ delimiter: '\r\n' })); |
29 | | -const encoder = fileReader.pipe(new SlipEncoder({ bluetoothQuirk: false })); |
30 | | -encoder.pipe(port); |
31 | | -*/ |
| 21 | + * A transform stream that emits SLIP-encoded data for each incoming packet. |
| 22 | + * |
| 23 | + * Runs in O(n) time, adding a 0xC0 character at the end of each |
| 24 | + * received packet and escaping characters, according to RFC 1055. |
| 25 | + */ |
32 | 26 | export class SlipEncoder extends Transform { |
33 | 27 | opts: { |
34 | 28 | START: number | undefined |
|
0 commit comments