"""Extract the last 5 minutes of SWA TM before each unexpected DPU reboot """ from solar import * from CCSDS import CCSDS_reader import datetime REBOOT_LIST = "dpu_reboot.list" OFFSET = datetime.timedelta (minutes = 5) TM_filter = lambda packet: packet.packet_type == 0 PAS_TM_filter = lambda packet : packet.packet_type == 0 and packet.descr.startswith ("SWA_TM_SCI_PAS") FILTER = TM_filter def read_dpu_reboot (filename): """ Read DPU reboots timetags from Ascii file """ with open (filename) as input: for line in input: yield str_to_datetime (line.strip()) def get_last_TM (reboot_tt): """ Get last minutes TM data for a given timetag """ day = reboot_tt.date() filename = get_L0_filename (day, "swa-pas-tm", "bin") start = reboot_tt - OFFSET print (start.isoformat(), reboot_tt.isoformat(), filename) log_file = "%s.log" % ymd (day) hex_file = "%s.hex" % ymd (day) with open (log_file, "w") as flog: with open (hex_file, "w") as fhex: for packet in filter (FILTER, CCSDS_reader (filename)): if start <= packet.dt <= reboot_tt: print (packet, file = flog) print (packet.raw.hex(), file = fhex) if __name__ == "__main__": # for reboot in read_dpu_reboot (REBOOT_LIST): reboot = list (read_dpu_reboot (REBOOT_LIST))[-1] get_last_TM (reboot)