This commit is contained in:
Robin Müller 2023-04-16 02:56:14 +02:00
parent 5a49c4a6ce
commit d623e83be8
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 23 additions and 6 deletions

View File

@ -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

View File

@ -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())