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 brightness);
60 void setNewValue(uint64_t value);
61 void setNewValue(const TDSC_RollerShutterValue &value);
62 void setNewValue(const TDSC_FacadeBlindValue &value);
63 bool setNewValue(const char *newValue);
64
65 void setStateOffline();
66 void setStateOnline();
67 void setStateOnlineAndNotAvailable();
68 void setStateFirmwareUpdateOngoing();
69 void setStateOfflineRemoteWakeupNotSupported();
70 bool isStateOnline() const;
71 bool isStateOnlineAndNotAvailable() const;
72 bool isStateOfflineRemoteWakeupNotSupported() const;
73 bool isStateFirmwareUpdateOngoing() const;
74
75 // Sets container channel value. fillLevel should contain 0-100 value, any
76 // other value will be set to "unknown" value.
77 void setContainerFillValue(int8_t fillLevel);
78 void setContainerAlarm(bool active);
79 void setContainerWarning(bool active);
80 void setContainerInvalidSensorState(bool invalid);
81 void setContainerSoundAlarmOn(bool soundAlarmOn);
82
83 // Returns 0-100 value for 0-100 %, -1 if not available
84 int8_t getContainerFillValue() const;
85 bool isContainerAlarmActive() const;
86 bool isContainerWarningActive() const;
87 bool isContainerInvalidSensorStateActive() const;
88 bool isContainerSoundAlarmOn() const;
89
96 void setValveOpenState(uint8_t openState);
97
104 void setValveFloodingFlag(bool active);
105
113 void setValveManuallyClosedFlag(bool active);
114
120 void setValveMotorProblemFlag(bool active);
121
127 uint8_t getValveOpenState() const;
128
134 bool isValveOpen() const;
135
141 bool isValveFloodingFlagActive() const;
142
149
156
157 double getValueDouble();
158 double getValueDoubleFirst();
159 double getValueDoubleSecond();
160 int32_t getValueInt32();
161 uint64_t getValueInt64();
162 virtual bool getValueBool();
163 uint8_t getValueRed();
164 uint8_t getValueGreen();
165 uint8_t getValueBlue();
166 uint8_t getValueColorBrightness();
167 uint8_t getValueBrightness();
168 double getLastTemperature();
169 uint8_t getValueClosingPercentage() const;
170 uint8_t getValueTilt() const;
171 bool getValueIsCalibrating() const;
172
173 void setHvacIsOn(bool isOn);
174 void setHvacIsOnPercent(uint8_t percent);
175 void setHvacMode(uint8_t mode);
176 void setHvacSetpointTemperatureHeat(int16_t setpointTemperatureHeat);
177 void setHvacSetpointTemperatureCool(int16_t setpointTemperatureCool);
178 void clearHvacSetpointTemperatureHeat();
179 void clearHvacSetpointTemperatureCool();
180 void setHvacFlags(uint16_t alarmsAndFlags);
181 void setHvacFlagSetpointTemperatureHeatSet(bool value);
182 void setHvacFlagSetpointTemperatureCoolSet(bool value);
183 void setHvacFlagHeating(bool value);
184 void setHvacFlagCooling(bool value);
185 void setHvacFlagWeeklySchedule(bool value);
186 void setHvacFlagFanEnabled(bool value);
187 void setHvacFlagThermometerError(bool value);
188 void setHvacFlagClockError(bool value);
189 void setHvacFlagCountdownTimer(bool value);
190 void setHvacFlagForcedOffBySensor(bool value);
191 void setHvacFlagCoolSubfunction(enum HvacCoolSubfunctionFlag flag);
192 void setHvacFlagWeeklyScheduleTemporalOverride(bool value);
193 void setHvacFlagBatteryCoverOpen(bool value);
194 void setHvacFlagCalibrationError(bool value);
195 void setHvacFlagAntifreezeOverheatActive(bool value);
196 void clearHvacState();
197
198 uint8_t getHvacIsOnRaw() const;
199 bool getHvacIsOnBool() const;
200 uint8_t getHvacIsOnPercent() const;
201
202 uint8_t getHvacMode() const;
203 // returns mode as a string. If mode parameters is -1 then it returns current
204 // channel mode, otherwise mode parameter is used.
205 const char *getHvacModeCstr(int mode = -1) const;
206 int16_t getHvacSetpointTemperatureHeat() const;
207 int16_t getHvacSetpointTemperatureCool() const;
208 uint16_t getHvacFlags() const;
209 bool isHvacFlagSetpointTemperatureHeatSet() const;
210 bool isHvacFlagSetpointTemperatureCoolSet() const;
211 bool isHvacFlagHeating() const;
212 bool isHvacFlagCooling() const;
213 bool isHvacFlagWeeklySchedule() const;
214 bool isHvacFlagFanEnabled() const;
215 bool isHvacFlagThermometerError() const;
216 bool isHvacFlagClockError() const;
217 bool isHvacFlagCountdownTimer() const;
218 bool isHvacFlagForcedOffBySensor() const;
219 enum HvacCoolSubfunctionFlag getHvacFlagCoolSubfunction() const;
220 bool isHvacFlagWeeklyScheduleTemporalOverride() const;
221 bool isHvacFlagBatteryCoverOpen() const;
222 bool isHvacFlagCalibrationError() const;
223 bool isHvacFlagAntifreezeOverheatActive() const;
224
225 static bool isHvacFlagSetpointTemperatureHeatSet(const THVACValue *hvacValue);
226 static bool isHvacFlagSetpointTemperatureCoolSet(const THVACValue *hvacValue);
227 static bool isHvacFlagHeating(const THVACValue *hvacValue);
228 static bool isHvacFlagCooling(const THVACValue *hvacValue);
229 static bool isHvacFlagWeeklySchedule(const THVACValue *hvacValue);
230 static bool isHvacFlagFanEnabled(const THVACValue *hvacValue);
231 static bool isHvacFlagThermometerError(const THVACValue *hvacValue);
232 static bool isHvacFlagClockError(const THVACValue *hvacValue);
233 static bool isHvacFlagCountdownTimer(const THVACValue *hvacValue);
234 static bool isHvacFlagForcedOffBySensor(const THVACValue *hvacValue);
235 static enum HvacCoolSubfunctionFlag getHvacFlagCoolSubfunction(
236 const THVACValue *hvacValue);
237 static bool isHvacFlagWeeklyScheduleTemporalOverride(
238 const THVACValue *hvacValue);
239 static bool isHvacFlagBatteryCoverOpen(const THVACValue *hvacValue);
240 static bool isHvacFlagCalibrationError(const THVACValue *hvacValue);
241 static bool isHvacFlagAntifreezeOverheatActive(const THVACValue *hvacValue);
242
243 static void setHvacSetpointTemperatureHeat(THVACValue *hvacValue,
244 int16_t setpointTemperatureHeat);
245 static void setHvacSetpointTemperatureCool(THVACValue *hvacValue,
246 int16_t setpointTemperatureCool);
247
248 THVACValue *getValueHvac();
249 const THVACValue *getValueHvac() const;
250 static bool isHvacValueValid(const THVACValue *hvacValue);
251
252 virtual bool isExtended() const;
253 bool isUpdateReady() const;
254 int getChannelNumber() const;
255 uint32_t getChannelType() const;
256
257 void setType(uint32_t type);
258
259 // setDefault and setDefaultFunction are the same methods.
260 // Second was added for better readability
261 void setDefault(uint32_t value);
262
269 void setDefaultFunction(uint32_t function);
270 uint32_t getDefaultFunction() const;
271 bool isFunctionValid(uint32_t function) const;
272 void setFlag(uint64_t flag);
273 void unsetFlag(uint64_t flag);
274 uint64_t getFlags() const;
275 void setFuncList(uint32_t functions);
276 uint32_t getFuncList() const;
277 void addToFuncList(uint32_t function);
278 void removeFromFuncList(uint32_t function);
279 void setActionTriggerCaps(uint32_t caps);
280 uint32_t getActionTriggerCaps();
281
282 void setValidityTimeSec(uint32_t timeSec);
283 virtual void sendUpdate();
284 virtual TSuplaChannelExtendedValue *getExtValue();
285 // Returns true when value was properly converted to EM value.
286 // "out" has to be valid pointer to allocated structure.
287 virtual bool getExtValueAsElectricityMeter(
289 void setCorrection(double correction, bool forSecondaryValue = false);
290 bool isSleepingEnabled();
291 bool isWeeklyScheduleAvailable();
292
293 // Returns true if channel is battery powered (for channel state info)
294 bool isBatteryPoweredFieldEnabled() const;
295 bool isBatteryPowered() const;
296 // sets battery powered flag
297 void setBatteryPowered(bool);
298
304 uint8_t getBatteryLevel() const;
305
311 void setBatteryLevel(int level);
312
313 // Sets bridge signal strength. Allowed values are 0..100, or 255 to disable
314 void setBridgeSignalStrength(unsigned char level);
315 uint8_t getBridgeSignalStrength() const;
316 bool isBridgeSignalStrengthAvailable() const;
317
318 void setInitialCaption(const char *caption);
319 bool isInitialCaptionSet() const;
320 const char* getInitialCaption() const;
321
335 void setDefaultIcon(uint8_t iconId);
336
342 uint8_t getDefaultIcon() const;
343
344 void fillRawValue(void *value);
345 int8_t *getValuePtr();
346
347 void setSubDeviceId(uint8_t subDeviceId);
348 uint8_t getSubDeviceId() const;
349
350 bool isRollerShutterRelayType() const;
351 void setRelayOvercurrentCutOff(bool value);
352 bool isRelayOvercurrentCutOff() const;
353
354 void onRegistered();
355 void setSendGetConfig();
356
357 bool isChannelStateEnabled() const;
358 void clearSendValue();
359
360 protected:
361 void setSendValue();
362 bool isValueUpdateReady() const;
363
364 void clearSendGetConfig();
365 bool isGetConfigRequested() const;
366
367 void setSendInitialCaption();
368 void clearSendInitialCaption();
369 bool isInitialCaptionUpdateReady() const;
370
371 void setSendStateInfo();
372 void clearSendStateInfo();
373 bool isStateInfoUpdateReady() const;
374
375 static Channel *firstPtr;
376 Channel *nextPtr = nullptr;
377
378 char *initialCaption = nullptr;
379
380 uint32_t functionsBitmap = 0;
381
382 uint64_t channelFlags = 0;
383 uint32_t validityTimeSec = 0;
384
385 int16_t channelNumber = -1;
386
387 uint16_t defaultFunction =
388 0; // function in proto use 32 bit, but there are no functions defined so
389 // far that use more than 16 bits
390
391 uint8_t changedFields = 0; // keeps track of pending updates
392
393 uint8_t batteryLevel = 255; // 0 - 100%; 255 - not used
394 uint8_t batteryPowered = 0; // 0 - not used, 1 - true, 2 - false
395 unsigned char bridgeSignalStrength = 255; // 0 - 100%; 255 - not used
396
397 // registration parameter
398 ChannelType channelType = ChannelType::NOT_SET;
399
400 uint8_t state = 0;
401 uint8_t defaultIcon = 0;
402 uint8_t subDeviceId = 0;
403
404 union {
405 int8_t value[SUPLA_CHANNELVALUE_SIZE] = {};
406 TActionTriggerProperties actionTriggerProperties;
407 THVACValue hvacValue;
408 };
409};
410
411}; // namespace Supla
412
413#endif // SRC_SUPLA_CHANNELS_CHANNEL_H_
bool isValveMotorProblemFlagActive() const
Returns the motor problem flag of the Valve channel.
Definition channel.cpp:1995
uint8_t getValveOpenState() const
Returns the open state (open/close) of the Valve channel.
Definition channel.cpp:1969
void setValveMotorProblemFlag(bool active)
Sets the motor problem flag of the Valve channel.
Definition channel.cpp:1954
void setDefaultIcon(uint8_t iconId)
Sets default icon.
Definition channel.cpp:1501
void setValveManuallyClosedFlag(bool active)
Sets the manually closed flag of the Valve channel.
Definition channel.cpp:1938
bool isValveFloodingFlagActive() const
Returns the flooding flag of the Valve channel.
Definition channel.cpp:1985
void setDefaultFunction(uint32_t function)
Set default function.
Definition channel.cpp:326
void setBatteryLevel(int level)
Sets battery level.
Definition channel.cpp:764
void setValveFloodingFlag(bool active)
Sets the flooding flag of the Valve channel.
Definition channel.cpp:1923
uint8_t getDefaultIcon() const
Returns default icon.
Definition channel.cpp:1505
uint8_t getBatteryLevel() const
Returns battery level.
Definition channel.cpp:747
bool isValveManuallyClosedFlagActive() const
Returns the manually closed flag of the Valve channel.
Definition channel.cpp:1990
bool isValveOpen() const
Returns the open state (open/close) of the Valve channel.
Definition channel.cpp:1981
void setValveOpenState(uint8_t openState)
Sets the open state (open/close) of the Valve channel.
Definition channel.cpp:1884
Definition proto.h:818
Definition proto.h:2074
Definition proto.h:2039
Definition proto.h:929
Definition proto.h:955
Definition proto.h:1962
Definition proto.h:872
Definition proto.h:761