-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeacon.py
More file actions
61 lines (50 loc) · 1.45 KB
/
beacon.py
File metadata and controls
61 lines (50 loc) · 1.45 KB
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
51
52
53
54
55
56
57
58
59
60
61
# Beacon Class
# koki 15072015
class Beacon:
""" private vars """
uuid = "N/A"
macs = []
major = 0
minor = 0
txpower = 0
rssi = 0
def __init__(self, uuid, mac, major, minor, txpower, rssi):
self.uuid = uuid
self.macs = []
self.macs.append(mac)
self.major = major
self.minor = minor
self.txpower = txpower
self.rssi = rssi
def __str__(self):
string = "-------------\n"
string += "\tUDID: " + self.uuid
string += "\tMAJOR: " + str(self.major)
string += "\tMINOR: " + str(self.minor)
string += "\tDIST: " + str(self.getDistance())
# string += "\t(Unknown): " + str(self.txpower)
# string += "\tRSSI:" + str(self.rssi)
string += "\tMAC address: "
if len(self.macs) > 1:
string += str(len(self.macs))
else:
string += self.macs[0]
return string
def addMACadr(self, mac):
if any(mac in s for s in self.macs):
pass
else:
self.macs.append(mac)
def updateData(self, txp, rssi):
self.txp = txp
self.rssi = rssi
def getDistance(self):
if self.rssi == 0:
return -1.0
if self.txpower == 0:
return -1.0
ratio = self.rssi * 1.0 / self.txpower
if ratio < 1.0:
return ratio ** 10
else:
return 0.89976 * ratio ** 7.7095 + 0.111