Configuration Package

Module

Configuration helpers and definitions.

Submodules:

  • tmtccmd.config.hook - Base hook class which should be implemented by user and is used by the framework to retrieve certain configuration from the user.

  • tmtccmd.config.args - Various helper methods and classes to create the argument parsers and arguments converts to create the data structures expected by this library from passed CLI arguments.

class tmtccmd.config.SetupWrapper(hook_obj: HookBase, setup_params: SetupParams, proc_param_wrapper: ProcedureParamsWrapper, json_cfg_path: str | None = None)

Bases: object

This class encapsulates various important setup parameters required by tmtccmd components

Parameters:
  • hook_obj – User hook object. Needs to be implemented by the user

  • setup_params – Optional helper wrapper which contains CLI arguments.

property params
tmtccmd.config.backend_mode_conversion(mode: str, mode_wrapper: ModeWrapper)
tmtccmd.config.cfdp_put_req_params_to_procedure(params: CfdpParams) CfdpProcedure
tmtccmd.config.params_to_procedure_conversion(param_wrapper: ProcedureParamsWrapper) ProcedureWrapper
tmtccmd.config.tmtc_params_to_procedure(params: TreeCommandingParams) TreeCommandingProcedure

Configuration Hook Submodule

class tmtccmd.config.hook.HookBase(cfg_file_path: str | None = None)

Bases: ABC

This hook allows users to adapt the TMTC commander core to the unique mission requirements. It is used by implementing all abstract functions and then passing the instance to the TMTC commander core.

get_cmd_history() History | None

Optionlly return a history class for the past command paths which will be used when prompting a command path from the user in CLI mode.

get_com_if_dict() Mapping[str, tuple[str, Any]]
abstract get_command_definitions() CmdTreeNode

This function should return the root node of the command definition tree.

abstract get_communication_interface(com_if_key: str) ComInterface | None
perform_mode_operation(tmtc_backend: BackendBase, mode: int)

Perform custom mode operations.

Parameters:
  • tmtc_backend

  • mode

Returns:

Argument Parsing Submodule

Argument parser module.

class tmtccmd.config.args.AppParams(use_gui: 'bool' = False, reduced_printout: 'bool' = False, use_ansi_colors: 'bool' = True, compl_style: 'CompleteStyle' = <CompleteStyle.READLINE_LIKE: 'READLINE_LIKE'>)

Bases: object

compl_style: CompleteStyle = 'READLINE_LIKE'
reduced_printout: bool = False
use_ansi_colors: bool = True
use_gui: bool = False
class tmtccmd.config.args.BackendParams(mode: 'str' = '', com_if_id: 'str' = '', listener: 'bool' = False, interactive: 'bool' = False)

Bases: object

com_if_id: str = ''
interactive: bool = False
listener: bool = False
mode: str = ''
class tmtccmd.config.args.CommandingParams(delay: 'float' = 0.0, apid: 'int' = 0, print_tree: 'bool' = False, tree_print_with_description: 'bool' = True, tree_print_max_depth: 'int | None' = None)

Bases: object

apid: int = 0
delay: float = 0.0
print_tree: bool = False
tree_print_max_depth: int | None = None
tree_print_with_description: bool = True
class tmtccmd.config.args.PostArgsParsingWrapper(args_raw: Namespace, unknown_args: list[str], params: SetupParams, hook_obj: HookBase)

Bases: object

This helper class helps with the internalization of the parse arguments into the format expected by tmtccmd.

Variables:

assign_com_if – If this is set to True (default), the wrapper will try to create a tmtccmd.com.ComInterface on the conversion methods.

It is recommended to use PreArgsParsingWrapper.parse() to retrieve an instance instead of using the constructor directly.

Parameters:
  • args_raw

  • unknown_args

  • params

  • hook_obj

