Skip to content

Commit

Permalink
better parsing of initial input response
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed Sep 23, 2016
1 parent a968641 commit 55dbaed
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions mpf/platforms/opp/opp.py
Expand Up @@ -821,9 +821,10 @@ def _identify_connection(self):

# get initial value for inputs
self.writer.write(self.platform.read_input_msg[self.chain_serial])
resp = yield from self.readuntil(b'\xff', 6)
self.log.debug("Init get input response: %s", "".join(" 0x%02x" % b for b in resp))
self._parse_msg(resp)
while True:
resp = yield from self.readuntil(b'\xff', 6)
if self._parse_msg(resp):
break

self.platform.register_processor_connection(self.chain_serial, self)

Expand Down Expand Up @@ -882,6 +883,7 @@ def lost_synch(self):
def _parse_msg(self, msg):
self.partMsg += msg
strlen = len(self.partMsg)
messaged_found = 0
# Split into individual responses
while strlen >= 7:
if self._lost_synch:
Expand All @@ -897,6 +899,7 @@ def _parse_msg(self, msg):
# Only command expect to receive back is
if self.partMsg[1] == ord(OppRs232Intf.READ_GEN2_INP_CMD):
self.platform.process_received_message(self.chain_serial, self.partMsg[:7])
messaged_found += 1
self.partMsg = self.partMsg[7:]
strlen -= 7
else:
Expand All @@ -913,3 +916,5 @@ def _parse_msg(self, msg):
self.partMsg = self.partMsg[1:]
strlen -= 1
self._lost_synch = True

return messaged_found

0 comments on commit 55dbaed

Please sign in to comment.