From f6fc68afc235238e0aa89257ec76ea09e5d8f589 Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Thu, 15 Aug 2024 11:48:42 -0400 Subject: [PATCH] feature: send heartbeat pgn 126993 for socketcan devices --- lib/candevice.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/candevice.js b/lib/candevice.js index e174e20..ca814ca 100644 --- a/lib/candevice.js +++ b/lib/candevice.js @@ -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 ) { @@ -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] ) { @@ -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)