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