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 void setStartingChannelNumber(int channelNumber);
38 static int getStartingChannelNumber();
39 static Channel *Begin();
40 static Channel *Last();
41 static Channel *GetByChannelNumber(int channelNumber);
42 Channel *next();
43
44#ifdef SUPLA_TEST
45 static void resetToDefaults();
46#endif
47 void fillDeviceChannelStruct(TDS_SuplaDeviceChannel_D *deviceChannelStruct);
48 void fillDeviceChannelStruct(TDS_SuplaDeviceChannel_E *deviceChannelStruct);
49
50 bool setChannelNumber(int newChannelNumber);
51
52 void setNewValue(double dbl);
53 void setNewValue(double temp, double humi);
54 void setNewValue(int32_t value);
55 void setNewValue(bool value);
56 void setNewValue(const TElectricityMeter_ExtendedValue_V3 &emValue);
57 void setNewValue(uint8_t red,
58 uint8_t green,
59 uint8_t blue,
60 uint8_t colorBrightness,
61 uint8_t whiteBrightness,
62 uint8_t whiteTemperature);
63 void setNewValue(uint64_t value);
64 void setNewValue(const TDSC_RollerShutterValue &value);
65 void setNewValue(const TDSC_FacadeBlindValue &value);
66 bool setNewValue(const char *newValue);
67
68 void setStateOffline();
69 void setStateOnline();
70 void setStateOnlineAndNotAvailable();
71 void setStateFirmwareUpdateOngoing();
72 void setStateOfflineRemoteWakeupNotSupported();
73 bool isStateOnline() const;
74 bool isStateOnlineAndNotAvailable() const;
75 bool isStateOfflineRemoteWakeupNotSupported() const;
76 bool isStateFirmwareUpdateOngoing() const;
77
78 // Sets container channel value. fillLevel should contain 0-100 value, any
79 // other value will be set to "unknown" value.
80 void setContainerFillValue(int8_t fillLevel);
81 void setContainerAlarm(bool active);
82 void setContainerWarning(bool active);
83 void setContainerInvalidSensorState(bool invalid);
84 void setContainerSoundAlarmOn(bool soundAlarmOn);
85
86 // Returns 0-100 value for 0-100 %, -1 if not available
87 int8_t getContainerFillValue() const;
88 bool isContainerAlarmActive() const;
89 bool isContainerWarningActive() const;
90 bool isContainerInvalidSensorStateActive() const;
91 bool isContainerSoundAlarmOn() const;
92
99 void setValveOpenState(uint8_t openState);
100
107 void setValveFloodingFlag(bool active);
108
116 void setValveManuallyClosedFlag(bool active);
117
123 void setValveMotorProblemFlag(bool active);
124
130 uint8_t getValveOpenState() const;
131
137 bool isValveOpen() const;
138
144 bool isValveFloodingFlagActive() const;
145
152
159
160 double getValueDouble();
161 double getValueDoubleFirst();
162 double getValueDoubleSecond();
163 int32_t getValueInt32();
164 uint64_t getValueInt64();
165 virtual bool getValueBool();
166 uint8_t getValueRed() const;
167 uint8_t getValueGreen() const;
168 uint8_t getValueBlue() const;
169 uint8_t getValueColorBrightness() const;
170 uint8_t getValueBrightness() const;
171 uint8_t getValueWhiteTemperature() const;
172 double getLastTemperature();
173 uint8_t getValueClosingPercentage() const;
174 uint8_t getValueTilt() const;
175 bool getValueIsCalibrating() const;
176
177 void setHvacIsOn(bool isOn);
178 void setHvacIsOnPercent(uint8_t percent);
179 void setHvacMode(uint8_t mode);
180 void setHvacSetpointTemperatureHeat(int16_t setpointTemperatureHeat);
181 void setHvacSetpointTemperatureCool(int16_t setpointTemperatureCool);
182 void clearHvacSetpointTemperatureHeat();
183 void clearHvacSetpointTemperatureCool();
184 void setHvacFlags(uint16_t alarmsAndFlags);
185 void setHvacFlagSetpointTemperatureHeatSet(bool value);
186 void setHvacFlagSetpointTemperatureCoolSet(bool value);
187 void setHvacFlagHeating(bool value);
188 void setHvacFlagCooling(bool value);
189 void setHvacFlagWeeklySchedule(bool value);
190 void setHvacFlagFanEnabled(bool value);
191 void setHvacFlagThermometerError(bool value);
192 void setHvacFlagClockError(bool value);
193 void setHvacFlagCountdownTimer(bool value);
194 void setHvacFlagForcedOffBySensor(bool value);
195 void setHvacFlagCoolSubfunction(enum HvacCoolSubfunctionFlag flag);
196 void setHvacFlagWeeklyScheduleTemporalOverride(bool value);
197 void setHvacFlagBatteryCoverOpen(bool value);
198 void setHvacFlagCalibrationError(bool value);
199 void setHvacFlagAntifreezeOverheatActive(bool value);
200 void clearHvacState();
201
202 uint8_t getHvacIsOnRaw() const;
203 bool getHvacIsOnBool() const;
204 uint8_t getHvacIsOnPercent() const;
205
206 uint8_t getHvacMode() const;
207 // returns mode as a string. If mode parameters is -1 then it returns current
208 // channel mode, otherwise mode parameter is used.
209 const char *getHvacModeCstr(int mode = -1) const;
210 int16_t getHvacSetpointTemperatureHeat() const;
211 int16_t getHvacSetpointTemperatureCool() const;
212 uint16_t getHvacFlags() const;
213 bool isHvacFlagSetpointTemperatureHeatSet() const;
214 bool isHvacFlagSetpointTemperatureCoolSet() const;
215 bool isHvacFlagHeating() const;
216 bool isHvacFlagCooling() const;
217 bool isHvacFlagWeeklySchedule() const;
218 bool isHvacFlagFanEnabled() const;
219 bool isHvacFlagThermometerError() const;
220 bool isHvacFlagClockError() const;
221 bool isHvacFlagCountdownTimer() const;
222 bool isHvacFlagForcedOffBySensor() const;
223 enum HvacCoolSubfunctionFlag getHvacFlagCoolSubfunction() const;
224 bool isHvacFlagWeeklyScheduleTemporalOverride() const;
225 bool isHvacFlagBatteryCoverOpen() const;
226 bool isHvacFlagCalibrationError() const;
227 bool isHvacFlagAntifreezeOverheatActive() const;
228
229 static bool isHvacFlagSetpointTemperatureHeatSet(const THVACValue *hvacValue);
230 static bool isHvacFlagSetpointTemperatureCoolSet(const THVACValue *hvacValue);
231 static bool isHvacFlagHeating(const THVACValue *hvacValue);
232 static bool isHvacFlagCooling(const THVACValue *hvacValue);
233 static bool isHvacFlagWeeklySchedule(const THVACValue *hvacValue);
234 static bool isHvacFlagFanEnabled(const THVACValue *hvacValue);
235 static bool isHvacFlagThermometerError(const THVACValue *hvacValue);
236 static bool isHvacFlagClockError(const THVACValue *hvacValue);
237 static bool isHvacFlagCountdownTimer(const THVACValue *hvacValue);
238 static bool isHvacFlagForcedOffBySensor(const THVACValue *hvacValue);
239 static enum HvacCoolSubfunctionFlag getHvacFlagCoolSubfunction(
240 const THVACValue *hvacValue);
241 static bool isHvacFlagWeeklyScheduleTemporalOverride(
242 const THVACValue *hvacValue);
243 static bool isHvacFlagBatteryCoverOpen(const THVACValue *hvacValue);
244 static bool isHvacFlagCalibrationError(const THVACValue *hvacValue);
245 static bool isHvacFlagAntifreezeOverheatActive(const THVACValue *hvacValue);
246
247 static void setHvacSetpointTemperatureHeat(THVACValue *hvacValue,
248 int16_t setpointTemperatureHeat);
249 static void setHvacSetpointTemperatureCool(THVACValue *hvacValue,
250 int16_t setpointTemperatureCool);
251
252 THVACValue *getValueHvac();
253 const THVACValue *getValueHvac() const;
254 static bool isHvacValueValid(const THVACValue *hvacValue);
255
256 virtual bool isExtended() const;
257 bool isUpdateReady() const;
258 int getChannelNumber() const;
259 uint32_t getChannelType() const;
260
261 void setType(uint32_t type);
262
263 // setDefault and setDefaultFunction are the same methods.
264 // Second was added for better readability
265 void setDefault(uint32_t value);
266
273 void setDefaultFunction(uint32_t function);
274 uint32_t getDefaultFunction() const;
275 bool isFunctionValid(uint32_t function) const;
276 void setFlag(uint64_t flag);
277 void unsetFlag(uint64_t flag);
278 uint64_t getFlags() const;
279 void setFuncList(uint32_t functions);
280 uint32_t getFuncList() const;
281 void addToFuncList(uint32_t function);
282 void removeFromFuncList(uint32_t function);
283 void setActionTriggerCaps(uint32_t caps);
284 uint32_t getActionTriggerCaps();
285
286 void setValidityTimeSec(uint32_t timeSec);
287 virtual void sendUpdate();
288 virtual TSuplaChannelExtendedValue *getExtValue();
289 // Returns true when value was properly converted to EM value.
290 // "out" has to be valid pointer to allocated structure.
291 virtual bool getExtValueAsElectricityMeter(
293 void setCorrection(double correction, bool forSecondaryValue = false);
294 bool isSleepingEnabled();
295 bool isWeeklyScheduleAvailable();
296
297 // Returns true if channel is battery powered (for channel state info)
298 bool isBatteryPoweredFieldEnabled() const;
299 bool isBatteryPowered() const;
300 // sets battery powered flag
301 void setBatteryPowered(bool);
302
308 uint8_t getBatteryLevel() const;
309
315 void setBatteryLevel(int level);
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
358 void onRegistered();
359 void setSendGetConfig();
360
361 bool isChannelStateEnabled() const;
362 void clearSendValue();
363
364 protected:
365 void setSendValue();
366 bool isValueUpdateReady() const;
367
368 void clearSendGetConfig();
369 bool isGetConfigRequested() const;
370
371 void setSendInitialCaption();
372 void clearSendInitialCaption();
373 bool isInitialCaptionUpdateReady() const;
374
375 void setSendStateInfo();
376 void clearSendStateInfo();
377 bool isStateInfoUpdateReady() const;
378
379 static Channel *firstPtr;
380 static int startingChannelNumber;
381 Channel *nextPtr = nullptr;
382
383 char *initialCaption = nullptr;
384
385 uint32_t functionsBitmap = 0;
386
387 uint64_t channelFlags = 0;
388 uint32_t validityTimeSec = 0;
389
390 int16_t channelNumber = -1;
391
392 uint16_t defaultFunction =
393 0; // function in proto use 32 bit, but there are no functions defined so
394 // far that use more than 16 bits
395
396 uint8_t changedFields = 0; // keeps track of pending updates
397
398 uint8_t batteryLevel = 255; // 0 - 100%; 255 - not used
399 uint8_t batteryPowered = 0; // 0 - not used, 1 - true, 2 - false
400 unsigned char bridgeSignalStrength = 255; // 0 - 100%; 255 - not used
401
402 // registration parameter
403 ChannelType channelType = ChannelType::NOT_SET;
404
405 uint8_t state = 0;
406 uint8_t defaultIcon = 0;
407 uint8_t subDeviceId = 0;
408
409 union {
410 int8_t value[SUPLA_CHANNELVALUE_SIZE] = {};
411 TActionTriggerProperties actionTriggerProperties;
412 THVACValue hvacValue;
413 };
414};
415
416}; // namespace Supla
417
418#endif // SRC_SUPLA_CHANNELS_CHANNEL_H_
bool isValveMotorProblemFlagActive() const
Returns the motor problem flag of the Valve channel.
Definition channel.cpp:2024
uint8_t getValveOpenState() const
Returns the open state (open/close) of the Valve channel.
Definition channel.cpp:1998
void setValveMotorProblemFlag(bool active)
Sets the motor problem flag of the Valve channel.
Definition channel.cpp:1983
void setDefaultIcon(uint8_t iconId)
Sets default icon.
Definition channel.cpp:1530
void setValveManuallyClosedFlag(bool active)
Sets the manually closed flag of the Valve channel.
Definition channel.cpp:1967
bool isValveFloodingFlagActive() const
Returns the flooding flag of the Valve channel.
Definition channel.cpp:2014
void setDefaultFunction(uint32_t function)
Set default function.
Definition channel.cpp:337
void setBatteryLevel(int level)
Sets battery level.
Definition channel.cpp:793
void setValveFloodingFlag(bool active)
Sets the flooding flag of the Valve channel.
Definition channel.cpp:1952
uint8_t getDefaultIcon() const
Returns default icon.
Definition channel.cpp:1534
uint8_t getBatteryLevel() const
Returns battery level.
Definition channel.cpp:776
bool isValveManuallyClosedFlagActive() const
Returns the manually closed flag of the Valve channel.
Definition channel.cpp:2019
bool isValveOpen() const
Returns the open state (open/close) of the Valve channel.
Definition channel.cpp:2010
void setValveOpenState(uint8_t openState)
Sets the open state (open/close) of the Valve channel.
Definition channel.cpp:1913
Definition proto.h:854
Definition proto.h:2122
Definition proto.h:2087
Definition proto.h:969
Definition proto.h:995
Definition proto.h:2010
Definition proto.h:912
Definition proto.h:782