-
Notifications
You must be signed in to change notification settings - Fork 0
/
beacons.cpp
50 lines (41 loc) · 1 KB
/
beacons.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "beacons.h"
Beacons::Beacons(void) {
}
void Beacons::updatePosition(uint32_t beaconId, double lat, double lon, double alt) {
Beacon *beacon = getBeacon(beaconId);
beacon->setPos(lat, lon, alt);
}
Beacon *Beacons::getEmpty(void) {
for (uint8_t i = 0; i < BEACONS_MAX_COUNT; i++) {
if (!_beacons[i].getId()) {
return &_beacons[i];
}
}
return NULL;
}
Beacon *Beacons::getBeacon(uint32_t id) {
for (uint8_t i = 0; i < BEACONS_MAX_COUNT; i++) {
if (_beacons[i].getId() == id) {
return &_beacons[i];
}
}
Beacon *b = getEmpty();
b->setId(id);
return b;
}
Beacon *Beacons::get(uint8_t index) {
if (index >= 0 && index < BEACONS_MAX_COUNT) {
return &_beacons[index];
} else {
return NULL;
}
}
uint8_t Beacons::count(void) {
uint8_t count = 0;
for (uint8_t i = 0; i < BEACONS_MAX_COUNT; i++) {
if (_beacons[i].getId()) {
count++;
}
}
return count;
}