HomeWaterLeaksDetection
ALeakDetectable Class Referenceabstract

#include <ALeakDetectable.h>

Public Types

enum  Type { Low, High, Total }
 The type of the water leak detection algorithm. More...
 

Public Member Functions

 ALeakDetectable (PulseCounter *pulseCounter, Type type, LeakDetectionConfig_t normalConfig, LeakDetectionConfig_t alarmConfig)
 Constructor of the class. More...
 
virtual ~ALeakDetectable ()
 Destructor of the class. More...
 
int isActive () const
 Returns a flag whether of not a leak has been detected and the bypass is off. More...
 
void changeStateOfHomeAlarm (bool state)
 Changes the state of the home alarm. More...
 
LeakDetectionConfig_t getAlarmConfig ()
 Returns the current alarm config. More...
 
LeakDetectionConfig_t getNormalConfig ()
 Returns the current normal config. More...
 
virtual String getFormatOfSettingsToSave ()=0
 Returns a string containing the current settings of the detection algorithm. More...
 
void updateNormalConfig (LeakDetectionConfig_t newNormalConfig)
 Updates the normal settings. More...
 
void updateAlarmConfig (LeakDetectionConfig_t newAlarmConfig)
 Updates the alarm settings. More...
 
virtual void update ()=0
 This method is called for updating its state. More...
 
virtual void reset ()=0
 This method resets the algorithm. More...
 

Protected Member Functions

void applyNewConfig ()
 Applies the new config configuration. More...
 
String getType () const
 Returns the type of the water leak detection algorithm. More...
 

Protected Attributes

PulseCounterpulseCounter
 instance of a pulse counter (input of the system) More...
 
LeakDetectionConfig_t normalConfig
 normal configuarion for when the house is occupied More...
 
LeakDetectionConfig_t alarmConfig
 alarm configuration for when there's nobody in the house More...
 
LeakDetectionConfig_tconfig
 pointer to the current configuration More...
 
int bypass
 bypass pin More...
 
int oldBypassValue
 old bypass value (used for sending e-mails) More...
 
int active
 indication if a leak has been detected + bypass is off More...
 
int stateOfHomeAlarm
 the current state of the home alarm More...
 
bool detected
 indication if a leak has been detected More...
 
int resetWhenDetected
 the reset value (%) when a leak was detected More...
 
String timeOfDetection
 time when the leak has been detected More...
 
Type type
 the type of the water leak detection algorithm More...
 
LeakDetectionConfig_t newNormalConfig
 new parameters of the normal config when the user changes them More...
 
LeakDetectionConfig_t newAlarmConfig
 new parameters of the alarm config when the user changes them More...
 
int requestUpdateNormalConfig
 flag if the new normal config should be applied More...
 
int requestUpdateAlarmConfig
 flag if the new alarms config should be applied More...
 

Private Member Functions

virtual void testActiveLeak ()=0
 Test is a water leak has been detected. More...
 
virtual void testResetLeak ()=0
 Test is a water leak has been detected. More...
 

Detailed Description

Author
silhavyj A17B0362P

This class sepresents an abstraction of a water leak detection algorithm. It holds all the common variables, defines the common methods, etc.

Definition at line 52 of file ALeakDetectable.h.

Member Enumeration Documentation

◆ Type

The type of the water leak detection algorithm.

Enumerator
Low 

low water leak detection algorithm

High 

high water leak detection algorithm

Total 

total water leak detection algorithm

Definition at line 57 of file ALeakDetectable.h.

57  {
58  Low,
59  High,
60  Total
61  };

Constructor & Destructor Documentation

◆ ALeakDetectable()

ALeakDetectable::ALeakDetectable ( PulseCounter pulseCounter,
Type  type,
LeakDetectionConfig_t  normalConfig,
LeakDetectionConfig_t  alarmConfig 
)

Constructor of the class.

Parameters
pulseCounter- instance of PulseCounter which is used as the main input of all water leak detection algorithms
type- type of the water leak detection algorithm (high, low, total)
normalConfig- default normal configuration (defined in LimitsDefinition.h)
alarmConfig- default alarms configuration (defined in LimitsDefinition.h)

Definition at line 3 of file ALeakDetectable.cpp.

