Skip to content

Commit

Permalink
docs: remove outdated samples, update descirptions
Browse files Browse the repository at this point in the history
  • Loading branch information
reconbot committed Feb 8, 2022
1 parent 7538995 commit 956de7e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 58 deletions.
10 changes: 1 addition & 9 deletions packages/parser-inter-byte-timeout/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ export interface InterByteTimeoutOptions extends TransformOptions {
}

/**
* Emits data if there is a pause between packets for the specified amount of time.
*
* A transform stream that emits data as a buffer after not receiving any bytes for the specified amount of time.
* @example
const SerialPort = require('serialport')
const { InterByteTimeoutParser } = require('@serialport/parser-inter-byte-timeout')
const port = new SerialPort('/dev/tty-usbserial1')
const parser = port.pipe(new InterByteTimeoutParser({interval: 30}))
parser.on('data', console.log) // will emit data if there is a pause between packets greater than 30ms
* A transform stream that buffers data and emits it after not receiving any bytes for the specified amount of time or hitting a max buffer size.
*/

export class InterByteTimeoutParser extends Transform {
Expand Down
6 changes: 3 additions & 3 deletions packages/parser-readline/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { DelimiterParser } from '@serialport/parser-delimiter'
import { TransformOptions } from 'stream'

export interface ReadlineOptions extends TransformOptions {
/** defaults to false */
includeDelimiter?: boolean
/** defaults to \n */
/** delimiter to use defaults to \n */
delimiter?: string | Buffer | number[]
/** include the delimiter at the end of the packet defaults to false */
includeDelimiter?: boolean
/** Defaults to utf8 */
encoding?: BufferEncoding
}
Expand Down
8 changes: 1 addition & 7 deletions packages/parser-ready/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { Transform, TransformCallback, TransformOptions } from 'stream'

export interface ReadyParserOptions extends TransformOptions {
/** delimiter to use to detect the input is ready */
delimiter: string | Buffer | number[]
}

/**
* A transform stream that waits for a sequence of "ready" bytes before emitting a ready event and emitting data events
*
* To use the `Ready` parser provide a byte start sequence. After the bytes have been received a ready event is fired and data events are passed through.
* @example
const SerialPort = require('serialport')
const { ReadyParser } = require('@serialport/parser-ready')
const port = new SerialPort('/dev/tty-usbserial1')
const parser = port.pipe(new ReadyParser({ delimiter: 'READY' }))
parser.on('ready', () => console.log('the ready byte sequence has been received'))
parser.on('data', console.log) // all data after READY is received
*/
export class ReadyParser extends Transform {
delimiter: Buffer
Expand Down
10 changes: 3 additions & 7 deletions packages/parser-regex/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { Transform, TransformCallback, TransformOptions } from 'stream'

export interface RegexParserOptions extends TransformOptions {
/** The regular expression to use to split incoming text */
regex: RegExp | string | Buffer
/** Defaults to utf8 */
encoding?: BufferEncoding
}

/**
* A transform stream that uses a regular expression to split the incoming text upon.
*
* To use the `Regex` parser provide a regular expression to split the incoming text upon. Data is emitted as string controllable by the `encoding` option (defaults to `utf8`).
*
* @example
const SerialPort = require('serialport')
const Regex = require('@serialport/parser-regex')
const port = new SerialPort('/dev/tty-usbserial1')
const parser = port.pipe(new Regex({ regex: /[\r\n]+/ }))
parser.on('data', console.log)
*/
export class RegexParser extends Transform {
regex: RegExp
Expand Down
25 changes: 12 additions & 13 deletions packages/parser-slip-encoder/lib/decoder.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { Transform, TransformCallback, TransformOptions } from 'stream'

export interface SlipDecoderOptions extends TransformOptions {
/** Custom start byte */
START?: number
/** Custom start escape byte */
ESC_START?: number
/** custom escape byte */
ESC?: number
/** custom end byte */
END?: number
ESC_START?: number
/** custom escape end byte */
ESC_END?: number
/** custom escape escape byte */
ESC_ESC?: number
}

/**
* A transform stream that decodes slip encoded data.
* @extends Transform
* @summary Runs in O(n) time, stripping out slip encoding and emitting decoded data. Optionally,
* custom slip escape and delimiters can be provided.
* @example
// Receive slip encoded data from a serialport and log decoded data
const SerialPort = require('serialport')
const { SlipDecoder } = require('@serialport/parser-slip-encoder')
const port = new SerialPort('/dev/tty-usbserial1')
const parser = port.pipe(new SlipDecoder())
parser.on('data', console.log)
*/
* A transform stream that decodes slip encoded data.
* @extends Transform
*
* Runs in O(n) time, stripping out slip encoding and emitting decoded data. Optionally custom slip escape and delimiters can be provided.
*/
export class SlipDecoder extends Transform {
opts: { START: number | undefined; ESC: number; END: number; ESC_START: number | undefined; ESC_END: number; ESC_ESC: number }
buffer: Buffer
Expand Down
32 changes: 13 additions & 19 deletions packages/parser-slip-encoder/lib/encoder.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
import { Transform, TransformCallback, TransformOptions } from 'stream'

export interface SlipEncoderOptions extends TransformOptions {
/** Custom start byte */
START?: number
/** Custom start escape byte */
ESC_START?: number
/** custom escape byte */
ESC?: number
/** custom end byte */
END?: number
ESC_START?: number
/** custom escape end byte */
ESC_END?: number
/** custom escape escape byte */
ESC_ESC?: number
/** 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 */
bluetoothQuirk?: boolean
}

/**
* A transform stream that emits SLIP-encoded data for each incoming packet.
* @extends Transform
* @summary Runs in O(n) time, adding a 0xC0 character at the end of each
* received packet and escaping characters, according to RFC 1055. Adds another
* 0xC0 character at the beginning if the `bluetoothQuirk` option is truthy (as
* per the Bluetooth Core Specification 4.0, Volume 4, Part D, Chapter 3 "SLIP Layer").
* Optionally, custom slip escape and delimiters can be provided.
* @example
// Read lines from a text file, then SLIP-encode each and send them to a serial port
const SerialPort = require('serialport')
const { SlipEncoder } = require('@serialport/parser-slip-encoder')
const Readline = require('parser-readline')
const fileReader = require('fs').createReadStream('/tmp/some-file.txt');
const port = new SerialPort('/dev/tty-usbserial1')
const lineParser = fileReader.pipe(new Readline({ delimiter: '\r\n' }));
const encoder = fileReader.pipe(new SlipEncoder({ bluetoothQuirk: false }));
encoder.pipe(port);
*/
* A transform stream that emits SLIP-encoded data for each incoming packet.
*
* Runs in O(n) time, adding a 0xC0 character at the end of each
* received packet and escaping characters, according to RFC 1055.
*/
export class SlipEncoder extends Transform {
opts: {
START: number | undefined
Expand Down

0 comments on commit 956de7e

Please sign in to comment.