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

@csllc/j1939

v1.1.2

Published

J1939 transport layer for CANBUS communication

Downloads

32

Readme

Javascript J1939 CANBUS Package

This package implements a J1939 protocol. It is intended to be used on top of a CANBUS interface package (like can-usb-com).

The main purpose of this package is for testing and diagnostic purposes. The implementation is not fully J1939 compliant, does not necessarily implement strict packet timings, and may have missing or broken features.

Quick Start

Getting right to sending and receiving messages, let's set up a simple system. We will assume the actual BUS is 250K bits/seconds, and we are using the can-usb-com package, so we install and set up the bus interface

npm install can-usb-com npm install @csllc/j1939

const Canbus = require('can-usb-com');
const J1939 = require('j1939');

// Create the bus interface
let bus = new Canbus({
    canRate: 250000
});

// Create the J1939 protocol instance
let j1939 = new J1939( bus, {
    // My ID on the network
    address: 0x80
});

// Catch the 'open' event to know when the bus is ready to send and receive
j1939.on('open', (address) => {

  console.log('J1939 ready with address ', address);

  // Print out any received message
  // Of course, in order for this to do anything, you need a device
  // on the bus to send a message to our address (0x80)
  j1939.on('data', function(msg) {
    console.log('Received', msg);
  });

  // Send a message to device #100
  j1939.write({
    pgn: 0xEF00,
    dst: 100,
    priority: 7,
    buf: Buffer.alloc(200).fill(0x55),
  });

});

Examples

Check the example or test folders for more ideas on how to use this module

Methods

write( msg )

Events

address( addressClaimStatus, attemptedSourceAddress) indicates the progress of the address claim procedure. If it is successful, the open event will be emitted.

open( address ) signals that the bus is online, and the address claim procedure has completed.

data signals an incoming PGN, to either the local address or broadcast address

rx signals an incoming non-J1939 message (11-bit id)

close indicates that the bus (and protocol) are shut down

error( err ) indicates an error in either the J1939 processing or detected from the CANBUS interface. The error event is NOT triggered for messages that fail to send or be properly received.

Development

eslint rules are stored in .eslintrc, please lint any changes and update/verify proper unit testing

Unit testing

use npm test to run the unit tests