npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-slip

v0.0.2

Published

RFC 1055 compliant SLIP packet parsing and generation.

Downloads

12

Readme

node-slip

This package parses (and generates) RFC 1055 Serial Line Internet Protocol (SLIP) packets. Used in conjunction with packages like node-serialport, it can be useful to communicate between node programs and old-skool embedded systems that are still using SLIP.

Note: this package is does not support CSLIP (Compressed SLIP.)

Installation

The easiest way to install this package is to use npm:

If you want to check out the source, use the git command:

Usage

Theory of Operation

This package lets you parse and generate SLIP formatted packets. The parser is implemented in a simple stateful object. The user feeds a SLIP octet stream to the parser object. This parser object strips off the leading and trailing END characters (0xC0) and unescapes escape sequences (0xDB 0xDC and 0xDB 0xDD).

When you initialize a parser, you pass it a "receiver" object. When the parser receives a complete packet, it calls the "data" function in the receiver object. If the receiver defines "framing" or "escape" functions, it will call these functions when it encounters framing or escape errors.

The packet generator is a simple static method on the slip package. Pass it a raw node Buffer and the generator will add END characters to the front and back and escape octets that require escaping.

Using the Parser

Start your node program like any other by requiring the package:

Now define a receiver object. This is an instance that optionally defines the functions: data, framing and escape. Here's a very simple example:

Now instantiate a slip parser like so:

And start sending the parser some data:

In theory, this line should emit something like this:

But if you did something like this, you'll see why it's a useful package:

This code fragment will emit this:

Note the parser doesn't emit anything until the whole packet is available. This is useful if (like me) you're using node-serialport to read input from an embedded system over the serial port and that embedded system doesn't always give you complete packets.

Another fun thing that can happen is we get two (or more) SLIP packets in one call to read the serial port. This sometimes happens if your packets are small and you only process serial port input every NNN microseconds. So if you do this:

You'll get this:

And if you get a framing error (like you add stuff between the two middle END bytes, we collect the data and pass it as a parameter to the framing() function. Ergo, doing this:

Will get you this:

Mucking up an escape sequence will cause the escape() function in the receiver to be called. So if you do this:

You get this:

Note: data() and framing() are passed Buffer objects. escape() is only passed a number.

Using the Generator

The generator is much simpler. You simply call the slip.generator() function, passing it a buffer as input. What you get back will be a data buffer with starting and ending END bytes applied and C0 and DB bytes escaped.

This routine:

Will output this: