Canboatjs
Pure javascript NMEA 2000 decoder and encoder
Canboatjs is a port of the canboat project (https://github.com/canboat/canboat) to javascript
Contributors
Canboajs js is built on the backs of a few people whithout whom it would not be possible.
Features
- Read directly from an Actisense NGT-1, canbus devices, Digital Yachts' iKonvert and Yacht Devices YDWG-02
- Supports input in canboat analyzer json format
- Take input in canboat analyzer json format and convert to binary N2K format and output to supported devices
PGN Descriptions
The details about the PGN's 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
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 | candumpanalyzer
Use in your own software
Installation
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
}
}
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 pgnToYdwgRawFormat = require('./index').pgnToYdwgRawFormat
const array = pgnToYdwgRawFormat({
"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"
]