Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@canboat/canboatjs

canboat6.8kApache-2.03.0.2

Native javascript version of canboat

boat, bus, can, canboat, k, marine, nmea2000, parser, pgn, signalk, signal

readme

Canboatjs

npm version

Pure javascript NMEA 2000 decoder and encoder

Canboatjs is a port of the canboat project (https://github.com/canboat/canboat) to javascript

Contributors

Features

  • Reads directly from CAN bus devices and NMEA 2000 gateways including:
    • Actisense NGT-1 and W2K-1
    • Digital Yacht iKonvert
    • Yacht Devices YDWG-02 and YDEN-02
    • Shipmodul MiniPlex-3-N2K
  • Parses input in canboat analyzer json format
  • Converts and outputs binary N2K format to supported devices

PGN Descriptions

The details about the PGNs recognized by Canboatjs come from the canboat project in pgns.json. If you want to add or update PGN details, please make changes to the pgn.h file in canboat and submit a pull request there. Include sample data and raise an issue here so that I can include your changes in Canboatjs.

Command Line Programs

analyzerjs

This program is similar to the canboat analyzer command-line. It takes input in the actisense serial format and outputs canboat json for mat.

Examples:

  • actisense-serialjs /dev/ttyUSB0 | analyzerjs
  • ikonvert-serial /dev/ttyUSB0 | analyzerjs
  • nc ydgw 1475 | analyzerjs
  • nc w2k-1 6002 | analyzerjs // port should be N2K ACSCII format server on a w2k-1

to-pgn

This program takes input in the canboat json format and outputs actisense serial format.

candumpanalyzer

This program takes input in the candump format and outputs canboat json format

Example: candump can0 | candumpanalyzerjs

candumpjs

Read directly from a socketcan device without the need to install can-utils

Example: candumpjs can0

ydvr-file

This program takes input in the YDVR file format and outputs canboat json format

Example: ydvr-file <file>

Usage

Instalation for command line programs

  • sudo npm install -g @canboat/canboatjs

Installation for a nodejs project

  • npm install @canboat/canboatjs

Create the parser

const FromPgn = require("@canboat/canboatjs").FromPgn;

const parser = new FromPgn();

parser.on("warning", (pgn, warning) => {
  console.log(`[warning] ${pgn.pgn} ${warning}`);
});

Parse input from the Actisense NGT-1 or iKonvert string formats

const json = parser.parseString(
  "2017-03-13T01:00:00.146Z,2,127245,204,255,8,fc,f8,ff,7f,ff,7f,ff,ff"
);
if (json) {
  console.log(JSON.stringify(json));
}

Output:

{
  "description": "Rudder",
  "dst": 255,
  "prio": 2,
  "pgn": 127245,
  "fields": {
    "Reserved1": "62",
    "Direction Order": 0,
    "Instance": 252
  },
  "src": 204,
  "timestamp": "2017-03-13T01:00:00.146Z"
}

Parse input from the YDWG-02

const json = parser.parseString(
  "16:29:27.082 R 09F8017F 50 C3 B8 13 47 D8 2B C6"
);
if (json) {
  console.log(JSON.stringify(json));
}

Output:

{
  "src": 127,
  "pgn": 129025,
  "description": "Position, Rapid Update",
  "timestamp": "2019-04-10T20:29:27.082Z",
  "dst": 255,
  "prio": 2,
  "fields": {
    "Latitude": 33.0875728,
    "Longitude": -97.0205113
  }
}

Parse input from the MiniPlex-3-N2K

const json = parser.parseString("$MXPGN,01F801,2801,C1308AC40C5DE343*19");
if (json) {
  console.log(JSON.stringify(json));
}

Output:

{
  "src": 1,
  "pgn": 129025,
  "description": "Position, Rapid Update",
  "timestamp": "2019-04-10T20:29:27.082Z",
  "dst": 255,
  "prio": 0,
  "fields": {
    "Latitude": 33.0875728,
    "Longitude": -97.0205113
  }
}

Generate Actisense format from canboat json

const pgnToActisenseSerialFormat = require("./index")
  .pgnToActisenseSerialFormat;

const string = pgnToActisenseSerialFormat({
  dst: 255,
  prio: 2,
  pgn: 127245,
  fields: {
    Reserved1: "62",
    "Direction Order": 0,
    Instance: 252,
  },
  src: 204,
});

if (string) {
  console.log(string);
}

Output:

2019-04-10T12:00:32.733Z,2,127245,0,255,8,fc,f8,ff,7f,ff,7f,ff,ff

Generate iKconvert format from canboat json

const pgnToiKonvertSerialFormat = require("./index").pgnToiKonvertSerialFormat;

const string = pgnToiKonvertSerialFormat({
  dst: 255,
  prio: 2,
  pgn: 127245,
  fields: {
    Reserved1: "62",
    "Direction Order": 0,
    Instance: 252,
  },
  src: 204,
});

if (string) {
  console.log(string);
}

Output: !PDGY,127245,255,/Pj/f/9///8=

Generate YDGW-02 format from canboat json

const pgnToYdgwRawFormat = require("./index").pgnToYdgwRawFormat;

const array = pgnToYdgwRawFormat({
  src: 127,
  prio: 3,
  dst: 255,
  pgn: 129029,
  fields: {
    SID: 0,
    Date: "2019.02.17",
    Time: "16:29:28",
    Latitude: 33.08757283333333,
    Longitude: -97.02051133333333,
    Altitude: 148.94,
    "GNSS type": "GPS+GLONASS",
    Method: "GNSS fix",
    Integrity: "No integrity checking",
    "Number of SVs": 0,
    HDOP: 0.5,
    PDOP: 1,
    "Geoidal Separation": -24,
    "Reference Stations": 0,
    list: [{ "Reference Station ID": 15 }],
  },
});

if (array) {
  console.log(JSON.stringify(array, null, 2));
}

Output:

[
  "0df8057f 40 2f 00 18 46 80 d6 62",
  "0df8057f 41 23 40 63 1b cc b8 81",
  "0df8057f 42 97 04 7f c2 7f fc 96",
  "0df8057f 43 23 89 f2 e0 a4 e0 08",
  "0df8057f 44 00 00 00 00 12 fc 00",
  "0df8057f 45 32 00 64 00 a0 f6 ff",
  "0df8057f 46 ff 00 ff 00 ff ff ff"
]

Parse a N2K string into canId parts and create Buffer

Before the conversion of the individual fields happens the string needs to be parsed for attributes like priority, pgn, destination, source (collectively the CanId) and the hex or base64 needs to be converted to a Buffer. Use parseN2kString for this purpose.

const { parseN2kString } = require("@canboat/canboatjs");

const n2kParts1 = parseN2kString(
  "$PCDIN,01F119,00000000,0F,2AAF00D1067414FF*59"
);
const matches1 =
  n2kParts1 ===
  {
    data: Buffer.from("2AAF00D1067414FF", "hex"),
    dst: 255,
    format: "PCDIN",
    prefix: "$PCDIN",
    pgn: 127257,
    prio: 0,
    src: 15,
    timer: 0,
    timestamp: new Date(0),
  };

const n2kParts2 = parseN2kString(
  "16:29:27.082 R 09F8017F 50 C3 B8 13 47 D8 2B C6"
);
const today = new Date().toISOString().split("T")[0];
const matches2 =
  n2kParts2 ===
  {
    canId: 0x09f8017f,
    data: Buffer.from("50C3B81347D82BC6", "hex"),
    direction: "R",
    dst: 255,
    format: "YDRAW",
    pgn: 129025,
    prio: 2,
    src: 127,
    timestamp: new Date(`${today}T16:29:27.082Z`),
  };

const n2kParts3 = parseN2kString(
  "2016-04-09T16:41:09.078Z,3,127257,17,255,8,00,ff,7f,52,00,21,fe,ff"
);
const matches3 =
  n2kParts3 ===
  {
    data: Buffer.from("00ff7f520021feff", "hex"),
    dst: 255,
    len: 8,
    format: "Actisense",
    pgn: 127257,
    prio: 3,
    src: 17,
    timestamp: "2016-04-09T16:41:09.078Z",
  };

changelog

Change Log

v1.5.2 (2019/04/10 12:29 +00:00)

  • #55 fix: make iKonvert and YDGW emit nmea2000OutAvailable (@sbender9)
  • #54 fix: some proprietary pgns not getting parsed with the YDGW (@sbender9)
  • #53 fix: YDGW output broken (@sbender9)

v1.5.1 (2019/04/08 21:25 +00:00)

  • #52 fix: issues with the YDWG (@sbender9)
  • #51 feature: add support NMEA 2000 via MQTT on Venus (@sbender9)

v1.5.0 (2019/04/04 13:53 +00:00)

  • #50 feature: add the ability for to ouput to the YDWG-02 (@jncarter123)

v1.4.0 (2019/03/19 17:34 +00:00)

  • #48 feature: add callback interface to parse (@tkurki)

v1.3.1 (2019/03/04 14:49 +00:00)

  • #47 fix: YDWG date parse error (@jncarter123)

v1.3.0 (2019/02/26 19:36 +00:00)

  • #45 refactor: pcdin implmentation (@sbender9)
  • #44 refactor: Yacht Devices RAW format code cleanup. #42 (@webmasterkai)
  • #43 feature: add support for Yacht Devices NMEA 2000 Wi-Fi Gateway (@sbender9)
  • #40 fix: Handle offset values (@webmasterkai)
  • #38 style: whitespace (@webmasterkai)
  • #39 chore: Edit git and editor config (@webmasterkai)

v1.2.1 (2018/12/12 21:08 +00:00)

  • #28 feature: add support for Digital Yacht’s iKonvert (@sbender9)
  • #36 chore: make serialport an optional dependency (@tkurki)

v1.1.10 (2018/12/12 19:52 +00:00)

  • #37 fix: new bit-buffer release breaks reading n2k data (@sbender9)

v1.1.9 (2018/11/06 19:57 +00:00)

  • #34 fix: changes in canboat to 130306 and 129029 broke n2k output (@sbender9)

v1.1.8 (2018/11/02 14:33 +00:00)

  • #33 fix: revert timestamp change #31 (@sbender9)

v1.1.7 (2018/10/31 19:24 +00:00)

  • #32 fix: definition for 127501 (Binary Switch Bank Status) was wrong (@sbender9)
  • #31 fix: timestamps from actisense log files not formatted properly (@sbender9)

v1.1.6 (2018/10/21 17:55 +00:00)

  • #30 chore: update pgns.json to include Airmar: Speed Pulse Count (@sbender9)

v1.1.5 (2018/10/14 17:28 +00:00)

  • #27 chore: update to the latest pgn definitions from canboat (@sbender9)
  • #26 fix: issues with address claims not being handled properly (@sbender9)
  • #24 chore: add debugging of toPgn conversion results (@sbender9)

v1.1.4 (2018/09/13 14:05 +00:00)

  • #23 fix: allow input to be in both "fast" and "plain" (@sbender9)

v1.1.3 (2018/09/12 19:17 +00:00)

  • #22 fix: server crashes if logging is turned on with a canbus device (@sbender9)

v1.1.2 (2018/09/06 17:35 +00:00)

  • #20 fix: stops working with invalid/unknown/unrecognized data (@sbender9)

v1.1.1 (2018/08/16 16:08 +00:00)

  • #18 feature: include the actisence device path in the status message (@sbender9)

v1.1.0 (2018/08/15 17:59 +00:00)

  • #17 feature: provide connection status to the server (@sbender9)

v1.0.4 (2018/08/12 14:50 +00:00)

  • #16 fix: bin/candumpanalyzerjs not working because of missing fromPgnStream.js (@sbender9)

v1.0.3 (2018/05/29 19:19 +00:00)

  • #15 fix: actisense input broken when logging is turned on in node server (@sbender9)

v1.0.1 (2018/04/19 20:46 +00:00)

  • #14 fix: timestamp should be in iso format when parsing $PCDIN sentences (@sarfata)
  • #11 README s/inteded/intended (@webmasterkai)

v1.0.0 (2018/04/06 15:02 +00:00)

  • #10 feature: add command line actisense serial reader (@sbender9)

v0.0.12 (2018/04/01 00:55 +00:00)

  • #8 fix: catch and report exceptions when connecting to canbus (@sbender9)
  • #9 fix: Alternator Potential should be signed in pgn 127489 (@sbender9)
  • #7 fix: ignore messages sent by myself (@sbender9)
  • #6 feature: add support for $PCDIN (@sbender9)

v0.0.10 (2018/02/21 22:28 +00:00)

  • #5 feature: add support for "ASCII string starting with length byte" fields (@sbender9)

v0.0.9 (2018/02/05 02:56 +00:00)

  • #4 feature: support latest node server plugin api (@sbender9)

v0.0.6 (2018/02/03 12:49 +00:00)

  • #3 Version 0.0.4 (@sbender9)

v0.0.4 (2018/02/02 23:51 +00:00)

  • #2 feature: use socketcan package for canbus access (@sbender9)

v0.0.3 (2018/02/02 00:46 +00:00)

  • #1 feature: canbus support (@sbender9)