nodejs-poolcontroller 7.3.1 → 7.6.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/.eslintrc.json +44 -44
- package/.github/ISSUE_TEMPLATE/bug_report.md +52 -52
- package/CONTRIBUTING.md +74 -74
- package/Changelog +215 -195
- package/Dockerfile +17 -17
- package/Gruntfile.js +40 -40
- package/LICENSE +661 -661
- package/README.md +191 -186
- package/app.ts +2 -0
- package/config/Config.ts +27 -2
- package/config/VersionCheck.ts +33 -14
- package/config copy.json +299 -299
- package/controller/Constants.ts +88 -0
- package/controller/Equipment.ts +2459 -2225
- package/controller/Errors.ts +180 -157
- package/controller/Lockouts.ts +437 -0
- package/controller/State.ts +364 -79
- package/controller/boards/BoardFactory.ts +45 -45
- package/controller/boards/EasyTouchBoard.ts +2653 -2489
- package/controller/boards/IntelliCenterBoard.ts +4230 -3973
- package/controller/boards/IntelliComBoard.ts +63 -63
- package/controller/boards/IntelliTouchBoard.ts +241 -167
- package/controller/boards/NixieBoard.ts +1675 -1105
- package/controller/boards/SystemBoard.ts +4697 -3201
- package/controller/comms/Comms.ts +222 -10
- package/controller/comms/messages/Messages.ts +13 -9
- package/controller/comms/messages/config/ChlorinatorMessage.ts +13 -4
- package/controller/comms/messages/config/CircuitGroupMessage.ts +6 -0
- package/controller/comms/messages/config/CircuitMessage.ts +0 -0
- package/controller/comms/messages/config/ConfigMessage.ts +0 -0
- package/controller/comms/messages/config/CoverMessage.ts +1 -0
- package/controller/comms/messages/config/CustomNameMessage.ts +30 -30
- package/controller/comms/messages/config/EquipmentMessage.ts +4 -0
- package/controller/comms/messages/config/ExternalMessage.ts +53 -33
- package/controller/comms/messages/config/FeatureMessage.ts +8 -1
- package/controller/comms/messages/config/GeneralMessage.ts +8 -0
- package/controller/comms/messages/config/HeaterMessage.ts +14 -28
- package/controller/comms/messages/config/IntellichemMessage.ts +4 -1
- package/controller/comms/messages/config/OptionsMessage.ts +38 -2
- package/controller/comms/messages/config/PumpMessage.ts +4 -20
- package/controller/comms/messages/config/RemoteMessage.ts +4 -0
- package/controller/comms/messages/config/ScheduleMessage.ts +347 -331
- package/controller/comms/messages/config/SecurityMessage.ts +1 -0
- package/controller/comms/messages/config/ValveMessage.ts +13 -3
- package/controller/comms/messages/status/ChlorinatorStateMessage.ts +2 -3
- package/controller/comms/messages/status/EquipmentStateMessage.ts +79 -25
- package/controller/comms/messages/status/HeaterStateMessage.ts +86 -53
- package/controller/comms/messages/status/IntelliChemStateMessage.ts +445 -386
- package/controller/comms/messages/status/IntelliValveStateMessage.ts +35 -35
- package/controller/comms/messages/status/PumpStateMessage.ts +0 -0
- package/controller/comms/messages/status/VersionMessage.ts +0 -0
- package/controller/nixie/Nixie.ts +162 -160
- package/controller/nixie/NixieEquipment.ts +103 -103
- package/controller/nixie/bodies/Body.ts +120 -117
- package/controller/nixie/bodies/Filter.ts +135 -135
- package/controller/nixie/chemistry/ChemController.ts +2498 -2395
- package/controller/nixie/chemistry/Chlorinator.ts +314 -313
- package/controller/nixie/circuits/Circuit.ts +248 -210
- package/controller/nixie/heaters/Heater.ts +649 -441
- package/controller/nixie/pumps/Pump.ts +661 -599
- package/controller/nixie/schedules/Schedule.ts +257 -256
- package/controller/nixie/valves/Valve.ts +170 -170
- package/defaultConfig.json +286 -271
- package/issue_template.md +51 -51
- package/logger/DataLogger.ts +448 -433
- package/logger/Logger.ts +0 -0
- package/package.json +56 -54
- package/tsconfig.json +25 -25
- package/web/Server.ts +522 -31
- package/web/bindings/influxDB.json +1022 -894
- package/web/bindings/mqtt.json +654 -543
- package/web/bindings/mqttAlt.json +684 -574
- package/web/bindings/rulesManager.json +54 -54
- package/web/bindings/smartThings-Hubitat.json +31 -31
- package/web/bindings/valveRelays.json +20 -20
- package/web/bindings/vera.json +25 -25
- package/web/interfaces/baseInterface.ts +136 -136
- package/web/interfaces/httpInterface.ts +124 -122
- package/web/interfaces/influxInterface.ts +245 -240
- package/web/interfaces/mqttInterface.ts +475 -464
- package/web/services/config/Config.ts +181 -152
- package/web/services/config/ConfigSocket.ts +0 -0
- package/web/services/state/State.ts +118 -7
- package/web/services/state/StateSocket.ts +18 -1
- package/web/services/utilities/Utilities.ts +42 -42
|
@@ -1,599 +1,661 @@
|
|
|
1
|
-
import { EquipmentNotFoundError, InvalidEquipmentDataError, InvalidEquipmentIdError, ParameterOutOfRangeError } from '../../Errors';
|
|
2
|
-
import { utils, Timestamp } from '../../Constants';
|
|
3
|
-
import { logger } from '../../../logger/Logger';
|
|
4
|
-
|
|
5
|
-
import { NixieEquipment, NixieChildEquipment, NixieEquipmentCollection, INixieControlPanel } from "../NixieEquipment";
|
|
6
|
-
import { Pump, PumpCircuit, PumpCollection, PumpRelay, sys } from "../../../controller/Equipment";
|
|
7
|
-
import { CircuitState, PumpState, state, } from "../../State";
|
|
8
|
-
import { setTimeout, clearTimeout } from 'timers';
|
|
9
|
-
import { NixieControlPanel } from '../Nixie';
|
|
10
|
-
import { webApp, InterfaceServerResponse } from "../../../web/Server";
|
|
11
|
-
import { Outbound, Protocol } from '../../comms/messages/Messages';
|
|
12
|
-
import { conn } from '../../comms/Comms';
|
|
13
|
-
|
|
14
|
-
export class NixiePumpCollection extends NixieEquipmentCollection<NixiePump> {
|
|
15
|
-
public async deletePumpAsync(id: number) {
|
|
16
|
-
try {
|
|
17
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
18
|
-
let pump = this[i];
|
|
19
|
-
if (pump.id === id) {
|
|
20
|
-
await pump.closeAsync();
|
|
21
|
-
this.splice(i, 1);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
} catch (err) { logger.error(`Nixie Control Panel deletePumpAsync ${err.message}`); }
|
|
25
|
-
}
|
|
26
|
-
public async setPumpStateAsync(pstate: PumpState) {
|
|
27
|
-
try {
|
|
28
|
-
let pump: NixiePump = this.find(elem => elem.id === pstate.id) as NixiePump;
|
|
29
|
-
if (typeof pump === 'undefined') {
|
|
30
|
-
return logger.error(`Nixie Control Panel Error setPumpState could not find pump ${pstate.id}-${pstate.name}`);
|
|
31
|
-
}
|
|
32
|
-
await pump.setPumpStateAsync(pstate);
|
|
33
|
-
} catch (err) { logger.error(`Nixie Error setting pump state ${pstate.id}-${pstate.name}: ${err.message}`); return Promise.reject(err); }
|
|
34
|
-
}
|
|
35
|
-
public async setPumpAsync(pump: Pump, data: any) {
|
|
36
|
-
// By the time we get here we know that we are in control and this is a Nixie pump.
|
|
37
|
-
try {
|
|
38
|
-
let c: NixiePump = this.find(elem => elem.id === pump.id) as NixiePump;
|
|
39
|
-
if (typeof c === 'undefined') {
|
|
40
|
-
pump.master = 1;
|
|
41
|
-
if (typeof data.type !== 'undefined') pump.type = data.type; // needed for init of correct type
|
|
42
|
-
if (typeof pump.type === 'undefined') return Promise.reject(new InvalidEquipmentIdError(`Invalid pump type for ${pump.name}`, data.id, 'Pump'));
|
|
43
|
-
c = this.pumpFactory(pump);
|
|
44
|
-
// c = new NixiePump(this.controlPanel, pump);
|
|
45
|
-
this.push(c);
|
|
46
|
-
logger.info(`A pump was not found for id #${pump.id} creating pump`);
|
|
47
|
-
return await c.setPumpAsync(data);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
if (typeof data.type !== 'undefined' && c.pump.type !== data.type) {
|
|
51
|
-
// pump exists, changing type
|
|
52
|
-
await c.closeAsync();
|
|
53
|
-
pump.type = data.type; // needed for init of correct type
|
|
54
|
-
if (typeof pump.type === 'undefined') return Promise.reject(new InvalidEquipmentIdError(`Invalid pump type for ${pump.name}`, data.id, 'Pump'));
|
|
55
|
-
c = this.pumpFactory(pump);
|
|
56
|
-
}
|
|
57
|
-
return await c.setPumpAsync(data);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch (err) { logger.error(`setPumpAsync: ${err.message}`); return Promise.reject(err); }
|
|
61
|
-
}
|
|
62
|
-
public async initAsync(pumps: PumpCollection) {
|
|
63
|
-
try {
|
|
64
|
-
for (let i = 0; i < pumps.length; i++) {
|
|
65
|
-
let pump = pumps.getItemByIndex(i);
|
|
66
|
-
if (pump.master === 1) {
|
|
67
|
-
if (typeof this.find(elem => elem.id === pump.id) === 'undefined') {
|
|
68
|
-
let type = sys.board.valueMaps.pumpTypes.getName(pump.type);
|
|
69
|
-
let npump = this.pumpFactory(pump);
|
|
70
|
-
logger.info(`Initializing Nixie Pump ${npump.id}-${pump.name}`);
|
|
71
|
-
this.push(npump);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (err) { logger.error(`Nixie Pump initAsync Error: ${err.message}`); return Promise.reject(err); }
|
|
77
|
-
}
|
|
78
|
-
public async closeAsync() {
|
|
79
|
-
try {
|
|
80
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
81
|
-
try {
|
|
82
|
-
await this[i].closeAsync();
|
|
83
|
-
this.splice(i, 1);
|
|
84
|
-
} catch (err) { logger.error(`Error stopping Nixie Pump ${err}`); }
|
|
85
|
-
}
|
|
86
|
-
} catch (err) { } // Don't bail if we have an errror.
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public async initPumpAsync(pump: Pump): Promise<NixiePump> {
|
|
90
|
-
try {
|
|
91
|
-
let c: NixiePump = this.find(elem => elem.id === pump.id) as NixiePump;
|
|
92
|
-
if (pump.master === 1) {
|
|
93
|
-
// if pump exists, close it so we can re-init
|
|
94
|
-
// (EG if pump type changes, we need to setup a new instance of the pump)
|
|
95
|
-
if (typeof c !== 'undefined' && c.pump.type !== pump.type) {
|
|
96
|
-
await c.closeAsync();
|
|
97
|
-
c = this.pumpFactory(pump);
|
|
98
|
-
}
|
|
99
|
-
logger.info(`Initializing Nixie Pump ${c.id}-${pump.name}`);
|
|
100
|
-
this.push(c);
|
|
101
|
-
}
|
|
102
|
-
return c;
|
|
103
|
-
} catch (err) { return Promise.reject(logger.error(`Nixie Controller: initPumpAsync Error: ${err.message}`)); }
|
|
104
|
-
}
|
|
105
|
-
private pumpFactory(pump: Pump) {
|
|
106
|
-
let type = sys.board.valueMaps.pumpTypes.getName(pump.type);
|
|
107
|
-
switch (type) {
|
|
108
|
-
case 'ss':
|
|
109
|
-
return new NixiePumpSS(this.controlPanel, pump);
|
|
110
|
-
case 'ds':
|
|
111
|
-
return new NixiePumpDS(this.controlPanel, pump);
|
|
112
|
-
case 'vsf':
|
|
113
|
-
return new NixiePumpVSF(this.controlPanel, pump);
|
|
114
|
-
case 'vf':
|
|
115
|
-
return new NixiePumpVF(this.controlPanel, pump);
|
|
116
|
-
case 'sf':
|
|
117
|
-
return new NixiePumpSF(this.controlPanel, pump);
|
|
118
|
-
case 'vs':
|
|
119
|
-
return new NixiePumpVS(this.controlPanel, pump);
|
|
120
|
-
default:
|
|
121
|
-
throw new EquipmentNotFoundError(`NCP: Cannot create pump ${pump.name}.`, type);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
public syncPumpStates() {
|
|
125
|
-
// loop through all pumps and update rates based on circuit changes
|
|
126
|
-
// this would happen in <2s anyway based on pollAsync but this is immediate.
|
|
127
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
128
|
-
setTimeout(async () => {
|
|
129
|
-
let pump = this[i] as NixiePump;
|
|
130
|
-
try {
|
|
131
|
-
if (!pump.closing) await pump.pollEquipmentAsync();
|
|
132
|
-
} catch (err) { }
|
|
133
|
-
}, 100);
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
export class NixiePump extends NixieEquipment {
|
|
139
|
-
public pollingInterval: number = 2000;
|
|
140
|
-
protected _pollTimer: NodeJS.Timeout = null;
|
|
141
|
-
public pump: Pump;
|
|
142
|
-
protected _targetSpeed: number;
|
|
143
|
-
protected _suspendPolling = 0;
|
|
144
|
-
public get suspendPolling(): boolean { return this._suspendPolling > 0; }
|
|
145
|
-
public set suspendPolling(val: boolean) { this._suspendPolling = Math.max(0, this._suspendPolling + (val ? 1 : -1)); }
|
|
146
|
-
public closing = false;
|
|
147
|
-
|
|
148
|
-
/*
|
|
149
|
-
_targetSpeed will hold values as follows:
|
|
150
|
-
vs/vsf/vf: rpm/gpm;
|
|
151
|
-
ss: 0=off, 1=on;
|
|
152
|
-
ds/sf: bit shift 1-4 = values 1/2/4/8 for relays 1/2/3/4
|
|
153
|
-
*/
|
|
154
|
-
constructor(ncp: INixieControlPanel, pump: Pump) {
|
|
155
|
-
super(ncp);
|
|
156
|
-
this.pump = pump;
|
|
157
|
-
this._targetSpeed = 0;
|
|
158
|
-
this.pollEquipmentAsync();
|
|
159
|
-
}
|
|
160
|
-
public get id(): number { return typeof this.pump !== 'undefined' ? this.pump.id : -1; }
|
|
161
|
-
public async setPumpStateAsync(pstate: PumpState) {
|
|
162
|
-
try {
|
|
163
|
-
// Here we go we need to set the pump state.
|
|
164
|
-
return new InterfaceServerResponse(200, 'Ok');
|
|
165
|
-
} catch (err) { return Promise.reject(`Nixie Error setting pump state ${pstate.id}-${pstate.name}: ${err.message}`); }
|
|
166
|
-
}
|
|
167
|
-
public async setPumpAsync(data: any): Promise<InterfaceServerResponse> {
|
|
168
|
-
try {
|
|
169
|
-
|
|
170
|
-
this.pump.master = 1;
|
|
171
|
-
// if (typeof data.isVirtual !== 'undefined') this.pump.isVirtual = data.isVirtual;
|
|
172
|
-
this.pump.isActive = true;
|
|
173
|
-
// if (typeof data.type !== 'undefined' && data.type !== this.pump.type) {
|
|
174
|
-
// sys.board.pumps.setType(this.pump, data.type);
|
|
175
|
-
// this.pump = sys.pumps.getItemById(id, true);
|
|
176
|
-
// spump = state.pumps.getItemById(id, true);
|
|
177
|
-
// }
|
|
178
|
-
let type = sys.board.valueMaps.pumpTypes.transform(this.pump.type);
|
|
179
|
-
this.pump.name = data.name || this.pump.name || type.desc;
|
|
180
|
-
if (typeof type.maxCircuits !== 'undefined' && type.maxCircuits > 0 && typeof data.circuits !== 'undefined') { // This pump type supports circuits
|
|
181
|
-
for (let i = 1; i <= data.circuits.length && i <= type.maxCircuits; i++) {
|
|
182
|
-
let c = data.circuits[i - 1];
|
|
183
|
-
let speed = parseInt(c.speed, 10);
|
|
184
|
-
let relay = parseInt(c.relay, 10);
|
|
185
|
-
let flow = parseInt(c.flow, 10);
|
|
186
|
-
if (isNaN(speed)) speed = type.minSpeed;
|
|
187
|
-
if (isNaN(flow)) flow = type.minFlow;
|
|
188
|
-
if (isNaN(relay)) relay = 1;
|
|
189
|
-
c.units = parseInt(c.units, 10) || type.name === 'vf' ? sys.board.valueMaps.pumpUnits.getValue('gpm') : sys.board.valueMaps.pumpUnits.getValue('rpm');
|
|
190
|
-
if (typeof type.minSpeed !== 'undefined' && c.units === sys.board.valueMaps.pumpUnits.getValue('rpm')) {
|
|
191
|
-
c.speed = speed;
|
|
192
|
-
}
|
|
193
|
-
else if (typeof type.minFlow !== 'undefined' && c.units === sys.board.valueMaps.pumpUnits.getValue('gpm')) {
|
|
194
|
-
c.flow = flow;
|
|
195
|
-
}
|
|
196
|
-
else if (type.maxRelays > 0)
|
|
197
|
-
c.relay = relay;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
this.pump.set(data); // Sets all the data back to the pump. This also sets the relays should it exist on the data.
|
|
201
|
-
let spump = state.pumps.getItemById(this.pump.id, true);
|
|
202
|
-
spump.name = this.pump.name;
|
|
203
|
-
spump.address = this.pump.address;
|
|
204
|
-
spump.type = this.pump.type;
|
|
205
|
-
sys.pumps.sortById();
|
|
206
|
-
state.pumps.sortById();
|
|
207
|
-
return Promise.resolve(new InterfaceServerResponse(200, 'Ok'));
|
|
208
|
-
}
|
|
209
|
-
catch (err) { logger.error(`Nixie setPumpAsync: ${err.message}`); return Promise.reject(err); }
|
|
210
|
-
}
|
|
211
|
-
public async pollEquipmentAsync() {
|
|
212
|
-
let self = this;
|
|
213
|
-
try {
|
|
214
|
-
if (this.suspendPolling || this.closing) return;
|
|
215
|
-
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
216
|
-
this._pollTimer = null;
|
|
217
|
-
// let success = false;
|
|
218
|
-
this.
|
|
219
|
-
|
|
220
|
-
await this.setPumpStateAsync(pstate);
|
|
221
|
-
}
|
|
222
|
-
catch (err) { logger.error(`Nixie Error running pump sequence - ${err}`); }
|
|
223
|
-
finally { if (!this.closing) this._pollTimer = setTimeout(async () => await self.pollEquipmentAsync(), this.pollingInterval || 2000); }
|
|
224
|
-
}
|
|
225
|
-
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
226
|
-
try {
|
|
227
|
-
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
228
|
-
return dev;
|
|
229
|
-
} catch (err) { logger.error(`Nixie Pump checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
230
|
-
}
|
|
231
|
-
public async validateSetupAsync(pump: Pump, pstate: PumpState) {
|
|
232
|
-
try {
|
|
233
|
-
} catch (err) { logger.error(`Nixie Error checking Pump Hardware ${this.pump.name}: ${err.message}`); return Promise.reject(err); }
|
|
234
|
-
}
|
|
235
|
-
public async closeAsync() {
|
|
236
|
-
try {
|
|
237
|
-
logger.info(`Nixie Pump closing ${this.pump.name}.`)
|
|
238
|
-
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
239
|
-
this._pollTimer = null;
|
|
240
|
-
this._targetSpeed = 0;
|
|
241
|
-
let pstate = state.pumps.getItemById(this.pump.id);
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
let
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
export class
|
|
331
|
-
public
|
|
332
|
-
//
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if (!
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
1
|
+
import { EquipmentNotFoundError, InvalidEquipmentDataError, InvalidEquipmentIdError, ParameterOutOfRangeError } from '../../Errors';
|
|
2
|
+
import { utils, Timestamp } from '../../Constants';
|
|
3
|
+
import { logger } from '../../../logger/Logger';
|
|
4
|
+
|
|
5
|
+
import { NixieEquipment, NixieChildEquipment, NixieEquipmentCollection, INixieControlPanel } from "../NixieEquipment";
|
|
6
|
+
import { Pump, PumpCircuit, PumpCollection, PumpRelay, sys } from "../../../controller/Equipment";
|
|
7
|
+
import { CircuitState, PumpState, state, } from "../../State";
|
|
8
|
+
import { setTimeout, clearTimeout } from 'timers';
|
|
9
|
+
import { NixieControlPanel } from '../Nixie';
|
|
10
|
+
import { webApp, InterfaceServerResponse } from "../../../web/Server";
|
|
11
|
+
import { Outbound, Protocol } from '../../comms/messages/Messages';
|
|
12
|
+
import { conn } from '../../comms/Comms';
|
|
13
|
+
|
|
14
|
+
export class NixiePumpCollection extends NixieEquipmentCollection<NixiePump> {
|
|
15
|
+
public async deletePumpAsync(id: number) {
|
|
16
|
+
try {
|
|
17
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
18
|
+
let pump = this[i];
|
|
19
|
+
if (pump.id === id) {
|
|
20
|
+
await pump.closeAsync();
|
|
21
|
+
this.splice(i, 1);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} catch (err) { logger.error(`Nixie Control Panel deletePumpAsync ${err.message}`); }
|
|
25
|
+
}
|
|
26
|
+
public async setPumpStateAsync(pstate: PumpState) {
|
|
27
|
+
try {
|
|
28
|
+
let pump: NixiePump = this.find(elem => elem.id === pstate.id) as NixiePump;
|
|
29
|
+
if (typeof pump === 'undefined') {
|
|
30
|
+
return logger.error(`Nixie Control Panel Error setPumpState could not find pump ${pstate.id}-${pstate.name}`);
|
|
31
|
+
}
|
|
32
|
+
await pump.setPumpStateAsync(pstate);
|
|
33
|
+
} catch (err) { logger.error(`Nixie Error setting pump state ${pstate.id}-${pstate.name}: ${err.message}`); return Promise.reject(err); }
|
|
34
|
+
}
|
|
35
|
+
public async setPumpAsync(pump: Pump, data: any) {
|
|
36
|
+
// By the time we get here we know that we are in control and this is a Nixie pump.
|
|
37
|
+
try {
|
|
38
|
+
let c: NixiePump = this.find(elem => elem.id === pump.id) as NixiePump;
|
|
39
|
+
if (typeof c === 'undefined') {
|
|
40
|
+
pump.master = 1;
|
|
41
|
+
if (typeof data.type !== 'undefined') pump.type = data.type; // needed for init of correct type
|
|
42
|
+
if (typeof pump.type === 'undefined') return Promise.reject(new InvalidEquipmentIdError(`Invalid pump type for ${pump.name}`, data.id, 'Pump'));
|
|
43
|
+
c = this.pumpFactory(pump);
|
|
44
|
+
// c = new NixiePump(this.controlPanel, pump);
|
|
45
|
+
this.push(c);
|
|
46
|
+
logger.info(`A pump was not found for id #${pump.id} creating pump`);
|
|
47
|
+
return await c.setPumpAsync(data);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
if (typeof data.type !== 'undefined' && c.pump.type !== data.type) {
|
|
51
|
+
// pump exists, changing type
|
|
52
|
+
await c.closeAsync();
|
|
53
|
+
pump.type = data.type; // needed for init of correct type
|
|
54
|
+
if (typeof pump.type === 'undefined') return Promise.reject(new InvalidEquipmentIdError(`Invalid pump type for ${pump.name}`, data.id, 'Pump'));
|
|
55
|
+
c = this.pumpFactory(pump);
|
|
56
|
+
}
|
|
57
|
+
return await c.setPumpAsync(data);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (err) { logger.error(`setPumpAsync: ${err.message}`); return Promise.reject(err); }
|
|
61
|
+
}
|
|
62
|
+
public async initAsync(pumps: PumpCollection) {
|
|
63
|
+
try {
|
|
64
|
+
for (let i = 0; i < pumps.length; i++) {
|
|
65
|
+
let pump = pumps.getItemByIndex(i);
|
|
66
|
+
if (pump.master === 1) {
|
|
67
|
+
if (typeof this.find(elem => elem.id === pump.id) === 'undefined') {
|
|
68
|
+
let type = sys.board.valueMaps.pumpTypes.getName(pump.type);
|
|
69
|
+
let npump = this.pumpFactory(pump);
|
|
70
|
+
logger.info(`Initializing Nixie Pump ${npump.id}-${pump.name}`);
|
|
71
|
+
this.push(npump);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) { logger.error(`Nixie Pump initAsync Error: ${err.message}`); return Promise.reject(err); }
|
|
77
|
+
}
|
|
78
|
+
public async closeAsync() {
|
|
79
|
+
try {
|
|
80
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
81
|
+
try {
|
|
82
|
+
await this[i].closeAsync();
|
|
83
|
+
this.splice(i, 1);
|
|
84
|
+
} catch (err) { logger.error(`Error stopping Nixie Pump ${err}`); }
|
|
85
|
+
}
|
|
86
|
+
} catch (err) { } // Don't bail if we have an errror.
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public async initPumpAsync(pump: Pump): Promise<NixiePump> {
|
|
90
|
+
try {
|
|
91
|
+
let c: NixiePump = this.find(elem => elem.id === pump.id) as NixiePump;
|
|
92
|
+
if (pump.master === 1) {
|
|
93
|
+
// if pump exists, close it so we can re-init
|
|
94
|
+
// (EG if pump type changes, we need to setup a new instance of the pump)
|
|
95
|
+
if (typeof c !== 'undefined' && c.pump.type !== pump.type) {
|
|
96
|
+
await c.closeAsync();
|
|
97
|
+
c = this.pumpFactory(pump);
|
|
98
|
+
}
|
|
99
|
+
logger.info(`Initializing Nixie Pump ${c.id}-${pump.name}`);
|
|
100
|
+
this.push(c);
|
|
101
|
+
}
|
|
102
|
+
return c;
|
|
103
|
+
} catch (err) { return Promise.reject(logger.error(`Nixie Controller: initPumpAsync Error: ${err.message}`)); }
|
|
104
|
+
}
|
|
105
|
+
private pumpFactory(pump: Pump) {
|
|
106
|
+
let type = sys.board.valueMaps.pumpTypes.getName(pump.type);
|
|
107
|
+
switch (type) {
|
|
108
|
+
case 'ss':
|
|
109
|
+
return new NixiePumpSS(this.controlPanel, pump);
|
|
110
|
+
case 'ds':
|
|
111
|
+
return new NixiePumpDS(this.controlPanel, pump);
|
|
112
|
+
case 'vsf':
|
|
113
|
+
return new NixiePumpVSF(this.controlPanel, pump);
|
|
114
|
+
case 'vf':
|
|
115
|
+
return new NixiePumpVF(this.controlPanel, pump);
|
|
116
|
+
case 'sf':
|
|
117
|
+
return new NixiePumpSF(this.controlPanel, pump);
|
|
118
|
+
case 'vs':
|
|
119
|
+
return new NixiePumpVS(this.controlPanel, pump);
|
|
120
|
+
default:
|
|
121
|
+
throw new EquipmentNotFoundError(`NCP: Cannot create pump ${pump.name}.`, type);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
public syncPumpStates() {
|
|
125
|
+
// loop through all pumps and update rates based on circuit changes
|
|
126
|
+
// this would happen in <2s anyway based on pollAsync but this is immediate.
|
|
127
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
128
|
+
setTimeout(async () => {
|
|
129
|
+
let pump = this[i] as NixiePump;
|
|
130
|
+
try {
|
|
131
|
+
if (!pump.closing) await pump.pollEquipmentAsync();
|
|
132
|
+
} catch (err) { }
|
|
133
|
+
}, 100);
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export class NixiePump extends NixieEquipment {
|
|
139
|
+
public pollingInterval: number = 2000;
|
|
140
|
+
protected _pollTimer: NodeJS.Timeout = null;
|
|
141
|
+
public pump: Pump;
|
|
142
|
+
protected _targetSpeed: number;
|
|
143
|
+
protected _suspendPolling = 0;
|
|
144
|
+
public get suspendPolling(): boolean { return this._suspendPolling > 0; }
|
|
145
|
+
public set suspendPolling(val: boolean) { this._suspendPolling = Math.max(0, this._suspendPolling + (val ? 1 : -1)); }
|
|
146
|
+
public closing = false;
|
|
147
|
+
|
|
148
|
+
/*
|
|
149
|
+
_targetSpeed will hold values as follows:
|
|
150
|
+
vs/vsf/vf: rpm/gpm;
|
|
151
|
+
ss: 0=off, 1=on;
|
|
152
|
+
ds/sf: bit shift 1-4 = values 1/2/4/8 for relays 1/2/3/4
|
|
153
|
+
*/
|
|
154
|
+
constructor(ncp: INixieControlPanel, pump: Pump) {
|
|
155
|
+
super(ncp);
|
|
156
|
+
this.pump = pump;
|
|
157
|
+
this._targetSpeed = 0;
|
|
158
|
+
this.pollEquipmentAsync();
|
|
159
|
+
}
|
|
160
|
+
public get id(): number { return typeof this.pump !== 'undefined' ? this.pump.id : -1; }
|
|
161
|
+
public async setPumpStateAsync(pstate: PumpState) {
|
|
162
|
+
try {
|
|
163
|
+
// Here we go we need to set the pump state.
|
|
164
|
+
return new InterfaceServerResponse(200, 'Ok');
|
|
165
|
+
} catch (err) { return Promise.reject(`Nixie Error setting pump state ${pstate.id}-${pstate.name}: ${err.message}`); }
|
|
166
|
+
}
|
|
167
|
+
public async setPumpAsync(data: any): Promise<InterfaceServerResponse> {
|
|
168
|
+
try {
|
|
169
|
+
|
|
170
|
+
this.pump.master = 1;
|
|
171
|
+
// if (typeof data.isVirtual !== 'undefined') this.pump.isVirtual = data.isVirtual;
|
|
172
|
+
this.pump.isActive = true;
|
|
173
|
+
// if (typeof data.type !== 'undefined' && data.type !== this.pump.type) {
|
|
174
|
+
// sys.board.pumps.setType(this.pump, data.type);
|
|
175
|
+
// this.pump = sys.pumps.getItemById(id, true);
|
|
176
|
+
// spump = state.pumps.getItemById(id, true);
|
|
177
|
+
// }
|
|
178
|
+
let type = sys.board.valueMaps.pumpTypes.transform(this.pump.type);
|
|
179
|
+
this.pump.name = data.name || this.pump.name || type.desc;
|
|
180
|
+
if (typeof type.maxCircuits !== 'undefined' && type.maxCircuits > 0 && typeof data.circuits !== 'undefined') { // This pump type supports circuits
|
|
181
|
+
for (let i = 1; i <= data.circuits.length && i <= type.maxCircuits; i++) {
|
|
182
|
+
let c = data.circuits[i - 1];
|
|
183
|
+
let speed = parseInt(c.speed, 10);
|
|
184
|
+
let relay = parseInt(c.relay, 10);
|
|
185
|
+
let flow = parseInt(c.flow, 10);
|
|
186
|
+
if (isNaN(speed)) speed = type.minSpeed;
|
|
187
|
+
if (isNaN(flow)) flow = type.minFlow;
|
|
188
|
+
if (isNaN(relay)) relay = 1;
|
|
189
|
+
c.units = parseInt(c.units, 10) || type.name === 'vf' ? sys.board.valueMaps.pumpUnits.getValue('gpm') : sys.board.valueMaps.pumpUnits.getValue('rpm');
|
|
190
|
+
if (typeof type.minSpeed !== 'undefined' && c.units === sys.board.valueMaps.pumpUnits.getValue('rpm')) {
|
|
191
|
+
c.speed = speed;
|
|
192
|
+
}
|
|
193
|
+
else if (typeof type.minFlow !== 'undefined' && c.units === sys.board.valueMaps.pumpUnits.getValue('gpm')) {
|
|
194
|
+
c.flow = flow;
|
|
195
|
+
}
|
|
196
|
+
else if (type.maxRelays > 0)
|
|
197
|
+
c.relay = relay;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
this.pump.set(data); // Sets all the data back to the pump. This also sets the relays should it exist on the data.
|
|
201
|
+
let spump = state.pumps.getItemById(this.pump.id, true);
|
|
202
|
+
spump.name = this.pump.name;
|
|
203
|
+
spump.address = this.pump.address;
|
|
204
|
+
spump.type = this.pump.type;
|
|
205
|
+
sys.pumps.sortById();
|
|
206
|
+
state.pumps.sortById();
|
|
207
|
+
return Promise.resolve(new InterfaceServerResponse(200, 'Ok'));
|
|
208
|
+
}
|
|
209
|
+
catch (err) { logger.error(`Nixie setPumpAsync: ${err.message}`); return Promise.reject(err); }
|
|
210
|
+
}
|
|
211
|
+
public async pollEquipmentAsync() {
|
|
212
|
+
let self = this;
|
|
213
|
+
try {
|
|
214
|
+
if (this.suspendPolling || this.closing) return;
|
|
215
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
216
|
+
this._pollTimer = null;
|
|
217
|
+
// let success = false;
|
|
218
|
+
let pstate = state.pumps.getItemById(this.pump.id);
|
|
219
|
+
this.setTargetSpeed(pstate);
|
|
220
|
+
await this.setPumpStateAsync(pstate);
|
|
221
|
+
}
|
|
222
|
+
catch (err) { logger.error(`Nixie Error running pump sequence - ${err}`); }
|
|
223
|
+
finally { if (!this.closing) this._pollTimer = setTimeout(async () => await self.pollEquipmentAsync(), this.pollingInterval || 2000); }
|
|
224
|
+
}
|
|
225
|
+
private async checkHardwareStatusAsync(connectionId: string, deviceBinding: string) {
|
|
226
|
+
try {
|
|
227
|
+
let dev = await NixieEquipment.getDeviceService(connectionId, `/status/device/${deviceBinding}`);
|
|
228
|
+
return dev;
|
|
229
|
+
} catch (err) { logger.error(`Nixie Pump checkHardwareStatusAsync: ${err.message}`); return { hasFault: true } }
|
|
230
|
+
}
|
|
231
|
+
public async validateSetupAsync(pump: Pump, pstate: PumpState) {
|
|
232
|
+
try {
|
|
233
|
+
} catch (err) { logger.error(`Nixie Error checking Pump Hardware ${this.pump.name}: ${err.message}`); return Promise.reject(err); }
|
|
234
|
+
}
|
|
235
|
+
public async closeAsync() {
|
|
236
|
+
try {
|
|
237
|
+
logger.info(`Nixie Pump closing ${this.pump.name}.`)
|
|
238
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
239
|
+
this._pollTimer = null;
|
|
240
|
+
this._targetSpeed = 0;
|
|
241
|
+
let pstate = state.pumps.getItemById(this.pump.id);
|
|
242
|
+
try {
|
|
243
|
+
await this.setPumpStateAsync(pstate);
|
|
244
|
+
// Since we are closing we need to not reject.
|
|
245
|
+
} catch (err) { logger.error(`Nixie Closing pump closeAsync: ${err.message}`); }
|
|
246
|
+
// This will make sure the timer is dead and we are completely closed.
|
|
247
|
+
this.closing = true;
|
|
248
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
249
|
+
pstate.emitEquipmentChange();
|
|
250
|
+
}
|
|
251
|
+
catch (err) { logger.error(`Nixie Pump closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
252
|
+
}
|
|
253
|
+
public logData(filename: string, data: any) { this.controlPanel.logData(filename, data); }
|
|
254
|
+
protected setTargetSpeed(pstate: PumpState) { };
|
|
255
|
+
protected isBodyOn(bodyCode: number) {
|
|
256
|
+
let assoc = sys.board.valueMaps.pumpBodies.transform(bodyCode);
|
|
257
|
+
switch (assoc.name) {
|
|
258
|
+
case 'body1':
|
|
259
|
+
case 'pool':
|
|
260
|
+
return state.temps.bodies.getItemById(1).isOn;
|
|
261
|
+
case 'body2':
|
|
262
|
+
case 'spa':
|
|
263
|
+
return state.temps.bodies.getItemById(2).isOn;
|
|
264
|
+
case 'body3':
|
|
265
|
+
return state.temps.bodies.getItemById(3).isOn;
|
|
266
|
+
case 'body4':
|
|
267
|
+
return state.temps.bodies.getItemById(4).isOn;
|
|
268
|
+
case 'poolspa':
|
|
269
|
+
if (sys.equipment.shared && sys.equipment.maxBodies >= 2) {
|
|
270
|
+
return state.temps.bodies.getItemById(1).isOn === true || state.temps.bodies.getItemById(2).isOn === true;
|
|
271
|
+
}
|
|
272
|
+
else
|
|
273
|
+
return state.temps.bodies.getItemById(1).isOn;
|
|
274
|
+
}
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
export class NixiePumpSS extends NixiePump {
|
|
279
|
+
public setTargetSpeed(pState: PumpState) {
|
|
280
|
+
// Turn on ss pumps.
|
|
281
|
+
let _newSpeed = 0;
|
|
282
|
+
if (!pState.pumpOnDelay) {
|
|
283
|
+
let pt = sys.board.valueMaps.pumpTypes.get(this.pump.type);
|
|
284
|
+
if (pt.hasBody) _newSpeed = this.isBodyOn(this.pump.body) ? 1 : 0;
|
|
285
|
+
//console.log(`BODY: ${sys.board.bodies.isBodyOn(this.pump.body)} CODE: ${this.pump.body}`);
|
|
286
|
+
}
|
|
287
|
+
if (this._targetSpeed !== _newSpeed) logger.info(`NCP: Setting Pump ${this.pump.name} to ${_newSpeed > 0 ? 'on' : 'off'}. ${sys.board.bodies.isBodyOn(this.pump.body)}`);
|
|
288
|
+
if (isNaN(_newSpeed)) _newSpeed = 0;
|
|
289
|
+
this._targetSpeed = _newSpeed;
|
|
290
|
+
}
|
|
291
|
+
public async setPumpStateAsync(pstate: PumpState) {
|
|
292
|
+
let relays: PumpRelay[] = this.pump.relays.get();
|
|
293
|
+
let relayState = 0;
|
|
294
|
+
for (let i = 0; i < relays.length; i++) {
|
|
295
|
+
let pr = relays[i];
|
|
296
|
+
if (typeof pr.id === 'undefined') pr.id = i + 1; // remove when id is added to dP relays upon save.
|
|
297
|
+
let isOn = this._targetSpeed >> pr.id - 1 & 1;
|
|
298
|
+
if (utils.isNullOrEmpty(pr.connectionId) || utils.isNullOrEmpty(pr.deviceBinding)) {
|
|
299
|
+
// If they haven't set a program for the relay bugger out.
|
|
300
|
+
if (isOn) relayState |= (1 << pr.id - 1);
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
try {
|
|
304
|
+
let res = await NixieEquipment.putDeviceService(pr.connectionId, `/state/device/${pr.deviceBinding}`, { isOn, latch: isOn ? 5000 : undefined });
|
|
305
|
+
if (res.status.code === 200) {
|
|
306
|
+
if (isOn) relayState |= (1 << pr.id - 1);
|
|
307
|
+
}
|
|
308
|
+
else pstate.status = 16;
|
|
309
|
+
}
|
|
310
|
+
catch (err) {
|
|
311
|
+
logger.error(`NCP: Error setting pump ${this.pump.name} relay ${pr.id} to ${isOn ? 'on' : 'off'}. Error ${err.message}}`);
|
|
312
|
+
pstate.status = 16;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (pstate.targetSpeed === 0) {
|
|
317
|
+
pstate.status = 0;
|
|
318
|
+
pstate.driveState = 0; // We need to set this if it is a priming cycle but it might not matter for our relay based pumps.
|
|
319
|
+
pstate.command = 0;
|
|
320
|
+
}
|
|
321
|
+
else if (relayState === pstate.targetSpeed) {
|
|
322
|
+
pstate.status = 1;
|
|
323
|
+
pstate.driveState = 2;
|
|
324
|
+
pstate.command = 4;
|
|
325
|
+
}
|
|
326
|
+
pstate.relay = relayState;
|
|
327
|
+
return new InterfaceServerResponse(200, 'Success');
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
export class NixiePumpDS extends NixiePumpSS {
|
|
331
|
+
public setTargetSpeed(pState: PumpState) {
|
|
332
|
+
// Turn on sf pumps. The new speed will be the relays associated with the pump. I believe when this comes out in the final
|
|
333
|
+
// wash it should engage all the relays for all speeds associated with the pump. The pump logic will determine which program is
|
|
334
|
+
// the one to engage.
|
|
335
|
+
let _newSpeed = 0;
|
|
336
|
+
if (!pState.pumpOnDelay) {
|
|
337
|
+
let pumpCircuits: PumpCircuit[] = this.pump.circuits.get();
|
|
338
|
+
if (!pState.pumpOnDelay) {
|
|
339
|
+
for (let i = 0; i < pumpCircuits.length; i++) {
|
|
340
|
+
let circ = state.circuits.getInterfaceById(pumpCircuits[i].circuit);
|
|
341
|
+
// relay speeds are bit-shifted 'or' based on 1,2,4,8
|
|
342
|
+
if (circ.isOn) _newSpeed |= (1 << pumpCircuits[i].relay - 1);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (isNaN(_newSpeed)) _newSpeed = 0;
|
|
347
|
+
this.logSpeed(_newSpeed);
|
|
348
|
+
this._targetSpeed = _newSpeed;
|
|
349
|
+
}
|
|
350
|
+
public logSpeed(_newSpeed: number) {
|
|
351
|
+
if (this._targetSpeed !== _newSpeed) logger.info(`NCP: Setting Pump ${this.pump.name} relays to Relay 1: ${_newSpeed & 1 ? 'on' : 'off'}, Relay 2: ${_newSpeed & 2 ? 'on' : 'off'}.`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
export class NixiePumpSF extends NixiePumpDS {
|
|
355
|
+
// effectively operates the same way as a DS pump since we removed the body association on DS.
|
|
356
|
+
// only logger msg is different
|
|
357
|
+
public logSpeed(_newSpeed: number) {
|
|
358
|
+
if (this._targetSpeed !== _newSpeed) logger.info(`NCP: Setting Pump ${this.pump.name} relays to Relay 1: ${_newSpeed & 1 ? 'on' : 'off'}, Relay 2: ${_newSpeed & 2 ? 'on' : 'off'}, Relay 3: ${_newSpeed & 4 ? 'on' : 'off'}, and Relay 4: ${_newSpeed & 8 ? 'on' : 'off'}.`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
export class NixiePumpRS485 extends NixiePump {
|
|
362
|
+
public async setPumpStateAsync(pstate: PumpState) {
|
|
363
|
+
// Don't poll while we are seting the state.
|
|
364
|
+
this.suspendPolling = true;
|
|
365
|
+
try {
|
|
366
|
+
let pt = sys.board.valueMaps.pumpTypes.get(this.pump.type);
|
|
367
|
+
// Since these process are async the closing flag can be set
|
|
368
|
+
// between calls. We need to check it in between each call.
|
|
369
|
+
try { if (!this.closing) await this.setDriveStateAsync(); } catch (err) {}
|
|
370
|
+
try { if (!this.closing) {
|
|
371
|
+
if (this._targetSpeed >= pt.minFlow && this._targetSpeed <= pt.maxFlow) await this.setPumpGPMAsync();
|
|
372
|
+
else if (this._targetSpeed >= pt.minSpeed && this._targetSpeed <= pt.maxSpeed) await this.setPumpRPMAsync();
|
|
373
|
+
} } catch (err) {}
|
|
374
|
+
|
|
375
|
+
try { if(!this.closing) await this.setPumpFeature(6); } catch (err) {};
|
|
376
|
+
try { if(!this.closing) await utils.sleep(1000); } catch (err) {};
|
|
377
|
+
try { if(!this.closing) await this.requestPumpStatus(); } catch (err) {};
|
|
378
|
+
try { if(!this.closing) await this.setPumpToRemoteControl(); } catch (err) {};
|
|
379
|
+
return new InterfaceServerResponse(200, 'Success');
|
|
380
|
+
}
|
|
381
|
+
catch (err) {
|
|
382
|
+
logger.error(`Error running pump sequence for ${this.pump.name}: ${err.message}`);
|
|
383
|
+
return Promise.reject(err);
|
|
384
|
+
}
|
|
385
|
+
finally { this.suspendPolling = false; }
|
|
386
|
+
};
|
|
387
|
+
protected async setDriveStateAsync(running: boolean = true) {
|
|
388
|
+
return new Promise<void>((resolve, reject) => {
|
|
389
|
+
let out = Outbound.create({
|
|
390
|
+
protocol: Protocol.Pump,
|
|
391
|
+
dest: this.pump.address,
|
|
392
|
+
action: 6,
|
|
393
|
+
payload: running && this._targetSpeed > 0 ? [10] : [4],
|
|
394
|
+
retries: 1,
|
|
395
|
+
response: true,
|
|
396
|
+
onComplete: (err, msg: Outbound) => {
|
|
397
|
+
if (err) {
|
|
398
|
+
logger.error(`Error sending setDriveState for ${this.pump.name} : ${err.message}`);
|
|
399
|
+
reject(err);
|
|
400
|
+
}
|
|
401
|
+
else resolve();
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
conn.queueSendMessage(out);
|
|
405
|
+
});
|
|
406
|
+
};
|
|
407
|
+
protected async requestPumpStatus() {
|
|
408
|
+
return new Promise<void>((resolve, reject) => {
|
|
409
|
+
let out = Outbound.create({
|
|
410
|
+
protocol: Protocol.Pump,
|
|
411
|
+
dest: this.pump.address,
|
|
412
|
+
action: 7,
|
|
413
|
+
payload: [],
|
|
414
|
+
retries: 2,
|
|
415
|
+
response: true,
|
|
416
|
+
onComplete: (err, msg) => {
|
|
417
|
+
if (err) {
|
|
418
|
+
logger.error(`Error sending requestPumpStatus for ${this.pump.name}: ${err.message}`);
|
|
419
|
+
reject(err);
|
|
420
|
+
}
|
|
421
|
+
else resolve();
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
conn.queueSendMessage(out);
|
|
425
|
+
})
|
|
426
|
+
};
|
|
427
|
+
protected setPumpToRemoteControl(running: boolean = true) {
|
|
428
|
+
return new Promise<void>((resolve, reject) => {
|
|
429
|
+
let out = Outbound.create({
|
|
430
|
+
protocol: Protocol.Pump,
|
|
431
|
+
dest: this.pump.address,
|
|
432
|
+
action: 4,
|
|
433
|
+
payload: running ? [255] : [0], // when stopAsync is called, pass false to return control to pump panel
|
|
434
|
+
// payload: spump.virtualControllerStatus === sys.board.valueMaps.virtualControllerStatus.getValue('running') ? [255] : [0],
|
|
435
|
+
retries: 1,
|
|
436
|
+
response: true,
|
|
437
|
+
onComplete: (err) => {
|
|
438
|
+
if (err) {
|
|
439
|
+
logger.error(`Error sending setPumpToRemoteControl for ${this.pump.name}: ${err.message}`);
|
|
440
|
+
reject(err);
|
|
441
|
+
}
|
|
442
|
+
else resolve();
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
conn.queueSendMessage(out);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
protected setPumpFeature(feature?: number) {
|
|
449
|
+
// empty payload (possibly 0?, too) is no feature
|
|
450
|
+
// 6: Feature 1
|
|
451
|
+
return new Promise<void>((resolve, reject) => {
|
|
452
|
+
let out = Outbound.create({
|
|
453
|
+
protocol: Protocol.Pump,
|
|
454
|
+
dest: this.pump.address,
|
|
455
|
+
action: 5,
|
|
456
|
+
payload: typeof feature === 'undefined' ? [] : [ feature ],
|
|
457
|
+
retries: 2,
|
|
458
|
+
repsonse: true,
|
|
459
|
+
onComplete: (err, msg: Outbound) => {
|
|
460
|
+
if (err) {
|
|
461
|
+
logger.error(`Error sending setPumpManual for ${this.pump.name}: ${err.message}`);
|
|
462
|
+
reject(err);
|
|
463
|
+
}
|
|
464
|
+
else resolve();
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
conn.queueSendMessage(out);
|
|
468
|
+
});
|
|
469
|
+
};
|
|
470
|
+
protected async setPumpRPMAsync() {
|
|
471
|
+
return new Promise<void>((resolve, reject) => {
|
|
472
|
+
let out = Outbound.create({
|
|
473
|
+
protocol: Protocol.Pump,
|
|
474
|
+
dest: this.pump.address,
|
|
475
|
+
action: 1,
|
|
476
|
+
payload: [2, 196, Math.floor(this._targetSpeed / 256), this._targetSpeed % 256],
|
|
477
|
+
retries: 1,
|
|
478
|
+
// timeout: 250,
|
|
479
|
+
response: true,
|
|
480
|
+
onComplete: (err, msg) => {
|
|
481
|
+
if (err) {
|
|
482
|
+
logger.error(`Error sending setPumpRPMAsync for ${this.pump.name}: ${err.message}`);
|
|
483
|
+
reject(err);
|
|
484
|
+
}
|
|
485
|
+
else resolve();
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
conn.queueSendMessage(out);
|
|
489
|
+
});
|
|
490
|
+
};
|
|
491
|
+
protected async setPumpGPMAsync() {
|
|
492
|
+
// packet for vf; vsf will override
|
|
493
|
+
return new Promise<void>((resolve, reject) => {
|
|
494
|
+
let out = Outbound.create({
|
|
495
|
+
protocol: Protocol.Pump,
|
|
496
|
+
dest: this.pump.address,
|
|
497
|
+
action: 1,
|
|
498
|
+
payload: [2, 228, 0, this._targetSpeed],
|
|
499
|
+
retries: 1,
|
|
500
|
+
response: true,
|
|
501
|
+
onComplete: (err, msg) => {
|
|
502
|
+
if (err) {
|
|
503
|
+
logger.error(`Error sending setPumpGPMAsync for ${this.pump.name}: ${err.message}`);
|
|
504
|
+
reject(err);
|
|
505
|
+
}
|
|
506
|
+
else resolve();
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
conn.queueSendMessage(out);
|
|
510
|
+
});
|
|
511
|
+
};
|
|
512
|
+
public async closeAsync() {
|
|
513
|
+
try {
|
|
514
|
+
this.suspendPolling = true;
|
|
515
|
+
logger.info(`Nixie Pump closing ${this.pump.name}.`)
|
|
516
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
517
|
+
this._pollTimer = null;
|
|
518
|
+
let pstate = state.pumps.getItemById(this.pump.id);
|
|
519
|
+
this._targetSpeed = 0;
|
|
520
|
+
try { await this.setDriveStateAsync(false); } catch (err) { logger.error(`Error closing pump ${this.pump.name}: ${err.message}`) }
|
|
521
|
+
try { await this.setPumpFeature(); } catch (err) { logger.error(`Error closing pump ${this.pump.name}: ${err.message}`) }
|
|
522
|
+
try { await this.setDriveStateAsync(false); } catch (err) { logger.error(`Error closing pump ${this.pump.name}: ${err.message}`) }
|
|
523
|
+
try { await this.setPumpToRemoteControl(false); } catch (err) { logger.error(`Error closing pump ${this.pump.name}: ${err.message}`) }
|
|
524
|
+
this.closing = true;
|
|
525
|
+
// Make sure the polling timer is dead after we have closted this all off. That way we do not
|
|
526
|
+
// have another process that revives it from the dead.
|
|
527
|
+
if (typeof this._pollTimer !== 'undefined' || this._pollTimer) clearTimeout(this._pollTimer);
|
|
528
|
+
this._pollTimer = null;
|
|
529
|
+
pstate.emitEquipmentChange();
|
|
530
|
+
}
|
|
531
|
+
catch (err) { logger.error(`Nixie Pump closeAsync: ${err.message}`); return Promise.reject(err); }
|
|
532
|
+
finally { this.suspendPolling = false; }
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
export class NixiePumpVS extends NixiePumpRS485 {
|
|
536
|
+
public setTargetSpeed(pState: PumpState) {
|
|
537
|
+
let _newSpeed = 0;
|
|
538
|
+
if (!pState.pumpOnDelay) {
|
|
539
|
+
let pumpCircuits = this.pump.circuits.get();
|
|
540
|
+
|
|
541
|
+
for (let i = 0; i < pumpCircuits.length; i++) {
|
|
542
|
+
let circ = state.circuits.getInterfaceById(pumpCircuits[i].circuit);
|
|
543
|
+
let pc = pumpCircuits[i];
|
|
544
|
+
if (circ.isOn) _newSpeed = Math.max(_newSpeed, pc.speed);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
if (isNaN(_newSpeed)) _newSpeed = 0;
|
|
548
|
+
this._targetSpeed = _newSpeed;
|
|
549
|
+
if (this._targetSpeed !== 0) Math.min(Math.max(this.pump.minSpeed, this._targetSpeed), this.pump.maxSpeed);
|
|
550
|
+
if (this._targetSpeed !== _newSpeed) logger.info(`NCP: Setting Pump ${this.pump.name} to ${_newSpeed} RPM.`);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
export class NixiePumpVF extends NixiePumpRS485 {
|
|
554
|
+
public setTargetSpeed(pState: PumpState) {
|
|
555
|
+
let _newSpeed = 0;
|
|
556
|
+
if (!pState.pumpOnDelay) {
|
|
557
|
+
let pumpCircuits = this.pump.circuits.get();
|
|
558
|
+
for (let i = 0; i < pumpCircuits.length; i++) {
|
|
559
|
+
let circ = state.circuits.getInterfaceById(pumpCircuits[i].circuit);
|
|
560
|
+
let pc = pumpCircuits[i];
|
|
561
|
+
if (circ.isOn) _newSpeed = Math.max(_newSpeed, pc.flow);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (isNaN(_newSpeed)) _newSpeed = 0;
|
|
565
|
+
this._targetSpeed = _newSpeed;
|
|
566
|
+
if (this._targetSpeed !== 0) Math.min(Math.max(this.pump.minFlow, this._targetSpeed), this.pump.maxFlow);
|
|
567
|
+
if (this._targetSpeed !== _newSpeed) logger.info(`NCP: Setting Pump ${this.pump.name} to ${_newSpeed} GPM.`);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
export class NixiePumpVSF extends NixiePumpRS485 {
|
|
571
|
+
public setTargetSpeed(pState: PumpState) {
|
|
572
|
+
let _newSpeed = 0;
|
|
573
|
+
let maxRPM = 0;
|
|
574
|
+
let maxGPM = 0;
|
|
575
|
+
let flows = 0;
|
|
576
|
+
let speeds = 0;
|
|
577
|
+
if (!pState.pumpOnDelay) {
|
|
578
|
+
let pumpCircuits = this.pump.circuits.get();
|
|
579
|
+
let pt = sys.board.valueMaps.pumpTypes.get(this.pump.type);
|
|
580
|
+
// VSF pumps present a problem. In fact they do not currently operate properly on Touch panels. On touch these need to either be all in RPM or GPM
|
|
581
|
+
// if there is a mix in the circuit array then they will not work. In IntelliCenter if there is an RPM setting in the mix it will use RPM by converting
|
|
582
|
+
// the GPM to RPM but if there is none then it will use GPM.
|
|
583
|
+
let toRPM = (flowRate: number, minSpeed: number = 450, maxSpeed: number = 3450) => {
|
|
584
|
+
let eff = .03317 * maxSpeed;
|
|
585
|
+
let rpm = Math.min((flowRate * maxSpeed) / eff, maxSpeed);
|
|
586
|
+
return rpm > 0 ? Math.max(rpm, minSpeed) : 0;
|
|
587
|
+
};
|
|
588
|
+
let toGPM = (speed: number, maxSpeed: number = 3450, minFlow: number = 15, maxFlow: number = 140) => {
|
|
589
|
+
let eff = .03317 * maxSpeed;
|
|
590
|
+
let gpm = Math.min((eff * speed) / maxSpeed, maxFlow);
|
|
591
|
+
return gpm > 0 ? Math.max(gpm, minFlow) : 0;
|
|
592
|
+
}
|
|
593
|
+
for (let i = 0; i < pumpCircuits.length; i++) {
|
|
594
|
+
let circ = state.circuits.getInterfaceById(pumpCircuits[i].circuit);
|
|
595
|
+
let pc = pumpCircuits[i];
|
|
596
|
+
if (circ.isOn) {
|
|
597
|
+
if (pc.units > 0) {
|
|
598
|
+
maxGPM = Math.max(maxGPM, pc.flow);
|
|
599
|
+
// Calculate an RPM from this flow.
|
|
600
|
+
maxRPM = Math.max(maxGPM, toRPM(pc.flow, pt.minSpeed, pt.maxSpeed));
|
|
601
|
+
flows++;
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
maxRPM = Math.max(maxRPM, pc.speed);
|
|
605
|
+
maxGPM = Math.max(maxGPM, toGPM(pc.speed, pt.maxSpeed, pt.minFlow, pt.maxFlow));
|
|
606
|
+
speeds++;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
_newSpeed = speeds > 0 || flows === 0 ? maxRPM : maxGPM;
|
|
611
|
+
}
|
|
612
|
+
if (isNaN(_newSpeed)) _newSpeed = 0;
|
|
613
|
+
// Send the flow message if it is flow and the rpm message if it is rpm.
|
|
614
|
+
if (this._targetSpeed !== _newSpeed) logger.info(`NCP: Setting Pump ${this.pump.name} to ${_newSpeed} ${flows > 0 ? 'GPM' : 'RPM'}.`);
|
|
615
|
+
this._targetSpeed = _newSpeed;
|
|
616
|
+
}
|
|
617
|
+
protected async setPumpRPMAsync() {
|
|
618
|
+
// vsf action is 10 for rpm
|
|
619
|
+
return new Promise<void>((resolve, reject) => {
|
|
620
|
+
let out = Outbound.create({
|
|
621
|
+
protocol: Protocol.Pump,
|
|
622
|
+
dest: this.pump.address,
|
|
623
|
+
action: 10,
|
|
624
|
+
payload: [2, 196, Math.floor(this._targetSpeed / 256), this._targetSpeed % 256],
|
|
625
|
+
retries: 1,
|
|
626
|
+
// timeout: 250,
|
|
627
|
+
response: true,
|
|
628
|
+
onComplete: (err, msg) => {
|
|
629
|
+
if (err) {
|
|
630
|
+
logger.error(`Error sending setPumpRPMAsync for ${this.pump.name}: ${err.message}`);
|
|
631
|
+
reject(err);
|
|
632
|
+
}
|
|
633
|
+
else resolve();
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
conn.queueSendMessage(out);
|
|
637
|
+
});
|
|
638
|
+
};
|
|
639
|
+
protected async setPumpGPMAsync() {
|
|
640
|
+
// vsf payload; different from vf payload
|
|
641
|
+
return new Promise<void>((resolve, reject) => {
|
|
642
|
+
let out = Outbound.create({
|
|
643
|
+
protocol: Protocol.Pump,
|
|
644
|
+
dest: this.pump.address,
|
|
645
|
+
action: 9,
|
|
646
|
+
payload: [2, 196, 0, this._targetSpeed],
|
|
647
|
+
retries: 1,
|
|
648
|
+
response: true,
|
|
649
|
+
onComplete: (err, msg) => {
|
|
650
|
+
if (err) {
|
|
651
|
+
logger.error(`Error sending setPumpGPMAsync for ${this.pump.name}: ${err.message}`);
|
|
652
|
+
reject(err);
|
|
653
|
+
}
|
|
654
|
+
else resolve();
|
|
655
|
+
return
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
conn.queueSendMessage(out);
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
};
|