change slot nicknames encoding: gbk -> utf8

This commit is contained in:
Philippe Teuwen
2023-08-19 00:14:19 +02:00
parent 8e093d00b6
commit 3bfc52432a
3 changed files with 7 additions and 8 deletions
-2
View File
@@ -473,7 +473,6 @@ data_frame_tx_t* cmd_processor_set_mf1_anti_collision_res(uint16_t cmd, uint16_t
}
data_frame_tx_t* cmd_processor_set_slot_tag_nick_name(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
// one chinese have 2byte(gbk).
if (length > 34 || length < 3) {
status = STATUS_PAR_ERR;
} else {
@@ -498,7 +497,6 @@ data_frame_tx_t* cmd_processor_set_slot_tag_nick_name(uint16_t cmd, uint16_t sta
}
data_frame_tx_t* cmd_processor_get_slot_tag_nick_name(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
// one chinese have 2byte(gbk).
if (length != 2) {
status = STATUS_PAR_ERR;
} else {
+4 -3
View File
@@ -940,9 +940,10 @@ class HWSlotNickSet(SlotIndexRequireUint, SenseTypeRequireUint):
slot_num = args.slot
sense_type = args.sense_type
name: str = args.name
if len(name.encode(encoding="gbk")) > 32:
uname = name.encode(encoding="utf8")
if len(uname) > 32:
raise ValueError("Your tag nick name too long.")
self.cmd_positive.set_slot_tag_nick_name(slot_num, sense_type, name)
self.cmd_positive.set_slot_tag_nick_name(slot_num, sense_type, uname)
print(f' - Set tag nick name for slot {slot_num} success.')
@@ -958,7 +959,7 @@ class HWSlotNickGet(SlotIndexRequireUint, SenseTypeRequireUint):
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")}')
print(f' - Get tag nick name for slot {slot_num}: {res.data.decode(encoding="utf8")}')
class HWSlotUpdate(DeviceRequiredUnit):
+3 -3
View File
@@ -433,7 +433,7 @@ class BaseChameleonCMD:
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):
def set_slot_tag_nick_name(self, slot: int, sense_type: int, name: bytes):
"""
设置MF1的模拟卡的防冲撞资源信息
:param slot: 卡槽号码
@@ -443,7 +443,7 @@ class BaseChameleonCMD:
"""
data = bytearray()
data.extend([slot, sense_type])
data.extend(name.encode(encoding="gbk"))
data.extend(name)
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):
@@ -620,7 +620,7 @@ class PositiveChameleonCMD(BaseChameleonCMD):
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):
def set_slot_tag_nick_name(self, slot: int, sense_type: int, name: bytes):
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