Git Product home page Git Product logo

ais-decoder's Introduction

AIS Stream Decoder

AIS/NMEA decoder with native stream interface for Node.js.

NPM Version

Installation

This is a Node.js module available through the npm registry.

Installation is done using the npm install command:

$ npm install ais-stream-decoder

Features

  • Currently supports message types 1,2,3,4,5,18,24 (more to come)
  • Handles multi-part messages out of the box
  • Streaming API implemented as a Node.js transform stream
  • Returns nicely formatted JSON messages
  • Written in TypeScript

Usage

Decode a single line of data:

import AisDecoder from 'ais-stream-decoder';

const aisDecoder = new AisDecoder();
aisDecoder.on('error', err => console.error(err));
aisDecoder.on('data', decodedMessage => console.log(decodedMessage));

const nmea = '!AIVDM,1,1,,B,133i;RPP1DPEbcDMV@1r:Ow:2>`<,0*41';
aisDecoder.write(nmea);

=>

{"type":1,"repeat":0,"mmsi":205278090,"navStatus":0,"rateOfTurn":null,"speedOverGround":8.4,"accuracy":true,"lon":4.73319,"lat":51.725665,"courseOverGround":260.1,"heading":null,"utcSecond":37,"specialManoeuvre":0,"raim":true,"radio":59916}

Handles multi-part messages like a pro:

import AisDecoder from 'ais-stream-decoder';

const aisDecoder = new AisDecoder();
aisDecoder.on('error', err => console.error(err));
aisDecoder.on('data', decodedMessage => console.log(decodedMessage));

const part1 =
  '!AIVDM,2,1,7,A,57lof8`2F5HeT<eC:204e86373:222222222221@8HQC16Ch0:RA7kAD,0*28';
const part2 = '!AIVDM,2,2,7,A,PBp888888888880,2*79';

aisDecoder.write(part1);
aisDecoder.write(part2);

=>

{"type":5,"repeat":0,"mmsi":525200930,"aisVersion":2,"imo":9835915,"callsign":"YCKT2","name":"AKRA 102","typeAndCargo":80,"dimBow":67,"dimStern":33,"dimPort":19,"dimStarboard":1,"epfd":1,"etaMonth":9,"etaDay":7,"etaHour":16,"etaMinute":0,"draught":4.2,"destination":"MERAK            @@@","dte":false}

Use it to read and decode NMEA line-by-line from a file:

import AisDecoder from 'ais-stream-decoder';
import {createReadStream} from 'fs';
import {resolve} from 'path';
import {createInterface} from 'readline';

const aisDecoder = new AisDecoder();
aisDecoder.on('error', err => console.error(err));
aisDecoder.on('data', decodedMessage => console.log(decodedMessage));

const fileStream = createReadStream(
  resolve(__dirname, './examples/messages.txt')
);
const readLine = createInterface(fileStream);
readLine.on('line', line => aisDecoder.write(line));

We all love pipes! ❤

import AisDecoder from 'ais-stream-decoder';
import split from 'split';
import {createReadStream} from 'fs';
import {resolve} from 'path';

const fileStream = createReadStream(
  resolve(__dirname, './examples/messages.txt')
);
const aisDecoder = new AisDecoder({silent: true});

fileStream
  .pipe(split())
  .pipe(aisDecoder)
  .on('data', decodedMessage => {
    console.log(decodedMessage);
  });

License

MIT

ais-decoder's People

Contributors

mjaros avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.