supla-device
Loading...
Searching...
No Matches
container.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
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_SENSOR_CONTAINER_H_
20#define SRC_SUPLA_SENSOR_CONTAINER_H_
21
22#include <supla/channel_element.h>
23#include <supla/action_handler.h>
24
25namespace Supla {
26namespace Html {
28} // namespace Html
29
30namespace Sensor {
31
32#pragma pack(push, 1)
33struct SensorData {
34 uint8_t fillLevel = 0;
35 uint8_t channelNumber = 255; // not used
36};
37
39 uint8_t warningAboveLevel = 0; // 0 - not set, 1-101 for 0-100%
40 uint8_t alarmAboveLevel = 0; // 0 - not set, 1-101 for 0-100%
41 uint8_t warningBelowLevel = 0; // 0 - not set, 1-101 for 0-100%
42 uint8_t alarmBelowLevel = 0; // 0 - not set, 1-101 for 0-100%
43
44 uint8_t muteAlarmSoundWithoutAdditionalAuth = 0; // 0 - admin login is
45 // required, 1 - regular
46 // user is allowed
47 SensorData sensorData[10] = {};
48};
49#pragma pack(pop)
50
51enum class SensorState {
52 Unknown = 0,
53 Active = 1,
54 Inactive = 2,
55 Offline = 3
56};
57
58class Container : public ChannelElement, public ActionHandler {
59 public:
61 Container();
62
71 void setInternalLevelReporting(bool internalLevelReporting);
72
78 bool isInternalLevelReporting() const;
79
80 void iterateAlways() override;
81 void onLoadConfig(SuplaDeviceClass *) override;
82 Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
83 bool local = false) override;
84 void fillChannelConfig(void *channelConfig,
85 int *size,
86 uint8_t configType) override;
88
89 void handleAction(int event, int action) override;
90
91 void printConfig() const;
92 void saveConfig();
93
94 // should return 0-100 value for 0-100 %, -1 if not available
95 virtual int readNewValue();
96
97 // 0-100 value for 0-100 %, -1 if not available
98 void setValue(int value);
99
100 bool isAlarmActive() const;
101 bool isWarningActive() const;
102 bool isInvalidSensorStateActive() const;
103 bool isSoundAlarmOn() const;
104
111 bool isExternalSoundAlarmOn() const;
112
113 virtual void setReadIntervalMs(uint32_t timeMs);
114
115 // set warning level as 0-100 value, where
116 // -1 - not set, 1-100 for 0-100%
117 void setWarningAboveLevel(int8_t warningAboveLevel);
118 // returns 0-100 value for 0-100 %, -1 if not available
119 int8_t getWarningAboveLevel() const;
120 bool isWarningAboveLevelSet() const;
121
122 // set alarm level as 0-100 value, where
123 // -1 - not set, 0-100 for 0-100%
124 void setAlarmAboveLevel(int8_t alarmAboveLevel);
125 // returns 0-100 value for 0-100 %, -1 if not available
126 int8_t getAlarmAboveLevel() const;
127 bool isAlarmAboveLevelSet() const;
128
129 // set warning level as 0-100 value, where
130 // -1 - not set, 1-100 for 0-100%
131 void setWarningBelowLevel(int8_t warningBelowLevel);
132 // returns 0-100 value for 0-100 %, -1 if not available
133 int8_t getWarningBelowLevel() const;
134 bool isWarningBelowLevelSet() const;
135
136 // set alarm level as 0-100 value, where
137 // -1 - not set, 1-100 for 0-100%
138 void setAlarmBelowLevel(int8_t alarmBelowLevel);
139 // returns 0-100 value for 0-100 %, -1 if not available
140 int8_t getAlarmBelowLevel() const;
141 bool isAlarmBelowLevelSet() const;
142
143 void setMuteAlarmSoundWithoutAdditionalAuth(
144 bool muteAlarmSoundWithoutAdditionalAuth);
145 bool isMuteAlarmSoundWithoutAdditionalAuth() const;
146
156 bool setSensorData(uint8_t channelNumber, uint8_t fillLevel);
162 void removeSensorData(uint8_t channelNumber);
163
172 int getFillLevelForSensor(uint8_t channelNumber) const;
173
179 bool isSensorDataUsed() const;
180
186 bool isAlarmingUsed() const;
187
188 void setSoundAlarmSupported(bool soundAlarmSupported);
189 bool isSoundAlarmSupported() const;
190
196 void muteSoundAlarm();
197
198 void setExternalSoundAlarmOn();
199 void setExternalSoundAlarmOff();
200
201 protected:
202 void updateConfigField(uint8_t *configField, int8_t value);
203 int8_t getHighestSensorValueAndUpdateState();
204 void setAlarmActive(bool alarmActive);
205 void setWarningActive(bool warningActive);
206 void setInvalidSensorStateActive(bool invalidSensorStateActive);
207 void setSoundAlarmOn(uint8_t level);
208
220 bool checkSensorInvalidState(const int8_t currentFillLevel,
221 const int8_t tolerance = 0) const;
222
223 // returns -1 when sensor is not configured or on error
224 // returns 0 when sensor is not active
225 // returns 1 when sensor is active
226 enum SensorState getSensorState(const uint8_t channelNumber) const;
227 uint32_t lastReadTime = 0;
228 uint32_t readIntervalMs = 1000;
229 int8_t fillLevel = -1;
230 bool soundAlarmSupported = false;
231 uint8_t soundAlarmActivatedLevel = 0;
232 bool externalSoundAlarm = false;
233 bool sensorOfflineReported = false;
234
235 ContainerConfig config = {};
236};
237
238static_assert(sizeof(ContainerConfig().sensorData) / sizeof(SensorData) ==
239 sizeof(TChannelConfig_Container().SensorInfo) /
240 sizeof(TContainer_SensorInfo));
241
242}; // namespace Sensor
243}; // namespace Supla
244
245
246#endif // SRC_SUPLA_SENSOR_CONTAINER_H_
Definition SuplaDevice.h:93
Definition container_parameters.h:29
bool setSensorData(uint8_t channelNumber, uint8_t fillLevel)
Sets sensor data for given channel number.
Definition container.cpp:244
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition container.cpp:412
bool isSensorDataUsed() const
Checks if any sensor data is set.
Definition container.cpp:298
int getFillLevelForSensor(uint8_t channelNumber) const
Returns fill level for sensor with given channel number.
Definition container.cpp:289
void setInternalLevelReporting(bool internalLevelReporting)
Sets the internal level reporting flag.
Definition container.cpp:40
bool isExternalSoundAlarmOn() const
Checks if the sound alarm was enabled for external source (other than container itself)
Definition container.cpp:649
bool isInternalLevelReporting() const
Checks if the internal level reporting flag is enabled.
Definition container.cpp:50
bool isAlarmingUsed() const
Checks if any alarm or warning level is set (both above and below)
Definition container.cpp:391
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition container.cpp:618
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition container.cpp:55
void removeSensorData(uint8_t channelNumber)
Removes sensor data for given channel number.
Definition container.cpp:279
bool checkSensorInvalidState(const int8_t currentFillLevel, const int8_t tolerance=0) const
Checks if sensor is in invalid state.
Definition container.cpp:343
void muteSoundAlarm()
Mutes the sound alarmm by clearing channel value flag, but does not clear soundAlarmActivated flag,...
Definition container.cpp:194
Definition container.h:38
Definition container.h:33
Definition proto.h:3564
Definition proto.h:3553
Definition proto.h:2987
Definition proto.h:2248