forked from haineb-zz/ASLHackfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.py
48 lines (30 loc) · 1.02 KB
/
service.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
import threading
import queue
from asl_sdr_hackfest.zmq_sub import ZMQ_sub, ZMQ_sub_timeout
from asl_sdr_hackfest.zmq_pub import ZMQ_pub
class Service(threading.Thread, object):
def __init__(self, portIn, portOut):
self.running = False
self._ZMQ_in = ZMQ_sub(portIn = portIn)
self._ZMQ_out = ZMQ_pub(portOut = portOut)
self._input_queue = queue.Queue()
threading.Thread.__init__(self)
def run(self):
self.running = True
while self.running is True:
try:
data = self._ZMQ_in.recv()
except ZMQ_sub_timeout:
continue
self.inputData(bytearray(data))
def stop(self):
self.running = False
def inputData(self, data):
self._input_queue.put(data)
def readData(self):
data = None
if not self._input_queue.empty():
data = self._input_queue.get()
return data
def outputData(self, data):
self._ZMQ_out.send(data)