Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_AssetRecord.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Aug 17, 2021
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7
8#pragma once
9
11
12struct __attribute__((__packed__)) asset_record_t {
17
22
29 uint8_t lastReceivedCounter = 0xFF;
30
35 uint8_t throttlingCountdown = 0;
36
37#if BUILD_CLOSEST_CROWNSTONE_TRACKER == 1
42 stone_id_t nearestStoneId;
43
48 int8_t nearestRssi;
49#endif
50
51 // ------------- record functions -------------
52
56 void invalidate() {
57 lastReceivedCounter = 0xFF;
58 }
59
63 bool isValid() {
64 return lastReceivedCounter != 0xFF;
65 }
66
68 return assetId;
69 }
70
71 // ------------- utility functions -------------
72
73 void empty() {
74 lastReceivedCounter = 0;
75 throttlingCountdown = 0;
76#if BUILD_CLOSEST_CROWNSTONE_TRACKER == 1
77 nearestStoneId = 0;
78#endif
79 }
80
81 bool isThrottled() {
82 return throttlingCountdown != 0;
83 }
84
85 void setThrottlingCountdown(uint8_t ticks) {
86 if (ticks >= 0xff) {
87 throttlingCountdown = 0xff - 1;
88 }
89 else {
90 throttlingCountdown = ticks;
91 }
92 }
93
94 void addThrottlingCountdown(uint8_t ticks) {
95 auto val = uint16_t(throttlingCountdown) + ticks;
96 setThrottlingCountdown(val);
97 }
98};
uint8_t stone_id_t
Definition: cs_Typedefs.h:23
Definition: cs_AssetFilterPackets.h:93
Definition: cs_AssetRecord.h:12
bool isThrottled()
Definition: cs_AssetRecord.h:81
void addThrottlingCountdown(uint8_t ticks)
Definition: cs_AssetRecord.h:94
bool isValid()
Returns whether this record is valid.
Definition: cs_AssetRecord.h:63
asset_id_t assetId
ID of the asset, unique field.
Definition: cs_AssetRecord.h:16
rssi_and_channel_t myRssi
Most recent RSSI value observed by this Crownstone.
Definition: cs_AssetRecord.h:21
void setThrottlingCountdown(uint8_t ticks)
Definition: cs_AssetRecord.h:85
asset_id_t id()
Definition: cs_AssetRecord.h:67
void invalidate()
Invalidate this record.
Definition: cs_AssetRecord.h:56
void empty()
Definition: cs_AssetRecord.h:73
Definition: cs_RssiAndChannel.h:63