6  {
7 
8  // store all the params given through the constructor
9  this->normalConfig = normalConfig;
10  this->alarmConfig = alarmConfig;
13  this->type = type;
14  this->pulseCounter = pulseCounter;
15 
16  // the normal settings are used by default
18 
19  // initialize default values
22  stateOfHomeAlarm = 0;
23  oldBypassValue = 0;
24 }

References alarmConfig, config, newAlarmConfig, newNormalConfig, normalConfig, oldBypassValue, pulseCounter, requestUpdateAlarmConfig, requestUpdateNormalConfig, stateOfHomeAlarm, and type.

◆ ~ALeakDetectable()

virtual ALeakDetectable::~ALeakDetectable ( )
inlinevirtual

Destructor of the class.

Definition at line 124 of file ALeakDetectable.h.

124 {};

Member Function Documentation

◆ applyNewConfig()

void ALeakDetectable::applyNewConfig ( )
protected

Applies the new config configuration.

This method is called on each reset of the algorithm. If the appropriate flag is set, the new settings will be put in place.

Definition at line 34 of file ALeakDetectable.cpp.

34  {
35  // update the normal settings
37  #ifdef EMAIL_NOTIFICATION
38  sendEmailAboutSettings(EmailSender::APPLIED_NEW_SETTING, normalConfig, newNormalConfig, false);
39  #endif
42  }
43  // update the alarm settings
45  #ifdef EMAIL_NOTIFICATION
46  sendEmailAboutSettings(EmailSender::APPLIED_NEW_SETTING, alarmConfig, newAlarmConfig, true);
47  #endif
50  }
51  // set the current settings according to
52  // the state of the home alarm
53  if (stateOfHomeAlarm)
55  else config = &normalConfig;
56 }

References alarmConfig, EmailSender::APPLIED_NEW_SETTING, config, newAlarmConfig, newNormalConfig, normalConfig, requestUpdateAlarmConfig, requestUpdateNormalConfig, and stateOfHomeAlarm.

Referenced by LowLeakDetection::reset(), HighLeakDetection::reset(), TotalLeakDetection::testResetLeak(), LowLeakDetection::testResetLeak(), and HighLeakDetection::testResetLeak().

◆ changeStateOfHomeAlarm()

void ALeakDetectable::changeStateOfHomeAlarm ( bool  state)

Changes the state of the home alarm.

Parameters
statenew state of the home alarm

Definition at line 93 of file ALeakDetectable.cpp.

93  {
94  stateOfHomeAlarm = state;
95 }

References stateOfHomeAlarm.

◆ getAlarmConfig()

LeakDetectionConfig_t ALeakDetectable::getAlarmConfig ( )

Returns the current alarm config.

Returns
the current alarm config

Definition at line 26 of file ALeakDetectable.cpp.

26  {
27  return alarmConfig;
28 }

References alarmConfig.

Referenced by LeaksController::changeSettings().

◆ getFormatOfSettingsToSave()

virtual String ALeakDetectable::getFormatOfSettingsToSave ( )
pure virtual

Returns a string containing the current settings of the detection algorithm.

It contains both kinds of configurations. The settings will be stored on the SD card so it can be loaded on the next start of the system.

Returns
settings in a string format

Implemented in HighLeakDetection, and LowLeakDetection.

◆ getNormalConfig()

LeakDetectionConfig_t ALeakDetectable::getNormalConfig ( )

Returns the current normal config.

Returns
the current normal config

Definition at line 30 of file ALeakDetectable.cpp.

30  {
31  return normalConfig;
32 }

References normalConfig.

Referenced by LeaksController::changeSettings().

◆ getType()

String ALeakDetectable::getType ( ) const
protected

Returns the type of the water leak detection algorithm.

Returns
the type of the detection algorithm

Definition at line 84 of file ALeakDetectable.cpp.

84  {
85  switch (type) {
86  case High: return "High";
87  case Low: return "Low";
88  case Total: return "Total";
89  }
90  return "unknown";
91 }

References High, Low, Total, and type.

Referenced by LowLeakDetection::update(), and HighLeakDetection::update().

◆ isActive()

int ALeakDetectable::isActive ( ) const
inline

Returns a flag whether of not a leak has been detected and the bypass is off.

Returns
flag (1/0) indicating to close up the main valve

Definition at line 128 of file ALeakDetectable.h.

128 { return active; }

References active.

◆ reset()

virtual void ALeakDetectable::reset ( )
pure virtual

This method resets the algorithm.

