Utility Package

Submodules

JSON Module

class tmtccmd.util.json.JsonKeyNames(value)

Bases: Enum

An enumeration.

COM_IF = 'com_if'
SERIAL_BAUDRATE = 'serial_baudrate'
SERIAL_HINT = 'serial_hint'
SERIAL_PORT = 'serial_port'
TCPIP_TCP_DEST_IP_ADDRESS = 'tcpip_tcp_ip_addr'
TCPIP_TCP_DEST_PORT = 'tcpip_tcp_port'
TCPIP_TCP_RECV_MAX_SIZE = 'tcpip_tcp_recv_max_size'
TCPIP_UDP_DEST_IP_ADDRESS = 'tcpip_udp_ip_addr'
TCPIP_UDP_DEST_PORT = 'tcpip_udp_port'
TCPIP_UDP_RECV_IP_ADDRESS = 'tcpip_udp_recv_addr'
TCPIP_UDP_RECV_MAX_SIZE = 'tcpip_udp_recv_max_size'
TCPIP_UDP_RECV_PORT = 'tcpip_udp_recv_port'
tmtccmd.util.json.check_json_file(json_cfg_path: str) bool

The check JSON file and return whether it was valid or not. A JSON file is invalid if it does not exist or the format ins invalid. :return: True if JSON file is valid, False if not and a new one was created at the specified path

tmtccmd.util.json.save_to_json_with_prompt(key: str, value: Any, name: str, json_cfg_path: str, json_obj: Any) bool

Object ID Module

class tmtccmd.util.obj_id.ComponentIdBase(obj_id: int, byte_len: int, name: str | None = None)

Bases: UnsignedByteField

Base class for unsigned object IDs with different byte sizes

property as_hex_string: str
property obj_id: int
class tmtccmd.util.obj_id.ComponentIdU16(obj_id: int, name: str | None = None)

Bases: ComponentIdBase

A helper object for a unique object identifier which has a raw unsigned 16-bit representation.

classmethod from_bytes_typed(obj_id_as_bytes: bytes) ComponentIdU16
class tmtccmd.util.obj_id.ComponentIdU32(obj_id: int, name: str | None = None)

Bases: ComponentIdBase

A helper object for a unique object identifier which has a raw unsigned 32-bit representation.

>>> obj_id = ComponentIdU32(42, "Object with the answer to everything")
>>> int(obj_id)
42
>>> obj_id.value
42
>>> obj_id.name
'Object with the answer to everything'
>>> obj_id.as_bytes.hex(sep=",")
'00,00,00,2a'
>>> obj_id.as_hex_string
'0x0000002a'
classmethod from_bytes_typed(obj_id_as_bytes: bytes) ComponentIdU32
class tmtccmd.util.obj_id.ComponentIdU8(obj_id: int, name: str | None = None)

Bases: ComponentIdBase

A helper object for a unique object identifier which has a raw unsigned 8-bit representation.

classmethod from_bytes_typed(obj_id_as_bytes: bytes) ComponentIdU8
tmtccmd.util.obj_id.ObjectIdBase

Deprecated type defintion for ComponentIdBase

tmtccmd.util.obj_id.ObjectIdDictT

Deprecated type defintion for ObjectIdMapping

tmtccmd.util.obj_id.ObjectIdMapping

Deprecated type defintion for ComponentIdMapping

tmtccmd.util.obj_id.ObjectIdU16

Deprecated type defintion for ComponentIdU16

tmtccmd.util.obj_id.ObjectIdU32

Deprecated type defintion for ComponentIdU32

tmtccmd.util.obj_id.ObjectIdU8

Deprecated type defintion for ComponentIdU8

Exit Module

class tmtccmd.util.exit.GracefulKiller

Bases: object

exit_gracefully()
kill_now = False
tmtccmd.util.exit.keyboard_interrupt_handler(tmtc_backend: BackendBase)

Hamming-Code Module

Hamming Code Implementation Hamming codes belong to the family of linear error correcting codes. Documentation: https://en.wikipedia.org/wiki/Hamming_code They can be used to identify up to two bit errors and correct one bit error per 256 byte block.

class tmtccmd.util.hammingcode.HammingReturnCodes(value)

Bases: Enum

An enumeration.

CODE_OKAY = 0
ERROR_ECC = 2
ERROR_MULTI_BIT = 3
ERROR_SINGLE_BIT = 1
OTHER_ERROR = 4
tmtccmd.util.hammingcode.hamming_compute_256(data: bytearray) bytearray

Takes a bytearray with the size of 256 bytes and calculates the 22 parity bits for the hamming code which will be returned as a three byte bytearray.

Parameters:

