-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx0passthrough.py
64 lines (45 loc) · 1.53 KB
/
x0passthrough.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
##
## imports
##
##
## code
##
class X0Passthrough:
"""THe main Apex state object that does the magic"""
def __init__(self, inComm, useLog,timeoutConfig, closeOnComplete):
global log
log = useLog
self.desired = None
self.comm = inComm
self.state = ''
def action(self):
# this is where the work happens
if self.desired == None:
return
if self.state == '':
# nothing going on, let's start the procoess
log.debug(f'Inside state "{self.state}"')
rxData = self.comm.read()
if rxData == b'':
log.debug(f'No unexpected data to purge')
self.state = 'purgedone'
else:
# well... we got something we didn't expect
# just toss it away and try to get nothing
log.debug(f'Received data during purge {rxData}')
elif self.state == 'purgedone':
# no unexpected data coming from source so we start
log.debug(f'Inside state "{self.state}"')
cmd = self.desired
log.info(f'Sending passthrough command {cmd}')
sent = self.comm.send(cmd)
if sent:
self.state = ''
self.desired = None
self.comm.close()
def set(self, inDesired):
self.desired = inDesired
log.info(f'Asked to send passthrough {self.desired}')
self.comm.close()
self.state = ''
self.action()