@canboat/canboatjs 1.27.2 → 1.28.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/bin/candumpjs +18 -1
- package/lib/canbus.js +1 -1
- package/lib/fromPgn.js +21 -7
- package/package.json +1 -1
package/bin/candumpjs
CHANGED
|
@@ -67,8 +67,25 @@ channel.addListener('onMessage', (msg) => {
|
|
|
67
67
|
var pgn = parseCanId(msg.id)
|
|
68
68
|
|
|
69
69
|
pgn.timestamp = new Date().toISOString()
|
|
70
|
+
|
|
71
|
+
let sourceString = binToActisense(pgn, msg.data, msg.data.length)
|
|
70
72
|
|
|
71
|
-
parser.parse({ pgn, length: msg.data.length, data: msg.data })
|
|
73
|
+
parser.parse({ pgn, length: msg.data.length, data: msg.data, sourceString })
|
|
72
74
|
})
|
|
73
75
|
|
|
74
76
|
channel.start()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
function binToActisense(pgn, data, length) {
|
|
80
|
+
return (
|
|
81
|
+
pgn.timestamp +
|
|
82
|
+
`,${pgn.prio},${pgn.pgn},${pgn.src},${pgn.dst},${length},` +
|
|
83
|
+
new Uint32Array(data)
|
|
84
|
+
.reduce(function(acc, i) {
|
|
85
|
+
acc.push(i.toString(16));
|
|
86
|
+
return acc;
|
|
87
|
+
}, [])
|
|
88
|
+
.map(x => (x.length === 1 ? "0" + x : x))
|
|
89
|
+
.join(",")
|
|
90
|
+
);
|
|
91
|
+
}
|
package/lib/canbus.js
CHANGED
|
@@ -318,7 +318,7 @@ function readLine(that, line) {
|
|
|
318
318
|
|
|
319
319
|
pgn.timestamp = new Date().toISOString()
|
|
320
320
|
|
|
321
|
-
that.push({ pgn: pgn, length: len, data })
|
|
321
|
+
that.push({ pgn: pgn, length: len, data, sourceString: line })
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
CanbusStream.prototype._transform = function (chunk, encoding, done) {
|
package/lib/fromPgn.js
CHANGED
|
@@ -40,6 +40,7 @@ const maxInt64 = new Int64LE(0x7fffffff, 0xffffffff)
|
|
|
40
40
|
|
|
41
41
|
const FORMAT_PLAIN = 0
|
|
42
42
|
const FORMAT_COALESCED = 1
|
|
43
|
+
const RES_BINARY = 'Binary data'
|
|
43
44
|
|
|
44
45
|
const FASTPACKET_INDEX = 0
|
|
45
46
|
const FASTPACKET_SIZE = 1
|
|
@@ -299,11 +300,11 @@ class Parser extends EventEmitter {
|
|
|
299
300
|
} else if ( _.isBuffer(data) ) {
|
|
300
301
|
return this.parseBuffer(data, cb)
|
|
301
302
|
} else {
|
|
302
|
-
return this.parsePgnData(data.pgn, data.length, data.data, data.coalesced === true)
|
|
303
|
+
return this.parsePgnData(data.pgn, data.length, data.data, data.coalesced === true, cb, data.sourceString)
|
|
303
304
|
}
|
|
304
305
|
}
|
|
305
306
|
|
|
306
|
-
parsePgnData(pgn, length, data, coalesced, cb) {
|
|
307
|
+
parsePgnData(pgn, length, data, coalesced, cb, sourceString) {
|
|
307
308
|
try
|
|
308
309
|
{
|
|
309
310
|
var buffer = data
|
|
@@ -317,7 +318,7 @@ class Parser extends EventEmitter {
|
|
|
317
318
|
|
|
318
319
|
var bv = new BitView(buffer);
|
|
319
320
|
var bs = new BitStream(bv)
|
|
320
|
-
const res = this._parse(pgn, bs, length, coalesced, cb);
|
|
321
|
+
const res = this._parse(pgn, bs, length, coalesced, cb, sourceString);
|
|
321
322
|
if ( res ) {
|
|
322
323
|
debug('parsed pgn %j', pgn)
|
|
323
324
|
}
|
|
@@ -568,7 +569,7 @@ function readField(options, runPostProcessor, pgn, field, bs) {
|
|
|
568
569
|
if ( reader ) {
|
|
569
570
|
value = reader(pgn, field, bs)
|
|
570
571
|
} else {
|
|
571
|
-
if ( bs.bitsLeft < field.BitLength ) {
|
|
572
|
+
if ( field.Type !== RES_BINARY && bs.bitsLeft < field.BitLength ) {
|
|
572
573
|
//no more data
|
|
573
574
|
bs.readBits(bs.bitsLeft, false)
|
|
574
575
|
return
|
|
@@ -697,12 +698,25 @@ function readValue(options, pgn, field, bs, bitLength) {
|
|
|
697
698
|
} else {
|
|
698
699
|
value = x === 0xffffffff && y == 0xffffffff ? null : new Uint64LE(y,x)
|
|
699
700
|
}
|
|
700
|
-
} else {
|
|
701
|
+
} else if ( bitLength <= 64 ) {
|
|
701
702
|
value = bs.readBits(bitLength, field.Signed)
|
|
702
703
|
if ( bitLength > 1 && isMax(bitLength, value, field.Signed) ) {
|
|
703
704
|
value = null
|
|
704
705
|
}
|
|
705
|
-
|
|
706
|
+
} else {
|
|
707
|
+
if ( bs.bitsLeft < field.BitLength ) {
|
|
708
|
+
bitLength = bs.bitsLeft
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
value = bs.readArrayBuffer(bitLength/8, field.Signed)
|
|
712
|
+
value = new Uint32Array(value)
|
|
713
|
+
.reduce(function(acc, i) {
|
|
714
|
+
acc.push(i.toString(16));
|
|
715
|
+
return acc;
|
|
716
|
+
}, [])
|
|
717
|
+
.map(x => (x.length === 1 ? "0" + x : x))
|
|
718
|
+
.join(" ")
|
|
719
|
+
return value
|
|
706
720
|
}
|
|
707
721
|
|
|
708
722
|
if ( value != null && typeof value !== 'undefined' && typeof value !== 'number' ) {
|
|
@@ -911,7 +925,7 @@ fieldTypePostProcessors['Pressure'] = (field, value) => {
|
|
|
911
925
|
return value
|
|
912
926
|
}
|
|
913
927
|
|
|
914
|
-
fieldTypePostProcessors[
|
|
928
|
+
fieldTypePostProcessors[RES_BINARY] = (field, value) => {
|
|
915
929
|
return value.toString()
|
|
916
930
|
}
|
|
917
931
|
|