mirror of
https://github.com/andreili/katapult.git
synced 2025-08-24 03:44:06 +02:00
flash_can: add query option
It is possible that a user will flash the bootloader before ever having flashed Klipper. In this case they would be unable to supply a UUID. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
0838d844e9
commit
db1123d69d
@ -25,7 +25,7 @@ def output(msg: str) -> None:
|
|||||||
sys.stdout.write(msg)
|
sys.stdout.write(msg)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.INFO)
|
||||||
CAN_FMT = "<IB3x8s"
|
CAN_FMT = "<IB3x8s"
|
||||||
CAN_READER_LIMIT = 1024 * 1024
|
CAN_READER_LIMIT = 1024 * 1024
|
||||||
|
|
||||||
@ -374,6 +374,19 @@ class CanSocket:
|
|||||||
await flasher.verify_file()
|
await flasher.verify_file()
|
||||||
await flasher.finish()
|
await flasher.finish()
|
||||||
|
|
||||||
|
async def run_query(self, intf: str):
|
||||||
|
try:
|
||||||
|
self.cansock.bind((intf,))
|
||||||
|
except Exception:
|
||||||
|
raise FlashCanError("Unable to bind socket to can0")
|
||||||
|
self.closed = False
|
||||||
|
self.cansock.setblocking(False)
|
||||||
|
self._loop.add_reader(
|
||||||
|
self.cansock.fileno(), self._handle_can_response)
|
||||||
|
self._reset_nodes()
|
||||||
|
await asyncio.sleep(.5)
|
||||||
|
await self._query_uuids()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if self.closed:
|
if self.closed:
|
||||||
return
|
return
|
||||||
@ -394,16 +407,29 @@ def main():
|
|||||||
"-f", "--firmware", metavar="<klipper.bin>",
|
"-f", "--firmware", metavar="<klipper.bin>",
|
||||||
default="~/klipper/out/klipper.bin",
|
default="~/klipper/out/klipper.bin",
|
||||||
help="Path to Klipper firmware file")
|
help="Path to Klipper firmware file")
|
||||||
parser.add_argument('uuid', metavar="<uuid>",
|
parser.add_argument(
|
||||||
help="Can device uuid")
|
"-u", "--uuid", metavar="<uuid>", default=None,
|
||||||
|
help="Can device uuid"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-q", "--query", action="store_true",
|
||||||
|
help="Query Bootloader Device IDs"
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
intf = args.interface
|
intf = args.interface
|
||||||
uuid = int(args.uuid, 16)
|
|
||||||
fpath = pathlib.Path(args.firmware).expanduser().resolve()
|
fpath = pathlib.Path(args.firmware).expanduser().resolve()
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
try:
|
try:
|
||||||
cansock = CanSocket(loop)
|
cansock = CanSocket(loop)
|
||||||
|
if args.query:
|
||||||
|
loop.run_until_complete(cansock.run_query(intf))
|
||||||
|
else:
|
||||||
|
if args.uuid is None:
|
||||||
|
raise FlashCanError(
|
||||||
|
"The 'uuid' option must be specified to flash a device"
|
||||||
|
)
|
||||||
|
uuid = int(args.uuid, 16)
|
||||||
loop.run_until_complete(cansock.run(intf, uuid, fpath))
|
loop.run_until_complete(cansock.run(intf, uuid, fpath))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception("Can Flash Error")
|
logging.exception("Can Flash Error")
|
||||||
@ -411,6 +437,9 @@ def main():
|
|||||||
finally:
|
finally:
|
||||||
if cansock is not None:
|
if cansock is not None:
|
||||||
cansock.close()
|
cansock.close()
|
||||||
|
if args.query:
|
||||||
|
output_line("Query Complete")
|
||||||
|
else:
|
||||||
output_line("CAN Flash Success")
|
output_line("CAN Flash Success")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user