MPSoC flash content reporter #190

Merged
meggert merged 4 commits from mpsoc_action_reply_handler into main 2023-05-15 09:10:42 +02:00
Showing only changes of commit 04bbe057e7 - Show all commits

View File

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