-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathCapabilities.cpp
327 lines (314 loc) · 10.6 KB
/
Capabilities.cpp
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
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
#include "Appliance/AirConditioner/Capabilities.h"
#include "Frame/FrameData.h"
#include "Helpers/Log.h"
namespace dudanov {
namespace midea {
namespace ac {
static const char *TAG = "Capabilities";
enum CapabilityID : uint16_t {
CAPABILITY_INDOOR_HUMIDITY = 0x0015,
CAPABILITY_SILKY_COOL = 0x0018,
CAPABILITY_SMART_EYE = 0x0030,
CAPABILITY_WIND_ON_ME = 0x0032,
CAPABILITY_WIND_OF_ME = 0x0033,
CAPABILITY_ACTIVE_CLEAN = 0x0039,
CAPABILITY_ONE_KEY_NO_WIND_ON_ME = 0x0042,
CAPABILITY_BREEZE_CONTROL = 0x0043,
CAPABILITY_FAN_SPEED_CONTROL = 0x0210,
CAPABILITY_PRESET_ECO = 0x0212,
CAPABILITY_PRESET_FREEZE_PROTECTION = 0x0213,
CAPABILITY_MODES = 0x0214,
CAPABILITY_SWING_MODES = 0x0215,
CAPABILITY_POWER = 0x0216,
CAPABILITY_NEST = 0x0217,
CAPABILITY_AUX_ELECTRIC_HEATING = 0x0219,
CAPABILITY_PRESET_TURBO = 0x021A,
CAPABILITY_HUMIDITY = 0x021F,
CAPABILITY_UNIT_CHANGEABLE = 0x0222,
CAPABILITY_LIGHT_CONTROL = 0x0224,
CAPABILITY_TEMPERATURES = 0x0225,
CAPABILITY_BUZZER = 0x022C,
};
static uint16_t read_u16(const uint8_t *data) { return (data[1] << 8) | data[0]; }
class CapabilityData {
public:
CapabilityData(const FrameData &data) :
m_it(data.data() + 2),
m_end(data.data() + data.size() - 1),
m_num(*(data.data() + 1)) {}
// Get capability ID
CapabilityID id() const { return static_cast<CapabilityID>(read_u16(this->m_it)); }
// Read-only indexed access to capability data
const uint8_t &operator[](uint8_t idx) const { return *(this->m_it + idx + 3); }
// Get size of capability data
uint8_t size() const { return this->m_it[2]; }
//
bool isValid() const { return m_num && this->m_available() >= 3; }
// One more request needed
bool isNeedMore() const { return this->m_available() == 2 && *this->m_it != 0; }
// Advance to next capability
void advance() {
this->m_it += this->size() + 3;
--this->m_num;
}
private:
uint8_t m_available() const { return std::distance(this->m_it, this->m_end); }
// Iterator
const uint8_t *m_it;
// End of data
const uint8_t *const m_end;
// Number of capabilities in answer
uint8_t m_num;
};
bool Capabilities::read(const FrameData &frame) {
if (frame.size() < 14)
return false;
CapabilityData cap(frame);
for (; cap.isValid(); cap.advance()) {
if (!cap.size())
continue;
const uint8_t uval = cap[0];
const bool bval = uval;
switch (cap.id()) {
case CAPABILITY_INDOOR_HUMIDITY:
this->m_indoorHumidity = bval;
break;
case CAPABILITY_SILKY_COOL:
this->m_silkyCool = bval;
break;
case CAPABILITY_SMART_EYE:
this->m_smartEye = uval == 1;
break;
case CAPABILITY_WIND_ON_ME:
this->m_windOnMe = uval == 1;
break;
case CAPABILITY_WIND_OF_ME:
this->m_windOfMe = uval == 1;
break;
case CAPABILITY_ACTIVE_CLEAN:
this->m_activeClean = uval == 1;
break;
case CAPABILITY_ONE_KEY_NO_WIND_ON_ME:
this->m_oneKeyNoWindOnMe = uval == 1;
break;
case CAPABILITY_BREEZE_CONTROL:
this->m_breezeControl = uval == 1;
break;
case CAPABILITY_FAN_SPEED_CONTROL:
this->m_fanSpeedControl = uval != 1;
break;
case CAPABILITY_PRESET_ECO:
this->m_ecoMode = uval == 1;
this->m_specialEco = uval == 2;
break;
case CAPABILITY_PRESET_FREEZE_PROTECTION:
this->m_frostProtectionMode = uval == 1;
break;
case CAPABILITY_MODES:
switch (uval) {
case 0:
this->m_heatMode = false;
this->m_coolMode = true;
this->m_dryMode = true;
this->m_autoMode = true;
break;
case 1:
this->m_coolMode = true;
this->m_heatMode= true;
this->m_dryMode = true;
this->m_autoMode = true;
break;
case 2:
this->m_coolMode = false;
this->m_dryMode = false;
this->m_heatMode = true;
this->m_autoMode = true;
break;
case 3:
this->m_coolMode = true;
this->m_dryMode = false;
this->m_heatMode = false;
this->m_autoMode = false;
break;
}
break;
case CAPABILITY_SWING_MODES:
switch (uval) {
case 0:
this->m_leftrightFan = false;
this->m_updownFan = true;
break;
case 1:
this->m_leftrightFan = true;
this->m_updownFan = true;
break;
case 2:
this->m_leftrightFan = false;
this->m_updownFan = false;
break;
case 3:
this->m_leftrightFan = true;
this->m_updownFan = false;
break;
}
break;
case CAPABILITY_POWER:
switch (uval) {
case 0:
case 1:
this->m_powerCal = false;
this->m_powerCalSetting = false;
break;
case 2:
this->m_powerCal = true;
this->m_powerCalSetting = false;
break;
case 3:
this->m_powerCal = true;
this->m_powerCalSetting = true;
break;
}
break;
case CAPABILITY_NEST:
switch (uval) {
case 0:
this->m_nestCheck = false;
this->m_nestNeedChange = false;
break;
case 1:
case 2:
this->m_nestCheck = true;
this->m_nestNeedChange = false;
break;
case 3:
this->m_nestCheck = false;
this->m_nestNeedChange = true;
break;
case 4:
this->m_nestCheck = true;
this->m_nestNeedChange = true;
break;
}
break;
case CAPABILITY_AUX_ELECTRIC_HEATING:
this->m_electricAuxHeating = bval;
break;
case CAPABILITY_PRESET_TURBO:
switch (uval) {
case 0:
this->m_turboHeat = false;
this->m_turboCool = true;
break;
case 1:
this->m_turboHeat = true;
this->m_turboCool = true;
break;
case 2:
this->m_turboHeat = false;
this->m_turboCool = false;
break;
case 3:
this->m_turboHeat = true;
this->m_turboCool = false;
break;
}
break;
case CAPABILITY_HUMIDITY:
switch (uval) {
case 0:
this->m_autoSetHumidity = false;
this->m_manualSetHumidity = false;
break;
case 1:
this->m_autoSetHumidity = true;
this->m_manualSetHumidity = false;
break;
case 2:
this->m_autoSetHumidity = true;
this->m_manualSetHumidity = true;
break;
case 3:
this->m_autoSetHumidity = false;
this->m_manualSetHumidity = true;
break;
}
break;
case CAPABILITY_UNIT_CHANGEABLE:
this->m_unitChangeable = !bval;
break;
case CAPABILITY_LIGHT_CONTROL:
this->m_lightControl = bval;
break;
case CAPABILITY_TEMPERATURES:
if (cap.size() >= 6) {
this->m_minTempCool = static_cast<float>(uval) * 0.5f;
this->m_maxTempCool = static_cast<float>(cap[1]) * 0.5f;
this->m_minTempAuto = static_cast<float>(cap[2]) * 0.5f;
this->m_maxTempAuto = static_cast<float>(cap[3]) * 0.5f;
this->m_minTempHeat = static_cast<float>(cap[4]) * 0.5f;
this->m_maxTempHeat = static_cast<float>(cap[5]) * 0.5f;
this->m_decimals = (cap.size() > 6) ? cap[6] : cap[2];
}
break;
case CAPABILITY_BUZZER:
this->m_buzzer = bval;
break;
}
}
// Как минимум указывает на предпоследний элемент (минимум 2 непрочитанных байта)
if (cap.isNeedMore())
return true; // если предпоследний байт != 0, то нужно опрашивать дальше
return false;
}
#define LOG_CAPABILITY(str, condition) \
if (condition) \
LOG_CONFIG(TAG, str);
void Capabilities::dump() const {
LOG_CONFIG(TAG, "CAPABILITIES REPORT:");
if (this->m_autoMode) {
LOG_CONFIG(TAG, " [x] AUTO MODE");
LOG_CONFIG(TAG, " - MIN TEMP: %.1f", this->m_minTempAuto);
LOG_CONFIG(TAG, " - MAX TEMP: %.1f", this->m_maxTempAuto);
}
if (this->m_coolMode) {
LOG_CONFIG(TAG, " [x] COOL MODE");
LOG_CONFIG(TAG, " - MIN TEMP: %.1f", this->m_minTempCool);
LOG_CONFIG(TAG, " - MAX TEMP: %.1f", this->m_maxTempCool);
}
if (this->m_heatMode) {
LOG_CONFIG(TAG, " [x] HEAT MODE");
LOG_CONFIG(TAG, " - MIN TEMP: %.1f", this->m_minTempHeat);
LOG_CONFIG(TAG, " - MAX TEMP: %.1f", this->m_maxTempHeat);
}
LOG_CAPABILITY(" [x] DRY MODE", this->m_dryMode);
LOG_CAPABILITY(" [x] ECO MODE", this->m_ecoMode);
LOG_CAPABILITY(" [x] SPECIAL ECO", this->m_specialEco);
LOG_CAPABILITY(" [x] FROST PROTECTION MODE", this->m_frostProtectionMode);
LOG_CAPABILITY(" [x] TURBO COOL", this->m_turboCool);
LOG_CAPABILITY(" [x] TURBO HEAT", this->m_turboHeat);
LOG_CAPABILITY(" [x] FANSPEED CONTROL", this->m_fanSpeedControl);
LOG_CAPABILITY(" [x] BREEZE CONTROL", this->m_breezeControl);
LOG_CAPABILITY(" [x] LIGHT CONTROL", this->m_lightControl);
LOG_CAPABILITY(" [x] UPDOWN FAN", this->m_updownFan);
LOG_CAPABILITY(" [x] LEFTRIGHT FAN", this->m_leftrightFan);
LOG_CAPABILITY(" [x] AUTO SET HUMIDITY", this->m_autoSetHumidity);
LOG_CAPABILITY(" [x] MANUAL SET HUMIDITY", this->m_manualSetHumidity);
LOG_CAPABILITY(" [x] INDOOR HUMIDITY", this->m_indoorHumidity);
LOG_CAPABILITY(" [x] POWER CAL", this->m_powerCal);
LOG_CAPABILITY(" [x] POWER CAL SETTING", this->m_powerCalSetting);
LOG_CAPABILITY(" [x] BUZZER", this->m_buzzer);
LOG_CAPABILITY(" [x] ACTIVE CLEAN", this->m_activeClean);
LOG_CAPABILITY(" [x] DECIMALS", this->m_decimals);
LOG_CAPABILITY(" [x] ELECTRIC AUX HEATING", this->m_electricAuxHeating);
LOG_CAPABILITY(" [x] NEST CHECK", this->m_nestCheck);
LOG_CAPABILITY(" [x] NEST NEED CHANGE", this->m_nestNeedChange);
LOG_CAPABILITY(" [x] ONE KEY NO WIND ON ME", this->m_oneKeyNoWindOnMe);
LOG_CAPABILITY(" [x] SILKY COOL", this->m_silkyCool);
LOG_CAPABILITY(" [x] SMART EYE", this->m_smartEye);
LOG_CAPABILITY(" [x] UNIT CHANGEABLE", this->m_unitChangeable);
LOG_CAPABILITY(" [x] WIND OF ME", this->m_windOfMe);
LOG_CAPABILITY(" [x] WIND ON ME", this->m_windOnMe);
}
} // namespace ac
} // namespace midea
} // namespace dudanov