@signalk/streams 5.1.3 → 6.0.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.
Files changed (132) hide show
  1. package/dist/actisense-serial.d.ts +3 -0
  2. package/dist/actisense-serial.d.ts.map +1 -0
  3. package/dist/actisense-serial.js +4 -0
  4. package/dist/autodetect.d.ts +54 -0
  5. package/dist/autodetect.d.ts.map +1 -0
  6. package/dist/autodetect.js +186 -0
  7. package/dist/canboatjs.d.ts +25 -0
  8. package/dist/canboatjs.d.ts.map +1 -0
  9. package/dist/canboatjs.js +57 -0
  10. package/dist/canbus.d.ts +3 -0
  11. package/dist/canbus.d.ts.map +1 -0
  12. package/dist/canbus.js +4 -0
  13. package/dist/execute.d.ts +34 -0
  14. package/dist/execute.d.ts.map +1 -0
  15. package/dist/execute.js +101 -0
  16. package/dist/filestream.d.ts +24 -0
  17. package/dist/filestream.d.ts.map +1 -0
  18. package/dist/filestream.js +58 -0
  19. package/dist/folderstream.d.ts +12 -0
  20. package/dist/folderstream.d.ts.map +1 -0
  21. package/dist/folderstream.js +36 -0
  22. package/dist/from_json.d.ts +6 -0
  23. package/dist/from_json.d.ts.map +1 -0
  24. package/dist/from_json.js +22 -0
  25. package/dist/gpiod-seatalk.d.ts +19 -0
  26. package/dist/gpiod-seatalk.d.ts.map +1 -0
  27. package/{gpiod-seatalk.js → dist/gpiod-seatalk.js} +18 -16
  28. package/dist/gpsd.d.ts +23 -0
  29. package/dist/gpsd.d.ts.map +1 -0
  30. package/dist/gpsd.js +55 -0
  31. package/dist/index.d.ts +5 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +14 -0
  34. package/dist/keys-filter.d.ts +27 -0
  35. package/dist/keys-filter.d.ts.map +1 -0
  36. package/dist/keys-filter.js +59 -0
  37. package/dist/liner.d.ts +14 -0
  38. package/dist/liner.d.ts.map +1 -0
  39. package/dist/liner.js +35 -0
  40. package/dist/log.d.ts +15 -0
  41. package/dist/log.d.ts.map +1 -0
  42. package/dist/log.js +17 -0
  43. package/dist/logging.d.ts +14 -0
  44. package/dist/logging.d.ts.map +1 -0
  45. package/dist/logging.js +125 -0
  46. package/dist/mdns-ws.d.ts +37 -0
  47. package/dist/mdns-ws.d.ts.map +1 -0
  48. package/dist/mdns-ws.js +144 -0
  49. package/dist/multiplexedlog.d.ts +3 -0
  50. package/dist/multiplexedlog.d.ts.map +1 -0
  51. package/dist/multiplexedlog.js +7 -0
  52. package/dist/n2k-signalk.d.ts +39 -0
  53. package/dist/n2k-signalk.d.ts.map +1 -0
  54. package/dist/n2k-signalk.js +180 -0
  55. package/dist/n2kAnalyzer.d.ts +19 -0
  56. package/dist/n2kAnalyzer.d.ts.map +1 -0
  57. package/dist/n2kAnalyzer.js +61 -0
  58. package/dist/nmea0183-signalk.d.ts +33 -0
  59. package/dist/nmea0183-signalk.d.ts.map +1 -0
  60. package/dist/nmea0183-signalk.js +105 -0
  61. package/dist/nullprovider.d.ts +5 -0
  62. package/dist/nullprovider.d.ts.map +1 -0
  63. package/dist/nullprovider.js +9 -0
  64. package/dist/pigpio-seatalk.d.ts +19 -0
  65. package/dist/pigpio-seatalk.d.ts.map +1 -0
  66. package/{pigpio-seatalk.js → dist/pigpio-seatalk.js} +21 -18
  67. package/dist/replacer.d.ts +13 -0
  68. package/dist/replacer.d.ts.map +1 -0
  69. package/dist/replacer.js +20 -0
  70. package/dist/s3.d.ts +13 -0
  71. package/dist/s3.d.ts.map +1 -0
  72. package/dist/s3.js +82 -0
  73. package/dist/serialport.d.ts +35 -0
  74. package/dist/serialport.d.ts.map +1 -0
  75. package/dist/serialport.js +125 -0
  76. package/dist/simple.d.ts +78 -0
  77. package/dist/simple.d.ts.map +1 -0
  78. package/dist/simple.js +446 -0
  79. package/dist/splitting-liner.d.ts +12 -0
  80. package/dist/splitting-liner.d.ts.map +1 -0
  81. package/dist/splitting-liner.js +19 -0
  82. package/dist/tcp.d.ts +32 -0
  83. package/dist/tcp.d.ts.map +1 -0
  84. package/dist/tcp.js +113 -0
  85. package/dist/tcpserver.d.ts +14 -0
  86. package/dist/tcpserver.d.ts.map +1 -0
  87. package/dist/tcpserver.js +18 -0
  88. package/dist/test-helpers.d.ts +52 -0
  89. package/dist/test-helpers.d.ts.map +1 -0
  90. package/dist/test-helpers.js +73 -0
  91. package/dist/throttle.d.ts +3 -0
  92. package/dist/throttle.d.ts.map +1 -0
  93. package/dist/throttle.js +4 -0
  94. package/dist/timestamp-throttle.d.ts +17 -0
  95. package/dist/timestamp-throttle.d.ts.map +1 -0
  96. package/dist/timestamp-throttle.js +41 -0
  97. package/dist/types.d.ts +8 -0
  98. package/dist/types.d.ts.map +1 -0
  99. package/dist/types.js +2 -0
  100. package/dist/udp.d.ts +26 -0
  101. package/dist/udp.d.ts.map +1 -0
  102. package/dist/udp.js +53 -0
  103. package/package.json +46 -4
  104. package/actisense-serial.js +0 -1
  105. package/autodetect.js +0 -198
  106. package/canboatjs.js +0 -71
  107. package/canbus.js +0 -17
  108. package/execute.js +0 -137
  109. package/filestream.js +0 -90
  110. package/folderstream.js +0 -36
  111. package/from_json.js +0 -51
  112. package/gpsd.js +0 -94
  113. package/keys-filter.js +0 -81
  114. package/liner.js +0 -68
  115. package/log.js +0 -51
  116. package/logging.js +0 -149
  117. package/mdns-ws.js +0 -167
  118. package/multiplexedlog.js +0 -3
  119. package/n2k-signalk.js +0 -195
  120. package/n2kAnalyzer.js +0 -82
  121. package/nmea0183-signalk.js +0 -119
  122. package/nullprovider.js +0 -31
  123. package/replacer.js +0 -57
  124. package/s3.js +0 -87
  125. package/serialport.js +0 -209
  126. package/simple.js +0 -446
  127. package/splitting-liner.js +0 -46
  128. package/tcp.js +0 -138
  129. package/tcpserver.js +0 -40
  130. package/throttle.js +0 -31
  131. package/timestamp-throttle.js +0 -63
  132. package/udp.js +0 -95
