@signalk/streams 5.1.4 → 6.1.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/dist/actisense-serial.d.ts +3 -0
- package/dist/actisense-serial.d.ts.map +1 -0
- package/dist/actisense-serial.js +4 -0
- package/dist/autodetect.d.ts +54 -0
- package/dist/autodetect.d.ts.map +1 -0
- package/dist/autodetect.js +186 -0
- package/dist/canboatjs.d.ts +25 -0
- package/dist/canboatjs.d.ts.map +1 -0
- package/dist/canboatjs.js +57 -0
- package/dist/canbus.d.ts +3 -0
- package/dist/canbus.d.ts.map +1 -0
- package/dist/canbus.js +4 -0
- package/dist/execute.d.ts +34 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +101 -0
- package/dist/filestream.d.ts +24 -0
- package/dist/filestream.d.ts.map +1 -0
- package/dist/filestream.js +58 -0
- package/dist/folderstream.d.ts +12 -0
- package/dist/folderstream.d.ts.map +1 -0
- package/dist/folderstream.js +36 -0
- package/dist/from_json.d.ts +6 -0
- package/dist/from_json.d.ts.map +1 -0
- package/dist/from_json.js +22 -0
- package/dist/gpiod-seatalk.d.ts +19 -0
- package/dist/gpiod-seatalk.d.ts.map +1 -0
- package/{gpiod-seatalk.js → dist/gpiod-seatalk.js} +18 -16
- package/dist/gpsd.d.ts +23 -0
- package/dist/gpsd.d.ts.map +1 -0
- package/dist/gpsd.js +55 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/keys-filter.d.ts +27 -0
- package/dist/keys-filter.d.ts.map +1 -0
- package/dist/keys-filter.js +59 -0
- package/dist/liner.d.ts +14 -0
- package/dist/liner.d.ts.map +1 -0
- package/dist/liner.js +35 -0
- package/dist/log.d.ts +15 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +17 -0
- package/dist/logging.d.ts +14 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +125 -0
- package/dist/mdns-ws.d.ts +39 -0
- package/dist/mdns-ws.d.ts.map +1 -0
- package/dist/mdns-ws.js +180 -0
- package/dist/multiplexedlog.d.ts +3 -0
- package/dist/multiplexedlog.d.ts.map +1 -0
- package/dist/multiplexedlog.js +7 -0
- package/dist/n2k-signalk.d.ts +39 -0
- package/dist/n2k-signalk.d.ts.map +1 -0
- package/dist/n2k-signalk.js +180 -0
- package/dist/n2kAnalyzer.d.ts +19 -0
- package/dist/n2kAnalyzer.d.ts.map +1 -0
- package/dist/n2kAnalyzer.js +61 -0
- package/dist/nmea0183-signalk.d.ts +33 -0
- package/dist/nmea0183-signalk.d.ts.map +1 -0
- package/dist/nmea0183-signalk.js +105 -0
- package/dist/nullprovider.d.ts +5 -0
- package/dist/nullprovider.d.ts.map +1 -0
- package/dist/nullprovider.js +9 -0
- package/dist/pigpio-seatalk.d.ts +19 -0
- package/dist/pigpio-seatalk.d.ts.map +1 -0
- package/{pigpio-seatalk.js → dist/pigpio-seatalk.js} +21 -18
- package/dist/replacer.d.ts +13 -0
- package/dist/replacer.d.ts.map +1 -0
- package/dist/replacer.js +20 -0
- package/dist/s3.d.ts +13 -0
- package/dist/s3.d.ts.map +1 -0
- package/dist/s3.js +82 -0
- package/dist/serialport.d.ts +35 -0
- package/dist/serialport.d.ts.map +1 -0
- package/dist/serialport.js +129 -0
- package/dist/simple.d.ts +78 -0
- package/dist/simple.d.ts.map +1 -0
- package/dist/simple.js +446 -0
- package/dist/splitting-liner.d.ts +12 -0
- package/dist/splitting-liner.d.ts.map +1 -0
- package/dist/splitting-liner.js +19 -0
- package/dist/tcp.d.ts +33 -0
- package/dist/tcp.d.ts.map +1 -0
- package/dist/tcp.js +117 -0
- package/dist/tcpserver.d.ts +14 -0
- package/dist/tcpserver.d.ts.map +1 -0
- package/dist/tcpserver.js +18 -0
- package/dist/test-helpers.d.ts +52 -0
- package/dist/test-helpers.d.ts.map +1 -0
- package/dist/test-helpers.js +73 -0
- package/dist/throttle.d.ts +3 -0
- package/dist/throttle.d.ts.map +1 -0
- package/dist/throttle.js +4 -0
- package/dist/timestamp-throttle.d.ts +17 -0
- package/dist/timestamp-throttle.d.ts.map +1 -0
- package/dist/timestamp-throttle.js +41 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/udp.d.ts +27 -0
- package/dist/udp.d.ts.map +1 -0
- package/dist/udp.js +55 -0
- package/package.json +48 -5
- package/actisense-serial.js +0 -1
- package/autodetect.js +0 -201
- package/canboatjs.js +0 -71
- package/canbus.js +0 -17
- package/execute.js +0 -137
- package/filestream.js +0 -90
- package/folderstream.js +0 -36
- package/from_json.js +0 -51
- package/gpsd.js +0 -94
- package/keys-filter.js +0 -81
- package/liner.js +0 -68
- package/log.js +0 -51
- package/logging.js +0 -149
- package/mdns-ws.js +0 -167
- package/multiplexedlog.js +0 -3
- package/n2k-signalk.js +0 -197
- package/n2kAnalyzer.js +0 -82
- package/nmea0183-signalk.js +0 -119
- package/nullprovider.js +0 -31
- package/replacer.js +0 -57
- package/s3.js +0 -87
- package/serialport.js +0 -209
- package/simple.js +0 -448
- package/splitting-liner.js +0 -46
- package/tcp.js +0 -138
- package/tcpserver.js +0 -40
- package/throttle.js +0 -31
- package/timestamp-throttle.js +0 -63
- package/udp.js +0 -95
package/simple.js
DELETED
|
@@ -1,448 +0,0 @@
|
|
|
1
|
-
const Transform = require('stream').Transform
|
|
2
|
-
const _ = require('lodash')
|
|
3
|
-
const N2kAnalyzer = require('./n2kAnalyzer')
|
|
4
|
-
const FromJson = require('./from_json')
|
|
5
|
-
const MultiplexedLog = require('./multiplexedlog')
|
|
6
|
-
const nmea0183_signalk = require('./nmea0183-signalk')
|
|
7
|
-
const N2kToSignalK = require('./n2k-signalk')
|
|
8
|
-
const Log = require('./log')
|
|
9
|
-
const Liner = require('./liner')
|
|
10
|
-
const SplittingLiner = require('./splitting-liner')
|
|
11
|
-
const execute = require('./execute')
|
|
12
|
-
const Udp = require('./udp')
|
|
13
|
-
const Tcp = require('./tcp')
|
|
14
|
-
const TcpServer = require('./tcpserver')
|
|
15
|
-
const FileStream = require('./filestream')
|
|
16
|
-
const Replacer = require('./replacer')
|
|
17
|
-
const Throttle = require('./throttle')
|
|
18
|
-
const TimestampThrottle = require('./timestamp-throttle')
|
|
19
|
-
const CanboatJs = require('./canboatjs')
|
|
20
|
-
const iKonvert = require('@canboat/canboatjs').iKonvert
|
|
21
|
-
const Ydwg02 = require('@canboat/canboatjs').Ydwg02
|
|
22
|
-
const W2k01 = require('@canboat/canboatjs').W2k01
|
|
23
|
-
const gpsd = require('./gpsd')
|
|
24
|
-
const pigpioSeatalk = require('./pigpio-seatalk')
|
|
25
|
-
const gpiodSeatalk = require('./gpiod-seatalk')
|
|
26
|
-
|
|
27
|
-
function Simple(options) {
|
|
28
|
-
Transform.call(this, { objectMode: true })
|
|
29
|
-
|
|
30
|
-
const { emitPropertyValue, onPropertyValues, createDebug } = options
|
|
31
|
-
options = { ...options }
|
|
32
|
-
options.subOptions = {
|
|
33
|
-
...options.subOptions,
|
|
34
|
-
emitPropertyValue,
|
|
35
|
-
onPropertyValues,
|
|
36
|
-
createDebug
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
options.subOptions.providerId = options.providerId
|
|
40
|
-
const dataType = options.subOptions.dataType || options.type
|
|
41
|
-
if (!dataType) {
|
|
42
|
-
throw new Error(`Unknown data type for ${options.type}`)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (!pipeStartByType[options.type]) {
|
|
46
|
-
throw new Error(`Invalid input type: ${options.type}`)
|
|
47
|
-
}
|
|
48
|
-
if (!dataTypeMapping[dataType]) {
|
|
49
|
-
throw new Error(`Unknown data type: ${dataType}`)
|
|
50
|
-
}
|
|
51
|
-
if (dataType !== 'Multiplexed' && !discriminatorByDataType[dataType]) {
|
|
52
|
-
throw new Error(`No discriminator for: ${dataType}`)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
options.subOptions.app = options.app
|
|
56
|
-
|
|
57
|
-
let mappingType = dataType
|
|
58
|
-
|
|
59
|
-
if (options.type === 'NMEA2000' && options.subOptions) {
|
|
60
|
-
if (
|
|
61
|
-
options.subOptions.type === 'ngt-1-canboatjs' ||
|
|
62
|
-
options.subOptions.type === 'canbus-canboatjs' ||
|
|
63
|
-
options.subOptions.type === 'w2k-1-n2k-actisense-canboatjs' ||
|
|
64
|
-
options.subOptions.type === 'w2k-1-n2k-ascii-canboatjs'
|
|
65
|
-
) {
|
|
66
|
-
mappingType = 'NMEA2000JS'
|
|
67
|
-
} else if (
|
|
68
|
-
options.subOptions.type === 'ikonvert-canboatjs' ||
|
|
69
|
-
options.subOptions.type === 'navlink2-tcp-canboatjs'
|
|
70
|
-
) {
|
|
71
|
-
mappingType = 'NMEA2000IK'
|
|
72
|
-
} else if (
|
|
73
|
-
options.subOptions.type === 'ydwg02-canboatjs' ||
|
|
74
|
-
options.subOptions.type === 'ydwg02-udp-canboatjs' ||
|
|
75
|
-
options.subOptions.type === 'ydwg02-usb-canboatjs'
|
|
76
|
-
) {
|
|
77
|
-
mappingType = 'NMEA2000YD'
|
|
78
|
-
}
|
|
79
|
-
options.app.on('nmea2000out', () => {
|
|
80
|
-
setImmediate(() =>
|
|
81
|
-
options.app.emit('connectionwrite', { providerId: options.providerId })
|
|
82
|
-
)
|
|
83
|
-
})
|
|
84
|
-
options.app.on('nmea2000JsonOut', () => {
|
|
85
|
-
setImmediate(() =>
|
|
86
|
-
options.app.emit('connectionwrite', { providerId: options.providerId })
|
|
87
|
-
)
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const pipeline = [].concat(
|
|
92
|
-
pipeStartByType[options.type](options.subOptions, options.logging),
|
|
93
|
-
getLogger(options.app, options.logging, discriminatorByDataType[dataType]),
|
|
94
|
-
dataTypeMapping[mappingType](options)
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
const dataReceivedEventName = `${options.subOptions.providerId}-received`
|
|
98
|
-
|
|
99
|
-
const spy = new Transform({
|
|
100
|
-
objectMode: true,
|
|
101
|
-
transform(chunk, encoding, callback) {
|
|
102
|
-
options.app.emit(dataReceivedEventName, chunk)
|
|
103
|
-
callback(null, chunk)
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
pipeline.splice(pipeline.length - 1, 0, spy)
|
|
107
|
-
|
|
108
|
-
options.subOptions.app.emitPropertyValue('pipedprovider', {
|
|
109
|
-
id: options.subOptions.providerId,
|
|
110
|
-
type: mappingType,
|
|
111
|
-
eventNames: {
|
|
112
|
-
received: dataReceivedEventName
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
if (options.subOptions.overrideTimestamp) {
|
|
117
|
-
pipeline.push(
|
|
118
|
-
new Transform({
|
|
119
|
-
objectMode: true,
|
|
120
|
-
transform(delta, encoding, callback) {
|
|
121
|
-
if (delta.updates) {
|
|
122
|
-
const now = new Date().toISOString()
|
|
123
|
-
delta.updates.forEach((update) => {
|
|
124
|
-
update.timestamp = now
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
callback(null, delta)
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
for (let i = pipeline.length - 2; i >= 0; i--) {
|
|
134
|
-
pipeline[i].pipe(pipeline[i + 1])
|
|
135
|
-
}
|
|
136
|
-
pipeline[pipeline.length - 1].pipe(this)
|
|
137
|
-
|
|
138
|
-
this.pipeline = pipeline
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
require('util').inherits(Simple, Transform)
|
|
142
|
-
|
|
143
|
-
Simple.prototype._transform = function (msg, encoding, done) {
|
|
144
|
-
this.push(msg)
|
|
145
|
-
done()
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
Simple.prototype.end = function () {
|
|
149
|
-
this.pipeline[0].end()
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
module.exports = Simple
|
|
153
|
-
|
|
154
|
-
const getLogger = (app, logging, discriminator) =>
|
|
155
|
-
logging
|
|
156
|
-
? [
|
|
157
|
-
new Log({
|
|
158
|
-
app: app,
|
|
159
|
-
discriminator
|
|
160
|
-
})
|
|
161
|
-
]
|
|
162
|
-
: []
|
|
163
|
-
|
|
164
|
-
const discriminatorByDataType = {
|
|
165
|
-
NMEA2000JS: 'A',
|
|
166
|
-
NMEA2000IK: 'A',
|
|
167
|
-
NMEA2000YD: 'A',
|
|
168
|
-
NMEA2000: 'A',
|
|
169
|
-
NMEA0183: 'N',
|
|
170
|
-
SignalK: 'I',
|
|
171
|
-
Seatalk: 'N'
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const dataTypeMapping = {
|
|
175
|
-
SignalK: (options) =>
|
|
176
|
-
options.subOptions.type !== 'wss' && options.subOptions.type !== 'ws'
|
|
177
|
-
? [new FromJson(options.subOptions)]
|
|
178
|
-
: [],
|
|
179
|
-
Seatalk: (options) => [
|
|
180
|
-
new nmea0183_signalk({ ...options.subOptions, validateChecksum: false })
|
|
181
|
-
],
|
|
182
|
-
NMEA0183: (options) => {
|
|
183
|
-
const result = [new nmea0183_signalk(options.subOptions)]
|
|
184
|
-
if (options.type === 'FileStream') {
|
|
185
|
-
result.unshift(
|
|
186
|
-
new Throttle({
|
|
187
|
-
rate: options.subOptions.throttleRate || 1000,
|
|
188
|
-
chunksize: options.subOptions.throttleRate || 1000
|
|
189
|
-
})
|
|
190
|
-
)
|
|
191
|
-
}
|
|
192
|
-
return result
|
|
193
|
-
},
|
|
194
|
-
NMEA2000: (options) => {
|
|
195
|
-
const result = [new N2kAnalyzer(options.subOptions)]
|
|
196
|
-
if (options.type === 'FileStream') {
|
|
197
|
-
result.push(new TimestampThrottle())
|
|
198
|
-
}
|
|
199
|
-
return result.concat([new N2kToSignalK(options.subOptions)])
|
|
200
|
-
},
|
|
201
|
-
NMEA2000JS: (options) => {
|
|
202
|
-
const result = [new CanboatJs(options.subOptions)]
|
|
203
|
-
if (options.type === 'FileStream') {
|
|
204
|
-
result.push(new TimestampThrottle())
|
|
205
|
-
}
|
|
206
|
-
return result.concat([new N2kToSignalK(options.subOptions)])
|
|
207
|
-
},
|
|
208
|
-
NMEA2000IK: (options) => {
|
|
209
|
-
const result = [new CanboatJs(options.subOptions)]
|
|
210
|
-
if (options.type === 'FileStream') {
|
|
211
|
-
result.push(
|
|
212
|
-
new TimestampThrottle({
|
|
213
|
-
getMilliseconds: (msg) => {
|
|
214
|
-
return msg.timer * 1000
|
|
215
|
-
}
|
|
216
|
-
})
|
|
217
|
-
)
|
|
218
|
-
} // else
|
|
219
|
-
{
|
|
220
|
-
let subOptions
|
|
221
|
-
if (options.subOptions.type === 'navlink2-tcp-canboatjs') {
|
|
222
|
-
subOptions = { ...options.subOptions, tcp: true }
|
|
223
|
-
} else {
|
|
224
|
-
subOptions = options.subOptions
|
|
225
|
-
}
|
|
226
|
-
result.unshift(new iKonvert(subOptions))
|
|
227
|
-
}
|
|
228
|
-
return result.concat([new N2kToSignalK(options.subOptions)])
|
|
229
|
-
},
|
|
230
|
-
NMEA2000YD: (options) => {
|
|
231
|
-
const result = [
|
|
232
|
-
new Ydwg02(
|
|
233
|
-
{ ...options.subOptions },
|
|
234
|
-
options.subOptions.type === 'ydwg02-usb-canboatjs' ? 'usb' : 'network'
|
|
235
|
-
)
|
|
236
|
-
]
|
|
237
|
-
if (options.type === 'FileStream') {
|
|
238
|
-
result.push(new TimestampThrottle())
|
|
239
|
-
}
|
|
240
|
-
return result.concat([new N2kToSignalK(options.subOptions)])
|
|
241
|
-
},
|
|
242
|
-
NMEA2000W2K_ASCII: (options) => {
|
|
243
|
-
const result = [new W2k01({ format: 'ascii', ...options.subOptions })]
|
|
244
|
-
if (options.type === 'FileStream') {
|
|
245
|
-
result.push(new TimestampThrottle())
|
|
246
|
-
}
|
|
247
|
-
return result.concat([new N2kToSignalK(options.subOptions)])
|
|
248
|
-
},
|
|
249
|
-
NMEA2000W2K_ACTISENSE: (options) => {
|
|
250
|
-
const result = [new W2k01({ format: 'actisense', ...options.subOptions })]
|
|
251
|
-
if (options.type === 'FileStream') {
|
|
252
|
-
result.push(new TimestampThrottle())
|
|
253
|
-
}
|
|
254
|
-
return result.concat([new N2kToSignalK(options.subOptions)])
|
|
255
|
-
},
|
|
256
|
-
Multiplexed: (options) => [new MultiplexedLog(options.subOptions)]
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const pipeStartByType = {
|
|
260
|
-
NMEA2000: nmea2000input,
|
|
261
|
-
NMEA0183: nmea0183input,
|
|
262
|
-
Execute: executeInput,
|
|
263
|
-
FileStream: fileInput,
|
|
264
|
-
SignalK: signalKInput,
|
|
265
|
-
Seatalk: seatalkInput
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function nmea2000input(subOptions, logging) {
|
|
269
|
-
if (subOptions.type === 'ngt-1-canboatjs') {
|
|
270
|
-
const actisenseSerial = require('./actisense-serial')
|
|
271
|
-
if (!actisenseSerial) {
|
|
272
|
-
throw new Error('unable to load actisense serial')
|
|
273
|
-
}
|
|
274
|
-
return [
|
|
275
|
-
new actisenseSerial({
|
|
276
|
-
...subOptions,
|
|
277
|
-
plainText: logging
|
|
278
|
-
})
|
|
279
|
-
]
|
|
280
|
-
} else if (subOptions.type === 'canbus-canboatjs') {
|
|
281
|
-
return [
|
|
282
|
-
new require('./canbus')({
|
|
283
|
-
...subOptions,
|
|
284
|
-
canDevice: subOptions.interface
|
|
285
|
-
})
|
|
286
|
-
]
|
|
287
|
-
} else if (subOptions.type === 'ikonvert-canboatjs') {
|
|
288
|
-
const serialport = require('./serialport')
|
|
289
|
-
return [
|
|
290
|
-
new serialport({
|
|
291
|
-
...subOptions,
|
|
292
|
-
baudrate: 230400,
|
|
293
|
-
toStdout: 'ikonvertOut'
|
|
294
|
-
})
|
|
295
|
-
]
|
|
296
|
-
} else if (subOptions.type === 'ydwg02-canboatjs') {
|
|
297
|
-
return [
|
|
298
|
-
new Tcp({
|
|
299
|
-
...subOptions,
|
|
300
|
-
outEvent: 'ydwg02-out'
|
|
301
|
-
}),
|
|
302
|
-
new Liner(subOptions)
|
|
303
|
-
]
|
|
304
|
-
} else if (subOptions.type === 'ydwg02-udp-canboatjs') {
|
|
305
|
-
return [
|
|
306
|
-
new Udp({
|
|
307
|
-
...subOptions,
|
|
308
|
-
outEvent: 'ydwg02-out'
|
|
309
|
-
}),
|
|
310
|
-
new Liner(subOptions)
|
|
311
|
-
]
|
|
312
|
-
} else if (subOptions.type === 'navlink2-tcp-canboatjs') {
|
|
313
|
-
return [
|
|
314
|
-
new Tcp({
|
|
315
|
-
...subOptions,
|
|
316
|
-
outEvent: 'navlink2-out'
|
|
317
|
-
}),
|
|
318
|
-
new Liner(subOptions)
|
|
319
|
-
]
|
|
320
|
-
} else if (subOptions.type === 'w2k-1-n2k-ascii-canboatjs') {
|
|
321
|
-
return [
|
|
322
|
-
new Tcp({
|
|
323
|
-
...subOptions,
|
|
324
|
-
outEvent: 'w2k-1-out'
|
|
325
|
-
}),
|
|
326
|
-
new Liner(subOptions),
|
|
327
|
-
new W2k01(subOptions, 'ascii', 'w2k-1-out')
|
|
328
|
-
]
|
|
329
|
-
} else if (subOptions.type === 'w2k-1-n2k-actisense-canboatjs') {
|
|
330
|
-
return [
|
|
331
|
-
new Tcp({
|
|
332
|
-
...subOptions,
|
|
333
|
-
outEvent: 'w2k-1-out'
|
|
334
|
-
}),
|
|
335
|
-
new W2k01(subOptions, 'actisense', 'w2k-1-out')
|
|
336
|
-
]
|
|
337
|
-
} else if (subOptions.type === 'navlink2-udp-canboatjs') {
|
|
338
|
-
return [new Udp(subOptions), new Liner(subOptions)]
|
|
339
|
-
} else if (subOptions.type === 'ydwg02-usb-canboatjs') {
|
|
340
|
-
const serialport = require('./serialport')
|
|
341
|
-
return [
|
|
342
|
-
new serialport({
|
|
343
|
-
...subOptions,
|
|
344
|
-
baudrate: 38400,
|
|
345
|
-
toStdout: 'ydwg02-out'
|
|
346
|
-
})
|
|
347
|
-
]
|
|
348
|
-
} else {
|
|
349
|
-
let command
|
|
350
|
-
let toChildProcess
|
|
351
|
-
if (subOptions.type === 'ngt-1') {
|
|
352
|
-
command = `actisense-serial -s ${subOptions.baudrate || 115200} ${
|
|
353
|
-
subOptions.device
|
|
354
|
-
}`
|
|
355
|
-
toChildProcess = 'nmea2000out'
|
|
356
|
-
} else if (subOptions.type === 'canbus') {
|
|
357
|
-
command = `candump ${subOptions.interface} | candump2analyzer`
|
|
358
|
-
toChildProcess = null
|
|
359
|
-
} else {
|
|
360
|
-
throw new Error(`unknown NMEA2000 type ${subOptions.type}`)
|
|
361
|
-
}
|
|
362
|
-
return [
|
|
363
|
-
new execute({
|
|
364
|
-
command: command,
|
|
365
|
-
toChildProcess: toChildProcess,
|
|
366
|
-
app: subOptions.app,
|
|
367
|
-
providerId: subOptions.providerId
|
|
368
|
-
}),
|
|
369
|
-
new Liner(subOptions)
|
|
370
|
-
]
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
function nmea0183input(subOptions) {
|
|
375
|
-
let pipePart
|
|
376
|
-
if (subOptions.type === 'tcp') {
|
|
377
|
-
pipePart = [new Tcp(subOptions), new Liner(subOptions)]
|
|
378
|
-
} else if (subOptions.type === 'tcpserver') {
|
|
379
|
-
pipePart = [new TcpServer(subOptions), new Liner(subOptions)]
|
|
380
|
-
} else if (subOptions.type === 'udp') {
|
|
381
|
-
pipePart = [new Udp(subOptions), new SplittingLiner(subOptions)]
|
|
382
|
-
} else if (subOptions.type === 'serial') {
|
|
383
|
-
const serialport = require('./serialport')
|
|
384
|
-
pipePart = [new serialport(subOptions)]
|
|
385
|
-
} else if (subOptions.type === 'gpsd') {
|
|
386
|
-
pipePart = [new gpsd(subOptions)]
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
if (pipePart) {
|
|
390
|
-
if (subOptions.removeNulls) {
|
|
391
|
-
pipePart.push(
|
|
392
|
-
new Replacer({
|
|
393
|
-
regexp: '\u0000',
|
|
394
|
-
template: ''
|
|
395
|
-
})
|
|
396
|
-
)
|
|
397
|
-
}
|
|
398
|
-
if (subOptions.ignoredSentences) {
|
|
399
|
-
console.log(subOptions.ignoredSentences)
|
|
400
|
-
subOptions.ignoredSentences.forEach((sentence) => {
|
|
401
|
-
if (sentence.length > 0) {
|
|
402
|
-
pipePart.push(
|
|
403
|
-
new Replacer({
|
|
404
|
-
regexp: `^...${sentence}.*`,
|
|
405
|
-
template: ''
|
|
406
|
-
})
|
|
407
|
-
)
|
|
408
|
-
}
|
|
409
|
-
})
|
|
410
|
-
}
|
|
411
|
-
return pipePart
|
|
412
|
-
} else {
|
|
413
|
-
throw new Error(`Unknown networking tyoe: ${subOptions.networking}`)
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
function executeInput(subOptions) {
|
|
418
|
-
return [new execute(subOptions), new Liner(subOptions)]
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
function fileInput(subOptions) {
|
|
422
|
-
const result = [new FileStream(subOptions)]
|
|
423
|
-
result.push(new Liner(subOptions))
|
|
424
|
-
return result
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
function signalKInput(subOptions) {
|
|
428
|
-
if (subOptions.type === 'ws' || subOptions.type === 'wss') {
|
|
429
|
-
const mdns_ws = require('./mdns-ws')
|
|
430
|
-
return [new mdns_ws(subOptions)]
|
|
431
|
-
} else if (subOptions.type === 'tcp') {
|
|
432
|
-
return [new Tcp(subOptions), new Liner(subOptions)]
|
|
433
|
-
} else if (subOptions.type === 'udp') {
|
|
434
|
-
return [new Udp(subOptions)]
|
|
435
|
-
} else if (subOptions.type === 'serial') {
|
|
436
|
-
const serialport = require('./serialport')
|
|
437
|
-
return [new serialport(subOptions)]
|
|
438
|
-
}
|
|
439
|
-
throw new Error(`unknown SignalK type: ${subOptions.type}`)
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
function seatalkInput(subOptions) {
|
|
443
|
-
if (subOptions.type === 'gpiod') {
|
|
444
|
-
return [new gpiodSeatalk(subOptions)]
|
|
445
|
-
} else {
|
|
446
|
-
return [new pigpioSeatalk(subOptions)]
|
|
447
|
-
}
|
|
448
|
-
}
|
package/splitting-liner.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2019 Scott Bender <scott@scottbender.net>
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/* Usage:
|
|
18
|
-
* This is part of a PipedProvider that splits the input into separate lines and passes one line at a time to the next provider.
|
|
19
|
-
* You can specify the line separator with the option lineSeparator.
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
"type": "providers/splitting-liner"
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
const Transform = require('stream').Transform
|
|
28
|
-
|
|
29
|
-
require('util').inherits(SplittingLiner, Transform)
|
|
30
|
-
|
|
31
|
-
function SplittingLiner(options) {
|
|
32
|
-
Transform.call(this, {
|
|
33
|
-
objectMode: true
|
|
34
|
-
})
|
|
35
|
-
this.doPush = this.push.bind(this)
|
|
36
|
-
this.lineSeparator = options.lineSeparator || '\n'
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
SplittingLiner.prototype._transform = function (chunk, encoding, done) {
|
|
40
|
-
const data = chunk.toString()
|
|
41
|
-
const lines = data.split(this.lineSeparator)
|
|
42
|
-
lines.forEach(this.doPush)
|
|
43
|
-
done()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
module.exports = SplittingLiner
|
package/tcp.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2014-2018 Fabian Tollenaar <fabian@decipher.industries>,Teppo Kurki <teppo.kurki@iki.fi
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/* Usage: This is TCP client provider that can connect to a tcp server and pass data from there to the provider pipeline.
|
|
18
|
-
* It takes the options "host" and "port".
|
|
19
|
-
* Example:
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
"type": "providers/tcp",
|
|
23
|
-
"options": {
|
|
24
|
-
"host": 'localhost',
|
|
25
|
-
"port": 10110,
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
const net = require('net')
|
|
32
|
-
const Transform = require('stream').Transform
|
|
33
|
-
const isArray = require('lodash').isArray
|
|
34
|
-
|
|
35
|
-
function TcpStream(options) {
|
|
36
|
-
Transform.call(this, options)
|
|
37
|
-
this.options = options
|
|
38
|
-
this.noDataReceivedTimeout =
|
|
39
|
-
Number.parseInt((this.options.noDataReceivedTimeout + '').trim()) * 1000
|
|
40
|
-
this.debug = (options.createDebug || require('debug'))('signalk:streams:tcp')
|
|
41
|
-
this.debug(`noDataReceivedTimeout:${this.noDataReceivedTimeout}`)
|
|
42
|
-
this.debugData = (options.createDebug || require('debug'))(
|
|
43
|
-
'signalk:streams:tcp-data'
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
require('util').inherits(TcpStream, Transform)
|
|
48
|
-
|
|
49
|
-
TcpStream.prototype.pipe = function (pipeTo) {
|
|
50
|
-
const that = this
|
|
51
|
-
if (this.options.outEvent) {
|
|
52
|
-
that.options.app.on(that.options.outEvent, function (d) {
|
|
53
|
-
if (that.tcpStream) {
|
|
54
|
-
that.debug('sending %s', d)
|
|
55
|
-
that.tcpStream.write(d)
|
|
56
|
-
setImmediate(() => {
|
|
57
|
-
that.options.app.emit('connectionwrite', {
|
|
58
|
-
providerId: that.options.providerId
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const stdOutEvent = this.options.toStdout
|
|
66
|
-
if (stdOutEvent) {
|
|
67
|
-
const that = this //semicolon required here
|
|
68
|
-
;(isArray(stdOutEvent) ? stdOutEvent : [stdOutEvent]).forEach(
|
|
69
|
-
(stdEvent) => {
|
|
70
|
-
that.options.app.on(stdEvent, function (d) {
|
|
71
|
-
if (that.tcpStream) {
|
|
72
|
-
that.tcpStream.write(d + '\r\n')
|
|
73
|
-
that.debug('event %s sending %s', stdEvent, d)
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
require('reconnect-core')(function () {
|
|
81
|
-
return net.connect.apply(null, arguments)
|
|
82
|
-
})({ maxDelay: 5 * 1000 }, (tcpStream) => {
|
|
83
|
-
if (!isNaN(this.noDataReceivedTimeout)) {
|
|
84
|
-
tcpStream.setTimeout(this.noDataReceivedTimeout)
|
|
85
|
-
that.debug(
|
|
86
|
-
`Setting socket idle timeout ${this.options.host}:${this.options.port} ${this.noDataReceivedTimeout}`
|
|
87
|
-
)
|
|
88
|
-
tcpStream.on('timeout', () => {
|
|
89
|
-
that.debug(
|
|
90
|
-
`Idle timeout, closing socket ${this.options.host}:${this.options.port}`
|
|
91
|
-
)
|
|
92
|
-
tcpStream.end()
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
tcpStream.on('data', (data) => {
|
|
96
|
-
if (that.debugData.enabled) {
|
|
97
|
-
that.debugData(data.toString())
|
|
98
|
-
}
|
|
99
|
-
this.write(data)
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
.on('connect', (con) => {
|
|
103
|
-
this.tcpStream = con
|
|
104
|
-
const msg = `Connected to ${this.options.host} ${this.options.port}`
|
|
105
|
-
this.options.app.setProviderStatus(this.options.providerId, msg)
|
|
106
|
-
that.debug(msg)
|
|
107
|
-
})
|
|
108
|
-
.on('reconnect', (n, delay) => {
|
|
109
|
-
const msg = `Reconnect ${this.options.host} ${this.options.port} retry ${n} delay ${delay}`
|
|
110
|
-
this.options.app.setProviderError(this.options.providerId, msg)
|
|
111
|
-
that.debug(msg)
|
|
112
|
-
})
|
|
113
|
-
.on('disconnect', () => {
|
|
114
|
-
delete this.tcpStream
|
|
115
|
-
that.debug(`Disconnected ${this.options.host} ${this.options.port}`)
|
|
116
|
-
})
|
|
117
|
-
.on('error', (err) => {
|
|
118
|
-
let msg = err
|
|
119
|
-
if (err.message && err.message.length > 0) {
|
|
120
|
-
msg = err.message
|
|
121
|
-
} else if (err.errors) {
|
|
122
|
-
msg = err.errors.toString()
|
|
123
|
-
} else {
|
|
124
|
-
msg = err.toString()
|
|
125
|
-
}
|
|
126
|
-
this.options.app.setProviderError(this.options.providerId, msg)
|
|
127
|
-
console.error('TcpProvider:' + msg)
|
|
128
|
-
})
|
|
129
|
-
.connect(this.options)
|
|
130
|
-
|
|
131
|
-
Transform.prototype.pipe.call(this, pipeTo)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
TcpStream.prototype._transform = function (data, encoding, callback) {
|
|
135
|
-
callback(null, data)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
module.exports = TcpStream
|
package/tcpserver.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2018 Teppo Kurki <teppo.kurki@iki.fi>
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/*
|
|
18
|
-
The server is the tcp nmea0183 interface, this provider just
|
|
19
|
-
shovels data from tcpserver0183data to the provider pipe.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const Transform = require('stream').Transform
|
|
23
|
-
|
|
24
|
-
function TcpServer(options) {
|
|
25
|
-
Transform.call(this)
|
|
26
|
-
this.options = options
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
require('util').inherits(TcpServer, Transform)
|
|
30
|
-
|
|
31
|
-
TcpServer.prototype.pipe = function (pipeTo) {
|
|
32
|
-
this.options.app.on('tcpserver0183data', (d) => this.write(d))
|
|
33
|
-
Transform.prototype.pipe.call(this, pipeTo)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
TcpServer.prototype._transform = function (data, encoding, callback) {
|
|
37
|
-
callback(null, data)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = TcpServer
|
package/throttle.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2014-2015 Fabian Tollenaar <fabian@starting-point.nl>
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/* Usage: This provider is used for throttling input data from files. It takes the option "rate" which is the rate in bytes/s for the stream to come in.
|
|
18
|
-
* Example:
|
|
19
|
-
|
|
20
|
-
{
|
|
21
|
-
"type": "providers/throttle",
|
|
22
|
-
"options": {
|
|
23
|
-
"rate": 500
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
const Throttle = require('stream-throttle').Throttle
|
|
30
|
-
|
|
31
|
-
module.exports = Throttle
|