Skip to content

Commit

Permalink
Fix/enum representation types (#155)
Browse files Browse the repository at this point in the history
* Jack White: Added serialise/representation type to XML loader

* Jack White: Amended new call to EnumType.contruct_type()

* Jack White: Replaced explicit check-and-set for default enum serialize type with default value in dict.get()

* Bumping fprime-tools version for representation types

---------

Co-authored-by: Jack White <[email protected]>
Co-authored-by: M Starch <[email protected]>
  • Loading branch information
3 people authored Feb 16, 2024
1 parent a46f835 commit 7f3bb47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies = [
"pexpect>=4.8.0",
"pytest>=6.2.4",
"flask_restful>=0.3.8",
"fprime-tools>=3.1.2a1",
"fprime-tools>=3.4.3",
"argcomplete>=1.12.3",
"Jinja2>=2.11.3",
"openpyxl>=3.0.10",
Expand Down
6 changes: 5 additions & 1 deletion src/fprime_gds/common/loaders/xml_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class XmlLoader(dict_loader.DictLoader):

ENUM_SECT = "enums"
ENUM_TYPE_TAG = "type"
ENUM_SERIALIZE_TYPE_TAG = "serialize_type"
ENUM_ELEM_NAME_TAG = "name"
ENUM_ELEM_VAL_TAG = "value"
ENUM_ELEM_DESC_TAG = "description"
Expand Down Expand Up @@ -202,14 +203,17 @@ def get_enum_type(self, enum_name, xml_obj):
for enum in enum_section:
# Check enum name
if enum.get(self.ENUM_TYPE_TAG) == enum_name:
# Get serialize/representation type, if present
serialize_type = enum.get(self.ENUM_SERIALIZE_TYPE_TAG, "I32")

# Go through all possible values of the enum
members = {}
for item in enum:
item_name = item.get(self.ENUM_ELEM_NAME_TAG)
item_val = int(item.get(self.ENUM_ELEM_VAL_TAG))
members[item_name] = item_val

enum_obj = EnumType.construct_type(enum_name, members)
enum_obj = EnumType.construct_type(enum_name, members, serialize_type)

self.enums[enum_name] = enum_obj
return enum_obj
Expand Down

0 comments on commit 7f3bb47

Please sign in to comment.