From 831c401b5d66aa3480888d6d21d67106f20cd1d6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 8 Oct 2023 17:20:50 +0200 Subject: [PATCH] cli: hw raw --- software/script/chameleon_cli_unit.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/software/script/chameleon_cli_unit.py b/software/script/chameleon_cli_unit.py index 7558f8c..c8bcc87 100644 --- a/software/script/chameleon_cli_unit.py +++ b/software/script/chameleon_cli_unit.py @@ -1754,16 +1754,29 @@ class HWRaw(DeviceRequiredUnit): def args_parser(self) -> ArgumentParserNoExit: parser = ArgumentParserNoExit() parser.description = 'Send raw command' - parser.add_argument('-c', '--command', type=int, required=True, help="Command (Int) to send") - parser.add_argument('-d', '--data', type=str, help="Data (HEX) to send", default="") - parser.add_argument('-t', '--timeout', type=int, help="Timeout in seconds", default=3) + cmd_names = sorted([c.name for c in list(chameleon_cmd.Command)]) + help_str = "Command: " + ", ".join(cmd_names) + command_group = parser.add_mutually_exclusive_group(required=True) + command_group.add_argument('-c', '--command', type=str, metavar="COMMAND", help=help_str, choices=cmd_names) + command_group.add_argument('-n', '--num_command', type=int, metavar="", help="Numeric command ID: ") + parser.add_argument('-d', '--data', type=str, help="Data to send", default="", metavar="") + parser.add_argument('-t', '--timeout', type=int, help="Timeout in seconds", default=3, metavar="") return parser def on_exec(self, args: argparse.Namespace): + if args.command is not None: + command = chameleon_cmd.Command[args.command] + else: + # We accept not-yet-known command ids as "hw raw" is meant for debugging + command = args.num_command response = self.cmd.device.send_cmd_sync( - args.command, data=bytes.fromhex(args.data), status=0x0, timeout=args.timeout) + command, data=bytes.fromhex(args.data), status=0x0, timeout=args.timeout) print(" - Received:") - print(f" Command: {response.cmd}") + try: + command = chameleon_cmd.Command(response.cmd) + print(f" Command: {response.cmd} {command.name}") + except ValueError: + print(f" Command: {response.cmd} (unknown)") status_string = f" Status: {response.status:#02x}" if response.status in chameleon_status.Device: status_string += f" {chameleon_status.Device[response.status]}"