Skip to content

Commit af86e1e

Browse files
committed
handle invalid binary time value set
only sends the time command when the time is gregorian calendar, else raise an exception
1 parent c8a131c commit af86e1e

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/explorepy/command.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ def __init__(self):
234234
self.opcode = OpcodeID.CMD_SET_EMMC_TIME
235235
from datetime import datetime
236236
now = datetime.now()
237+
if not (2020 < now.year < 2099):
238+
raise ValueError(f"Unsupported year: {now.year}")
237239
date_time = bytes(
238240
[
239241
now.year - 2000,

src/explorepy/explore.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,14 @@ def set_binary_time(self):
661661
Returns:
662662
bool: True for success, False otherwise
663663
"""
664-
cmd = SetBinaryTime()
665-
if self.stream_processor.configure_device(cmd):
666-
logger.info('Device set to current time.')
667-
return True
664+
try:
665+
cmd = SetBinaryTime()
666+
if self.stream_processor.configure_device(cmd):
667+
logger.info('Device set to current time.')
668+
return True
669+
except ValueError as e:
670+
logger.error('Error on setting the binary file time: {}'.format(e))
671+
return False
668672

669673
def reset_soft(self):
670674
"""Reset the device to the default settings

0 commit comments

Comments
 (0)