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 <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-03-16 10:57:23 -04:00
parent a06bf6158a
commit 10cc588874
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B

View File

@ -408,20 +408,22 @@ class CanSocket:
endtime = curtime + 2. endtime = curtime + 2.
self.uuids: List[int] = [] self.uuids: List[int] = []
while curtime < endtime: while curtime < endtime:
diff = endtime - curtime timeout = max(.1, endtime - curtime)
try: try:
resp = await self.admin_node.readexactly(8, diff) resp = await self.admin_node.read(8, timeout)
except asyncio.TimeoutError: except asyncio.TimeoutError:
break continue
finally: finally:
curtime = self._loop.time() curtime = self._loop.time()
if resp[0] != CANBUS_RESP_NEED_NODEID: if len(resp) < 7 or resp[0] != CANBUS_RESP_NEED_NODEID:
continue continue
app_names = { app_names = {
KLIPPER_SET_NODE_CMD: "Klipper", KLIPPER_SET_NODE_CMD: "Klipper",
CANBUS_CMD_SET_NODEID: "CanBoot" 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] data = resp[1:7]
output_line(f"Detected UUID: {data.hex()}, Application: {app}") output_line(f"Detected UUID: {data.hex()}, Application: {app}")
uuid = sum([v << ((5 - i) * 8) for i, v in enumerate(data)]) uuid = sum([v << ((5 - i) * 8) for i, v in enumerate(data)])