flash c ontent report works now

This commit is contained in:
Robin Müller 2023-05-12 16:24:45 +02:00 committed by Robin Mueller
parent d74c3fc241
commit 1c1af2c7c7

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])}")