Skip to content

Commit

Permalink
feature: send heartbeat pgn 126993 for socketcan devices (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 authored Aug 15, 2024
1 parent 112ebfe commit 775291d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/candevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CanDevice extends EventEmitter {
this.address = _.isUndefined(options.preferredAddress) ? 100 : options.preferredAddress
this.cansend = false
this.foundConflict = false
this.heartbeatCounter = 0
this.devices = {}

if ( !options.disableDefaultTransmitPGNs ) {
Expand Down Expand Up @@ -271,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] ) {
Expand All @@ -287,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)
Expand Down

0 comments on commit 775291d

Please sign in to comment.