@@ -1,119 +0,0 @@
1
- /*
2
- * Copyright 2017 Signal K & Fabian Tollenaar <fabian@signalk.org>
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
- * Usage: this is the pipeElement that transforms NMEA0183 input to Signal K deltas.
19
- * Emits sentence data as "nmea0183" events on app and app.signalk by default.
20
- * Furthermore you can use "sentenceEvent" option, that will cause sentence data to be
21
- * emitted as events on app. sentenceEvent can be a string or an array of strings.
22
- *
23
- * Example:
24
- * {
25
- * "type": "providers/nmea0183-signalk",
26
- * "options": {
27
- * "sentenceEvent": "nmea0183-B"
28
- * },
29
- * }
30
- */
31
-
32
- const Transform = require('stream').Transform
33
- const Parser = require('@signalk/nmea0183-signalk')
34
- const utils = require('@signalk/nmea0183-utilities')
35
- const n2kToDelta = require('@signalk/n2k-signalk').toDelta
36
- const FromPgn = require('@canboat/canboatjs').FromPgn
37
-
38
- function Nmea0183ToSignalK(options) {
39
- Transform.call(this, {
40
- objectMode: true
41
- })
42
- this.debug = (options.createDebug || require('debug'))(
43
- 'signalk:streams:nmea0183-signalk'
44
- )
45
-
46
- this.parser = new Parser(options)
47
- this.n2kParser = new FromPgn(options)
48
- this.n2kState = {}
49
-
50
- // Object on which to send 'sentence' events
51
- this.app = options.app
52
-
53
- // Prepare a list of events to send for each sentence received
54
- this.sentenceEvents = options.suppress0183event ? [] : ['nmea0183']
55
- this.appendChecksum = options.appendChecksum
56
-
57
- if (options.sentenceEvent) {
58
- if (Array.isArray(options.sentenceEvent)) {
59
- this.sentenceEvents = this.sentenceEvents.concat(options.sentenceEvent)
60
- } else {
61
- this.sentenceEvents.push(options.sentenceEvent)
62
- }
63
- }
64
- }
65
-
66
- require('util').inherits(Nmea0183ToSignalK, Transform)
67
-
68
- Nmea0183ToSignalK.prototype._transform = function (chunk, encoding, done) {
69
- let sentence
70
- let timestamp = null
71
-
72
- if (chunk && typeof chunk === 'object' && typeof chunk.line === 'string') {
73
- timestamp = new Date(Number(chunk.timestamp))
74
- sentence = chunk.line.trim()
75
- } else if (Buffer.isBuffer(chunk)) {
76
- sentence = chunk.toString().trim()
77
- } else if (chunk && typeof chunk === 'string') {
78
- sentence = chunk.trim()
79
- }
80
-
81
- try {
82
- if (sentence !== undefined) {
83
- if (this.appendChecksum) {
84
- sentence = utils.appendChecksum(sentence)
85
- }
86
- // Send 'sentences' event to the app for each sentence
87
- this.sentenceEvents.forEach((eventName) => {
88
- this.app.emit(eventName, sentence)
89
- this.app.signalk.emit(eventName, sentence)
90
- })
91
-
92
- let delta = null
93
- if (this.n2kParser.isN2KOver0183(sentence)) {
94
- const pgn = this.n2kParser.parseN2KOver0183(sentence)
95
- if (pgn) {
96
- delta = n2kToDelta(pgn, this.state, { sendMetaData: true })
97
- }
98
- } else {
99
- delta = this.parser.parse(sentence)
100
- }
101
-
102
- if (delta !== null) {
103
- if (timestamp !== null) {
104
- delta.updates.forEach((update) => {
105
- update.timestamp = timestamp
106
- })
107
- }
108
-
109
- this.push(delta)
110
- }
111
- }
112
- } catch (e) {
113
- this.debug(e)
114
- }
115
-
116
- done()
117
- }
118
-
119
- module.exports = Nmea0183ToSignalK
package/nullprovider.js DELETED
@@ -1,31 +0,0 @@
1
- /*
2
- *
3
- * prototype-server: An implementation of a Signal K server for boats.
4
- * Copyright (C) 2017 Teppo Kurki <teppo.kurki@iki.fi>.
5
- *
6
- * This program is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- */
20
-
21
- const Transform = require('stream').Transform
22
-
23
- function NullProvider() {
24
- Transform.call(this, {
25
- objectMode: true
26
- })
27
- }
28
-
29
- require('util').inherits(NullProvider, Transform)
30
-
31
- module.exports = NullProvider
package/replacer.js DELETED
@@ -1,57 +0,0 @@
1
- /*
2
- * Copyright 2020 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
- const Transform = require('stream').Transform
18
-
19
- require('util').inherits(Replacer, Transform)
20
-
21
- function Replacer(options) {
22
- Transform.call(this, {
23
- objectMode: true
24
- })
25
- this.doPush = this.push.bind(this)
26
- this.regexp = new RegExp(options.regexp, 'gu')
27
- this.template = options.template
28
- }
29
-
30
- Replacer.prototype._transform = function (chunk, encoding, done) {
31
- this.doPush(chunk.toString().replace(this.regexp, this.template))
32
- done()
33
- }
34
-
35
- module.exports = Replacer
36
-
37
- // const replacers = [
38
- // {
39
- // regexp: '\u0000',
40
- // template: '',
41
- // testdata: '\u0000$WIMWV,1\u000047,R,0,N,A21',
42
- // testresult: '$WIMWV,147,R,0,N,A21'
43
- // }
44
- // ,
45
- // {
46
- // regexp: '^...RMC.*',
47
- // template: '',
48
- // testdata: '$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A',
49
- // testresult: ''
50
- // }
51
- // ]
52
-
53
- // replacers.forEach(replacerOptions => {
54
- // const replacer = new Replacer(replacerOptions)
55
- // replacer.doPush = x => console.log(JSON.stringify(x))
56
- // replacer._transform(replacerOptions.testdata, null, () => {})
57
- // })
package/s3.js DELETED
@@ -1,87 +0,0 @@
1
- /*
2
- * Copyright 2015 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
- var Transform = require('stream').Transform
18
- /*
19
- aws-sdk is not included in dependencies because of the
20
- persistent deprecation warnings caused by its transitive
21
- dependencies. This feature is not in wide use, especially
22
- not in signalk-server where people encounter the scary looking
23
- deprecation warnings.
24
- Known to work with ^2.413.0
25
- */
26
- const AWS = require('aws-sdk')
27
-
28
- function S3Provider({ bucket, prefix }) {
29
- Transform.call(this, {
30
- objectMode: false
31
- })
32
- this.Bucket = bucket
33
- this.Prefix = prefix
34
- // AWS.config.credentials = new AWS.SharedIniFileCredentials()
35
- }
36
-
37
- require('util').inherits(S3Provider, Transform)
38
-
39
- S3Provider.prototype.pipe = function (pipeTo) {
40
- const doEnd = this.end.bind(this)
41
- const s3 = new AWS.S3()
42
- const params = {
43
- Bucket: this.Bucket,
44
- Prefix: this.Prefix
45
- }
46
- console.log('listobjects')
47
- s3.listObjects(params)
48
- .promise()
49
- .then((data) => {
50
- // console.log(data)
51
- const jobs = data.Contents.map(
52
- (item, i) =>
53
- function () {
54
- return new Promise((resolve) => {
55
- console.log('Starting key ' + item.Key)
56
- const objectParams = {
57
- Bucket: params.Bucket,
58
- Key: item.Key
59
- }
60
- const request = s3.getObject(objectParams)
61
- request.on('error', (err) => {
62
- console.log(err)
63
- })
64
- const stream = request.createReadStream()
65
- stream.on('end', resolve)
66
- stream.pipe(pipeTo, { end: i === data.Contents.length - 1 })
67
- })
68
- }
69
- )
70
-
71
- let i = 0
72
- function startNext() {
73
- if (i < jobs.length) {
74
- jobs[i++]().then(startNext)
75
- } else {
76
- doEnd()
77
- }
78
- }
79
- startNext()
80
- })
81
- .catch((error) => {
82
- console.error(error)
83
- })
84
- return pipeTo
85
- }
86
-
87
- module.exports = S3Provider
package/serialport.js DELETED
@@ -1,209 +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 is the first pipeElement in a PipedProvider. Used to pass data input from Serial
18
- * to the next pipeElement.
19
- * Reads data from a serial device and allows writing back to serial with the "toStdout" option
20
- * It takes two options; "device" and "baudrate".
21
- *
22
- * The "toStdout" option is not mandatory. It routes events emitted on app with that name to
23
- * serial output, followed by newline. toStdout can be a string or an array of strings.
24
- *
25
- * You can run arbitrary shell command that get the configured serial port as the parameter
26
- * by setting the environment variable PRESERIALCOMMAND. The command is invoked once per each
27
- * configured serial port.
28
- *
29
- * For example running the server having run
30
- *
31
- * export PRESERIALCOMMAND="echo >>/tmp/serialports"
32
- *
33
- * will append all configured serial port devices to the file /tmp/serialports
34
- * every time the server is started.
35
- *
36
- * Example:
37
-
38
- {
39
- "type": "providers/serialport",
40
- "options": {
41
- "device": "/dev/ttyUSB0",
42
- "baudrate": 4800,
43
- "toStdout": "nmea0183out1"
44
- },
45
- "optionMappings": [
46
- {
47
- "fromAppProperty": "argv.nmeadevice",
48
- "toOption": "device"
49
- },
50
-
51
- {
52
- "fromAppProperty": "argv.nmeabaudrate",
53
- "toOption": "baudrate"
54
- }
55
- ]
56
- },
57
-
58
- */
59
-
60
- const Transform = require('stream').Transform
61
- const child_process = require('child_process')
62
- const shellescape = require('any-shell-escape')
63
- const { SerialPort } = require('serialport')
64
- const { ReadlineParser } = require('@serialport/parser-readline')
65
- const isArray = require('lodash').isArray
66
- const isBuffer = require('lodash').isBuffer
67
-
68
- function SerialStream(options) {
69
- if (!(this instanceof SerialStream)) {
70
- return new SerialStream(options)
71
- }
72
-
73
- Transform.call(this, options)
74
-
75
- this.reconnect = options.reconnect || true
76
- this.reconnectDelay = 1000
77
- this.serial = null
78
- this.options = options
79
- this.maxPendingWrites = options.maxPendingWrites || 5
80
- this.start()
81
- this.isFirstError = true
82
-
83
- const createDebug = options.createDebug || require('debug')
84
- this.debug = createDebug('signalk:streams:serialport')
85
-
86
- let pendingWrites = 0
87
- const stdOutEvents = isArray(this.options.toStdout)
88
- ? this.options.toStdout
89
- : [this.options.toStdout]
90
- const standardOutEventName = `serial-${this.options.providerId}-toStdout`
91
- stdOutEvents.push(standardOutEventName)
92
-
93
- const that = this
94
- stdOutEvents.forEach((event) => {
95
- const onDrain = () => {
96
- pendingWrites--
97
- }
98
-
99
- that.options.app.on(event, (d) => {
100
- if (pendingWrites > that.maxPendingWrites) {
101
- that.debug('Buffer overflow, not writing:' + d)
102
- return
103
- }
104
- that.debug('Writing:' + d)
105
- if (isBuffer(d)) {
106
- that.serial.write(d)
107
- } else {
108
- that.serial.write(d + '\r\n')
109
- }
110
- setImmediate(() => {
111
- that.options.app.emit('connectionwrite', {
112
- providerId: that.options.providerId
113
- })
114
- })
115
- pendingWrites++
116
- that.serial.drain(onDrain)
117
- })
118
- })
119
-
120
- this.options.app.emitPropertyValue('serialport', {
121
- id: this.options.providerId,
122
- eventNames: {
123
- toStdout: standardOutEventName
124
- }
125
- })
126
- }
127
-
128
- require('util').inherits(SerialStream, Transform)
129
-
130
- SerialStream.prototype.start = function () {
131
- if (this.serial !== null) {
132
- this.serial.unpipe(this)
133
- this.serial.removeAllListeners()
134
- this.serial = null
135
- }
136
-
137
- if (this.reconnect === false) {
138
- return
139
- }
140
-
141
- if (process.env.PRESERIALCOMMAND) {
142
- child_process.execSync(
143
- `${process.env.PRESERIALCOMMAND} ${shellescape(this.options.device)}`
144
- )
145
- }
146
-
147
- this.serial = new SerialPort({
148
- path: this.options.device,
149
- baudRate: this.options.baudrate
150
- })
151
-
152
- this.serial.on(
153
- 'open',
154
- function () {
155
- this.reconnectDelay = 1000
156
- this.options.app.setProviderStatus(
157
- this.options.providerId,
158
- `Connected to ${this.options.device}`
159
- )
160
- this.isFirstError = true
161
- const parser = new ReadlineParser()
162
- this.serial.pipe(parser).pipe(this)
163
- }.bind(this)
164
- )
165
-
166
- this.serial.on(
167
- 'error',
168
- function (x) {
169
- this.options.app.setProviderError(this.options.providerId, x.message)
170
- if (this.isFirstError) {
171
- console.log(x.message)
172
- }
173
- this.debug(x.message)
174
- this.isFirstError = false
175
- this.scheduleReconnect()
176
- }.bind(this)
177
- )
178
- this.serial.on(
179
- 'close',
180
- function () {
181
- this.options.app.setProviderError(
182
- this.options.providerId,
183
- 'Closed, reconnecting...'
184
- )
185
- this.scheduleReconnect()
186
- }.bind(this)
187
- )
188
- }
189
-
190
- SerialStream.prototype.end = function () {
191
- this.serial.close()
192
- }
193
-
194
- SerialStream.prototype._transform = function (chunk, encoding, done) {
195
- this.push(chunk)
196
- done()
197
- }
198
-
199
- SerialStream.prototype.scheduleReconnect = function () {
200
- this.reconnectDelay *= this.reconnectDelay < 60 * 1000 ? 1.5 : 1
201
- const msg = `Not connected (retry delay ${(
202
- this.reconnectDelay / 1000
203
- ).toFixed(0)} s)`
204
- this.debug(msg)
205
- this.options.app.setProviderStatus(this.options.providerId, msg)
206
- setTimeout(this.start.bind(this), this.reconnectDelay)
207
- }
208
-
209
- module.exports = SerialStream