Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_TrackedDevices.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Feb 7, 2020
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7#pragma once
8
11#include <util/cs_Store.h>
12
13#include <cstdint>
14
28public:
30
36 void init();
37
41 void handleEvent(event_t& evt) override;
42
46 static const uint8_t MAX_TRACKED_DEVICES = 20;
47
52 static const uint8_t LOCATION_ID_TTL_MINUTES = 5;
53
58 static const uint16_t HEARTBEAT_TTL_MINUTES_MAX = 60;
59
60private:
61 static const uint16_t TICKS_PER_SECOND = (1000 / TICK_INTERVAL_MS);
62 static const uint16_t TICKS_PER_MINUTES = (60 * 1000 / TICK_INTERVAL_MS);
63
66
73
79 bool _deviceListIsSynced = false;
80
86
94
101
107 TrackedDevice* findToken(uint8_t* deviceToken, uint8_t size);
108
116
124 cs_ret_code_t handleHeartbeat(TrackedDevice& device, uint8_t locationId, uint8_t ttlMinutes, bool fromMesh);
126
130 bool hasAccess(TrackedDevice& device, uint8_t accessLevel);
131
135 bool isTokenOkToSet(TrackedDevice& device, uint8_t* deviceToken, uint8_t size);
136
137 void print(TrackedDevice& device);
138
147
152
157
163 void sendBackgroundAdv(TrackedDevice& device, uint8_t* macAddress, int8_t rssi);
164
172 void sendHeartbeatLocation(TrackedDevice& device, bool fromMesh, bool simulated);
173
178
183
188
192 void sendListSizeToMesh(uint8_t deviceCount);
193
198};
Event listener.
Definition: cs_EventListener.h:17
A variable size storage utility for objects of type RecordType with absolute maximum MaxItemCount.
Definition: cs_Store.h:25
Class that keeps up devices to be tracked.
Definition: cs_TrackedDevices.h:27
void handleMeshRegister(TYPIFY(EVT_MESH_TRACKED_DEVICE_REGISTER) &packet)
TrackedDevice * findOrAdd(device_id_t deviceId)
Find device with given ID, else add a new device with given ID.
static const uint16_t TICKS_PER_SECOND
Definition: cs_TrackedDevices.h:61
cs_ret_code_t handleHeartbeat(TrackedDevice &device, uint8_t locationId, uint8_t ttlMinutes, bool fromMesh)
void handleEvent(event_t &evt) override
Handle events.
void handleScannedDevice(adv_background_parsed_v1_t &packet)
uint8_t _expectedDeviceListSize
When syncing, the remote crownstone will tell how many devices there are.
Definition: cs_TrackedDevices.h:85
uint16_t ticksLeftSecond
Definition: cs_TrackedDevices.h:64
void sendDeviceList()
Send all tracked devices to mesh.
TrackedDevice * findToken(uint8_t *deviceToken, uint8_t size)
Find and return device with given token.
void checkSynced()
Check if tracked device list is synced yet.
void sendHeartbeatLocation(TrackedDevice &device, bool fromMesh, bool simulated)
Send profile location to event dispatcher.
TrackedDevice * find(device_id_t deviceId)
Find and return device with given id.
void sendListSizeToMesh(uint8_t deviceCount)
Send tracked devices list size to mesh.
TrackedDevice * add()
Add device to list.
cs_ret_code_t handleUpdate(internal_update_tracked_device_packet_t &packet)
void handleMeshHeartbeat(TYPIFY(EVT_MESH_TRACKED_DEVICE_HEARTBEAT) &packet)
static const uint16_t HEARTBEAT_TTL_MINUTES_MAX
Max heartbeat TTL in minutes.
Definition: cs_TrackedDevices.h:58
void print(TrackedDevice &device)
void sendBackgroundAdv(TrackedDevice &device, uint8_t *macAddress, int8_t rssi)
Send background adv event.
void sendRegisterToMesh(TrackedDevice &device)
Send tracked device register msg to mesh.
uint16_t ticksLeftMinute
Definition: cs_TrackedDevices.h:65
Store< TrackedDevice, MAX_TRACKED_DEVICES > _store
List of all tracked devices.
Definition: cs_TrackedDevices.h:72
void init()
Init class.
void handleMeshListSize(TYPIFY(EVT_MESH_TRACKED_DEVICE_LIST_SIZE) &packet)
bool isTokenOkToSet(TrackedDevice &device, uint8_t *deviceToken, uint8_t size)
Returns true when no other device has this token.
void handleMeshToken(TYPIFY(EVT_MESH_TRACKED_DEVICE_TOKEN) &packet)
static const uint16_t TICKS_PER_MINUTES
Definition: cs_TrackedDevices.h:62
void sendTokenToMesh(TrackedDevice &device)
Send tracked device token msg to mesh.
static const uint8_t MAX_TRACKED_DEVICES
Maximum number of registered tracked devices.
Definition: cs_TrackedDevices.h:46
cs_ret_code_t handleRegister(internal_register_tracked_device_packet_t &packet)
bool hasAccess(TrackedDevice &device, uint8_t accessLevel)
Return true when given access level is equal or higher than device access level.
void tickMinute()
A minute has passed.
static const uint8_t LOCATION_ID_TTL_MINUTES
After N minutes not hearing anything from the device, the location ID will be set to 0 (in sphere).
Definition: cs_TrackedDevices.h:52
void tickSecond()
Send location of devices with non-timed out heartbeat.
void sendHeartbeatToMesh(TrackedDevice &device)
Send the heartbeat msg to the mesh.
bool _deviceListIsSynced
Whether there has been a successful sync of tracked devices.
Definition: cs_TrackedDevices.h:79
cs_ret_code_t handleHeartbeat(internal_tracked_device_heartbeat_packet_t &packet)
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
#define TICK_INTERVAL_MS
Interval in milliseconds at which tick events are dispatched.
Definition: cs_Config.h:277
uint16_t device_id_t
Definition: cs_Typedefs.h:24
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
#define TYPIFY(NAME)
Definition: cs_Types.h:476
@ EVT_MESH_TRACKED_DEVICE_TOKEN
@ EVT_MESH_TRACKED_DEVICE_REGISTER
@ EVT_MESH_TRACKED_DEVICE_HEARTBEAT
@ EVT_MESH_TRACKED_DEVICE_LIST_SIZE
Definition: cs_TrackedDevice.h:23
Definition: cs_PacketsInternal.h:249
Definition: cs_PacketsInternal.h:271
Definition: cs_PacketsInternal.h:278