supla-device
Loading...
Searching...
No Matches
container.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_SENSOR_CONTAINER_H_
5#define SRC_SUPLA_SENSOR_CONTAINER_H_
6
7#include <supla/channel_element.h>
8#include <supla/action_handler.h>
9
10namespace Supla {
11namespace Html {
12class ContainerParameters;
13} // namespace Html
14
15namespace Sensor {
16
17#pragma pack(push, 1)
18struct SensorData {
19 uint8_t fillLevel = 0;
20 uint8_t channelNumber = 255; // not used
21};
22
24 uint8_t warningAboveLevel = 0; // 0 - not set, 1-101 for 0-100%
25 uint8_t alarmAboveLevel = 0; // 0 - not set, 1-101 for 0-100%
26 uint8_t warningBelowLevel = 0; // 0 - not set, 1-101 for 0-100%
27 uint8_t alarmBelowLevel = 0; // 0 - not set, 1-101 for 0-100%
28
29 uint8_t muteAlarmSoundWithoutAdditionalAuth = 0; // 0 - admin login is
30 // required, 1 - regular
31 // user is allowed
32 SensorData sensorData[10] = {};
33};
34#pragma pack(pop)
35
36enum class SensorState {
37 Unknown = 0,
38 Active = 1,
39 Inactive = 2,
40 Offline = 3
41};
42
43class Container : public ChannelElement, public ActionHandler {
44 public:
46 Container();
47
56 void setInternalLevelReporting(bool internalLevelReporting);
57
63 bool isInternalLevelReporting() const;
64
65 void iterateAlways() override;
66 void onLoadConfig(SuplaDeviceClass *) override;
67 Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
68 bool local = false) override;
69 void fillChannelConfig(void *channelConfig,
70 int *size,
71 uint8_t configType) override;
73
74 void handleAction(int event, int action) override;
75
76 void printConfig() const;
77 void saveConfig();
78
79 // should return 0-100 value for 0-100 %, -1 if not available
80 virtual int readNewValue();
81
82 // 0-100 value for 0-100 %, -1 if not available
83 void setValue(int value);
84
85 bool isAlarmActive() const;
86 bool isWarningActive() const;
87 bool isInvalidSensorStateActive() const;
88 bool isSoundAlarmOn() const;
89
96 bool isExternalSoundAlarmOn() const;
97
98 virtual void setReadIntervalMs(uint32_t timeMs);
99
100 // set warning level as 0-100 value, where
101 // -1 - not set, 1-100 for 0-100%
102 void setWarningAboveLevel(int8_t warningAboveLevel);
103 // returns 0-100 value for 0-100 %, -1 if not available
104 int8_t getWarningAboveLevel() const;
105 bool isWarningAboveLevelSet() const;
106
107 // set alarm level as 0-100 value, where
108 // -1 - not set, 0-100 for 0-100%
109 void setAlarmAboveLevel(int8_t alarmAboveLevel);
110 // returns 0-100 value for 0-100 %, -1 if not available
111 int8_t getAlarmAboveLevel() const;
112 bool isAlarmAboveLevelSet() const;
113
114 // set warning level as 0-100 value, where
115 // -1 - not set, 1-100 for 0-100%
116 void setWarningBelowLevel(int8_t warningBelowLevel);
117 // returns 0-100 value for 0-100 %, -1 if not available
118 int8_t getWarningBelowLevel() const;
119 bool isWarningBelowLevelSet() const;
120
121 // set alarm level as 0-100 value, where
122 // -1 - not set, 1-100 for 0-100%
123 void setAlarmBelowLevel(int8_t alarmBelowLevel);
124 // returns 0-100 value for 0-100 %, -1 if not available
125 int8_t getAlarmBelowLevel() const;
126 bool isAlarmBelowLevelSet() const;
127
128 void setMuteAlarmSoundWithoutAdditionalAuth(
129 bool muteAlarmSoundWithoutAdditionalAuth);
130 bool isMuteAlarmSoundWithoutAdditionalAuth() const;
131
141 bool setSensorData(uint8_t channelNumber, uint8_t fillLevel);
147 void removeSensorData(uint8_t channelNumber);
148
157 int getFillLevelForSensor(uint8_t channelNumber) const;
158
164 bool isSensorDataUsed() const;
165
171 bool isAlarmingUsed() const;
172
173 void setSoundAlarmSupported(bool soundAlarmSupported);
174 bool isSoundAlarmSupported() const;
175
181 void muteSoundAlarm();
182
183 void setExternalSoundAlarmOn();
184 void setExternalSoundAlarmOff();
185
186 protected:
187 void updateConfigField(uint8_t *configField, int8_t value);
188 int8_t getHighestSensorValueAndUpdateState();
189 void setAlarmActive(bool alarmActive);
190 void setWarningActive(bool warningActive);
191 void setInvalidSensorStateActive(bool invalidSensorStateActive);
192 void setSoundAlarmOn(uint8_t level);
193
205 bool checkSensorInvalidState(const int8_t currentFillLevel,
206 const int8_t tolerance = 0) const;
207
208 // returns -1 when sensor is not configured or on error
209 // returns 0 when sensor is not active
210 // returns 1 when sensor is active
211 enum SensorState getSensorState(const uint8_t channelNumber) const;
212 uint32_t lastReadTime = 0;
213 uint32_t readIntervalMs = 1000;
214 int8_t fillLevel = -1;
215 bool soundAlarmSupported = false;
216 uint8_t soundAlarmActivatedLevel = 0;
217 bool externalSoundAlarm = false;
218 bool sensorOfflineReported = false;
219
220 ContainerConfig config = {};
221};
222
223static_assert(sizeof(ContainerConfig().sensorData) / sizeof(SensorData) ==
224 sizeof(TChannelConfig_Container().SensorInfo) /
225 sizeof(TContainer_SensorInfo));
226
227}; // namespace Sensor
228}; // namespace Supla
229
230
231#endif // SRC_SUPLA_SENSOR_CONTAINER_H_
Definition SuplaDevice.h:167
Definition action_handler.h:8
Definition channel_element.h:15
Definition container_parameters.h:14
Definition container.h:43
bool setSensorData(uint8_t channelNumber, uint8_t fillLevel)
Sets sensor data for given channel number.
Definition container.cpp:233
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition container.cpp:401
bool isSensorDataUsed() const
Checks if any sensor data is set.
Definition container.cpp:287
int getFillLevelForSensor(uint8_t channelNumber) const
Returns fill level for sensor with given channel number.
Definition container.cpp:278
void setInternalLevelReporting(bool internalLevelReporting)
Sets the internal level reporting flag.
Definition container.cpp:26
bool isExternalSoundAlarmOn() const
Checks if the sound alarm was enabled for external source (other than container itself)
Definition container.cpp:638
bool isInternalLevelReporting() const
Checks if the internal level reporting flag is enabled.
Definition container.cpp:36
bool isAlarmingUsed() const
Checks if any alarm or warning level is set (both above and below)
Definition container.cpp:380
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition container.cpp:607
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition container.cpp:41
void removeSensorData(uint8_t channelNumber)
Removes sensor data for given channel number.
Definition container.cpp:268
bool checkSensorInvalidState(const int8_t currentFillLevel, const int8_t tolerance=0) const
Checks if sensor is in invalid state.
Definition container.cpp:332
void muteSoundAlarm()
Mutes the sound alarmm by clearing channel value flag, but does not clear soundAlarmActivated flag,...
Definition container.cpp:183
Definition container.h:23
Definition container.h:18
Definition proto.h:3757
Definition proto.h:3746
Definition proto.h:3159
Definition proto.h:2315