@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/mdns-ws.js
CHANGED
|
@@ -18,14 +18,11 @@ 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
|
-
|
|
24
21
|
const WebSocket = require('ws')
|
|
25
22
|
|
|
26
|
-
function MdnsWs
|
|
23
|
+
function MdnsWs(options) {
|
|
27
24
|
Transform.call(this, {
|
|
28
|
-
objectMode: true
|
|
25
|
+
objectMode: true,
|
|
29
26
|
})
|
|
30
27
|
this.options = options
|
|
31
28
|
this.selfHost = options.app.config.getExternalHostname() + '.'
|
|
@@ -33,9 +30,13 @@ function MdnsWs (options) {
|
|
|
33
30
|
this.remoteServers = {}
|
|
34
31
|
this.remoteServers[this.selfHost + ':' + this.selfPort] = {}
|
|
35
32
|
const deltaStreamBehaviour = options.subscription ? 'none' : 'all'
|
|
33
|
+
|
|
34
|
+
const createDebug = options.createDebug || require('debug')
|
|
35
|
+
this.debug = createDebug('signalk:streams:mdns-ws')
|
|
36
|
+
this.dataDebug = createDebug('signalk:streams:mdns-ws-data')
|
|
36
37
|
debug(`deltaStreamBehaviour:${deltaStreamBehaviour}`)
|
|
37
38
|
|
|
38
|
-
this.handleContext = () => {
|
|
39
|
+
this.handleContext = () => {}
|
|
39
40
|
if (options.selfHandling === 'manualSelf') {
|
|
40
41
|
if (options.remoteSelf) {
|
|
41
42
|
debug(`Using manual remote self ${options.remoteSelf}`)
|
|
@@ -45,12 +46,14 @@ function MdnsWs (options) {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
} else {
|
|
48
|
-
console.error(
|
|
49
|
+
console.error(
|
|
50
|
+
'Manual self handling speficied but no remoteSelf configured'
|
|
51
|
+
)
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
if (options.ignoreServers) {
|
|
53
|
-
options.ignoreServers.forEach(s => {
|
|
56
|
+
options.ignoreServers.forEach((s) => {
|
|
54
57
|
this.remoteServers[s] = {}
|
|
55
58
|
})
|
|
56
59
|
}
|
|
@@ -62,18 +65,21 @@ function MdnsWs (options) {
|
|
|
62
65
|
reconnect: true,
|
|
63
66
|
autoConnect: false,
|
|
64
67
|
deltaStreamBehaviour,
|
|
65
|
-
rejectUnauthorized: !(options.selfsignedcert === true)
|
|
68
|
+
rejectUnauthorized: !(options.selfsignedcert === true),
|
|
66
69
|
})
|
|
67
70
|
this.connect(this.signalkClient)
|
|
68
71
|
} else {
|
|
69
|
-
this.options.app.setProviderError(
|
|
72
|
+
this.options.app.setProviderError(
|
|
73
|
+
this.options.providerId,
|
|
74
|
+
'This connection is deprecated and must be deleted'
|
|
75
|
+
)
|
|
70
76
|
return
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
require('util').inherits(MdnsWs, Transform)
|
|
75
81
|
|
|
76
|
-
function setProviderStatus
|
|
82
|
+
function setProviderStatus(that, providerId, message, isError) {
|
|
77
83
|
if (!isError) {
|
|
78
84
|
that.options.app.setProviderStatus(providerId, message)
|
|
79
85
|
console.log(message)
|
|
@@ -89,50 +95,70 @@ MdnsWs.prototype.connect = function (client) {
|
|
|
89
95
|
client
|
|
90
96
|
.connect()
|
|
91
97
|
.then(() => {
|
|
92
|
-
setProviderStatus(
|
|
98
|
+
setProviderStatus(
|
|
99
|
+
that,
|
|
100
|
+
that.options.providerId,
|
|
101
|
+
`ws connection connected to ${client.options.hostname}:${client.options.port}`
|
|
102
|
+
)
|
|
93
103
|
if (this.options.selfHandling === 'useRemoteSelf') {
|
|
94
|
-
client
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
client
|
|
105
|
+
.API()
|
|
106
|
+
.then((api) => api.get('/self'))
|
|
107
|
+
.then((selfFromServer) => {
|
|
108
|
+
that.debug(
|
|
109
|
+
`Mapping context ${selfFromServer} to self (empty context)`
|
|
110
|
+
)
|
|
111
|
+
this.handleContext = (delta) => {
|
|
112
|
+
if (delta.context === selfFromServer) {
|
|
113
|
+
delete delta.context
|
|
114
|
+
}
|
|
99
115
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
116
|
+
})
|
|
117
|
+
.catch((err) => {
|
|
118
|
+
console.error('Error retrieving self from remote server')
|
|
119
|
+
console.error(err)
|
|
120
|
+
})
|
|
105
121
|
}
|
|
106
|
-
that.remoteServers[client.options.hostname + ':' + client.options.port] =
|
|
107
|
-
|
|
108
|
-
|
|
122
|
+
that.remoteServers[client.options.hostname + ':' + client.options.port] =
|
|
123
|
+
client
|
|
124
|
+
if (that.options.subscription) {
|
|
125
|
+
let parsed
|
|
109
126
|
try {
|
|
110
127
|
parsed = JSON.parse(that.options.subscription)
|
|
111
|
-
} catch (
|
|
112
|
-
setProviderStatus(
|
|
128
|
+
} catch (ex) {
|
|
129
|
+
setProviderStatus(
|
|
130
|
+
that,
|
|
131
|
+
that.options.providerId,
|
|
132
|
+
`unable to parse subscription json: ${that.options.subscription}: ${ex.message}`,
|
|
133
|
+
true
|
|
134
|
+
)
|
|
113
135
|
}
|
|
114
|
-
if (
|
|
115
|
-
parsed = [
|
|
136
|
+
if (!Array.isArray(parsed)) {
|
|
137
|
+
parsed = [parsed]
|
|
116
138
|
}
|
|
117
139
|
parsed.forEach((sub, idx) => {
|
|
118
|
-
debug('sending subscription %j', sub)
|
|
140
|
+
that.debug('sending subscription %j', sub)
|
|
119
141
|
client.subscribe(sub, String(idx))
|
|
120
142
|
})
|
|
121
143
|
}
|
|
122
144
|
})
|
|
123
|
-
.catch(err => {
|
|
145
|
+
.catch((err) => {
|
|
124
146
|
setProviderStatus(that, that.options.providerId, err.message, true)
|
|
125
147
|
})
|
|
126
|
-
|
|
148
|
+
|
|
127
149
|
client.on('delta', (data) => {
|
|
128
150
|
if (data && data.updates) {
|
|
129
151
|
that.handleContext(data)
|
|
130
|
-
if (dataDebug.enabled) {
|
|
152
|
+
if (that.dataDebug.enabled) {
|
|
153
|
+
that.dataDebug(JSON.stringify(data))
|
|
154
|
+
}
|
|
131
155
|
data.updates.forEach(function (update) {
|
|
132
|
-
update[
|
|
156
|
+
update[
|
|
157
|
+
'$source'
|
|
158
|
+
] = `${that.options.providerId}.${client.options.hostname}:${client.options.port}`
|
|
133
159
|
})
|
|
134
160
|
}
|
|
135
|
-
|
|
161
|
+
|
|
136
162
|
that.push(data)
|
|
137
163
|
})
|
|
138
164
|
}
|
package/n2k-signalk.js
CHANGED
|
@@ -20,22 +20,22 @@ const N2kMapper = require('@signalk/n2k-signalk').N2kMapper
|
|
|
20
20
|
|
|
21
21
|
require('util').inherits(ToSignalK, Transform)
|
|
22
22
|
|
|
23
|
-
function ToSignalK
|
|
23
|
+
function ToSignalK(options) {
|
|
24
24
|
Transform.call(this, {
|
|
25
|
-
objectMode: true
|
|
25
|
+
objectMode: true,
|
|
26
26
|
})
|
|
27
27
|
const n2kOutEvent = 'nmea2000JsonOut'
|
|
28
28
|
this.sourceMeta = {}
|
|
29
29
|
this.notifications = {}
|
|
30
30
|
this.options = options
|
|
31
31
|
this.app = options.app
|
|
32
|
-
if (
|
|
33
|
-
this.filters = options.filters.filter(f => {
|
|
32
|
+
if (options.filters && options.filtersEnabled) {
|
|
33
|
+
this.filters = options.filters.filter((f) => {
|
|
34
34
|
return (f.source && f.source.length) || (f.pgn && f.pgn.length)
|
|
35
35
|
})
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
this.n2kMapper = new N2kMapper({...options, sendMetaData: true})
|
|
38
|
+
this.n2kMapper = new N2kMapper({ ...options, sendMetaData: true })
|
|
39
39
|
|
|
40
40
|
this.n2kMapper.on('n2kOut', (pgn) => this.app.emit('nmea2000JsonOut', pgn))
|
|
41
41
|
|
|
@@ -43,7 +43,7 @@ function ToSignalK (options) {
|
|
|
43
43
|
const existing = this.sourceMeta[n2k.src] || {}
|
|
44
44
|
this.sourceMeta[n2k.src] = {
|
|
45
45
|
...existing,
|
|
46
|
-
...meta
|
|
46
|
+
...meta,
|
|
47
47
|
}
|
|
48
48
|
const delta = {
|
|
49
49
|
context: this.app.selfContext,
|
|
@@ -54,21 +54,24 @@ function ToSignalK (options) {
|
|
|
54
54
|
label: this.options.providerId,
|
|
55
55
|
type: 'NMEA2000',
|
|
56
56
|
pgn: Number(n2k.pgn),
|
|
57
|
-
src: n2k.src.toString()
|
|
57
|
+
src: n2k.src.toString(),
|
|
58
58
|
},
|
|
59
59
|
timestamp:
|
|
60
60
|
n2k.timestamp.substring(0, 10) +
|
|
61
61
|
'T' +
|
|
62
62
|
n2k.timestamp.substring(11, n2k.timestamp.length),
|
|
63
|
-
values: []
|
|
64
|
-
}
|
|
65
|
-
]
|
|
63
|
+
values: [],
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
66
|
}
|
|
67
|
-
this.app.deltaCache.setSourceDelta(
|
|
67
|
+
this.app.deltaCache.setSourceDelta(
|
|
68
|
+
`${this.options.providerId}.${n2k.src}`,
|
|
69
|
+
delta
|
|
70
|
+
)
|
|
68
71
|
})
|
|
69
72
|
|
|
70
73
|
this.n2kMapper.on('n2kSourceMetadataTimeout', (pgn, src) => {
|
|
71
|
-
if (
|
|
74
|
+
if (pgn == 60928) {
|
|
72
75
|
console.warn(`n2k-signalk: unable to detect can name for src ${src}`)
|
|
73
76
|
this.sourceMeta[src].unknowCanName = true
|
|
74
77
|
}
|
|
@@ -76,86 +79,110 @@ function ToSignalK (options) {
|
|
|
76
79
|
|
|
77
80
|
this.n2kMapper.on('n2kSourceChanged', (src, from, to) => {
|
|
78
81
|
console.warn(`n2k-signalk: address ${src} changed from ${from} ${to}`)
|
|
79
|
-
if (
|
|
82
|
+
if (this.sourceMeta[src]) {
|
|
80
83
|
delete this.sourceMeta[src]
|
|
81
84
|
}
|
|
82
85
|
})
|
|
83
86
|
|
|
84
|
-
if (
|
|
87
|
+
if (this.app.isNmea2000OutAvailable) {
|
|
85
88
|
this.n2kMapper.n2kOutIsAvailable(this.app, n2kOutEvent)
|
|
86
89
|
} else {
|
|
87
90
|
this.app.on('nmea2000OutAvailable', () =>
|
|
88
|
-
|
|
91
|
+
this.n2kMapper.n2kOutIsAvailable(this.app, n2kOutEvent)
|
|
92
|
+
)
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
ToSignalK.prototype.isFiltered = function(source) {
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
ToSignalK.prototype.isFiltered = function (source) {
|
|
97
|
+
return (
|
|
98
|
+
this.filters &&
|
|
99
|
+
this.filters.find((filter) => {
|
|
100
|
+
const sFilter = this.options.useCanName ? source.canName : source.src
|
|
101
|
+
return (
|
|
102
|
+
(!filter.source ||
|
|
103
|
+
filter.source.length === 0 ||
|
|
104
|
+
filter.source == sFilter) &&
|
|
105
|
+
(!filter.pgn || filter.pgn.length === 0 || filter.pgn == source.pgn)
|
|
106
|
+
)
|
|
107
|
+
})
|
|
108
|
+
)
|
|
97
109
|
}
|
|
98
110
|
|
|
99
111
|
ToSignalK.prototype._transform = function (chunk, encoding, done) {
|
|
100
112
|
try {
|
|
101
113
|
const delta = this.n2kMapper.toDelta(chunk)
|
|
102
|
-
|
|
114
|
+
|
|
103
115
|
const src = Number(chunk.src)
|
|
104
|
-
if (
|
|
116
|
+
if (!this.sourceMeta[src]) {
|
|
105
117
|
this.sourceMeta[src] = {}
|
|
106
|
-
}
|
|
118
|
+
}
|
|
107
119
|
|
|
108
|
-
if (
|
|
109
|
-
|
|
120
|
+
if (
|
|
121
|
+
delta &&
|
|
122
|
+
delta.updates[0].values.length > 0 &&
|
|
123
|
+
!this.isFiltered(delta.updates[0].source)
|
|
124
|
+
) {
|
|
125
|
+
if (!this.options.useCanName) {
|
|
110
126
|
delete delta.updates[0].source.canName
|
|
111
127
|
}
|
|
112
128
|
|
|
113
129
|
const canName = delta.updates[0].source.canName
|
|
114
|
-
|
|
115
|
-
if (
|
|
130
|
+
|
|
131
|
+
if (
|
|
132
|
+
this.options.useCanName &&
|
|
133
|
+
!canName &&
|
|
134
|
+
!this.sourceMeta[src].unknowCanName
|
|
135
|
+
) {
|
|
116
136
|
done()
|
|
117
137
|
return
|
|
118
138
|
}
|
|
119
139
|
|
|
120
|
-
delta.updates.forEach(update => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
140
|
+
delta.updates.forEach((update) => {
|
|
141
|
+
update.values.forEach((kv) => {
|
|
142
|
+
if (kv.path && kv.path.startsWith('notifications.')) {
|
|
143
|
+
if (
|
|
144
|
+
kv.value.state === 'normal' &&
|
|
145
|
+
this.notifications[kv.path] &&
|
|
146
|
+
this.notifications[kv.path][src]
|
|
147
|
+
) {
|
|
148
|
+
clearInterval(this.notifications[kv.path][src].interval)
|
|
149
|
+
delete this.notifications[kv.path][src]
|
|
150
|
+
} else if (kv.value.state !== 'normal') {
|
|
151
|
+
if (!this.notifications[kv.path]) {
|
|
152
|
+
this.notifications[kv.path] = {}
|
|
153
|
+
}
|
|
154
|
+
if (!this.notifications[kv.path][src]) {
|
|
155
|
+
const interval = setInterval(() => {
|
|
156
|
+
if (
|
|
157
|
+
Date.now() - this.notifications[kv.path][src].lastTime >
|
|
158
|
+
10000
|
|
159
|
+
) {
|
|
160
|
+
const copy = JSON.parse(JSON.stringify(kv))
|
|
161
|
+
copy.value.state = 'normal'
|
|
162
|
+
const normalDelta = {
|
|
163
|
+
context: delta.context,
|
|
164
|
+
updates: [
|
|
165
|
+
{
|
|
166
|
+
source: update.source,
|
|
167
|
+
values: [copy],
|
|
168
|
+
},
|
|
169
|
+
],
|
|
147
170
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
interval: interval
|
|
171
|
+
delete this.notifications[kv.path][src]
|
|
172
|
+
clearInterval(interval)
|
|
173
|
+
this.app.handleMessage(this.options.providerId, normalDelta)
|
|
152
174
|
}
|
|
153
|
-
}
|
|
154
|
-
|
|
175
|
+
}, 5000)
|
|
176
|
+
this.notifications[kv.path][src] = {
|
|
177
|
+
lastTime: Date.now(),
|
|
178
|
+
interval: interval,
|
|
155
179
|
}
|
|
180
|
+
} else {
|
|
181
|
+
this.notifications[kv.path][src].lastTime = Date.now()
|
|
156
182
|
}
|
|
157
183
|
}
|
|
158
|
-
}
|
|
184
|
+
}
|
|
185
|
+
})
|
|
159
186
|
})
|
|
160
187
|
this.push(delta)
|
|
161
188
|
}
|
package/n2kAnalyzer.js
CHANGED
|
@@ -15,21 +15,20 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
const Transform = require('stream').Transform
|
|
18
|
-
const debug = require('debug')('signalk:streams:n2k-analyzer')
|
|
19
18
|
|
|
20
|
-
function N2KAnalyzer
|
|
19
|
+
function N2KAnalyzer(options) {
|
|
21
20
|
Transform.call(this, {
|
|
22
|
-
objectMode: true
|
|
21
|
+
objectMode: true,
|
|
23
22
|
})
|
|
24
23
|
if (process.platform === 'win32') {
|
|
25
24
|
this.analyzerProcess = require('child_process').spawn('cmd', [
|
|
26
25
|
'/c',
|
|
27
|
-
'analyzer -json -si'
|
|
26
|
+
'analyzer -json -si',
|
|
28
27
|
])
|
|
29
28
|
} else {
|
|
30
29
|
this.analyzerProcess = require('child_process').spawn('sh', [
|
|
31
30
|
'-c',
|
|
32
|
-
'analyzer -json -si'
|
|
31
|
+
'analyzer -json -si',
|
|
33
32
|
])
|
|
34
33
|
}
|
|
35
34
|
this.analyzerProcess.stderr.on('data', function (data) {
|
|
@@ -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,13 +32,12 @@
|
|
|
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
|
|
|
39
|
-
function Nmea0183ToSignalK
|
|
38
|
+
function Nmea0183ToSignalK(options) {
|
|
40
39
|
Transform.call(this, {
|
|
41
|
-
objectMode: true
|
|
40
|
+
objectMode: true,
|
|
42
41
|
})
|
|
43
42
|
|
|
44
43
|
this.parser = new Parser(options)
|
|
@@ -50,7 +49,7 @@ function Nmea0183ToSignalK (options) {
|
|
|
50
49
|
|
|
51
50
|
// Prepare a list of events to send for each sentence received
|
|
52
51
|
this.sentenceEvents = options.suppress0183event ? [] : ['nmea0183']
|
|
53
|
-
this.appendChecksum = options.appendChecksum
|
|
52
|
+
this.appendChecksum = options.appendChecksum
|
|
54
53
|
|
|
55
54
|
if (options.sentenceEvent) {
|
|
56
55
|
if (Array.isArray(options.sentenceEvent)) {
|
|
@@ -79,19 +78,19 @@ Nmea0183ToSignalK.prototype._transform = function (chunk, encoding, done) {
|
|
|
79
78
|
try {
|
|
80
79
|
if (sentence !== undefined) {
|
|
81
80
|
if (this.appendChecksum) {
|
|
82
|
-
sentence = utils.appendChecksum(sentence)
|
|
81
|
+
sentence = utils.appendChecksum(sentence)
|
|
83
82
|
}
|
|
84
83
|
// Send 'sentences' event to the app for each sentence
|
|
85
|
-
this.sentenceEvents.forEach(eventName => {
|
|
84
|
+
this.sentenceEvents.forEach((eventName) => {
|
|
86
85
|
this.app.emit(eventName, sentence)
|
|
87
86
|
this.app.signalk.emit(eventName, sentence)
|
|
88
87
|
})
|
|
89
88
|
|
|
90
89
|
let delta = null
|
|
91
|
-
if (
|
|
90
|
+
if (this.n2kParser.isN2KOver0183(sentence)) {
|
|
92
91
|
const pgn = this.n2kParser.parseN2KOver0183(sentence)
|
|
93
|
-
if (
|
|
94
|
-
delta = n2kToDelta(pgn, this.state, {sendMetaData: true})
|
|
92
|
+
if (pgn) {
|
|
93
|
+
delta = n2kToDelta(pgn, this.state, { sendMetaData: true })
|
|
95
94
|
}
|
|
96
95
|
} else {
|
|
97
96
|
delta = this.parser.parse(sentence)
|
|
@@ -99,7 +98,7 @@ Nmea0183ToSignalK.prototype._transform = function (chunk, encoding, done) {
|
|
|
99
98
|
|
|
100
99
|
if (delta !== null) {
|
|
101
100
|
if (timestamp !== null) {
|
|
102
|
-
delta.updates.forEach(update => {
|
|
101
|
+
delta.updates.forEach((update) => {
|
|
103
102
|
update.timestamp = timestamp
|
|
104
103
|
})
|
|
105
104
|
}
|
|
@@ -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/nullprovider.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signalk/streams",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Utilities for handling streams of Signal K data",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"ci": "prettier --check .",
|
|
8
|
+
"format": "prettier --write ."
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -28,7 +29,6 @@
|
|
|
28
29
|
"@signalk/nmea0183-utilities": "^0.8.0",
|
|
29
30
|
"@signalk/signalk-schema": "^1.5.0",
|
|
30
31
|
"any-shell-escape": "^0.1.1",
|
|
31
|
-
"aws-sdk": "^2.413.0",
|
|
32
32
|
"file-timestamp-stream": "^2.1.2",
|
|
33
33
|
"lodash": "^4.17.4",
|
|
34
34
|
"moment": "^2.24.0",
|
|
@@ -38,5 +38,8 @@
|
|
|
38
38
|
},
|
|
39
39
|
"optionalDependencies": {
|
|
40
40
|
"serialport": "^9.0.1"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"prettier": "2.5.1"
|
|
41
44
|
}
|
|
42
45
|
}
|
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/replacer.js
CHANGED
|
@@ -14,21 +14,19 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
const Transform = require('stream').Transform
|
|
19
18
|
|
|
20
19
|
require('util').inherits(Replacer, Transform)
|
|
21
20
|
|
|
22
|
-
function Replacer
|
|
21
|
+
function Replacer(options) {
|
|
23
22
|
Transform.call(this, {
|
|
24
|
-
objectMode: true
|
|
23
|
+
objectMode: true,
|
|
25
24
|
})
|
|
26
25
|
this.doPush = this.push.bind(this)
|
|
27
26
|
this.regexp = new RegExp(options.regexp, 'gu')
|
|
28
27
|
this.template = options.template
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
|
|
32
30
|
Replacer.prototype._transform = function (chunk, encoding, done) {
|
|
33
31
|
this.doPush(chunk.toString().replace(this.regexp, this.template))
|
|
34
32
|
done()
|
package/s3.js
CHANGED
|
@@ -15,12 +15,19 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
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
|
+
*/
|
|
18
26
|
const AWS = require('aws-sdk')
|
|
19
|
-
const debug = require('debug')('signalk:streams:s3-provider')
|
|
20
27
|
|
|
21
|
-
function S3Provider
|
|
28
|
+
function S3Provider({ bucket, prefix }) {
|
|
22
29
|
Transform.call(this, {
|
|
23
|
-
objectMode: false
|
|
30
|
+
objectMode: false,
|
|
24
31
|
})
|
|
25
32
|
this.Bucket = bucket
|
|
26
33
|
this.Prefix = prefix
|
|
@@ -34,12 +41,12 @@ S3Provider.prototype.pipe = function (pipeTo) {
|
|
|
34
41
|
const s3 = new AWS.S3()
|
|
35
42
|
const params = {
|
|
36
43
|
Bucket: this.Bucket,
|
|
37
|
-
Prefix: this.Prefix
|
|
44
|
+
Prefix: this.Prefix,
|
|
38
45
|
}
|
|
39
46
|
console.log('listobjects')
|
|
40
47
|
s3.listObjects(params)
|
|
41
48
|
.promise()
|
|
42
|
-
.then(data => {
|
|
49
|
+
.then((data) => {
|
|
43
50
|
// console.log(data)
|
|
44
51
|
const jobs = data.Contents.map(
|
|
45
52
|
(item, i) =>
|
|
@@ -48,18 +55,15 @@ S3Provider.prototype.pipe = function (pipeTo) {
|
|
|
48
55
|
console.log('Starting key ' + item.Key)
|
|
49
56
|
const objectParams = {
|
|
50
57
|
Bucket: params.Bucket,
|
|
51
|
-
Key: item.Key
|
|
58
|
+
Key: item.Key,
|
|
52
59
|
}
|
|
53
60
|
const request = s3.getObject(objectParams)
|
|
54
|
-
request.on('error', err => {
|
|
61
|
+
request.on('error', (err) => {
|
|
55
62
|
console.log(err)
|
|
56
63
|
})
|
|
57
64
|
const stream = request.createReadStream()
|
|
58
65
|
stream.on('end', resolve)
|
|
59
|
-
stream.pipe(
|
|
60
|
-
pipeTo,
|
|
61
|
-
{ end: i === data.Contents.length-1 }
|
|
62
|
-
)
|
|
66
|
+
stream.pipe(pipeTo, { end: i === data.Contents.length - 1 })
|
|
63
67
|
})
|
|
64
68
|
}
|
|
65
69
|
)
|
|
@@ -67,14 +71,14 @@ S3Provider.prototype.pipe = function (pipeTo) {
|
|
|
67
71
|
let i = 0
|
|
68
72
|
function startNext() {
|
|
69
73
|
if (i < jobs.length) {
|
|
70
|
-
jobs[i++]().then(startNext)
|
|
74
|
+
jobs[i++]().then(startNext)
|
|
71
75
|
} else {
|
|
72
76
|
doEnd()
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
|
-
startNext()
|
|
79
|
+
startNext()
|
|
76
80
|
})
|
|
77
|
-
.catch(error => {
|
|
81
|
+
.catch((error) => {
|
|
78
82
|
console.error(error)
|
|
79
83
|
})
|
|
80
84
|
return pipeTo
|