flash_can: add interface argument

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-04-13 18:23:44 -04:00
parent abb966713e
commit 3686db10fd
No known key found for this signature in database
GPG Key ID: 7027245FBBDDF59A

View File

@ -346,11 +346,11 @@ class CanSocket:
self.nodes[decoded_id + 1] = node self.nodes[decoded_id + 1] = node
return node return node
async def run(self, uuid: int, fw_path: pathlib.Path): async def run(self, intf: str, uuid: int, fw_path: pathlib.Path) -> None:
if not fw_path.is_file(): if not fw_path.is_file():
raise FlashCanError("Invalid firmware path '%s'" % (fw_path)) raise FlashCanError("Invalid firmware path '%s'" % (fw_path))
try: try:
self.cansock.bind(("can0",)) self.cansock.bind((intf,))
except Exception: except Exception:
raise FlashCanError("Unable to bind socket to can0") raise FlashCanError("Unable to bind socket to can0")
self.closed = False self.closed = False
@ -386,17 +386,25 @@ class CanSocket:
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Can Bootloader Flash Utility") description="Can Bootloader Flash Utility")
parser.add_argument(
"-i", "--interface", default="can0", metavar='<can interface>',
help="Can Interface"
)
parser.add_argument(
"-f", "--firmware", metavar="<klipper.bin>",
default="~/klipper/out/klipper.bin",
help="Path to Klipper firmware file")
parser.add_argument('uuid', metavar="<uuid>", parser.add_argument('uuid', metavar="<uuid>",
help="Can device uuid") help="Can device uuid")
parser.add_argument('fwpath', metavar="<klipper.bin>",
help="Path to firmware file")
args = parser.parse_args() args = parser.parse_args()
intf = args.interface
uuid = int(args.uuid, 16) uuid = int(args.uuid, 16)
fpath = pathlib.Path(args.fwpath).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)
loop.run_until_complete(cansock.run(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")
sys.exit(-1) sys.exit(-1)