From ed83b0ba8aa7e50735bcaea1b37440327c6ac75c Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" <robin.mueller.m@gmail.com> Date: Sun, 26 Apr 2020 21:33:22 +0200 Subject: [PATCH] some more logger replacements --- comIF/obsw_serial_com_if.py | 51 ++++++--------------- sendreceive/obsw_command_sender_receiver.py | 5 +- 2 files changed, 16 insertions(+), 40 deletions(-) diff --git a/comIF/obsw_serial_com_if.py b/comIF/obsw_serial_com_if.py index 29371c1..c631521 100644 --- a/comIF/obsw_serial_com_if.py +++ b/comIF/obsw_serial_com_if.py @@ -8,14 +8,17 @@ import sys import time import logging -from typing import Tuple, List, Union, Optional +from typing import Tuple, List, Optional import serial -from comIF.obsw_com_interface import CommunicationInterface, PusTmQueueT +from comIF.obsw_com_interface import CommunicationInterface from utility.obsw_tmtc_printer import TmTcPrinter -from tm.obsw_pus_tm_factory import PusTelemetryFactory, PusTmInfoQueueT, PusTmTupleQueueT, PusTmListT +from tm.obsw_pus_tm_factory import PusTelemetryFactory, PusTmListT from tc.obsw_pus_tc_base import PusTcInfoT +from utility.obsw_logger import get_logger + +logger = get_logger() SERIAL_FRAME_LENGTH = 256 HEADER_BYTES_BEFORE_SIZE = 5 @@ -31,20 +34,16 @@ class SerialComIF(CommunicationInterface): super().__init__(tmtc_printer) try: self.serial = serial.Serial(port=com_port, baudrate=baud_rate, timeout=serial_timeout) - except serial.SerialException: - print("Serial Port can not be opened") - logging.exception("Error") - sys.exit() + except serial.SerialException as e: + logging.exception("Serial Port could not be closed! Traceback: " + str(e)) self.data = bytearray() self.number_of_packets = 0 def close(self): try: self.serial.close() - except serial.SerialException: - print("Serial Port could not be closed !") - logging.exception("Error") - sys.exit() + except serial.SerialException as e: + logging.exception("Serial Port could not be closed! Traceback: " + str(e)) def send_telecommand(self, tc_packet: bytearray, tc_packet_info: PusTcInfoT = None) -> None: self.serial.write(tc_packet) @@ -105,9 +104,9 @@ class SerialComIF(CommunicationInterface): next_payload_len = (self.data[end_index - 1] << 8 | self.data[end_index]) next_packet_size = next_payload_len + 7 if next_packet_size > SERIAL_FRAME_LENGTH: - print("PUS Polling: Very Large wiretapping_packet detected, " - "large wiretapping_packet reading not implemented yet !") - print("Detected Size: " + str(next_packet_size)) + logger.error("PUS Polling: Very large packet detected, " + "large packet reading not implemented yet !") + logger.error("Detected Size: " + str(next_packet_size)) return end_index elif next_payload_len == 0: end_index = SERIAL_FRAME_LENGTH @@ -118,27 +117,3 @@ class SerialComIF(CommunicationInterface): self.number_of_packets = self.number_of_packets + 1 return end_index - # def receive_telemetry_and_store_tm(self, tm_queue: PusTmQueueT) -> Union[None, PusTmQueueT]: - # (packet_received, pus_packets) = self.poll_interface() - # if packet_received: - # for packet in pus_packets: - # tm_queue.append(packet) - # return tm_queue - # - # def receive_telemetry_and_store_info(self, tm_info_queue: PusTmInfoQueueT) -> \ - # Union[None, PusTmInfoQueueT]: - # (packet_received, pus_packets) = self.poll_interface() - # if packet_received: - # for packet in pus_packets: - # tm_info = packet.pack_tm_information() - # tm_info_queue.append(tm_info) - # return tm_info_queue - # - # def receive_telemetry_and_store_tuple(self, tm_tuple_queue: PusTmTupleQueueT) -> \ - # Union[None, PusTmTupleQueueT]: - # (packet_received, pus_packets) = self.poll_interface() - # if packet_received: - # for packet in pus_packets: - # tm_info = packet.pack_tm_information() - # tm_tuple_queue.append((tm_info, packet)) - # return tm_tuple_queue diff --git a/sendreceive/obsw_command_sender_receiver.py b/sendreceive/obsw_command_sender_receiver.py index 48232da..bb46548 100644 --- a/sendreceive/obsw_command_sender_receiver.py +++ b/sendreceive/obsw_command_sender_receiver.py @@ -12,15 +12,16 @@ if the first reply has not been received. @author: R. Mueller """ import time -import logging import config.obsw_config as g from comIF.obsw_com_interface import CommunicationInterface from utility.obsw_tmtc_printer import TmTcPrinter +from utility.obsw_logger import get_logger + from sendreceive.obsw_tm_listener import TmListener from tc.obsw_pus_tc_base import TcQueueEntryT from tm.obsw_pus_tm_factory import PusTmQueueT -from utility.obsw_logger import get_logger + logger = get_logger() -- GitLab