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