@canboat/canboatjs 3.0.0-beta.6 → 3.0.0-beta.8

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 CHANGED
@@ -4,7 +4,7 @@ const canboatjs = require('../index')
4
4
  const Parser = require('../index').FromPgn
5
5
  const { parseCanId } = require('../lib/canId')
6
6
  const socketcan = require('socketcan')
7
-
7
+ const { binToActisense } = require('../lib/utilities')
8
8
  var parser = new canboatjs.FromPgn()
9
9
 
10
10
 
@@ -83,16 +83,3 @@ channel.addListener('onMessage', (msg) => {
83
83
  channel.start()
84
84
 
85
85
 
86
- function binToActisense(pgn, data, length) {
87
- return (
88
- pgn.timestamp +
89
- `,${pgn.prio},${pgn.pgn},${pgn.src},${pgn.dst},${length},` +
90
- new Uint32Array(data)
91
- .reduce(function(acc, i) {
92
- acc.push(i.toString(16));
93
- return acc;
94
- }, [])
95
- .map(x => (x.length === 1 ? "0" + x : x))
96
- .join(",")
97
- );
98
- }
package/bin/cansend ADDED
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+
3
+ const canboatjs = require('../index')
4
+ const Parser = require('../index').FromPgn
5
+ const { parseCanId } = require('../lib/canId')
6
+ const { parseActisense } = require('../lib/stringMsg')
7
+ const socketcan = require('socketcan')
8
+
9
+ const { toPgn } = require('../lib/toPgn')
10
+ const { getPlainPGNs, binToActisense } = require('../lib/utilities')
11
+ const { encodeCanId } = require('../lib/canId')
12
+
13
+ const argv = require('minimist')(process.argv.slice(2), {
14
+ alias: { h: 'help' },
15
+ boolean: ['log-output'],
16
+ string: ['src'],
17
+ })
18
+
19
+ if ( argv['help'] ) {
20
+ console.error(`Usage: ${process.argv[0]} [options] candevice
21
+
22
+ Options:
23
+ --src <src> use src for all messages
24
+ --log-output log messages sent
25
+ -h, --help output usage information`)
26
+ process.exit(1)
27
+ }
28
+
29
+ if ( argv['_'].length === 0 ) {
30
+ console.error('Please specify a device')
31
+ process.exit(1)
32
+ }
33
+
34
+ const canDevice = argv['_'][0]
35
+ const srcArg = argv.src
36
+ const logOut = argv['log-output']
37
+
38
+ const channel = socketcan.createRawChannel(canDevice);
39
+
40
+ channel.addListener('onStopped', (msg) => {
41
+ console.error('socketcan stopped')
42
+ })
43
+
44
+ channel.start()
45
+
46
+ var readline = require('readline')
47
+ var rl = readline.createInterface({
48
+ input: process.stdin,
49
+ output: process.stdout,
50
+ terminal: false
51
+ })
52
+
53
+ var input = []
54
+
55
+ rl.on('line', function (line) {
56
+ let msg = line[0] === '{' ? JSON.parse(line) : line
57
+
58
+ if ( typeof msg === 'string' ) {
59
+ var split = msg.split(',')
60
+ if ( srcArg !== undefined ) {
61
+ split[3] = srcArg
62
+ }
63
+ msg = split.join(',')
64
+ } else {
65
+ if ( msg.prio === undefined ) {
66
+ msg.prio = 3
67
+ }
68
+ if ( msg.dst === undefined ) {
69
+ msg.dst = 255
70
+ }
71
+ if ( srcArg !== undefined ) {
72
+ msg.src = srcArg
73
+ }
74
+ if ( msg.src === undefined ) {
75
+ msg.src = 100
76
+ }
77
+ }
78
+
79
+ var pgn, canid, buffer
80
+ if ( typeof msg === 'object' ) {
81
+ canid = encodeCanId(msg)
82
+ buffer = toPgn(msg)
83
+ pgn = msg
84
+ } else {
85
+ pgn = parseActisense(msg)
86
+ canid = encodeCanId(pgn)
87
+ buffer = pgn.data
88
+ }
89
+
90
+ pgn.timestamp = new Date().toISOString()
91
+
92
+ if ( buffer.length > 8 || pgn.pgn == 126720 ) {
93
+ var pgns = getPlainPGNs(buffer)
94
+ pgns.forEach(pbuffer => {
95
+ channel.send({id: canid, ext:true, data: pbuffer})
96
+ if ( logOut ) {
97
+ console.log(binToActisense(pgn, pbuffer, pbuffer.length))
98
+ }
99
+ })
100
+ } else {
101
+ channel.send({id: canid, ext:true, data: buffer})
102
+ if ( logOut ) {
103
+ console.log(binToActisense(pgn, buffer, buffer.length))
104
+ }
105
+ }
106
+ })
package/lib/canbus.js CHANGED
@@ -23,7 +23,7 @@ const { toPgn } = require('./toPgn')
23
23
  const Parser = require('./fromPgn').Parser
24
24
  const _ = require('lodash')
25
25
  const CanDevice = require('./candevice')
26
- const { getPlainPGNs } = require('./utilities')
26
+ const { getPlainPGNs, binToActisense } = require('./utilities')
27
27
  const { encodeCanId, parseCanId } = require('./canId')
28
28
  const { toActisenseSerialFormat, parseActisense } = require('./stringMsg')
29
29
 
@@ -169,21 +169,6 @@ CanbusStream.prototype.connect = function() {
169
169
  }
170
170
  }
171
171
 
172
- function binToActisense(pgn, data, length) {
173
- return (
174
- pgn.timestamp +
175
- `,${pgn.prio},${pgn.pgn},${pgn.src},${pgn.dst},${length},` +
176
- new Uint32Array(data)
177
- .reduce(function(acc, i) {
178
- acc.push(i.toString(16));
179
- return acc;
180
- }, [])
181
- .map(x => (x.length === 1 ? "0" + x : x))
182
- .join(",")
183
- );
184
- }
185
-
186
-
187
172
  require('util').inherits(CanbusStream, Transform)
188
173
 
189
174
  CanbusStream.prototype.start = function () {
@@ -2,6 +2,7 @@ const debug = require('debug')('canboatjs:w2k01')
2
2
  const debugData = require('debug')('canboatjs:w2k01-data')
3
3
  const { parseCanId, encodeCanId } = require('./canId')
4
4
  const BitStream = require('bit-buffer').BitStream
5
+ const { binToActisense } = require('./utilities')
5
6
 
6
7
  exports.readN2KActisense = function (data, plainText, context, cb) {
7
8
  const inBuf = Buffer.from(data)
@@ -105,20 +106,3 @@ exports.encodeN2KActisense = ({
105
106
 
106
107
  return bs.view.buffer
107
108
  }
108
-
109
-
110
- function binToActisense(pgn, data, length) {
111
- return (
112
- pgn.timestamp +
113
- `,${pgn.prio},${pgn.pgn},${pgn.src},${pgn.dst},${length},` +
114
- new Uint32Array(data)
115
- .reduce(function(acc, i) {
116
- acc.push(i.toString(16));
117
- return acc;
118
- }, [])
119
- .map(x => (x.length === 1 ? "0" + x : x))
120
- .join(",")
121
- );
122
- }
123
-
124
-
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:
@@ -184,9 +185,10 @@ function handleISORequest(device, n2kMsg) {
184
185
 
185
186
  function handleGroupFunction(device, n2kMsg) {
186
187
  debug('handleGroupFunction %j', n2kMsg)
187
- if(n2kMsg.fields.functionCode === 'Request') {
188
+ const functionCode = n2kMsg.fields.functionCode || n2kMsg.fields["Function Code"]
189
+ if(functionCode === 'Request') {
188
190
  handleRequestGroupFunction(device, n2kMsg)
189
- } else if(n2kMsg.fields.functionCode === 'Command') {
191
+ } else if(functionCode === 'Command') {
190
192
  handleCommandGroupFunction(device, n2kMsg)
191
193
  } else {
192
194
  debug('Got unsupported Group Function PGN: %j', n2kMsg)
@@ -338,7 +340,7 @@ function sendISORequest(device, pgn, src, dst=255) {
338
340
 
339
341
 
340
342
  function sendProductInformation(device) {
341
- debug("Sending product info..")
343
+ debug("Sending product info %j", device.productInfo))
342
344
 
343
345
  device.sendPGN(device.productInfo)
344
346
  }
package/lib/simpleCan.js CHANGED
@@ -3,7 +3,7 @@ const debug = require('debug')('canboatjs:simpleCan')
3
3
  const { encodeCanId, parseCanId } = require('./canId')
4
4
  const { toActisenseSerialFormat, parseActisense } = require('./stringMsg')
5
5
  const { toPgn } = require('./toPgn')
6
- const { getPlainPGNs } = require('./utilities')
6
+ const { getPlainPGNs, binToActisense } = require('./utilities')
7
7
  const _ = require('lodash')
8
8
 
9
9
  function SimpleCan (options, messageCb) {
@@ -102,18 +102,4 @@ SimpleCan.prototype.sendActisenseFormat = function (msg) {
102
102
  this.sendPGN(msg)
103
103
  }
104
104
 
105
- function binToActisense(pgn, data, length) {
106
- return (
107
- pgn.timestamp +
108
- `,${pgn.prio},${pgn.pgn},${pgn.src},${pgn.dst},${length},` +
109
- new Uint32Array(data)
110
- .reduce(function(acc, i) {
111
- acc.push(i.toString(16));
112
- return acc;
113
- }, [])
114
- .map(x => (x.length === 1 ? "0" + x : x))
115
- .join(",")
116
- );
117
- }
118
-
119
105
  module.exports = SimpleCan
package/lib/utilities.js CHANGED
@@ -85,6 +85,21 @@ function compute0183Checksum (sentence) {
85
85
  return '*' + toHexString(c1)
86
86
  }
87
87
 
88
+ function binToActisense(pgn, data, length) {
89
+ return (
90
+ pgn.timestamp +
91
+ `,${pgn.prio},${pgn.pgn},${pgn.src},${pgn.dst},${length},` +
92
+ new Uint32Array(data)
93
+ .reduce(function(acc, i) {
94
+ acc.push(i.toString(16));
95
+ return acc;
96
+ }, [])
97
+ .map(x => (x.length === 1 ? "0" + x : x))
98
+ .join(",")
99
+ );
100
+ }
101
+
102
+ exports.binToActisense = binToActisense
88
103
  exports.compute0183Checksum = compute0183Checksum
89
104
  exports.trimWrap = trimChars('()<>[]')
90
105
  exports.rmChecksum = str => str.includes('*') ? str.split('*', 1)[0] : str
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canboat/canboatjs",
3
- "version": "3.0.0-beta.6",
3
+ "version": "3.0.0-beta.8",
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"