diff --git a/src/fprime_gds/common/loaders/ch_json_loader.py b/src/fprime_gds/common/loaders/ch_json_loader.py index c6509b12..acbd3134 100644 --- a/src/fprime_gds/common/loaders/ch_json_loader.py +++ b/src/fprime_gds/common/loaders/ch_json_loader.py @@ -8,18 +8,17 @@ from fprime_gds.common.templates.ch_template import ChTemplate from fprime_gds.common.loaders.json_loader import JsonLoader +from enum import Enum class ChJsonLoader(JsonLoader): """Class to load python based telemetry channel dictionaries""" - # Field names in the python module files (used to construct dictionaries) - ID_FIELD = "id" - NAME_FIELD = "name" - KIND_FIELD = "kind" - DESC_FIELD = "annotation" - TYPE_FIELD = "type" - FMT_STR_FIELD = "format" + ID = "id" + NAME = "name" + DESC = "annotation" + TYPE = "type" + FMT_STR = "format" LIMIT_FIELD = "limit" LIMIT_LOW = "low" LIMIT_HIGH = "high" @@ -27,15 +26,12 @@ class ChJsonLoader(JsonLoader): LIMIT_ORANGE = "orange" LIMIT_YELLOW = "yellow" - def __init__(self, dict_path: str): - super().__init__(dict_path) - - def construct_dicts(self, dict_path: str): + def construct_dicts(self, _): """ Constructs and returns python dictionaries keyed on id and name Args: - path: Path to JSON dictionary file + _: Unused argument (inherited) Returns: A tuple with two channel dictionaries (python type dict): (id_dict, name_dict). The keys should be the channels' id and @@ -59,33 +55,29 @@ def construct_dicts(self, dict_path: str): ) def construct_template_from_dict(self, channel_dict: dict) -> ChTemplate: - component_name = channel_dict[self.NAME_FIELD].split(".")[0] - channel_name = channel_dict[self.NAME_FIELD].split(".")[1] - channel_type = channel_dict["type"] + component_name = channel_dict[self.NAME].split(".")[0] + channel_name = channel_dict[self.NAME].split(".")[1] + channel_type = channel_dict[self.TYPE] type_obj = self.parse_type(channel_type) - format_str = JsonLoader.preprocess_format_str( - channel_dict.get(self.FMT_STR_FIELD) - ) + format_str = JsonLoader.preprocess_format_str(channel_dict.get(self.FMT_STR)) limit_field = channel_dict.get(self.LIMIT_FIELD) limit_low = limit_field.get(self.LIMIT_LOW) if limit_field else None limit_high = limit_field.get(self.LIMIT_HIGH) if limit_field else None - limit_low_yellow = limit_low.get(self.LIMIT_YELLOW) if limit_low else None limit_low_red = limit_low.get(self.LIMIT_RED) if limit_low else None limit_low_orange = limit_low.get(self.LIMIT_ORANGE) if limit_low else None - limit_high_yellow = limit_high.get(self.LIMIT_YELLOW) if limit_high else None limit_high_red = limit_high.get(self.LIMIT_RED) if limit_high else None limit_high_orange = limit_high.get(self.LIMIT_ORANGE) if limit_high else None return ChTemplate( - channel_dict[self.ID_FIELD], + channel_dict[self.ID], channel_name, component_name, type_obj, ch_fmt_str=format_str, - ch_desc=channel_dict.get(self.DESC_FIELD), + ch_desc=channel_dict.get(self.DESC), low_red=limit_low_red, low_orange=limit_low_orange, low_yellow=limit_low_yellow, diff --git a/src/fprime_gds/common/loaders/cmd_json_loader.py b/src/fprime_gds/common/loaders/cmd_json_loader.py index 1abcb832..d8443ae3 100644 --- a/src/fprime_gds/common/loaders/cmd_json_loader.py +++ b/src/fprime_gds/common/loaders/cmd_json_loader.py @@ -13,26 +13,22 @@ class CmdJsonLoader(JsonLoader): """Class to load xml based command dictionaries""" - MNEMONIC_TAG = "name" + NAME_TAG = "name" OPCODE_TAG = "opcode" DESC_TAG = "annotation" PARAMETERS_TAG = "formalParams" - def __init__(self, dict_path: str): - super().__init__(dict_path) - - def construct_dicts(self, path): + def construct_dicts(self, _): """ Constructs and returns python dictionaries keyed on id and name Args: - path: Path to JSON dictionary file + _: Unused argument (inherited) Returns: - A tuple with two command dictionaries (python type dict): - (id_dict, name_dict). The keys are the events' id and name fields - respectively and the values are CmdTemplate objects + A tuple with two command dictionaries (python type dict): + (id_dict, name_dict). The keys are the events' id and name fields + respectively and the values are CmdTemplate objects """ - id_dict = {} name_dict = {} @@ -49,26 +45,20 @@ def construct_dicts(self, path): ) def construct_template_from_dict(self, cmd_dict: dict) -> CmdTemplate: - cmd_name = cmd_dict.get("name") - + cmd_name = cmd_dict.get(self.NAME_TAG) cmd_comp = cmd_name.split(".")[0] cmd_mnemonic = cmd_name.split(".")[1] - - cmd_opcode = cmd_dict.get("opcode") - - cmd_desc = cmd_dict.get("annotation") - + cmd_opcode = cmd_dict.get(self.OPCODE_TAG) + cmd_desc = cmd_dict.get(self.DESC_TAG) # Parse Arguments cmd_args = [] - for arg in cmd_dict.get("formalParams", []): + for param in cmd_dict.get(self.PARAMETERS_TAG, []): cmd_args.append( ( - arg.get("name"), - arg.get("annotation"), - self.parse_type(arg.get("type")), + param.get("name"), + param.get("annotation"), + self.parse_type(param.get("type")), ) ) - return CmdTemplate( - cmd_opcode, cmd_mnemonic, cmd_comp, cmd_args, cmd_desc - ) + return CmdTemplate(cmd_opcode, cmd_mnemonic, cmd_comp, cmd_args, cmd_desc) diff --git a/src/fprime_gds/common/loaders/event_json_loader.py b/src/fprime_gds/common/loaders/event_json_loader.py index a0b766d8..be84a537 100644 --- a/src/fprime_gds/common/loaders/event_json_loader.py +++ b/src/fprime_gds/common/loaders/event_json_loader.py @@ -6,27 +6,22 @@ @author thomas-bc """ -from fprime_gds.common.data_types import exceptions from fprime_gds.common.templates.event_template import EventTemplate from fprime_gds.common.utils.event_severity import EventSeverity - -# Custom Python Modules from fprime_gds.common.loaders.json_loader import JsonLoader class EventJsonLoader(JsonLoader): """Class to load xml based event dictionaries""" - EVENT_SECT = "events" - - COMP_TAG = "component" NAME_TAG = "name" ID_TAG = "id" SEVERITY_TAG = "severity" FMT_STR_TAG = "format" DESC_TAG = "annotation" + PARAMETERS_TAG = "formalParams" - def construct_dicts(self, path): + def construct_dicts(self, _): """ Constructs and returns python dictionaries keyed on id and name @@ -34,7 +29,7 @@ def construct_dicts(self, path): get_id_dict(path) and get_name_dict(path) Args: - path: Path to the xml dictionary file containing event information + _: Unused argument (inherited) Returns: A tuple with two event dictionaries (python type dict): @@ -57,7 +52,7 @@ def construct_dicts(self, path): ) def construct_template_from_dict(self, event_dict: dict): - event_mnemonic = event_dict.get("name") + event_mnemonic = event_dict.get(self.NAME_TAG) event_comp = event_mnemonic.split(".")[0] event_name = event_mnemonic.split(".")[1] @@ -72,7 +67,7 @@ def construct_template_from_dict(self, event_dict: dict): # Parse arguments event_args = [] - for arg in event_dict.get("formalParams", []): + for arg in event_dict.get(self.PARAMETERS_TAG, []): event_args.append( ( arg.get("name"),