eive-tmtc/config/tmtcc_globals.py

229 lines
8.2 KiB
Python
Raw Normal View History

2020-12-17 17:50:00 +01:00
"""
@brief This file transfers definitions of global variables to the user.
@details Template configuration file. Copy this folder to the TMTC commander root and adapt
it to your needs.
"""
import enum
import argparse
# All globals can be added here and will be part of a globals dictionary.
from config.tmtcc_definitions import ServiceList, ModeList
from tmtc_core.com_if.tmtcc_serial_com_if import SerialCommunicationType
from tmtc_core.com_if.tmtcc_serial_utilities import determine_com_port
from tmtc_core.core.tmtc_core_definitions import ComInterfaces
from tmtc_core.utility.tmtcc_logger import get_logger
class GlobalIds(enum.Enum):
from enum import auto
# Generic parameters
APID = auto()
MODE = auto()
SERVICE = auto()
SERVICELIST = auto()
COM_IF = auto()
OP_CODE = auto()
TM_TIMEOUT = auto()
# Miscellaneous
DISPLAY_MODE = auto()
USE_LISTENER_AFTER_OP = auto()
PRINT_HK = auto()
PRINT_TM = auto()
PRINT_RAW_TM = auto()
PRINT_TO_FILE = auto()
RESEND_TC = auto()
TC_SEND_TIMEOUT_FACTOR = auto()
# Config dictionaries
USE_SERIAL = auto()
SERIAL_CONFIG = auto()
USE_ETHERNET = auto()
ETHERNET_CONFIG = auto()
# Object handles
PRETTY_PRINTER = auto()
TM_LISTENER_HANDLE = auto()
COM_INTERFACE_HANDLE = auto()
TMTC_PRINTER_HANDLE = auto()
def add_globals_pre_args_parsing(gui: bool = False):
from tmtc_core.core.tmtcc_globals_manager import update_global
import pprint
2020-12-17 18:09:00 +01:00
update_global(GlobalIds.APID, 0x65)
2020-12-17 17:50:00 +01:00
update_global(GlobalIds.COM_IF, ComInterfaces.EthernetUDP)
update_global(GlobalIds.TC_SEND_TIMEOUT_FACTOR, 2)
update_global(GlobalIds.TM_TIMEOUT, 4)
update_global(GlobalIds.DISPLAY_MODE, "long")
update_global(GlobalIds.PRINT_TO_FILE, True)
update_global(GlobalIds.SERIAL_CONFIG, dict())
update_global(GlobalIds.ETHERNET_CONFIG, dict())
pp = pprint.PrettyPrinter()
update_global(GlobalIds.PRETTY_PRINTER, pp)
update_global(GlobalIds.TM_LISTENER_HANDLE, None)
update_global(GlobalIds.COM_INTERFACE_HANDLE, None)
update_global(GlobalIds.TMTC_PRINTER_HANDLE, None)
update_global(GlobalIds.PRINT_RAW_TM, False)
update_global(GlobalIds.RESEND_TC, False)
update_global(GlobalIds.OP_CODE, "0")
update_global(GlobalIds.MODE, ModeList.ListenerMode)
if gui:
set_up_ethernet_cfg()
servicelist = dict()
servicelist[ServiceList.SERVICE_2] = ["Service 2 Raw Commanding"]
servicelist[ServiceList.SERVICE_3] = ["Service 3 Housekeeping"]
servicelist[ServiceList.SERVICE_5] = ["Service 5 Event"]
servicelist[ServiceList.SERVICE_8] = ["Service 8 Functional Commanding"]
servicelist[ServiceList.SERVICE_9] = ["Service 9 Time"]
servicelist[ServiceList.SERVICE_17] = ["Service 17 Test"]
servicelist[ServiceList.SERVICE_20] = ["Service 20 Parameters"]
servicelist[ServiceList.SERVICE_23] = ["Service 23 File Management"]
servicelist[ServiceList.SERVICE_200] = ["Service 200 Mode Management"]
update_global(GlobalIds.SERVICE, ServiceList.SERVICE_17)
update_global(GlobalIds.SERVICELIST, servicelist)
def add_globals_post_args_parsing(args: argparse.Namespace):
from tmtc_core.core.tmtcc_globals_manager import update_global
from config.tmtcc_definitions import ModeList
logger = get_logger()
mode_param = ModeList.ListenerMode
if 0 <= args.mode <= 6:
if args.mode == 0:
mode_param = ModeList.GUIMode
elif args.mode == 1:
mode_param = ModeList.ListenerMode
elif args.mode == 2:
mode_param = ModeList.SingleCommandMode
elif args.mode == 3:
mode_param = ModeList.ServiceTestMode
elif args.mode == 4:
mode_param = ModeList.SoftwareTestMode
update_global(GlobalIds.MODE, mode_param)
if args.com_if == ComInterfaces.EthernetUDP.value:
com_if = ComInterfaces.EthernetUDP
elif args.com_if == ComInterfaces.Serial.value:
com_if = ComInterfaces.Serial
elif args.com_if == ComInterfaces.Dummy.value:
com_if = ComInterfaces.Dummy
elif args.com_if == ComInterfaces.QEMU.value:
com_if = ComInterfaces.QEMU
else:
com_if = ComInterfaces.Serial
update_global(GlobalIds.COM_IF, com_if)
if args.short_display_mode:
display_mode_param = "short"
else:
display_mode_param = "long"
update_global(GlobalIds.DISPLAY_MODE, display_mode_param)
service = str(args.service).lower()
if service == "2":
service = ServiceList.SERVICE_2
elif service == "3":
service = ServiceList.SERVICE_3
elif service == "5":
service = ServiceList.SERVICE_5
elif service == "8":
service = ServiceList.SERVICE_8
elif service == "9":
service = ServiceList.SERVICE_9
elif service == "17":
service = ServiceList.SERVICE_17
elif service == "20":
service = ServiceList.SERVICE_20
elif service == "23":
service = ServiceList.SERVICE_23
2020-12-29 11:29:03 +01:00
elif service == "p60dock":
service = ServiceList.P60DOCK
elif service == "pdu1":
service = ServiceList.PDU1
elif service == "pdu2":
service = ServiceList.PDU2
elif service == "acu":
service = ServiceList.ACU
2021-01-10 11:42:06 +01:00
elif service == "tmp1075":
service = ServiceList.TMP1075
2020-12-17 17:50:00 +01:00
else:
logger.warning("Service not known! Setting standard service 17")
service = ServiceList.SERVICE_17
update_global(GlobalIds.SERVICE, service)
if args.op_code is None:
op_code = 0
else:
op_code = str(args.op_code).lower()
update_global(GlobalIds.OP_CODE, op_code)
update_global(GlobalIds.USE_LISTENER_AFTER_OP, args.listener)
update_global(GlobalIds.TM_TIMEOUT, args.tm_timeout)
update_global(GlobalIds.PRINT_HK, args.print_hk)
update_global(GlobalIds.PRINT_TM, args.print_tm)
update_global(GlobalIds.PRINT_RAW_TM, args.raw_data_print)
update_global(GlobalIds.PRINT_TO_FILE, args.print_log)
update_global(GlobalIds.RESEND_TC, args.resend_tc)
update_global(GlobalIds.TC_SEND_TIMEOUT_FACTOR, 3)
use_serial_cfg = False
if com_if == ComInterfaces.Serial or com_if == ComInterfaces.QEMU:
use_serial_cfg = True
if use_serial_cfg:
set_up_serial_cfg(com_if)
use_ethernet_cfg = False
if com_if == ComInterfaces.EthernetUDP:
use_ethernet_cfg = True
if use_ethernet_cfg:
# TODO: Port and IP address can also be passed as CLI parameters. Use them here if applicable
set_up_ethernet_cfg()
def set_up_serial_cfg(com_if: ComInterfaces):
from tmtc_core.core.tmtcc_globals_manager import update_global
update_global(GlobalIds.USE_SERIAL, True)
from tmtc_core.core.tmtcc_globals_manager import get_global
from config.tmtcc_definitions import SerialConfig
serial_cfg_dict = get_global(GlobalIds.SERIAL_CONFIG)
if com_if == ComInterfaces.Serial:
com_port = determine_com_port()
else:
com_port = ""
serial_cfg_dict.update({SerialConfig.SERIAL_PORT: com_port})
serial_cfg_dict.update({SerialConfig.SERIAL_BAUD_RATE: 115200})
serial_cfg_dict.update({SerialConfig.SERIAL_TIMEOUT: 0.01})
serial_cfg_dict.update({SerialConfig.SERIAL_COMM_TYPE: SerialCommunicationType.DLE_ENCODING})
serial_cfg_dict.update({SerialConfig.SERIAL_FRAME_SIZE: 256})
serial_cfg_dict.update({SerialConfig.SERIAL_DLE_QUEUE_LEN: 25})
serial_cfg_dict.update({SerialConfig.SERIAL_DLE_MAX_FRAME_SIZE: 1024})
update_global(GlobalIds.SERIAL_CONFIG, serial_cfg_dict)
def set_up_ethernet_cfg():
from tmtc_core.core.tmtcc_globals_manager import update_global
update_global(GlobalIds.USE_ETHERNET, True)
from tmtc_core.core.tmtcc_globals_manager import get_global
from config.tmtcc_definitions import EthernetConfig
2020-12-17 18:09:00 +01:00
from tmtc_core.com_if.tmtcc_ethernet_utilities import determine_ip_addresses
2020-12-17 17:50:00 +01:00
ethernet_cfg_dict = get_global(GlobalIds.ETHERNET_CONFIG)
2020-12-17 18:09:00 +01:00
# This will either load the addresses from a JSON file or prompt them from the user.
send_addr, rcv_addr = determine_ip_addresses()
ethernet_cfg_dict.update({EthernetConfig.SEND_ADDRESS: send_addr})
ethernet_cfg_dict.update({EthernetConfig.RECV_ADDRESS: rcv_addr})
2020-12-17 17:50:00 +01:00
update_global(GlobalIds.ETHERNET_CONFIG, ethernet_cfg_dict)