@canboat/canboatjs 3.0.0-beta.8 → 3.0.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/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,20 @@ 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
+ let channel
39
40
 
40
- channel.addListener('onStopped', (msg) => {
41
- console.error('socketcan stopped')
42
- })
43
-
44
- channel.start()
41
+ if ( !test ) {
42
+ const socketcan = require('socketcan')
43
+ channel = socketcan.createRawChannel(canDevice);
44
+
45
+ channel.addListener('onStopped', (msg) => {
46
+ console.error('socketcan stopped')
47
+ })
48
+
49
+ channel.start()
50
+ }
45
51
 
46
52
  var readline = require('readline')
47
53
  var rl = readline.createInterface({
@@ -53,6 +59,10 @@ var rl = readline.createInterface({
53
59
  var input = []
54
60
 
55
61
  rl.on('line', function (line) {
62
+ if ( line.length === 0 ) {
63
+ return
64
+ }
65
+
56
66
  let msg = line[0] === '{' ? JSON.parse(line) : line
57
67
 
58
68
  if ( typeof msg === 'string' ) {
@@ -80,9 +90,19 @@ rl.on('line', function (line) {
80
90
  if ( typeof msg === 'object' ) {
81
91
  canid = encodeCanId(msg)
82
92
  buffer = toPgn(msg)
93
+ if ( buffer === undefined ) {
94
+ console.error('invalid input: %s', line)
95
+ return
96
+ }
83
97
  pgn = msg
84
98
  } else {
85
99
  pgn = parseActisense(msg)
100
+
101
+ if ( isNaN(pgn.prio) || isNaN(pgn.pgn) || isNaN(pgn.dst) || isNaN(pgn.src) ) {
102
+ console.error('invalid input: ' + line)
103
+ return
104
+ }
105
+
86
106
  canid = encodeCanId(pgn)
87
107
  buffer = pgn.data
88
108
  }
@@ -92,13 +112,17 @@ rl.on('line', function (line) {
92
112
  if ( buffer.length > 8 || pgn.pgn == 126720 ) {
93
113
  var pgns = getPlainPGNs(buffer)
94
114
  pgns.forEach(pbuffer => {
95
- channel.send({id: canid, ext:true, data: pbuffer})
115
+ if ( !test ) {
116
+ channel.send({id: canid, ext:true, data: pbuffer})
117
+ }
96
118
  if ( logOut ) {
97
119
  console.log(binToActisense(pgn, pbuffer, pbuffer.length))
98
120
  }
99
121
  })
100
122
  } else {
101
- channel.send({id: canid, ext:true, data: buffer})
123
+ if ( !test ) {
124
+ channel.send({id: canid, ext:true, data: buffer})
125
+ }
102
126
  if ( logOut ) {
103
127
  console.log(binToActisense(pgn, buffer, buffer.length))
104
128
  }
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",
4
4
  "description": "Native javascript version of canboat",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -54,7 +54,7 @@
54
54
  ],
55
55
  "license": "Apache-2.0",
56
56
  "dependencies": {
57
- "@canboat/pgns": "6.0.0-beta.3",
57
+ "@canboat/pgns": "6.0.x",
58
58
  "bit-buffer": "0.2.3",
59
59
  "debug": "^4.3.4",
60
60
  "dnssd": "^0.4.1",