-
Notifications
You must be signed in to change notification settings - Fork 0
/
mockDisplayModule.py
executable file
·49 lines (39 loc) · 1.47 KB
/
mockDisplayModule.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
#!/usr/bin/env python3
import os
import robomodules as rm
from messages import message_buffers, MsgType
ADDRESS = os.environ.get("BIND_ADDRESS","localhost")
PORT = os.environ.get("BIND_PORT", 11297)
FREQUENCY = 10
class MockGuiModule(rm.ProtoModule):
def __init__(self, addr, port):
self.subscriptions = [MsgType.MOCK_MSG]
super().__init__(addr, port, message_buffers, MsgType, FREQUENCY, self.subscriptions)
self.value = -1
self.sub_ticks = 0
self.subbed = True
def msg_received(self, msg, msg_type):
# This gets called whenever any message is received
if msg_type == MsgType.MOCK_MSG:
self.value = msg.mockValue
def tick(self):
# this function will get called in a loop with FREQUENCY frequency
# for this mock module we will print out the current value
print('Current value: {}'.format(self.value))
# to demonstrate subscription and unsubscription,
# we will periodically unsubscribe and resubscribe
if self.sub_ticks > 100:
if self.subbed:
print('Unsubscribed!')
self.unsubscribe([MsgType.MOCK_MSG])
else:
print('Subscribed!')
self.subscribe([MsgType.MOCK_MSG])
self.subbed = not self.subbed
self.sub_ticks = 0
self.sub_ticks += 1
def main():
module = MockGuiModule(ADDRESS, PORT)
module.run()
if __name__ == "__main__":
main()