This is called either when the user manually presses the reset button or when the algorithm resets by itself.

Implemented in HighLeakDetection, LowLeakDetection, and TotalLeakDetection.

◆ testActiveLeak()

virtual void ALeakDetectable::testActiveLeak ( )
privatepure virtual

Test is a water leak has been detected.

The implementation depends on the particular algorithm.

Implemented in TotalLeakDetection, HighLeakDetection, and LowLeakDetection.

◆ testResetLeak()

virtual void ALeakDetectable::testResetLeak ( )
privatepure virtual

Test is a water leak has been detected.

The implementation depends on the particular algorithm.

Implemented in HighLeakDetection, LowLeakDetection, and TotalLeakDetection.

◆ update()

virtual void ALeakDetectable::update ( )
pure virtual

This method is called for updating its state.

It updates the algorithm in order to find out if there's a leak taking place.

Implemented in HighLeakDetection, and LowLeakDetection.

◆ updateAlarmConfig()

void ALeakDetectable::updateAlarmConfig ( LeakDetectionConfig_t  newAlarmConfig)

Updates the alarm settings.

The settings won't be applied right away. Instead, the flag will be set and the new settings will be put in place when the algorithm resets.

Parameters
newAlarmConfigthe new alarm settings

Definition at line 71 of file ALeakDetectable.cpp.

71  {
72  if (this->alarmConfig != newAlarmConfig) { // test if the settings are not the same
73  this->newAlarmConfig = newAlarmConfig; // store the new settings
74  requestUpdateAlarmConfig = 1; // set the flag so it can be applied when the algorithm resets
75 
76  // if e-mail notifications are enabled send
77  // an e-mail to the user
78  #ifdef EMAIL_NOTIFICATION
79  sendEmailAboutSettings(EmailSender::CHANGED_SETTINGS, alarmConfig, newAlarmConfig, true);
80  #endif
81  }
82 }

References alarmConfig, EmailSender::CHANGED_SETTINGS, newAlarmConfig, and requestUpdateAlarmConfig.

Referenced by LeaksController::changeSettings().

◆ updateNormalConfig()

void ALeakDetectable::updateNormalConfig ( LeakDetectionConfig_t  newNormalConfig)

Updates the normal settings.

The settings won't be applied right away. Instead, the flag will be set and the new setting will be put in place when the algorithm resets.

Parameters
newNormalConfigthe new normal settings

Definition at line 58 of file ALeakDetectable.cpp.

58  {
59  if (this->normalConfig != newNormalConfig) { // test if the settings are not the same
60  this->newNormalConfig = newNormalConfig; // store the new settings
61  requestUpdateNormalConfig = 1; // set the flag so it can be applied when the algorithm resets
62 
63  // if e-mail notifications are enabled send
64  // an e-mail to the user
65  #ifdef EMAIL_NOTIFICATION
66  sendEmailAboutSettings(EmailSender::CHANGED_SETTINGS, normalConfig, newNormalConfig, false);
67  #endif
68  }
69 }

References EmailSender::CHANGED_SETTINGS, newNormalConfig, normalConfig, and requestUpdateNormalConfig.

Referenced by LeaksController::changeSettings().

Member Data Documentation

◆ active

◆ alarmConfig

LeakDetectionConfig_t ALeakDetectable::alarmConfig
protected

alarm configuration for when there's nobody in the house

Definition at line 67 of file ALeakDetectable.h.

Referenced by ALeakDetectable(), applyNewConfig(), getAlarmConfig(), and updateAlarmConfig().

◆ bypass

◆ config

◆ detected

◆ newAlarmConfig

LeakDetectionConfig_t ALeakDetectable::newAlarmConfig
protected

new parameters of the alarm config when the user changes them

Definition at line 79 of file ALeakDetectable.h.

Referenced by ALeakDetectable(), applyNewConfig(), LowLeakDetection::getFormatOfSettingsToSave(), HighLeakDetection::getFormatOfSettingsToSave(), and updateAlarmConfig().

◆ newNormalConfig

LeakDetectionConfig_t ALeakDetectable::newNormalConfig
protected

new parameters of the normal config when the user changes them

Definition at line 78 of file ALeakDetectable.h.

Referenced by ALeakDetectable(), applyNewConfig(), LowLeakDetection::getFormatOfSettingsToSave(), HighLeakDetection::getFormatOfSettingsToSave(), and updateNormalConfig().

