From 30bc561231a36e4da78adda736aeebe9fa3fb5b2 Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Tue, 28 Jul 2020 15:02:02 +0200 Subject: [PATCH] dump_errors: better handling of unknown errors --- tools/odrive/utils.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tools/odrive/utils.py b/tools/odrive/utils.py index dd51f5ac..571db8e9 100755 --- a/tools/odrive/utils.py +++ b/tools/odrive/utils.py @@ -89,13 +89,10 @@ def dump_errors(odrv, clear=False): if (remote_obj.error != 0): foundError = False print(prefix + _VT100Colors['red'] + "Error(s):" + _VT100Colors['default']) - errorcodes_tup = [(name, val) for name, val in errorcodes.items() if 'ERROR_' in name] - for codename, codeval in errorcodes_tup: - if remote_obj.error & codeval != 0: - foundError = True - print(" " + codename) - if not foundError: - print(" " + 'UNKNOWN ERROR!') + errorcodes_dict = {val: name for name, val in errorcodes.items() if 'ERROR_' in name} + for bit in range(64): + if remote_obj.error & (1 << bit) != 0: + print(" " + errorcodes_dict.get((1 << bit), 'UNKNOWN ERROR: 0x{:08X}'.format(1 << bit))) if clear: remote_obj.error = 0 else: