Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_SwitchBehaviour.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Dec 20, 2019
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7
8#pragma once
9
11#include <logging/cs_Logger.h>
14#include <stdint.h>
15#include <test/cs_TestAccess.h>
16#include <util/cs_WireFormat.h>
17
18#include <optional>
19
26class SwitchBehaviour : public Behaviour {
27 friend class TestAccess<SwitchBehaviour>;
28
29public:
30 typedef std::array<uint8_t, WireFormat::size<Behaviour>() + WireFormat::size<PresenceCondition>()>
32
33 virtual ~SwitchBehaviour() = default;
34
36 uint8_t intensity,
37 uint8_t profileid,
38 DayOfWeekBitMask activedaysofweek,
41 PresenceCondition presencecondition);
42
45
46 virtual uint8_t* serialize(uint8_t* outbuff, size_t max_size) override;
47 virtual size_t serializedSize() const override;
48
49 virtual Type getType() const override { return Type::Switch; }
50
51 virtual void print();
52
53 // =========== Semantics ===========
54
55 // Returns true if time passed since between prevInRoomTimeStamp and current up time
56 // is less than presenceCondition.timeout. Else, returns false.
58
59 virtual bool requiresPresence() override;
60 virtual bool requiresAbsence() override;
62
67 virtual bool isValid(Time currenttime, PresenceStateDescription currentpresence);
68
69 // Presence description is cached in order to prevent
70 // that the behaviour flickers when a user is on the border of two rooms.
71 // (not there is a timeout in the presencehandler to check if the user hasn't disappeared,
72 // but it tries to describe the location as accurately as possible. Thus, when a user is
73 // detected in another room, the presence is immediately updated.)
74 bool isValid(PresenceStateDescription currentpresence); // cached version
75
76 // Because of the definition of isValid(PresenceStateDescription) in this class
77 // the base class function with the same name is shadowed. This using statement
78 // reintroduces the function name in this class's scope.
80
81protected:
82 // (serialized field)
84
85private:
86 // unserialized fields (runtime values)
87 std::optional<uint32_t> prevInRoomTimeStamp = {}; // when was the last call to _isValid that returned true?
88
89 // uncached version of ::isValid
90 bool _isValid(PresenceStateDescription currentpresence);
91};
bool isValid()
Checks if the data has valid values.
Class to derrive behaviours from, centralizing common variables such as from and until times.
Definition: cs_Behaviour.h:20
Type
Definition: cs_Behaviour.h:22
TimeOfDay until() const
Returns until (excl.) which time on this behaviour applies.
TimeOfDay from() const
Returns from (incl.) which time on this behaviour applies.
Definition: cs_PresenceCondition.h:14
Definition: cs_PresencePredicate.h:15
Class that holds the presence of a profile.
Definition: cs_PresenceDescription.h:23
Object that defines when a state transition should occur.
Definition: cs_SwitchBehaviour.h:26
virtual size_t serializedSize() const override
std::array< uint8_t, WireFormat::size< Behaviour >()+WireFormat::size< PresenceCondition >()> SerializedDataType
Definition: cs_SwitchBehaviour.h:31
bool isValid(PresenceStateDescription currentpresence)
virtual bool requiresAbsence() override
bool gracePeriodForPresenceIsActive()
virtual bool requiresPresence() override
virtual ~SwitchBehaviour()=default
bool _isValid(PresenceStateDescription currentpresence)
SwitchBehaviour(SerializedDataType arr)
virtual void print()
virtual PresencePredicate currentPresencePredicate()
SerializedDataType serialize()
virtual Type getType() const override
Definition: cs_SwitchBehaviour.h:49
std::optional< uint32_t > prevInRoomTimeStamp
Definition: cs_SwitchBehaviour.h:87
PresenceCondition presenceCondition
Definition: cs_SwitchBehaviour.h:83
SwitchBehaviour(uint8_t intensity, uint8_t profileid, DayOfWeekBitMask activedaysofweek, TimeOfDay from, TimeOfDay until, PresenceCondition presencecondition)
virtual uint8_t * serialize(uint8_t *outbuff, size_t max_size) override
virtual bool isValid(Time currenttime, PresenceStateDescription currentpresence)
Does the behaviour apply to the current situation? If from() == until() the behaviour isValid all day...
Definition: cs_TestAccess.h:11
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Sep 24,...
Definition: cs_TimeOfDay.h:19
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Sep 24,...
Definition: cs_Time.h:14
uint8_t DayOfWeekBitMask
Definition: cs_DayOfWeek.h:23