◆ normalConfig

LeakDetectionConfig_t ALeakDetectable::normalConfig
protected

normal configuarion for when the house is occupied

Definition at line 66 of file ALeakDetectable.h.

Referenced by ALeakDetectable(), applyNewConfig(), getNormalConfig(), and updateNormalConfig().

◆ oldBypassValue

int ALeakDetectable::oldBypassValue
protected

old bypass value (used for sending e-mails)

Definition at line 70 of file ALeakDetectable.h.

Referenced by ALeakDetectable(), LowLeakDetection::update(), and HighLeakDetection::update().

◆ pulseCounter

◆ requestUpdateAlarmConfig

int ALeakDetectable::requestUpdateAlarmConfig
protected

flag if the new alarms config should be applied

Definition at line 81 of file ALeakDetectable.h.

Referenced by ALeakDetectable(), applyNewConfig(), and updateAlarmConfig().

◆ requestUpdateNormalConfig

int ALeakDetectable::requestUpdateNormalConfig
protected

flag if the new normal config should be applied

Definition at line 80 of file ALeakDetectable.h.

Referenced by ALeakDetectable(), applyNewConfig(), and updateNormalConfig().

◆ resetWhenDetected

int ALeakDetectable::resetWhenDetected
protected

◆ stateOfHomeAlarm

int ALeakDetectable::stateOfHomeAlarm
protected

the current state of the home alarm

Definition at line 72 of file ALeakDetectable.h.

Referenced by ALeakDetectable(), applyNewConfig(), and changeStateOfHomeAlarm().

◆ timeOfDetection

String ALeakDetectable::timeOfDetection
protected

◆ type

Type ALeakDetectable::type
protected

the type of the water leak detection algorithm

Definition at line 76 of file ALeakDetectable.h.

Referenced by ALeakDetectable(), and getType().


The documentation for this class was generated from the following files:
EmailSender::CHANGED_SETTINGS
@ CHANGED_SETTINGS
when the user changes settings
Definition: EmailSender.h:51
ALeakDetectable::alarmConfig
LeakDetectionConfig_t alarmConfig
alarm configuration for when there's nobody in the house
Definition: ALeakDetectable.h:67
ALeakDetectable::Total
@ Total
total water leak detection algorithm
Definition: ALeakDetectable.h:60
ALeakDetectable::requestUpdateAlarmConfig
int requestUpdateAlarmConfig
flag if the new alarms config should be applied
Definition: ALeakDetectable.h:81
ALeakDetectable::type
Type type
the type of the water leak detection algorithm
Definition: ALeakDetectable.h:76
ALeakDetectable::Low
@ Low
low water leak detection algorithm
Definition: ALeakDetectable.h:58
ALeakDetectable::config
LeakDetectionConfig_t * config
pointer to the current configuration
Definition: ALeakDetectable.h:68
ALeakDetectable::High
@ High
high water leak detection algorithm
Definition: ALeakDetectable.h:59
ALeakDetectable::stateOfHomeAlarm
int stateOfHomeAlarm
the current state of the home alarm
Definition: ALeakDetectable.h:72
ALeakDetectable::newNormalConfig
LeakDetectionConfig_t newNormalConfig
new parameters of the normal config when the user changes them
Definition: ALeakDetectable.h:78
EmailSender::APPLIED_NEW_SETTING
@ APPLIED_NEW_SETTING
when the new settings are applied
Definition: EmailSender.h:52
ALeakDetectable::active
int active
indication if a leak has been detected + bypass is off
Definition: ALeakDetectable.h:71
ALeakDetectable::newAlarmConfig
LeakDetectionConfig_t newAlarmConfig
new parameters of the alarm config when the user changes them
Definition: ALeakDetectable.h:79
ALeakDetectable::oldBypassValue
int oldBypassValue
old bypass value (used for sending e-mails)
Definition: ALeakDetectable.h:70
ALeakDetectable::pulseCounter
PulseCounter * pulseCounter
instance of a pulse counter (input of the system)
Definition: ALeakDetectable.h:65
ALeakDetectable::requestUpdateNormalConfig
int requestUpdateNormalConfig
flag if the new normal config should be applied
Definition: ALeakDetectable.h:80
ALeakDetectable::normalConfig
LeakDetectionConfig_t normalConfig
normal configuarion for when the house is occupied
Definition: ALeakDetectable.h:66