Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issues with address claims not being handled properly #26

Merged
merged 1 commit into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/canbus.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,21 @@ CanbusStream.prototype.start = function () {

CanbusStream.prototype.sendPGN = function (msg) {
if ( this.candevice ) {
if ( !this.candevice.cansend && (_.isString(msg) || msg.pgn != 59904) ) {
if ( !this.candevice.cansend && (_.isString(msg) || msg.pgn !== 59904) ) {
//we have not completed address claim yet
return
}

debug('sending %j', msg)

let src = msg.pgn === 59904 ? msg.src : this.candevice.address

if ( _.isString(msg) ) {
var split = msg.split(',')
split[3] = this.candevice.address
split[3] = src
msg = split.join(',')
} else {
msg.src = this.candevice.address
msg.src = src
if ( _.isUndefined(msg.prio) ) {
msg.prio = 3
}
Expand Down
11 changes: 8 additions & 3 deletions lib/candevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const addressClaim = {
pgn: 60928,
dst: 255,
"Unique Number": 1263,
"Manufacturer Code": 273, // Made up, not recognized by standard products
"Manufacturer Code": 999,
"Device Function": 130, // PC gateway
"Device Class": 25, // Inter/Intranetwork Device
"Device Instance Lower": 0,
Expand Down Expand Up @@ -58,6 +58,8 @@ class CanDevice extends EventEmitter {
constructor (canbus, options) {
super()

addressClaim["Unique Number"] = Math.floor(Math.random() * Math.floor(2097151));

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

Expand Down Expand Up @@ -112,7 +114,7 @@ class CanDevice extends EventEmitter {
}
}

function sendPGN(device, pgn, src) {
function sendPGN(device, pgn, src, dest) {
pgn.src = src || device.address
debug('Sending PGN %j', pgn)
device.canbus.sendPGN(pgn)
Expand All @@ -126,7 +128,10 @@ function handleISORequest(device, n2kMsg) {
sendProductInformation(device)
break;
case 60928: // ISO address claim request
sendAddressClaim(device)
//sendAddressClaim(device)
let ac = JSON.parse(JSON.stringify(addressClaim))
ac.dst = n2kMsg.src
sendPGN(device, ac)
break;
case 126464:
sendPGNList(device)
Expand Down