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
20enum class BatteryState : uint8_t {
21 Normal = SUPLA_BATTERY_STATE_OK,
22 Low = SUPLA_BATTERY_STATE_LOW,
23 NotSet = 0xFF,
24};
25
26class Channel : public LocalAction {
27 public:
28 explicit Channel(int number = -1);
29 virtual ~Channel();
30 static void setStartingChannelNumber(int channelNumber);
31 static int getStartingChannelNumber();
32 static Channel *Begin();
33 static Channel *Last();
34 static Channel *GetByChannelNumber(int channelNumber);
35 Channel *next();
36
37#ifdef SUPLA_TEST
38 static void resetToDefaults();
39#endif
40 void fillDeviceChannelStruct(TDS_SuplaDeviceChannel_D *deviceChannelStruct);
41 void fillDeviceChannelStruct(TDS_SuplaDeviceChannel_E *deviceChannelStruct);
42
43 bool setChannelNumber(int newChannelNumber);
44
45 void setNewValue(double dbl);
46 void setNewValue(double temp, double humi);
47 void setNewValue(int32_t value);
48 void setNewValue(bool value);
49 void setNewValue(const TElectricityMeter_ExtendedValue_V3 &emValue);
50 void setNewValue(uint8_t red,
51 uint8_t green,
52 uint8_t blue,
53 uint8_t colorBrightness,
54 uint8_t whiteBrightness,
55 uint8_t whiteTemperature);
56 void setNewValue(uint64_t value);
57 void setNewValue(const TDSC_RollerShutterValue &value);
58 void setNewValue(const TDSC_FacadeBlindValue &value);
59 bool setNewValue(const char *newValue);
60
61 void setStateOffline();
62 void setStateOnline();
63 void setStateOnlineAndNotAvailable();
64 void setStateFirmwareUpdateOngoing();
65 void setStateOfflineRemoteWakeupNotSupported();
66 bool isStateOnline() const;
67 bool isStateOnlineAndNotAvailable() const;
68 bool isStateOfflineRemoteWakeupNotSupported() const;
69 bool isStateFirmwareUpdateOngoing() const;
70
71 // Sets container channel value. fillLevel should contain 0-100 value, any
72 // other value will be set to "unknown" value.
73 void setContainerFillValue(int8_t fillLevel);
74 void setContainerAlarm(bool active);
75 void setContainerWarning(bool active);
76 void setContainerInvalidSensorState(bool invalid);
77 void setContainerSoundAlarmOn(bool soundAlarmOn);
78
79 // Returns 0-100 value for 0-100 %, -1 if not available
80 int8_t getContainerFillValue() const;
81 bool isContainerAlarmActive() const;
82 bool isContainerWarningActive() const;
83 bool isContainerInvalidSensorStateActive() const;
84 bool isContainerSoundAlarmOn() const;
85
92 void setValveOpenState(uint8_t openState);
93
100 void setValveFloodingFlag(bool active);
101
109 void setValveManuallyClosedFlag(bool active);
110
116 void setValveMotorProblemFlag(bool active);
117
123 uint8_t getValveOpenState() const;
124
130 bool isValveOpen() const;
131
137 bool isValveFloodingFlagActive() const;
138
145
152
153 double getValueDouble();
154 double getValueDoubleFirst();
155 double getValueDoubleSecond();
156 int32_t getValueInt32();
157 uint64_t getValueInt64();
158 virtual bool getValueBool();
159 uint8_t getValueRed() const;
160 uint8_t getValueGreen() const;
161 uint8_t getValueBlue() const;
162 uint8_t getValueColorBrightness() const;
163 uint8_t getValueBrightness() const;
164 uint8_t getValueWhiteTemperature() const;
165 double getLastTemperature();
166 uint8_t getValueClosingPercentage() const;
167 uint8_t getValueTilt() const;
168 bool getValueIsCalibrating() const;
169
170 void setHvacIsOn(bool isOn);
171 void setHvacIsOnPercent(uint8_t percent);
172 void setHvacMode(uint8_t mode);
173 void setHvacSetpointTemperatureHeat(int16_t setpointTemperatureHeat);
174 void setHvacSetpointTemperatureCool(int16_t setpointTemperatureCool);
175 void clearHvacSetpointTemperatureHeat();
176 void clearHvacSetpointTemperatureCool();
177 void setHvacFlags(uint16_t alarmsAndFlags);
178 void setHvacFlagSetpointTemperatureHeatSet(bool value);
179 void setHvacFlagSetpointTemperatureCoolSet(bool value);
180 void setHvacFlagHeating(bool value);
181 void setHvacFlagCooling(bool value);
182 void setHvacFlagWeeklySchedule(bool value);
183 void setHvacFlagFanEnabled(bool value);
184 void setHvacFlagThermometerError(bool value);
185 void setHvacFlagClockError(bool value);
186 void setHvacFlagCountdownTimer(bool value);
187 void setHvacFlagForcedOffBySensor(bool value);
188 void setHvacFlagCoolSubfunction(enum HvacCoolSubfunctionFlag flag);
189 void setHvacFlagWeeklyScheduleTemporalOverride(bool value);
190 void setHvacFlagBatteryCoverOpen(bool value);
191 void setHvacFlagCalibrationError(bool value);
192 void setHvacFlagAntifreezeOverheatActive(bool value);
193 void clearHvacState();
194
195 uint8_t getHvacIsOnRaw() const;
196 bool getHvacIsOnBool() const;
197 uint8_t getHvacIsOnPercent() const;
198
199 uint8_t getHvacMode() const;
200 // returns mode as a string. If mode parameters is -1 then it returns current
201 // channel mode, otherwise mode parameter is used.
202 const char *getHvacModeCstr(int mode = -1) const;
203 int16_t getHvacSetpointTemperatureHeat() const;
204 int16_t getHvacSetpointTemperatureCool() const;
205 uint16_t getHvacFlags() const;
206 bool isHvacFlagSetpointTemperatureHeatSet() const;
207 bool isHvacFlagSetpointTemperatureCoolSet() const;
208 bool isHvacFlagHeating() const;
209 bool isHvacFlagCooling() const;
210 bool isHvacFlagWeeklySchedule() const;
211 bool isHvacFlagFanEnabled() const;
212 bool isHvacFlagThermometerError() const;
213 bool isHvacFlagClockError() const;
214 bool isHvacFlagCountdownTimer() const;
215 bool isHvacFlagForcedOffBySensor() const;
216 enum HvacCoolSubfunctionFlag getHvacFlagCoolSubfunction() const;
217 bool isHvacFlagWeeklyScheduleTemporalOverride() const;
218 bool isHvacFlagBatteryCoverOpen() const;
219 bool isHvacFlagCalibrationError() const;
220 bool isHvacFlagAntifreezeOverheatActive() const;
221
222 static bool isHvacFlagSetpointTemperatureHeatSet(const THVACValue *hvacValue);
223 static bool isHvacFlagSetpointTemperatureCoolSet(const THVACValue *hvacValue);
224 static bool isHvacFlagHeating(const THVACValue *hvacValue);
225 static bool isHvacFlagCooling(const THVACValue *hvacValue);
226 static bool isHvacFlagWeeklySchedule(const THVACValue *hvacValue);
227 static bool isHvacFlagFanEnabled(const THVACValue *hvacValue);
228 static bool isHvacFlagThermometerError(const THVACValue *hvacValue);
229 static bool isHvacFlagClockError(const THVACValue *hvacValue);
230 static bool isHvacFlagCountdownTimer(const THVACValue *hvacValue);
231 static bool isHvacFlagForcedOffBySensor(const THVACValue *hvacValue);
232 static enum HvacCoolSubfunctionFlag getHvacFlagCoolSubfunction(
233 const THVACValue *hvacValue);
234 static bool isHvacFlagWeeklyScheduleTemporalOverride(
235 const THVACValue *hvacValue);
236 static bool isHvacFlagBatteryCoverOpen(const THVACValue *hvacValue);
237 static bool isHvacFlagCalibrationError(const THVACValue *hvacValue);
238 static bool isHvacFlagAntifreezeOverheatActive(const THVACValue *hvacValue);
239
240 static void setHvacSetpointTemperatureHeat(THVACValue *hvacValue,
241 int16_t setpointTemperatureHeat);
242 static void setHvacSetpointTemperatureCool(THVACValue *hvacValue,
243 int16_t setpointTemperatureCool);
244
245 THVACValue *getValueHvac();
246 const THVACValue *getValueHvac() const;
247 static bool isHvacValueValid(const THVACValue *hvacValue);
248
249 virtual bool isExtended() const;
250 bool isUpdateReady() const;
251 int getChannelNumber() const;
252 virtual uint32_t getChannelType() const;
253
254 void setType(uint32_t type);
255
256 // setDefault and setDefaultFunction are the same methods.
257 // Second was added for better readability
258 void setDefault(uint32_t value);
259
266 void setDefaultFunction(uint32_t function);
267 uint32_t getDefaultFunction() const;
268 bool isFunctionValid(uint32_t function) const;
269 void setFlag(uint64_t flag);
270 void unsetFlag(uint64_t flag);
271 uint64_t getFlags() const;
272 void setFuncList(uint32_t functions);
273 uint32_t getFuncList() const;
274 void addToFuncList(uint32_t function);
275 void removeFromFuncList(uint32_t function);
276 void setActionTriggerCaps(uint32_t caps);
277 uint32_t getActionTriggerCaps();
278
279 void setValidityTimeSec(uint32_t timeSec);
280 void clearValue();
281 virtual void sendUpdate();
282 virtual TSuplaChannelExtendedValue *getExtValue();
283 // Returns true when value was properly converted to EM value.
284 // "out" has to be valid pointer to allocated structure.
285 virtual bool getExtValueAsElectricityMeter(
287 void setCorrection(double correction, bool forSecondaryValue = false);
288 bool isSleepingEnabled() const;
289 uint32_t getValidityTimeSec() const;
290 bool isWeeklyScheduleAvailable();
291
292 // Returns true if channel is battery powered (for channel state info)
293 bool isBatteryPoweredFieldEnabled() const;
294 bool isBatteryPowered() const;
295 // sets battery powered flag
296 void setBatteryPowered(bool);
297
303 uint8_t getBatteryLevel() const;
304
310 void setBatteryLevel(int level);
311
312 BatteryState getBatteryState() const;
313 void setBatteryState(BatteryState state,
314 bool applyToWholeDevice = false);
315 bool isBatteryStateAppliedToWholeDevice() const;
316
317 // Sets bridge signal strength. Allowed values are 0..100, or 255 to disable
318 void setBridgeSignalStrength(unsigned char level);
319 uint8_t getBridgeSignalStrength() const;
320 bool isBridgeSignalStrengthAvailable() const;
321
322 void setInitialCaption(const char *caption);
323 bool isInitialCaptionSet() const;
324 const char* getInitialCaption() const;
325
339 void setDefaultIcon(uint8_t iconId);
340
346 uint8_t getDefaultIcon() const;
347
348 void fillRawValue(void *value);
349 int8_t *getValuePtr();
350
351 void setSubDeviceId(uint8_t subDeviceId);
352 uint8_t getSubDeviceId() const;
353
354 bool isRollerShutterRelayType() const;
355 void setRelayOvercurrentCutOff(bool value);
356 bool isRelayOvercurrentCutOff() const;
357 void setRelayMode(uint8_t mode);
358 uint8_t getRelayMode() const;
359 void setRelayWeeklyScheduleEnabled(bool enabled);
360 bool isRelayWeeklyScheduleEnabled() const;
361
362 void onRegistered();
363 void setSendGetConfig();
364
365 bool isChannelStateEnabled() const;
366 void clearSendValue();
367
368 protected:
369 void setSendValue();
370 bool isValueUpdateReady() const;
371
372 void clearSendGetConfig();
373 bool isGetConfigRequested() const;
374
375 void setSendInitialCaption();
376 void clearSendInitialCaption();
377 bool isInitialCaptionUpdateReady() const;
378
379 void setSendStateInfo();
380 void clearSendStateInfo();
381 bool isStateInfoUpdateReady() const;
382
383 static Channel *firstPtr;
384 static int startingChannelNumber;
385 Channel *nextPtr = nullptr;
386
387 char *initialCaption = nullptr;
388
389 uint32_t functionsBitmap = 0;
390
391 uint64_t channelFlags = 0;
392 uint32_t validityTimeSec = 0;
393
394 int16_t channelNumber = -1;
395
396 uint16_t defaultFunction =
397 0; // function in proto use 32 bit, but there are no functions defined so
398 // far that use more than 16 bits
399
400 uint8_t changedFields = 0; // keeps track of pending updates
401
402 uint8_t batteryLevel = 255; // 0 - 100%; 255 - not used
403 uint8_t batteryPowered = 0; // 0 - not used, 1 - true, 2 - false
404 BatteryState batteryState = BatteryState::NotSet;
405 bool batteryStateAppliedToWholeDevice = false;
406 unsigned char bridgeSignalStrength = 255; // 0 - 100%; 255 - not used
407
408 // registration parameter
409 ChannelType channelType = ChannelType::NOT_SET;
410
411 uint8_t state = 0;
412 uint8_t defaultIcon = 0;
413 uint8_t subDeviceId = 0;
414
415 union {
416 int8_t value[SUPLA_CHANNELVALUE_SIZE] = {};
417 TActionTriggerProperties actionTriggerProperties;
418 THVACValue hvacValue;
419 };
420};
421
422}; // namespace Supla
423
424#endif // SRC_SUPLA_CHANNELS_CHANNEL_H_
Definition channel.h:26
bool isValveMotorProblemFlagActive() const
Returns the motor problem flag of the Valve channel.
Definition channel.cpp:2027
uint8_t getValveOpenState() const
Returns the open state (open/close) of the Valve channel.
Definition channel.cpp:2001
void setValveMotorProblemFlag(bool active)
Sets the motor problem flag of the Valve channel.
Definition channel.cpp:1986
void setDefaultIcon(uint8_t iconId)
Sets default icon.
Definition channel.cpp:1588
void setValveManuallyClosedFlag(bool active)
Sets the manually closed flag of the Valve channel.
Definition channel.cpp:1970
bool isValveFloodingFlagActive() const
Returns the flooding flag of the Valve channel.
Definition channel.cpp:2017
void setDefaultFunction(uint32_t function)
Set default function.
Definition channel.cpp:352
void setBatteryLevel(int level)
Sets battery level.
Definition channel.cpp:828
void setValveFloodingFlag(bool active)
Sets the flooding flag of the Valve channel.
Definition channel.cpp:1955
uint8_t getDefaultIcon() const
Returns default icon.
Definition channel.cpp:1592
uint8_t getBatteryLevel() const
Returns battery level.
Definition channel.cpp:811
bool isValveManuallyClosedFlagActive() const
Returns the manually closed flag of the Valve channel.
Definition channel.cpp:2022
bool isValveOpen() const
Returns the open state (open/close) of the Valve channel.
Definition channel.cpp:2013
void setValveOpenState(uint8_t openState)
Sets the open state (open/close) of the Valve channel.
Definition channel.cpp:1916
Definition local_action.h:87
Definition proto.h:873
Definition proto.h:2141
Definition proto.h:2106
Definition proto.h:988
Definition proto.h:1014
Definition proto.h:2029
Definition proto.h:931
Definition proto.h:799