supla-device
Loading...
Searching...
No Matches
channel.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_CHANNELS_CHANNEL_H_
5#define SRC_SUPLA_CHANNELS_CHANNEL_H_
6
7#include <stdint.h>
8
9#include <supla-common/proto.h>
10#include <supla/local_action.h>
11#include "channel_types.h"
12
13namespace Supla {
14
15enum class HvacCoolSubfunctionFlag {
16 HeatSubfunctionOrNotUsed,
17 CoolSubfunction,
18};
19
20class Channel : public LocalAction {
21 public:
22 explicit Channel(int number = -1);
23 virtual ~Channel();
24 static void setStartingChannelNumber(int channelNumber);
25 static int getStartingChannelNumber();
26 static Channel *Begin();
27 static Channel *Last();
28 static Channel *GetByChannelNumber(int channelNumber);
29 Channel *next();
30
31#ifdef SUPLA_TEST
32 static void resetToDefaults();
33#endif
34 void fillDeviceChannelStruct(TDS_SuplaDeviceChannel_D *deviceChannelStruct);
35 void fillDeviceChannelStruct(TDS_SuplaDeviceChannel_E *deviceChannelStruct);
36
37 bool setChannelNumber(int newChannelNumber);
38
39 void setNewValue(double dbl);
40 void setNewValue(double temp, double humi);
41 void setNewValue(int32_t value);
42 void setNewValue(bool value);
43 void setNewValue(const TElectricityMeter_ExtendedValue_V3 &emValue);
44 void setNewValue(uint8_t red,
45 uint8_t green,
46 uint8_t blue,
47 uint8_t colorBrightness,
48 uint8_t whiteBrightness,
49 uint8_t whiteTemperature);
50 void setNewValue(uint64_t value);
51 void setNewValue(const TDSC_RollerShutterValue &value);
52 void setNewValue(const TDSC_FacadeBlindValue &value);
53 bool setNewValue(const char *newValue);
54
55 void setStateOffline();
56 void setStateOnline();
57 void setStateOnlineAndNotAvailable();
58 void setStateFirmwareUpdateOngoing();
59 void setStateOfflineRemoteWakeupNotSupported();
60 bool isStateOnline() const;
61 bool isStateOnlineAndNotAvailable() const;
62 bool isStateOfflineRemoteWakeupNotSupported() const;
63 bool isStateFirmwareUpdateOngoing() const;
64
65 // Sets container channel value. fillLevel should contain 0-100 value, any
66 // other value will be set to "unknown" value.
67 void setContainerFillValue(int8_t fillLevel);
68 void setContainerAlarm(bool active);
69 void setContainerWarning(bool active);
70 void setContainerInvalidSensorState(bool invalid);
71 void setContainerSoundAlarmOn(bool soundAlarmOn);
72
73 // Returns 0-100 value for 0-100 %, -1 if not available
74 int8_t getContainerFillValue() const;
75 bool isContainerAlarmActive() const;
76 bool isContainerWarningActive() const;
77 bool isContainerInvalidSensorStateActive() const;
78 bool isContainerSoundAlarmOn() const;
79
86 void setValveOpenState(uint8_t openState);
87
94 void setValveFloodingFlag(bool active);
95
103 void setValveManuallyClosedFlag(bool active);
104
110 void setValveMotorProblemFlag(bool active);
111
117 uint8_t getValveOpenState() const;
118
124 bool isValveOpen() const;
125
131 bool isValveFloodingFlagActive() const;
132
139
146
147 double getValueDouble();
148 double getValueDoubleFirst();
149 double getValueDoubleSecond();
150 int32_t getValueInt32();
151 uint64_t getValueInt64();
152 virtual bool getValueBool();
153 uint8_t getValueRed() const;
154 uint8_t getValueGreen() const;
155 uint8_t getValueBlue() const;
156 uint8_t getValueColorBrightness() const;
157 uint8_t getValueBrightness() const;
158 uint8_t getValueWhiteTemperature() const;
159 double getLastTemperature();
160 uint8_t getValueClosingPercentage() const;
161 uint8_t getValueTilt() const;
162 bool getValueIsCalibrating() const;
163
164 void setHvacIsOn(bool isOn);
165 void setHvacIsOnPercent(uint8_t percent);
166 void setHvacMode(uint8_t mode);
167 void setHvacSetpointTemperatureHeat(int16_t setpointTemperatureHeat);
168 void setHvacSetpointTemperatureCool(int16_t setpointTemperatureCool);
169 void clearHvacSetpointTemperatureHeat();
170 void clearHvacSetpointTemperatureCool();
171 void setHvacFlags(uint16_t alarmsAndFlags);
172 void setHvacFlagSetpointTemperatureHeatSet(bool value);
173 void setHvacFlagSetpointTemperatureCoolSet(bool value);
174 void setHvacFlagHeating(bool value);
175 void setHvacFlagCooling(bool value);
176 void setHvacFlagWeeklySchedule(bool value);
177 void setHvacFlagFanEnabled(bool value);
178 void setHvacFlagThermometerError(bool value);
179 void setHvacFlagClockError(bool value);
180 void setHvacFlagCountdownTimer(bool value);
181 void setHvacFlagForcedOffBySensor(bool value);
182 void setHvacFlagCoolSubfunction(enum HvacCoolSubfunctionFlag flag);
183 void setHvacFlagWeeklyScheduleTemporalOverride(bool value);
184 void setHvacFlagBatteryCoverOpen(bool value);
185 void setHvacFlagCalibrationError(bool value);
186 void setHvacFlagAntifreezeOverheatActive(bool value);
187 void clearHvacState();
188
189 uint8_t getHvacIsOnRaw() const;
190 bool getHvacIsOnBool() const;
191 uint8_t getHvacIsOnPercent() const;
192
193 uint8_t getHvacMode() const;
194 // returns mode as a string. If mode parameters is -1 then it returns current
195 // channel mode, otherwise mode parameter is used.
196 const char *getHvacModeCstr(int mode = -1) const;
197 int16_t getHvacSetpointTemperatureHeat() const;
198 int16_t getHvacSetpointTemperatureCool() const;
199 uint16_t getHvacFlags() const;
200 bool isHvacFlagSetpointTemperatureHeatSet() const;
201 bool isHvacFlagSetpointTemperatureCoolSet() const;
202 bool isHvacFlagHeating() const;
203 bool isHvacFlagCooling() const;
204 bool isHvacFlagWeeklySchedule() const;
205 bool isHvacFlagFanEnabled() const;
206 bool isHvacFlagThermometerError() const;
207 bool isHvacFlagClockError() const;
208 bool isHvacFlagCountdownTimer() const;
209 bool isHvacFlagForcedOffBySensor() const;
210 enum HvacCoolSubfunctionFlag getHvacFlagCoolSubfunction() const;
211 bool isHvacFlagWeeklyScheduleTemporalOverride() const;
212 bool isHvacFlagBatteryCoverOpen() const;
213 bool isHvacFlagCalibrationError() const;
214 bool isHvacFlagAntifreezeOverheatActive() const;
215
216 static bool isHvacFlagSetpointTemperatureHeatSet(const THVACValue *hvacValue);
217 static bool isHvacFlagSetpointTemperatureCoolSet(const THVACValue *hvacValue);
218 static bool isHvacFlagHeating(const THVACValue *hvacValue);
219 static bool isHvacFlagCooling(const THVACValue *hvacValue);
220 static bool isHvacFlagWeeklySchedule(const THVACValue *hvacValue);
221 static bool isHvacFlagFanEnabled(const THVACValue *hvacValue);
222 static bool isHvacFlagThermometerError(const THVACValue *hvacValue);
223 static bool isHvacFlagClockError(const THVACValue *hvacValue);
224 static bool isHvacFlagCountdownTimer(const THVACValue *hvacValue);
225 static bool isHvacFlagForcedOffBySensor(const THVACValue *hvacValue);
226 static enum HvacCoolSubfunctionFlag getHvacFlagCoolSubfunction(
227 const THVACValue *hvacValue);
228 static bool isHvacFlagWeeklyScheduleTemporalOverride(
229 const THVACValue *hvacValue);
230 static bool isHvacFlagBatteryCoverOpen(const THVACValue *hvacValue);
231 static bool isHvacFlagCalibrationError(const THVACValue *hvacValue);
232 static bool isHvacFlagAntifreezeOverheatActive(const THVACValue *hvacValue);
233
234 static void setHvacSetpointTemperatureHeat(THVACValue *hvacValue,
235 int16_t setpointTemperatureHeat);
236 static void setHvacSetpointTemperatureCool(THVACValue *hvacValue,
237 int16_t setpointTemperatureCool);
238
239 THVACValue *getValueHvac();
240 const THVACValue *getValueHvac() const;
241 static bool isHvacValueValid(const THVACValue *hvacValue);
242
243 virtual bool isExtended() const;
244 bool isUpdateReady() const;
245 int getChannelNumber() const;
246 uint32_t getChannelType() const;
247
248 void setType(uint32_t type);
249
250 // setDefault and setDefaultFunction are the same methods.
251 // Second was added for better readability
252 void setDefault(uint32_t value);
253
260 void setDefaultFunction(uint32_t function);
261 uint32_t getDefaultFunction() const;
262 bool isFunctionValid(uint32_t function) const;
263 void setFlag(uint64_t flag);
264 void unsetFlag(uint64_t flag);
265 uint64_t getFlags() const;
266 void setFuncList(uint32_t functions);
267 uint32_t getFuncList() const;
268 void addToFuncList(uint32_t function);
269 void removeFromFuncList(uint32_t function);
270 void setActionTriggerCaps(uint32_t caps);
271 uint32_t getActionTriggerCaps();
272
273 void setValidityTimeSec(uint32_t timeSec);
274 void clearValue();
275 virtual void sendUpdate();
276 virtual TSuplaChannelExtendedValue *getExtValue();
277 // Returns true when value was properly converted to EM value.
278 // "out" has to be valid pointer to allocated structure.
279 virtual bool getExtValueAsElectricityMeter(
281 void setCorrection(double correction, bool forSecondaryValue = false);
282 bool isSleepingEnabled();
283 bool isWeeklyScheduleAvailable();
284
285 // Returns true if channel is battery powered (for channel state info)
286 bool isBatteryPoweredFieldEnabled() const;
287 bool isBatteryPowered() const;
288 // sets battery powered flag
289 void setBatteryPowered(bool);
290
296 uint8_t getBatteryLevel() const;
297
303 void setBatteryLevel(int level);
304
305 // Sets bridge signal strength. Allowed values are 0..100, or 255 to disable
306 void setBridgeSignalStrength(unsigned char level);
307 uint8_t getBridgeSignalStrength() const;
308 bool isBridgeSignalStrengthAvailable() const;
309
310 void setInitialCaption(const char *caption);
311 bool isInitialCaptionSet() const;
312 const char* getInitialCaption() const;
313
327 void setDefaultIcon(uint8_t iconId);
328
334 uint8_t getDefaultIcon() const;
335
336 void fillRawValue(void *value);
337 int8_t *getValuePtr();
338
339 void setSubDeviceId(uint8_t subDeviceId);
340 uint8_t getSubDeviceId() const;
341
342 bool isRollerShutterRelayType() const;
343 void setRelayOvercurrentCutOff(bool value);
344 bool isRelayOvercurrentCutOff() const;
345
346 void onRegistered();
347 void setSendGetConfig();
348
349 bool isChannelStateEnabled() const;
350 void clearSendValue();
351
352 protected:
353 void setSendValue();
354 bool isValueUpdateReady() const;
355
356 void clearSendGetConfig();
357 bool isGetConfigRequested() const;
358
359 void setSendInitialCaption();
360 void clearSendInitialCaption();
361 bool isInitialCaptionUpdateReady() const;
362
363 void setSendStateInfo();
364 void clearSendStateInfo();
365 bool isStateInfoUpdateReady() const;
366
367 static Channel *firstPtr;
368 static int startingChannelNumber;
369 Channel *nextPtr = nullptr;
370
371 char *initialCaption = nullptr;
372
373 uint32_t functionsBitmap = 0;
374
375 uint64_t channelFlags = 0;
376 uint32_t validityTimeSec = 0;
377
378 int16_t channelNumber = -1;
379
380 uint16_t defaultFunction =
381 0; // function in proto use 32 bit, but there are no functions defined so
382 // far that use more than 16 bits
383
384 uint8_t changedFields = 0; // keeps track of pending updates
385
386 uint8_t batteryLevel = 255; // 0 - 100%; 255 - not used
387 uint8_t batteryPowered = 0; // 0 - not used, 1 - true, 2 - false
388 unsigned char bridgeSignalStrength = 255; // 0 - 100%; 255 - not used
389
390 // registration parameter
391 ChannelType channelType = ChannelType::NOT_SET;
392
393 uint8_t state = 0;
394 uint8_t defaultIcon = 0;
395 uint8_t subDeviceId = 0;
396
397 union {
398 int8_t value[SUPLA_CHANNELVALUE_SIZE] = {};
399 TActionTriggerProperties actionTriggerProperties;
400 THVACValue hvacValue;
401 };
402};
403
404}; // namespace Supla
405
406#endif // SRC_SUPLA_CHANNELS_CHANNEL_H_
Definition channel.h:20
bool isValveMotorProblemFlagActive() const
Returns the motor problem flag of the Valve channel.
Definition channel.cpp:1968
uint8_t getValveOpenState() const
Returns the open state (open/close) of the Valve channel.
Definition channel.cpp:1942
void setValveMotorProblemFlag(bool active)
Sets the motor problem flag of the Valve channel.
Definition channel.cpp:1927
void setDefaultIcon(uint8_t iconId)
Sets default icon.
Definition channel.cpp:1529
void setValveManuallyClosedFlag(bool active)
Sets the manually closed flag of the Valve channel.
Definition channel.cpp:1911
bool isValveFloodingFlagActive() const
Returns the flooding flag of the Valve channel.
Definition channel.cpp:1958
void setDefaultFunction(uint32_t function)
Set default function.
Definition channel.cpp:324
void setBatteryLevel(int level)
Sets battery level.
Definition channel.cpp:792
void setValveFloodingFlag(bool active)
Sets the flooding flag of the Valve channel.
Definition channel.cpp:1896
uint8_t getDefaultIcon() const
Returns default icon.
Definition channel.cpp:1533
uint8_t getBatteryLevel() const
Returns battery level.
Definition channel.cpp:775
bool isValveManuallyClosedFlagActive() const
Returns the manually closed flag of the Valve channel.
Definition channel.cpp:1963
bool isValveOpen() const
Returns the open state (open/close) of the Valve channel.
Definition channel.cpp:1954
void setValveOpenState(uint8_t openState)
Sets the open state (open/close) of the Valve channel.
Definition channel.cpp:1857
Definition local_action.h:42
Definition proto.h:858
Definition proto.h:2126
Definition proto.h:2091
Definition proto.h:973
Definition proto.h:999
Definition proto.h:2014
Definition proto.h:916
Definition proto.h:784