-
Notifications
You must be signed in to change notification settings - Fork 3
/
Wireless.py
53 lines (41 loc) · 1.38 KB
/
Wireless.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
# built-in
# third-party
# local
class Wireless(object):
'''
The wireless medium through which DotBot and orchestrator communicate.
'''
PDR = 1
# singleton pattern
_instance = None
_init = False
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(Wireless, cls).__new__(cls, *args, **kwargs)
return cls._instance
def __init__(self):
# singleton patterm
if self._init:
return
self._init = True
# local variables
self.dotbots = None
self.orchestrator = None
#======================== public ==========================================
def indicateElements(self,dotbots,orchestrator):
assert self.dotbots==None
assert self.orchestrator==None
self.dotbots = dotbots
self.orchestrator = orchestrator
def toDotBots(self,msg):
for dotbot in self.dotbots:
if self.PDR==1:
dotbot.fromOrchestrator(msg)
else:
raise NotImplementedError()
def toOrchestrator(self,msg):
if self.PDR==1:
self.orchestrator.fromDotBot(msg)
else:
raise NotImplementedError()
#======================== private =========================================