25 static const constexpr uint8_t MAX_LOCATION_ID = 63;
26 static const constexpr uint8_t MAX_PROFILE_ID = 7;
33 bool isValid() {
return profile <= MAX_PROFILE_ID && location <= MAX_LOCATION_ID; }
94 uint8_t meshThrottleSeconds = 0)
142 std::optional<PresenceStateDescription> prevDescription,
143 std::optional<PresenceStateDescription> nextDescription);
Helper class to manage decoupling of components.
Definition: cs_Component.h:35
Event listener.
Definition: cs_EventListener.h:17
Keeps up all the locations each profile is present in.
Definition: cs_PresenceHandler.h:22
void registerPresence(ProfileLocation profileLocation)
Validates and administrate a presence update.
virtual void handleEvent(event_t &evt) override
receive background messages indicating where users are, record the time and place and update the curr...
PresenceRecord * clearOldestRecord(ProfileLocation profileLocation)
finds oldest record and default constructs its present record, then returns the pointer to it.
virtual ~PresenceHandler()
void dispatchPresenceChangeEvent(PresenceChange type, ProfileLocation profileLocation={})
Sends presence change event.
PresenceMutation handleProfileLocation(ProfileLocation profileLocation, bool forwardToMesh)
Handle an incoming profile-location combination.
Store< PresenceRecord, MAX_RECORDS > _store
Stores presence records.
Definition: cs_PresenceHandler.h:109
PresenceMutation getMutationType(std::optional< PresenceStateDescription > prevDescription, std::optional< PresenceStateDescription > nextDescription)
Resolves the type of mutation from previous and next descriptions.
std::optional< PresenceStateDescription > getCurrentPresenceDescription()
Returns a simplified description of the current presence knowledge, each bit in the description indic...
void sendMeshMessage(ProfileLocation profileLocation)
Send a mesh message with profile and location.
static const constexpr uint8_t PRESENCE_TIMEOUT_SECONDS
Number of seconds before presence times out.
Definition: cs_PresenceHandler.h:58
static const constexpr uint32_t PRESENCE_UNCERTAIN_SECONDS_AFTER_BOOT
Number of seconds after boot it is assumed to take to receive the location of all devices.
Definition: cs_PresenceHandler.h:67
void handlePresenceEvent(ProfileLocation profileLocation, bool forwardToMesh)
Handle an incoming profile-location combination.
void tickSecond()
To be called every second.
virtual cs_ret_code_t init() override
calls listen();
static const constexpr uint8_t PRESENCE_MESH_SEND_THROTTLE_SECONDS
For each presence entry, send it max every (x + variation) seconds over the mesh.
Definition: cs_PresenceHandler.h:61
static const constexpr uint8_t MAX_RECORDS
Maximum number of presence records that is kept up.
Definition: cs_PresenceHandler.h:74
void dispatchPresenceMutationEvent(PresenceMutation mutation)
Sends presence mutation event.
static const constexpr uint8_t PRESENCE_MESH_SEND_THROTTLE_SECONDS_VARIATION
Definition: cs_PresenceHandler.h:62
A variable size storage utility for objects of type RecordType with absolute maximum MaxItemCount.
Definition: cs_Store.h:25
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
PresenceMutation
Definition: cs_PacketsInternal.h:255
PresenceChange
Definition: cs_Packets.h:378
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
Definition: cs_PresenceHandler.h:76
uint8_t meshSendCountdownSeconds
Used to determine whether to send a mesh message.
Definition: cs_PresenceHandler.h:89
ProfileLocation id()
Definition: cs_PresenceHandler.h:103
bool isValid()
Definition: cs_PresenceHandler.h:101
void invalidate()
Definition: cs_PresenceHandler.h:99
uint8_t timeoutCountdownSeconds
Used to determine when a record is timed out.
Definition: cs_PresenceHandler.h:83
ProfileLocation profileLocation
Definition: cs_PresenceHandler.h:77
PresenceRecord(ProfileLocation profileLocation={}, uint8_t timeoutSeconds=PRESENCE_TIMEOUT_SECONDS, uint8_t meshThrottleSeconds=0)
Definition: cs_PresenceHandler.h:91
Definition: cs_PresenceHandler.h:24
uint8_t location
Definition: cs_PresenceHandler.h:29
bool isValid()
Definition: cs_PresenceHandler.h:33
uint8_t profile
Definition: cs_PresenceHandler.h:28
bool operator==(const ProfileLocation &other)
Definition: cs_PresenceHandler.h:31