Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: canboat/canboatjs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.5.7
Choose a base ref
...
head repository: canboat/canboatjs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on May 28, 2024

  1. Copy the full SHA
    e8ef256 View commit details
  2. Copy the full SHA
    d585bb7 View commit details
  3. 2.6.0

    sbender9 committed May 28, 2024
    Copy the full SHA
    5ac7ec8 View commit details
  4. Copy the full SHA
    aa5ff47 View commit details
  5. Copy the full SHA
    ce4bb87 View commit details

Commits on Jun 18, 2024

  1. Copy the full SHA
    af1b006 View commit details
  2. Copy the full SHA
    6bc159b View commit details
  3. Copy the full SHA
    edae1e1 View commit details

Commits on Jul 25, 2024

  1. Copy the full SHA
    549edd0 View commit details
  2. Copy the full SHA
    6dfb34f View commit details
  3. Copy the full SHA
    2166890 View commit details
  4. 2.7.0

    sbender9 committed Jul 25, 2024
    Copy the full SHA
    86e7c32 View commit details

Commits on Aug 2, 2024

  1. Copy the full SHA
    2c4e2b0 View commit details
  2. Copy the full SHA
    c69c8e3 View commit details
  3. 2.8.0

    sbender9 committed Aug 2, 2024
    Copy the full SHA
    a9d1f92 View commit details

Commits on Aug 7, 2024

  1. Copy the full SHA
    b077817 View commit details
  2. 2.8.1

    sbender9 committed Aug 7, 2024
    Copy the full SHA
    bab9b13 View commit details
  3. Copy the full SHA
    f64173b View commit details
  4. 2.8.2

    sbender9 committed Aug 7, 2024
    Copy the full SHA
    112ebfe View commit details

Commits on Aug 15, 2024

  1. Copy the full SHA
    775291d View commit details
  2. 2.9.0

    sbender9 committed Aug 15, 2024
    Copy the full SHA
    fc208a8 View commit details

Commits on Aug 16, 2024

  1. Copy the full SHA
    7a2b43d View commit details
  2. 2.10.0

    sbender9 committed Aug 16, 2024
    Copy the full SHA
    380aceb View commit details

Commits on Dec 27, 2024

  1. Copy the full SHA
    c52e9dc View commit details
Showing with 185 additions and 39 deletions.
  1. +4 −1 bin/analyzerjs
  2. +6 −1 lib/canbus.js
  3. +57 −7 lib/candevice.js
  4. +5 −1 lib/fromPgn.js
  5. +2 −0 lib/ikonvert.js
  6. +2 −0 lib/serial.js
  7. +31 −9 lib/stringMsg.js
  8. +27 −1 lib/stringMsg.test.js
  9. +0 −13 lib/toPgn.js
  10. +2 −0 lib/w2k01.js
  11. +2 −0 lib/ydgw02.js
  12. +2 −2 package.json
  13. +41 −0 test/mxpgn.js
  14. +2 −2 test/pgns/129810.js
  15. +2 −2 test/pgns/65379.js
5 changes: 4 additions & 1 deletion bin/analyzerjs
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@

const argv = require('minimist')(process.argv.slice(2), {
alias: { h: 'help' },
boolean: ['n']
boolean: ['n'],
boolean: ['r']
})

