@serialpilot/parser-hdlc
v0.1.0
Published
Transform-stream parser that emits one unframed payload per HDLC 0x7E flag boundary. Wraps @serialpilot/hdlc.
Maintainers
Readme
@serialpilot/parser-hdlc
Transform-stream wrapper around @serialpilot/hdlc. Buffers incoming bytes until the next 0x7E flag, unframes the frame body, and pushes the unframed payload as a single chunk. Handles FCS verification automatically.
Install
npm install @serialpilot/parser-hdlcUse
import { SerialPilot } from 'serialpilot'
import { HdlcParser } from '@serialpilot/parser-hdlc'
const port = new SerialPilot({ path: '/dev/ttyUSB0', baudRate: 115200 })
const frames = port.pipe(new HdlcParser())
frames.on('data', (payload: Buffer) => {
// one HDLC payload, FCS already verified
})Options
new HdlcParser({ fcs: 'crc16-ccitt' }) // default
new HdlcParser({ fcs: 'none' }) // raw byte-stuffing only
new HdlcParser({ strict: true }) // emit 'error' on bad frames
new HdlcParser({ strict: false }) // (default) drop bad framesIn strict mode an HdlcError (code 'FCS_MISMATCH', 'INVALID_ESCAPE', or 'TRUNCATED') is emitted via the stream's 'error' event. In non-strict mode the bad frame is silently dropped and parsing resumes at the next 0x7E boundary — the typical choice for noisy radio links.
License
MIT.
