@canboat/canboatjs 3.0.0-beta.8 → 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 CHANGED
@@ -2,10 +2,7 @@
2
2
 
3
3
  const argv = require('minimist')(process.argv.slice(2), {
4
4
  alias: { h: 'help' },
5
- boolean: ['n'],
6
- boolean: ['r'],
7
- boolean: ['camel'],
8
- boolean: ['camel-compat']
5
+ boolean: ['n', 'r', 'camel', 'camel-compat']
9
6
  })
10
7
 
11
8
  if ( argv['help'] ) {
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
- alias: { h: 'help' },
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> use src for all messages
24
- --log-output log messages sent
25
- -h, --help output usage information`)
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
- const channel = socketcan.createRawChannel(canDevice);
39
-
40
- channel.addListener('onStopped', (msg) => {
41
- console.error('socketcan stopped')
42
- })
43
-
44
- channel.start()
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
- channel.send({id: canid, ext:true, data: pbuffer})
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
- channel.send({id: canid, ext:true, data: buffer})
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
@@ -340,7 +340,7 @@ function sendISORequest(device, pgn, src, dst=255) {
340
340
 
341
341
 
342
342
  function sendProductInformation(device) {
343
- debug("Sending product info %j", device.productInfo))
343
+ debug("Sending product info %j", device.productInfo)
344
344
 
345
345
  device.sendPGN(device.productInfo)
346
346
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canboat/canboatjs",
3
- "version": "3.0.0-beta.8",
3
+ "version": "3.0.0-beta.9",
4
4
  "description": "Native javascript version of canboat",
5
5
  "main": "index.js",
6
6
  "scripts": {