request_type_from_args() TcProcedureType
set_cfdp_params_with_prompts(cfdp_params: CfdpParams)
set_cfdp_params_without_prompts(cfdp_params: CfdpParams)
set_params_with_prompts(proc_base: ProcedureParamsWrapper)
set_params_without_prompts(proc_wrapper: ProcedureParamsWrapper)
set_tmtc_params_with_prompts(tmtc_params: TreeCommandingParams)
set_tmtc_params_without_prompts(tmtc_params: TreeCommandingParams)

Set up the parameter object from the parsed arguments. This call auto-determines whether prompts should be used depending on whether the GUI flag was passed or not.

Raises:

Value Error – Parse function call missing

property use_gui

This only yields valid values if parse() was called once

class tmtccmd.config.args.PreArgsParsingWrapper

Bases: object

This class can be used to simplify parsing all tmtccmd CLI arguments.

It wraps a parent parser and an argument parser but is also able to create default parsers. The parse() method can be used to convert this parse the CLI arguments and then create a PostArgsParsingWrapper to process these arguments.

Please note that the parent parser and argument parser field have to be set or created first after creating this wrapper. They can be created by calling create_default_parent_parser() and the create_default_parser(), but the second function requires the parent parser to be set or created first.

add_cfdp_args()

Add the default CFDP procedure parameters to the default parser.

add_def_proc_and_cfdp_as_subparsers() tuple[ArgumentParser, ArgumentParser]

Add the default tmtc and cfdp procedure as subparsers.

add_def_proc_args()

Add the default tmtc procedure parameters to the default parser. This includes the service and operation code flags.

create_default_parent_parser()

Create a default parent parser, which contains common flags for all possible tmtccmd submodules. For example, both the cfdp and default tmtc submodule could contain these common flags. The user can extend or modify the parent parser after it was created.

create_default_parser()

Create the default parser. Requires a valid parent parser containing common flags, The user can create or modify the parser after it was created. This function requires a valid parent parser to be set or created via create_default_parent_parser().

parse(hook_obj: HookBase, setup_params: SetupParams) PostArgsParsingWrapper

Parses the set parser by calling the argparse.ArgumentParser.parse_known_args() method internally and returns the PostArgsParsingWrapper to simplify processing the arguments.

class tmtccmd.config.args.ProcedureParamsWrapper

Bases: object

cfdp_params() CfdpParams | None
property ptype
set_params(params: TreeCommandingParams | CfdpParams)
tree_commanding_params() TreeCommandingParams | None
class tmtccmd.config.args.SetupParams(com_if: ComInterface | None = None, cmd_params: CommandingParams | None = None, backend_params: BackendParams | None = None, app_params: AppParams | None = None)

Bases: object

property apid
property com_if_id
property mode
property use_gui
tmtccmd.config.args.add_cfdp_procedure_arguments(parser_or_subparser: ArgumentParser)

TODO: Could be extended to support the various types of CFDP user primitives. Right now, the first thing to be implemented will be the put request

tmtccmd.config.args.add_default_com_if_arguments(arg_parser: ArgumentParser)
tmtccmd.config.args.add_default_tmtccmd_args(parser: ArgumentParser)
tmtccmd.config.args.add_ethernet_arguments(arg_parser: ArgumentParser)
tmtccmd.config.args.add_generic_arguments(arg_parser: ArgumentParser)
tmtccmd.config.args.add_tmtc_listener_arg(arg_parser: ArgumentParser)
tmtccmd.config.args.add_tmtc_mode_arguments(arg_parser: ArgumentParser)
tmtccmd.config.args.add_tree_commanding_arguments(parser_or_subparser: ArgumentParser)
tmtccmd.config.args.args_to_all_params_for_cfdp(pargs: Namespace, params: SetupParams, cfdp_params: CfdpParams, hook_obj: HookBase, use_prompts: bool, assign_com_if: bool)

Helper function to convert CFDP command line arguments to the setup parameters.

tmtccmd.config.args.args_to_all_params_tmtc(pargs: Namespace, params: SetupParams, def_tmtc_params: TreeCommandingParams, hook_obj: HookBase, use_prompts: bool, assign_com_if: bool = True)

