Skip to content

Commit

Permalink
[SC64][SW] Fixed firmware update error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Polprzewodnikowy committed Feb 12, 2023
1 parent fc3e6dd commit 72f6160
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sw/pc/sc64.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,23 @@ def __queue_cmd(self, cmd: bytes, args: list[int]=[0, 0], data: bytes=b'') -> No
packet += data
self.__queue_output.put(packet)

def __pop_response(self, cmd: bytes, timeout: float) -> bytes:
def __pop_response(self, cmd: bytes, timeout: float, raise_on_err: bool) -> bytes:
try:
(response_cmd, data, success) = self.__queue_input.get(timeout=timeout)
self.__queue_input.task_done()
if (cmd != response_cmd):
raise ConnectionException('CMD wrong command response')
if (success == False):
if (raise_on_err and success == False):
raise ConnectionException('CMD response error')
return data
except queue.Empty:
raise ConnectionException('CMD response timeout')

def execute_cmd(self, cmd: bytes, args: list[int]=[0, 0], data: bytes=b'', response: bool=True, timeout: float=5.0) -> Optional[bytes]:
def execute_cmd(self, cmd: bytes, args: list[int]=[0, 0], data: bytes=b'', response: bool=True, timeout: float=5.0, raise_on_err: bool=True) -> Optional[bytes]:
self.__check_threads()
self.__queue_cmd(cmd, args, data)
if (response):
return self.__pop_response(cmd, timeout)
return self.__pop_response(cmd, timeout, raise_on_err)
return None

def get_packet(self, timeout: float=0.1) -> Optional[tuple[bytes, bytes]]:
Expand Down Expand Up @@ -554,7 +554,7 @@ def set_led_enable(self, enabled: bool) -> None:
def update_firmware(self, data: bytes, status_callback: Optional[Callable[[str], None]]=None) -> None:
address = self.__Address.FIRMWARE
self.__write_memory(address, data)
response = self.__link.execute_cmd(cmd=b'F', args=[address, len(data)])
response = self.__link.execute_cmd(cmd=b'F', args=[address, len(data)], raise_on_err=False)
error = self.__UpdateError(self.__get_int(response[0:4]))
if (error != self.__UpdateError.OK):
raise ConnectionException(f'Bad update image [{error.name}]')
Expand All @@ -575,7 +575,7 @@ def update_firmware(self, data: bytes, status_callback: Optional[Callable[[str],

def backup_firmware(self) -> bytes:
address = self.__Address.FIRMWARE
info = self.__link.execute_cmd(cmd=b'f', args=[address, 0], timeout=60.0)
info = self.__link.execute_cmd(cmd=b'f', args=[address, 0], timeout=60.0, raise_on_err=False)
error = self.__UpdateError(self.__get_int(info[0:4]))
length = self.__get_int(info[4:8])
if (error != self.__UpdateError.OK):
Expand Down

0 comments on commit 72f6160

Please sign in to comment.