Skip to content

Commit

Permalink
feature: use canboatjs version for "Software Version Code" and add su…
Browse files Browse the repository at this point in the history
…pport for 126998 (#270)
  • Loading branch information
sbender9 authored Jun 18, 2024
1 parent ce4bb87 commit af1b006
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lib/candevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]

Expand Down Expand Up @@ -51,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
Expand All @@ -62,14 +71,25 @@ 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 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

Expand Down Expand Up @@ -144,6 +164,9 @@ 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
sendPGN(device, device.addressClaim)
break;
Expand Down Expand Up @@ -292,6 +315,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,
Expand Down

0 comments on commit af1b006

Please sign in to comment.