data

Returns:

tmtccmd.util.hammingcode.hamming_compute_256x(data: bytearray) bytearray

Computes 3-bytes hamming codes for a data block whose size is multiple of 256 bytes. Each 256 bytes block gets its own code.

Parameters:

data – Data to compute code for. Should be a multiple of 256 bytes, pad data with 0 if necessary!

Returns:

bytearray of hamming codes with the size (3 / 256 * size). Empty bytearray if input is invalid.

tmtccmd.util.hammingcode.hamming_test()

Algorithm was verified with this simple test.

tmtccmd.util.hammingcode.hamming_verify_256(data: bytearray, original_hamming_code: bytearray) HammingReturnCodes

Verifies and corrects a 256-bytes block of data using the given 22-bits hamming code. Returns 0 if there is no error, otherwise returns a HAMMING_ERROR code.

Parameters:
  • data – 256 code block to verify

  • original_hamming_code – Original 3 byte hamming code with 22 parity bits

Returns:

See HammingReturnCodes enums. - -1 for invalid input - 0 if there are no errors. - 1 if there is a single bit error which has been corrected - 2 if the hamming code has been corrupted - 3 if there was a multi bit error which can not be corrected

tmtccmd.util.hammingcode.hamming_verify_256x(data: bytearray, original_hamming_code: bytearray) HammingReturnCodes

TMTC Printer (FSFW) Module

Contains classes and functions that perform all printing functionalities.

class tmtccmd.fsfw.tmtc_printer.DisplayMode(value)

Bases: Enum

List of display modes

LONG = <class 'enum.auto'>
SHORT = <class 'enum.auto'>
class tmtccmd.fsfw.tmtc_printer.FsfwTmTcPrinter(file_logger: Logger | None, display_mode: DisplayMode = DisplayMode.SHORT)

Bases: object

This class handles printing to the command line and to files

Parameters:

display_mode

static bit_extractor(byte: int, position: int)
Parameters:
  • byte

  • position

Returns:

static chunks(lst: list, n) Generator[list[list], None, None]

Yield successive n-sized chunks from lst.

generic_hk_tm_print(content_type: HkContentType, object_id: ComponentIdU32, set_id: int, hk_data: bytes)

This function pretty prints HK packets with a given header and content list :param content_type: Type of content for HK packet :param object_id: Object ID of the HK source :param set_id: Unique set ID for the HK packet :param hk_data: User defined HK data :return:

static generic_short_string(packet_if: PusTmInterface) str
static get_validity_buffer_str(validity_buffer: bytes, num_vars: int) str
Parameters:
  • validity_buffer – Validity buffer in bytes format

  • num_vars – Number of variables

Returns:

handle_long_tm_print(packet_if: PusTmInterface, info_if: PusTmInfoInterface)

Main function to print the most important information inside the telemetry :param packet_if: Core packet interface :param info_if: Information interface :return:

static print_data(data: bytes)
Parameters:

data – Data to print

Returns:

None

print_validity_buffer(validity_buffer: bytes, num_vars: int)
tmtccmd.fsfw.tmtc_printer.get_validity_buffer_str(validity_buffer: bytes, num_vars: int) str
Parameters:
  • validity_buffer – Validity buffer in bytes format

  • num_vars – Number of variables

Returns:

Configuration Utility Module

class tmtccmd.util.conf_util.AnsiColors

Bases: object

BLUE = '\x1b[34m'
BOLD = '\x1b[1m'
CYAN = '\x1b[36m'
GREEN = '\x1b[32m'
MAGNETA = '\x1b[35m'
RED = '\x1b[31m'
RESET = '\x1b[0m'
YELLOW = '\x1b[33m'
tmtccmd.util.conf_util.acquire_timeout(lock, timeout)

Helper functions which allows to check result of the acquire operation while also using the context manager. :param lock: :param timeout: :return:

tmtccmd.util.conf_util.check_args_in_dict(param: any, iterable: Iterable | dict, warning_hint: str) tuple[bool, int]

This functions checks whether the integer representation of a given parameter in contained within the passed collections, for example an (integer) enumeration. Please note that if the passed parameter has a string representation but is a digit, this function will attempt to check whether the integer representation is contained inside the passed enumeration. :param param: Value to be checked :param iterable: Enumeration, for example a enum.Enum or enum.IntEnum implementation :param warning_hint: :return:

tmtccmd.util.conf_util.wrapped_prompt(text: str)

Module contents

Countdown Module

The countdown module was moved to the spacepackets library. Use the spacepackets.countdown module.

Sequence Count Module

The sequence count module was moved to the spacepackets library. Use the spacepackets.seqcount module.