runners: canopen: Convert to -i/--dev-id
Remove the previous canopen-specific --node-id option and switch to the common -i/--dev-id one. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
parent
5ee719ee9d
commit
e3e23a51bb
1 changed files with 15 additions and 7 deletions
|
|
@ -39,7 +39,7 @@ class ToggleAction(argparse.Action):
|
|||
|
||||
class CANopenBinaryRunner(ZephyrBinaryRunner):
|
||||
'''Runner front-end for CANopen.'''
|
||||
def __init__(self, cfg, node_id, can_context=DEFAULT_CAN_CONTEXT,
|
||||
def __init__(self, cfg, dev_id, can_context=DEFAULT_CAN_CONTEXT,
|
||||
program_number=1, confirm=True,
|
||||
confirm_only=True, timeout=10):
|
||||
if MISSING_REQUIREMENTS:
|
||||
|
|
@ -48,12 +48,13 @@ class CANopenBinaryRunner(ZephyrBinaryRunner):
|
|||
"how to fix")
|
||||
|
||||
super().__init__(cfg)
|
||||
self.dev_id = dev_id # Only use for error checking in do_run()
|
||||
self.bin_file = cfg.bin_file
|
||||
self.confirm = confirm
|
||||
self.confirm_only = confirm_only
|
||||
self.timeout = timeout
|
||||
self.downloader = CANopenProgramDownloader(logger=self.logger,
|
||||
node_id=node_id,
|
||||
node_id=dev_id,
|
||||
can_context=can_context,
|
||||
program_number=program_number)
|
||||
|
||||
|
|
@ -63,14 +64,18 @@ class CANopenBinaryRunner(ZephyrBinaryRunner):
|
|||
|
||||
@classmethod
|
||||
def capabilities(cls):
|
||||
return RunnerCaps(commands={'flash'}, flash_addr=False)
|
||||
return RunnerCaps(commands={'flash'}, dev_id=True, flash_addr=False)
|
||||
|
||||
@classmethod
|
||||
def dev_id_help(cls) -> str:
|
||||
return 'CANopen Node ID.'
|
||||
|
||||
@classmethod
|
||||
def do_add_parser(cls, parser):
|
||||
# Required:
|
||||
parser.add_argument('--node-id', required=True, help='Node ID')
|
||||
|
||||
# Optional:
|
||||
parser.add_argument('--node-id', dest='dev_id',
|
||||
help=cls.dev_id_help())
|
||||
|
||||
parser.add_argument('--can-context', default=DEFAULT_CAN_CONTEXT,
|
||||
help='Custom Python-CAN context to use')
|
||||
parser.add_argument('--program-number', default=1,
|
||||
|
|
@ -88,7 +93,7 @@ class CANopenBinaryRunner(ZephyrBinaryRunner):
|
|||
|
||||
@classmethod
|
||||
def do_create(cls, cfg, args):
|
||||
return CANopenBinaryRunner(cfg, int(args.node_id),
|
||||
return CANopenBinaryRunner(cfg, int(args.dev_id),
|
||||
can_context=args.can_context,
|
||||
program_number=int(args.program_number),
|
||||
confirm=args.confirm,
|
||||
|
|
@ -96,6 +101,9 @@ class CANopenBinaryRunner(ZephyrBinaryRunner):
|
|||
timeout=int(args.timeout))
|
||||
|
||||
def do_run(self, command, **kwargs):
|
||||
if not self.dev_id:
|
||||
raise RuntimeError('Please specify a CANopen node ID with the '
|
||||
'-i/--dev-id or --node-id command-line switch.')
|
||||
if command == 'flash':
|
||||
self.flash(**kwargs)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue