Add cmd for nickname set and get.

This commit is contained in:
dxl
2023-02-10 11:24:00 +08:00
parent 2847a8e27c
commit 58a310b6e3
3 changed files with 96 additions and 1 deletions
+5
View File
@@ -59,6 +59,11 @@ class ChameleonCLI:
'type': new_uint(chameleon_cli_unit.HWSlotTagType, "Set emulation tag type"),
'init': new_uint(chameleon_cli_unit.HWSlotDataDefault, "Set emulation tag data to default"),
'enable': new_uint(chameleon_cli_unit.HWSlotEnableSet, "Set emulation tag slot enable or disable"),
'nick': {
'set': new_uint(chameleon_cli_unit.HWSlotNickSet, "Set tag nick name for slot"),
'get': new_uint(chameleon_cli_unit.HWSlotNickGet, "Get tag nick name for slot"),
'help': "Get/Set tag nick name for slot",
},
'help': "Emulation tag slot.",
},
'help': "hardware controller",
+51 -1
View File
@@ -745,6 +745,21 @@ class SlotIndexRequireUint(DeviceRequiredUnit):
parser.add_argument('-s', "--slot", type=int, required=True,
help="Slot index", metavar="number", choices=slot_choices)
return parser
class SenseTypeRequireUint(DeviceRequiredUnit):
def args_parser(self) -> ArgumentParserNoExit or None:
raise NotImplementedError()
def on_exec(self, args: argparse.Namespace):
raise NotImplementedError()
@staticmethod
def add_sense_type_args(parser: ArgumentParserNoExit):
slot_choices = [1, 2]
parser.add_argument('-st', "--sense_type", type=int, required=True,
help="Sense type", metavar="number", choices=slot_choices)
return parser
class HWSlotSet(SlotIndexRequireUint):
@@ -805,7 +820,8 @@ class HWSlotDataDefault(TagTypeRequiredUint, SlotIndexRequireUint):
self.add_slot_args(parser)
return parser
# hw slot init -s 1 -t 2
# m1 1k卡模拟 hw slot init -s 1 -t 3
# em id卡模拟 hw slot init -s 1 -t 1
def on_exec(self, args: argparse.Namespace):
tag_type = args.type
slot_num = args.slot
@@ -840,3 +856,37 @@ class LFEMSim(LFEMCardRequiredUint):
id_bytes = bytearray.fromhex(id_hex)
self.cmd_positive.set_em140x_sim_id(id_bytes)
print(f' - Set em410x tag id success.')
class HWSlotNickSet(SlotIndexRequireUint, SenseTypeRequireUint):
def args_parser(self) -> ArgumentParserNoExit or None:
parser = ArgumentParserNoExit()
self.add_slot_args(parser)
self.add_sense_type_args(parser)
parser.add_argument('-n', '--name', type=str, required=True, help="Yout tag nick name for slot")
return parser
# hw slot nick set -s 1 -st 1 -n 测试名称保存
def on_exec(self, args: argparse.Namespace):
slot_num = args.slot
sense_type = args.sense_type
name: str = args.name
if len(name.encode(encoding="gbk")) > 32:
raise ValueError("Your tag nick name too long.")
self.cmd_positive.set_slot_tag_nick_name(slot_num, sense_type, name)
print(f' - Set tag nick name for slot {slot_num} success.')
class HWSlotNickGet(SlotIndexRequireUint, SenseTypeRequireUint):
def args_parser(self) -> ArgumentParserNoExit or None:
parser = ArgumentParserNoExit()
self.add_slot_args(parser)
self.add_sense_type_args(parser)
return parser
# hw slot nick get -s 1 -st 1
def on_exec(self, args: argparse.Namespace):
slot_num = args.slot
sense_type = args.sense_type
res = self.cmd_positive.get_slot_tag_nick_name(slot_num, sense_type)
print(f' - Get tag nick name for slot {slot_num}: {res.data.decode(encoding="gbk")}')
+40
View File
@@ -10,6 +10,9 @@ DATA_CMD_SET_SLOT_TAG_TYPE = 1004
DATA_CMD_SET_SLOT_DATA_DEFAULT = 1005
DATA_CMD_SET_SLOT_ENABLE = 1006
DATA_CMD_SET_SLOT_TAG_NICK = 1007
DATA_CMD_GET_SLOT_TAG_NICK = 1008
DATA_CMD_SCAN_14A_TAG = 2000
DATA_CMD_MF1_SUPPORT_DETECT = 2001
DATA_CMD_MF1_NT_LEVEL_DETECT = 2002
@@ -353,6 +356,32 @@ class BaseChameleonCMD:
data.extend(atqa)
data.extend(uid)
return self.device.send_cmd_sync(DATA_CMD_SET_MF1_ANTI_COLLISION_RES, 0X00, data)
def set_slot_tag_nick_name(self, slot: int, sense_type: int, name: str):
"""
设置MF1的模拟卡的防冲撞资源信息
:param slot: 卡槽号码
:param sense_type: 场类型
:param name: 卡槽昵称
:return:
"""
data = bytearray()
data.extend([slot, sense_type])
data.extend(name.encode(encoding="gbk"))
return self.device.send_cmd_sync(DATA_CMD_SET_SLOT_TAG_NICK, 0x00, data)
def get_slot_tag_nick_name(self, slot: int, sense_type: int):
"""
设置MF1的模拟卡的防冲撞资源信息
:param slot: 卡槽号码
:param sense_type: 场类型
:param name: 卡槽昵称
:return:
"""
data = bytearray()
data.extend([slot, sense_type])
return self.device.send_cmd_sync(DATA_CMD_GET_SLOT_TAG_NICK, 0x00, data)
class NegativeResponseError(Exception):
@@ -477,4 +506,15 @@ class PositiveChameleonCMD(BaseChameleonCMD):
ret = super(PositiveChameleonCMD, self).set_mf1_anti_collision_res(sak, atqa, uid)
self.check_status(ret.status, chameleon_status.Device.STATUS_DEVICE_SUCCESS)
return ret
def set_slot_tag_nick_name(self, slot: int, sense_type: int, name: str):
ret = super(PositiveChameleonCMD, self).set_slot_tag_nick_name(slot, sense_type, name)
self.check_status(ret.status, chameleon_status.Device.STATUS_DEVICE_SUCCESS)
return ret
def get_slot_tag_nick_name(self, slot: int, sense_type: int):
ret = super(PositiveChameleonCMD, self).get_slot_tag_nick_name(slot, sense_type)
self.check_status(ret.status, chameleon_status.Device.STATUS_DEVICE_SUCCESS)
return ret