@canboat/canboatjs 1.27.1 → 1.28.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/candumpjs +18 -1
- package/lib/canbus.js +1 -1
- package/lib/fromPgn.js +3 -3
- package/lib/serial.js +21 -2
- package/package.json +1 -1
package/bin/candumpjs
CHANGED
|
@@ -67,8 +67,25 @@ channel.addListener('onMessage', (msg) => {
|
|
|
67
67
|
var pgn = parseCanId(msg.id)
|
|
68
68
|
|
|
69
69
|
pgn.timestamp = new Date().toISOString()
|
|
70
|
+
|
|
71
|
+
let sourceString = binToActisense(pgn, msg.data, msg.data.length)
|
|
70
72
|
|
|
71
|
-
parser.parse({ pgn, length: msg.data.length, data: msg.data })
|
|
73
|
+
parser.parse({ pgn, length: msg.data.length, data: msg.data, sourceString })
|
|
72
74
|
})
|
|
73
75
|
|
|
74
76
|
channel.start()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
function binToActisense(pgn, data, length) {
|
|
80
|
+
return (
|
|
81
|
+
pgn.timestamp +
|
|
82
|
+
`,${pgn.prio},${pgn.pgn},${pgn.src},${pgn.dst},${length},` +
|
|
83
|
+
new Uint32Array(data)
|
|
84
|
+
.reduce(function(acc, i) {
|
|
85
|
+
acc.push(i.toString(16));
|
|
86
|
+
return acc;
|
|
87
|
+
}, [])
|
|
88
|
+
.map(x => (x.length === 1 ? "0" + x : x))
|
|
89
|
+
.join(",")
|
|
90
|
+
);
|
|
91
|
+
}
|
package/lib/canbus.js
CHANGED
|
@@ -318,7 +318,7 @@ function readLine(that, line) {
|
|
|
318
318
|
|
|
319
319
|
pgn.timestamp = new Date().toISOString()
|
|
320
320
|
|
|
321
|
-
that.push({ pgn: pgn, length: len, data })
|
|
321
|
+
that.push({ pgn: pgn, length: len, data, sourceString: line })
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
CanbusStream.prototype._transform = function (chunk, encoding, done) {
|
package/lib/fromPgn.js
CHANGED
|
@@ -299,11 +299,11 @@ class Parser extends EventEmitter {
|
|
|
299
299
|
} else if ( _.isBuffer(data) ) {
|
|
300
300
|
return this.parseBuffer(data, cb)
|
|
301
301
|
} else {
|
|
302
|
-
return this.parsePgnData(data.pgn, data.length, data.data, data.coalesced === true)
|
|
302
|
+
return this.parsePgnData(data.pgn, data.length, data.data, data.coalesced === true, cb, data.sourceString)
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
-
parsePgnData(pgn, length, data, coalesced, cb) {
|
|
306
|
+
parsePgnData(pgn, length, data, coalesced, cb, sourceString) {
|
|
307
307
|
try
|
|
308
308
|
{
|
|
309
309
|
var buffer = data
|
|
@@ -317,7 +317,7 @@ class Parser extends EventEmitter {
|
|
|
317
317
|
|
|
318
318
|
var bv = new BitView(buffer);
|
|
319
319
|
var bs = new BitStream(bv)
|
|
320
|
-
const res = this._parse(pgn, bs, length, coalesced, cb);
|
|
320
|
+
const res = this._parse(pgn, bs, length, coalesced, cb, sourceString);
|
|
321
321
|
if ( res ) {
|
|
322
322
|
debug('parsed pgn %j', pgn)
|
|
323
323
|
}
|
package/lib/serial.js
CHANGED
|
@@ -108,6 +108,10 @@ SerialStream.prototype.start = function () {
|
|
|
108
108
|
this.isFile = false
|
|
109
109
|
this.state = MSG_START
|
|
110
110
|
|
|
111
|
+
if ( typeof this.reconnectDelay === 'undefined' ) {
|
|
112
|
+
this.reconnectDelay = 1000
|
|
113
|
+
}
|
|
114
|
+
|
|
111
115
|
if ( !this.options.fromFile ) {
|
|
112
116
|
this.serial = new SerialPort(this.options.device, {
|
|
113
117
|
baudRate: this.options.baudrate || 115200
|
|
@@ -122,7 +126,9 @@ SerialStream.prototype.start = function () {
|
|
|
122
126
|
? (msg) => {
|
|
123
127
|
this.options.app.setProviderError(this.options.providerId, msg)
|
|
124
128
|
}
|
|
125
|
-
|
|
129
|
+
: () => {}
|
|
130
|
+
this.setProviderStatus = setProviderStatus
|
|
131
|
+
|
|
126
132
|
var that = this
|
|
127
133
|
|
|
128
134
|
this.serial.on('data', (data) => {
|
|
@@ -175,15 +181,18 @@ SerialStream.prototype.start = function () {
|
|
|
175
181
|
this.serial.on('error', function (x) {
|
|
176
182
|
setProviderError(x.message)
|
|
177
183
|
console.log(x)
|
|
184
|
+
that.scheduleReconnect()
|
|
178
185
|
})
|
|
179
186
|
this.serial.on('close', () => {
|
|
180
187
|
setProviderError('Closed, reconnecting...')
|
|
181
|
-
this.start.bind(this)
|
|
188
|
+
//this.start.bind(this)
|
|
189
|
+
that.scheduleReconnect()
|
|
182
190
|
})
|
|
183
191
|
this.serial.on(
|
|
184
192
|
'open',
|
|
185
193
|
function () {
|
|
186
194
|
try {
|
|
195
|
+
this.reconnectDelay = 1000
|
|
187
196
|
setProviderStatus(`Connected to ${that.options.device}`)
|
|
188
197
|
var buf = composeMessage(NGT_MSG_SEND, Buffer.from(NGT_STARTUP_MSG), NGT_STARTUP_MSG.length)
|
|
189
198
|
debugOut(buf)
|
|
@@ -211,6 +220,16 @@ SerialStream.prototype.start = function () {
|
|
|
211
220
|
}
|
|
212
221
|
}
|
|
213
222
|
|
|
223
|
+
SerialStream.prototype.scheduleReconnect = function () {
|
|
224
|
+
this.reconnectDelay *= this.reconnectDelay < 60 * 1000 ? 1.5 : 1
|
|
225
|
+
const msg = `Not connected (retry delay ${(
|
|
226
|
+
this.reconnectDelay / 1000
|
|
227
|
+
).toFixed(0)} s)`
|
|
228
|
+
debug(msg)
|
|
229
|
+
this.setProviderStatus(msg)
|
|
230
|
+
setTimeout(this.start.bind(this), this.reconnectDelay)
|
|
231
|
+
}
|
|
232
|
+
|
|
214
233
|
function readData(that, data) {
|
|
215
234
|
for ( var i = 0; i < data.length; i++ ) {
|
|
216
235
|
//console.log(data[i])
|