supla-device
Loading...
Searching...
No Matches
channel.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15*/
16
17#ifndef SRC_SUPLA_CHANNELS_CHANNEL_H_
18#define SRC_SUPLA_CHANNELS_CHANNEL_H_
19
20#include <stdint.h>
21
22#include <supla-common/proto.h>
23#include <supla/local_action.h>
24#include "channel_types.h"
25
26namespace Supla {
27
28enum class HvacCoolSubfunctionFlag {
29 HeatSubfunctionOrNotUsed,
30 CoolSubfunction,
31};
32
33class Channel : public LocalAction {
34 public:
35 explicit Channel(int number = -1);
36 virtual ~Channel();
37 static Channel *Begin();
38 static Channel *Last();
39 static Channel *GetByChannelNumber(int channelNumber);
40 Channel *next();
41
42#ifdef SUPLA_TEST
43 static void resetToDefaults();
44#endif
45 void fillDeviceChannelStruct(TDS_SuplaDeviceChannel_D *deviceChannelStruct);
46 void fillDeviceChannelStruct(TDS_SuplaDeviceChannel_E *deviceChannelStruct);
47
48 bool setChannelNumber(int newChannelNumber);
49
50 void setNewValue(double dbl);
51 void setNewValue(double temp, double humi);
52 void setNewValue(int32_t value);
53 void setNewValue(bool value);
54 void setNewValue(const TElectricityMeter_ExtendedValue_V3 &emValue);
55 void setNewValue(uint8_t red,
56 uint8_t green,
57 uint8_t blue,
58 uint8_t colorBrightness,
59 uint8_t whiteBrightness,
60 uint8_t whiteTemperature);
61 void setNewValue(uint64_t value);
62 void setNewValue(const TDSC_RollerShutterValue &value);
63 void setNewValue(const TDSC_FacadeBlindValue &value);
64 bool setNewValue(const char *newValue);
65
66 void setStateOffline();
67 void setStateOnline();
68 void setStateOnlineAndNotAvailable();
69 void setStateFirmwareUpdateOngoing();
70 void setStateOfflineRemoteWakeupNotSupported();
71 bool isStateOnline() const;
72 bool isStateOnlineAndNotAvailable() const;
73 bool isStateOfflineRemoteWakeupNotSupported() const;
74 bool isStateFirmwareUpdateOngoing() const;
75
76 // Sets container channel value. fillLevel should contain 0-100 value, any
77 // other value will be set to "unknown" value.
78 void setContainerFillValue(int8_t fillLevel);
79 void setContainerAlarm(bool active);
80 void setContainerWarning(bool active);
81 void setContainerInvalidSensorState(bool invalid);
82 void setContainerSoundAlarmOn(bool soundAlarmOn);
83
84 // Returns 0-100 value for 0-100 %, -1 if not available
85 int8_t getContainerFillValue() const;
86 bool isContainerAlarmActive() const;
87 bool isContainerWarningActive() const;
88 bool isContainerInvalidSensorStateActive() const;
89 bool isContainerSoundAlarmOn() const;
90
97 void setValveOpenState(uint8_t openState);
98
105 void setValveFloodingFlag(bool active);
106
114 void setValveManuallyClosedFlag(bool active);
115
121 void setValveMotorProblemFlag(bool active);
122
128 uint8_t getValveOpenState() const;
129
135 bool isValveOpen() const;
136
142 bool isValveFloodingFlagActive() const;
143
150
157
158 double getValueDouble();
159 double getValueDoubleFirst();
160 double getValueDoubleSecond();
161 int32_t getValueInt32();
162 uint64_t getValueInt64();
163 virtual bool getValueBool();
164 uint8_t getValueRed() const;
165 uint8_t getValueGreen() const;
166 uint8_t getValueBlue() const;
167 uint8_t getValueColorBrightness() const;
168 uint8_t getValueBrightness() const;
169 uint8_t getValueWhiteTemperature() const;
170 double getLastTemperature();
171 uint8_t getValueClosingPercentage() const;
172 uint8_t getValueTilt() const;
173 bool getValueIsCalibrating() const;
174
175 void setHvacIsOn(bool isOn);
176 void setHvacIsOnPercent(uint8_t percent);
177 void setHvacMode(uint8_t mode);
178 void setHvacSetpointTemperatureHeat(int16_t setpointTemperatureHeat);
179 void setHvacSetpointTemperatureCool(int16_t setpointTemperatureCool);
180 void clearHvacSetpointTemperatureHeat();
181 void clearHvacSetpointTemperatureCool();
182 void setHvacFlags(uint16_t alarmsAndFlags);
183 void setHvacFlagSetpointTemperatureHeatSet(bool value);
184 void setHvacFlagSetpointTemperatureCoolSet(bool value);
185 void setHvacFlagHeating(bool value);
186 void setHvacFlagCooling(bool value);
187 void setHvacFlagWeeklySchedule(bool value);
188 void setHvacFlagFanEnabled(bool value);
189 void setHvacFlagThermometerError(bool value);
190 void setHvacFlagClockError(bool value);
191 void setHvacFlagCountdownTimer(bool value);
192 void setHvacFlagForcedOffBySensor(bool value);
193 void setHvacFlagCoolSubfunction(enum HvacCoolSubfunctionFlag flag);
194 void setHvacFlagWeeklyScheduleTemporalOverride(bool value);
195 void setHvacFlagBatteryCoverOpen(bool value);
196 void setHvacFlagCalibrationError(bool value);
197 void setHvacFlagAntifreezeOverheatActive(bool value);
198 void clearHvacState();
199
200 uint8_t getHvacIsOnRaw() const;
201 bool getHvacIsOnBool() const;
202 uint8_t getHvacIsOnPercent() const;
203
204 uint8_t getHvacMode() const;
205 // returns mode as a string. If mode parameters is -1 then it returns current
206 // channel mode, otherwise mode parameter is used.
207 const char *getHvacModeCstr(int mode = -1) const;
208 int16_t getHvacSetpointTemperatureHeat() const;
209 int16_t getHvacSetpointTemperatureCool() const;
210 uint16_t getHvacFlags() const;
211 bool isHvacFlagSetpointTemperatureHeatSet() const;
212 bool isHvacFlagSetpointTemperatureCoolSet() const;
213 bool isHvacFlagHeating() const;
214 bool isHvacFlagCooling() const;
215 bool isHvacFlagWeeklySchedule() const;
216 bool isHvacFlagFanEnabled() const;
217 bool isHvacFlagThermometerError() const;
218 bool isHvacFlagClockError() const;
219 bool isHvacFlagCountdownTimer() const;
220 bool isHvacFlagForcedOffBySensor() const;
221 enum HvacCoolSubfunctionFlag getHvacFlagCoolSubfunction() const;
222 bool isHvacFlagWeeklyScheduleTemporalOverride() const;
223 bool isHvacFlagBatteryCoverOpen() const;
224 bool isHvacFlagCalibrationError() const;
225 bool isHvacFlagAntifreezeOverheatActive() const;
226
227 static bool isHvacFlagSetpointTemperatureHeatSet(const THVACValue *hvacValue);
228 static bool isHvacFlagSetpointTemperatureCoolSet(const THVACValue *hvacValue);
229 static bool isHvacFlagHeating(const THVACValue *hvacValue);
230 static bool isHvacFlagCooling(const THVACValue *hvacValue);
231 static bool isHvacFlagWeeklySchedule(const THVACValue *hvacValue);
232 static bool isHvacFlagFanEnabled(const THVACValue *hvacValue);
233 static bool isHvacFlagThermometerError(const THVACValue *hvacValue);
234 static bool isHvacFlagClockError(const THVACValue *hvacValue);
235 static bool isHvacFlagCountdownTimer(const THVACValue *hvacValue);
236 static bool isHvacFlagForcedOffBySensor(const THVACValue *hvacValue);
237 static enum HvacCoolSubfunctionFlag getHvacFlagCoolSubfunction(
238 const THVACValue *hvacValue);
239 static bool isHvacFlagWeeklyScheduleTemporalOverride(
240 const THVACValue *hvacValue);
241 static bool isHvacFlagBatteryCoverOpen(const THVACValue *hvacValue);
242 static bool isHvacFlagCalibrationError(const THVACValue *hvacValue);
243 static bool isHvacFlagAntifreezeOverheatActive(const THVACValue *hvacValue);
244
245 static void setHvacSetpointTemperatureHeat(THVACValue *hvacValue,
246 int16_t setpointTemperatureHeat);
247 static void setHvacSetpointTemperatureCool(THVACValue *hvacValue,
248 int16_t setpointTemperatureCool);
249
250 THVACValue *getValueHvac();
251 const THVACValue *getValueHvac() const;
252 static bool isHvacValueValid(const THVACValue *hvacValue);
253
254 virtual bool isExtended() const;
255 bool isUpdateReady() const;
256 int getChannelNumber() const;
257 uint32_t getChannelType() const;
258
259 void setType(uint32_t type);
260
261 // setDefault and setDefaultFunction are the same methods.
262 // Second was added for better readability
263 void setDefault(uint32_t value);
264
271 void setDefaultFunction(uint32_t function);
272 uint32_t getDefaultFunction() const;
273 bool isFunctionValid(uint32_t function) const;
274 void setFlag(uint64_t flag);
275 void unsetFlag(uint64_t flag);
276 uint64_t getFlags() const;
277 void setFuncList(uint32_t functions);
278 uint32_t getFuncList() const;
279 void addToFuncList(uint32_t function);
280 void removeFromFuncList(uint32_t function);
281 void setActionTriggerCaps(uint32_t caps);
282 uint32_t getActionTriggerCaps();
283
284 void setValidityTimeSec(uint32_t timeSec);
285 virtual void sendUpdate();
286 virtual TSuplaChannelExtendedValue *getExtValue();
287 // Returns true when value was properly converted to EM value.
288 // "out" has to be valid pointer to allocated structure.
289 virtual bool getExtValueAsElectricityMeter(
291 void setCorrection(double correction, bool forSecondaryValue = false);
292 bool isSleepingEnabled();
293 bool isWeeklyScheduleAvailable();
294
295 // Returns true if channel is battery powered (for channel state info)
296 bool isBatteryPoweredFieldEnabled() const;
297 bool isBatteryPowered() const;
298 // sets battery powered flag
299 void setBatteryPowered(bool);
300
306 uint8_t getBatteryLevel() const;
307
313 void setBatteryLevel(int level);
314
315 // Sets bridge signal strength. Allowed values are 0..100, or 255 to disable
316 void setBridgeSignalStrength(unsigned char level);
317 uint8_t getBridgeSignalStrength() const;
318 bool isBridgeSignalStrengthAvailable() const;
319
320 void setInitialCaption(const char *caption);
321 bool isInitialCaptionSet() const;
322 const char* getInitialCaption() const;
323
337 void setDefaultIcon(uint8_t iconId);
338
344 uint8_t getDefaultIcon() const;
345
346 void fillRawValue(void *value);
347 int8_t *getValuePtr();
348
349 void setSubDeviceId(uint8_t subDeviceId);
350 uint8_t getSubDeviceId() const;
351
352 bool isRollerShutterRelayType() const;
353 void setRelayOvercurrentCutOff(bool value);
354 bool isRelayOvercurrentCutOff() const;
355
356 void onRegistered();
357 void setSendGetConfig();
358
359 bool isChannelStateEnabled() const;
360 void clearSendValue();
361
362 protected:
363 void setSendValue();
364 bool isValueUpdateReady() const;
365
366 void clearSendGetConfig();
367 bool isGetConfigRequested() const;
368
369 void setSendInitialCaption();
370 void clearSendInitialCaption();
371 bool isInitialCaptionUpdateReady() const;
372
373 void setSendStateInfo();
374 void clearSendStateInfo();
375 bool isStateInfoUpdateReady() const;
376
377 static Channel *firstPtr;
378 Channel *nextPtr = nullptr;
379
380 char *initialCaption = nullptr;
381
382 uint32_t functionsBitmap = 0;
383
384 uint64_t channelFlags = 0;
385 uint32_t validityTimeSec = 0;
386
387 int16_t channelNumber = -1;
388
389 uint16_t defaultFunction =
390 0; // function in proto use 32 bit, but there are no functions defined so
391 // far that use more than 16 bits
392
393 uint8_t changedFields = 0; // keeps track of pending updates
394
395 uint8_t batteryLevel = 255; // 0 - 100%; 255 - not used
396 uint8_t batteryPowered = 0; // 0 - not used, 1 - true, 2 - false
397 unsigned char bridgeSignalStrength = 255; // 0 - 100%; 255 - not used
398
399 // registration parameter
400 ChannelType channelType = ChannelType::NOT_SET;
401
402 uint8_t state = 0;
403 uint8_t defaultIcon = 0;
404 uint8_t subDeviceId = 0;
405
406 union {
407 int8_t value[SUPLA_CHANNELVALUE_SIZE] = {};
408 TActionTriggerProperties actionTriggerProperties;
409 THVACValue hvacValue;
410 };
411};
412
413}; // namespace Supla
414
415#endif // SRC_SUPLA_CHANNELS_CHANNEL_H_
bool isValveMotorProblemFlagActive() const
Returns the motor problem flag of the Valve channel.
Definition channel.cpp:2014
uint8_t getValveOpenState() const
Returns the open state (open/close) of the Valve channel.
Definition channel.cpp:1988
void setValveMotorProblemFlag(bool active)
Sets the motor problem flag of the Valve channel.
Definition channel.cpp:1973
void setDefaultIcon(uint8_t iconId)
Sets default icon.
Definition channel.cpp:1520
void setValveManuallyClosedFlag(bool active)
Sets the manually closed flag of the Valve channel.
Definition channel.cpp:1957
bool isValveFloodingFlagActive() const
Returns the flooding flag of the Valve channel.
Definition channel.cpp:2004
void setDefaultFunction(uint32_t function)
Set default function.
Definition channel.cpp:327
void setBatteryLevel(int level)
Sets battery level.
Definition channel.cpp:783
void setValveFloodingFlag(bool active)
Sets the flooding flag of the Valve channel.
Definition channel.cpp:1942
uint8_t getDefaultIcon() const
Returns default icon.
Definition channel.cpp:1524
uint8_t getBatteryLevel() const
Returns battery level.
Definition channel.cpp:766
bool isValveManuallyClosedFlagActive() const
Returns the manually closed flag of the Valve channel.
Definition channel.cpp:2009
bool isValveOpen() const
Returns the open state (open/close) of the Valve channel.
Definition channel.cpp:2000
void setValveOpenState(uint8_t openState)
Sets the open state (open/close) of the Valve channel.
Definition channel.cpp:1903
Definition proto.h:833
Definition proto.h:2094
Definition proto.h:2059
Definition proto.h:944
Definition proto.h:970
Definition proto.h:1982
Definition proto.h:887
Definition proto.h:776