Contains core methods called by entry point files to setup and start a tmtccmd application. It also re-exports commonly used classes and functions.
- tmtccmd.create_default_tmtc_backend(setup_wrapper: SetupWrapper, tm_handler: TmHandlerBase, tc_handler: TcHandlerBase, init_procedure: ProcedureWrapper | None) BackendBase
Creates a default TMTC backend instance which can be passed to the tmtccmd runner
- Parameters:
init_procedure
tc_handler
setup_wrapper
tm_handler
- Returns:
- tmtccmd.get_lib_logger() Logger
Get the library logger. Please note that this logger can be configured by calling
init_logger(). This might make sense depending on how the library logger is used.
- tmtccmd.init_logger(propagate: bool = False, log_level: int = 20)
Initiate the library internal logger. There are various ways how to use the logging support of tmtccmd in an application.
Usage of a custom application logger, possibly a root logger created with
logging.getLogger(). In that case, this function does not have to be called if the goal is to have the library logs be emitted by the custom logger. It might still make sense to apply the library console logging format to the application logger usingtmtccmd.logging.add_colorlog_console_logger().Usage of a custom application logger, but the library logs should not be emitted by that logger. In that case, the propagation can be disabled but this function can be used to still set up the library logger.
No usage of logging in the application but the logs of the library should still be emitted. In that case, this function should still be called to set the log level and set up formatting. The propagation flag does not matter and can be left at the default level.
- Parameters:
propagate – Specifies whether logs are propagated. If the user wants to use an own (root) logger and does not wish the logs of the library to be propagated to that logger, this should be set to False, which is the default.
log_level – Sets the log level of the library logger
- tmtccmd.setup(setup_args: SetupWrapper)
This function needs to be called first before running the TMTC commander core. The setup arguments encapsulate all required arguments for the TMTC commander.
- Parameters:
setup_args – Setup arguments
- tmtccmd.setup_backend_def_procedure(backend: CcsdsTmtcBackend, tmtc_params: TreeCommandingProcedure)
- tmtccmd.start(tmtc_backend: BackendBase, hook_obj: HookBase, tmtc_frontend: FrontendBase | None = None, app_name: str = 'TMTC Commander')
This is the primary function to run the TMTC commander. Users should call this function to start the TMTC commander. Please note that
setup()needs to be called before this function. You also need to build a TMTC backend instance and pass it to this call. You can usecreate_default_tmtc_backend()to create a generic backend.- Parameters:
tmtc_backend – Custom backend can be passed here. Otherwise, a default backend will be created
hook_obj
tmtc_frontend – Custom frontend can be passed here. Otherwise, a default frontend will be created
app_name – Name of application. Will be displayed in GUI
- Raises:
RunTimeError – if
setup()was not called before- Returns:
Core Package
Module contents
Submodules
tmtccmd.core.ccsds_backend module
- class tmtccmd.core.ccsds_backend.CcsdsTmtcBackend(tc_mode: TcMode, tm_mode: TmMode, com_if: ComInterface, tm_listener: CcsdsTmListener, tc_handler: TcHandlerBase)
Bases:
BackendBaseThis is the primary class which handles TMTC reception and sending
- close_com_if()
Closes the TM listener and the communication interface :return:
- property com_if: ComInterface
- com_if_active()
- property com_if_id
- property current_procedure: ProcedureWrapper
- default_operation()
Command handling. This is a convenience function to call the TM and the TC operation and then auto-determine the internal mode with the
mode_to_req()method.- Raises:
NoValidProcedureSet – No valid procedure set to be passed to the feed callback of the TC handler
- property inter_cmd_delay
- mode_to_req()
This function will convert the internal state of the backend to a backend
request, which can be used to determine the next operation. These requests can be treated like recommendations. For example, for if both the TC and the TM mode are IDLE, the request will be set toBackendRequest.DELAY_IDLEfield.
- open_com_if()
Start the backend. Raise RuntimeError on failure
- periodic_op(_args: any | None = None) BackendState
Periodic operation. Simply calls the
default_operation()function. :raises KeyboardInterrupt: Yields info output and then propagates the exception :raises IOError: Yields informative output and propagates exception :
- poll_tm()
Poll TM, irrespective of current TM mode
- register_keyboard_interrupt_handler()
Register a keyboard interrupt handler which closes the COM interface and prints a small message
- property request
- start()
- property state
- property tc_mode
- tc_operation()
This function will handle consuming the current TC queue if one is available, or attempting to fetch a new one if it is not. This function will only do something if the
tc_modeis set to a non IDLE value.It is necessary to set a valid procedure before calling this by using the
current_proc_infosetter function.- Raises:
NoValidProcedureSet – No valid procedure set to be passed to the feed callback of the TC handler
- property tm_listener
- property tm_mode
- tm_operation()
This function will fetch and forward TM data from the current communication interface to the user TM handler. It only does so if the
tm_modeis set to the LISTENER mode
- try_set_com_if(com_if: ComInterface) bool
tmtccmd.core.base module
- class tmtccmd.core.base.BackendRequest(value)
Bases:
IntEnumThese requests can be treated like recommendations on what to do after calling the backend handler functions and the
BackendState.mode_to_req()function.- Brief explanation of fields:
NONE: No special recommendation
TERMINATION_NO_ERROR: Will be returned for the One Queue mode after finishing queue handling.
DELAY_IDLE: TC and TM mode are idle, so there is nothing to do
DELAY_LISTENER: TC handling is not active but TM listening is active. Delay to wait for new TM packets
CALL_NEXT: It is recommended to call the handler functions immediately, for example to handle the next entry in the TC queue
- CALL_NEXT = 5
- DELAY_CUSTOM = 4
- DELAY_IDLE = 2
- DELAY_LISTENER = 3
- NONE = 0
- TERMINATION_NO_ERROR = 1
tmtccmd.core.globals_manager module
- tmtccmd.core.globals_manager.lock_global_pool(blocking: bool | None = None, timeout: float | None = None) bool
Lock the global objects. This is important if the values are changed. Don’t forget to unlock the pool after finishing work with the globals! :param timeout_seconds: Attempt to lock for this many second. Default value -1 blocks permanently until lock is released. :return: Returns whether lock was locked or not.
- tmtccmd.core.globals_manager.unlock_global_pool()