@signalk/streams 5.1.0 → 5.1.3
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/package.json +1 -1
- package/serialport.js +41 -42
- package/simple.js +1 -0
package/package.json
CHANGED
package/serialport.js
CHANGED
|
@@ -82,13 +82,52 @@ function SerialStream(options) {
|
|
|
82
82
|
|
|
83
83
|
const createDebug = options.createDebug || require('debug')
|
|
84
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
|
+
})
|
|
85
126
|
}
|
|
86
127
|
|
|
87
128
|
require('util').inherits(SerialStream, Transform)
|
|
88
129
|
|
|
89
130
|
SerialStream.prototype.start = function () {
|
|
90
|
-
const that = this
|
|
91
|
-
|
|
92
131
|
if (this.serial !== null) {
|
|
93
132
|
this.serial.unpipe(this)
|
|
94
133
|
this.serial.removeAllListeners()
|
|
@@ -146,46 +185,6 @@ SerialStream.prototype.start = function () {
|
|
|
146
185
|
this.scheduleReconnect()
|
|
147
186
|
}.bind(this)
|
|
148
187
|
)
|
|
149
|
-
|
|
150
|
-
let pendingWrites = 0
|
|
151
|
-
const stdOutEvents = isArray(this.options.toStdout)
|
|
152
|
-
? this.options.toStdout
|
|
153
|
-
: [this.options.toStdout]
|
|
154
|
-
const standardOutEventName = `serial-${this.options.subOptions.providerId}-toStdout`
|
|
155
|
-
stdOutEvents.push(standardOutEventName)
|
|
156
|
-
|
|
157
|
-
stdOutEvents.forEach((event) => {
|
|
158
|
-
const onDrain = () => {
|
|
159
|
-
pendingWrites--
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
that.options.app.on(event, (d) => {
|
|
163
|
-
if (pendingWrites > that.maxPendingWrites) {
|
|
164
|
-
that.debug('Buffer overflow, not writing:' + d)
|
|
165
|
-
return
|
|
166
|
-
}
|
|
167
|
-
that.debug('Writing:' + d)
|
|
168
|
-
if (isBuffer(d)) {
|
|
169
|
-
that.serial.write(d)
|
|
170
|
-
} else {
|
|
171
|
-
that.serial.write(d + '\r\n')
|
|
172
|
-
}
|
|
173
|
-
setImmediate(() => {
|
|
174
|
-
that.options.app.emit('connectionwrite', {
|
|
175
|
-
providerId: that.options.providerId
|
|
176
|
-
})
|
|
177
|
-
})
|
|
178
|
-
pendingWrites++
|
|
179
|
-
that.serial.drain(onDrain)
|
|
180
|
-
})
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
this.options.app.emitPropertyValue('serialport', {
|
|
184
|
-
id: this.options.providerId,
|
|
185
|
-
eventNames: {
|
|
186
|
-
toStdout: standardOutEventName
|
|
187
|
-
}
|
|
188
|
-
})
|
|
189
188
|
}
|
|
190
189
|
|
|
191
190
|
SerialStream.prototype.end = function () {
|
package/simple.js
CHANGED
|
@@ -97,6 +97,7 @@ function Simple(options) {
|
|
|
97
97
|
const dataReceivedEventName = `${options.subOptions.providerId}-received`
|
|
98
98
|
|
|
99
99
|
const spy = new Transform({
|
|
100
|
+
objectMode: true,
|
|
100
101
|
transform(chunk, encoding, callback) {
|
|
101
102
|
options.app.emit(dataReceivedEventName, chunk)
|
|
102
103
|
callback(null, chunk)
|