Skip to content

Parse CCDD files

Travis Christian edited this page Mar 31, 2022 · 1 revision

The following code snippet can be used to parse CCDD files and generate the MID and macro maps that CTF uses internally to resolve message parameters. These maps can be used to inspect and debug data types created by the CCDDExportReader, or to provide message data for use in larger scripts.

from plugins.ccsds_plugin.readers.ccdd_export_reader import CCDDExportReader
from plugins.cfs.cfs_config import CfsConfig
from lib.ctf_global import Global

Global.load_config("./configs/default_config.ini") # use your test config
cfg = CfsConfig("cfs") # use your target name
mid_map, macro_map = CCDDExportReader(cfg).get_ccsds_messages_from_dir(cfg.ccsds_data_dir) # this may produce a lot of output depending on your CCDD exports and config settings

# mid map is a dictionary of the form:
#{
#   MID_NAME: {
#       'MID': MID_VALUE,
#       'CC': {
#           CC_NAME: {
#               'CODE': CC_VALUE,
#               'ARG_CLASS': CUSTOM_TYPE
#           }
#           ...
#       }
#   }
#   ...
#}
for mid_name in mid_map:
    print(mid_name + ": " + str(mid_map[mid_name]['MID']))
    for cc_name in mid_map[mid_name].get('CC', []):
        print("  " + cc_name + ": " + str(mid_map[mid_name]['CC'][cc_name]['CODE']))

# macro_map is a simple dictionary containing constant names and values
for k, v in macro_map.items():
    print(k + ": " + str(v))

Example output using the sample workspace and default config:

# partial output of CCDDExportReader
Data type CF_NoArgsCmd_t is already created, but will be overridden
Data type CF_NoArgsCmd_t is already created, but will be overridden
Data type CF_CARSCmd_t is already created, but will be overridden
Data type CF_CARSCmd_t is already created, but will be overridden
...

# partial output of mid_map
CF_CMD_MID: 10881
CF_NOOP_CC: 0
CF_RESET_CC: 1
CF_PLAYBACK_FILE_CC: 2
CF_PLAYBACK_DIR_CC: 3
CF_FREEZE_CC: 4
CF_THAW_CC: 5
CF_SUSPEND_CC: 6
CF_RESUME_CC: 7
CF_CANCEL_CC: 8
CF_ABANDON_CC: 9
...

# partial output of macro_map
TRUE: 1
FALSE: 0
CCSDS_TIME_SIZE: 6
CFE_ES_CDS_MAX_FULL_NAME_LEN: 38
CFE_ES_MAX_APPLICATIONS: 32
CFE_ES_MAX_MEMPOOL_BLOCK_SIZES: 17
CFE_ES_MAX_SHELL_CMD: 64
CFE_MISSION_ES_MAX_SHELL_CMD: 64
CFE_MISSION_ES_MAX_SHELL_PKT: 64
CFE_MISSION_ES_PERF_MAX_IDS: 128
...

If using an interpreter like IDLE, you can then inspect mid_map to see the custom types. These classes may be instantiated and used like so:

>>> to_enable_output = mid_map["TO_CMD_MID"]['CC']['TO_ENABLE_OUTPUT_CC']['ARG_CLASS']()
>>> to_enable_output.cDestIp = "127.0.0.1".encode()
>>> to_enable_output.usDestPort = 5011
>>> bytes(to_enable_output)
b'127.0.0.1\x00\x00\x00\x00\x00\x00\x00\x93\x13\x00\x00\x00\x00\x00\x00'

>>> to_enable_output_2 = mid_map["TO_CMD_MID"]['CC']['TO_ENABLE_OUTPUT_CC']['ARG_CLASS']("127.0.0.1".encode(), 5011)
>>> to_enable_output_2.cDestIp
b'127.0.0.1'
Clone this wiki locally