This function converts command line arguments to the internalized setup parameters.

It is recommended to use the PostArgsParsingHelper class to do this instead of calling this function directly.

If some arguments are unspecified, they are set here with (variable) default values.

Parameters:
  • pargs – Parsed arguments from calling parse method.

  • params – Setup parameter object which will be set by this function.

  • hook_obj

  • def_tmtc_params

  • use_prompts – Specify whether terminal prompts are allowed to retrieve unspecified arguments. For something like a GUI, it might make sense to disable this

  • assign_com_if – Specifies whether this function should try to determine the COM interface from the specified key.

Returns:

None

tmtccmd.config.args.args_to_params_generic(pargs: Namespace, params: SetupParams, hook_obj: HookBase, use_prompts: bool, assign_com_if: bool)
tmtccmd.config.args.cfdp_args_to_cfdp_params(pargs: Namespace, cfdp_params: CfdpParams)

Convert the argument parser CFDP arguments provided by this library to the internalized tmtccmd.config.defs.CfdpParams dataclass.

tmtccmd.config.args.create_default_args_parser(parent_parser: ArgumentParser, descript_txt: str | None = None) ArgumentParser
tmtccmd.config.args.determine_cmd_path(params: SetupParams, def_params: TreeCommandingParams, hook_obj: HookBase, pargs: Namespace, use_prompts: bool)
tmtccmd.config.args.get_default_descript_txt() str
tmtccmd.config.args.parse_default_tmtccmd_input_arguments(args: Sequence[str], parser: ArgumentParser, print_known_args: bool = False, print_unknown_args: bool = False) tuple[Namespace, list[str]]

Parses all input arguments by calling argparse.ArgumentParser.parse_known_args(). It is recommended to use the PreArgsParsingWrapper instead of using this function directly.

Parameters:
  • args – The actual full list of parse CLI arguments

  • parser – The parser to be used.

  • print_known_args – Debugging function to print all known arguments.

  • print_unknown_args

Returns:

Input arguments contained in a special namespace and accessable by args.<variable>

tmtccmd.config.args.perform_tree_printout(cmd_params: CommandingParams, cmd_def_tree: CmdTreeNode)

TMTC Configuration Submodule

class tmtccmd.config.tmtc.CmdTreeNode(name: str, description: str, parent: CmdTreeNode | None = None, hide_children_for_print: bool = False, hide_children_which_are_leaves: bool = False)

Bases: object

The command tree node is the primary data structure used to specify the command structure in a way it can be used by framework components.

The node class provides an API which allows to build a tree of command nodes. Generally, a full path from the root node to a leaf will be the command identifier or command path for executing a certain command or procedure.

You can create the root node using the CmdTreeNode.root_node() class method. After that children can be appended to the nodes using the CmdTreeNode.add_child() method.

You can use square bracket operator to access the children of a node directly. For example, if a node with the name test_node has the child event, you could use test_node["event"] to access the child node.

Parameters:
  • name – Name of the node, which will be also part of the command path when picking a path through the tree.

  • description – Additional description for the node.

  • parent – Parent of the node. Generally, this does not need to be set, as it will be set correctly when using the CmdTreeNode.add_child() method.

  • hide_children_for_print – For large tree, it can make sense to hide the children for a regular printout of the tree. This field allows to do this.

  • hide_children_which_are_leaves – For large tree, it can make sense to hide the children which are leaves for a regular printout of the tree. This field allows to do this. This field is overriden by the strong hide_children_for_print field.

add_child(child: CmdTreeNode)

Add a child to the node. This will also assign the parent class of the child to the current node.

contains_path(path: str) bool

Check whether a full slash separated command path is contained within the command tree.

contains_path_from_node_list(node_name_list: list[str]) bool

Check whether the given list of nodes are contained within the command tree.

extract_subnode(path: str) CmdTreeNode | None

Extract a subnode given a relative path.

extract_subnode_by_node_list(node_list: list[str]) CmdTreeNode | None

