fix px_uploader bytes and char comparison & remove python 2 support (#15859)

This commit is contained in:
Jacob Dahl 2020-10-12 23:30:37 -08:00 committed by GitHub
parent c2af7ba961
commit 74c9ba8d55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 12 deletions

View File

@ -287,13 +287,13 @@ class uploader(object):
if (len(data) != count):
raise RuntimeError("Ack Window %i not %i " % (len(data), count))
for i in range(0, len(data), 2):
if chr(data[i]) != self.INSYNC:
if bytes([data[i]]) != self.INSYNC:
raise RuntimeError("unexpected %s instead of INSYNC" % data[i])
if chr(data[i+1]) == self.INVALID:
if bytes([data[i+1]]) == self.INVALID:
raise RuntimeError("bootloader reports INVALID OPERATION")
if chr(data[i+1]) == self.FAILED:
if bytes([data[i+1]]) == self.FAILED:
raise RuntimeError("bootloader reports OPERATION FAILED")
if chr(data[i+1]) != self.OK:
if bytes([data[i+1]]) != self.OK:
raise RuntimeError("unexpected response 0x%x instead of OK" % ord(data[i+1]))
# attempt to get back into sync with the bootloader
@ -426,10 +426,7 @@ class uploader(object):
# send a PROG_MULTI command to write a collection of bytes
def __program_multi(self, data, windowMode):
if runningPython3:
length = len(data).to_bytes(1, byteorder='big')
else:
length = chr(len(data))
length = len(data).to_bytes(1, byteorder='big')
self.__send(uploader.PROG_MULTI)
self.__send(length)
@ -450,10 +447,7 @@ class uploader(object):
# verify multiple bytes in flash
def __verify_multi(self, data):
if runningPython3:
length = len(data).to_bytes(1, byteorder='big')
else:
length = chr(len(data))
length = len(data).to_bytes(1, byteorder='big')
self.__send(uploader.READ_MULTI)
self.__send(length)
@ -711,6 +705,9 @@ class uploader(object):
def main():
# Python2 is EOL
if not runningPython3:
raise RuntimeError("Python 2 is not supported. Please try again using Python 3.")
# Parse commandline arguments
parser = argparse.ArgumentParser(description="Firmware uploader for the PX autopilot system.")