Bluenet
5.7.0
Bluenet, firmware for nRF52 smart home devices
|
Class that keeps up devices to be tracked. More...
#include <cs_TrackedDevices.h>
Public Member Functions | |
TrackedDevices () | |
void | init () |
Init class. More... | |
void | handleEvent (event_t &evt) override |
Handle events. 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... | |
Static Public Attributes | |
static const uint8_t | MAX_TRACKED_DEVICES = 20 |
Maximum number of registered tracked devices. More... | |
static const uint8_t | LOCATION_ID_TTL_MINUTES = 5 |
After N minutes not hearing anything from the device, the location ID will be set to 0 (in sphere). More... | |
static const uint16_t | HEARTBEAT_TTL_MINUTES_MAX = 60 |
Max heartbeat TTL in minutes. More... | |
Private Member Functions | |
TrackedDevice * | findOrAdd (device_id_t deviceId) |
Find device with given ID, else add a new device with given ID. More... | |
TrackedDevice * | find (device_id_t deviceId) |
Find and return device with given id. More... | |
TrackedDevice * | findToken (uint8_t *deviceToken, uint8_t size) |
Find and return device with given token. More... | |
TrackedDevice * | add () |
Add device to list. More... | |
cs_ret_code_t | handleRegister (internal_register_tracked_device_packet_t &packet) |
cs_ret_code_t | handleUpdate (internal_update_tracked_device_packet_t &packet) |
void | handleMeshRegister (TYPIFY(EVT_MESH_TRACKED_DEVICE_REGISTER) &packet) |
void | handleMeshToken (TYPIFY(EVT_MESH_TRACKED_DEVICE_TOKEN) &packet) |
void | handleMeshListSize (TYPIFY(EVT_MESH_TRACKED_DEVICE_LIST_SIZE) &packet) |
void | handleScannedDevice (adv_background_parsed_v1_t &packet) |
cs_ret_code_t | handleHeartbeat (internal_tracked_device_heartbeat_packet_t &packet) |
cs_ret_code_t | handleHeartbeat (TrackedDevice &device, uint8_t locationId, uint8_t ttlMinutes, bool fromMesh) |
void | handleMeshHeartbeat (TYPIFY(EVT_MESH_TRACKED_DEVICE_HEARTBEAT) &packet) |
bool | hasAccess (TrackedDevice &device, uint8_t accessLevel) |
Return true when given access level is equal or higher than device access level. More... | |
bool | isTokenOkToSet (TrackedDevice &device, uint8_t *deviceToken, uint8_t size) |
Returns true when no other device has this token. More... | |
void | print (TrackedDevice &device) |
void | tickMinute () |
A minute has passed. More... | |
void | tickSecond () |
Send location of devices with non-timed out heartbeat. More... | |
void | checkSynced () |
Check if tracked device list is synced yet. More... | |
void | sendBackgroundAdv (TrackedDevice &device, uint8_t *macAddress, int8_t rssi) |
Send background adv event. More... | |
void | sendHeartbeatLocation (TrackedDevice &device, bool fromMesh, bool simulated) |
Send profile location to event dispatcher. More... | |
void | sendHeartbeatToMesh (TrackedDevice &device) |
Send the heartbeat msg to the mesh. More... | |
void | sendRegisterToMesh (TrackedDevice &device) |
Send tracked device register msg to mesh. More... | |
void | sendTokenToMesh (TrackedDevice &device) |
Send tracked device token msg to mesh. More... | |
void | sendListSizeToMesh (uint8_t deviceCount) |
Send tracked devices list size to mesh. More... | |
void | sendDeviceList () |
Send all tracked devices to mesh. More... | |
Private Attributes | |
uint16_t | ticksLeftSecond = TICKS_PER_SECOND |
uint16_t | ticksLeftMinute = TICKS_PER_MINUTES |
Store< TrackedDevice, MAX_TRACKED_DEVICES > | _store |
List of all tracked devices. More... | |
bool | _deviceListIsSynced = false |
Whether there has been a successful sync of tracked devices. More... | |
uint8_t | _expectedDeviceListSize = 0xFF |
When syncing, the remote crownstone will tell how many devices there are. More... | |
Static Private Attributes | |
static const uint16_t | TICKS_PER_SECOND = (1000 / TICK_INTERVAL_MS) |
static const uint16_t | TICKS_PER_MINUTES = (60 * 1000 / TICK_INTERVAL_MS) |
Class that keeps up devices to be tracked.
Alternative to dynamic background broadcasts (no heartbeat required), or to no background broadcasts at all (heartbeats required).
|
private |
Add device to list.
Returns invalidated entry when added. Returns null if couldn't be added.
|
private |
Check if tracked device list is synced yet.
|
private |
Find and return device with given id.
Returns null if it couldn't be found.
|
private |
Find device with given ID, else add a new device with given ID.
Returns device with given ID when found or added. Returns null if couldn't be added.
|
private |
Find and return device with given token.
Returns null if it couldn't be found.
|
overridevirtual |
Handle events.
Implements EventListener.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Return true when given access level is equal or higher than device access level.
void TrackedDevices::init | ( | ) |
Init class.
Register as event listener.
|
private |
Returns true when no other device has this token.
|
private |
|
private |
Send background adv event.
Checks if all fields are set.
|
private |
Send all tracked devices to mesh.
|
private |
Send profile location to event dispatcher.
Checks if all fields are set. Set fromMesh to true when location is based on a mesh message. Set simulated to true when the location is from the heartbeat TTL, not from a command or broadcast.
|
private |
Send the heartbeat msg to the mesh.
|
private |
Send tracked devices list size to mesh.
|
private |
Send tracked device register msg to mesh.
|
private |
Send tracked device token msg to mesh.
|
private |
A minute has passed.
Decrease TTL of all devices by 1. Decrease location timeout of all device by 1. Decrease heartbeat TTL.
|
private |
Send location of devices with non-timed out heartbeat.
|
private |
Whether there has been a successful sync of tracked devices.
For now, this means just getting a list of devices from another crownstone, after boot.
|
private |
When syncing, the remote crownstone will tell how many devices there are.
This number is cached in this variable, so we know when we're synced.
|
private |
List of all tracked devices.
Device ID should be unique.
|
static |
Max heartbeat TTL in minutes.
Make sure that it's not larger than what fits in location id timeout.
|
static |
After N minutes not hearing anything from the device, the location ID will be set to 0 (in sphere).
This prevents sending out old locations.
|
static |
Maximum number of registered tracked devices.
|
staticprivate |
|
staticprivate |
|
private |
|
private |