@canboat/canboatjs 3.0.0-beta.7 → 3.0.0-beta.9
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/analyzerjs +1 -4
- package/bin/cansend +37 -15
- package/lib/n2kDevice.js +2 -1
- package/package.json +3 -2
package/bin/analyzerjs
CHANGED
package/bin/cansend
CHANGED
|
@@ -4,25 +4,25 @@ const canboatjs = require('../index')
|
|
|
4
4
|
const Parser = require('../index').FromPgn
|
|
5
5
|
const { parseCanId } = require('../lib/canId')
|
|
6
6
|
const { parseActisense } = require('../lib/stringMsg')
|
|
7
|
-
const socketcan = require('socketcan')
|
|
8
7
|
|
|
9
8
|
const { toPgn } = require('../lib/toPgn')
|
|
10
9
|
const { getPlainPGNs, binToActisense } = require('../lib/utilities')
|
|
11
10
|
const { encodeCanId } = require('../lib/canId')
|
|
12
11
|
|
|
13
12
|
const argv = require('minimist')(process.argv.slice(2), {
|
|
14
|
-
|
|
15
|
-
boolean: ['log-output'],
|
|
13
|
+
boolean: ['test', 'log-output'],
|
|
16
14
|
string: ['src'],
|
|
15
|
+
alias: { h: 'help' }
|
|
17
16
|
})
|
|
18
17
|
|
|
19
18
|
if ( argv['help'] ) {
|
|
20
19
|
console.error(`Usage: ${process.argv[0]} [options] candevice
|
|
21
20
|
|
|
22
21
|
Options:
|
|
23
|
-
--src <src>
|
|
24
|
-
--log-output
|
|
25
|
-
|
|
22
|
+
--src <src> use src for all messages
|
|
23
|
+
--log-output log messages sent
|
|
24
|
+
--test don't connect or send any data
|
|
25
|
+
-h, --help output usage information`)
|
|
26
26
|
process.exit(1)
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -34,14 +34,18 @@ if ( argv['_'].length === 0 ) {
|
|
|
34
34
|
const canDevice = argv['_'][0]
|
|
35
35
|
const srcArg = argv.src
|
|
36
36
|
const logOut = argv['log-output']
|
|
37
|
+
const test = argv.test
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
channel.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
if ( !test ) {
|
|
40
|
+
const socketcan = require('socketcan')
|
|
41
|
+
const channel = socketcan.createRawChannel(canDevice);
|
|
42
|
+
|
|
43
|
+
channel.addListener('onStopped', (msg) => {
|
|
44
|
+
console.error('socketcan stopped')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
channel.start()
|
|
48
|
+
}
|
|
45
49
|
|
|
46
50
|
var readline = require('readline')
|
|
47
51
|
var rl = readline.createInterface({
|
|
@@ -53,6 +57,10 @@ var rl = readline.createInterface({
|
|
|
53
57
|
var input = []
|
|
54
58
|
|
|
55
59
|
rl.on('line', function (line) {
|
|
60
|
+
if ( line.length === 0 ) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
let msg = line[0] === '{' ? JSON.parse(line) : line
|
|
57
65
|
|
|
58
66
|
if ( typeof msg === 'string' ) {
|
|
@@ -80,9 +88,19 @@ rl.on('line', function (line) {
|
|
|
80
88
|
if ( typeof msg === 'object' ) {
|
|
81
89
|
canid = encodeCanId(msg)
|
|
82
90
|
buffer = toPgn(msg)
|
|
91
|
+
if ( buffer === undefined ) {
|
|
92
|
+
console.error('invalid input: %s', line)
|
|
93
|
+
return
|
|
94
|
+
}
|
|
83
95
|
pgn = msg
|
|
84
96
|
} else {
|
|
85
97
|
pgn = parseActisense(msg)
|
|
98
|
+
|
|
99
|
+
if ( isNaN(pgn.prio) || isNaN(pgn.pgn) || isNaN(pgn.dst) || isNaN(pgn.src) ) {
|
|
100
|
+
console.error('invalid input: ' + line)
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
|
|
86
104
|
canid = encodeCanId(pgn)
|
|
87
105
|
buffer = pgn.data
|
|
88
106
|
}
|
|
@@ -92,13 +110,17 @@ rl.on('line', function (line) {
|
|
|
92
110
|
if ( buffer.length > 8 || pgn.pgn == 126720 ) {
|
|
93
111
|
var pgns = getPlainPGNs(buffer)
|
|
94
112
|
pgns.forEach(pbuffer => {
|
|
95
|
-
|
|
113
|
+
if ( !test ) {
|
|
114
|
+
channel.send({id: canid, ext:true, data: pbuffer})
|
|
115
|
+
}
|
|
96
116
|
if ( logOut ) {
|
|
97
117
|
console.log(binToActisense(pgn, pbuffer, pbuffer.length))
|
|
98
118
|
}
|
|
99
119
|
})
|
|
100
120
|
} else {
|
|
101
|
-
|
|
121
|
+
if ( !test ) {
|
|
122
|
+
channel.send({id: canid, ext:true, data: buffer})
|
|
123
|
+
}
|
|
102
124
|
if ( logOut ) {
|
|
103
125
|
console.log(binToActisense(pgn, buffer, buffer.length))
|
|
104
126
|
}
|
package/lib/n2kDevice.js
CHANGED
|
@@ -169,6 +169,7 @@ function handleISORequest(device, n2kMsg) {
|
|
|
169
169
|
sendConfigInformation(device)
|
|
170
170
|
break;
|
|
171
171
|
case 60928: // ISO address claim request
|
|
172
|
+
debug('sending address claim %j', device.addressClaim)
|
|
172
173
|
device.sendPGN(device.addressClaim)
|
|
173
174
|
break;
|
|
174
175
|
case 126464:
|
|
@@ -339,7 +340,7 @@ function sendISORequest(device, pgn, src, dst=255) {
|
|
|
339
340
|
|
|
340
341
|
|
|
341
342
|
function sendProductInformation(device) {
|
|
342
|
-
debug("Sending product info
|
|
343
|
+
debug("Sending product info %j", device.productInfo)
|
|
343
344
|
|
|
344
345
|
device.sendPGN(device.productInfo)
|
|
345
346
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canboat/canboatjs",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.9",
|
|
4
4
|
"description": "Native javascript version of canboat",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"actisense-file": "./bin/actisense-file",
|
|
19
19
|
"actisense-n2k-tcp": "./bin/actisense-n2k-tcp",
|
|
20
20
|
"candumpjs": "./bin/candumpjs",
|
|
21
|
-
"ikonvert-serial": "./bin/ikonvert-serial"
|
|
21
|
+
"ikonvert-serial": "./bin/ikonvert-serial",
|
|
22
|
+
"cansend": "./bin/cansend"
|
|
22
23
|
},
|
|
23
24
|
"jest": {
|
|
24
25
|
"rootDir": "lib"
|