flash c ontent report works now

This commit is contained in:
Robin Müller 2023-05-12 16:24:45 +02:00
parent e05a54b076
commit 04bbe057e7
Signed by: muellerr
GPG Key ID: A649FB78196E3849

View File

@ -652,19 +652,20 @@ def handle_mpsoc_data_reply(
printer.file_logger.info(header_list) printer.file_logger.info(header_list)
printer.file_logger.info(content_list) printer.file_logger.info(content_list)
elif action_id == ActionId.TM_FLASH_DIRECTORY_CONTENT: elif action_id == ActionId.TM_FLASH_DIRECTORY_CONTENT:
print(custom_data.hex(sep=","))
if len(custom_data) < 16: if len(custom_data) < 16:
_LOGGER.warning( _LOGGER.warning(
"PLOC MPSoC flash directory data shorter than minimum 16 bytes" "PLOC MPSoC flash directory data shorter than minimum 16 bytes"
) )
current_idx = 0 current_idx = 0
dir_name_short = custom_data[current_idx : current_idx + 12] dir_name_short = custom_data[current_idx : current_idx + 12].decode("utf-8")
current_idx += 12 current_idx += 12
num_elements = struct.unpack("!I", custom_data[current_idx : current_idx + 4])[ num_elements = struct.unpack("!I", custom_data[current_idx : current_idx + 4])[
0 0
] ]
current_idx += 4 current_idx += 4
elems = [] elem_names = []
elem_attrs = []
elem_sizes = []
expected_size = 16 + num_elements * 17 expected_size = 16 + num_elements * 17
if len(custom_data) < expected_size: if len(custom_data) < expected_size:
_LOGGER.warning( _LOGGER.warning(
@ -674,13 +675,21 @@ def handle_mpsoc_data_reply(
f"Received PLOC MPSoC flash directory content for path {dir_name_short} " f"Received PLOC MPSoC flash directory content for path {dir_name_short} "
f"with {num_elements} elements" f"with {num_elements} elements"
) )
for i in range(num_elements): # It is as weird as it looks..
elem_name = custom_data[current_idx : current_idx + 12].decode("utf-8") for _ in range(num_elements):
end_of_str = custom_data[current_idx : current_idx + 12].index(b"\x00")
elem_name = custom_data[current_idx : current_idx + end_of_str].decode(
"utf-8"
)
current_idx += 12 current_idx += 12
elem_attr = custom_data[current_idx] elem_names.append(elem_name)
for _ in range(num_elements):
elem_attrs.append(custom_data[current_idx])
current_idx += 1 current_idx += 1
elem_size = current_idx[current_idx : current_idx + 4] for _ in range(num_elements):
elem_sizes.append(
struct.unpack("!I", custom_data[current_idx : current_idx + 4])[0]
)
current_idx += 4 current_idx += 4
elems.append(DirElement(elem_name, elem_attr, elem_size)) for i in range(num_elements):
for elem in elems: pw.dlog(f"{DirElement(elem_names[i], elem_attrs[i], elem_sizes[i])}")
pw.dlog(f"{elem}")