autotest: fix MSP_DJI test for Py2

This commit is contained in:
Peter Barker 2021-11-19 09:17:37 +11:00 committed by Peter Barker
parent 821a041cbe
commit 5025056f4e
1 changed files with 8 additions and 3 deletions

View File

@ -359,22 +359,27 @@ class MSP_Generic(Telem):
def update_read(self):
for byte in self.do_read():
if sys.version_info[0] < 3:
c = byte[0]
byte = ord(c)
else:
c = chr(byte)
# print("Got (0x%02x) (%s) (%s) state=%s" % (byte, chr(byte), str(type(byte)), self.state))
if self.state == self.STATE_IDLE:
# reset state
self.set_state(self.STATE_WANT_HEADER_DOLLARS)
# deliberate fallthrough right here
if self.state == self.STATE_WANT_HEADER_DOLLARS:
if chr(byte) == '$':
if c == '$':
self.set_state(self.STATE_WANT_HEADER_M)
continue
if self.state == self.STATE_WANT_HEADER_M:
if chr(byte) != 'M':
if c != 'M':
raise Exception("Malformed packet")
self.set_state(self.STATE_WANT_HEADER_GT)
continue
if self.state == self.STATE_WANT_HEADER_GT:
if chr(byte) != '>':
if c != '>':
raise Exception("Malformed packet")
self.set_state(self.STATE_WANT_DATA_SIZE)
continue