Bluenet
5.7.0
Bluenet, firmware for nRF52 smart home devices
|
Keeps up all the locations each profile is present in. More...
#include <cs_PresenceHandler.h>
Classes | |
struct | PresenceRecord |
struct | ProfileLocation |
Public Member Functions | |
PresenceHandler () | |
virtual | ~PresenceHandler () |
virtual cs_ret_code_t | init () override |
calls listen(); More... | |
std::optional< PresenceStateDescription > | getCurrentPresenceDescription () |
Returns a simplified description of the current presence knowledge, each bit in the description indicates if a person is in that room or not. More... | |
void | registerPresence (ProfileLocation profileLocation) |
Validates and administrate a presence update. More... | |
virtual void | handleEvent (event_t &evt) override |
receive background messages indicating where users are, record the time and place and update the current presence description when necessary More... | |
![]() | |
EventListener () | |
virtual | ~EventListener () |
unregisters the listener. More... | |
virtual void | handleEvent (event_t &event)=0 |
Handle events. More... | |
void | listen () |
Registers this with the EventDispatcher. More... | |
![]() | |
template<class T > | |
T * | getComponent (Component *requester=nullptr) |
Returns a component of type T* from _parent->children(), If not found try again with ancestors: _parent-> ... ->_parent->children(). More... | |
virtual cs_ret_code_t | init () |
Components can implement this if they need to get references to sibling or if they need to do specific initialization. More... | |
void | parentAllChildren () |
utility that loops over all elements of getChildren() and setParent on the non-nullptr ones. More... | |
virtual | ~Component ()=default |
Private Member Functions | |
PresenceRecord * | clearOldestRecord (ProfileLocation profileLocation) |
finds oldest record and default constructs its present record, then returns the pointer to it. More... | |
void | handlePresenceEvent (ProfileLocation profileLocation, bool forwardToMesh) |
Handle an incoming profile-location combination. More... | |
PresenceMutation | handleProfileLocation (ProfileLocation profileLocation, bool forwardToMesh) |
Handle an incoming profile-location combination. More... | |
PresenceMutation | getMutationType (std::optional< PresenceStateDescription > prevDescription, std::optional< PresenceStateDescription > nextDescription) |
Resolves the type of mutation from previous and next descriptions. More... | |
void | sendMeshMessage (ProfileLocation profileLocation) |
Send a mesh message with profile and location. More... | |
void | dispatchPresenceChangeEvent (PresenceChange type, ProfileLocation profileLocation={}) |
Sends presence change event. More... | |
void | dispatchPresenceMutationEvent (PresenceMutation mutation) |
Sends presence mutation event. More... | |
void | tickSecond () |
To be called every second. More... | |
Private Attributes | |
Store< PresenceRecord, MAX_RECORDS > | _store |
Stores presence records. More... | |
Static Private Attributes | |
static const constexpr uint8_t | PRESENCE_TIMEOUT_SECONDS = 10 |
Number of seconds before presence times out. More... | |
static const constexpr uint8_t | PRESENCE_MESH_SEND_THROTTLE_SECONDS = 10 |
For each presence entry, send it max every (x + variation) seconds over the mesh. More... | |
static const constexpr uint8_t | PRESENCE_MESH_SEND_THROTTLE_SECONDS_VARIATION = 20 |
static const constexpr uint32_t | PRESENCE_UNCERTAIN_SECONDS_AFTER_BOOT = 30 |
Number of seconds after boot it is assumed to take to receive the location of all devices. More... | |
static const constexpr uint8_t | MAX_RECORDS = 20 |
Maximum number of presence records that is kept up. More... | |
Additional Inherited Members | |
![]() | |
virtual std::vector< Component * > | getChildren () |
Components with children can override this method to return them. More... | |
cs_ret_code_t | initChildren () |
void | setParent (Component *p) |
Children that are instantiated later can also be added individually. More... | |
Keeps up all the locations each profile is present in.
Sends out event when this changes. Sends out throttled mesh messages when the location of a profile is received.
|
virtual |
|
private |
finds oldest record and default constructs its present record, then returns the pointer to it.
|
private |
Sends presence change event.
[in] | type | Type of change. |
[in] | profileLocation | The relevant profile ID and location. |
|
private |
Sends presence mutation event.
This event is deprecated, but still used.
std::optional< PresenceStateDescription > PresenceHandler::getCurrentPresenceDescription | ( | ) |
Returns a simplified description of the current presence knowledge, each bit in the description indicates if a person is in that room or not.
|
private |
Resolves the type of mutation from previous and next descriptions.
|
overridevirtual |
receive background messages indicating where users are, record the time and place and update the current presence description when necessary
Implements EventListener.
|
private |
Handle an incoming profile-location combination.
|
private |
Handle an incoming profile-location combination.
[in] | profile | The profile ID. |
[in] | location | The location ID. |
[in] | forwardToMesh | If true, the update will be pushed into the mesh (throttled). |
|
overridevirtual |
void PresenceHandler::registerPresence | ( | ProfileLocation | profileLocation | ) |
Validates and administrate a presence update.
May include sending a EVT_PRESENCE_CHANGE
|
private |
Send a mesh message with profile and location.
|
private |
To be called every second.
Decreases timeoutCountdownSeconds of the records and dispatches exit-events when necessary.
|
private |
Stores presence records.
|
staticconstexprprivate |
Maximum number of presence records that is kept up.
Must be smaller than 0xFF.
|
staticconstexprprivate |
For each presence entry, send it max every (x + variation) seconds over the mesh.
|
staticconstexprprivate |
|
staticconstexprprivate |
Number of seconds before presence times out.
|
staticconstexprprivate |
Number of seconds after boot it is assumed to take to receive the location of all devices.