Skip to content

serialpilot/serialpilot-protocols

serialpilot-protocols

Pure protocol codecs for the SerialPilot ecosystem.

CRC kit · COBS · HDLC · Modbus RTU framing — plus matching Transform-stream parsers.

Build OpenSSF Scorecard Node.js TypeScript License


This is the missing middle layer for the SerialPilot org: a small set of pure-function protocol codecs (no I/O, no native deps, Uint8Array-only) plus their Transform-stream parser counterparts. Drivers in serialpilot-drivers and the core serialpilot toolkit consume these instead of re-implementing them.

Because the codec packages have zero Node-only API surface, the same code runs unchanged in browsers / Web Serial.

Packages

Package What it does
@serialpilot/crc CRC-8, CRC-16/Modbus, CRC-16/CCITT, CRC-16/XMODEM, CRC-32, CRC-32C — table-driven, branchless, frozen presets.
@serialpilot/cobs RFC-style Consistent Overhead Byte Stuffing encode/decode.
@serialpilot/parser-cobs Transform stream that emits one decoded payload per 0x00 delimiter.
@serialpilot/hdlc HDLC byte-stuffing framer with optional CRC-16/CCITT-FALSE FCS (PPP, MAVLink, AX.25).
@serialpilot/parser-hdlc Transform stream that emits one unframed payload per 0x7E flag boundary.
@serialpilot/modbus-rtu Modbus RTU frame encode/decode (CRC-16/Modbus). Framing only — pair with @serialpilot/parser-inter-byte-timeout for live streams.

Install

npm install @serialpilot/crc          # zero deps, browser-clean
npm install @serialpilot/cobs         # zero deps, browser-clean
npm install @serialpilot/parser-cobs  # depends on @serialpilot/cobs + node:stream

Quick example

import { crc16Modbus } from '@serialpilot/crc'
import { encode, decode } from '@serialpilot/modbus-rtu'

const frame = encode({ address: 1, fc: 3, pdu: new Uint8Array([0, 0, 0, 10]) })
console.log(decode(frame))
// { address: 1, fc: 3, pdu: Uint8Array(4) [0, 0, 0, 10] }

console.log(crc16Modbus(new TextEncoder().encode('123456789')).toString(16))
// '4b37'  (canonical Modbus check value)

Developing

git clone git@github.com:serialpilot/serialpilot-protocols.git
cd serialpilot-protocols
npm install
npm test

See CONTRIBUTING.md for layout, style, and changeset workflow.

License

MIT — see LICENSE.

About

This is the missing middle layer for the SerialPilot org: a small set of pure-function protocol codecs (no I/O, no native deps, Uint8Array-only) plus their Transform-stream parser counterparts.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors