diff --git a/obsw_tmtc_client.py b/obsw_tmtc_client.py index f4974460f5f609d5ac0ad37812f192df076136e3..d4c97f195a27b7f2634072a8afabf04d1b643f22 100644 --- a/obsw_tmtc_client.py +++ b/obsw_tmtc_client.py @@ -168,6 +168,7 @@ class TmTcHandler: com_interface=communication_interface, tmtc_printer=tmtc_printer, tc_queue=all_tc_queue, tm_listener=tm_listener) sender_and_receiver.send_queue_tc_and_receive_tm_sequentially() + tmtc_printer.print_file_buffer_list_to_file("log/tmtc_log.txt", True) elif self.mode == g.ModeList.UnitTest: # Set up test suite and run it with runner. Verbosity specifies detail level diff --git a/sendreceive/obsw_command_sender_receiver.py b/sendreceive/obsw_command_sender_receiver.py index 8824782260adefd7c421bc7cf8672f145b3421d2..f30e18cb4e878402bb7c28f957bcd79025864f50 100644 --- a/sendreceive/obsw_command_sender_receiver.py +++ b/sendreceive/obsw_command_sender_receiver.py @@ -121,7 +121,8 @@ class CommandSenderReceiver: self._tmtc_printer.print_string(print_string) elif queue_entry_first == "export": export_name = queue_entry_second - self._tmtc_printer.print_to_file(export_name, False) + self._tmtc_printer.add_print_buffer_to_buffer_list() + self._tmtc_printer.print_to_file(export_name, True) elif queue_entry_first == "timeout": self._tm_timeout = queue_entry_second else: diff --git a/utility/obsw_tmtc_printer.py b/utility/obsw_tmtc_printer.py index 9645c2f5aa477aa6c12312e8f6634a132b0c832a..3beaff47489147b5452411d711c7be4722eb08ee 100644 --- a/utility/obsw_tmtc_printer.py +++ b/utility/obsw_tmtc_printer.py @@ -238,7 +238,7 @@ class TmTcPrinter: if self.do_print_to_file: self.__file_buffer = self.__file_buffer + self.__print_buffer + "\r\n" - def store_file_buffer_into_buffer_list(self): + def add_print_buffer_to_buffer_list(self): self.file_buffer_list.append(self.__file_buffer) def clear_file_buffer(self): @@ -262,6 +262,29 @@ class TmTcPrinter: logger.info("Log file written to " + log_name) file.close() + def print_file_buffer_list_to_file(self, log_name: str = "log/tmtc_log.txt", + clear_list: bool = True): + """ + Joins the string list and prints it to an output file. + :param log_name: + :param clear_list: + :return: + """ + try: + file = open(log_name, 'w') + except FileNotFoundError: + logger.info("Log directory does not exists, creating log folder.") + os.mkdir('log') + file = open(log_name, 'w') + file_buffer = ''.join(self.file_buffer_list) + file.write(file_buffer) + if clear_list: + self.file_buffer_list = [] + logger.info("Log file written to " + log_name) + file.close() + + + @staticmethod def bit_extractor(byte: int, position: int): """