From 74c9ba8d55f3659cfbb18a82c14f3a9e64b03183 Mon Sep 17 00:00:00 2001 From: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> Date: Mon, 12 Oct 2020 23:30:37 -0800 Subject: [PATCH] fix px_uploader bytes and char comparison & remove python 2 support (#15859) --- Tools/px_uploader.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Tools/px_uploader.py b/Tools/px_uploader.py index b783eae54b..a12c35a76c 100755 --- a/Tools/px_uploader.py +++ b/Tools/px_uploader.py @@ -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.")