Skip to content
Snippets Groups Projects
Forked from an inaccessible project.
OBSW_ArgParser.py 3.90 KiB
#!/usr/bin/python3.7
"""
@file
    OBSW_ArgParser.py
@date
    11.01.2020
@brief
    Reads all input arguments or requests them from user.
"""

import argparse
import sys


def parseInputArguments():
    argParser = argparse.ArgumentParser(description="TMTC Client Command Line Interface")

    argParser.add_argument('-m', '--mode', type=int, help='Target Mode. Default is 1(Listener Mode), '
                                                          '0: GUI Mode, 1:Listener Mode, '
                                                          '2: Single Command Mode, 3: Service Test Mode, '
                                                          '4: Software Test Mode, 5: Unit Test Mode ', default=0)
    argParser.add_argument('-c', '--comIF', type=int, help='Communication Interface. 0 for Ethernet, 1 for Serial',
                           default=0)
    argParser.add_argument('--clientIP', help='Client(Computer) IP. Default:\'\'', default='')
    argParser.add_argument('--boardIP', help='Board IP. Default: 169.254.1.38', default='169.254.1.38')
    argParser.add_argument('-s', '--service',  help='Service to test. Default: 17', default=17)
    argParser.add_argument('-t', '--tmTimeout', type=float, help='TM Timeout when listening to verification sequence.'
                                                                 ' Default: 12, 6(Serial)', default=6.0)
    argParser.add_argument('-p', '--printFile', help='Supply -p to print output to file. Default: False',
                           action='store_true')
    argParser.add_argument('-o', '--tcTimeoutFactor', type=float, help='TC Timeout Factor. Default: 3.5', default=3.5)
    argParser.add_argument('-r', '--rawDataPrint', help='Supply -r to print all raw data directly', action='store_true')
    argParser.add_argument('-d', '--shortDisplayMode', help='Supply -d to print short output', action='store_true')
    argParser.add_argument('-k', '--hk', help='Supply -k or --hk to print HK data', action='store_true')
    argParser.add_argument('--COM', help='COM Port for serial communication')

    if len(sys.argv) == 1:
        print("No Input Arguments specified.")
        argParser.print_help()
    args = argParser.parse_args()
    assignEmptyArgs(args)
    print(args)
    return args


def assignEmptyArgs(args):
    if len(sys.argv) > 1:
        handleUnspecifiedArgs(args)
    if len(sys.argv) == 1:
        handleEmptyArgs(args)


def handleUnspecifiedArgs(args):
    if args.comIF == 1 and args.tmTimeout is None:
        args.tmTimeout = 6.0
    if args.comIF == 1 and args.COM is None:
        args.COM = input("Serial Commuinication specified without COM port. Please enter COM Port: ")
    if args.mode is None:
        print("No mode specified with -m Parameter.")
        print("Possible Modes: ")
        print("1: Listener Mode")
        print("2: Single Command Mode with manual command")
        print("3: Service Mode, Commands specified in tc folder")
        print("4: Software Mode, runs all command specified in OBSW_TcPacker.py")
        print("5: Unit Test, runs unit test specified in OBSW_UnitTest.py")
        args.mode = input("Please enter Mode: ")
        if args.mode == 1 and args.service is None:
            args.service = input("No Service specified for Service Mode. Please enter PUS service number: ")


def handleEmptyArgs(args):
    printHk = input("Print HK packets ? (y/n or yes/no)")
    try:
        printHk = printHk.lower()
    except TypeError:
        pass
    if printHk == 'y' or printHk == 'yes' or printHk == 1:
        args.hk = True
    else:
        args.hk = False
    printToLog = input("Export service test output to log files ? (y/n or yes/no)")
    try:
        printToLog = printToLog.lower()
    except TypeError:
        pass
    if printToLog == 'y' or printToLog == 'yes' or printHk == 1:
        args.printFile = True
    else:
        args.printFile = False