@signalk/streams 1.18.0 → 2.0.2
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/.prettierrc.json +4 -0
- package/README.md +14 -0
- package/autodetect.js +5 -5
- package/canboatjs.js +9 -6
- package/execute.js +9 -6
- package/filestream.js +2 -2
- package/folderstream.js +20 -23
- package/from_json.js +2 -2
- package/gpsd.js +15 -11
- package/keys-filter.js +8 -7
- package/liner.js +2 -2
- package/log.js +3 -3
- package/logging.js +75 -11
- package/mdns-ws.js +61 -35
- package/n2k-signalk.js +88 -61
- package/n2kAnalyzer.js +5 -6
- package/nmea0183-signalk.js +10 -11
- package/nullprovider.js +2 -2
- package/package.json +6 -3
- package/pigpio-seatalk.js +4 -5
- package/replacer.js +2 -4
- package/s3.js +18 -14
- package/serialport.js +15 -12
- package/signalk-streams-3.0.1.tgz +0 -0
- package/simple.js +87 -65
- package/splitting-liner.js +2 -2
- package/tcp.js +35 -33
- package/tcpserver.js +2 -2
- package/timestamp-throttle.js +3 -3
- package/udp.js +4 -4
package/serialport.js
CHANGED
|
@@ -62,10 +62,9 @@ const child_process = require('child_process')
|
|
|
62
62
|
const shellescape = require('any-shell-escape')
|
|
63
63
|
const SerialPort = require('serialport')
|
|
64
64
|
const isArray = require('lodash').isArray
|
|
65
|
-
const debug = require('debug')('signalk:streams:serialport')
|
|
66
65
|
const isBuffer = require('lodash').isBuffer
|
|
67
66
|
|
|
68
|
-
function SerialStream
|
|
67
|
+
function SerialStream(options) {
|
|
69
68
|
if (!(this instanceof SerialStream)) {
|
|
70
69
|
return new SerialStream(options)
|
|
71
70
|
}
|
|
@@ -79,11 +78,16 @@ function SerialStream (options) {
|
|
|
79
78
|
this.maxPendingWrites = options.maxPendingWrites || 5
|
|
80
79
|
this.start()
|
|
81
80
|
this.isFirstError = true
|
|
81
|
+
|
|
82
|
+
const createDebug = options.createDebug || require('debug')
|
|
83
|
+
this.debug = createDebug('signalk:streams:serialport')
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
require('util').inherits(SerialStream, Transform)
|
|
85
87
|
|
|
86
88
|
SerialStream.prototype.start = function () {
|
|
89
|
+
const that = this
|
|
90
|
+
|
|
87
91
|
if (this.serial !== null) {
|
|
88
92
|
this.serial.unpipe(this)
|
|
89
93
|
this.serial.removeAllListeners()
|
|
@@ -101,7 +105,7 @@ SerialStream.prototype.start = function () {
|
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
this.serial = new SerialPort(this.options.device, {
|
|
104
|
-
baudRate: this.options.baudrate
|
|
108
|
+
baudRate: this.options.baudrate,
|
|
105
109
|
})
|
|
106
110
|
|
|
107
111
|
this.serial.on(
|
|
@@ -125,7 +129,7 @@ SerialStream.prototype.start = function () {
|
|
|
125
129
|
if (this.isFirstError) {
|
|
126
130
|
console.log(x.message)
|
|
127
131
|
}
|
|
128
|
-
debug(x.message)
|
|
132
|
+
this.debug(x.message)
|
|
129
133
|
this.isFirstError = false
|
|
130
134
|
this.scheduleReconnect()
|
|
131
135
|
}.bind(this)
|
|
@@ -141,26 +145,25 @@ SerialStream.prototype.start = function () {
|
|
|
141
145
|
}.bind(this)
|
|
142
146
|
)
|
|
143
147
|
|
|
144
|
-
const that = this
|
|
145
148
|
let pendingWrites = 0
|
|
146
149
|
const stdOutEvent = this.options.toStdout
|
|
147
150
|
if (stdOutEvent) {
|
|
148
|
-
(isArray(stdOutEvent) ? stdOutEvent : [stdOutEvent]).forEach(event => {
|
|
151
|
+
;(isArray(stdOutEvent) ? stdOutEvent : [stdOutEvent]).forEach((event) => {
|
|
149
152
|
const onDrain = () => {
|
|
150
153
|
pendingWrites--
|
|
151
154
|
}
|
|
152
155
|
|
|
153
|
-
that.options.app.on(event, d => {
|
|
156
|
+
that.options.app.on(event, (d) => {
|
|
154
157
|
if (pendingWrites > that.maxPendingWrites) {
|
|
155
|
-
debug('Buffer overflow, not writing:' + d)
|
|
158
|
+
that.debug('Buffer overflow, not writing:' + d)
|
|
156
159
|
return
|
|
157
160
|
}
|
|
158
|
-
debug('Writing:' + d)
|
|
159
|
-
if (
|
|
161
|
+
that.debug('Writing:' + d)
|
|
162
|
+
if (isBuffer(d)) {
|
|
160
163
|
that.serial.write(d)
|
|
161
164
|
} else {
|
|
162
165
|
that.serial.write(d + '\r\n')
|
|
163
|
-
}
|
|
166
|
+
}
|
|
164
167
|
pendingWrites++
|
|
165
168
|
that.serial.drain(onDrain)
|
|
166
169
|
})
|
|
@@ -182,7 +185,7 @@ SerialStream.prototype.scheduleReconnect = function () {
|
|
|
182
185
|
const msg = `Not connected (retry delay ${(
|
|
183
186
|
this.reconnectDelay / 1000
|
|
184
187
|
).toFixed(0)} s)`
|
|
185
|
-
debug(msg)
|
|
188
|
+
this.debug(msg)
|
|
186
189
|
this.options.app.setProviderStatus(this.options.providerId, msg)
|
|
187
190
|
setTimeout(this.start.bind(this), this.reconnectDelay)
|
|
188
191
|
}
|
|
Binary file
|
package/simple.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const Transform = require('stream').Transform
|
|
2
2
|
const Writable = require('stream').Writable
|
|
3
3
|
const _ = require('lodash')
|
|
4
|
-
const debug = require('debug')('signalk:simple')
|
|
5
4
|
const N2kAnalyzer = require('./n2kAnalyzer')
|
|
6
5
|
const FromJson = require('./from_json')
|
|
7
6
|
const MultiplexedLog = require('./multiplexedlog')
|
|
@@ -24,12 +23,17 @@ const Ydwg02 = require('@canboat/canboatjs').Ydwg02
|
|
|
24
23
|
const gpsd = require('./gpsd')
|
|
25
24
|
const pigpioSeatalk = require('./pigpio-seatalk')
|
|
26
25
|
|
|
27
|
-
function Simple
|
|
26
|
+
function Simple(options) {
|
|
28
27
|
Transform.call(this, { objectMode: true })
|
|
29
28
|
|
|
30
|
-
const { emitPropertyValue, onPropertyValues } = options
|
|
29
|
+
const { emitPropertyValue, onPropertyValues, createDebug } = options
|
|
31
30
|
options = { ...options }
|
|
32
|
-
options.subOptions = {
|
|
31
|
+
options.subOptions = {
|
|
32
|
+
...options.subOptions,
|
|
33
|
+
emitPropertyValue,
|
|
34
|
+
onPropertyValues,
|
|
35
|
+
createDebug,
|
|
36
|
+
}
|
|
33
37
|
|
|
34
38
|
options.subOptions.providerId = options.providerId
|
|
35
39
|
const dataType = options.subOptions.dataType || options.type
|
|
@@ -57,14 +61,18 @@ function Simple (options) {
|
|
|
57
61
|
options.subOptions.type === 'canbus-canboatjs'
|
|
58
62
|
) {
|
|
59
63
|
mappingType = 'NMEA2000JS'
|
|
60
|
-
} else if (
|
|
61
|
-
|
|
64
|
+
} else if (
|
|
65
|
+
options.subOptions.type === 'ikonvert-canboatjs' ||
|
|
66
|
+
options.subOptions.type === 'navlink2-tcp-canboatjs'
|
|
67
|
+
) {
|
|
62
68
|
mappingType = 'NMEA2000IK'
|
|
63
|
-
} else if (
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
} else if (
|
|
70
|
+
options.subOptions.type === 'ydwg02-canboatjs' ||
|
|
71
|
+
options.subOptions.type === 'ydwg02-udp-canboatjs' ||
|
|
72
|
+
options.subOptions.type === 'ydwg02-usb-canboatjs'
|
|
73
|
+
) {
|
|
66
74
|
mappingType = 'NMEA2000YD'
|
|
67
|
-
}
|
|
75
|
+
}
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
const pipeline = [].concat(
|
|
@@ -99,8 +107,8 @@ const getLogger = (app, logging, discriminator) =>
|
|
|
99
107
|
? [
|
|
100
108
|
new Log({
|
|
101
109
|
app: app,
|
|
102
|
-
discriminator
|
|
103
|
-
})
|
|
110
|
+
discriminator,
|
|
111
|
+
}),
|
|
104
112
|
]
|
|
105
113
|
: []
|
|
106
114
|
|
|
@@ -111,73 +119,77 @@ const discriminatorByDataType = {
|
|
|
111
119
|
NMEA2000: 'A',
|
|
112
120
|
NMEA0183: 'N',
|
|
113
121
|
SignalK: 'I',
|
|
114
|
-
Seatalk: 'N'
|
|
122
|
+
Seatalk: 'N',
|
|
115
123
|
}
|
|
116
124
|
|
|
117
125
|
const dataTypeMapping = {
|
|
118
|
-
SignalK: options =>
|
|
126
|
+
SignalK: (options) =>
|
|
119
127
|
options.subOptions.type !== 'wss' && options.subOptions.type !== 'ws'
|
|
120
128
|
? [new FromJson(options.subOptions)]
|
|
121
129
|
: [],
|
|
122
|
-
Seatalk:
|
|
123
|
-
|
|
130
|
+
Seatalk: (options) => [
|
|
131
|
+
new nmea0183_signalk({ ...options.subOptions, validateChecksum: false }),
|
|
132
|
+
],
|
|
133
|
+
NMEA0183: (options) => {
|
|
124
134
|
const result = [new nmea0183_signalk(options.subOptions)]
|
|
125
135
|
if (options.type === 'FileStream') {
|
|
126
136
|
result.unshift(
|
|
127
137
|
new Throttle({
|
|
128
|
-
rate: options.subOptions.throttleRate || 1000
|
|
138
|
+
rate: options.subOptions.throttleRate || 1000,
|
|
129
139
|
})
|
|
130
140
|
)
|
|
131
141
|
}
|
|
132
142
|
return result
|
|
133
143
|
},
|
|
134
|
-
NMEA2000: options => {
|
|
144
|
+
NMEA2000: (options) => {
|
|
135
145
|
const result = [new N2kAnalyzer(options.subOptions)]
|
|
136
146
|
if (options.type === 'FileStream') {
|
|
137
147
|
result.push(new TimestampThrottle())
|
|
138
148
|
}
|
|
139
149
|
return result.concat([new N2kToSignalK(options.subOptions)])
|
|
140
150
|
},
|
|
141
|
-
NMEA2000JS: options => {
|
|
151
|
+
NMEA2000JS: (options) => {
|
|
142
152
|
const result = [new CanboatJs(options.subOptions)]
|
|
143
153
|
if (options.type === 'FileStream') {
|
|
144
154
|
result.push(new TimestampThrottle())
|
|
145
155
|
}
|
|
146
156
|
return result.concat([new N2kToSignalK(options.subOptions)])
|
|
147
157
|
},
|
|
148
|
-
NMEA2000IK: options => {
|
|
158
|
+
NMEA2000IK: (options) => {
|
|
149
159
|
const result = [new CanboatJs(options.subOptions)]
|
|
150
160
|
if (options.type === 'FileStream') {
|
|
151
161
|
result.push(
|
|
152
162
|
new TimestampThrottle({
|
|
153
|
-
getMilliseconds: msg => {
|
|
163
|
+
getMilliseconds: (msg) => {
|
|
154
164
|
return msg.timer * 1000
|
|
155
|
-
}
|
|
165
|
+
},
|
|
156
166
|
})
|
|
157
167
|
)
|
|
158
168
|
} // else
|
|
159
169
|
{
|
|
160
170
|
let subOptions
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
else
|
|
166
|
-
{
|
|
171
|
+
if (options.subOptions.type === 'navlink2-tcp-canboatjs') {
|
|
172
|
+
subOptions = { ...options.subOptions, tcp: true }
|
|
173
|
+
} else {
|
|
167
174
|
subOptions = options.subOptions
|
|
168
175
|
}
|
|
169
176
|
result.unshift(new iKonvert(subOptions))
|
|
170
177
|
}
|
|
171
178
|
return result.concat([new N2kToSignalK(options.subOptions)])
|
|
172
179
|
},
|
|
173
|
-
NMEA2000YD: options => {
|
|
174
|
-
const result = [
|
|
180
|
+
NMEA2000YD: (options) => {
|
|
181
|
+
const result = [
|
|
182
|
+
new Ydwg02(
|
|
183
|
+
options.subOptions,
|
|
184
|
+
options.subOptions.type === 'ydwg02-usb-canboatjs' ? 'usb' : 'network'
|
|
185
|
+
),
|
|
186
|
+
]
|
|
175
187
|
if (options.type === 'FileStream') {
|
|
176
188
|
result.push(new TimestampThrottle())
|
|
177
189
|
}
|
|
178
190
|
return result.concat([new N2kToSignalK(options.subOptions)])
|
|
179
191
|
},
|
|
180
|
-
Multiplexed: options => [new MultiplexedLog(options.subOptions)]
|
|
192
|
+
Multiplexed: (options) => [new MultiplexedLog(options.subOptions)],
|
|
181
193
|
}
|
|
182
194
|
|
|
183
195
|
const pipeStartByType = {
|
|
@@ -186,28 +198,28 @@ const pipeStartByType = {
|
|
|
186
198
|
Execute: executeInput,
|
|
187
199
|
FileStream: fileInput,
|
|
188
200
|
SignalK: signalKInput,
|
|
189
|
-
Seatalk: seatalkInput
|
|
201
|
+
Seatalk: seatalkInput,
|
|
190
202
|
}
|
|
191
203
|
|
|
192
|
-
function nmea2000input
|
|
204
|
+
function nmea2000input(subOptions, logging) {
|
|
193
205
|
if (subOptions.type === 'ngt-1-canboatjs') {
|
|
194
206
|
const actisenseSerial = require('./actisense-serial')
|
|
195
|
-
if (
|
|
207
|
+
if (!actisenseSerial) {
|
|
196
208
|
throw new Error('unable to load actisense serial')
|
|
197
209
|
}
|
|
198
210
|
return [
|
|
199
211
|
new actisenseSerial({
|
|
200
212
|
...subOptions,
|
|
201
213
|
outEvent: 'nmea2000out',
|
|
202
|
-
plainText: logging
|
|
203
|
-
})
|
|
214
|
+
plainText: logging,
|
|
215
|
+
}),
|
|
204
216
|
]
|
|
205
217
|
} else if (subOptions.type === 'canbus-canboatjs') {
|
|
206
218
|
return [
|
|
207
219
|
new require('./canbus')({
|
|
208
220
|
...subOptions,
|
|
209
221
|
canDevice: subOptions.interface,
|
|
210
|
-
})
|
|
222
|
+
}),
|
|
211
223
|
]
|
|
212
224
|
} else if (subOptions.type === 'ikonvert-canboatjs') {
|
|
213
225
|
const serialport = require('./serialport')
|
|
@@ -215,22 +227,28 @@ function nmea2000input (subOptions, logging) {
|
|
|
215
227
|
new serialport({
|
|
216
228
|
...subOptions,
|
|
217
229
|
baudrate: 230400,
|
|
218
|
-
toStdout: 'ikonvertOut'
|
|
219
|
-
})
|
|
230
|
+
toStdout: 'ikonvertOut',
|
|
231
|
+
}),
|
|
220
232
|
]
|
|
221
233
|
} else if (subOptions.type === 'ydwg02-canboatjs') {
|
|
222
|
-
return [
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
234
|
+
return [
|
|
235
|
+
new Tcp({
|
|
236
|
+
...subOptions,
|
|
237
|
+
outEvent: 'ydwg02-out',
|
|
238
|
+
}),
|
|
239
|
+
new Liner(subOptions),
|
|
240
|
+
]
|
|
226
241
|
} else if (subOptions.type === 'ydwg02-udp-canboatjs') {
|
|
227
242
|
return [new Udp(subOptions), new Liner(subOptions)]
|
|
228
243
|
} else if (subOptions.type === 'navlink2-tcp-canboatjs') {
|
|
229
|
-
return [
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
244
|
+
return [
|
|
245
|
+
new Tcp({
|
|
246
|
+
...subOptions,
|
|
247
|
+
outEvent: 'navlink2-out',
|
|
248
|
+
}),
|
|
249
|
+
new Liner(subOptions),
|
|
250
|
+
]
|
|
251
|
+
} else if (subOptions.type === 'navlink2-udp-canboatjs') {
|
|
234
252
|
return [new Udp(subOptions), new Liner(subOptions)]
|
|
235
253
|
} else if (subOptions.type === 'ydwg02-usb-canboatjs') {
|
|
236
254
|
const serialport = require('./serialport')
|
|
@@ -238,8 +256,8 @@ function nmea2000input (subOptions, logging) {
|
|
|
238
256
|
new serialport({
|
|
239
257
|
...subOptions,
|
|
240
258
|
baudrate: 38400,
|
|
241
|
-
toStdout: 'ydwg02-out'
|
|
242
|
-
})
|
|
259
|
+
toStdout: 'ydwg02-out',
|
|
260
|
+
}),
|
|
243
261
|
]
|
|
244
262
|
} else {
|
|
245
263
|
let command
|
|
@@ -260,14 +278,14 @@ function nmea2000input (subOptions, logging) {
|
|
|
260
278
|
command: command,
|
|
261
279
|
toChildProcess: toChildProcess,
|
|
262
280
|
app: subOptions.app,
|
|
263
|
-
providerId: subOptions.providerId
|
|
281
|
+
providerId: subOptions.providerId,
|
|
264
282
|
}),
|
|
265
|
-
new Liner(subOptions)
|
|
283
|
+
new Liner(subOptions),
|
|
266
284
|
]
|
|
267
285
|
}
|
|
268
286
|
}
|
|
269
287
|
|
|
270
|
-
function nmea0183input
|
|
288
|
+
function nmea0183input(subOptions) {
|
|
271
289
|
let pipePart
|
|
272
290
|
if (subOptions.type === 'tcp') {
|
|
273
291
|
pipePart = [new Tcp(subOptions), new Liner(subOptions)]
|
|
@@ -284,19 +302,23 @@ function nmea0183input (subOptions) {
|
|
|
284
302
|
|
|
285
303
|
if (pipePart) {
|
|
286
304
|
if (subOptions.removeNulls) {
|
|
287
|
-
pipePart.push(
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
305
|
+
pipePart.push(
|
|
306
|
+
new Replacer({
|
|
307
|
+
regexp: '\u0000',
|
|
308
|
+
template: '',
|
|
309
|
+
})
|
|
310
|
+
)
|
|
291
311
|
}
|
|
292
312
|
if (subOptions.ignoredSentences) {
|
|
293
313
|
console.log(subOptions.ignoredSentences)
|
|
294
|
-
subOptions.ignoredSentences.forEach(sentence => {
|
|
314
|
+
subOptions.ignoredSentences.forEach((sentence) => {
|
|
295
315
|
if (sentence.length > 0) {
|
|
296
|
-
pipePart.push(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
316
|
+
pipePart.push(
|
|
317
|
+
new Replacer({
|
|
318
|
+
regexp: `^...${sentence}.*`,
|
|
319
|
+
template: '',
|
|
320
|
+
})
|
|
321
|
+
)
|
|
300
322
|
}
|
|
301
323
|
})
|
|
302
324
|
}
|
|
@@ -306,17 +328,17 @@ function nmea0183input (subOptions) {
|
|
|
306
328
|
}
|
|
307
329
|
}
|
|
308
330
|
|
|
309
|
-
function executeInput
|
|
331
|
+
function executeInput(subOptions) {
|
|
310
332
|
return [new execute(subOptions), new Liner(subOptions)]
|
|
311
333
|
}
|
|
312
334
|
|
|
313
|
-
function fileInput
|
|
335
|
+
function fileInput(subOptions) {
|
|
314
336
|
const result = [new FileStream(subOptions)]
|
|
315
337
|
result.push(new Liner(subOptions))
|
|
316
338
|
return result
|
|
317
339
|
}
|
|
318
340
|
|
|
319
|
-
function signalKInput
|
|
341
|
+
function signalKInput(subOptions) {
|
|
320
342
|
if (subOptions.type === 'ws' || subOptions.type === 'wss') {
|
|
321
343
|
const mdns_ws = require('./mdns-ws')
|
|
322
344
|
return [new mdns_ws(subOptions)]
|
package/splitting-liner.js
CHANGED
|
@@ -28,9 +28,9 @@ const Transform = require('stream').Transform
|
|
|
28
28
|
|
|
29
29
|
require('util').inherits(SplittingLiner, Transform)
|
|
30
30
|
|
|
31
|
-
function SplittingLiner
|
|
31
|
+
function SplittingLiner(options) {
|
|
32
32
|
Transform.call(this, {
|
|
33
|
-
objectMode: true
|
|
33
|
+
objectMode: true,
|
|
34
34
|
})
|
|
35
35
|
this.doPush = this.push.bind(this)
|
|
36
36
|
this.lineSeparator = options.lineSeparator || '\n'
|
package/tcp.js
CHANGED
|
@@ -32,23 +32,25 @@ const net = require('net')
|
|
|
32
32
|
const Transform = require('stream').Transform
|
|
33
33
|
const isArray = require('lodash').isArray
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
const debugData = require('debug')('signalk-server:streams:tcp-data')
|
|
37
|
-
|
|
38
|
-
function TcpStream (options) {
|
|
35
|
+
function TcpStream(options) {
|
|
39
36
|
Transform.call(this, options)
|
|
40
37
|
this.options = options
|
|
41
|
-
this.noDataReceivedTimeout =
|
|
38
|
+
this.noDataReceivedTimeout =
|
|
39
|
+
Number.parseInt((this.options.noDataReceivedTimeout + '').trim()) * 1000
|
|
40
|
+
this.debug = (options.createDebug || require('debug'))('signalk:streams:tcp')
|
|
41
|
+
this.debugData = (options.createDebug || require('debug'))(
|
|
42
|
+
'signalk:streams:tcp-data'
|
|
43
|
+
)
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
require('util').inherits(TcpStream, Transform)
|
|
45
47
|
|
|
46
48
|
TcpStream.prototype.pipe = function (pipeTo) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
const that = this
|
|
50
|
+
if (this.options.outEvent) {
|
|
49
51
|
that.options.app.on(that.options.outEvent, function (d) {
|
|
50
|
-
if (
|
|
51
|
-
debug('sending %s', d)
|
|
52
|
+
if (that.tcpStream) {
|
|
53
|
+
that.debug('sending %s', d)
|
|
52
54
|
that.tcpStream.write(d)
|
|
53
55
|
}
|
|
54
56
|
})
|
|
@@ -56,57 +58,57 @@ TcpStream.prototype.pipe = function (pipeTo) {
|
|
|
56
58
|
|
|
57
59
|
const stdOutEvent = this.options.toStdout
|
|
58
60
|
if (stdOutEvent) {
|
|
59
|
-
const that = this
|
|
60
|
-
(isArray(stdOutEvent) ? stdOutEvent : [stdOutEvent]).forEach(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
that.tcpStream
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
const that = this //semicolon required here
|
|
62
|
+
;(isArray(stdOutEvent) ? stdOutEvent : [stdOutEvent]).forEach(
|
|
63
|
+
(stdEvent) => {
|
|
64
|
+
that.options.app.on(stdEvent, function (d) {
|
|
65
|
+
if (that.tcpStream) {
|
|
66
|
+
that.tcpStream.write(d + '\r\n')
|
|
67
|
+
that.debug('event %s sending %s', stdEvent, d)
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
)
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
const re = require('reconnect-core')(function () {
|
|
71
75
|
return net.connect.apply(null, arguments)
|
|
72
|
-
})({ maxDelay: 5 * 1000 }, tcpStream => {
|
|
76
|
+
})({ maxDelay: 5 * 1000 }, (tcpStream) => {
|
|
73
77
|
if (!isNaN(this.noDataReceivedTimeout)) {
|
|
74
78
|
tcpStream.setTimeout(this.noDataReceivedTimeout)
|
|
75
|
-
debug(
|
|
79
|
+
that.debug(
|
|
76
80
|
`Setting socket idle timeout ${this.options.host}:${this.options.port} ${this.noDataReceivedTimeout}`
|
|
77
81
|
)
|
|
78
82
|
tcpStream.on('timeout', () => {
|
|
79
|
-
debug(
|
|
83
|
+
that.debug(
|
|
80
84
|
`Idle timeout, closing socket ${this.options.host}:${this.options.port}`
|
|
81
85
|
)
|
|
82
86
|
tcpStream.end()
|
|
83
87
|
})
|
|
84
88
|
}
|
|
85
|
-
tcpStream.on('data', data => {
|
|
86
|
-
if (debugData.enabled) {
|
|
87
|
-
debugData(data.toString())
|
|
89
|
+
tcpStream.on('data', (data) => {
|
|
90
|
+
if (that.debugData.enabled) {
|
|
91
|
+
that.debugData(data.toString())
|
|
88
92
|
}
|
|
89
93
|
this.write(data)
|
|
90
94
|
})
|
|
91
95
|
})
|
|
92
|
-
.on('connect', con => {
|
|
96
|
+
.on('connect', (con) => {
|
|
93
97
|
this.tcpStream = con
|
|
94
98
|
const msg = `Connected to ${this.options.host} ${this.options.port}`
|
|
95
99
|
this.options.app.setProviderStatus(this.options.providerId, msg)
|
|
96
|
-
debug(msg)
|
|
100
|
+
that.debug(msg)
|
|
97
101
|
})
|
|
98
102
|
.on('reconnect', (n, delay) => {
|
|
99
|
-
const msg = `Reconnect ${this.options.host} ${
|
|
100
|
-
this.options.port
|
|
101
|
-
} retry ${n} delay ${delay}`
|
|
103
|
+
const msg = `Reconnect ${this.options.host} ${this.options.port} retry ${n} delay ${delay}`
|
|
102
104
|
this.options.app.setProviderError(this.options.providerId, msg)
|
|
103
|
-
debug(msg)
|
|
105
|
+
that.debug(msg)
|
|
104
106
|
})
|
|
105
|
-
.on('disconnect', err => {
|
|
107
|
+
.on('disconnect', (err) => {
|
|
106
108
|
delete this.tcpStream
|
|
107
|
-
debug(`Disconnected ${this.options.host} ${this.options.port}`)
|
|
109
|
+
that.debug(`Disconnected ${this.options.host} ${this.options.port}`)
|
|
108
110
|
})
|
|
109
|
-
.on('error', err => {
|
|
111
|
+
.on('error', (err) => {
|
|
110
112
|
this.options.app.setProviderError(this.options.providerId, err.message)
|
|
111
113
|
console.error('TcpProvider:' + err.message)
|
|
112
114
|
})
|
package/tcpserver.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
const Transform = require('stream').Transform
|
|
23
23
|
|
|
24
|
-
function TcpServer
|
|
24
|
+
function TcpServer(options) {
|
|
25
25
|
Transform.call(this)
|
|
26
26
|
this.options = options
|
|
27
27
|
}
|
|
@@ -29,7 +29,7 @@ function TcpServer (options) {
|
|
|
29
29
|
require('util').inherits(TcpServer, Transform)
|
|
30
30
|
|
|
31
31
|
TcpServer.prototype.pipe = function (pipeTo) {
|
|
32
|
-
this.options.app.on('tcpserver0183data', d => this.write(d))
|
|
32
|
+
this.options.app.on('tcpserver0183data', (d) => this.write(d))
|
|
33
33
|
Transform.prototype.pipe.call(this, pipeTo)
|
|
34
34
|
}
|
|
35
35
|
|
package/timestamp-throttle.js
CHANGED
|
@@ -23,9 +23,9 @@ so that throughput rate is real time. Aimed at canboat analyzer output
|
|
|
23
23
|
rate control
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
function TimestampThrottle
|
|
26
|
+
function TimestampThrottle(options) {
|
|
27
27
|
Transform.call(this, {
|
|
28
|
-
objectMode: true
|
|
28
|
+
objectMode: true,
|
|
29
29
|
})
|
|
30
30
|
this.lastMsgMillis = new Date().getTime()
|
|
31
31
|
this.getMilliseconds =
|
|
@@ -55,7 +55,7 @@ TimestampThrottle.prototype._transform = function (msg, encoding, done) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function getMilliseconds
|
|
58
|
+
function getMilliseconds(msg) {
|
|
59
59
|
// 2014-08-15-16:00:00.083
|
|
60
60
|
return moment(msg.timestamp, 'YYYY-MM-DD-HH:mm:ss.SSS').valueOf()
|
|
61
61
|
}
|
package/udp.js
CHANGED
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
const Transform = require('stream').Transform
|
|
37
|
-
const debug = require('debug')('signalk:streams:udp')
|
|
38
37
|
|
|
39
|
-
function Udp
|
|
38
|
+
function Udp(options) {
|
|
40
39
|
Transform.call(this, {
|
|
41
|
-
objectMode: false
|
|
40
|
+
objectMode: false,
|
|
42
41
|
})
|
|
43
42
|
this.options = options
|
|
43
|
+
this.debug = (options.createDebug || require('debug'))('signalk:streams:udp')
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
require('util').inherits(Udp, Transform)
|
|
@@ -52,7 +52,7 @@ Udp.prototype.pipe = function (pipeTo) {
|
|
|
52
52
|
const socket = require('dgram').createSocket('udp4')
|
|
53
53
|
const self = this
|
|
54
54
|
socket.on('message', function (message, remote) {
|
|
55
|
-
debug(message.toString())
|
|
55
|
+
self.debug(message.toString())
|
|
56
56
|
self.push(message)
|
|
57
57
|
})
|
|
58
58
|
socket.bind(this.options.port)
|