@canboat/canboatjs 3.0.1 → 3.1.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/.github/workflows/test.yml +2 -2
- package/.github/workflows/test_canboat_changes.yml +91 -0
- package/.husky/pre-commit +4 -0
- package/.mocharc.js +7 -0
- package/.prettierrc.json +5 -0
- package/README.md +2 -7
- package/dist/actisense-serial.d.ts +17 -0
- package/dist/actisense-serial.d.ts.map +1 -0
- package/dist/actisense-serial.js +569 -0
- package/dist/actisense-serial.js.map +1 -0
- package/dist/bin/actisense-file.d.ts +3 -0
- package/dist/bin/actisense-file.d.ts.map +1 -0
- package/dist/bin/actisense-file.js +49 -0
- package/dist/bin/actisense-file.js.map +1 -0
- package/dist/bin/actisense-n2k-tcp.d.ts +3 -0
- package/dist/bin/actisense-n2k-tcp.d.ts.map +1 -0
- package/dist/bin/actisense-n2k-tcp.js +46 -0
- package/dist/bin/actisense-n2k-tcp.js.map +1 -0
- package/dist/bin/actisense-serialjs.d.ts +3 -0
- package/dist/bin/actisense-serialjs.d.ts.map +1 -0
- package/dist/bin/actisense-serialjs.js +51 -0
- package/dist/bin/actisense-serialjs.js.map +1 -0
- package/dist/bin/analyzerjs.d.ts +3 -0
- package/dist/bin/analyzerjs.d.ts.map +1 -0
- package/dist/bin/analyzerjs.js +61 -0
- package/dist/bin/analyzerjs.js.map +1 -0
- package/dist/bin/candumpanalyzerjs.d.ts +3 -0
- package/dist/bin/candumpanalyzerjs.d.ts.map +1 -0
- package/dist/bin/candumpanalyzerjs.js +31 -0
- package/dist/bin/candumpanalyzerjs.js.map +1 -0
- package/dist/bin/candumpjs.d.ts +3 -0
- package/dist/bin/candumpjs.d.ts.map +1 -0
- package/dist/bin/candumpjs.js +73 -0
- package/dist/bin/candumpjs.js.map +1 -0
- package/dist/bin/cansend.d.ts +3 -0
- package/dist/bin/cansend.d.ts.map +1 -0
- package/dist/bin/cansend.js +123 -0
- package/dist/bin/cansend.js.map +1 -0
- package/dist/bin/ikonvert-serial.d.ts +3 -0
- package/dist/bin/ikonvert-serial.d.ts.map +1 -0
- package/dist/bin/ikonvert-serial.js +36 -0
- package/dist/bin/ikonvert-serial.js.map +1 -0
- package/dist/bin/to-pgn.d.ts +3 -0
- package/dist/bin/to-pgn.d.ts.map +1 -0
- package/dist/bin/to-pgn.js +57 -0
- package/dist/bin/to-pgn.js.map +1 -0
- package/dist/canId.d.ts +21 -0
- package/dist/canId.d.ts.map +1 -0
- package/dist/canId.js +66 -0
- package/dist/canId.js.map +1 -0
- package/dist/canId.test.d.ts +2 -0
- package/dist/canId.test.d.ts.map +1 -0
- package/dist/canId.test.js +58 -0
- package/dist/canId.test.js.map +1 -0
- package/dist/canbus.d.ts +17 -0
- package/dist/canbus.d.ts.map +1 -0
- package/dist/canbus.js +261 -0
- package/dist/canbus.js.map +1 -0
- package/dist/candevice.d.ts +23 -0
- package/dist/candevice.d.ts.map +1 -0
- package/dist/candevice.js +38 -0
- package/dist/candevice.js.map +1 -0
- package/dist/codes.d.ts +2 -0
- package/dist/codes.d.ts.map +1 -0
- package/dist/codes.js +24 -0
- package/dist/codes.js.map +1 -0
- package/dist/discovery.d.ts +17 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +119 -0
- package/dist/discovery.js.map +1 -0
- package/dist/fromPgn.d.ts +51 -0
- package/dist/fromPgn.d.ts.map +1 -0
- package/dist/fromPgn.js +989 -0
- package/dist/fromPgn.js.map +1 -0
- package/dist/fromPgnStream.d.ts +17 -0
- package/dist/fromPgnStream.d.ts.map +1 -0
- package/dist/fromPgnStream.js +47 -0
- package/dist/fromPgnStream.js.map +1 -0
- package/dist/ikonvert.d.ts +17 -0
- package/dist/ikonvert.d.ts.map +1 -0
- package/dist/ikonvert.js +224 -0
- package/dist/ikonvert.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/n2k-actisense.d.ts +24 -0
- package/dist/n2k-actisense.d.ts.map +1 -0
- package/dist/n2k-actisense.js +126 -0
- package/dist/n2k-actisense.js.map +1 -0
- package/dist/n2k-actisense.test.d.ts +2 -0
- package/dist/n2k-actisense.test.d.ts.map +1 -0
- package/dist/n2k-actisense.test.js +49 -0
- package/dist/n2k-actisense.test.js.map +1 -0
- package/dist/n2kDevice.d.ts +40 -0
- package/dist/n2kDevice.d.ts.map +1 -0
- package/dist/n2kDevice.js +387 -0
- package/dist/n2kDevice.js.map +1 -0
- package/dist/ncanbus.d.ts +17 -0
- package/dist/ncanbus.d.ts.map +1 -0
- package/dist/ncanbus.js +92 -0
- package/dist/ncanbus.js.map +1 -0
- package/dist/pgns.d.ts +22 -0
- package/dist/pgns.d.ts.map +1 -0
- package/dist/pgns.js +157 -0
- package/dist/pgns.js.map +1 -0
- package/dist/pgns.test.d.ts +2 -0
- package/dist/pgns.test.d.ts.map +1 -0
- package/dist/pgns.test.js +14 -0
- package/dist/pgns.test.js.map +1 -0
- package/dist/simpleCan.d.ts +17 -0
- package/dist/simpleCan.d.ts.map +1 -0
- package/dist/simpleCan.js +125 -0
- package/dist/simpleCan.js.map +1 -0
- package/dist/stringMsg.d.ts +33 -0
- package/dist/stringMsg.d.ts.map +1 -0
- package/dist/stringMsg.js +359 -0
- package/dist/stringMsg.js.map +1 -0
- package/dist/stringMsg.test.d.ts +2 -0
- package/dist/stringMsg.test.d.ts.map +1 -0
- package/dist/stringMsg.test.js +244 -0
- package/dist/stringMsg.test.js.map +1 -0
- package/dist/toPgn.d.ts +34 -0
- package/dist/toPgn.d.ts.map +1 -0
- package/dist/toPgn.js +500 -0
- package/dist/toPgn.js.map +1 -0
- package/dist/utilities.d.ts +26 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +112 -0
- package/dist/utilities.js.map +1 -0
- package/dist/utilities.test.d.ts +2 -0
- package/dist/utilities.test.d.ts.map +1 -0
- package/dist/utilities.test.js +9 -0
- package/dist/utilities.test.js.map +1 -0
- package/dist/venus-mqtt.d.ts +11 -0
- package/dist/venus-mqtt.d.ts.map +1 -0
- package/dist/venus-mqtt.js +100 -0
- package/dist/venus-mqtt.js.map +1 -0
- package/dist/venus.d.ts +11 -0
- package/dist/venus.d.ts.map +1 -0
- package/dist/venus.js +71 -0
- package/dist/venus.js.map +1 -0
- package/dist/w2k01.d.ts +17 -0
- package/dist/w2k01.d.ts.map +1 -0
- package/dist/w2k01.js +119 -0
- package/dist/w2k01.js.map +1 -0
- package/dist/yddevice.d.ts +25 -0
- package/dist/yddevice.d.ts.map +1 -0
- package/dist/yddevice.js +45 -0
- package/dist/yddevice.js.map +1 -0
- package/dist/ydgw02.d.ts +17 -0
- package/dist/ydgw02.d.ts.map +1 -0
- package/dist/ydgw02.js +163 -0
- package/dist/ydgw02.js.map +1 -0
- package/dist/ydvr.d.ts +17 -0
- package/dist/ydvr.d.ts.map +1 -0
- package/dist/ydvr.js +120 -0
- package/dist/ydvr.js.map +1 -0
- package/eslint.config.js +58 -0
- package/jest.config.js +5 -0
- package/lib/actisense-serial.ts +644 -0
- package/lib/bin/actisense-file.ts +53 -0
- package/lib/bin/actisense-n2k-tcp.ts +50 -0
- package/lib/bin/actisense-serialjs.ts +55 -0
- package/{bin/analyzerjs → lib/bin/analyzerjs.ts} +16 -15
- package/{bin/candumpjs → lib/bin/candumpjs.ts} +19 -20
- package/lib/bin/cansend.ts +131 -0
- package/lib/bin/ikonvert-serial.ts +44 -0
- package/{bin/to-pgn → lib/bin/to-pgn.ts} +23 -17
- package/lib/bin/ydvr-file +33 -0
- package/lib/canId.test.js +35 -15
- package/lib/canId.ts +84 -0
- package/lib/canbus.ts +293 -0
- package/lib/{candevice.js → candevice.ts} +14 -21
- package/lib/codes.ts +21 -0
- package/lib/{discovery.js → discovery.ts} +32 -30
- package/lib/fromPgn.ts +1207 -0
- package/lib/{fromPgnStream.js → fromPgnStream.ts} +17 -12
- package/lib/{ikonvert.js → ikonvert.ts} +90 -85
- package/lib/index.ts +48 -0
- package/lib/n2k-actisense.test.js +31 -32
- package/lib/n2k-actisense.ts +152 -0
- package/lib/n2kDevice.ts +458 -0
- package/lib/pgns.test.ts +12 -0
- package/lib/pgns.ts +191 -0
- package/lib/simpleCan.ts +140 -0
- package/lib/stringMsg.test.js +58 -41
- package/lib/stringMsg.ts +464 -0
- package/lib/toPgn.ts +597 -0
- package/lib/{utilities.js → utilities.ts} +48 -37
- package/lib/venus-mqtt.js +69 -73
- package/lib/venus.js +8 -8
- package/lib/{w2k01.js → w2k01.ts} +57 -44
- package/lib/{yddevice.js → yddevice.ts} +18 -13
- package/lib/{ydgw02.js → ydgw02.ts} +55 -47
- package/lib/ydvr.js +65 -147
- package/package.json +54 -18
- package/tsconfig.json +19 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/bin/actisense-file +0 -47
- package/bin/actisense-n2k-tcp +0 -45
- package/bin/actisense-serialjs +0 -52
- package/bin/candumpanalyzerjs +0 -29
- package/bin/cansend +0 -130
- package/bin/ikonvert-serial +0 -50
- package/bin/ydgw-analyzerjs +0 -36
- package/bin/ydvr-file +0 -33
- package/index.js +0 -53
- package/lib/canId.js +0 -64
- package/lib/canbus.js +0 -278
- package/lib/codes.js +0 -69
- package/lib/codes.test.js +0 -17
- package/lib/codesMfgs.json +0 -166
- package/lib/fromPgn.js +0 -1027
- package/lib/n2k-actisense.js +0 -108
- package/lib/n2kDevice.js +0 -390
- package/lib/pgns.js +0 -196
- package/lib/pgns.test.js +0 -13
- package/lib/serial.js +0 -647
- package/lib/simpleCan.js +0 -105
- package/lib/stringMsg.js +0 -339
- package/lib/toPgn.js +0 -518
package/bin/ydgw-analyzerjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const Parser = require('../index').FromPgn
|
|
4
|
-
var parser = new Parser()
|
|
5
|
-
|
|
6
|
-
parser.on('error', (pgn, error) => {
|
|
7
|
-
console.error(`Error parsing ${pgn.pgn} ${error}`)
|
|
8
|
-
console.error(error.stack)
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
parser.on('warning', (pgn, error) => {
|
|
12
|
-
//console.error(`Warning parsing ${pgn.pgn} ${error}`)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
/*
|
|
16
|
-
parser.on('pgn', (pgn) => {
|
|
17
|
-
console.log(JSON.stringify(pgn))
|
|
18
|
-
})
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var readline = require('readline')
|
|
23
|
-
var rl = readline.createInterface({
|
|
24
|
-
input: process.stdin,
|
|
25
|
-
output: process.stdout,
|
|
26
|
-
terminal: false
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
var input = []
|
|
30
|
-
rl.on('line', function (line) {
|
|
31
|
-
const res = parser.parseYDGW02(line)
|
|
32
|
-
//console.log(line + ': ' + JSON.stringify(res))
|
|
33
|
-
if ( res ) {
|
|
34
|
-
console.log(JSON.stringify(res))
|
|
35
|
-
}
|
|
36
|
-
})
|
package/bin/ydvr-file
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const YdvrStream = require('../lib/ydvr.js');
|
|
4
|
-
|
|
5
|
-
const argv = require('minimist')(process.argv.slice(2), {
|
|
6
|
-
alias: { h: 'help' },
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
if (argv['help']) {
|
|
10
|
-
console.error(`Usage: ${process.argv[0]} file
|
|
11
|
-
|
|
12
|
-
Options:
|
|
13
|
-
-h, --help output usage information`);
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (argv['_'].length === 0) {
|
|
18
|
-
console.error('Please specify a file');
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const serial = YdvrStream();
|
|
23
|
-
|
|
24
|
-
filestream = require('fs').createReadStream(argv['_'][0]);
|
|
25
|
-
filestream.on('error', (err) => {
|
|
26
|
-
console.error(err.message);
|
|
27
|
-
});
|
|
28
|
-
filestream.on('end', () => {
|
|
29
|
-
process.exit(0);
|
|
30
|
-
});
|
|
31
|
-
filestream.pipe(serial).on("data", (chunk) => {
|
|
32
|
-
console.log(JSON.stringify(chunk));
|
|
33
|
-
});
|
package/index.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Copyright 2019 Scott Bender <scott@scottbender.net>
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
const pgns = require('./lib/pgns')
|
|
20
|
-
|
|
21
|
-
module.exports = {
|
|
22
|
-
FromPgn: require('./lib/fromPgn').Parser,
|
|
23
|
-
parseN2kString: require('./lib/stringMsg').parseN2kString,
|
|
24
|
-
isN2KString: require('./lib/stringMsg').isN2KString,
|
|
25
|
-
toPgn: require('./lib/toPgn').toPgn,
|
|
26
|
-
toActisenseSerialFormat: require('./lib/stringMsg').toActisenseSerialFormat,
|
|
27
|
-
pgnToActisenseSerialFormat: require('./lib/toPgn').pgnToActisenseSerialFormat,
|
|
28
|
-
pgnToActisenseN2KAsciiFormat: require('./lib/toPgn').pgnToActisenseN2KAsciiFormat,
|
|
29
|
-
pgnToiKonvertSerialFormat: require('./lib/toPgn').pgnToiKonvertSerialFormat,
|
|
30
|
-
pgnToYdgwRawFormat: require('./lib/toPgn').pgnToYdgwRawFormat,
|
|
31
|
-
pgnToYdgwFullRawFormat: require('./lib/toPgn').pgnToYdgwFullRawFormat,
|
|
32
|
-
pgnToPCDIN: require('./lib/toPgn').pgnToPCDIN,
|
|
33
|
-
pgnToMXPGN: require('./lib/toPgn').pgnToMXPGN,
|
|
34
|
-
canbus: require('./lib/canbus'),
|
|
35
|
-
iKonvert: require('./lib/ikonvert'),
|
|
36
|
-
Ydwg02: require('./lib/ydgw02'),
|
|
37
|
-
Ydgw02: require('./lib/ydgw02'),
|
|
38
|
-
W2k01: require('./lib/w2k01'),
|
|
39
|
-
Venus: require('./lib/venus'),
|
|
40
|
-
VenusMQTT: require('./lib/venus-mqtt'),
|
|
41
|
-
discover: require('./lib/discovery'),
|
|
42
|
-
SimpleCan: require('./lib/simpleCan'),
|
|
43
|
-
YdDevice: require('./lib/yddevice'),
|
|
44
|
-
addCustomPgns: pgns.addCustomPgns,
|
|
45
|
-
lookupEnumerationValue: pgns.lookupEnumerationValue,
|
|
46
|
-
lookupEnumerationName: pgns.lookupEnumerationName
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
module.exports.serial = require('./lib/serial')
|
|
51
|
-
} catch ( ex ) {
|
|
52
|
-
}
|
|
53
|
-
|
package/lib/canId.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
const { flow } = require('lodash/fp')
|
|
2
|
-
|
|
3
|
-
// Decode CAN Identifier (canId). ISO 11783 (CAN 2.0 B Extended Frame Format)
|
|
4
|
-
exports.parseCanId = (id) => {
|
|
5
|
-
const res = {
|
|
6
|
-
canId: id, // Include original canId in return object.
|
|
7
|
-
prio: ((id >> 26) & 0x7), // Priority
|
|
8
|
-
src: id & 0xff, // Source Address (SA)
|
|
9
|
-
}
|
|
10
|
-
const PF = (id >> 16) & 0xff // PDU Format
|
|
11
|
-
const PS = (id >> 8) & 0xff // PDU Specific
|
|
12
|
-
const DP = (id >> 24) & 1 // Data Page
|
|
13
|
-
|
|
14
|
-
if (PF < 240) {
|
|
15
|
-
/* PDU1 format, the PS contains the destination address */
|
|
16
|
-
res.dst = PS;
|
|
17
|
-
res.pgn = (DP << 16) + (PF << 8);
|
|
18
|
-
} else {
|
|
19
|
-
/* PDU2 format, the destination is implied global and the PGN is extended */
|
|
20
|
-
res.dst = 0xff
|
|
21
|
-
res.pgn = (DP << 16) + (PF << 8) + PS
|
|
22
|
-
}
|
|
23
|
-
return res
|
|
24
|
-
}
|
|
25
|
-
// canId should be a hex encoded string without spaces or commas.
|
|
26
|
-
exports.parseCanIdStr = canId => exports.parseCanId(parseInt(canId, 16))
|
|
27
|
-
|
|
28
|
-
exports.buildCanId = (prio, pgn, dst, src) => ({
|
|
29
|
-
prio: Number(prio),
|
|
30
|
-
pgn: Number(pgn),
|
|
31
|
-
dst: Number(dst),
|
|
32
|
-
src: Number(src),
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
// Encode CAN Identifier (canId)
|
|
36
|
-
exports.encodeCanId = ({ dst, pgn, prio, src }) => {
|
|
37
|
-
let canId = src & 0xff
|
|
38
|
-
|
|
39
|
-
//I can't get this to work, but things seem ok??
|
|
40
|
-
//let canId = ((src & 0xff) | 0x80000000)) // src bits are the lowest ones of the CAN ID. Also set the highest bit to 1 as n2k uses
|
|
41
|
-
// only extended frames (EFF bit).
|
|
42
|
-
|
|
43
|
-
const PF = (pgn >> 8) & 0xff
|
|
44
|
-
|
|
45
|
-
if (PF < 240)
|
|
46
|
-
{ // PDU 1
|
|
47
|
-
canId = (canId | ((dst & 0xff) << 8))
|
|
48
|
-
canId = (canId | (pgn << 8))
|
|
49
|
-
}
|
|
50
|
-
else
|
|
51
|
-
{ // PDU 2
|
|
52
|
-
canId = (canId | pgn << 8)
|
|
53
|
-
}
|
|
54
|
-
canId = (canId | prio << 26)
|
|
55
|
-
|
|
56
|
-
return canId
|
|
57
|
-
}
|
|
58
|
-
exports.canIdString = canId => canId.toString(16).padStart(8, '0')
|
|
59
|
-
exports.encodeCanIdString = flow(
|
|
60
|
-
exports.encodeCanId,
|
|
61
|
-
exports.canIdString,
|
|
62
|
-
)
|
|
63
|
-
// Utility function that parses and re-encodes. Compare result to original.
|
|
64
|
-
exports.parseEncode = x => exports.encodeCanId(exports.parseCanId(x))
|
package/lib/canbus.js
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2018 Scott Bender (scott@scottbender.net)
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
const debug = require('debug')('canboatjs:canbus')
|
|
18
|
-
const Transform = require('stream').Transform
|
|
19
|
-
const isArray = require('lodash').isArray
|
|
20
|
-
const BitStream = require('bit-buffer').BitStream
|
|
21
|
-
const BitView = require('bit-buffer').BitView
|
|
22
|
-
const { toPgn } = require('./toPgn')
|
|
23
|
-
const Parser = require('./fromPgn').Parser
|
|
24
|
-
const _ = require('lodash')
|
|
25
|
-
const CanDevice = require('./candevice')
|
|
26
|
-
const { getPlainPGNs, binToActisense } = require('./utilities')
|
|
27
|
-
const { encodeCanId, parseCanId } = require('./canId')
|
|
28
|
-
const { toActisenseSerialFormat, parseActisense } = require('./stringMsg')
|
|
29
|
-
|
|
30
|
-
const MSG_BUF_SIZE = 2000
|
|
31
|
-
const CANDUMP_DATA_INC_3 = 3
|
|
32
|
-
const CANDUMP_DATA_INC_2 = 2
|
|
33
|
-
const MAX_DATA_BYTES = 223
|
|
34
|
-
|
|
35
|
-
// There are at least three variations in candump output
|
|
36
|
-
// format which are currently handled...
|
|
37
|
-
//
|
|
38
|
-
const FMT_TBD = 0
|
|
39
|
-
const FMT_1 = 1 // Angstrom ex: "<0x18eeff01> [8] 05 a0 be 1c 00 a0 a0 c0"
|
|
40
|
-
const FMT_2 = 2 // Debian ex: " can0 09F8027F [8] 00 FC FF FF 00 00 FF FF"
|
|
41
|
-
const FMT_3 = 3 // candump log ex: "(1502979132.106111) slcan0 09F50374#000A00FFFF00FFFF"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function CanbusStream (options) {
|
|
45
|
-
if (!(this instanceof CanbusStream)) {
|
|
46
|
-
return new CanbusStream(options)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
Transform.call(this, {
|
|
50
|
-
objectMode: true
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
this.plainText = false
|
|
54
|
-
this.options = options
|
|
55
|
-
this.start()
|
|
56
|
-
|
|
57
|
-
this.setProviderStatus = options.app && options.app.setProviderStatus
|
|
58
|
-
? (msg) => {
|
|
59
|
-
options.app.setProviderStatus(options.providerId, msg)
|
|
60
|
-
}
|
|
61
|
-
: () => {}
|
|
62
|
-
this.setProviderError = options.app && options.app.setProviderError
|
|
63
|
-
? (msg) => {
|
|
64
|
-
options.app.setProviderError(options.providerId, msg)
|
|
65
|
-
}
|
|
66
|
-
: () => {}
|
|
67
|
-
|
|
68
|
-
if ( options.fromStdIn ) {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
this.socketcan = require('socketcan')
|
|
74
|
-
} catch ( err ) {
|
|
75
|
-
console.error(err)
|
|
76
|
-
var msg = 'unable to load native socketcan interface'
|
|
77
|
-
console.error(msg)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
var that = this
|
|
81
|
-
|
|
82
|
-
if ( options.app ) {
|
|
83
|
-
options.app.on(options.outEvent || 'nmea2000out', (msg) => {
|
|
84
|
-
that.sendPGN(msg)
|
|
85
|
-
})
|
|
86
|
-
options.app.on(options.jsonOutEvent || 'nmea2000JsonOut', (msg) => {
|
|
87
|
-
that.sendPGN(msg)
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
var canDevice = options.canDevice || 'can0'
|
|
92
|
-
|
|
93
|
-
if ( this.connect() == false ) {
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const noDataReceivedTimeout = typeof options.noDataReceivedTimeout !== 'undefined' ? options.noDataReceivedTimeout : -1
|
|
98
|
-
if ( noDataReceivedTimeout > 0 ) {
|
|
99
|
-
this.noDataInterval = setInterval(() => {
|
|
100
|
-
if ( this.channel && this.lastDataReceived && Date.now() - this.lastDataReceived > noDataReceivedTimeout * 1000 ) {
|
|
101
|
-
let channel = this.channel
|
|
102
|
-
delete this.channel
|
|
103
|
-
try {
|
|
104
|
-
channel.stop()
|
|
105
|
-
} catch ( error ) {
|
|
106
|
-
}
|
|
107
|
-
this.setProviderError('No data received, retrying...')
|
|
108
|
-
if ( this.options.app ) {
|
|
109
|
-
console.error('No data received, retrying...')
|
|
110
|
-
}
|
|
111
|
-
this.connect()
|
|
112
|
-
}
|
|
113
|
-
}, noDataReceivedTimeout * 1000)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
CanbusStream.prototype.connect = function() {
|
|
118
|
-
try {
|
|
119
|
-
if ( this.socketcan === undefined ) {
|
|
120
|
-
this.setProviderError('unable to load native socketcan interface')
|
|
121
|
-
return false
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
var that = this
|
|
125
|
-
var canDevice = this.options.canDevice || 'can0'
|
|
126
|
-
this.channel = this.socketcan.createRawChannelWithOptions(canDevice, { non_block_send: true} );
|
|
127
|
-
this.channel.addListener('onStopped', (msg) => {
|
|
128
|
-
if ( this.channel ) { // stoped by us?
|
|
129
|
-
delete this.channel
|
|
130
|
-
this.setProviderError('Stopped, Retrying...')
|
|
131
|
-
if ( this.options.app ) {
|
|
132
|
-
console.error('socketcan stopped, retrying...')
|
|
133
|
-
}
|
|
134
|
-
setTimeout(() => {
|
|
135
|
-
this.setProviderError('Reconnecting...')
|
|
136
|
-
this.connect()
|
|
137
|
-
}, 2000)
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
this.channel.addListener('onMessage', (msg) => {
|
|
141
|
-
var pgn = parseCanId(msg.id)
|
|
142
|
-
|
|
143
|
-
if ( this.noDataInterval ) {
|
|
144
|
-
this.lastDataReceived = Date.now()
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
//always send address claims through
|
|
148
|
-
if ( pgn.pgn != 60928 && that.candevice && that.candevice.cansend && pgn.src == that.candevice.address ) {
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
pgn.timestamp = new Date().toISOString()
|
|
153
|
-
if ( that.plainText ) {
|
|
154
|
-
this.push(binToActisense(pgn, msg.data, msg.data.length))
|
|
155
|
-
} else {
|
|
156
|
-
that.push({ pgn, length: msg.data.length, data: msg.data })
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
this.channel.start()
|
|
160
|
-
this.setProviderStatus('Connected to socketcan')
|
|
161
|
-
this.candevice = new CanDevice(this, this.options)
|
|
162
|
-
this.candevice.start()
|
|
163
|
-
return true
|
|
164
|
-
} catch (e) {
|
|
165
|
-
console.error(`unable to open canbus ${canDevice}: ${e}`)
|
|
166
|
-
console.error(e.stack)
|
|
167
|
-
this.setProviderError(e.message)
|
|
168
|
-
return false
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
require('util').inherits(CanbusStream, Transform)
|
|
173
|
-
|
|
174
|
-
CanbusStream.prototype.start = function () {
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
CanbusStream.prototype.sendPGN = function (msg, force) {
|
|
178
|
-
if ( this.candevice ) {
|
|
179
|
-
//if ( !this.candevice.cansend && (_.isString(msg) || msg.pgn !== 59904) ) {
|
|
180
|
-
if ( !this.candevice.cansend && force !== true ) {
|
|
181
|
-
//we have not completed address claim yet
|
|
182
|
-
return
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
debug('sending %j', msg)
|
|
186
|
-
|
|
187
|
-
if ( this.options.app ) {
|
|
188
|
-
this.options.app.emit('connectionwrite', { providerId: this.options.providerId })
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
let src = msg.pgn === 59904 || msg.forceSrc ? msg.src : this.candevice.address
|
|
192
|
-
if ( _.isString(msg) ) {
|
|
193
|
-
var split = msg.split(',')
|
|
194
|
-
split[3] = src
|
|
195
|
-
msg = split.join(',')
|
|
196
|
-
} else {
|
|
197
|
-
msg.src = src
|
|
198
|
-
if ( _.isUndefined(msg.prio) ) {
|
|
199
|
-
msg.prio = 3
|
|
200
|
-
}
|
|
201
|
-
if ( _.isUndefined(msg.dst) ) {
|
|
202
|
-
msg.dst = 255
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if ( this.socketCanWriter ) {
|
|
207
|
-
if ( _.isString(msg) ) {
|
|
208
|
-
this.socketCanWriter.stdin.write(msg + '\n')
|
|
209
|
-
} else {
|
|
210
|
-
var str = toActisenseSerialFormat(msg.pgn, toPgn(msg), msg.dst, msg.src)
|
|
211
|
-
this.socketCanWriter.stdin.write(str + '\n')
|
|
212
|
-
}
|
|
213
|
-
} else if ( this.channel ) {
|
|
214
|
-
var canid
|
|
215
|
-
var buffer
|
|
216
|
-
|
|
217
|
-
var pgn
|
|
218
|
-
if ( _.isObject(msg) ) {
|
|
219
|
-
canid = encodeCanId(msg)
|
|
220
|
-
buffer = toPgn(msg)
|
|
221
|
-
pgn = msg
|
|
222
|
-
} else {
|
|
223
|
-
pgn = parseActisense(msg)
|
|
224
|
-
canid = encodeCanId(pgn)
|
|
225
|
-
buffer = pgn.data
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if ( debug.enabled ) {
|
|
229
|
-
var str = toActisenseSerialFormat(pgn.pgn, buffer, pgn.dst, pgn.src)
|
|
230
|
-
debug(str)
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
//seems as though 126720 should always be encoded this way
|
|
234
|
-
if ( buffer.length > 8 || pgn.pgn == 126720 ) {
|
|
235
|
-
var pgns = getPlainPGNs(buffer)
|
|
236
|
-
pgns.forEach(pbuffer => {
|
|
237
|
-
this.channel.send({id: canid, ext:true, data: pbuffer})
|
|
238
|
-
})
|
|
239
|
-
} else {
|
|
240
|
-
this.channel.send({id: canid, ext:true, data: buffer})
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
CanbusStream.prototype._transform = function (chunk, encoding, done) {
|
|
248
|
-
done()
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
CanbusStream.prototype.end = function () {
|
|
252
|
-
if ( this.channel ) {
|
|
253
|
-
let channel = this.channel
|
|
254
|
-
delete this.channel
|
|
255
|
-
channel.stop()
|
|
256
|
-
}
|
|
257
|
-
if ( this.noDataInterval ) {
|
|
258
|
-
clearInterval(this.noDataInterval)
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
CanbusStream.prototype.pipe = function (pipeTo) {
|
|
264
|
-
if ( !pipeTo.fromPgn ) {
|
|
265
|
-
this.plainText = true
|
|
266
|
-
}
|
|
267
|
-
/*
|
|
268
|
-
pipeTo.fromPgn.on('pgn', (pgn) => {
|
|
269
|
-
if ( this.candevice ) {
|
|
270
|
-
this.candevice.n2kMessage(pgn)
|
|
271
|
-
}
|
|
272
|
-
})
|
|
273
|
-
*/
|
|
274
|
-
return CanbusStream.super_.prototype.pipe.call(this, pipeTo)
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
module.exports = CanbusStream
|
package/lib/codes.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const { invert, propertyOf } = require('lodash/fp')
|
|
2
|
-
const manufacturerNames = require('./codesMfgs.json')
|
|
3
|
-
|
|
4
|
-
const industryCodes = {
|
|
5
|
-
0: 'Global',
|
|
6
|
-
1: 'Highway',
|
|
7
|
-
2: 'Agriculture',
|
|
8
|
-
3: 'Construction',
|
|
9
|
-
4: 'Marine Industry',
|
|
10
|
-
5: 'Industrial'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const deviceClassCodes = {
|
|
14
|
-
0: 'Reserved for 2000 Use',
|
|
15
|
-
10: 'System tools',
|
|
16
|
-
20: 'Safety systems',
|
|
17
|
-
25: 'Internetwork device',
|
|
18
|
-
30: 'Electrical Distribution',
|
|
19
|
-
35: 'Electrical Generation',
|
|
20
|
-
40: 'Steering and Control surfaces',
|
|
21
|
-
50: 'Propulsion',
|
|
22
|
-
60: 'Navigation',
|
|
23
|
-
70: 'Communication',
|
|
24
|
-
75: 'Sensor Communication Interface',
|
|
25
|
-
80: 'Instrumentation/general systems',
|
|
26
|
-
85: 'External Environment',
|
|
27
|
-
90: 'Internal Environment',
|
|
28
|
-
100: 'Deck + cargo + fishing equipment systems',
|
|
29
|
-
120: 'Display',
|
|
30
|
-
125: 'Entertainment'
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const deviceClassNames = invert(deviceClassCodes)
|
|
34
|
-
const industryNames = invert(industryCodes)
|
|
35
|
-
industryNames['Marine'] = 4
|
|
36
|
-
|
|
37
|
-
const defaultTransmitPGNs = [
|
|
38
|
-
126992,
|
|
39
|
-
128267,
|
|
40
|
-
129794,
|
|
41
|
-
129038,
|
|
42
|
-
129041,
|
|
43
|
-
127505,
|
|
44
|
-
127506,
|
|
45
|
-
127508,
|
|
46
|
-
129026,
|
|
47
|
-
129025,
|
|
48
|
-
129029,
|
|
49
|
-
127250,
|
|
50
|
-
130306,
|
|
51
|
-
126720,
|
|
52
|
-
127489,
|
|
53
|
-
127488,
|
|
54
|
-
130311,
|
|
55
|
-
130312,
|
|
56
|
-
127257,
|
|
57
|
-
128259,
|
|
58
|
-
127502
|
|
59
|
-
]
|
|
60
|
-
|
|
61
|
-
const manufacturerCodes = invert(manufacturerNames)
|
|
62
|
-
module.exports.manufacturerCodes = manufacturerCodes
|
|
63
|
-
module.exports.getIndustryName = propertyOf(industryCodes)
|
|
64
|
-
module.exports.getManufacturerName = propertyOf(manufacturerCodes)
|
|
65
|
-
module.exports.getIndustryCode = propertyOf(industryNames)
|
|
66
|
-
module.exports.getManufacturerCode = propertyOf(manufacturerNames)
|
|
67
|
-
module.exports.getDeviceClassCode = propertyOf(deviceClassNames)
|
|
68
|
-
module.exports.getDeviceClassName = propertyOf(deviceClassCodes)
|
|
69
|
-
module.exports.defaultTransmitPGNs = defaultTransmitPGNs
|
package/lib/codes.test.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const { getManufacturerCode, getManufacturerName } = require('./codes')
|
|
2
|
-
|
|
3
|
-
describe('getManufacturerCode', () => {
|
|
4
|
-
test('Return mfg number from name string', () => {
|
|
5
|
-
expect(getManufacturerCode('Furuno')).toBe(1855)
|
|
6
|
-
expect(getManufacturerCode('Yacht Devices')).toBe(717)
|
|
7
|
-
expect(getManufacturerCode('TJC Micro')).toBe(963)
|
|
8
|
-
})
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
describe('getManufacturerName', () => {
|
|
12
|
-
test('Return name string from mfg number', () => {
|
|
13
|
-
expect(getManufacturerName(1855)).toBe('Furuno')
|
|
14
|
-
expect(getManufacturerName(717)).toBe('Yacht Devices')
|
|
15
|
-
expect(getManufacturerName(963)).toBe('TJC Micro')
|
|
16
|
-
})
|
|
17
|
-
})
|