if ( argv['help'] ) {
@@ -11,13 +12,15 @@ if ( argv['help'] ) {
Options:
-c don't check for invalid values
-n output null values
-r parse $MXPGN as little endian
-h, --help output usage information`)
process.exit(1)
}

const Parser = require('../index').FromPgn
var parser = new Parser( {
returnNulls: argv['n'] === true,
littleEndianMXPGN: argv['r'] === true,
checkForInvalidFields: argv['c'] !== true
})

7 changes: 6 additions & 1 deletion lib/canbus.js
Original file line number Diff line number Diff line change
@@ -168,7 +168,8 @@ CanbusStream.prototype.connect = function() {
this.lastDataReceived = Date.now()
}

if ( that.candevice && that.candevice.cansend && pgn.src == that.candevice.address ) {
//always send address claims through
if ( pgn.pgn != 60928 && that.candevice && that.candevice.cansend && pgn.src == that.candevice.address ) {
return
}

@@ -219,6 +220,10 @@ CanbusStream.prototype.sendPGN = function (msg) {

debug('sending %j', msg)

if ( this.options.app ) {
this.options.app.emit('connectionwrite', { providerId: this.options.providerId })
}

let src = msg.pgn === 59904 || msg.forceSrc ? msg.src : this.candevice.address
if ( _.isString(msg) ) {
var split = msg.split(',')
64 changes: 57 additions & 7 deletions lib/candevice.js
Original file line number Diff line number Diff line change
@@ -20,6 +20,13 @@ const _ = require('lodash')
const Uint64LE = require('int64-buffer').Uint64LE
const { defaultTransmitPGNs, getIndustryCode, getManufacturerCode, getDeviceClassCode } = require('./codes')
const { toPgn } = require('./toPgn')
let packageJson

try
{
packageJson = require('../' + 'package.json')
} catch (ex) {
}

const deviceTransmitPGNs = [ 60928, 59904, 126996, 126464 ]

@@ -31,10 +38,12 @@ class CanDevice extends EventEmitter {
this.addressClaim = options.addressClaim
this.addressClaim.pgn = 60928
this.addressClaim.dst = 255
this.addressClaim.prio = 6
} else {
this.addressClaim = {
pgn: 60928,
dst: 255,
prio:6,
"Unique Number": 1263,
"Manufacturer Code": 999,
"Device Function": 130, // PC gateway
@@ -49,6 +58,8 @@ class CanDevice extends EventEmitter {
this.addressClaim["Unique Number"] = options.uniqueNumber || Math.floor(Math.random() * Math.floor(2097151))
}

let version = packageJson ? packageJson.version : "1.0"

if ( options.productInfo ) {
this.productInfo = options.productInfo
this.productInfo.pgn = 126996
@@ -60,20 +71,32 @@ class CanDevice extends EventEmitter {
"NMEA 2000 Version": 1300,
"Product Code": 667, // Just made up..
"Model ID": "Signal K",
"Software Version Code": "1.0",
"Model Version": "canbusjs",
"Model Serial Code": "123456",
"Model Version": "canboatjs",
"Model Serial Code": options.uniqueNumber ? options.uniqueNumber.toString() : "000001",
"Certification Level": 0,
"Load Equivalency": 1
}
}

this.productInfo["Software Version Code"] = version

if ( options.serverVersion && options.serverUrl ) {
this.configurationInfo = {
pgn: 126998,
dst: 255,
"Installation Description #1": options.serverUrl,
"Installation Description #2": options.serverDescription,
"Manufacturer Information": options.serverVersion
}
}

this.canbus = canbus
this.options = _.isUndefined(options) ? {} : options

this.address = _.isUndefined(options.preferredAddress) ? 100 : options.preferredAddress
this.cansend = false
this.foundConflict = false
this.heartbeatCounter = 0
this.devices = {}

if ( !options.disableDefaultTransmitPGNs ) {
@@ -142,11 +165,11 @@ function handleISORequest(device, n2kMsg) {
case 126996: // Product Information request
sendProductInformation(device)
break;
case 126998: // Config Information request
sendConfigInformation(device)
break;
case 60928: // ISO address claim request
//sendAddressClaim(device)
let ac = JSON.parse(JSON.stringify(device.addressClaim))
ac.dst = n2kMsg.src
sendPGN(device, ac)
sendPGN(device, device.addressClaim)
break;
case 126464:
sendPGNList(device)
@@ -249,6 +272,23 @@ function handleProductInformation(device, n2kMsg) {
device.devices[n2kMsg.src].productInformation = n2kMsg
}

function sendHeartbeat(device)
{
device.heartbeatCounter = device.heartbeatCounter + 1
if ( device.heartbeatCounter > 252 )
{
device.heartbeatCounter = 0
}
sendPGN(device,{
pgn: 126993,
dst: 255,
prio:7,
"Data transmit offset": "00:01:00",
"Sequence Counter": device.heartbeatCounter,
"Controller 1 State":"Error Active"
})
}


function sendAddressClaim(device) {
if ( device.devices[device.address] ) {
@@ -265,6 +305,9 @@ function sendAddressClaim(device) {
device.options.app.emit('nmea2000OutAvailable')
}
sendISORequest(device, 126996)
device.heartbeatInterval = setInterval(() => {
sendHeartbeat(device)
}, 60*1000)
/*
_.keys(device.devices).forEach((address) => {
sendISORequest(device, 126996, undefined, address)
@@ -293,6 +336,13 @@ function sendProductInformation(device) {
sendPGN(device, device.productInfo)
}

function sendConfigInformation(device) {
if ( device.configurationInfo ) {
debug("Sending config info..")
sendPGN(device, device.configurationInfo)
}
}

function sendNAKAcknowledgement(device, src, requestedPGN) {
const acknowledgement = {
pgn: 59392,
6 changes: 5 additions & 1 deletion lib/fromPgn.js
Original file line number Diff line number Diff line change
@@ -233,6 +233,10 @@ class Parser extends EventEmitter {
} else {
const ts = _.get(pgn, 'timestamp', new Date())
pgn.timestamp = _.isDate(ts) ? ts.toISOString() : ts
if ( !_.isUndefined(value) && (value != null ||
this.options.returnNulls) ) {
pgn.fields[field.Name] = value
}
this.emit('pgn', pgn)
cb && cb(undefined, pgn)
return pgn
@@ -454,7 +458,7 @@ class Parser extends EventEmitter {

parseString (pgn_data, cb) {
try {
const { coalesced, data, error, len, ...pgn } = parseN2kString(pgn_data)
const { coalesced, data, error, len, ...pgn } = parseN2kString(pgn_data, this.options)
if (error) {
cb && cb(error)
this.emit('error', pgn, error)
2 changes: 2 additions & 0 deletions lib/ikonvert.js
Original file line number Diff line number Diff line change
@@ -75,9 +75,11 @@ function iKonvertStream (options) {
} else {
that.sendPGN(msg)
}
options.app.emit('connectionwrite', { providerId: options.providerId })
})
options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
that.sendPGN(msg)
options.app.emit('connectionwrite', { providerId: options.providerId })
})

this.isSetup = false
2 changes: 2 additions & 0 deletions lib/serial.js
Original file line number Diff line number Diff line change
@@ -148,6 +148,7 @@ SerialStream.prototype.start = function () {
buf = composeMessage(N2K_MSG_SEND, buf, buf.length)
debugOut(buf)
that.serial.write(buf)
that.options.app.emit('connectionwrite', { providerId: that.options.providerId })
}

function writeObject(msg) {
@@ -158,6 +159,7 @@ SerialStream.prototype.start = function () {
buf = composeMessage(N2K_MSG_SEND, buf, buf.length)
debugOut(buf)
that.serial.write(buf)
that.options.app.emit('connectionwrite', { providerId: that.options.providerId })
}

this.options.app.on(this.options.outEevent || 'nmea2000out', msg => {
40 changes: 31 additions & 9 deletions lib/stringMsg.js
Original file line number Diff line number Diff line change
@@ -19,13 +19,17 @@ const {
* @param {Object} [rest={}] Anything else to be added like len, timestamp, direction.
* @return {Object} All canId fields with format and data props added.
*/
function buildMsg(canIdInfo, format, data, rest = {}) {
return {
...canIdInfo,
function buildMsg(_canIdInfo, format, data, rest = {}) {
const canIdInfo = Object.assign({}, _canIdInfo, {
format,
data,
...rest,
data
})
for (const property in rest) {
if (canIdInfo[property] === undefined) {
canIdInfo[property] = rest[property]
}
}
return canIdInfo
}
function buildErrMsg(msg, input) {
if (input && isString(input)) return `${msg} - ${input}`
@@ -41,7 +45,8 @@ function toPaddedHexString(num, len) {
}

// 2016-02-28T19:57:02.364Z,2,127250,7,255,8,ff,10,3b,ff,7f,ce,f5,fc
exports.isActisense = input => input.charAt(10) === 'T' && input.charAt(23) === 'Z'
exports.isActisense = input => (input.charAt(10) === 'T' && input.charAt(23) === 'Z') || (input.charAt(10) === '-' && input.charAt(23) === ',')

exports.parseActisense = (input) => {
const [ timestamp, prio, pgn, src, dst, len, ...data ] = input.split(',')
return buildMsg(
@@ -151,12 +156,22 @@ exports.encodePCDIN = ({ prefix = '$PCDIN', pgn, data, dst = 255}) => {
return sentence + compute0183Checksum(sentence)
}

const changeEndianness = (string) => {
const result = [];
let len = string.length - 2;
while (len >= 0) {
result.push(string.substr(len, 2));
len -= 2;
}
return result.join('');
}

// $MXPGN,01F801,2801,C1308AC40C5DE343*19
exports.isMXPGN = (msg) => {
const sentence = get0183Sentence(msg)
return sentence.startsWith('$MXPGN,')
}
exports.parseMXPGN = (input) => {
exports.parseMXPGN = (input, options) => {
const sentence = get0183Sentence(input)
const [ prefix, pgn, attr_word, data ] = sentence.split(',')

@@ -167,11 +182,18 @@ exports.parseMXPGN = (input) => {
const len = parseInt(send_prio_len.substr(4,4), 2);
let src, dst;
send ? dst = addr: src = addr;

let reversed

if ( options && options.littleEndianMXPGN )
reversed = changeEndianness(rmChecksum(data))
else
reversed = data

return buildMsg(
buildCanId(0, parseInt(pgn, 16), 255, parseInt(src, 16)),
'MXPGN',
Buffer.from(rmChecksum(data), 'hex'),
Buffer.from(reversed, 'hex'),
{ coalesced: true, prefix },
)
}
@@ -263,7 +285,7 @@ exports.parseCandump3 = (input) => {
const [ timestamp, bus, canFrame ] = input.split(' ')
const [ canId, data ] = canFrame.split('#')
return buildMsg(
parseCanIdStr(canId), 'candump3', arrBuff(data), { timestamp, bus }
parseCanIdStr(canId), 'candump3', Buffer.from(data, 'hex'), { timestamp, bus }
)
}

28 changes: 27 additions & 1 deletion lib/stringMsg.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {
encodeActisense, encodeYDRAW, parseActisense, parseCandump1, parseCandump2,
parsePCDIN, parsePDGY, parseN2kString, parsePDGYdebug, parseYDRAW, encodeActisenseN2KACSII, parseActisenseN2KASCII
parsePCDIN, parsePDGY, parseN2kString, parsePDGYdebug, parseYDRAW, encodeActisenseN2KACSII, parseActisenseN2KASCII, parseCandump3
} = require('./stringMsg')

/* globals describe test expect */
@@ -61,6 +61,32 @@ describe('parseMultiLineCandump', () => {
})
})

describe('parseMultiLineCandumpV3', () => {
test('multi line messages', () => {
const msgs = [
'(0000000000.352000) vcan0 09F20101#601A00B706670D0B',
'(0000000000.353000) vcan0 09F20101#6186BA042600105F',
'(0000000000.354000) vcan0 09F20101#62090000008F027F',
'(0000000000.355000) vcan0 09F20101#63000000007F7FFF'
]
let res
msgs.forEach((msg) => {
res = parseCandump3(msg)
})
expect(res).toEqual({
bus: "vcan0",
canId: 166854913,
data: Buffer.from('63000000007f7fff', 'hex'),
dst: 255,
format: 'candump3',
src: 1,
pgn: 127489,
prio: 2,
timestamp: '(0000000000.355000)'
})
})
})

describe('parseActisense', () => {
test('basic msg', () => {
const msg = '2016-04-09T16:41:09.078Z,3,127257,17,255,8,00,ff,7f,52,00,21,fe,ff'
13 changes: 0 additions & 13 deletions lib/toPgn.js
Original file line number Diff line number Diff line change
@@ -54,19 +54,6 @@ function toPgn(data) {
const pgn_number = data.pgn
var pgnData = pgnList[0]

if ( pgnList.length > 1 && data['Manufacturer Code'] ) {
pgnData = pgnList.find(pgn => {
let mc = pgn.Fields.find(field => (field.Name === 'Manufacturer Code'))
//console.log(`mc ${JSON.stringify(mc)}`)
return mc && mc.Match && mc.Match == data['Manufacturer Code']
})
if ( !pgnData )
{
debug("no pgn found: " + data.pgn)
return undefined
}
}

var bs = new BitStream(Buffer.alloc(500))

if ( data.fields ) {
2 changes: 2 additions & 0 deletions lib/w2k01.js
Original file line number Diff line number Diff line change
@@ -49,10 +49,12 @@ function W2K01Stream (options, type, outEvent) {
} else {
this.sendPGN(msg)
}
options.app.emit('connectionwrite', { providerId: options.providerId })
})

options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
this.sendPGN(msg)
options.app.emit('connectionwrite', { providerId: options.providerId })
})
}
}
Loading