From a8de2feab739080388b575bf6dce01c364ecd830 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Tue, 17 Sep 2024 06:22:53 -0400 Subject: [PATCH] flashtool: support busy acknowledgements Signed-off-by: Eric Callahan --- scripts/flashtool.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/flashtool.py b/scripts/flashtool.py index 079a6af..2402289 100755 --- a/scripts/flashtool.py +++ b/scripts/flashtool.py @@ -62,6 +62,8 @@ BOOTLOADER_CMDS = { ACK_SUCCESS = 0xa0 NACK = 0xf1 +ACK_ERROR = 0xf2 +ACK_BUSY = 0xf3 # Klipper Admin Defs (for jumping to bootloader) KLIPPER_ADMIN_ID = 0x3f0 @@ -192,6 +194,11 @@ class CanFlasher: f"Command '{cmdname}': Frame CRC Mismatch, expected: " f"{calc_crc}, received {recd_crc}" ) + elif recd_ack == ACK_ERROR: + logging.info(f"Command '{cmdname}': Received Error Response") + elif recd_ack == ACK_BUSY: + logging.info(f"Command '{cmdname}': Received busy signal") + await asyncio.sleep(1.5) elif recd_ack != ACK_SUCCESS: logging.info(f"Command '{cmdname}': Received NACK") elif cmd_response != cmd: @@ -212,7 +219,7 @@ class CanFlasher: pass else: logging.info(f"Read Buffer Contents: {ret!r}") - await asyncio.sleep(.1) + await asyncio.sleep(.5) raise FlashError("Error sending command [%s] to Device" % (cmdname)) async def send_file(self): @@ -302,17 +309,17 @@ class CanNode: self._cansocket = cansocket async def read( - self, n: int = -1, timeout: Optional[float] = 5. + self, n: int = -1, timeout: Optional[float] = 2. ) -> bytes: return await asyncio.wait_for(self._reader.read(n), timeout) async def readexactly( - self, n: int, timeout: Optional[float] = 5. + self, n: int, timeout: Optional[float] = 2. ) -> bytes: return await asyncio.wait_for(self._reader.readexactly(n), timeout) async def readuntil( - self, sep: bytes = b"\x03", timeout: Optional[float] = 5. + self, sep: bytes = b"\x03", timeout: Optional[float] = 2. ) -> bytes: return await asyncio.wait_for(self._reader.readuntil(sep), timeout)