Skip to content

Commit aa0c1ba

Browse files
committed
fixed comand error when changing waketime
1 parent 441e81e commit aa0c1ba

2 files changed

Lines changed: 129 additions & 62 deletions

File tree

software/script/chameleon_cli_unit.py

Lines changed: 77 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ def args_parser(self) -> ArgumentParserNoExit:
964964
parser = ArgumentParserNoExit()
965965
parser.description = 'Mifare Classic clone tag from dump'
966966
parser.add_argument('-t', '--dump-file-type', type=str, required=False, help="Dump file content type", choices=['bin', 'hex'])
967-
parser.add_argument('-a', '--clone-access', type=bool, default=False, help="Write ACL from original dump too (/!\ could brick your tag)")
967+
parser.add_argument('-a', '--clone-access', type=bool, default=False, help=r"Write ACL from original dump too (/!\ could brick your tag)")
968968
parser.add_argument('-f', '--dump-file', type=argparse.FileType("rb"), required=True,
969969
help="Dump file containing data to write on new tag")
970970
parser.add_argument('-d', '--dic', type=argparse.FileType("r"), required=True,
@@ -3473,18 +3473,7 @@ def on_exec(self, args: argparse.Namespace):
34733473
print(AnimationMode(self.cmd.get_animation_mode()))
34743474

34753475

3476-
@hw_settings.group('wakeuptime')
3477-
class HWSettingsWakeupTime(DeviceRequiredUnit):
3478-
def args_parser(self) -> ArgumentParserNoExit:
3479-
parser = ArgumentParserNoExit()
3480-
return parser
3481-
3482-
def on_exec(self, args: argparse.Namespace):
3483-
# Show help if no subcommand is provided
3484-
self.args_parser().print_help()
3485-
3486-
3487-
@HWSettingsWakeupTime.command('button')
3476+
@hw_settings.command('wakeuptime_button')
34883477
class HWSettingsWakeupTimeButton(DeviceRequiredUnit):
34893478
def args_parser(self) -> ArgumentParserNoExit:
34903479
parser = ArgumentParserNoExit()
@@ -3494,26 +3483,47 @@ def args_parser(self) -> ArgumentParserNoExit:
34943483
return parser
34953484

34963485
def on_exec(self, args: argparse.Namespace):
3497-
if args.set is not None:
3498-
if not 1000 <= args.set <= 60000:
3499-
print(f"{CR}Error: Wake-up time must be between 1000 and 60000 milliseconds{C0}")
3500-
return
3501-
3502-
resp = self.cmd.set_wakeup_button_time(args.set)
3503-
if resp.status == Status.SUCCESS:
3504-
print(f"Successfully set button wake-up time to {args.set} ms")
3505-
print(f"{CY}Do not forget to store your settings in flash!{C0}")
3506-
else:
3507-
print(f"Failed to set button wake-up time: {Status(resp.status)}")
3508-
else:
3509-
resp = self.cmd.get_wakeup_button_time()
3510-
if resp.status == Status.SUCCESS:
3511-
print(f"Button wake-up time: {resp.parsed} ms")
3486+
try:
3487+
if args.set is not None:
3488+
print(f"[CLI] Setting button wake-up time to {args.set} ms")
3489+
try:
3490+
resp = self.cmd.set_wakeup_button_time(args.set)
3491+
if resp is None:
3492+
print(f"{CR}Error: No response from device{C0}")
3493+
return
3494+
3495+
print(f"{CG}Successfully set button wake-up time to {args.set} ms{C0}")
3496+
3497+
# Try to save settings to flash
3498+
try:
3499+
print("Saving settings to flash...")
3500+
save_resp = self.cmd.save_settings()
3501+
if save_resp and hasattr(save_resp, 'status'):
3502+
if save_resp.status == Status.SUCCESS:
3503+
print(f"{CG}Settings saved to flash memory{C0}")
3504+
else:
3505+
print(f"{CY}Warning: Save failed with status: {Status(save_resp.status).name}{C0}")
3506+
else:
3507+
print(f"{CY}Warning: Invalid response when saving settings{C0}")
3508+
except Exception as e:
3509+
print(f"{CY}Warning: Could not save settings: {str(e)}{C0}")
3510+
3511+
except Exception as e:
3512+
print(f"{CR}Error setting wake-up time: {str(e)}{C0}")
35123513
else:
3513-
print(f"Failed to get button wake-up time: {Status(resp.status)}")
3514+
print("[CLI] Getting button wake-up time")
3515+
resp = self.cmd.get_wakeup_button_time()
3516+
if resp is None:
3517+
print(f"{CR}Error: No response from device{C0}")
3518+
elif resp.status == Status.SUCCESS:
3519+
print(f"Button wake-up time: {CG}{resp.parsed} ms{C0}")
3520+
else:
3521+
print(f"{CR}Failed to get button wake-up time: {Status(resp.status).name}{C0}")
3522+
except Exception as e:
3523+
print(f"{CR}Error: {str(e)}{C0}")
35143524

35153525

3516-
@HWSettingsWakeupTime.command('field')
3526+
@hw_settings.command('wakeuptime_field')
35173527
class HWSettingsWakeupTimeField(DeviceRequiredUnit):
35183528
def args_parser(self) -> ArgumentParserNoExit:
35193529
parser = ArgumentParserNoExit()
@@ -3523,23 +3533,44 @@ def args_parser(self) -> ArgumentParserNoExit:
35233533
return parser
35243534

35253535
def on_exec(self, args: argparse.Namespace):
3526-
if args.set is not None:
3527-
if not 1000 <= args.set <= 60000:
3528-
print(f"{CR}Error: Wake-up time must be between 1000 and 60000 milliseconds{C0}")
3529-
return
3530-
3531-
resp = self.cmd.set_wakeup_field_time(args.set)
3532-
if resp.status == Status.SUCCESS:
3533-
print(f"Successfully set field detection wake-up time to {args.set} ms")
3534-
print(f"{CY}Do not forget to store your settings in flash!{C0}")
3535-
else:
3536-
print(f"Failed to set field detection wake-up time: {Status(resp.status)}")
3537-
else:
3538-
resp = self.cmd.get_wakeup_field_time()
3539-
if resp.status == Status.SUCCESS:
3540-
print(f"Field detection wake-up time: {resp.parsed} ms")
3536+
try:
3537+
if args.set is not None:
3538+
print(f"[CLI] Setting field detection wake-up time to {args.set} ms")
3539+
try:
3540+
resp = self.cmd.set_wakeup_field_time(args.set)
3541+
if resp is None:
3542+
print(f"{CR}Error: No response from device{C0}")
3543+
return
3544+
3545+
print(f"{CG}Successfully set field detection wake-up time to {args.set} ms{C0}")
3546+
3547+
# Try to save settings to flash
3548+
try:
3549+
print("Saving settings to flash...")
3550+
save_resp = self.cmd.save_settings()
3551+
if save_resp and hasattr(save_resp, 'status'):
3552+
if save_resp.status == Status.SUCCESS:
3553+
print(f"{CG}Settings saved to flash memory{C0}")
3554+
else:
3555+
print(f"{CY}Warning: Save failed with status: {Status(save_resp.status).name}{C0}")
3556+
else:
3557+
print(f"{CY}Warning: Invalid response when saving settings{C0}")
3558+
except Exception as e:
3559+
print(f"{CY}Warning: Could not save settings: {str(e)}{C0}")
3560+
3561+
except Exception as e:
3562+
print(f"{CR}Error setting field detection wake-up time: {str(e)}{C0}")
35413563
else:
3542-
print(f"Failed to get field detection wake-up time: {Status(resp.status)}")
3564+
print("[CLI] Getting field detection wake-up time")
3565+
resp = self.cmd.get_wakeup_field_time()
3566+
if resp is None:
3567+
print(f"{CR}Error: No response from device{C0}")
3568+
elif resp.status == Status.SUCCESS:
3569+
print(f"Field detection wake-up time: {CG}{resp.parsed} ms{C0}")
3570+
else:
3571+
print(f"{CR}Failed to get field detection wake-up time: {Status(resp.status).name}{C0}")
3572+
except Exception as e:
3573+
print(f"{CR}Error: {str(e)}{C0}")
35433574

35443575

35453576
@hw_settings.command('bleclearbonds')

software/script/chameleon_cmd.py

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,34 +1090,70 @@ def set_ble_pairing_enable(self, enabled: bool):
10901090
@expect_response(Status.SUCCESS)
10911091
def get_wakeup_button_time(self):
10921092
"""Get the button wake-up time in milliseconds (1000-60000)"""
1093-
resp = self.device.send_cmd_sync(Command.GET_WAKEUP_BUTTON_TIME)
1094-
if resp.status == Status.SUCCESS and len(resp.data) >= 2:
1095-
resp.parsed = int.from_bytes(resp.data[:2], byteorder='little')
1096-
return resp
1093+
try:
1094+
print(f"[DEBUG] Sending GET_WAKEUP_BUTTON_TIME command")
1095+
resp = self.device.send_cmd_sync(Command.GET_WAKEUP_BUTTON_TIME)
1096+
print(f"[DEBUG] Response: {resp}")
1097+
if resp and hasattr(resp, 'status'):
1098+
print(f"[DEBUG] Response status: {Status(resp.status).name}")
1099+
if resp.status == Status.SUCCESS and len(resp.data) >= 2:
1100+
resp.parsed = int.from_bytes(resp.data[:2], byteorder='little')
1101+
print(f"[DEBUG] Parsed wakeup time: {resp.parsed} ms")
1102+
return resp
1103+
except Exception as e:
1104+
print(f"[DEBUG] Error in get_wakeup_button_time: {str(e)}")
1105+
raise
10971106

10981107
@expect_response(Status.SUCCESS)
10991108
def set_wakeup_button_time(self, time_ms: int):
11001109
"""Set the button wake-up time (1000-60000 ms)"""
1101-
if not 1000 <= time_ms <= 60000:
1102-
raise ValueError("Wake-up time must be between 1000 and 60000 milliseconds")
1103-
data = time_ms.to_bytes(2, byteorder='little')
1104-
return self.device.send_cmd_sync(Command.SET_WAKEUP_BUTTON_TIME, data)
1110+
try:
1111+
if not 1000 <= time_ms <= 60000:
1112+
raise ValueError("Wake-up time must be between 1000 and 60000 milliseconds")
1113+
data = time_ms.to_bytes(2, byteorder='little')
1114+
print(f"[DEBUG] Sending SET_WAKEUP_BUTTON_TIME with data: {data.hex()}")
1115+
resp = self.device.send_cmd_sync(Command.SET_WAKEUP_BUTTON_TIME, data)
1116+
print(f"[DEBUG] Response: {resp}")
1117+
if resp and hasattr(resp, 'status'):
1118+
print(f"[DEBUG] Response status: {Status(resp.status).name}")
1119+
return resp
1120+
except Exception as e:
1121+
print(f"[DEBUG] Error in set_wakeup_button_time: {str(e)}")
1122+
raise
11051123

11061124
@expect_response(Status.SUCCESS)
11071125
def get_wakeup_field_time(self):
11081126
"""Get the field detection wake-up time in milliseconds (1000-60000)"""
1109-
resp = self.device.send_cmd_sync(Command.GET_WAKEUP_FIELD_TIME)
1110-
if resp.status == Status.SUCCESS and len(resp.data) >= 2:
1111-
resp.parsed = int.from_bytes(resp.data[:2], byteorder='little')
1112-
return resp
1127+
try:
1128+
print(f"[DEBUG] Sending GET_WAKEUP_FIELD_TIME command")
1129+
resp = self.device.send_cmd_sync(Command.GET_WAKEUP_FIELD_TIME)
1130+
print(f"[DEBUG] Response: {resp}")
1131+
if resp and hasattr(resp, 'status'):
1132+
print(f"[DEBUG] Response status: {Status(resp.status).name}")
1133+
if resp.status == Status.SUCCESS and len(resp.data) >= 2:
1134+
resp.parsed = int.from_bytes(resp.data[:2], byteorder='little')
1135+
print(f"[DEBUG] Parsed field wakeup time: {resp.parsed} ms")
1136+
return resp
1137+
except Exception as e:
1138+
print(f"[DEBUG] Error in get_wakeup_field_time: {str(e)}")
1139+
raise
11131140

11141141
@expect_response(Status.SUCCESS)
11151142
def set_wakeup_field_time(self, time_ms: int):
11161143
"""Set the field detection wake-up time (1000-60000 ms)"""
1117-
if not 1000 <= time_ms <= 60000:
1118-
raise ValueError("Wake-up time must be between 1000 and 60000 milliseconds")
1119-
data = time_ms.to_bytes(2, byteorder='little')
1120-
return self.device.send_cmd_sync(Command.SET_WAKEUP_FIELD_TIME, data)
1144+
try:
1145+
if not 1000 <= time_ms <= 60000:
1146+
raise ValueError("Wake-up time must be between 1000 and 60000 milliseconds")
1147+
data = time_ms.to_bytes(2, byteorder='little')
1148+
print(f"[DEBUG] Sending SET_WAKEUP_FIELD_TIME with data: {data.hex()}")
1149+
resp = self.device.send_cmd_sync(Command.SET_WAKEUP_FIELD_TIME, data)
1150+
print(f"[DEBUG] Response: {resp}")
1151+
if resp and hasattr(resp, 'status'):
1152+
print(f"[DEBUG] Response status: {Status(resp.status).name}")
1153+
return resp
1154+
except Exception as e:
1155+
print(f"[DEBUG] Error in set_wakeup_field_time: {str(e)}")
1156+
raise
11211157

11221158

11231159
def test_fn():

0 commit comments

Comments
 (0)