nodejs-poolcontroller 8.4.0 → 8.4.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/.github/workflows/ghcr-publish.yml +1 -1
- package/157_issues.md +101 -0
- package/AGENTS.md +17 -1
- package/README.md +13 -2
- package/controller/Equipment.ts +49 -0
- package/controller/State.ts +8 -0
- package/controller/boards/AquaLinkBoard.ts +174 -2
- package/controller/boards/EasyTouchBoard.ts +44 -0
- package/controller/boards/IntelliCenterBoard.ts +360 -172
- package/controller/boards/NixieBoard.ts +7 -4
- package/controller/boards/SunTouchBoard.ts +1 -0
- package/controller/boards/SystemBoard.ts +39 -4
- package/controller/comms/Comms.ts +9 -3
- package/controller/comms/messages/Messages.ts +218 -24
- package/controller/comms/messages/config/EquipmentMessage.ts +34 -0
- package/controller/comms/messages/config/ExternalMessage.ts +1051 -989
- package/controller/comms/messages/config/GeneralMessage.ts +65 -0
- package/controller/comms/messages/config/OptionsMessage.ts +15 -2
- package/controller/comms/messages/config/PumpMessage.ts +427 -421
- package/controller/comms/messages/config/SecurityMessage.ts +37 -13
- package/controller/comms/messages/status/EquipmentStateMessage.ts +0 -218
- package/controller/comms/messages/status/HeaterStateMessage.ts +27 -15
- package/controller/comms/messages/status/NeptuneModbusStateMessage.ts +217 -0
- package/controller/comms/messages/status/VersionMessage.ts +67 -18
- package/controller/nixie/chemistry/ChemController.ts +65 -33
- package/controller/nixie/heaters/Heater.ts +10 -1
- package/controller/nixie/pumps/Pump.ts +145 -2
- package/docker-compose.yml +1 -0
- package/logger/Logger.ts +75 -64
- package/package.json +1 -1
- package/tsconfig.json +2 -1
- package/web/Server.ts +3 -1
- package/web/services/config/Config.ts +150 -1
- package/web/services/state/State.ts +21 -0
- package/web/services/state/StateSocket.ts +28 -0
|
@@ -1,990 +1,1052 @@
|
|
|
1
|
-
/* nodejs-poolController. An application to control pool equipment.
|
|
2
|
-
Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022.
|
|
3
|
-
Russell Goldin, tagyoureit. russ.goldin@gmail.com
|
|
4
|
-
|
|
5
|
-
This program is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Affero General Public License as
|
|
7
|
-
published by the Free Software Foundation, either version 3 of the
|
|
8
|
-
License, or (at your option) any later version.
|
|
9
|
-
|
|
10
|
-
This program is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Affero General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Affero General Public License
|
|
16
|
-
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
import { Inbound } from "../Messages";
|
|
19
|
-
import { sys, Body, ICircuitGroup, LightGroup, CircuitGroup } from "../../../Equipment";
|
|
20
|
-
import { state, ICircuitGroupState, LightGroupState, CircuitGroupState } from "../../../State";
|
|
21
|
-
import { ControllerType, Timestamp, utils } from "../../../Constants";
|
|
22
|
-
import { logger } from "../../../../logger/Logger";
|
|
23
|
-
export class ExternalMessage {
|
|
24
|
-
public static processIntelliCenter(msg: Inbound): void {
|
|
25
|
-
// IntelliCenter v3.x: treat Wireless/ICP/Indoor -> OCP packets as requests, not source-of-truth.
|
|
26
|
-
// We are a bus listener, so we will see traffic not addressed to us; do not apply those requests to state.
|
|
27
|
-
// Only accept OCP-originated messages here. If/when OCP applies a request, it will broadcast authoritative
|
|
28
|
-
// state/config via other message types (e.g., Action 30 / 204).
|
|
29
|
-
if (sys.equipment.isIntellicenterV3 && msg.dest === 16 && msg.source !== 16) {
|
|
30
|
-
msg.isProcessed = true;
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
switch (msg.extractPayloadByte(0)) {
|
|
34
|
-
case 0: // Setpoints/HeatMode
|
|
35
|
-
ExternalMessage.processTempSettings(msg);
|
|
36
|
-
break;
|
|
37
|
-
case 1: // Circuit Changes
|
|
38
|
-
ExternalMessage.processCircuit(msg);
|
|
39
|
-
break;
|
|
40
|
-
case 2: // Feature Changes
|
|
41
|
-
ExternalMessage.processFeature(msg);
|
|
42
|
-
break;
|
|
43
|
-
case 3: // Schedule Changes
|
|
44
|
-
ExternalMessage.processSchedules(msg);
|
|
45
|
-
break;
|
|
46
|
-
case 4: // Pump Information
|
|
47
|
-
ExternalMessage.processPump(msg);
|
|
48
|
-
break;
|
|
49
|
-
case 5: // Remotes
|
|
50
|
-
break;
|
|
51
|
-
case 6: // Light/Circuit group
|
|
52
|
-
ExternalMessage.processGroupSettings(msg);
|
|
53
|
-
break;
|
|
54
|
-
case 7: // Chlorinator
|
|
55
|
-
ExternalMessage.processChlorinator(msg);
|
|
56
|
-
break;
|
|
57
|
-
case 8: // IntelliChem
|
|
58
|
-
ExternalMessage.processIntelliChem(msg);
|
|
59
|
-
break;
|
|
60
|
-
case 9: // Valves
|
|
61
|
-
ExternalMessage.processValve(msg);
|
|
62
|
-
break;
|
|
63
|
-
case 10: // Heaters
|
|
64
|
-
ExternalMessage.processHeater(msg);
|
|
65
|
-
break;
|
|
66
|
-
case 11: // Security
|
|
67
|
-
break;
|
|
68
|
-
case 12: // Pool Settings Alias, owner...etc.
|
|
69
|
-
ExternalMessage.processPool(msg);
|
|
70
|
-
break;
|
|
71
|
-
case 13: // Bodies (Manual heat, capacities)
|
|
72
|
-
ExternalMessage.processBodies(msg);
|
|
73
|
-
break;
|
|
74
|
-
case 14: // Covers
|
|
75
|
-
break;
|
|
76
|
-
case 15: // Circuit, feature, group, and schedule States
|
|
77
|
-
ExternalMessage.processCircuitState(3, msg);
|
|
78
|
-
ExternalMessage.processFeatureState(9, msg);
|
|
79
|
-
ExternalMessage.processScheduleState(15, msg);
|
|
80
|
-
ExternalMessage.processCircuitGroupState(13, msg);
|
|
81
|
-
break;
|
|
82
|
-
default:
|
|
83
|
-
logger.debug(`Unprocessed Message ${msg.toPacket()}`)
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
public static processIntelliChem(msg: Inbound) {
|
|
88
|
-
let id = msg.extractPayloadByte(2) + 1;
|
|
89
|
-
let isActive = utils.makeBool(msg.extractPayloadByte(6));
|
|
90
|
-
//let schem = state.chemchems.getItemById(id, isActive);
|
|
91
|
-
//chem.isActive = schem.isActive = isActive;
|
|
92
|
-
if (isActive) {
|
|
93
|
-
let chem = sys.chemControllers.getItemById(id, true);
|
|
94
|
-
let schem = state.chemControllers.getItemById(id, true);
|
|
95
|
-
// chem.isVirtual = false;
|
|
96
|
-
chem.master = 0;
|
|
97
|
-
chem.ph.tank.capacity = chem.orp.tank.capacity = 6;
|
|
98
|
-
chem.ph.tank.units = chem.orp.tank.units = '';
|
|
99
|
-
schem.type = chem.type = 2;
|
|
100
|
-
schem.name = chem.name = (chem.name || 'IntelliChem' + id);
|
|
101
|
-
schem.body = chem.body = msg.extractPayloadByte(3);
|
|
102
|
-
schem.address = chem.address = msg.extractPayloadByte(5);
|
|
103
|
-
chem.ph.setpoint = schem.ph.setpoint = msg.extractPayloadInt(7) / 100;
|
|
104
|
-
chem.orp.setpoint = schem.orp.setpoint = msg.extractPayloadInt(9);
|
|
105
|
-
chem.calciumHardness = msg.extractPayloadInt(13);
|
|
106
|
-
chem.cyanuricAcid = msg.extractPayloadInt(15);
|
|
107
|
-
chem.alkalinity = msg.extractPayloadInt(17);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
sys.chemControllers.removeItemById(id);
|
|
111
|
-
state.chemControllers.removeItemById(id);
|
|
112
|
-
}
|
|
113
|
-
msg.isProcessed = true;
|
|
114
|
-
}
|
|
115
|
-
public static processValve(msg: Inbound) {
|
|
116
|
-
let valve = sys.valves.getItemById(msg.extractPayloadByte(2) + 1);
|
|
117
|
-
valve.circuit = msg.extractPayloadByte(3) + 1;
|
|
118
|
-
valve.name = msg.extractPayloadString(4, 16);
|
|
119
|
-
valve.master = 0;
|
|
120
|
-
// valve.isVirtual = false;
|
|
121
|
-
msg.isProcessed = true;
|
|
122
|
-
}
|
|
123
|
-
public static processPool(msg: Inbound) {
|
|
124
|
-
switch (msg.extractPayloadByte(2)) {
|
|
125
|
-
case 0: // Pool Alias
|
|
126
|
-
sys.general.alias = msg.extractPayloadString(3, 16);
|
|
127
|
-
msg.isProcessed = true;
|
|
128
|
-
break;
|
|
129
|
-
case 1: // Address
|
|
130
|
-
sys.general.location.address = msg.extractPayloadString(3, 32);
|
|
131
|
-
msg.isProcessed = true;
|
|
132
|
-
break;
|
|
133
|
-
case 2: // Owner
|
|
134
|
-
sys.general.owner.name = msg.extractPayloadString(3, 16);
|
|
135
|
-
msg.isProcessed = true;
|
|
136
|
-
break;
|
|
137
|
-
case 3: // Email
|
|
138
|
-
sys.general.owner.email = msg.extractPayloadString(3, 32);
|
|
139
|
-
msg.isProcessed = true;
|
|
140
|
-
break;
|
|
141
|
-
case 4: // Email 2
|
|
142
|
-
sys.general.owner.email2 = msg.extractPayloadString(3, 32);
|
|
143
|
-
msg.isProcessed = true;
|
|
144
|
-
break;
|
|
145
|
-
case 5: // Phone
|
|
146
|
-
sys.general.owner.phone = msg.extractPayloadString(3, 16);
|
|
147
|
-
msg.isProcessed = true;
|
|
148
|
-
break;
|
|
149
|
-
case 6: // Phone 2
|
|
150
|
-
sys.general.owner.phone2 = msg.extractPayloadString(3, 16);
|
|
151
|
-
msg.isProcessed = true;
|
|
152
|
-
break;
|
|
153
|
-
case 7: // Zipcode
|
|
154
|
-
sys.general.location.zip = msg.extractPayloadString(3, 6);
|
|
155
|
-
msg.isProcessed = true;
|
|
156
|
-
break;
|
|
157
|
-
case 8: // Country
|
|
158
|
-
sys.general.location.country = msg.extractPayloadString(3,
|
|
159
|
-
msg.isProcessed = true;
|
|
160
|
-
break;
|
|
161
|
-
case 9: // City
|
|
162
|
-
sys.general.location.city = msg.extractPayloadString(3, 32);
|
|
163
|
-
msg.isProcessed = true;
|
|
164
|
-
break;
|
|
165
|
-
case 10: // State
|
|
166
|
-
sys.general.location.state = msg.extractPayloadString(3, 16);
|
|
167
|
-
msg.isProcessed = true;
|
|
168
|
-
break;
|
|
169
|
-
case 11: // Latitute
|
|
170
|
-
sys.general.location.latitude = ((msg.extractPayloadByte(4) * 256) + msg.extractPayloadByte(3)) / 100;
|
|
171
|
-
msg.isProcessed = true;
|
|
172
|
-
break;
|
|
173
|
-
case 12: // Longitude
|
|
174
|
-
sys.general.location.longitude = -((msg.extractPayloadByte(4) * 256) + msg.extractPayloadByte(3)) / 100;
|
|
175
|
-
msg.isProcessed = true;
|
|
176
|
-
break;
|
|
177
|
-
case 13: // Timezone
|
|
178
|
-
sys.general.location.timeZone = msg.extractPayloadByte(3);
|
|
179
|
-
msg.isProcessed = true;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
public static processGroupSettings(msg: Inbound) {
|
|
184
|
-
// We have 3 potential messages.
|
|
185
|
-
let groupId = msg.extractPayloadByte(2) + sys.board.equipmentIds.circuitGroups.start;
|
|
186
|
-
let group: ICircuitGroup = null;
|
|
187
|
-
let sgroup: ICircuitGroupState = null;
|
|
188
|
-
switch (msg.extractPayloadByte(1)) {
|
|
189
|
-
case 0:
|
|
190
|
-
{
|
|
191
|
-
// Get the type.
|
|
192
|
-
let type = msg.extractPayloadByte(3);
|
|
193
|
-
switch (msg.extractPayloadByte(3)) {
|
|
194
|
-
case 0:
|
|
195
|
-
group = sys.circuitGroups.getInterfaceById(groupId);
|
|
196
|
-
sgroup = group.type === 2 ? state.circuitGroups.getItemById(groupId) : state.lightGroups.getItemById(groupId);
|
|
197
|
-
sys.lightGroups.removeItemById(groupId);
|
|
198
|
-
sys.circuitGroups.removeItemById(groupId);
|
|
199
|
-
state.lightGroups.removeItemById(groupId);
|
|
200
|
-
sys.circuitGroups.removeItemById(groupId);
|
|
201
|
-
sgroup.isActive = false;
|
|
202
|
-
state.emitEquipmentChanges();
|
|
203
|
-
msg.isProcessed = true;
|
|
204
|
-
break;
|
|
205
|
-
case 1:
|
|
206
|
-
group = sys.lightGroups.getItemById(groupId, true);
|
|
207
|
-
sgroup = state.lightGroups.getItemById(groupId, true);
|
|
208
|
-
sys.circuitGroups.removeItemById(groupId);
|
|
209
|
-
state.circuitGroups.removeItemById(groupId);
|
|
210
|
-
sgroup.lightingTheme = group.lightingTheme = msg.extractPayloadByte(4) >> 2;
|
|
211
|
-
sgroup.type = group.type = type;
|
|
212
|
-
sgroup.isActive = group.isActive = true;
|
|
213
|
-
msg.isProcessed = true;
|
|
214
|
-
break;
|
|
215
|
-
case 2:
|
|
216
|
-
group = sys.circuitGroups.getItemById(groupId, true);
|
|
217
|
-
sgroup = state.circuitGroups.getItemById(groupId, true);
|
|
218
|
-
sgroup.type = group.type = type;
|
|
219
|
-
if (typeof group.showInFeatures === 'undefined') group.showInFeatures = sgroup.showInFeatures = true;
|
|
220
|
-
sgroup.showInFeatures = group.showInFeatures;
|
|
221
|
-
sys.lightGroups.removeItemById(groupId);
|
|
222
|
-
state.lightGroups.removeItemById(groupId);
|
|
223
|
-
sgroup.isActive = group.isActive = true;
|
|
224
|
-
msg.isProcessed = true;
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
if (group.isActive) {
|
|
228
|
-
for (let i = 0; i < 16; i++) {
|
|
229
|
-
let circuitId = msg.extractPayloadByte(i + 6);
|
|
230
|
-
let circuit = group.circuits.getItemById(i + 1, circuitId < 255);
|
|
231
|
-
if (circuitId === 255) group.circuits.removeItemById(i + 1);
|
|
232
|
-
circuit.circuit = circuitId + 1;
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
group.eggTimer = (msg.extractPayloadByte(38) * 60) + msg.extractPayloadByte(39);
|
|
237
|
-
group.dontStop = group.eggTimer === 1440;
|
|
238
|
-
// sgroup.eggTimer = group.eggTimer;
|
|
239
|
-
if (type === 1) {
|
|
240
|
-
let g = group as LightGroup;
|
|
241
|
-
for (let i = 0; i < 16; i++) {
|
|
242
|
-
g.circuits.getItemById(i + 1).swimDelay = msg.extractPayloadByte(22 + i);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
state.emitEquipmentChanges();
|
|
246
|
-
msg.isProcessed = true;
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
case 1:
|
|
250
|
-
group = sys.circuitGroups.getInterfaceById(groupId);
|
|
251
|
-
sgroup = group.type === 1 ? state.lightGroups.getItemById(groupId) : state.circuitGroups.getItemById(groupId);
|
|
252
|
-
sgroup.name = group.name = msg.extractPayloadString(19, 16);
|
|
253
|
-
if (group.type === 1) {
|
|
254
|
-
let g = group as LightGroup;
|
|
255
|
-
for (let i = 0; i < 16; i++) {
|
|
256
|
-
let circuit = g.circuits.getItemById(i + 1);
|
|
257
|
-
circuit.color = msg.extractPayloadByte(i + 3);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
state.emitEquipmentChanges();
|
|
261
|
-
msg.isProcessed = true;
|
|
262
|
-
break;
|
|
263
|
-
case 2:
|
|
264
|
-
group = sys.circuitGroups.getInterfaceById(groupId);
|
|
265
|
-
// Process the group states.
|
|
266
|
-
if (group.type === 2) {
|
|
267
|
-
let g = group as CircuitGroup;
|
|
268
|
-
for (let i = 0; i < 16; i++) {
|
|
269
|
-
let desiredState = msg.extractPayloadByte(i + 19);
|
|
270
|
-
let circuit = g.circuits.getItemById(i + 1);
|
|
271
|
-
circuit.desiredState = (desiredState !== 255) ? desiredState : 3;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
msg.isProcessed = true;
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
public static processIntelliCenterState(msg) {
|
|
279
|
-
// This is called from Action 30 case 15 (config message) - NOT Action 168 case 15 (wireless message).
|
|
280
|
-
// Action 30 and Action 168 have different payload structures!
|
|
281
|
-
//
|
|
282
|
-
// v1.x: Original offsets (2, 8, 14, 12) - in place since Oct 2019, working.
|
|
283
|
-
// v3.004+: Different structure, requires offsets (3, 9, 15, 13) to match wireless message layout.
|
|
284
|
-
if (sys.equipment.isIntellicenterV3) {
|
|
285
|
-
ExternalMessage.processCircuitState(3, msg);
|
|
286
|
-
ExternalMessage.processFeatureState(9, msg);
|
|
287
|
-
ExternalMessage.processScheduleState(15, msg);
|
|
288
|
-
ExternalMessage.processCircuitGroupState(13, msg);
|
|
289
|
-
} else {
|
|
290
|
-
// v1.x offsets - preserve original behavior since Oct 2019
|
|
291
|
-
ExternalMessage.processCircuitState(2, msg);
|
|
292
|
-
ExternalMessage.processFeatureState(8, msg);
|
|
293
|
-
ExternalMessage.processScheduleState(14, msg);
|
|
294
|
-
ExternalMessage.processCircuitGroupState(12, msg);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
private static processHeater(msg: Inbound) {
|
|
298
|
-
// So a user is changing the heater info. Lets
|
|
299
|
-
// hijack it and get it ourselves.
|
|
300
|
-
// Installing hybrid heater.
|
|
301
|
-
//[165, 63, 15, 16, 168, 30][10, 0, 2, 5, 32, 5, 6, 3, 0, 6, 112, 72, 121, 98, 114, 105, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 1][4, 230]
|
|
302
|
-
let isActive = msg.extractPayloadByte(3) !== 0;
|
|
303
|
-
let heaterId = msg.extractPayloadByte(2) + 1;
|
|
304
|
-
if (isActive) {
|
|
305
|
-
let heater = sys.heaters.getItemById(heaterId, true);
|
|
306
|
-
let hstate = state.heaters.getItemById(heater.id, true);
|
|
307
|
-
|
|
308
|
-
hstate.type = heater.type = msg.extractPayloadByte(3);
|
|
309
|
-
heater.body = msg.extractPayloadByte(4);
|
|
310
|
-
heater.cooldownDelay = msg.extractPayloadByte(5);
|
|
311
|
-
heater.startTempDelta = msg.extractPayloadByte(6);
|
|
312
|
-
heater.stopTempDelta = msg.extractPayloadByte(7);
|
|
313
|
-
heater.coolingEnabled = msg.extractPayloadByte(8) > 0;
|
|
314
|
-
heater.differentialTemp = msg.extractPayloadByte(9);
|
|
315
|
-
heater.address = msg.extractPayloadByte(10);
|
|
316
|
-
hstate.name = heater.name = msg.extractPayloadString(11, 16);
|
|
317
|
-
heater.efficiencyMode = msg.extractPayloadByte(27);
|
|
318
|
-
heater.maxBoostTemp = msg.extractPayloadByte(28);
|
|
319
|
-
heater.economyTime = msg.extractPayloadByte(29);
|
|
320
|
-
heater.master = 0;
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
sys.heaters.removeItemById(heaterId);
|
|
324
|
-
state.heaters.removeItemById(heaterId);
|
|
325
|
-
}
|
|
326
|
-
sys.board.heaters.updateHeaterServices();
|
|
327
|
-
// Check anyway to make sure we got it all.
|
|
328
|
-
//setTimeout(() => sys.checkConfiguration(), 500);
|
|
329
|
-
msg.isProcessed = true;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
private static processCircuitState(start: number, msg: Inbound) {
|
|
333
|
-
let circuitId = 1;//sys.board.equipmentIds.circuits.start;
|
|
334
|
-
for (let i = start; i < msg.payload.length && sys.board.equipmentIds.circuits.isInRange(circuitId); i++) {
|
|
335
|
-
let byte = msg.extractPayloadByte(i);
|
|
336
|
-
// Shift each bit getting the circuit identified by each value.
|
|
337
|
-
for (let j = 0; j < 8; j++) {
|
|
338
|
-
let circuit = sys.circuits.getItemById(circuitId);
|
|
339
|
-
let cstate = state.circuits.getItemById(circuitId, circuit.isActive);
|
|
340
|
-
if (circuit.isActive) {
|
|
341
|
-
let isOn = ((byte & (1 << (j))) >> j) > 0;
|
|
342
|
-
sys.board.circuits.setEndTime(circuit, cstate, isOn);
|
|
343
|
-
cstate.isOn = isOn;
|
|
344
|
-
cstate.name = circuit.name;
|
|
345
|
-
cstate.showInFeatures = circuit.showInFeatures;
|
|
346
|
-
cstate.type = circuit.type;
|
|
347
|
-
switch (circuit.type) {
|
|
348
|
-
case 6: // Globrite
|
|
349
|
-
case 5: // Magicstream
|
|
350
|
-
case 8: // Intellibrite
|
|
351
|
-
case 10: // Colorcascade
|
|
352
|
-
cstate.lightingTheme = circuit.lightingTheme;
|
|
353
|
-
if (!isOn) cstate.action = 0;
|
|
354
|
-
break;
|
|
355
|
-
case 9: // Dimmer
|
|
356
|
-
cstate.level = circuit.level;
|
|
357
|
-
break;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
else
|
|
361
|
-
state.circuits.removeItemById(circuitId);
|
|
362
|
-
state.emitEquipmentChanges();
|
|
363
|
-
circuitId++;
|
|
364
|
-
}
|
|
365
|
-
msg.isProcessed = true;
|
|
366
|
-
}
|
|
367
|
-
// state.body = body;
|
|
368
|
-
}
|
|
369
|
-
private static processScheduleState(start: number, msg: Inbound) {
|
|
370
|
-
let scheduleId = 1;
|
|
371
|
-
for (let i = start; i < msg.payload.length && scheduleId <= sys.equipment.maxSchedules; i++) {
|
|
372
|
-
let byte = msg.extractPayloadByte(i);
|
|
373
|
-
// Shift each bit getting the schedule identified by each value.
|
|
374
|
-
for (let j = 0; j < 8; j++) {
|
|
375
|
-
let schedule = sys.schedules.getItemById(scheduleId);
|
|
376
|
-
if (schedule.isActive) {
|
|
377
|
-
if (schedule.circuit > 0) { // Don't get the schedule state if we haven't determined the entire config for it yet.
|
|
378
|
-
let sstate = state.schedules.getItemById(scheduleId, schedule.isActive);
|
|
379
|
-
let isOn = ((byte & (1 << (j))) >> j) > 0;
|
|
380
|
-
sstate.isOn = isOn;
|
|
381
|
-
sstate.circuit = schedule.circuit;
|
|
382
|
-
sstate.endTime = schedule.endTime;
|
|
383
|
-
sstate.startDate = schedule.startDate;
|
|
384
|
-
sstate.startTime = schedule.startTime;
|
|
385
|
-
sstate.scheduleDays = schedule.scheduleDays;
|
|
386
|
-
sstate.scheduleType = schedule.scheduleType;
|
|
387
|
-
sstate.heatSetpoint = schedule.heatSetpoint;
|
|
388
|
-
sstate.heatSource = schedule.heatSource;
|
|
389
|
-
sstate.startTimeType = schedule.startTimeType;
|
|
390
|
-
sstate.endTimeType = schedule.endTimeType;
|
|
391
|
-
sstate.startDate = schedule.startDate;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
else
|
|
395
|
-
state.schedules.removeItemById(scheduleId);
|
|
396
|
-
scheduleId++;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
state.emitEquipmentChanges();
|
|
400
|
-
msg.isProcessed = true;
|
|
401
|
-
}
|
|
402
|
-
public static processFeatureState(start: number, msg: Inbound) {
|
|
403
|
-
let featureId = sys.board.equipmentIds.features.start;
|
|
404
|
-
let maxFeatureId = sys.features.getMaxId(true, 0);
|
|
405
|
-
//console.log(`Max Feature Id = ${maxFeatureId}`);
|
|
406
|
-
for (let i = start; i < msg.payload.length && featureId <= maxFeatureId; i++) {
|
|
407
|
-
let byte = msg.extractPayloadByte(i);
|
|
408
|
-
// Shift each bit getting the feature identified by each value.
|
|
409
|
-
for (let j = 0; j < 8 && featureId <= maxFeatureId; j++) {
|
|
410
|
-
let feature = sys.features.getItemById(featureId, false, { isActive: false });
|
|
411
|
-
if (feature.isActive !== false) {
|
|
412
|
-
let fstate = state.features.getItemById(featureId, true);
|
|
413
|
-
let isOn = (byte & (1 << j)) > 0;
|
|
414
|
-
sys.board.circuits.setEndTime(feature, fstate, isOn);
|
|
415
|
-
fstate.isOn = isOn;
|
|
416
|
-
fstate.name = feature.name;
|
|
417
|
-
}
|
|
418
|
-
else
|
|
419
|
-
// Just a little insurance to remove the feature from the state.
|
|
420
|
-
state.features.removeItemById(featureId);
|
|
421
|
-
featureId++;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
state.emitEquipmentChanges();
|
|
425
|
-
msg.isProcessed = true;
|
|
426
|
-
|
|
427
|
-
}
|
|
428
|
-
private static processCircuitGroupState(start: number, msg: Inbound) {
|
|
429
|
-
let groupId = sys.board.equipmentIds.circuitGroups.start;
|
|
430
|
-
let maxGroupId = Math.max(sys.lightGroups.getMaxId(true, 0), sys.circuitGroups.getMaxId(true, 0));
|
|
431
|
-
for (let i = start; i < msg.payload.length && groupId <= maxGroupId; i++) {
|
|
432
|
-
let byte = msg.extractPayloadByte(i);
|
|
433
|
-
// Shift each bit getting the group identified by each value.
|
|
434
|
-
for (let j = 0; j < 8; j++) {
|
|
435
|
-
let group = sys.circuitGroups.getInterfaceById(groupId);
|
|
436
|
-
let gstate = group.type === 1 ? state.lightGroups.getItemById(groupId, group.isActive) : state.circuitGroups.getItemById(groupId, group.isActive);
|
|
437
|
-
|
|
438
|
-
if (group.isActive !== false) {
|
|
439
|
-
let isOn = ((byte & (1 << (j))) >> j) > 0;
|
|
440
|
-
sys.board.circuits.setEndTime(group, gstate, isOn);
|
|
441
|
-
gstate.isOn = isOn;
|
|
442
|
-
gstate.name = group.name;
|
|
443
|
-
gstate.type = group.type;
|
|
444
|
-
// Now calculate out the sync/set/swim operations.
|
|
445
|
-
if (gstate.dataName === 'lightGroup' && start === 13) {
|
|
446
|
-
let lg = gstate as LightGroupState;
|
|
447
|
-
let ndx = lg.id - sys.board.equipmentIds.circuitGroups.start;
|
|
448
|
-
let byteNdx = Math.floor(ndx / 4);
|
|
449
|
-
let bitNdx = (ndx * 2) - (byteNdx * 8);
|
|
450
|
-
let byte = msg.extractPayloadByte(start + 15 + byteNdx, 255);
|
|
451
|
-
//console.log(`ndx:${start + 15 + byteNdx} byte: ${byte}, bit: ${bitNdx}`);
|
|
452
|
-
byte = ((byte >> bitNdx) & 0x0003);
|
|
453
|
-
// Each light group is represented by two bits on the status byte. There are 3 status bytes that give us only 12 of the 16 on the config stream but the 168 message
|
|
454
|
-
// does acutall send 4 so all are represented there.
|
|
455
|
-
// [10] = Set
|
|
456
|
-
// [01] = Swim
|
|
457
|
-
// [00] = Sync
|
|
458
|
-
// [11] = No sequencing underway.
|
|
459
|
-
switch (byte) {
|
|
460
|
-
case 0: // Sync
|
|
461
|
-
lg.action = sys.board.valueMaps.circuitActions.getValue('colorsync');
|
|
462
|
-
break;
|
|
463
|
-
case 1: // Color swim
|
|
464
|
-
lg.action = sys.board.valueMaps.circuitActions.getValue('colorswim');
|
|
465
|
-
break;
|
|
466
|
-
case 2: // Color set
|
|
467
|
-
lg.action = sys.board.valueMaps.circuitActions.getValue('colorset');
|
|
468
|
-
break;
|
|
469
|
-
default:
|
|
470
|
-
lg.action = 0;
|
|
471
|
-
break;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
else if(gstate.dataName === 'circuitGroup') {
|
|
475
|
-
(gstate as CircuitGroupState).showInFeatures = group.showInFeatures;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
else {
|
|
479
|
-
state.circuitGroups.removeItemById(groupId);
|
|
480
|
-
state.lightGroups.removeItemById(groupId);
|
|
481
|
-
}
|
|
482
|
-
groupId++;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
state.emitEquipmentChanges();
|
|
486
|
-
msg.isProcessed = true;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
private static processBodies(msg: Inbound) {
|
|
490
|
-
let bodyId = 0;
|
|
491
|
-
let cbody: Body = null;
|
|
492
|
-
switch (msg.extractPayloadByte(2)) {
|
|
493
|
-
case 0:
|
|
494
|
-
case 1:
|
|
495
|
-
case 2:
|
|
496
|
-
case 3:
|
|
497
|
-
bodyId = msg.extractPayloadByte(2);
|
|
498
|
-
if (bodyId === 1) bodyId = 3;
|
|
499
|
-
else if (bodyId === 0) bodyId = 1;
|
|
500
|
-
else if (bodyId === 3) bodyId = 4;
|
|
501
|
-
cbody = sys.bodies.getItemById(bodyId);
|
|
502
|
-
cbody.name = msg.extractPayloadString(3, 16);
|
|
503
|
-
state.temps.bodies.getItemById(bodyId, false).name = cbody.name;
|
|
504
|
-
msg.isProcessed = true;
|
|
505
|
-
break;
|
|
506
|
-
case 4:
|
|
507
|
-
case 5:
|
|
508
|
-
case 6:
|
|
509
|
-
case 7:
|
|
510
|
-
bodyId = msg.extractPayloadByte(2) - 4;
|
|
511
|
-
if (bodyId === 1) bodyId = 3;
|
|
512
|
-
else if (bodyId === 0) bodyId = 1;
|
|
513
|
-
else if (bodyId === 3) bodyId = 4;
|
|
514
|
-
cbody = sys.bodies.getItemById(bodyId);
|
|
515
|
-
cbody.capacity = msg.extractPayloadByte(3) * 1000;
|
|
516
|
-
msg.isProcessed = true;
|
|
517
|
-
break;
|
|
518
|
-
case
|
|
519
|
-
msg.
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
let
|
|
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
|
-
|
|
600
|
-
|
|
601
|
-
if (
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
s.
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
s.
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
let
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
case
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
msg.
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
msg.isProcessed = true;
|
|
886
|
-
break;
|
|
887
|
-
case
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
msg.
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
msg.
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
msg.isProcessed = true;
|
|
911
|
-
break;
|
|
912
|
-
case
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1
|
+
/* nodejs-poolController. An application to control pool equipment.
|
|
2
|
+
Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022.
|
|
3
|
+
Russell Goldin, tagyoureit. russ.goldin@gmail.com
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Affero General Public License as
|
|
7
|
+
published by the Free Software Foundation, either version 3 of the
|
|
8
|
+
License, or (at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Affero General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { Inbound } from "../Messages";
|
|
19
|
+
import { sys, Body, ICircuitGroup, LightGroup, CircuitGroup } from "../../../Equipment";
|
|
20
|
+
import { state, ICircuitGroupState, LightGroupState, CircuitGroupState } from "../../../State";
|
|
21
|
+
import { ControllerType, Timestamp, utils } from "../../../Constants";
|
|
22
|
+
import { logger } from "../../../../logger/Logger";
|
|
23
|
+
export class ExternalMessage {
|
|
24
|
+
public static processIntelliCenter(msg: Inbound): void {
|
|
25
|
+
// IntelliCenter v3.x: treat Wireless/ICP/Indoor -> OCP packets as requests, not source-of-truth.
|
|
26
|
+
// We are a bus listener, so we will see traffic not addressed to us; do not apply those requests to state.
|
|
27
|
+
// Only accept OCP-originated messages here. If/when OCP applies a request, it will broadcast authoritative
|
|
28
|
+
// state/config via other message types (e.g., Action 30 / 204).
|
|
29
|
+
if (sys.equipment.isIntellicenterV3 && msg.dest === 16 && msg.source !== 16) {
|
|
30
|
+
msg.isProcessed = true;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
switch (msg.extractPayloadByte(0)) {
|
|
34
|
+
case 0: // Setpoints/HeatMode
|
|
35
|
+
ExternalMessage.processTempSettings(msg);
|
|
36
|
+
break;
|
|
37
|
+
case 1: // Circuit Changes
|
|
38
|
+
ExternalMessage.processCircuit(msg);
|
|
39
|
+
break;
|
|
40
|
+
case 2: // Feature Changes
|
|
41
|
+
ExternalMessage.processFeature(msg);
|
|
42
|
+
break;
|
|
43
|
+
case 3: // Schedule Changes
|
|
44
|
+
ExternalMessage.processSchedules(msg);
|
|
45
|
+
break;
|
|
46
|
+
case 4: // Pump Information
|
|
47
|
+
ExternalMessage.processPump(msg);
|
|
48
|
+
break;
|
|
49
|
+
case 5: // Remotes
|
|
50
|
+
break;
|
|
51
|
+
case 6: // Light/Circuit group
|
|
52
|
+
ExternalMessage.processGroupSettings(msg);
|
|
53
|
+
break;
|
|
54
|
+
case 7: // Chlorinator
|
|
55
|
+
ExternalMessage.processChlorinator(msg);
|
|
56
|
+
break;
|
|
57
|
+
case 8: // IntelliChem
|
|
58
|
+
ExternalMessage.processIntelliChem(msg);
|
|
59
|
+
break;
|
|
60
|
+
case 9: // Valves
|
|
61
|
+
ExternalMessage.processValve(msg);
|
|
62
|
+
break;
|
|
63
|
+
case 10: // Heaters
|
|
64
|
+
ExternalMessage.processHeater(msg);
|
|
65
|
+
break;
|
|
66
|
+
case 11: // Security
|
|
67
|
+
break;
|
|
68
|
+
case 12: // Pool Settings Alias, owner...etc.
|
|
69
|
+
ExternalMessage.processPool(msg);
|
|
70
|
+
break;
|
|
71
|
+
case 13: // Bodies (Manual heat, capacities)
|
|
72
|
+
ExternalMessage.processBodies(msg);
|
|
73
|
+
break;
|
|
74
|
+
case 14: // Covers
|
|
75
|
+
break;
|
|
76
|
+
case 15: // Circuit, feature, group, and schedule States
|
|
77
|
+
ExternalMessage.processCircuitState(3, msg);
|
|
78
|
+
ExternalMessage.processFeatureState(9, msg);
|
|
79
|
+
ExternalMessage.processScheduleState(15, msg);
|
|
80
|
+
ExternalMessage.processCircuitGroupState(13, msg);
|
|
81
|
+
break;
|
|
82
|
+
default:
|
|
83
|
+
logger.debug(`Unprocessed Message ${msg.toPacket()}`)
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
public static processIntelliChem(msg: Inbound) {
|
|
88
|
+
let id = msg.extractPayloadByte(2) + 1;
|
|
89
|
+
let isActive = utils.makeBool(msg.extractPayloadByte(6));
|
|
90
|
+
//let schem = state.chemchems.getItemById(id, isActive);
|
|
91
|
+
//chem.isActive = schem.isActive = isActive;
|
|
92
|
+
if (isActive) {
|
|
93
|
+
let chem = sys.chemControllers.getItemById(id, true);
|
|
94
|
+
let schem = state.chemControllers.getItemById(id, true);
|
|
95
|
+
// chem.isVirtual = false;
|
|
96
|
+
chem.master = 0;
|
|
97
|
+
chem.ph.tank.capacity = chem.orp.tank.capacity = 6;
|
|
98
|
+
chem.ph.tank.units = chem.orp.tank.units = '';
|
|
99
|
+
schem.type = chem.type = 2;
|
|
100
|
+
schem.name = chem.name = (chem.name || 'IntelliChem' + id);
|
|
101
|
+
schem.body = chem.body = msg.extractPayloadByte(3);
|
|
102
|
+
schem.address = chem.address = msg.extractPayloadByte(5);
|
|
103
|
+
chem.ph.setpoint = schem.ph.setpoint = msg.extractPayloadInt(7) / 100;
|
|
104
|
+
chem.orp.setpoint = schem.orp.setpoint = msg.extractPayloadInt(9);
|
|
105
|
+
chem.calciumHardness = msg.extractPayloadInt(13);
|
|
106
|
+
chem.cyanuricAcid = msg.extractPayloadInt(15);
|
|
107
|
+
chem.alkalinity = msg.extractPayloadInt(17);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
sys.chemControllers.removeItemById(id);
|
|
111
|
+
state.chemControllers.removeItemById(id);
|
|
112
|
+
}
|
|
113
|
+
msg.isProcessed = true;
|
|
114
|
+
}
|
|
115
|
+
public static processValve(msg: Inbound) {
|
|
116
|
+
let valve = sys.valves.getItemById(msg.extractPayloadByte(2) + 1);
|
|
117
|
+
valve.circuit = msg.extractPayloadByte(3) + 1;
|
|
118
|
+
valve.name = msg.extractPayloadString(4, 16);
|
|
119
|
+
valve.master = 0;
|
|
120
|
+
// valve.isVirtual = false;
|
|
121
|
+
msg.isProcessed = true;
|
|
122
|
+
}
|
|
123
|
+
public static processPool(msg: Inbound) {
|
|
124
|
+
switch (msg.extractPayloadByte(2)) {
|
|
125
|
+
case 0: // Pool Alias
|
|
126
|
+
sys.general.alias = msg.extractPayloadString(3, 16);
|
|
127
|
+
msg.isProcessed = true;
|
|
128
|
+
break;
|
|
129
|
+
case 1: // Address
|
|
130
|
+
sys.general.location.address = msg.extractPayloadString(3, 32);
|
|
131
|
+
msg.isProcessed = true;
|
|
132
|
+
break;
|
|
133
|
+
case 2: // Owner
|
|
134
|
+
sys.general.owner.name = msg.extractPayloadString(3, 16);
|
|
135
|
+
msg.isProcessed = true;
|
|
136
|
+
break;
|
|
137
|
+
case 3: // Email
|
|
138
|
+
sys.general.owner.email = msg.extractPayloadString(3, 32);
|
|
139
|
+
msg.isProcessed = true;
|
|
140
|
+
break;
|
|
141
|
+
case 4: // Email 2
|
|
142
|
+
sys.general.owner.email2 = msg.extractPayloadString(3, 32);
|
|
143
|
+
msg.isProcessed = true;
|
|
144
|
+
break;
|
|
145
|
+
case 5: // Phone
|
|
146
|
+
sys.general.owner.phone = msg.extractPayloadString(3, 16);
|
|
147
|
+
msg.isProcessed = true;
|
|
148
|
+
break;
|
|
149
|
+
case 6: // Phone 2
|
|
150
|
+
sys.general.owner.phone2 = msg.extractPayloadString(3, 16);
|
|
151
|
+
msg.isProcessed = true;
|
|
152
|
+
break;
|
|
153
|
+
case 7: // Zipcode
|
|
154
|
+
sys.general.location.zip = msg.extractPayloadString(3, 6);
|
|
155
|
+
msg.isProcessed = true;
|
|
156
|
+
break;
|
|
157
|
+
case 8: // Country
|
|
158
|
+
sys.general.location.country = msg.extractPayloadString(3, 32);
|
|
159
|
+
msg.isProcessed = true;
|
|
160
|
+
break;
|
|
161
|
+
case 9: // City
|
|
162
|
+
sys.general.location.city = msg.extractPayloadString(3, 32);
|
|
163
|
+
msg.isProcessed = true;
|
|
164
|
+
break;
|
|
165
|
+
case 10: // State
|
|
166
|
+
sys.general.location.state = msg.extractPayloadString(3, 16);
|
|
167
|
+
msg.isProcessed = true;
|
|
168
|
+
break;
|
|
169
|
+
case 11: // Latitute
|
|
170
|
+
sys.general.location.latitude = ((msg.extractPayloadByte(4) * 256) + msg.extractPayloadByte(3)) / 100;
|
|
171
|
+
msg.isProcessed = true;
|
|
172
|
+
break;
|
|
173
|
+
case 12: // Longitude
|
|
174
|
+
sys.general.location.longitude = -((msg.extractPayloadByte(4) * 256) + msg.extractPayloadByte(3)) / 100;
|
|
175
|
+
msg.isProcessed = true;
|
|
176
|
+
break;
|
|
177
|
+
case 13: // Timezone
|
|
178
|
+
sys.general.location.timeZone = msg.extractPayloadByte(3);
|
|
179
|
+
msg.isProcessed = true;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
public static processGroupSettings(msg: Inbound) {
|
|
184
|
+
// We have 3 potential messages.
|
|
185
|
+
let groupId = msg.extractPayloadByte(2) + sys.board.equipmentIds.circuitGroups.start;
|
|
186
|
+
let group: ICircuitGroup = null;
|
|
187
|
+
let sgroup: ICircuitGroupState = null;
|
|
188
|
+
switch (msg.extractPayloadByte(1)) {
|
|
189
|
+
case 0:
|
|
190
|
+
{
|
|
191
|
+
// Get the type.
|
|
192
|
+
let type = msg.extractPayloadByte(3);
|
|
193
|
+
switch (msg.extractPayloadByte(3)) {
|
|
194
|
+
case 0:
|
|
195
|
+
group = sys.circuitGroups.getInterfaceById(groupId);
|
|
196
|
+
sgroup = group.type === 2 ? state.circuitGroups.getItemById(groupId) : state.lightGroups.getItemById(groupId);
|
|
197
|
+
sys.lightGroups.removeItemById(groupId);
|
|
198
|
+
sys.circuitGroups.removeItemById(groupId);
|
|
199
|
+
state.lightGroups.removeItemById(groupId);
|
|
200
|
+
sys.circuitGroups.removeItemById(groupId);
|
|
201
|
+
sgroup.isActive = false;
|
|
202
|
+
state.emitEquipmentChanges();
|
|
203
|
+
msg.isProcessed = true;
|
|
204
|
+
break;
|
|
205
|
+
case 1:
|
|
206
|
+
group = sys.lightGroups.getItemById(groupId, true);
|
|
207
|
+
sgroup = state.lightGroups.getItemById(groupId, true);
|
|
208
|
+
sys.circuitGroups.removeItemById(groupId);
|
|
209
|
+
state.circuitGroups.removeItemById(groupId);
|
|
210
|
+
sgroup.lightingTheme = group.lightingTheme = msg.extractPayloadByte(4) >> 2;
|
|
211
|
+
sgroup.type = group.type = type;
|
|
212
|
+
sgroup.isActive = group.isActive = true;
|
|
213
|
+
msg.isProcessed = true;
|
|
214
|
+
break;
|
|
215
|
+
case 2:
|
|
216
|
+
group = sys.circuitGroups.getItemById(groupId, true);
|
|
217
|
+
sgroup = state.circuitGroups.getItemById(groupId, true);
|
|
218
|
+
sgroup.type = group.type = type;
|
|
219
|
+
if (typeof group.showInFeatures === 'undefined') group.showInFeatures = sgroup.showInFeatures = true;
|
|
220
|
+
sgroup.showInFeatures = group.showInFeatures;
|
|
221
|
+
sys.lightGroups.removeItemById(groupId);
|
|
222
|
+
state.lightGroups.removeItemById(groupId);
|
|
223
|
+
sgroup.isActive = group.isActive = true;
|
|
224
|
+
msg.isProcessed = true;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
if (group.isActive) {
|
|
228
|
+
for (let i = 0; i < 16; i++) {
|
|
229
|
+
let circuitId = msg.extractPayloadByte(i + 6);
|
|
230
|
+
let circuit = group.circuits.getItemById(i + 1, circuitId < 255);
|
|
231
|
+
if (circuitId === 255) group.circuits.removeItemById(i + 1);
|
|
232
|
+
circuit.circuit = circuitId + 1;
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
group.eggTimer = (msg.extractPayloadByte(38) * 60) + msg.extractPayloadByte(39);
|
|
237
|
+
group.dontStop = group.eggTimer === 1440;
|
|
238
|
+
// sgroup.eggTimer = group.eggTimer;
|
|
239
|
+
if (type === 1) {
|
|
240
|
+
let g = group as LightGroup;
|
|
241
|
+
for (let i = 0; i < 16; i++) {
|
|
242
|
+
g.circuits.getItemById(i + 1).swimDelay = msg.extractPayloadByte(22 + i);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
state.emitEquipmentChanges();
|
|
246
|
+
msg.isProcessed = true;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case 1:
|
|
250
|
+
group = sys.circuitGroups.getInterfaceById(groupId);
|
|
251
|
+
sgroup = group.type === 1 ? state.lightGroups.getItemById(groupId) : state.circuitGroups.getItemById(groupId);
|
|
252
|
+
sgroup.name = group.name = msg.extractPayloadString(19, 16);
|
|
253
|
+
if (group.type === 1) {
|
|
254
|
+
let g = group as LightGroup;
|
|
255
|
+
for (let i = 0; i < 16; i++) {
|
|
256
|
+
let circuit = g.circuits.getItemById(i + 1);
|
|
257
|
+
circuit.color = msg.extractPayloadByte(i + 3);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
state.emitEquipmentChanges();
|
|
261
|
+
msg.isProcessed = true;
|
|
262
|
+
break;
|
|
263
|
+
case 2:
|
|
264
|
+
group = sys.circuitGroups.getInterfaceById(groupId);
|
|
265
|
+
// Process the group states.
|
|
266
|
+
if (group.type === 2) {
|
|
267
|
+
let g = group as CircuitGroup;
|
|
268
|
+
for (let i = 0; i < 16; i++) {
|
|
269
|
+
let desiredState = msg.extractPayloadByte(i + 19);
|
|
270
|
+
let circuit = g.circuits.getItemById(i + 1);
|
|
271
|
+
circuit.desiredState = (desiredState !== 255) ? desiredState : 3;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
msg.isProcessed = true;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
public static processIntelliCenterState(msg) {
|
|
279
|
+
// This is called from Action 30 case 15 (config message) - NOT Action 168 case 15 (wireless message).
|
|
280
|
+
// Action 30 and Action 168 have different payload structures!
|
|
281
|
+
//
|
|
282
|
+
// v1.x: Original offsets (2, 8, 14, 12) - in place since Oct 2019, working.
|
|
283
|
+
// v3.004+: Different structure, requires offsets (3, 9, 15, 13) to match wireless message layout.
|
|
284
|
+
if (sys.equipment.isIntellicenterV3) {
|
|
285
|
+
ExternalMessage.processCircuitState(3, msg);
|
|
286
|
+
ExternalMessage.processFeatureState(9, msg);
|
|
287
|
+
ExternalMessage.processScheduleState(15, msg);
|
|
288
|
+
ExternalMessage.processCircuitGroupState(13, msg);
|
|
289
|
+
} else {
|
|
290
|
+
// v1.x offsets - preserve original behavior since Oct 2019
|
|
291
|
+
ExternalMessage.processCircuitState(2, msg);
|
|
292
|
+
ExternalMessage.processFeatureState(8, msg);
|
|
293
|
+
ExternalMessage.processScheduleState(14, msg);
|
|
294
|
+
ExternalMessage.processCircuitGroupState(12, msg);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
private static processHeater(msg: Inbound) {
|
|
298
|
+
// So a user is changing the heater info. Lets
|
|
299
|
+
// hijack it and get it ourselves.
|
|
300
|
+
// Installing hybrid heater.
|
|
301
|
+
//[165, 63, 15, 16, 168, 30][10, 0, 2, 5, 32, 5, 6, 3, 0, 6, 112, 72, 121, 98, 114, 105, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 1][4, 230]
|
|
302
|
+
let isActive = msg.extractPayloadByte(3) !== 0;
|
|
303
|
+
let heaterId = msg.extractPayloadByte(2) + 1;
|
|
304
|
+
if (isActive) {
|
|
305
|
+
let heater = sys.heaters.getItemById(heaterId, true);
|
|
306
|
+
let hstate = state.heaters.getItemById(heater.id, true);
|
|
307
|
+
|
|
308
|
+
hstate.type = heater.type = msg.extractPayloadByte(3);
|
|
309
|
+
heater.body = msg.extractPayloadByte(4);
|
|
310
|
+
heater.cooldownDelay = msg.extractPayloadByte(5);
|
|
311
|
+
heater.startTempDelta = msg.extractPayloadByte(6);
|
|
312
|
+
heater.stopTempDelta = msg.extractPayloadByte(7);
|
|
313
|
+
heater.coolingEnabled = msg.extractPayloadByte(8) > 0;
|
|
314
|
+
heater.differentialTemp = msg.extractPayloadByte(9);
|
|
315
|
+
heater.address = msg.extractPayloadByte(10);
|
|
316
|
+
hstate.name = heater.name = msg.extractPayloadString(11, 16);
|
|
317
|
+
heater.efficiencyMode = msg.extractPayloadByte(27);
|
|
318
|
+
heater.maxBoostTemp = msg.extractPayloadByte(28);
|
|
319
|
+
heater.economyTime = msg.extractPayloadByte(29);
|
|
320
|
+
heater.master = 0;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
sys.heaters.removeItemById(heaterId);
|
|
324
|
+
state.heaters.removeItemById(heaterId);
|
|
325
|
+
}
|
|
326
|
+
sys.board.heaters.updateHeaterServices();
|
|
327
|
+
// Check anyway to make sure we got it all.
|
|
328
|
+
//setTimeout(() => sys.checkConfiguration(), 500);
|
|
329
|
+
msg.isProcessed = true;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
private static processCircuitState(start: number, msg: Inbound) {
|
|
333
|
+
let circuitId = 1;//sys.board.equipmentIds.circuits.start;
|
|
334
|
+
for (let i = start; i < msg.payload.length && sys.board.equipmentIds.circuits.isInRange(circuitId); i++) {
|
|
335
|
+
let byte = msg.extractPayloadByte(i);
|
|
336
|
+
// Shift each bit getting the circuit identified by each value.
|
|
337
|
+
for (let j = 0; j < 8; j++) {
|
|
338
|
+
let circuit = sys.circuits.getItemById(circuitId);
|
|
339
|
+
let cstate = state.circuits.getItemById(circuitId, circuit.isActive);
|
|
340
|
+
if (circuit.isActive) {
|
|
341
|
+
let isOn = ((byte & (1 << (j))) >> j) > 0;
|
|
342
|
+
sys.board.circuits.setEndTime(circuit, cstate, isOn);
|
|
343
|
+
cstate.isOn = isOn;
|
|
344
|
+
cstate.name = circuit.name;
|
|
345
|
+
cstate.showInFeatures = circuit.showInFeatures;
|
|
346
|
+
cstate.type = circuit.type;
|
|
347
|
+
switch (circuit.type) {
|
|
348
|
+
case 6: // Globrite
|
|
349
|
+
case 5: // Magicstream
|
|
350
|
+
case 8: // Intellibrite
|
|
351
|
+
case 10: // Colorcascade
|
|
352
|
+
cstate.lightingTheme = circuit.lightingTheme;
|
|
353
|
+
if (!isOn) cstate.action = 0;
|
|
354
|
+
break;
|
|
355
|
+
case 9: // Dimmer
|
|
356
|
+
cstate.level = circuit.level;
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
else
|
|
361
|
+
state.circuits.removeItemById(circuitId);
|
|
362
|
+
state.emitEquipmentChanges();
|
|
363
|
+
circuitId++;
|
|
364
|
+
}
|
|
365
|
+
msg.isProcessed = true;
|
|
366
|
+
}
|
|
367
|
+
// state.body = body;
|
|
368
|
+
}
|
|
369
|
+
private static processScheduleState(start: number, msg: Inbound) {
|
|
370
|
+
let scheduleId = 1;
|
|
371
|
+
for (let i = start; i < msg.payload.length && scheduleId <= sys.equipment.maxSchedules; i++) {
|
|
372
|
+
let byte = msg.extractPayloadByte(i);
|
|
373
|
+
// Shift each bit getting the schedule identified by each value.
|
|
374
|
+
for (let j = 0; j < 8; j++) {
|
|
375
|
+
let schedule = sys.schedules.getItemById(scheduleId);
|
|
376
|
+
if (schedule.isActive) {
|
|
377
|
+
if (schedule.circuit > 0) { // Don't get the schedule state if we haven't determined the entire config for it yet.
|
|
378
|
+
let sstate = state.schedules.getItemById(scheduleId, schedule.isActive);
|
|
379
|
+
let isOn = ((byte & (1 << (j))) >> j) > 0;
|
|
380
|
+
sstate.isOn = isOn;
|
|
381
|
+
sstate.circuit = schedule.circuit;
|
|
382
|
+
sstate.endTime = schedule.endTime;
|
|
383
|
+
sstate.startDate = schedule.startDate;
|
|
384
|
+
sstate.startTime = schedule.startTime;
|
|
385
|
+
sstate.scheduleDays = schedule.scheduleDays;
|
|
386
|
+
sstate.scheduleType = schedule.scheduleType;
|
|
387
|
+
sstate.heatSetpoint = schedule.heatSetpoint;
|
|
388
|
+
sstate.heatSource = schedule.heatSource;
|
|
389
|
+
sstate.startTimeType = schedule.startTimeType;
|
|
390
|
+
sstate.endTimeType = schedule.endTimeType;
|
|
391
|
+
sstate.startDate = schedule.startDate;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
else
|
|
395
|
+
state.schedules.removeItemById(scheduleId);
|
|
396
|
+
scheduleId++;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
state.emitEquipmentChanges();
|
|
400
|
+
msg.isProcessed = true;
|
|
401
|
+
}
|
|
402
|
+
public static processFeatureState(start: number, msg: Inbound) {
|
|
403
|
+
let featureId = sys.board.equipmentIds.features.start;
|
|
404
|
+
let maxFeatureId = sys.features.getMaxId(true, 0);
|
|
405
|
+
//console.log(`Max Feature Id = ${maxFeatureId}`);
|
|
406
|
+
for (let i = start; i < msg.payload.length && featureId <= maxFeatureId; i++) {
|
|
407
|
+
let byte = msg.extractPayloadByte(i);
|
|
408
|
+
// Shift each bit getting the feature identified by each value.
|
|
409
|
+
for (let j = 0; j < 8 && featureId <= maxFeatureId; j++) {
|
|
410
|
+
let feature = sys.features.getItemById(featureId, false, { isActive: false });
|
|
411
|
+
if (feature.isActive !== false) {
|
|
412
|
+
let fstate = state.features.getItemById(featureId, true);
|
|
413
|
+
let isOn = (byte & (1 << j)) > 0;
|
|
414
|
+
sys.board.circuits.setEndTime(feature, fstate, isOn);
|
|
415
|
+
fstate.isOn = isOn;
|
|
416
|
+
fstate.name = feature.name;
|
|
417
|
+
}
|
|
418
|
+
else
|
|
419
|
+
// Just a little insurance to remove the feature from the state.
|
|
420
|
+
state.features.removeItemById(featureId);
|
|
421
|
+
featureId++;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
state.emitEquipmentChanges();
|
|
425
|
+
msg.isProcessed = true;
|
|
426
|
+
|
|
427
|
+
}
|
|
428
|
+
private static processCircuitGroupState(start: number, msg: Inbound) {
|
|
429
|
+
let groupId = sys.board.equipmentIds.circuitGroups.start;
|
|
430
|
+
let maxGroupId = Math.max(sys.lightGroups.getMaxId(true, 0), sys.circuitGroups.getMaxId(true, 0));
|
|
431
|
+
for (let i = start; i < msg.payload.length && groupId <= maxGroupId; i++) {
|
|
432
|
+
let byte = msg.extractPayloadByte(i);
|
|
433
|
+
// Shift each bit getting the group identified by each value.
|
|
434
|
+
for (let j = 0; j < 8; j++) {
|
|
435
|
+
let group = sys.circuitGroups.getInterfaceById(groupId);
|
|
436
|
+
let gstate = group.type === 1 ? state.lightGroups.getItemById(groupId, group.isActive) : state.circuitGroups.getItemById(groupId, group.isActive);
|
|
437
|
+
|
|
438
|
+
if (group.isActive !== false) {
|
|
439
|
+
let isOn = ((byte & (1 << (j))) >> j) > 0;
|
|
440
|
+
sys.board.circuits.setEndTime(group, gstate, isOn);
|
|
441
|
+
gstate.isOn = isOn;
|
|
442
|
+
gstate.name = group.name;
|
|
443
|
+
gstate.type = group.type;
|
|
444
|
+
// Now calculate out the sync/set/swim operations.
|
|
445
|
+
if (gstate.dataName === 'lightGroup' && start === 13) {
|
|
446
|
+
let lg = gstate as LightGroupState;
|
|
447
|
+
let ndx = lg.id - sys.board.equipmentIds.circuitGroups.start;
|
|
448
|
+
let byteNdx = Math.floor(ndx / 4);
|
|
449
|
+
let bitNdx = (ndx * 2) - (byteNdx * 8);
|
|
450
|
+
let byte = msg.extractPayloadByte(start + 15 + byteNdx, 255);
|
|
451
|
+
//console.log(`ndx:${start + 15 + byteNdx} byte: ${byte}, bit: ${bitNdx}`);
|
|
452
|
+
byte = ((byte >> bitNdx) & 0x0003);
|
|
453
|
+
// Each light group is represented by two bits on the status byte. There are 3 status bytes that give us only 12 of the 16 on the config stream but the 168 message
|
|
454
|
+
// does acutall send 4 so all are represented there.
|
|
455
|
+
// [10] = Set
|
|
456
|
+
// [01] = Swim
|
|
457
|
+
// [00] = Sync
|
|
458
|
+
// [11] = No sequencing underway.
|
|
459
|
+
switch (byte) {
|
|
460
|
+
case 0: // Sync
|
|
461
|
+
lg.action = sys.board.valueMaps.circuitActions.getValue('colorsync');
|
|
462
|
+
break;
|
|
463
|
+
case 1: // Color swim
|
|
464
|
+
lg.action = sys.board.valueMaps.circuitActions.getValue('colorswim');
|
|
465
|
+
break;
|
|
466
|
+
case 2: // Color set
|
|
467
|
+
lg.action = sys.board.valueMaps.circuitActions.getValue('colorset');
|
|
468
|
+
break;
|
|
469
|
+
default:
|
|
470
|
+
lg.action = 0;
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
else if(gstate.dataName === 'circuitGroup') {
|
|
475
|
+
(gstate as CircuitGroupState).showInFeatures = group.showInFeatures;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
state.circuitGroups.removeItemById(groupId);
|
|
480
|
+
state.lightGroups.removeItemById(groupId);
|
|
481
|
+
}
|
|
482
|
+
groupId++;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
state.emitEquipmentChanges();
|
|
486
|
+
msg.isProcessed = true;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
private static processBodies(msg: Inbound) {
|
|
490
|
+
let bodyId = 0;
|
|
491
|
+
let cbody: Body = null;
|
|
492
|
+
switch (msg.extractPayloadByte(2)) {
|
|
493
|
+
case 0:
|
|
494
|
+
case 1:
|
|
495
|
+
case 2:
|
|
496
|
+
case 3:
|
|
497
|
+
bodyId = msg.extractPayloadByte(2);
|
|
498
|
+
if (bodyId === 1) bodyId = 3;
|
|
499
|
+
else if (bodyId === 0) bodyId = 1;
|
|
500
|
+
else if (bodyId === 3) bodyId = 4;
|
|
501
|
+
cbody = sys.bodies.getItemById(bodyId);
|
|
502
|
+
cbody.name = msg.extractPayloadString(3, 16);
|
|
503
|
+
state.temps.bodies.getItemById(bodyId, false).name = cbody.name;
|
|
504
|
+
msg.isProcessed = true;
|
|
505
|
+
break;
|
|
506
|
+
case 4:
|
|
507
|
+
case 5:
|
|
508
|
+
case 6:
|
|
509
|
+
case 7:
|
|
510
|
+
bodyId = msg.extractPayloadByte(2) - 4;
|
|
511
|
+
if (bodyId === 1) bodyId = 3;
|
|
512
|
+
else if (bodyId === 0) bodyId = 1;
|
|
513
|
+
else if (bodyId === 3) bodyId = 4;
|
|
514
|
+
cbody = sys.bodies.getItemById(bodyId);
|
|
515
|
+
cbody.capacity = msg.extractPayloadByte(3) * 1000;
|
|
516
|
+
msg.isProcessed = true;
|
|
517
|
+
break;
|
|
518
|
+
case 12: // Circuit notifications
|
|
519
|
+
if (msg.payload.length > 3) {
|
|
520
|
+
const value = msg.extractPayloadByte(3, 0);
|
|
521
|
+
sys.alerts.circuitNotifications = value;
|
|
522
|
+
sys.alerts.setRaw(12, [value]);
|
|
523
|
+
}
|
|
524
|
+
msg.isProcessed = true;
|
|
525
|
+
break;
|
|
526
|
+
case 13: // Pump notifications
|
|
527
|
+
ExternalMessage.applyAlertNotificationFromExternal(msg, 13, 3);
|
|
528
|
+
msg.isProcessed = true;
|
|
529
|
+
break;
|
|
530
|
+
case 14: // Heater notifications
|
|
531
|
+
ExternalMessage.applyAlertNotificationFromExternal(msg, 14, 3);
|
|
532
|
+
msg.isProcessed = true;
|
|
533
|
+
break;
|
|
534
|
+
case 15: // Chlorinator notifications
|
|
535
|
+
ExternalMessage.applyAlertNotificationFromExternal(msg, 15, 3);
|
|
536
|
+
msg.isProcessed = true;
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
state.emitEquipmentChanges();
|
|
540
|
+
}
|
|
541
|
+
private static applyAlertNotificationFromExternal(msg: Inbound, selector: number, startOffset: number) {
|
|
542
|
+
const raw: number[] = [];
|
|
543
|
+
for (let i = startOffset; i < msg.payload.length; i++) raw.push(msg.extractPayloadByte(i, 0));
|
|
544
|
+
sys.alerts.setRaw(selector, raw);
|
|
545
|
+
if (raw.length === 0) return;
|
|
546
|
+
const mask = raw.length === 1 ? (raw[0] & 0xFF) : (((raw[raw.length - 2] & 0xFF) << 8) | (raw[raw.length - 1] & 0xFF));
|
|
547
|
+
switch (selector) {
|
|
548
|
+
case 13:
|
|
549
|
+
sys.alerts.pumpNotifications = mask;
|
|
550
|
+
break;
|
|
551
|
+
case 14:
|
|
552
|
+
sys.alerts.heaterNotifications = mask;
|
|
553
|
+
break;
|
|
554
|
+
case 15:
|
|
555
|
+
sys.alerts.chlorinatorNotifications = mask;
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
private static processSchedules(msg: Inbound) {
|
|
560
|
+
let schedId = msg.extractPayloadByte(2) + 1;
|
|
561
|
+
// v3.004+: schedule times are big-endian (hi,lo) in Action 168 payloads.
|
|
562
|
+
// v1.x: schedule times are little-endian (lo,hi).
|
|
563
|
+
let startTime: number;
|
|
564
|
+
let endTime: number;
|
|
565
|
+
if (sys.controllerType === ControllerType.IntelliCenter && sys.equipment.isIntellicenterV3) {
|
|
566
|
+
startTime = msg.extractPayloadIntBE(3);
|
|
567
|
+
endTime = msg.extractPayloadIntBE(5);
|
|
568
|
+
} else {
|
|
569
|
+
startTime = msg.extractPayloadInt(3);
|
|
570
|
+
endTime = msg.extractPayloadInt(5);
|
|
571
|
+
}
|
|
572
|
+
let circuit = msg.extractPayloadByte(7) + 1;
|
|
573
|
+
let isActive = (msg.extractPayloadByte(8) & 128) === 128; // Inactive schedules do not have bit 8 set.
|
|
574
|
+
let cfg = sys.schedules.getItemById(schedId, isActive);
|
|
575
|
+
let s = state.schedules.getItemById(schedId, cfg.isActive);
|
|
576
|
+
//cfg.isActive = (circuit !== 256);
|
|
577
|
+
cfg.startTime = startTime;
|
|
578
|
+
cfg.endTime = endTime;
|
|
579
|
+
cfg.circuit = circuit;
|
|
580
|
+
cfg.isActive = isActive;
|
|
581
|
+
let byte = msg.extractPayloadByte(8);
|
|
582
|
+
cfg.scheduleType = (byte & 1 & 0xFF) === 1 ? 0 : 128;
|
|
583
|
+
if ((byte & 4 & 0xFF) === 4) cfg.startTimeType = 1;
|
|
584
|
+
else if ((byte & 8 & 0xFF) === 8) cfg.startTimeType = 2;
|
|
585
|
+
else cfg.startTimeType = 0;
|
|
586
|
+
|
|
587
|
+
if ((byte & 16 & 0xFF) === 16) cfg.endTimeType = 1;
|
|
588
|
+
else if ((byte & 32 & 0xFF) === 32) cfg.endTimeType = 2;
|
|
589
|
+
else cfg.endTimeType = 0;
|
|
590
|
+
//cfg.runOnce = byte;
|
|
591
|
+
cfg.scheduleDays = msg.extractPayloadByte(9);
|
|
592
|
+
cfg.startMonth = msg.extractPayloadByte(10);
|
|
593
|
+
cfg.startDay = msg.extractPayloadByte(11);
|
|
594
|
+
cfg.startYear = msg.extractPayloadByte(12);
|
|
595
|
+
let hs = msg.extractPayloadByte(13);
|
|
596
|
+
// RKS: During the transition to 1.047 the heat sources were all screwed up. O now means no change and 1 means off.
|
|
597
|
+
//if (hs === 1) hs = 0; // Shim for 1.047
|
|
598
|
+
cfg.heatSource = hs;
|
|
599
|
+
cfg.heatSetpoint = msg.extractPayloadByte(14);
|
|
600
|
+
cfg.coolSetpoint = msg.extractPayloadByte(15);
|
|
601
|
+
if (cfg.isActive) {
|
|
602
|
+
let s = state.schedules.getItemById(schedId, cfg.isActive);
|
|
603
|
+
s.isActive = cfg.isActive = true;
|
|
604
|
+
s.startTime = cfg.startTime;
|
|
605
|
+
s.endTime = cfg.endTime;
|
|
606
|
+
s.circuit = cfg.circuit;
|
|
607
|
+
s.scheduleType = cfg.scheduleType;
|
|
608
|
+
s.scheduleDays = cfg.scheduleType === 128 ? cfg.scheduleDays : 0;
|
|
609
|
+
s.heatSetpoint = cfg.heatSetpoint;
|
|
610
|
+
s.coolSetpoint = cfg.coolSetpoint;
|
|
611
|
+
s.heatSource = cfg.heatSource;
|
|
612
|
+
s.startDate = cfg.startDate;
|
|
613
|
+
s.startTimeType = cfg.startTimeType;
|
|
614
|
+
s.endTimeType = cfg.endTimeType;
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
s.isActive = cfg.isActive = false;
|
|
618
|
+
sys.schedules.removeItemById(cfg.id);
|
|
619
|
+
state.schedules.removeItemById(cfg.id);
|
|
620
|
+
s.emitEquipmentChange();
|
|
621
|
+
}
|
|
622
|
+
state.emitEquipmentChanges();
|
|
623
|
+
msg.isProcessed = true;
|
|
624
|
+
}
|
|
625
|
+
private static processChlorinator(msg: Inbound) {
|
|
626
|
+
let isActive = msg.extractPayloadByte(10) > 0;
|
|
627
|
+
let chlorId = msg.extractPayloadByte(2) + 1;
|
|
628
|
+
let cfg = sys.chlorinators.getItemById(chlorId, isActive);
|
|
629
|
+
let s = state.chlorinators.getItemById(chlorId, isActive);
|
|
630
|
+
if (!isActive) {
|
|
631
|
+
sys.chlorinators.removeItemById(chlorId);
|
|
632
|
+
state.chlorinators.removeItemById(chlorId);
|
|
633
|
+
s.emitEquipmentChange();
|
|
634
|
+
msg.isProcessed = true;
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
|
|
639
|
+
cfg.body = msg.extractPayloadByte(3);
|
|
640
|
+
cfg.poolSetpoint = msg.extractPayloadByte(5);
|
|
641
|
+
if (!cfg.disabled) {
|
|
642
|
+
// RKS: We don't want theses setpoints if our chem controller
|
|
643
|
+
// disabled the chlorinator.
|
|
644
|
+
cfg.spaSetpoint = msg.extractPayloadByte(6);
|
|
645
|
+
cfg.superChlor = msg.extractPayloadByte(7) > 0;
|
|
646
|
+
}
|
|
647
|
+
cfg.superChlorHours = msg.extractPayloadByte(8);
|
|
648
|
+
s.poolSetpoint = cfg.poolSetpoint;
|
|
649
|
+
s.spaSetpoint = cfg.spaSetpoint;
|
|
650
|
+
s.superChlorHours = cfg.superChlorHours;
|
|
651
|
+
s.body = cfg.body;
|
|
652
|
+
msg.isProcessed = true;
|
|
653
|
+
}
|
|
654
|
+
state.emitEquipmentChanges();
|
|
655
|
+
}
|
|
656
|
+
private static processPump(msg: Inbound) {
|
|
657
|
+
let pumpId = msg.extractPayloadByte(2) + 1;
|
|
658
|
+
const useBigEndian = sys.controllerType === ControllerType.IntelliCenter && sys.equipment.isIntellicenterV3;
|
|
659
|
+
const readInt = (ndx: number) => useBigEndian ? msg.extractPayloadIntBE(ndx) : msg.extractPayloadInt(ndx);
|
|
660
|
+
if (msg.extractPayloadByte(1) === 0) {
|
|
661
|
+
let type = msg.extractPayloadByte(3);
|
|
662
|
+
let cpump = sys.pumps.getItemById(pumpId, type > 0);
|
|
663
|
+
let spump = state.pumps.getItemById(pumpId, type > 0);
|
|
664
|
+
cpump.type = type;
|
|
665
|
+
spump.type = type;
|
|
666
|
+
if (cpump.type >= 2) {
|
|
667
|
+
cpump.address = msg.extractPayloadByte(5);
|
|
668
|
+
cpump.minSpeed = readInt(6);
|
|
669
|
+
cpump.maxSpeed = readInt(8);
|
|
670
|
+
cpump.minFlow = msg.extractPayloadByte(10);
|
|
671
|
+
cpump.maxFlow = msg.extractPayloadByte(11);
|
|
672
|
+
cpump.flowStepSize = msg.extractPayloadByte(12);
|
|
673
|
+
cpump.primingSpeed = readInt(13);
|
|
674
|
+
cpump.speedStepSize = msg.extractPayloadByte(15) * 10;
|
|
675
|
+
cpump.primingTime = msg.extractPayloadByte(16);
|
|
676
|
+
cpump.circuits.clear();
|
|
677
|
+
for (let i = 18; i < msg.payload.length && i <= 25; i++) {
|
|
678
|
+
let circuitId = msg.extractPayloadByte(i);
|
|
679
|
+
if (circuitId !== 255) {
|
|
680
|
+
let circuit = cpump.circuits.getItemById(i - 17, true);
|
|
681
|
+
circuit.circuit = circuitId + 1;
|
|
682
|
+
circuit.units = msg.extractPayloadByte(i + 8);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
else if (cpump.type === 1) {
|
|
687
|
+
cpump.circuits.clear();
|
|
688
|
+
cpump.circuits.add({ id: 1, body: msg.extractPayloadByte(18) });
|
|
689
|
+
}
|
|
690
|
+
if (cpump.type === 0) {
|
|
691
|
+
sys.pumps.removeItemById(cpump.id);
|
|
692
|
+
state.pumps.removeItemById(cpump.id);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
else if (msg.extractPayloadByte(1) === 1) {
|
|
696
|
+
let cpump = sys.pumps.getItemById(pumpId);
|
|
697
|
+
let spump = state.pumps.getItemById(pumpId);
|
|
698
|
+
cpump.name = msg.extractPayloadString(19, 16);
|
|
699
|
+
spump.name = cpump.name;
|
|
700
|
+
if (cpump.type > 2) {
|
|
701
|
+
for (let i = 3, circuitId = 1; i < msg.payload.length && i <= 18; circuitId++) {
|
|
702
|
+
let circuit = cpump.circuits.getItemById(circuitId);
|
|
703
|
+
let sp = readInt(i);
|
|
704
|
+
if (sp < 450)
|
|
705
|
+
circuit.flow = sp;
|
|
706
|
+
else
|
|
707
|
+
circuit.speed = sp;
|
|
708
|
+
i += 2;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
spump.emitData('pumpExt', spump.getExtended()); // Do this so clients can delete them.
|
|
712
|
+
}
|
|
713
|
+
msg.isProcessed = true;
|
|
714
|
+
}
|
|
715
|
+
private static processFeature(msg: Inbound) {
|
|
716
|
+
let featureId = msg.extractPayloadByte(2) + sys.board.equipmentIds.features.start;
|
|
717
|
+
let type = msg.extractPayloadByte(3);
|
|
718
|
+
let feature = sys.features.getItemById(featureId, type !== 255);
|
|
719
|
+
let fstate = state.features.getItemById(featureId, type !== 255);
|
|
720
|
+
if (type === 255) {
|
|
721
|
+
feature.isActive = false;
|
|
722
|
+
sys.features.removeItemById(featureId);
|
|
723
|
+
state.features.removeItemById(featureId);
|
|
724
|
+
}
|
|
725
|
+
else {
|
|
726
|
+
feature.freeze = msg.extractPayloadByte(4) > 0;
|
|
727
|
+
feature.dontStop = msg.extractPayloadByte(8) > 0;
|
|
728
|
+
fstate.name = feature.name = msg.extractPayloadString(9, 16);
|
|
729
|
+
fstate.type = feature.type = type;
|
|
730
|
+
feature.eggTimer = (msg.extractPayloadByte(6) * 60) + msg.extractPayloadByte(7);
|
|
731
|
+
fstate.showInFeatures = feature.showInFeatures = msg.extractPayloadByte(5) > 0;
|
|
732
|
+
}
|
|
733
|
+
state.emitEquipmentChanges();
|
|
734
|
+
msg.isProcessed = true;
|
|
735
|
+
}
|
|
736
|
+
private static processCircuit(msg: Inbound) {
|
|
737
|
+
let circuitId = msg.extractPayloadByte(2) + 1;
|
|
738
|
+
let circuit = sys.circuits.getItemById(circuitId, false);
|
|
739
|
+
let cstate = state.circuits.getItemById(circuitId, false);
|
|
740
|
+
circuit.showInFeatures = msg.extractPayloadByte(5) > 0;
|
|
741
|
+
circuit.freeze = msg.extractPayloadByte(4) > 0;
|
|
742
|
+
circuit.name = msg.extractPayloadString(10, 16);
|
|
743
|
+
circuit.type = msg.extractPayloadByte(3);
|
|
744
|
+
circuit.eggTimer = (msg.extractPayloadByte(7) * 60) + msg.extractPayloadByte(8);
|
|
745
|
+
circuit.showInFeatures = msg.extractPayloadByte(5) > 0;
|
|
746
|
+
cstate.type = circuit.type;
|
|
747
|
+
cstate.showInFeatures = circuit.showInFeatures;
|
|
748
|
+
cstate.name = circuit.name;
|
|
749
|
+
switch (circuit.type) {
|
|
750
|
+
case 5:
|
|
751
|
+
case 6:
|
|
752
|
+
case 8:
|
|
753
|
+
circuit.lightingTheme = msg.extractPayloadByte(6);
|
|
754
|
+
cstate.lightingTheme = circuit.lightingTheme;
|
|
755
|
+
break;
|
|
756
|
+
case 9:
|
|
757
|
+
circuit.level = msg.extractPayloadByte(6);
|
|
758
|
+
cstate.level = circuit.level;
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
761
|
+
state.emitEquipmentChanges();
|
|
762
|
+
msg.isProcessed = true;
|
|
763
|
+
}
|
|
764
|
+
private static processTempSettings(msg: Inbound) {
|
|
765
|
+
let fnTranslateByte = (byte: number) => { return (byte & 0x007F) * (((byte & 0x0080) > 0) ? -1 : 1); }
|
|
766
|
+
const decodeFreezeOverride = (raw: number) => raw <= 3 ? (30 + (raw * 60)) : raw;
|
|
767
|
+
|
|
768
|
+
// v3.004+: Wireless sends the FULL options block, not a single-field notification.
|
|
769
|
+
// v1.x: Used byte[2] as a pivot/index indicating which field changed, then byte[byte[2]+3] = new value.
|
|
770
|
+
//
|
|
771
|
+
// IMPORTANT: v3 Action 168 from Wireless has DIFFERENT offsets than Action 30 type 0!
|
|
772
|
+
// - Action 30 type 0: poolHeatNdx=19, spaHeatNdx=21, poolModeNdx=23, spaModeNdx=24
|
|
773
|
+
// - Action 168 Wireless: poolHeatNdx=20, spaHeatNdx=22, poolModeNdx=24, spaModeNdx=25
|
|
774
|
+
// The Wireless payload has an extra byte at position 4, shifting everything by +1.
|
|
775
|
+
const isIntellicenterV3 = (sys.controllerType === ControllerType.IntelliCenter && sys.equipment.isIntellicenterV3);
|
|
776
|
+
|
|
777
|
+
// Detect v3 full-block format by payload length (v3 sends 41 bytes for msgType 0)
|
|
778
|
+
if (isIntellicenterV3 && msg.payload.length >= 27) {
|
|
779
|
+
// v3.004+ Wireless full options block - different offsets than Action 30.
|
|
780
|
+
// Most captures use offsets [20..25], but some packets include an extra
|
|
781
|
+
// timestamp-like byte before setpoints, shifting to [21..26].
|
|
782
|
+
const buildCandidate = (shift: number) => ({
|
|
783
|
+
shift,
|
|
784
|
+
poolHeat: msg.extractPayloadByte(20 + shift),
|
|
785
|
+
poolCool: msg.extractPayloadByte(21 + shift),
|
|
786
|
+
spaHeat: msg.extractPayloadByte(22 + shift),
|
|
787
|
+
spaCool: msg.extractPayloadByte(23 + shift),
|
|
788
|
+
poolMode: msg.extractPayloadByte(24 + shift),
|
|
789
|
+
spaMode: msg.extractPayloadByte(25 + shift),
|
|
790
|
+
freezeCycleTime: msg.extractPayloadByte(26 + shift, 255),
|
|
791
|
+
freezeOverrideRaw: msg.extractPayloadByte(27 + shift, 255),
|
|
792
|
+
manualPriority: msg.extractPayloadByte(28 + shift, 255)
|
|
793
|
+
});
|
|
794
|
+
const scoreCandidate = (c: { poolHeat: number, poolCool: number, spaHeat: number, spaCool: number, poolMode: number, spaMode: number }) => {
|
|
795
|
+
let score = 0;
|
|
796
|
+
const isTemp = (v: number) => v > 0 && v <= 120;
|
|
797
|
+
const isMode = (v: number) => v > 0 && v <= 100;
|
|
798
|
+
if (isTemp(c.poolHeat)) score += 3;
|
|
799
|
+
if (isTemp(c.spaHeat)) score += 3;
|
|
800
|
+
if (isTemp(c.poolCool)) score += 2;
|
|
801
|
+
if (isTemp(c.spaCool)) score += 2;
|
|
802
|
+
if (isMode(c.poolMode)) score += 1;
|
|
803
|
+
if (isMode(c.spaMode)) score += 1;
|
|
804
|
+
return score;
|
|
805
|
+
};
|
|
806
|
+
let selected = buildCandidate(0);
|
|
807
|
+
if (msg.payload.length >= 27) {
|
|
808
|
+
const shifted = buildCandidate(1);
|
|
809
|
+
if (scoreCandidate(shifted) > scoreCandidate(selected)) selected = shifted;
|
|
810
|
+
}
|
|
811
|
+
if (selected.shift !== 0) {
|
|
812
|
+
logger.silly(`v3.004+ Action 168: using shifted temp offsets (+${selected.shift})`);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// Update Body 1 (Pool)
|
|
816
|
+
let body = sys.bodies.getItemById(1, sys.equipment.maxBodies > 0);
|
|
817
|
+
let sbody = state.temps.bodies.getItemById(1);
|
|
818
|
+
if (body.isActive) {
|
|
819
|
+
const newPoolHeat = selected.poolHeat;
|
|
820
|
+
const newPoolCool = selected.poolCool;
|
|
821
|
+
const newPoolMode = selected.poolMode;
|
|
822
|
+
logger.silly(`v3.004+ Action 168: Pool setpoint ${body.heatSetpoint} → ${newPoolHeat}, coolSetpoint ${body.coolSetpoint} → ${newPoolCool}, mode ${body.heatMode} → ${newPoolMode}`);
|
|
823
|
+
body.heatSetpoint = newPoolHeat;
|
|
824
|
+
body.coolSetpoint = newPoolCool;
|
|
825
|
+
body.heatMode = newPoolMode;
|
|
826
|
+
sbody.heatSetpoint = body.heatSetpoint;
|
|
827
|
+
sbody.coolSetpoint = body.coolSetpoint;
|
|
828
|
+
sbody.heatMode = body.heatMode;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// Update Body 2 (Spa)
|
|
832
|
+
body = sys.bodies.getItemById(2, sys.equipment.maxBodies > 1);
|
|
833
|
+
sbody = state.temps.bodies.getItemById(2);
|
|
834
|
+
if (body.isActive) {
|
|
835
|
+
const newSpaHeat = selected.spaHeat;
|
|
836
|
+
const newSpaCool = selected.spaCool;
|
|
837
|
+
const newSpaMode = selected.spaMode;
|
|
838
|
+
logger.silly(`v3.004+ Action 168: Spa setpoint ${body.heatSetpoint} → ${newSpaHeat}, coolSetpoint ${body.coolSetpoint} → ${newSpaCool}, mode ${body.heatMode} → ${newSpaMode}`);
|
|
839
|
+
body.heatSetpoint = newSpaHeat;
|
|
840
|
+
body.coolSetpoint = newSpaCool;
|
|
841
|
+
body.heatMode = newSpaMode;
|
|
842
|
+
sbody.heatSetpoint = body.heatSetpoint;
|
|
843
|
+
sbody.coolSetpoint = body.coolSetpoint;
|
|
844
|
+
sbody.heatMode = body.heatMode;
|
|
845
|
+
}
|
|
846
|
+
if (selected.freezeCycleTime !== 255) sys.general.options.freezeCycleTime = selected.freezeCycleTime;
|
|
847
|
+
if (selected.freezeOverrideRaw !== 255) sys.general.options.freezeOverride = decodeFreezeOverride(selected.freezeOverrideRaw);
|
|
848
|
+
if (selected.manualPriority !== 255) sys.general.options.manualPriority = selected.manualPriority > 0;
|
|
849
|
+
|
|
850
|
+
state.emitEquipmentChanges();
|
|
851
|
+
msg.isProcessed = true;
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// v1.x: Single-field-changed notification using byte[2] as pivot index.
|
|
856
|
+
// payLoadIndex = byte(2) + 3 where the first 3 bytes indicate what value changed.
|
|
857
|
+
let body: Body = null;
|
|
858
|
+
switch (msg.extractPayloadByte(2)) {
|
|
859
|
+
case 0: // Water Sensor 2 Adj
|
|
860
|
+
sys.equipment.tempSensors.setCalibration('water2', fnTranslateByte(msg.extractPayloadByte(3)));
|
|
861
|
+
msg.isProcessed = true;
|
|
862
|
+
break;
|
|
863
|
+
case 1: // Water Sensor 1 Adj
|
|
864
|
+
sys.equipment.tempSensors.setCalibration('water1', fnTranslateByte(msg.extractPayloadByte(4)));
|
|
865
|
+
msg.isProcessed = true;
|
|
866
|
+
break;
|
|
867
|
+
case 2: // Solar Sensor 1 Adj
|
|
868
|
+
sys.equipment.tempSensors.setCalibration('solar1', fnTranslateByte(msg.extractPayloadByte(5)));
|
|
869
|
+
msg.isProcessed = true;
|
|
870
|
+
break;
|
|
871
|
+
case 3: // Air Sensor Adj
|
|
872
|
+
sys.equipment.tempSensors.setCalibration('air', fnTranslateByte(msg.extractPayloadByte(6)));
|
|
873
|
+
msg.isProcessed = true;
|
|
874
|
+
break;
|
|
875
|
+
case 4: // Water Sensor 2 Adj
|
|
876
|
+
sys.equipment.tempSensors.setCalibration('water2', fnTranslateByte(msg.extractPayloadByte(7)));
|
|
877
|
+
msg.isProcessed = true;
|
|
878
|
+
break;
|
|
879
|
+
case 5: // Solar Sensor 2 Adj
|
|
880
|
+
sys.equipment.tempSensors.setCalibration('solar2', fnTranslateByte(msg.extractPayloadByte(8)));
|
|
881
|
+
msg.isProcessed = true;
|
|
882
|
+
break;
|
|
883
|
+
case 6: // Water Sensor 3 Adj
|
|
884
|
+
sys.equipment.tempSensors.setCalibration('water3', fnTranslateByte(msg.extractPayloadByte(9)));
|
|
885
|
+
msg.isProcessed = true;
|
|
886
|
+
break;
|
|
887
|
+
case 7: // Solar Sensor 3 Adj
|
|
888
|
+
sys.equipment.tempSensors.setCalibration('solar3', fnTranslateByte(msg.extractPayloadByte(10)));
|
|
889
|
+
msg.isProcessed = true;
|
|
890
|
+
break;
|
|
891
|
+
case 8: // Water Sensor 4 Adj
|
|
892
|
+
sys.equipment.tempSensors.setCalibration('water4', fnTranslateByte(msg.extractPayloadByte(11)));
|
|
893
|
+
msg.isProcessed = true;
|
|
894
|
+
break;
|
|
895
|
+
case 9: // Solar Sensor 4 Adj
|
|
896
|
+
sys.equipment.tempSensors.setCalibration('water4', fnTranslateByte(msg.extractPayloadByte(12)));
|
|
897
|
+
msg.isProcessed = true;
|
|
898
|
+
break;
|
|
899
|
+
case 11: // Clock mode
|
|
900
|
+
sys.general.options.clockMode = (msg.extractPayloadByte(14) & 0x0001) == 1 ? 24 : 12;
|
|
901
|
+
msg.isProcessed = true;
|
|
902
|
+
break;
|
|
903
|
+
case 12: // This is byte 15 but we don't know what it is. Numbers witnessed include 51, 52, 89, 235.
|
|
904
|
+
break;
|
|
905
|
+
case 14: // Clock source
|
|
906
|
+
if ((msg.extractPayloadByte(17) & 0x0040) === 1)
|
|
907
|
+
sys.general.options.clockSource = 'internet';
|
|
908
|
+
else if (sys.general.options.clockSource !== 'server')
|
|
909
|
+
sys.general.options.clockSource = 'manual';
|
|
910
|
+
msg.isProcessed = true;
|
|
911
|
+
break;
|
|
912
|
+
case 15: // This is byte 18 but we don't know what it is. Numbers witnessed include 1, 2, 3, 5, 100.
|
|
913
|
+
break;
|
|
914
|
+
case 18: // Body 1 Heat Setpoint
|
|
915
|
+
body = sys.bodies.getItemById(1, false);
|
|
916
|
+
body.heatSetpoint = msg.extractPayloadByte(21);
|
|
917
|
+
state.temps.bodies.getItemById(1).heatSetpoint = body.heatSetpoint;
|
|
918
|
+
state.emitEquipmentChanges();
|
|
919
|
+
msg.isProcessed = true;
|
|
920
|
+
break;
|
|
921
|
+
case 19: // Body 1 Cool Setpoint
|
|
922
|
+
body = sys.bodies.getItemById(1, false);
|
|
923
|
+
body.coolSetpoint = msg.extractPayloadByte(22);
|
|
924
|
+
state.temps.bodies.getItemById(1).coolSetpoint = body.coolSetpoint;
|
|
925
|
+
state.emitEquipmentChanges();
|
|
926
|
+
msg.isProcessed = true;
|
|
927
|
+
break;
|
|
928
|
+
case 20: // Body 2 Heat Setpoint
|
|
929
|
+
body = sys.bodies.getItemById(2, false);
|
|
930
|
+
body.heatSetpoint = msg.extractPayloadByte(23);
|
|
931
|
+
state.temps.bodies.getItemById(2).heatSetpoint = body.heatSetpoint;
|
|
932
|
+
state.emitEquipmentChanges();
|
|
933
|
+
msg.isProcessed = true;
|
|
934
|
+
break;
|
|
935
|
+
case 21: // Body 2 Cool Setpoint
|
|
936
|
+
body = sys.bodies.getItemById(2, false);
|
|
937
|
+
body.coolSetpoint = msg.extractPayloadByte(24);
|
|
938
|
+
state.temps.bodies.getItemById(2).coolSetpoint = body.coolSetpoint;
|
|
939
|
+
state.emitEquipmentChanges();
|
|
940
|
+
msg.isProcessed = true;
|
|
941
|
+
break;
|
|
942
|
+
case 22: // Body 1 Heat Mode
|
|
943
|
+
body = sys.bodies.getItemById(1, false);
|
|
944
|
+
body.heatMode = msg.extractPayloadByte(25);
|
|
945
|
+
state.temps.bodies.getItemById(1).heatMode = body.heatMode;
|
|
946
|
+
state.emitEquipmentChanges();
|
|
947
|
+
msg.isProcessed = true;
|
|
948
|
+
break;
|
|
949
|
+
case 23: // Body 2 Heat Mode
|
|
950
|
+
body = sys.bodies.getItemById(2, false);
|
|
951
|
+
body.heatMode = msg.extractPayloadByte(26);
|
|
952
|
+
state.temps.bodies.getItemById(2).heatMode = body.heatMode;
|
|
953
|
+
state.emitEquipmentChanges();
|
|
954
|
+
msg.isProcessed = true;
|
|
955
|
+
break;
|
|
956
|
+
case 24: // Body 3 Heat Mode
|
|
957
|
+
body = sys.bodies.getItemById(3, false);
|
|
958
|
+
body.heatMode = msg.extractPayloadByte(27);
|
|
959
|
+
state.temps.bodies.getItemById(3).heatMode = body.heatMode;
|
|
960
|
+
state.emitEquipmentChanges();
|
|
961
|
+
msg.isProcessed = true;
|
|
962
|
+
break;
|
|
963
|
+
case 25: // Body 4 Heat Mode
|
|
964
|
+
body = sys.bodies.getItemById(4, false);
|
|
965
|
+
body.heatMode = msg.extractPayloadByte(28);
|
|
966
|
+
state.temps.bodies.getItemById(4).heatMode = body.heatMode;
|
|
967
|
+
state.emitEquipmentChanges();
|
|
968
|
+
msg.isProcessed = true;
|
|
969
|
+
break;
|
|
970
|
+
case 27: // Pump Valve Delay
|
|
971
|
+
sys.general.options.pumpDelay = msg.extractPayloadByte(30) !== 0;
|
|
972
|
+
msg.isProcessed = true;
|
|
973
|
+
break;
|
|
974
|
+
case 28: // Cooldown Delay
|
|
975
|
+
sys.general.options.cooldownDelay = msg.extractPayloadByte(31) !== 0;
|
|
976
|
+
msg.isProcessed = true;
|
|
977
|
+
break;
|
|
978
|
+
case 36: // Manual Priority
|
|
979
|
+
sys.general.options.manualPriority = msg.extractPayloadByte(39) !== 0;
|
|
980
|
+
msg.isProcessed = true;
|
|
981
|
+
break;
|
|
982
|
+
case 37: // Manual Heat
|
|
983
|
+
sys.general.options.manualHeat = msg.extractPayloadByte(40) !== 0;
|
|
984
|
+
msg.isProcessed = true;
|
|
985
|
+
break;
|
|
986
|
+
case 64: // Vacation mode
|
|
987
|
+
let yy = msg.extractPayloadByte(5) + 2000;
|
|
988
|
+
let mm = msg.extractPayloadByte(6);
|
|
989
|
+
let dd = msg.extractPayloadByte(7);
|
|
990
|
+
sys.general.options.vacation.startDate = new Date(yy, mm - 1, dd);
|
|
991
|
+
yy = msg.extractPayloadByte(8) + 2000;
|
|
992
|
+
mm = msg.extractPayloadByte(9);
|
|
993
|
+
dd = msg.extractPayloadByte(10);
|
|
994
|
+
sys.general.options.vacation.endDate = new Date(yy, mm - 1, dd);
|
|
995
|
+
sys.general.options.vacation.enabled = msg.extractPayloadByte(3) > 0;
|
|
996
|
+
sys.general.options.vacation.useTimeframe = msg.extractPayloadByte(4) > 0;
|
|
997
|
+
msg.isProcessed = true;
|
|
998
|
+
break;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
public static processTouchChlorinator(msg: Inbound) {
|
|
1002
|
+
let isActive = (msg.extractPayloadByte(0) & 0x01) === 1;
|
|
1003
|
+
let chlor = sys.chlorinators.getItemById(1, isActive);
|
|
1004
|
+
let schlor = state.chlorinators.getItemById(1, isActive);
|
|
1005
|
+
chlor.isActive = schlor.isActive = isActive;
|
|
1006
|
+
if (isActive) {
|
|
1007
|
+
if (!chlor.disabled) {
|
|
1008
|
+
// RKS: We don't want these setpoints if our chem controller disabled the
|
|
1009
|
+
// chlorinator. These should be 0 anyway.
|
|
1010
|
+
schlor.poolSetpoint = chlor.spaSetpoint = msg.extractPayloadByte(0) >> 1;
|
|
1011
|
+
schlor.spaSetpoint = chlor.poolSetpoint = msg.extractPayloadByte(1);
|
|
1012
|
+
if (typeof chlor.address === 'undefined') chlor.address = 80; // chlor.id + 79;
|
|
1013
|
+
schlor.body = chlor.body = sys.equipment.maxBodies >= 1 || sys.equipment.shared === true ? 32 : 0;
|
|
1014
|
+
}
|
|
1015
|
+
schlor.superChlor = chlor.superChlor = msg.extractPayloadByte(2) - 128 > 0;
|
|
1016
|
+
if (schlor.superChlor) {
|
|
1017
|
+
schlor.superChlorRemaining = (msg.extractPayloadByte(2) - 128) * 3600;
|
|
1018
|
+
}
|
|
1019
|
+
else {
|
|
1020
|
+
schlor.superChlorRemaining = 0;
|
|
1021
|
+
}
|
|
1022
|
+
if (state.temps.bodies.getItemById(1).isOn) schlor.targetOutput = chlor.disabled ? 0 : chlor.poolSetpoint;
|
|
1023
|
+
else if (state.temps.bodies.getItemById(2).isOn) schlor.targetOutput = chlor.disabled ? 0 : chlor.spaSetpoint;
|
|
1024
|
+
}
|
|
1025
|
+
else {
|
|
1026
|
+
sys.chlorinators.removeItemById(1);
|
|
1027
|
+
state.chlorinators.removeItemById(1);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
public static processTouchSetHeatMode(msg: Inbound) {
|
|
1031
|
+
// We get here because some other controller is setting the heat
|
|
1032
|
+
// mode. The OCP will emit an 8 later but it can be very slow
|
|
1033
|
+
// in doing this. ScreenLogic also captures this message so it
|
|
1034
|
+
// doesn't get behind.
|
|
1035
|
+
//[165, 1, 16, 34, 136, 4][86, 100, 3, 0][2, 33]
|
|
1036
|
+
//payload: [temp1, temp2, mode2 << 2 | mode1, setPoint],
|
|
1037
|
+
let bstate1 = state.temps.bodies.getItemById(1);
|
|
1038
|
+
let bstate2 = state.temps.bodies.getItemById(2);
|
|
1039
|
+
let body1 = sys.bodies.getItemById(1);
|
|
1040
|
+
let body2 = sys.bodies.getItemById(2);
|
|
1041
|
+
let mode1 = msg.extractPayloadByte(2) & 0x03;
|
|
1042
|
+
let mode2 = (msg.extractPayloadByte(2) & 0x0C) >> 2;
|
|
1043
|
+
bstate1.setPoint = body1.heatSetpoint = msg.extractPayloadByte(0);
|
|
1044
|
+
bstate1.coolSetpoint = body1.coolSetpoint = msg.extractPayloadByte(3);
|
|
1045
|
+
bstate2.setPoint = body2.heatSetpoint = msg.extractPayloadByte(1);
|
|
1046
|
+
bstate1.heatMode = body1.heatMode = mode1;
|
|
1047
|
+
bstate2.heatMode = body2.heatMode = mode2;
|
|
1048
|
+
msg.isProcessed = true;
|
|
1049
|
+
state.emitEquipmentChanges();
|
|
1050
|
+
|
|
1051
|
+
}
|
|
990
1052
|
}
|