@signalk/streams 2.0.0 → 2.0.1
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/canboatjs.js +3 -1
- package/execute.js +2 -1
- package/gpsd.js +4 -3
- package/keys-filter.js +3 -2
- package/logging.js +2 -1
- package/mdns-ws.js +7 -5
- package/n2kAnalyzer.js +1 -2
- package/nmea0183-signalk.js +1 -2
- package/package.json +1 -1
- package/pigpio-seatalk.js +4 -5
- package/s3.js +1 -2
- package/serialport.js +9 -6
- package/simple.js +7 -3
- package/tcp.js +12 -13
- package/udp.js +2 -2
package/canboatjs.js
CHANGED
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
|
|
17
17
|
const Transform = require('stream').Transform
|
|
18
18
|
const FromPgn = require('@canboat/canboatjs').FromPgn
|
|
19
|
-
const debug = require('debug')('signalk:streams:canboatjs')
|
|
20
19
|
const _ = require('lodash')
|
|
21
20
|
|
|
22
21
|
function CanboatJs (options) {
|
|
@@ -25,6 +24,9 @@ function CanboatJs (options) {
|
|
|
25
24
|
})
|
|
26
25
|
|
|
27
26
|
this.fromPgn = new FromPgn(options)
|
|
27
|
+
const createDebug = options.createDebug || require('debug')
|
|
28
|
+
const debug = createDebug('signalk:streams:nmea0183-signalk')
|
|
29
|
+
|
|
28
30
|
|
|
29
31
|
this.fromPgn.on('warning', (pgn, warning) => {
|
|
30
32
|
debug(`[warning] ${pgn.pgn} ${warning}`)
|
package/execute.js
CHANGED
|
@@ -42,7 +42,8 @@ const { pgnToActisenseSerialFormat } = require('@canboat/canboatjs')
|
|
|
42
42
|
function Execute (options) {
|
|
43
43
|
Transform.call(this, {})
|
|
44
44
|
this.options = options
|
|
45
|
-
|
|
45
|
+
const createDebug = options.createDebug || require('debug')
|
|
46
|
+
this.debug = options.debug || createDebug('signalk:streams:execute')
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
require('util').inherits(Execute, Transform)
|
package/gpsd.js
CHANGED
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
|
|
33
33
|
const Transform = require('stream').Transform
|
|
34
34
|
const gpsd = require('node-gpsd')
|
|
35
|
-
const debug = require('debug')('signalk:streams:gpsd')
|
|
36
35
|
|
|
37
36
|
function Gpsd (options) {
|
|
38
37
|
Transform.call(this, {
|
|
@@ -45,12 +44,14 @@ function Gpsd (options) {
|
|
|
45
44
|
function setProviderStatus(msg) {
|
|
46
45
|
options.app.setProviderStatus(options.providerId, msg)
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
|
|
48
|
+
const createDebug = options.createDebug || require('debug')
|
|
49
|
+
|
|
49
50
|
this.listener = new gpsd.Listener({
|
|
50
51
|
port,
|
|
51
52
|
hostname,
|
|
52
53
|
logger: {
|
|
53
|
-
info:
|
|
54
|
+
info: createDebug('signalk:streams:gpsd'),
|
|
54
55
|
warn: console.warn,
|
|
55
56
|
error: (msg) => {
|
|
56
57
|
options.app.setProviderError(options.providerId, `${hostname}:${port}: ` + msg)
|
package/keys-filter.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const Transform = require('stream').Transform
|
|
4
|
-
const debug = require('debug')('signalk:streams:keys-filter')
|
|
5
4
|
|
|
6
5
|
function ToSignalK (options) {
|
|
7
6
|
Transform.call(this, {
|
|
8
7
|
objectMode: true
|
|
9
8
|
})
|
|
10
9
|
|
|
10
|
+
const createDebug = options.createDebug || require('debug')
|
|
11
|
+
this.debug = createDebug('signalk:streams:keys-filter')
|
|
11
12
|
this.exclude = options.excludeMatchingPaths
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -25,7 +26,7 @@ ToSignalK.prototype._transform = function (chunk, encoding, done) {
|
|
|
25
26
|
delta = JSON.parse(chunk)
|
|
26
27
|
string = true
|
|
27
28
|
} catch (e) {
|
|
28
|
-
debug(`Error parsing chunk: ${e.message}`)
|
|
29
|
+
this.debug(`Error parsing chunk: ${e.message}`)
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
package/logging.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
const { FileTimestampStream } = require('file-timestamp-stream')
|
|
18
18
|
const path = require('path')
|
|
19
|
-
|
|
19
|
+
let debug = require('debug')('signalk:streams:logging')
|
|
20
20
|
const fs = require('fs')
|
|
21
21
|
|
|
22
22
|
const filenamePattern = /skserver\-raw\_\d\d\d\d\-\d\d\-\d\dT\d\d\.log/
|
|
@@ -35,6 +35,7 @@ class FileTimestampStreamWithDelete extends FileTimestampStream {
|
|
|
35
35
|
this.filesToKeep = filesToKeep
|
|
36
36
|
this.fullLogDir = fullLogDir
|
|
37
37
|
this.prevFilename = undefined
|
|
38
|
+
debug = (options.createDebug || require('debug'))('signalk:streams:logging')
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
// This method of base class is called when new file name is contemplated
|
package/mdns-ws.js
CHANGED
|
@@ -18,8 +18,6 @@ const Transform = require('stream').Transform
|
|
|
18
18
|
|
|
19
19
|
const SignalK = require('@signalk/client')
|
|
20
20
|
|
|
21
|
-
const debug = require('debug')('signalk:streams:mdns-ws')
|
|
22
|
-
const dataDebug = require('debug')('signalk:streams:mdns-ws-data')
|
|
23
21
|
|
|
24
22
|
const WebSocket = require('ws')
|
|
25
23
|
|
|
@@ -33,6 +31,10 @@ function MdnsWs (options) {
|
|
|
33
31
|
this.remoteServers = {}
|
|
34
32
|
this.remoteServers[this.selfHost + ':' + this.selfPort] = {}
|
|
35
33
|
const deltaStreamBehaviour = options.subscription ? 'none' : 'all'
|
|
34
|
+
|
|
35
|
+
const createDebug = options.createDebug || require('debug')
|
|
36
|
+
this.debug = createDebug('signalk:streams:mdns-ws')
|
|
37
|
+
this.dataDebug = createDebug('signalk:streams:mdns-ws-data')
|
|
36
38
|
debug(`deltaStreamBehaviour:${deltaStreamBehaviour}`)
|
|
37
39
|
|
|
38
40
|
this.handleContext = () => { }
|
|
@@ -92,7 +94,7 @@ MdnsWs.prototype.connect = function (client) {
|
|
|
92
94
|
setProviderStatus(that, that.options.providerId, `ws connection connected to ${client.options.hostname}:${client.options.port}`)
|
|
93
95
|
if (this.options.selfHandling === 'useRemoteSelf') {
|
|
94
96
|
client.API().then(api => api.get('/self')).then(selfFromServer => {
|
|
95
|
-
debug(`Mapping context ${selfFromServer} to self (empty context)`)
|
|
97
|
+
that.debug(`Mapping context ${selfFromServer} to self (empty context)`)
|
|
96
98
|
this.handleContext = (delta) => {
|
|
97
99
|
if (delta.context === selfFromServer) {
|
|
98
100
|
delete delta.context
|
|
@@ -115,7 +117,7 @@ MdnsWs.prototype.connect = function (client) {
|
|
|
115
117
|
parsed = [ parsed ]
|
|
116
118
|
}
|
|
117
119
|
parsed.forEach((sub, idx) => {
|
|
118
|
-
debug('sending subscription %j', sub)
|
|
120
|
+
that.debug('sending subscription %j', sub)
|
|
119
121
|
client.subscribe(sub, String(idx))
|
|
120
122
|
})
|
|
121
123
|
}
|
|
@@ -127,7 +129,7 @@ MdnsWs.prototype.connect = function (client) {
|
|
|
127
129
|
client.on('delta', (data) => {
|
|
128
130
|
if (data && data.updates) {
|
|
129
131
|
that.handleContext(data)
|
|
130
|
-
if (dataDebug.enabled) { dataDebug(JSON.stringify(data)) }
|
|
132
|
+
if (that.dataDebug.enabled) { that.dataDebug(JSON.stringify(data)) }
|
|
131
133
|
data.updates.forEach(function (update) {
|
|
132
134
|
update['$source'] = `${that.options.providerId}.${client.options.hostname}:${client.options.port}`
|
|
133
135
|
})
|
package/n2kAnalyzer.js
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
const Transform = require('stream').Transform
|
|
18
|
-
const debug = require('debug')('signalk:streams:n2k-analyzer')
|
|
19
18
|
|
|
20
19
|
function N2KAnalyzer (options) {
|
|
21
20
|
Transform.call(this, {
|
|
@@ -68,7 +67,7 @@ N2KAnalyzer.prototype.pipe = function (pipeTo) {
|
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
N2KAnalyzer.prototype.end = function () {
|
|
71
|
-
|
|
70
|
+
console.log('end, killing child analyzer process')
|
|
72
71
|
this.analyzerProcess.kill()
|
|
73
72
|
this.pipeTo.end()
|
|
74
73
|
}
|
package/nmea0183-signalk.js
CHANGED
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
const Transform = require('stream').Transform
|
|
33
33
|
const Parser = require('@signalk/nmea0183-signalk')
|
|
34
34
|
const utils = require('@signalk/nmea0183-utilities')
|
|
35
|
-
const debug = require('debug')('signalk:streams:nmea0183-signalk')
|
|
36
35
|
const n2kToDelta = require('@signalk/n2k-signalk').toDelta
|
|
37
36
|
const FromPgn = require('@canboat/canboatjs').FromPgn
|
|
38
37
|
|
|
@@ -108,7 +107,7 @@ Nmea0183ToSignalK.prototype._transform = function (chunk, encoding, done) {
|
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
} catch (e) {
|
|
111
|
-
|
|
110
|
+
console.error(e)
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
done()
|
package/package.json
CHANGED
package/pigpio-seatalk.js
CHANGED
|
@@ -15,14 +15,13 @@
|
|
|
15
15
|
*
|
|
16
16
|
* You should have received a copy of the GNU General Public License
|
|
17
17
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*
|
|
18
|
+
*
|
|
19
19
|
* 2020-06-24 Original Python code from @Thomas-GeDaD https://github.com/Thomas-GeDaD/Seatalk1-Raspi-reader
|
|
20
20
|
* and finetuned by @MatsA
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
const Execute = require('./execute')
|
|
25
|
-
const debug = require('debug')('signalk:streams:pigpio-seatalk')
|
|
26
25
|
|
|
27
26
|
const cmd = `
|
|
28
27
|
import pigpio, time, signal, sys
|
|
@@ -79,13 +78,13 @@ if __name__ == "__main__":
|
|
|
79
78
|
print ("exit")
|
|
80
79
|
`
|
|
81
80
|
|
|
82
|
-
function PigpioSeatalk
|
|
83
|
-
|
|
81
|
+
function PigpioSeatalk(options) {
|
|
82
|
+
const createDebug = options.createDebug || require('debug')
|
|
83
|
+
Execute.call(this, { debug: createDebug('signalk:streams:pigpio-seatalk') })
|
|
84
84
|
this.options = options
|
|
85
85
|
this.options.command = `python -u -c '${cmd}' ${options.gpio} ${options.gpioInvert} `
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
require('util').inherits(PigpioSeatalk, Execute)
|
|
89
89
|
|
|
90
|
-
|
|
91
90
|
module.exports = PigpioSeatalk
|
package/s3.js
CHANGED
|
@@ -23,8 +23,7 @@ var Transform = require('stream').Transform
|
|
|
23
23
|
deprecation warnings.
|
|
24
24
|
Known to work with ^2.413.0
|
|
25
25
|
*/
|
|
26
|
-
const AWS = require('aws-sdk')
|
|
27
|
-
const debug = require('debug')('signalk:streams:s3-provider')
|
|
26
|
+
const AWS = require('aws-sdk')
|
|
28
27
|
|
|
29
28
|
function S3Provider ({ bucket, prefix }) {
|
|
30
29
|
Transform.call(this, {
|
package/serialport.js
CHANGED
|
@@ -62,7 +62,6 @@ 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
67
|
function SerialStream (options) {
|
|
@@ -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()
|
|
@@ -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,7 +145,6 @@ 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) {
|
|
@@ -152,10 +155,10 @@ SerialStream.prototype.start = function () {
|
|
|
152
155
|
|
|
153
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)
|
|
161
|
+
that.debug('Writing:' + d)
|
|
159
162
|
if ( isBuffer(d) ) {
|
|
160
163
|
that.serial.write(d)
|
|
161
164
|
} else {
|
|
@@ -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
|
}
|
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')
|
|
@@ -27,9 +26,14 @@ const pigpioSeatalk = require('./pigpio-seatalk')
|
|
|
27
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
|
package/tcp.js
CHANGED
|
@@ -32,23 +32,22 @@ const net = require('net')
|
|
|
32
32
|
const Transform = require('stream').Transform
|
|
33
33
|
const isArray = require('lodash').isArray
|
|
34
34
|
|
|
35
|
-
const debug = require('debug')('signalk-server:streams:tcp')
|
|
36
|
-
const debugData = require('debug')('signalk-server:streams:tcp-data')
|
|
37
|
-
|
|
38
35
|
function TcpStream (options) {
|
|
39
36
|
Transform.call(this, options)
|
|
40
37
|
this.options = options
|
|
41
38
|
this.noDataReceivedTimeout = Number.parseInt((this.options.noDataReceivedTimeout + '').trim()) * 1000
|
|
39
|
+
this.debug = (options.createDebug || require('debug'))('signalk:streams:tcp')
|
|
40
|
+
this.debugData = (options.createDebug || require('debug'))('signalk:streams:tcp-data')
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
require('util').inherits(TcpStream, Transform)
|
|
45
44
|
|
|
46
45
|
TcpStream.prototype.pipe = function (pipeTo) {
|
|
46
|
+
const that = this
|
|
47
47
|
if ( this.options.outEvent ) {
|
|
48
|
-
const that = this
|
|
49
48
|
that.options.app.on(that.options.outEvent, function (d) {
|
|
50
49
|
if ( that.tcpStream ) {
|
|
51
|
-
debug('sending %s', d)
|
|
50
|
+
that.debug('sending %s', d)
|
|
52
51
|
that.tcpStream.write(d)
|
|
53
52
|
}
|
|
54
53
|
})
|
|
@@ -61,7 +60,7 @@ TcpStream.prototype.pipe = function (pipeTo) {
|
|
|
61
60
|
that.options.app.on(stdEvent, function (d) {
|
|
62
61
|
if (that.tcpStream) {
|
|
63
62
|
that.tcpStream.write(d + '\r\n')
|
|
64
|
-
|
|
63
|
+
that. debug('event %s sending %s', stdEvent, d)
|
|
65
64
|
}
|
|
66
65
|
})
|
|
67
66
|
})
|
|
@@ -72,19 +71,19 @@ TcpStream.prototype.pipe = function (pipeTo) {
|
|
|
72
71
|
})({ maxDelay: 5 * 1000 }, tcpStream => {
|
|
73
72
|
if (!isNaN(this.noDataReceivedTimeout)) {
|
|
74
73
|
tcpStream.setTimeout(this.noDataReceivedTimeout)
|
|
75
|
-
debug(
|
|
74
|
+
that.debug(
|
|
76
75
|
`Setting socket idle timeout ${this.options.host}:${this.options.port} ${this.noDataReceivedTimeout}`
|
|
77
76
|
)
|
|
78
77
|
tcpStream.on('timeout', () => {
|
|
79
|
-
debug(
|
|
78
|
+
that.debug(
|
|
80
79
|
`Idle timeout, closing socket ${this.options.host}:${this.options.port}`
|
|
81
80
|
)
|
|
82
81
|
tcpStream.end()
|
|
83
82
|
})
|
|
84
83
|
}
|
|
85
84
|
tcpStream.on('data', data => {
|
|
86
|
-
if (debugData.enabled) {
|
|
87
|
-
debugData(data.toString())
|
|
85
|
+
if (that.debugData.enabled) {
|
|
86
|
+
that.debugData(data.toString())
|
|
88
87
|
}
|
|
89
88
|
this.write(data)
|
|
90
89
|
})
|
|
@@ -93,18 +92,18 @@ TcpStream.prototype.pipe = function (pipeTo) {
|
|
|
93
92
|
this.tcpStream = con
|
|
94
93
|
const msg = `Connected to ${this.options.host} ${this.options.port}`
|
|
95
94
|
this.options.app.setProviderStatus(this.options.providerId, msg)
|
|
96
|
-
debug(msg)
|
|
95
|
+
that.debug(msg)
|
|
97
96
|
})
|
|
98
97
|
.on('reconnect', (n, delay) => {
|
|
99
98
|
const msg = `Reconnect ${this.options.host} ${
|
|
100
99
|
this.options.port
|
|
101
100
|
} retry ${n} delay ${delay}`
|
|
102
101
|
this.options.app.setProviderError(this.options.providerId, msg)
|
|
103
|
-
debug(msg)
|
|
102
|
+
that.debug(msg)
|
|
104
103
|
})
|
|
105
104
|
.on('disconnect', err => {
|
|
106
105
|
delete this.tcpStream
|
|
107
|
-
debug(`Disconnected ${this.options.host} ${this.options.port}`)
|
|
106
|
+
that.debug(`Disconnected ${this.options.host} ${this.options.port}`)
|
|
108
107
|
})
|
|
109
108
|
.on('error', err => {
|
|
110
109
|
this.options.app.setProviderError(this.options.providerId, err.message)
|
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
38
|
function Udp (options) {
|
|
40
39
|
Transform.call(this, {
|
|
41
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)
|