From 10cc588874cc0dd103fd8d0275e17f7d9d2c42bf Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Thu, 16 Mar 2023 10:57:23 -0400 Subject: [PATCH] flash_can: query fix Don't requre exactly 8 bytes in a response, as its possible that some apps may not return a full 8 bytes. Signed-off-by: Eric Callahan --- scripts/flash_can.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/flash_can.py b/scripts/flash_can.py index 6f164bd..ac43916 100755 --- a/scripts/flash_can.py +++ b/scripts/flash_can.py @@ -408,20 +408,22 @@ class CanSocket: endtime = curtime + 2. self.uuids: List[int] = [] while curtime < endtime: - diff = endtime - curtime + timeout = max(.1, endtime - curtime) try: - resp = await self.admin_node.readexactly(8, diff) + resp = await self.admin_node.read(8, timeout) except asyncio.TimeoutError: - break + continue finally: curtime = self._loop.time() - if resp[0] != CANBUS_RESP_NEED_NODEID: + if len(resp) < 7 or resp[0] != CANBUS_RESP_NEED_NODEID: continue app_names = { KLIPPER_SET_NODE_CMD: "Klipper", CANBUS_CMD_SET_NODEID: "CanBoot" } - app = app_names.get(resp[7], "Unknown") + app = "Unknown" + if len(resp) > 7: + app = app_names.get(resp[7], "Unknown") data = resp[1:7] output_line(f"Detected UUID: {data.hex()}, Application: {app}") uuid = sum([v << ((5 - i) * 8) for i, v in enumerate(data)])