Skip to content

Commit

Permalink
cli: -s mandatory for slot change, sense_type now --hf/--lf, slot opt…
Browse files Browse the repository at this point in the history
…ional for hw slot init/type/delete
  • Loading branch information
doegox committed Oct 7, 2023
1 parent 3022e05 commit 0c6abbe
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions software/script/chameleon_cli_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,11 +1155,11 @@ def on_exec(self, args: argparse.Namespace):
raise NotImplementedError()

@staticmethod
def add_slot_args(parser: ArgumentParserNoExit):
def add_slot_args(parser: ArgumentParserNoExit, mandatory=False):
slot_choices = [x.value for x in chameleon_cmd.SlotNumber]
help_str = f"Slot Index: {slot_choices} Default: active slot"

parser.add_argument('-s', "--slot", type=int, required=False, help=help_str, metavar="number",
parser.add_argument('-s', "--slot", type=int, required=mandatory, help=help_str, metavar="number",
choices=slot_choices)
return parser

Expand All @@ -1173,16 +1173,9 @@ def on_exec(self, args: argparse.Namespace):

@staticmethod
def add_sense_type_args(parser: ArgumentParserNoExit):
sense_choices = chameleon_cmd.TagSenseType.list()

help_str = ""
for s in chameleon_cmd.TagSenseType:
if s == chameleon_cmd.TagSenseType.TAG_SENSE_NO:
continue
help_str += f"{s.value} = {s}, "

parser.add_argument('-st', "--sense_type", type=int, required=True, help=help_str, metavar="number",
choices=sense_choices)
sense_group = parser.add_mutually_exclusive_group(required=True)
sense_group.add_argument('--hf', action='store_true', help="HF type")
sense_group.add_argument('--lf', action='store_true', help="LF type")
return parser


Expand Down Expand Up @@ -1266,7 +1259,7 @@ class HWSlotSet(SlotIndexRequireUnit):
def args_parser(self) -> ArgumentParserNoExit:
parser = ArgumentParserNoExit()
parser.description = 'Set emulation tag slot activated'
return self.add_slot_args(parser)
return self.add_slot_args(parser, mandatory=True)

# hw slot change -s 1
def on_exec(self, args: argparse.Namespace):
Expand Down Expand Up @@ -1295,20 +1288,23 @@ def on_exec(self, args: argparse.Namespace):


@hw_slot.command('type')
class HWSlotTagType(TagTypeRequiredUnit, SlotIndexRequireUnit):
class HWSlotType(TagTypeRequiredUnit, SlotIndexRequireUnit):
def args_parser(self) -> ArgumentParserNoExit:
parser = ArgumentParserNoExit()
parser.description = 'Set emulation tag type'
self.add_slot_args(parser)
self.add_type_args(parser)
return parser

# hw slot tagtype -t 2
# hw slot type -t 2
def on_exec(self, args: argparse.Namespace):
tag_type = args.type
slot_index = args.slot
self.cmd.set_slot_tag_type(slot_index, tag_type)
print(' - Set slot tag type success.')
if args.slot is not None:
slot_num = args.slot
else:
slot_num = chameleon_cmd.SlotNumber.from_fw(self.cmd.get_active_slot())
self.cmd.set_slot_tag_type(slot_num, tag_type)
print(f' - Set slot {slot_num} tag type success.')


@hw_slot.command('delete')
Expand All @@ -1321,13 +1317,20 @@ def args_parser(self) -> ArgumentParserNoExit:
return parser

def on_exec(self, args: argparse.Namespace):
slot = args.slot
sense_type = chameleon_cmd.TagSenseType(args.sense_type)
self.cmd.delete_slot_sense_type(slot, sense_type)
if args.slot is not None:
slot_num = args.slot
else:
slot_num = chameleon_cmd.SlotNumber.from_fw(self.cmd.get_active_slot())
if args.lf:
sense_type = chameleon_cmd.TagSenseType.TAG_SENSE_LF
else:
sense_type = chameleon_cmd.TagSenseType.TAG_SENSE_HF
self.cmd.delete_slot_sense_type(slot_num, sense_type)
print(f' - Delete slot {slot_num} {sense_type} tag type success.')


@hw_slot.command('init')
class HWSlotDataDefault(TagTypeRequiredUnit, SlotIndexRequireUnit):
class HWSlotInit(TagTypeRequiredUnit, SlotIndexRequireUnit):
def args_parser(self) -> ArgumentParserNoExit:
parser = ArgumentParserNoExit()
parser.description = 'Set emulation tag data to default'
Expand All @@ -1339,7 +1342,10 @@ def args_parser(self) -> ArgumentParserNoExit:
# em id card simulation hw slot init -s 1 -t 1
def on_exec(self, args: argparse.Namespace):
tag_type = args.type
slot_num = args.slot
if args.slot is not None:
slot_num = args.slot
else:
slot_num = chameleon_cmd.SlotNumber.from_fw(self.cmd.get_active_slot())
self.cmd.set_slot_data_default(slot_num, tag_type)
print(' - Set slot tag data init success.')

Expand All @@ -1357,7 +1363,10 @@ def args_parser(self) -> ArgumentParserNoExit:
# hw slot enable -s 1 -st 0 -e 0
def on_exec(self, args: argparse.Namespace):
slot_num = args.slot
sense_type = chameleon_cmd.TagSenseType(args.sense_type)
if args.lf:
sense_type = chameleon_cmd.TagSenseType.TAG_SENSE_LF
else:
sense_type = chameleon_cmd.TagSenseType.TAG_SENSE_HF
enable = args.enable
self.cmd.set_slot_enable(slot_num, sense_type, enable)
print(f' - Set slot {slot_num} {sense_type} {"enable" if enable else "disable"} success.')
Expand Down Expand Up @@ -1408,7 +1417,10 @@ def on_exec(self, args: argparse.Namespace):
slot_num = args.slot
else:
slot_num = chameleon_cmd.SlotNumber.from_fw(self.cmd.get_active_slot())
sense_type = chameleon_cmd.TagSenseType(args.sense_type)
if args.lf:
sense_type = chameleon_cmd.TagSenseType.TAG_SENSE_LF
else:
sense_type = chameleon_cmd.TagSenseType.TAG_SENSE_HF
if args.name is not None:
name: str = args.name
encoded_name = name.encode(encoding="utf8")
Expand Down

0 comments on commit 0c6abbe

Please sign in to comment.