Extract a subnode given a list which would form a relative path if it were joined using slashes.

is_leaf() bool

A leaf is a node which has no children.

property name_dict: dict[str, dict[str, Any] | None]

Returns a nested dictionary where the key is always the name of the node, and the value is one nested name dictionary for each child node.

classmethod root_node() CmdTreeNode
str_for_tree(with_description: bool, max_depth: int | None = None, show_hidden_elements: bool = False) str

Retrieve the a human readable printout of the tree.

Parameters:
  • with_description – Display descriptions right to the tree.

  • max_depth – Entries will be cut-off at the specified depth. None can be specified to print all depths.

  • show_hidden_elements – Overrides the hide argument of command tree nodes.

class tmtccmd.config.tmtc.DepthInfo(depth: int, last_child: bool, max_depth: int | None = None, layer_is_last_set: set[int] | None = None)

Bases: object

clear_layer_is_last_child(depth: int)
is_layer_for_last_child(depth: int) bool
set_layer_is_last_child(depth: int)
class tmtccmd.config.tmtc.TreePart(value)

Bases: Enum

An enumeration.

BLANK = '   '
CORNER = '└──'
EDGE = '├──'
LINE = '│  '

CFDP Configuration Submodule

tmtccmd.config.cfdp.cfdp_req_to_put_req_get_req(params: CfdpParams, local_id: UnsignedByteField, remote_id: UnsignedByteField) PutRequest | None

This function converts the internalized CFDP parameters to the get request variant of the tmtccmd.cfdp.request.PutRequest class. Please note that the local ID refers to the receiver of the target of the file copy operation for a get request while the remote ID refers to the sender component for the file copy operation.

tmtccmd.config.cfdp.cfdp_req_to_put_req_proxy_put_req(params: CfdpParams, dest_id_put_request: UnsignedByteField, dest_id_proxy_put_req: UnsignedByteField) PutRequest | None

Generic function to convert the internalized CFDP parameters to a proxy put request.

Parameters:
  • params – CFDP parameters

  • dest_id_put_request – Recipient of the put request.

  • dest_id_proxy_put_req – Recipient of the proxy put operation. For a get request, this should the the ID of the sender.

tmtccmd.config.cfdp.cfdp_req_to_put_req_regular(params: CfdpParams, dest_id: UnsignedByteField) PutRequest | None
tmtccmd.config.cfdp.generic_cfdp_params_to_put_request(params: CfdpParams, local_id: UnsignedByteField, remote_id: UnsignedByteField, dest_id_proxy_put_req: UnsignedByteField) PutRequest | None

Please note that this function currently only has the following functionality. It might be extended in the future to have more functionality, or be converted to a factory class.

  1. Create a regular put request for a file copy operation.

  2. Create a proxy put request.

Communication Configuration Submodule

class tmtccmd.config.com.ComConfigCommon(com_if_key: str, cfg_path: str)

Bases: object

class tmtccmd.config.com.DummyConfig(com_if_key: str, cfg_path: str)

Bases: ComConfigCommon

class tmtccmd.config.com.SerialConfigCommon(com_if_key: str, config_path: str, serial_cfg: SerialCfg)

Bases: ComConfigCommon

class tmtccmd.config.com.TcpipConfig(if_type: TcpIpType, com_if_key: str, config_path: str, send_addr: EthAddr, space_packet_ids: Sequence[PacketId] | None, recv_addr: EthAddr | None = None)

Bases: ComConfigCommon

tmtccmd.config.com.create_com_interface_config_default(com_if_key: str, cfg_path: str, space_packet_ids: Sequence[PacketId] | None) TcpipConfig | SerialConfigCommon | DummyConfig | None
tmtccmd.config.com.create_com_interface_default(config: TcpipConfig | SerialConfigCommon | DummyConfig) ComInterface | None

Return the desired communication interface object

Parameters:

cfg – Generic configuration

Returns:

