@canboat/canboatjs 1.26.0 → 1.26.1
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 +16 -11
- package/package.json +1 -1
package/lib/canbus.js
CHANGED
|
@@ -123,11 +123,12 @@ function CanbusStream (options) {
|
|
|
123
123
|
if ( noDataReceivedTimeout > 0 ) {
|
|
124
124
|
this.noDataInterval = setInterval(() => {
|
|
125
125
|
if ( this.channel && this.lastDataReceived && Date.now() - this.lastDataReceived > noDataReceivedTimeout * 1000 ) {
|
|
126
|
+
let channel = this.channel
|
|
127
|
+
delete this.channel
|
|
126
128
|
try {
|
|
127
|
-
|
|
129
|
+
channel.stop()
|
|
128
130
|
} catch ( error ) {
|
|
129
131
|
}
|
|
130
|
-
delete this.channel
|
|
131
132
|
this.setProviderError('No data received, retrying...')
|
|
132
133
|
if ( this.options.app ) {
|
|
133
134
|
console.error('No data received, retrying...')
|
|
@@ -145,15 +146,17 @@ CanbusStream.prototype.connect = function() {
|
|
|
145
146
|
var canDevice = this.options.canDevice || 'can0'
|
|
146
147
|
this.channel = this.socketcan.createRawChannelWithOptions(canDevice, { non_block_send: true} );
|
|
147
148
|
this.channel.addListener('onStopped', (msg) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
if ( this.channel ) { // stoped by us?
|
|
150
|
+
delete this.channel
|
|
151
|
+
this.setProviderError('Stopped, Retrying...')
|
|
152
|
+
if ( this.options.app ) {
|
|
153
|
+
console.error('socketcan stopped, retrying...')
|
|
154
|
+
}
|
|
155
|
+
setTimeout(() => {
|
|
156
|
+
this.setProviderError('Reconnecting...')
|
|
157
|
+
this.connect()
|
|
158
|
+
}, 2000)
|
|
152
159
|
}
|
|
153
|
-
setTimeout(() => {
|
|
154
|
-
this.setProviderError('Reconnecting...')
|
|
155
|
-
this.connect()
|
|
156
|
-
}, 2000)
|
|
157
160
|
})
|
|
158
161
|
this.channel.addListener('onMessage', (msg) => {
|
|
159
162
|
var pgn = parseCanId(msg.id)
|
|
@@ -329,7 +332,9 @@ CanbusStream.prototype.end = function () {
|
|
|
329
332
|
this.socketCanWriter.kill()
|
|
330
333
|
}
|
|
331
334
|
if ( this.channel ) {
|
|
332
|
-
this.channel
|
|
335
|
+
let channel = this.channel
|
|
336
|
+
delete this.channel
|
|
337
|
+
channel.stop()
|
|
333
338
|
}
|
|
334
339
|
if ( this.noDataInterval ) {
|
|
335
340
|
clearInterval(this.noDataInterval)
|