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 uint8_t applyChannelConfig(TSD_ChannelConfig *result,
83 bool local = false) override;
84 void fillChannelConfig(void *channelConfig, int *size) override;
86
87 void handleAction(int event, int action) override;
88
89 void printConfig() const;
90 void saveConfig();
91
92 // should return 0-100 value for 0-100 %, -1 if not available
93 virtual int readNewValue();
94
95 // 0-100 value for 0-100 %, -1 if not available
96 void setValue(int value);
97
98 bool isAlarmActive() const;
99 bool isWarningActive() const;
100 bool isInvalidSensorStateActive() const;
101 bool isSoundAlarmOn() const;
102
109 bool isExternalSoundAlarmOn() const;
110
111 virtual void setReadIntervalMs(uint32_t timeMs);
112
113 // set warning level as 0-100 value, where
114 // -1 - not set, 1-100 for 0-100%
115 void setWarningAboveLevel(int8_t warningAboveLevel);
116 // returns 0-100 value for 0-100 %, -1 if not available
117 int8_t getWarningAboveLevel() const;
118 bool isWarningAboveLevelSet() const;
119
120 // set alarm level as 0-100 value, where
121 // -1 - not set, 0-100 for 0-100%
122 void setAlarmAboveLevel(int8_t alarmAboveLevel);
123 // returns 0-100 value for 0-100 %, -1 if not available
124 int8_t getAlarmAboveLevel() const;
125 bool isAlarmAboveLevelSet() const;
126
127 // set warning level as 0-100 value, where
128 // -1 - not set, 1-100 for 0-100%
129 void setWarningBelowLevel(int8_t warningBelowLevel);
130 // returns 0-100 value for 0-100 %, -1 if not available
131 int8_t getWarningBelowLevel() const;
132 bool isWarningBelowLevelSet() const;
133
134 // set alarm level as 0-100 value, where
135 // -1 - not set, 1-100 for 0-100%
136 void setAlarmBelowLevel(int8_t alarmBelowLevel);
137 // returns 0-100 value for 0-100 %, -1 if not available
138 int8_t getAlarmBelowLevel() const;
139 bool isAlarmBelowLevelSet() const;
140
141 void setMuteAlarmSoundWithoutAdditionalAuth(
142 bool muteAlarmSoundWithoutAdditionalAuth);
143 bool isMuteAlarmSoundWithoutAdditionalAuth() const;
144
154 bool setSensorData(uint8_t channelNumber, uint8_t fillLevel);
160 void removeSensorData(uint8_t channelNumber);
161
170 int getFillLevelForSensor(uint8_t channelNumber) const;
171
177 bool isSensorDataUsed() const;
178
184 bool isAlarmingUsed() const;
185
186 void setSoundAlarmSupported(bool soundAlarmSupported);
187 bool isSoundAlarmSupported() const;
188
194 void muteSoundAlarm();
195
196 void setExternalSoundAlarmOn();
197 void setExternalSoundAlarmOff();
198
199 protected:
200 void updateConfigField(uint8_t *configField, int8_t value);
201 int8_t getHighestSensorValueAndUpdateState();
202 void setAlarmActive(bool alarmActive);
203 void setWarningActive(bool warningActive);
204 void setInvalidSensorStateActive(bool invalidSensorStateActive);
205 void setSoundAlarmOn(uint8_t level);
206
218 bool checkSensorInvalidState(const int8_t currentFillLevel,
219 const int8_t tolerance = 0) const;
220
221 // returns -1 when sensor is not configured or on error
222 // returns 0 when sensor is not active
223 // returns 1 when sensor is active
224 enum SensorState getSensorState(const uint8_t channelNumber) const;
225 uint32_t lastReadTime = 0;
226 uint32_t readIntervalMs = 1000;
227 int8_t fillLevel = -1;
228 bool soundAlarmSupported = false;
229 uint8_t soundAlarmActivatedLevel = 0;
230 bool externalSoundAlarm = false;
231 bool sensorOfflineReported = false;
232
233 ContainerConfig config = {};
234};
235
236static_assert(sizeof(ContainerConfig().sensorData) / sizeof(SensorData) ==
237 sizeof(TChannelConfig_Container().SensorInfo) /
238 sizeof(TContainer_SensorInfo));
239
240}; // namespace Sensor
241}; // namespace Supla
242
243
244#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:242
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition container.cpp:410
bool isSensorDataUsed() const
Checks if any sensor data is set.
Definition container.cpp:296
int getFillLevelForSensor(uint8_t channelNumber) const
Returns fill level for sensor with given channel number.
Definition container.cpp:287
void setInternalLevelReporting(bool internalLevelReporting)
Sets the internal level reporting flag.
Definition container.cpp:38
bool isExternalSoundAlarmOn() const
Checks if the sound alarm was enabled for external source (other than container itself)
Definition container.cpp:642
bool isInternalLevelReporting() const
Checks if the internal level reporting flag is enabled.
Definition container.cpp:48
bool isAlarmingUsed() const
Checks if any alarm or warning level is set (both above and below)
Definition container.cpp:389
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition container.cpp:611
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition container.cpp:53
void removeSensorData(uint8_t channelNumber)
Removes sensor data for given channel number.
Definition container.cpp:277
bool checkSensorInvalidState(const int8_t currentFillLevel, const int8_t tolerance=0) const
Checks if sensor is in invalid state.
Definition container.cpp:341
void muteSoundAlarm()
Mutes the sound alarmm by clearing channel value flag, but does not clear soundAlarmActivated flag,...
Definition container.cpp:192
Definition container.h:38
Definition container.h:33
Definition proto.h:3489
Definition proto.h:3478
Definition proto.h:2912
Definition proto.h:2246