-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-state-data-sys-info.ts
259 lines (233 loc) · 6.66 KB
/
get-state-data-sys-info.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/**
* The {@link GetStateDataSysInfo} class is part of the {@link GetStateData}
* class, which is kind of an object representation of the `/GetState.csv`
* API endpoint response of the ProCon.IP pool controller.
* @packageDocumentation
*/
import { GetStateDataObject } from './get-state-data-object';
/**
* A class for an object representation of the first line of the `/GetState.csv`
* API endpoint response. This line has a special role and no relation to the
* subsequent lines of the CSV file.
*/
export class GetStateDataSysInfo {
/**
* Making {@link GetStateDataSysInfo} objects extensible, also allows accessing
* object keys using string variables.
*/
[key: string]: any; // eslint-disable-line no-undef
/**
*
*/
public time!: string;
/**
* Uptime of the ProCon.IP controller at the time this data was requested.
*/
public uptime!: number;
/**
* Current firmware version string.
*/
public version!: string;
/**
* Reset root cause.
*
* Values are documented bitwise as follows:
* - Bit 4: External reset
* - Bit 3: PowerUp reset
* - Bit 2: Brown out reset
* - Bit 1: Watchdog reset
* - Bit 0: SW reset
*
* See manual for more information or updates: http://www.pooldigital.de/trm/TRM_ProConIP.pdf
*/
public resetRootCause!: number;
/**
* NTP fault state.
*
* Values are documented bitwise as follows:
* - Bit 16: NTP available
* - Bit 15..3: reserved
* - Bit 2: Error
* - Bit 1: Warning
* - Bit 0: Logfile
*
* See manual for more information or updates: http://www.pooldigital.de/trm/TRM_ProConIP.pdf
*/
public ntpFaultState!: number;
/**
* Other config flags.
*
* Values are documented bitwise as follows:
* - Bit 8: Extension an SPI (`0`) oder DMX (`1`)
* - Bit 7: Repeated Mails
* - Bit 6: FlowSensor
* - Bit 5: High Bus Load
* - Bit 4: Relay Extension
* - Bit 3: Avatar
* - Bit 2: DMX
* - Bit 1: SD-Card
* - Bit 0: TCP-IP Boost
*
* See manual for more information or updates: http://www.pooldigital.de/trm/TRM_ProConIP.pdf
*/
public configOtherEnable!: number;
/**
* Dosage control information flags.
*
* Values are documented bitwise as follows:
* - Bit 12: pH+ enabled
* - Bit 11..9: reserved
* - Bit 8: pH- enabled
* - Bit 7..5: reserved
* - Bit 4: Cl liquid || Elektrolysis
* - Bit 3..1: reserved
* - Bit 0: CL enabled
*
* See manual for more information or updates: http://www.pooldigital.de/trm/TRM_ProConIP.pdf
*/
public dosageControl!: number;
/**
* pH+ dosage relay id.
*/
public phPlusDosageRelay!: number;
/**
* pH- dosage relay id.
*/
public phMinusDosageRelay!: number;
/**
* Chlorine dosage relay id.
*/
public chlorineDosageRelay!: number;
/**
* Initialize a new {@link GetStateDataSysInfo} object.
*
* @param data Parsed response CSV of the `/GetState.csv` endpoint as
* 2-dimensional array (see: {@link GetStateData.parsed})
*/
public constructor(data?: string[][]) {
if (data) {
this.setValuesFromArray(data);
}
}
/**
* Set values from based on a 2-dimensional array structure.
*
* @param data Parsed response CSV of the `/GetState.csv` endpoint as
* 2-dimensional array (see: {@link GetStateData.parsed})
*/
public setValuesFromArray(data: string[][]): void {
this.version = data[0][1];
this.uptime = Number(data[0][2]);
this.resetRootCause = Number(data[0][3]);
this.ntpFaultState = Number(data[0][4]);
this.configOtherEnable = Number(data[0][5]);
this.dosageControl = Number(data[0][6]);
this.phPlusDosageRelay = Number(data[0][7]);
this.phMinusDosageRelay = Number(data[0][8]);
this.chlorineDosageRelay = Number(data[0][9]);
}
/**
* Converts the object instance to a simple array of objects for better
* handling/iteration.
*/
public toArrayOfObjects(): { key: string; value: string }[] {
const values: { key: string; value: string }[] = [];
Object.keys(this).forEach((attr: string) => {
values.push({ key: attr, value: this[attr] });
});
return values;
}
/**
* Check whether the automated chlorine dosage is enabled.
*/
public isChlorineDosageEnabled(): boolean {
return (this.dosageControl & 1) === 1;
}
/**
* Checks if the chlorine dosage device is configured as an electrolysis cell or a pump.
*/
public isElectrolysis(): boolean {
return (this.dosageControl & 16) === 16;
}
/**
* Check whether the automated pH- dosage is enabled.
*/
public isPhMinusDosageEnabled(): boolean {
return (this.dosageControl & 256) === 256;
}
/**
* Check whether the automated pH+ dosage is enabled.
*/
public isPhPlusDosageEnabled(): boolean {
return (this.dosageControl & 4096) === 4096;
}
/**
* Check whether the given {@link GetStateDataObject} object is a dosage control
* relay.
*
* @param object The {@link GetStateDataObject} to check.
*/
public isDosageEnabled(object: GetStateDataObject): boolean {
switch (object.id) {
case 36:
case 39:
return this.isChlorineDosageEnabled();
case 37:
case 40:
return this.isPhMinusDosageEnabled();
case 38:
case 41:
return this.isPhPlusDosageEnabled();
default:
return false;
}
}
/**
* Returns the configured dosage relay for a given
* {@link GetStateDataObject} object.
*
* @param object The {@link GetStateDataObject} to check, should be a
* {@link GetStateData.categories | GetStateData.categories.canister} or a
* {@link GetStateData.categories | GetStateData.categories.canisterConsumptions} object.
*/
public getDosageRelay(object: GetStateDataObject): number {
switch (object.id) {
case 36:
case 39:
return this.chlorineDosageRelay;
case 37:
case 40:
return this.phMinusDosageRelay;
case 38:
case 41:
return this.phPlusDosageRelay;
default:
return 0;
}
}
/**
* Check whether generation of an avatar image is enabled or not.
*/
public isAvatarEnabled(): boolean {
return (this.configOtherEnable & 8) === 8;
}
/**
* Check whether external relays are enabled or not.
*/
public isExtRelaysEnabled(): boolean {
return (this.configOtherEnable & 16) === 16;
}
/**
* Check whether the digitial input 0 is configured as a flow sensor
* or not.
*/
public isFlowSensorEnabled(): boolean {
return (this.configOtherEnable & 64) === 64;
}
/**
* Check whether DMX is enabled or not.
*/
public isDmxEnabled(): boolean {
return (this.configOtherEnable & 256) === 256;
}
}