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

feature: send heartbeat pgn 126993 for socketcan devices #282

Merged
merged 1 commit into from
Aug 15, 2024
Merged
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
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
Loading