From 3f28ae26416dceeb1c40072e56f356dc4bc34421 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sat, 3 Aug 2024 17:57:49 -0400 Subject: [PATCH] flashtool: update stale can errors Signed-off-by: Eric Callahan --- scripts/flashtool.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/scripts/flashtool.py b/scripts/flashtool.py index c60b602..8f043f7 100755 --- a/scripts/flashtool.py +++ b/scripts/flashtool.py @@ -68,7 +68,7 @@ CANBUS_CMD_CLEAR_NODE_ID = 0x12 CANBUS_RESP_NEED_NODEID = 0x20 CANBUS_NODEID_OFFSET = 128 -class FlashCanError(Exception): +class FlashError(Exception): pass class CanFlasher: @@ -94,7 +94,7 @@ class CanFlasher: self.app_start_addr = start_addr proto_version = ".".join([str(v) for v in reversed(ver_bytes[:3])]) if self.block_size not in [64, 128, 256, 512]: - raise FlashCanError("Invalid Block Size: %d" % (self.block_size,)) + raise FlashError("Invalid Block Size: %d" % (self.block_size,)) while mcu_type and mcu_type[-1] == 0x00: mcu_type = mcu_type[:-1] mcu_type = mcu_type.decode() @@ -110,7 +110,7 @@ class CanFlasher: ret = await self.send_command('GET_CANBUS_ID') mcu_uuid = sum([v << ((5 - i) * 8) for i, v in enumerate(ret[:6])]) if mcu_uuid != uuid: - raise FlashCanError("UUID mismatch (%s vs %s)" % (uuid, mcu_uuid)) + raise FlashError("UUID mismatch (%s vs %s)" % (uuid, mcu_uuid)) async def send_command( self, @@ -155,7 +155,7 @@ class CanFlasher: except Exception as e: if type(e) is type(last_err) and e.args == last_err.args: last_err = e - logging.exception("Can Read Error") + logging.exception("Device Read Error") else: trailer = data[-2:] recd_crc, = struct.unpack("= last_percent + 2: @@ -267,7 +266,7 @@ class CanFlasher: ver_hex = ver_sha.hexdigest().upper() fw_hex = self.fw_sha.hexdigest().upper() if ver_hex != fw_hex: - raise FlashCanError("Checksum mismatch: Expected %s, Received %s" + raise FlashError("Checksum mismatch: Expected %s, Received %s" % (fw_hex, ver_hex)) output_line("]\n\nVerification Complete: SHA = %s" % (ver_hex)) @@ -456,11 +455,11 @@ class CanSocket: self, intf: str, uuid: int, fw_path: pathlib.Path, req_only: bool ) -> None: if not req_only and not fw_path.is_file(): - raise FlashCanError("Invalid firmware path '%s'" % (fw_path)) + raise FlashError("Invalid firmware path '%s'" % (fw_path)) try: self.cansock.bind((intf,)) except Exception: - raise FlashCanError("Unable to bind socket to can0") + raise FlashError("Unable to bind socket to can0") self.closed = False self.cansock.setblocking(False) self._loop.add_reader( @@ -490,7 +489,7 @@ class CanSocket: try: self.cansock.bind((intf,)) except Exception: - raise FlashCanError("Unable to bind socket to can0") + raise FlashError("Unable to bind socket to can0") self.closed = False self.cansock.setblocking(False) self._loop.add_reader( @@ -531,11 +530,11 @@ class SerialSocket: async def run(self, intf: str, baud: int, fw_path: pathlib.Path) -> None: if not fw_path.is_file(): - raise FlashCanError("Invalid firmware path '%s'" % (fw_path)) + raise FlashError("Invalid firmware path '%s'" % (fw_path)) try: import serial except ModuleNotFoundError: - raise FlashCanError( + raise FlashError( "The pyserial python package was not found. To install " "run the following command in a terminal: \n\n" " pip3 install pyserial\n\n") @@ -546,7 +545,7 @@ class SerialSocket: serial_dev.port = intf serial_dev.open() except (OSError, IOError, self.serial_error) as e: - raise FlashCanError("Unable to open serial port: %s" % (e,)) + raise FlashError("Unable to open serial port: %s" % (e,)) self.serial = serial_dev self._loop.add_reader(self.serial.fileno(), self._handle_response) flasher = CanFlasher(self.node, fw_path) @@ -619,16 +618,18 @@ def main(): loop.run_until_complete(sock.run_query(intf)) else: if args.uuid is None: - raise FlashCanError( + raise FlashError( "The 'uuid' option must be specified to flash a device" ) + output_line(f"Flashing CAN UUID {args.uuid} on interface {intf}") uuid = int(args.uuid, 16) loop.run_until_complete(sock.run(intf, uuid, fpath, req_only)) else: if args.device is None: - raise FlashCanError( + raise FlashError( "The 'device' option must be specified to flash a device" ) + output_line(f"Flashing Serial Device {args.device}, baud {args.baud}") sock = SerialSocket(loop) loop.run_until_complete(sock.run(args.device, args.baud, fpath)) except Exception: