From 1d63bc220d6a434b289dba95188f94823b96665b Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" <robin.mueller.m@gmail.com> Date: Sun, 26 Apr 2020 22:45:51 +0200 Subject: [PATCH] pylint --- config/obsw_config.py | 4 +- obsw_tmtc_client.py | 133 ++++++++++++++++++++---------------- utility/obsw_args_parser.py | 4 +- 3 files changed, 77 insertions(+), 64 deletions(-) diff --git a/config/obsw_config.py b/config/obsw_config.py index a54a776..6a3b434 100644 --- a/config/obsw_config.py +++ b/config/obsw_config.py @@ -131,9 +131,9 @@ def set_globals(args): G_MODE_ID = ModeList.UnitTest else: G_MODE_ID = ModeList[1] - if args.comIF == 0: + if args.com_if == 0: G_COM_IF = ComIF.Ethernet - elif args.comIF == 1: + elif args.com_if == 1: G_COM_IF = ComIF.Serial else: G_COM_IF = ComIF.Dummy diff --git a/obsw_tmtc_client.py b/obsw_tmtc_client.py index 23ff7ac..fc3730e 100644 --- a/obsw_tmtc_client.py +++ b/obsw_tmtc_client.py @@ -1,5 +1,52 @@ #!/usr/bin/python3.8 # -*- coding: utf-8 -*- +""" +This client was developed by KSat for the SOURCE project to test the on-board software. +It can be used to to send and receive TMTC packets and TMTC sequences. + +@manual +Manual installation of crcmod and pyserial for serial communication might be needed + 1. Install pip if it is not installed yet + 2. Install crcmod and all other required packages: + Command: python3.8 -m pip install crcmod + or use IDE (interpreter settings -> pip in PyCharm) + +The script can be used by specifying command line parameters. +Please run this script with the -h flag or without any command line parameters to display options. +GUI is work-in-progress +It might be necessary to set board or PC IP address if using ethernet communication. +Default values should work normally though. Use higher timeout value (-t Parameter) for STM32 + +Example command to test G_SERVICE 17, +assuming no set client IP (set manually to PC IP Address if necessary) +and default board IP 169.254.1.38: + obsw_tmtc_client.py -m 3 -s 17 +Example to run Unit Test: + obsw_tmtc_client.py -m 5 +Example to test G_SERVICE 17 with HK output and serial communication: + obsw_tmtc_client.py -m 3 -s 17 --hk -c 1 +Get command line help: + obsw_tmtc_client.py -h + +There are four different Modes: + 0. GUI Mode: Experimental mode, also called if no input parameter are specified + 1. Listener Mode: Only Listen for incoming TM packets + 2. SingleCommandMode: Send Single Command repeatedly until answer is received, + only listen after that + 3. ServiceTestMode: Send all Telecommands belonging to a certain G_SERVICE + and scan for replies for each telecommand. Listen after that + 4. SoftwareTestMode: Send all services and perform reply scanning like mode 3. + Listen after that + 5. Unit Test Mode: Performs a unit test which returns a simple OK or NOT OK. This mode + has the capability to send TCs in bursts, where applicable + +If there are problems receiving packets with Ethernet Communication, +use the tool Wireshark to track ethernet communication +for UDP echo packets (requests and response). +If the packets appear, there might be a problematic firewall setting. +Please ensure that python.exe UDP packets are not blocked in advanced firewall settings +and create a rule to allow packets from port 2008. +""" import atexit import time import unittest @@ -27,67 +74,23 @@ from gui.obsw_tmtc_gui import TmTcGUI from gui.obsw_backend_test import TmTcBackend -logger = get_logger() +LOGGER = get_logger() def main(): """ - This client was developed by KSat for the SOURCE project to test the on-board software. - It can be used to to send and receive TMTC packets and TMTC sequences. - - @manual - Manual installation of crcmod and pyserial for serial communication might be needed - 1. Install pip if it is not installed yet - 2. Install crcmod and all other required packages: - Command: python3.8 -m pip install crcmod - or use IDE (interpreter settings -> pip in PyCharm) - - The script can be used by specifying command line parameters. - Please run this script with the -h flag or without any command line parameters to display options. - GUI is work-in-progress - It might be necessary to set board or PC IP address if using ethernet communication. - Default values should work normally though. Use higher timeout value (-t Parameter) for STM32 - - Example command to test G_SERVICE 17, - assuming no set client IP (set manually to PC IP Address if necessary) - and default board IP 169.254.1.38: - obsw_tmtc_client.py -m 3 -s 17 - Example to run Unit Test: - obsw_tmtc_client.py -m 5 - Example to test G_SERVICE 17 with HK output and serial communication: - obsw_tmtc_client.py -m 3 -s 17 --hk -c 1 - Get command line help: - obsw_tmtc_client.py -h - - There are four different Modes: - 0. GUI Mode: Experimental mode, also called if no input parameter are specified - 1. Listener Mode: Only Listen for incoming TM packets - 2. SingleCommandMode: Send Single Command repeatedly until answer is received, - only listen after that - 3. ServiceTestMode: Send all Telecommands belonging to a certain G_SERVICE - and scan for replies for each telecommand. Listen after that - 4. SoftwareTestMode: Send all services and perform reply scanning like mode 3. - Listen after that - 5. Unit Test Mode: Performs a unit test which returns a simple OK or NOT OK. This mode - has the capability to send TCs in bursts, where applicable - - If there are problems receiving packets with Ethernet Communication, - use the tool Wireshark to track ethernet communication - for UDP echo packets (requests and response). - If the packets appear, there might be a problematic firewall setting. - Please ensure that python.exe UDP packets are not blocked in advanced firewall settings - and create a rule to allow packets from port 2008. + Main method, reads input arguments, sets global variables and start TMTC handler """ set_tmtc_logger() - logger.info("Starting TMTC Client") + LOGGER.info("Starting TMTC Client") - logger.info("Parsing input arguments") + LOGGER.info("Parsing input arguments") args = parse_input_arguments() - logger.info("Setting global variables") + LOGGER.info("Setting global variables") set_globals(args) - logger.info("Starting TMTC Handler") + LOGGER.info("Starting TMTC Handler") tmtc_handler = TmTcHandler() tmtc_handler.perform_operation() @@ -110,25 +113,35 @@ def command_preparation(): class TmTcHandler: + """ + This is the primary class which handles TMTC reception. This can be seen as the backend + in case a GUI or front-end is implemented. + """ def __init__(self): self.mode = g.G_MODE_ID - self.comIF = g.G_COM_IF + self.com_if = g.G_COM_IF # This flag could be used later to command the TMTC Client with a front-end self.command_received = True def perform_operation(self): + """ + Periodic operation + """ while True: try: if self.command_received: self.handle_action() self.command_received = False - logger.info("TMTC Client in idle mode") + LOGGER.info("TMTC Client in idle mode") time.sleep(5) except (IOError, KeyboardInterrupt): - logger.info("Closing TMTC client.") + LOGGER.info("Closing TMTC client.") def handle_action(self): + """ + Command handling. + """ tmtc_printer = TmTcPrinter(g.G_DISPLAY_MODE, g.G_PRINT_TO_FILE, True) if self.mode == g.ModeList.GUIMode: backend = TmTcBackend() @@ -137,7 +150,7 @@ class TmTcHandler: gui.start() backend.join() gui.join() - logger.info("Both processes have closed") + LOGGER.info("Both processes have closed") sys.exit() else: communication_interface = set_communication_interface(tmtc_printer) @@ -147,18 +160,18 @@ class TmTcHandler: tc_timeout_factor=g.G_TC_SEND_TIMEOUT_FACTOR) tm_listener.start() if self.mode == g.ModeList.ListenerMode: - logger.info("Listening for packages...") + LOGGER.info("Listening for packages...") elif self.mode == g.ModeList.SingleCommandMode: pus_packet_tuple = command_preparation() sender_and_receiver = SingleCommandSenderReceiver( com_interface=communication_interface, tmtc_printer=tmtc_printer, tm_listener=tm_listener) - logger.info("Performing single command operation") + LOGGER.info("Performing single command operation") sender_and_receiver.send_single_tc_and_receive_tm(pus_packet_tuple=pus_packet_tuple) - elif self.mode== g.ModeList.ServiceTestMode: + elif self.mode == g.ModeList.ServiceTestMode: service_queue = deque() - logger.info("Performing service command operation") + LOGGER.info("Performing service command operation") sender_and_receiver = SequentialCommandSenderReceiver( com_interface=communication_interface, tmtc_printer=tmtc_printer, tm_listener=tm_listener, @@ -167,7 +180,7 @@ class TmTcHandler: elif self.mode == g.ModeList.SoftwareTestMode: all_tc_queue = create_total_tc_queue() - logger.info("Performing multjple service commands operation") + LOGGER.info("Performing multjple service commands operation") sender_and_receiver = SequentialCommandSenderReceiver( com_interface=communication_interface, tmtc_printer=tmtc_printer, tc_queue=all_tc_queue, tm_listener=tm_listener) @@ -179,7 +192,7 @@ class TmTcHandler: g.G_TM_LISTENER = tm_listener g.G_COM_INTERFACE = communication_interface g.G_TMTC_PRINTER = tmtc_printer - logger.info("Performing module tests") + LOGGER.info("Performing module tests") # noinspection PyTypeChecker suite = unittest.TestLoader().loadTestsFromModule(obsw_pus_service_test) unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/utility/obsw_args_parser.py b/utility/obsw_args_parser.py index f0d3161..234aae6 100644 --- a/utility/obsw_args_parser.py +++ b/utility/obsw_args_parser.py @@ -79,9 +79,9 @@ def handle_unspecified_args(args) -> None: :param args: :return: None """ - if args.comIF == 1 and args.tm_timeout is None: + if args.com_if == 1 and args.tm_timeout is None: args.tm_timeout = 6.0 - if args.comIF == 1 and args.com_port is None: + if args.com_if == 1 and args.com_port is None: args.com_port = input("Serial Commuinication specified without COM port. " "Please enter COM Port: ") if args.mode is None: -- GitLab