import argparse import sys import traceback from typing import Optional from tmtccmd.config.definitions import CoreModeList from tmtccmd.config.globals import update_global, CoreGlobalIds try: import spacepackets except ImportError as error: print(error) print("Python spacepackets module could not be imported") print( 'Install with "cd spacepackets && python3 -m pip intall -e ." for interative installation' ) sys.exit(1) try: import tmtccmd.runner as tmtccmd from tmtccmd.logging.pus import create_tmtc_logger from tmtccmd.ccsds.handler import ApidHandler, CcsdsTmHandler from tmtccmd.config import SetupArgs, default_json_path from tmtccmd.config.args import ( create_default_args_parser, add_default_tmtccmd_args, parse_default_input_arguments, ) except ImportError as error: run_tmtc_commander = None initialize_tmtc_commander = None tb = traceback.format_exc() print(tb) print("Python tmtccmd submodule could not be imported") sys.exit(1) from config import __version__ from config.definitions import PUS_APID from config.hook_implementations import EiveHookObject from pus_tm.factory_hook import ccsds_tm_handler from pus_tc.tc_packer_hook import pre_tc_send_cb def tmtcc_pre_args() -> EiveHookObject: print(f"-- eive tmtc v{__version__} --") print(f"-- spacepackets v{spacepackets.__version__} --") tmtccmd.init_printout(False) return EiveHookObject(json_cfg_path=default_json_path()) def tmtcc_post_args( hook_obj: EiveHookObject, use_gui: bool, args: Optional[argparse.Namespace] ): setup_args = SetupArgs( hook_obj=hook_obj, use_gui=use_gui, apid=PUS_APID, cli_args=args ) tmtc_file_logger = create_tmtc_logger() apid_handler = ApidHandler(cb=ccsds_tm_handler, queue_len=50, user_args=None) ccsds_handler = CcsdsTmHandler() ccsds_handler.add_tm_handler(apid=PUS_APID, handler=apid_handler) tmtccmd.setup(setup_args=setup_args) tmtccmd.add_ccsds_handler(ccsds_handler) if use_gui: update_global(CoreGlobalIds.MODE, CoreModeList.LISTENER_MODE) tmtc_backend = tmtccmd.create_default_tmtc_backend( setup_args=setup_args, tm_handler=ccsds_handler, ) tmtc_backend.usr_send_wrapper = (pre_tc_send_cb, tmtc_file_logger) tmtccmd.run(tmtc_backend=tmtc_backend)