tmtccmd.config.com.create_default_serial_interface(com_if_key: str, serial_cfg: SerialCfg) ComInterface | None

Create a default serial interface. Requires a certain set of global variables set up. See set_up_serial_cfg() for more details.

Parameters:
  • com_if_key

  • serial_cfg – Generic serial configuration parameters

Returns:

tmtccmd.config.com.create_default_tcpip_interface(tcpip_cfg: TcpipConfig) ComInterface | None

Create a default serial interface. Requires a certain set of global variables set up. See default_tcpip_cfg_setup() for more details.

Parameters:

tcpip_cfg – Configuration parameters

Returns:

tmtccmd.config.com.default_serial_cfg_baud_and_port_setup(com_if_id: str, cfg_path: str) SerialCfg

Default setup for serial interfaces.

Parameters:
  • com_if_id – Identifier for the communication interface

  • cfg_path – Path to JSON or TOML config file

Returns:

SerialCfg object with baud rate and serial port set from config

tmtccmd.config.com.default_tcpip_config(com_if_key: str, tcpip_type: TcpIpType, cfg_path: str, space_packet_ids: Sequence[PacketId] | None) TcpipConfig | None

Default setup for TCP/IP communication interfaces. This intantiates all required data in the globals manager so a TCP/IP communication interface can be built with create_default_tcpip_interface()

Parameters:
  • com_if_key

  • tcpip_type

  • cfg_path – Path to JSON or TOML config file

  • space_packet_ids – Required if the TCP com interface needs to parse space packets

Returns:

Configuration Definitions Submodule

class tmtccmd.config.defs.CfdpParams(source_file: str = '', dest_file: str = '', closure_requested: bool = False, transmission_mode: TransmissionMode = TransmissionMode.UNACKNOWLEDGED, proxy_op: bool = False)

Bases: object

Simplified dataclass to model the most important CFDP parameters. This can for example be used to internalize CFDP CLI or GUI options.

closure_requested: bool = False
dest_file: str = ''
proxy_op: bool = False
source_file: str = ''
transmission_mode: TransmissionMode = 1
class tmtccmd.config.defs.CoreComInterfaces(value)

Bases: str, Enum

An enumeration.

DUMMY = 'dummy'
SERIAL_COBS = 'serial_cobs'
SERIAL_DLE = 'serial_dle'
SERIAL_QEMU = 'serial_qemu'
TCP = 'tcp'
UDP = 'udp'
UNSPECIFIED = 'unspec'
class tmtccmd.config.defs.CoreMode(value)

Bases: IntEnum

These are the core modes which will be translated to different TC and TM modes for the CCSDS backend

  1. ONE_QUEUE_MODE: This mode is optimized to handle one queue. It will configure the backend to request program termination upon finishing the queue handling. This is also the appropriate solution for single commands where the queue only consists of one telecommand.

  2. LISTENER_MODE: Only listen to TM

  3. MULTI_INTERACTIVE_QUEUE_MODE:

IDLE = 5

The program will not do anything in this mode. This includes polling TM and sending any TCs

LISTENER_MODE = 1
MULTI_INTERACTIVE_QUEUE_MODE = 3

This mode is optimized for the handling of multiple queues. It will configure the backend to request additional queues or a mode change from the user instead of requesting program termination

ONE_QUEUE_MODE = 0
class tmtccmd.config.defs.CoreModeConverter

Bases: object

static get_str(mode: CoreMode | int) str
class tmtccmd.config.defs.TreeCommandingParams(cmd_path: str | None)

Bases: object

cmd_path: str | None
tmtccmd.config.defs.default_json_path() str
tmtccmd.config.defs.default_toml_path() str

Objects Submodule

tmtccmd.config.objects.get_base_component_id_mapping() Mapping[bytes, ComponentIdBase]

These are the object IDs for the tmtccmd core. The core will usually take care of inserting these into the object manager during the program initialization.

:return Dictionary of the core object IDs

tmtccmd.config.objects.get_core_object_ids() Mapping[bytes, ComponentIdBase]