-
Notifications
You must be signed in to change notification settings - Fork 0
/
peers.py
executable file
·79 lines (60 loc) · 1.96 KB
/
peers.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class Target:
def __init__(self, mac: int, offset, hint=""):
self.__mac = mac
self.__hint = hint
self.__offset = offset
def __eq__(self, other):
if isinstance(other, Target):
return self.__mac == other.__mac
elif isinstance(other, int):
return self.__mac == other
return False
def __hash__(self):
return hash(self.__mac)
def prepared_mac(self):
return "{:012X}".format(self.__mac)
@property
def mac(self):
return self.__mac
@property
def offset(self):
return self.__offset
@property
def hint(self):
return self.__hint
def __repr__(self):
return "{:012X}".format(self.__mac)
def __str__(self):
return "{:012X}".format(self.__mac) # {self.__hint}
class Anchor(Target):
def __init__(self, target, x, y):
super(Anchor, self).__init__(target.mac, target.offset, target.hint)
self.__x = x
self.__y = y
@property
def x(self):
return self.__x
@property
def y(self):
return self.__y
def __repr__(self):
return "{} @ ({:3.1f}|{:3.1f})".format(self.prepared_mac(),
self.x,
self.y)
class Result(Target):
def __init__(self, target, distance, rssi, took_s):
super(Result, self).__init__(target.mac, target.offset, target.hint)
self.__distance = distance
self.__rssi = rssi
self.__took = took_s
@property
def distance(self):
return self.__distance - self.offset
@property
def rssi(self):
return self.__rssi
@property
def took(self):
return self.__took
def __str__(self):
return "{} -> {} cm @ {} dbm / {:.1f} ms".format(self.prepared_mac(), self.distance, self.rssi, 1000 * self.took)