From d623e83be8536f8887f1da00a1f0c4be191db1e8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 16 Apr 2023 02:56:14 +0200 Subject: [PATCH] done --- eive_tmtc/pus_tm/action_reply_handler.py | 1 + eive_tmtc/tmtc/core.py | 28 +++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/eive_tmtc/pus_tm/action_reply_handler.py b/eive_tmtc/pus_tm/action_reply_handler.py index ac09253..bc556d4 100644 --- a/eive_tmtc/pus_tm/action_reply_handler.py +++ b/eive_tmtc/pus_tm/action_reply_handler.py @@ -2,6 +2,7 @@ import struct from eive_tmtc.config.object_ids import * from eive_tmtc.tmtc.acs.imtq import ImtqActionId from eive_tmtc.pus_tm.defs import PrintWrapper +from eive_tmtc.tmtc.core import handle_core_ctrl_action_replies from eive_tmtc.tmtc.payload.ploc_mpsoc import PlocReplyIds from eive_tmtc.tmtc.payload.ploc_supervisor import SupvActionId from eive_tmtc.tmtc.acs.star_tracker import StarTrackerActionId diff --git a/eive_tmtc/tmtc/core.py b/eive_tmtc/tmtc/core.py index 706b582..461cc1f 100644 --- a/eive_tmtc/tmtc/core.py +++ b/eive_tmtc/tmtc/core.py @@ -1,6 +1,8 @@ import enum import logging +import os import struct +from pathlib import Path from eive_tmtc.pus_tm.defs import PrintWrapper @@ -603,23 +605,37 @@ def handle_core_ctrl_action_replies( return seq_idx = struct.unpack("!I", custom_data[0:4])[0] total_chunks = struct.unpack("!I", custom_data[4:8])[0] - compressed = custom_data[4] - ls_cmd = custom_data[5:].decode() + compressed = custom_data[8] + ls_cmd = custom_data[9:].split(b"\x00")[0].decode() # Include length of NULL termination - file_data_offset = 5 + len(ls_cmd) + 1 + file_data_offset = 9 + len(ls_cmd) + 1 pw.dlog( - f"Received directory listing dump for ls command {ls_cmd}. Chunk {seq_idx}/{total_chunks}" + f"Received directory listing dump for ls command {ls_cmd}. " + f"Chunk {seq_idx + 1}/{total_chunks}" ) + + def remove_if_exists_and_new(seq_idx_: int, path_: Path): + if seq_idx_ == 0 and path_.exists(): + os.remove(path_) + if compressed: + path = Path("dir_listing.txt.gz") + remove_if_exists_and_new(seq_idx, path) pw.dlog( f"Compression option: {compressed}. Dumping file into dir_listing.txt.gz" ) - with open("dir_listing.txt.gz", "ab") as listing_file: + with open(path, "ab") as listing_file: listing_file.write(custom_data[file_data_offset:]) else: + path = Path("dir_listing.txt") + remove_if_exists_and_new(seq_idx, path) pw.dlog( f"Compression option: {compressed}. Dumping file into dir_listing.txt" ) - with open("dir_listing.txt", "a") as listing_file: + with open(path, "a") as listing_file: listing_file_str = custom_data[file_data_offset:].decode() listing_file.write(listing_file_str) + if seq_idx + 1 == total_chunks: + pw.dlog("Full directory listing: ") + with open("dir_listing.txt", "r") as listing_file: + print(listing_file.read())