@canboat/canboatjs 1.25.0 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/canbus.js +30 -1
- package/package.json +1 -1
package/lib/canbus.js
CHANGED
|
@@ -118,6 +118,24 @@ function CanbusStream (options) {
|
|
|
118
118
|
})
|
|
119
119
|
} else {
|
|
120
120
|
this.connect()
|
|
121
|
+
|
|
122
|
+
const noDataReceivedTimeout = typeof options.noDataReceivedTimeout !== 'undefined' ? options.noDataReceivedTimeout : -1
|
|
123
|
+
if ( noDataReceivedTimeout > 0 ) {
|
|
124
|
+
this.noDataInterval = setInterval(() => {
|
|
125
|
+
if ( this.channel && this.lastDataReceived && Date.now() - this.lastDataReceived > noDataReceivedTimeout * 1000 ) {
|
|
126
|
+
try {
|
|
127
|
+
this.channel.stop()
|
|
128
|
+
} catch ( error ) {
|
|
129
|
+
}
|
|
130
|
+
delete this.channel
|
|
131
|
+
this.setProviderError('No data received, retrying...')
|
|
132
|
+
if ( this.options.app ) {
|
|
133
|
+
console.error('No data received, retrying...')
|
|
134
|
+
}
|
|
135
|
+
this.connect()
|
|
136
|
+
}
|
|
137
|
+
}, noDataReceivedTimeout * 1000)
|
|
138
|
+
}
|
|
121
139
|
}
|
|
122
140
|
}
|
|
123
141
|
|
|
@@ -127,6 +145,7 @@ CanbusStream.prototype.connect = function() {
|
|
|
127
145
|
var canDevice = this.options.canDevice || 'can0'
|
|
128
146
|
this.channel = this.socketcan.createRawChannelWithOptions(canDevice, { non_block_send: true} );
|
|
129
147
|
this.channel.addListener('onStopped', (msg) => {
|
|
148
|
+
delete this.channel
|
|
130
149
|
this.setProviderError('Stopped, Retrying...')
|
|
131
150
|
if ( this.options.app ) {
|
|
132
151
|
console.error('socketcan stopped, retrying...')
|
|
@@ -139,6 +158,10 @@ CanbusStream.prototype.connect = function() {
|
|
|
139
158
|
this.channel.addListener('onMessage', (msg) => {
|
|
140
159
|
var pgn = parseCanId(msg.id)
|
|
141
160
|
|
|
161
|
+
if ( this.noDataInterval ) {
|
|
162
|
+
this.lastDataReceived = Date.now()
|
|
163
|
+
}
|
|
164
|
+
|
|
142
165
|
if ( that.candevice && that.candevice.cansend && pgn.src == that.candevice.address ) {
|
|
143
166
|
return
|
|
144
167
|
}
|
|
@@ -304,7 +327,13 @@ CanbusStream.prototype.end = function () {
|
|
|
304
327
|
if ( this.socketCanWriter ) {
|
|
305
328
|
debug('end, killing socketcan-writer process')
|
|
306
329
|
this.socketCanWriter.kill()
|
|
307
|
-
|
|
330
|
+
}
|
|
331
|
+
if ( this.channel ) {
|
|
332
|
+
this.channel.stop()
|
|
333
|
+
}
|
|
334
|
+
if ( this.noDataInterval ) {
|
|
335
|
+
clearInterval(this.noDataInterval)
|
|
336
|
+
}
|
|
308
337
|
}
|
|
309
338
|
|
|
310
339
|
|