@canboat/canboatjs 1.26.0 → 1.26.2

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 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
- this.channel.stop()
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
- delete this.channel
149
- this.setProviderError('Stopped, Retrying...')
150
- if ( this.options.app ) {
151
- console.error('socketcan stopped, retrying...')
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.stop()
335
+ let channel = this.channel
336
+ delete this.channel
337
+ channel.stop()
333
338
  }
334
339
  if ( this.noDataInterval ) {
335
340
  clearInterval(this.noDataInterval)
package/lib/fromPgn.js CHANGED
@@ -488,11 +488,30 @@ class Parser extends EventEmitter {
488
488
 
489
489
  }
490
490
 
491
- function getField(pgn, index) {
491
+ function getField(pgn, index, data) {
492
492
  var pgnList = pgns[pgn]
493
493
  if ( pgnList ) {
494
494
  var pgn = pgnList[0]
495
495
 
496
+ if ( pgnList.length > 1 ) {
497
+ pgn.Fields.forEach((field, idx) => {
498
+ var hasMatch = !_.isUndefined(field.Match)
499
+ if ( hasMatch && data.fields.list.length > 0 ) {
500
+ let param = data.fields.list.find(f => f.Parameter === idx+1)
501
+
502
+ if ( param ) {
503
+ pgnList = pgnList.filter(f => f.Fields[idx].Match == param.Value)
504
+ if ( pgnList.length == 0 ) {
505
+ throw new Error('unable to read: ' + JSON.stringify(data))
506
+ return
507
+ } else {
508
+ pgn = pgnList[0]
509
+ }
510
+ }
511
+ }
512
+ })
513
+ }
514
+
496
515
  if ( index >= 0 && index < pgn.Fields.length ) {
497
516
  return pgn.Fields[index]
498
517
  }
@@ -719,13 +738,13 @@ function readVariableLengthField(options, pgn, field, bs) {
719
738
  * length and thus that the field number is exactly one byte earlier.
720
739
  */
721
740
 
722
- var refField = getField(pgn.fields.PGN, bs.view.buffer[bs.byteIndex-1]-1)
741
+ var refField = getField(pgn.fields.PGN, bs.view.buffer[bs.byteIndex-1]-1, pgn)
723
742
 
724
743
  if ( refField ) {
725
744
  var bits = (refField.BitLength + 7) & ~7; // Round # of bits in field refField up to complete bytes: 1->8, 7->8, 8->8 etc.
726
745
  let res = readField(options, false, pgn, refField, bs)
727
746
 
728
- if ( bits > field.BitLength ) {
747
+ if ( bits > refField.BitLength ) {
729
748
  bs.readBits(bits - refField.BitLength, false)
730
749
  }
731
750
 
package/lib/stringMsg.js CHANGED
@@ -60,7 +60,7 @@ exports.encodeActisense = ({
60
60
  ].join(','))
61
61
 
62
62
  exports.toActisenseSerialFormat = (pgn, data, dst=255, src=0) => exports.encodeActisense({
63
- pgn, data, dst, src,
63
+ pgn, data, dst, src, prio
64
64
  })
65
65
 
66
66
  // A764027.880 05FF7 1EF00 E59861060202FFFFFFFF03030000FFFFFFFFFFFFFFFFFFFF0000FFFFFF7FFFFFFF7FFFFFFF7F0000FF7F
package/lib/toPgn.js CHANGED
@@ -259,7 +259,7 @@ function writeField(bs, pgn_number, field, data, value, bitLength) {
259
259
  }
260
260
 
261
261
  function writeVariableLengthField(bs, pgn_number, pgn, field, value) {
262
- var refField = getField(pgn.PGN, bs.view.buffer[bs.byteIndex-1]-1)
262
+ var refField = getField(pgn.PGN, bs.view.buffer[bs.byteIndex-1]-1, pgn)
263
263
 
264
264
  if ( refField ) {
265
265
  var bits = (refField.BitLength + 7) & ~7; // Round # of bits in field refField up to complete bytes: 1->8, 7->8, 8->8 etc.
@@ -292,15 +292,15 @@ function canboat2Buffer(canboatData) {
292
292
  }
293
293
 
294
294
  function pgnToActisenseSerialFormat(pgn) {
295
- return encodeActisense({ pgn: pgn.pgn, data: toPgn(pgn), dst: pgn.dst})
295
+ return encodeActisense({ pgn: pgn.pgn, data: toPgn(pgn), dst: pgn.dst, src: pgn.src, prio: pgn.prio})
296
296
  }
297
297
 
298
298
  function pgnToActisenseN2KAsciiFormat(pgn) {
299
- return encodeActisenseN2KACSII({ pgn: pgn.pgn, data: toPgn(pgn), dst: pgn.dst})
299
+ return encodeActisenseN2KACSII({ pgn: pgn.pgn, data: toPgn(pgn), dst: pgn.dst, src: pgn.src, prio: pgn.prio})
300
300
  }
301
301
 
302
302
  function pgnToN2KActisenseFormat(pgn) {
303
- return encodeN2KActisense({ pgn: pgn.pgn, data: toPgn(pgn), dst: pgn.dst})
303
+ return encodeN2KActisense({ pgn: pgn.pgn, data: toPgn(pgn), dst: pgn.dst, src: pgn.src, prio: pgn.prio})
304
304
  }
305
305
 
306
306
  function toiKonvertSerialFormat(pgn, data, dst=255) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canboat/canboatjs",
3
- "version": "1.26.0",
3
+ "version": "1.26.2",
4
4
  "description": "Native javascript version of canboat",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -80,7 +80,7 @@
80
80
  },
81
81
  "optionalDependencies": {
82
82
  "serialport": "^9.0.7",
83
- "socketcan": "^2.2.2"
83
+ "socketcan": "^4.0.3"
84
84
  },
85
85
  "repository": {
86
86
  "type": "git",