Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mavgen_python: make enumerations MavEnum instances #904

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Examples can be found [in the repository](examples/) or in the [ArduSub book](ht

# Installation

Pymavlink supports both Python 2 and Python 3.

The following instructions assume you are using Python 3 and a Debian-based (like Ubuntu) installation.

.. note::
Expand All @@ -27,7 +25,7 @@ The following instructions assume you are using Python 3 and a Debian-based (lik

Pymavlink has several dependencies :

- [future](http://python-future.org/) : for Python 2 and Python 3 interoperability
- [future](http://python-future.org/) : for interoperability
- [lxml](http://lxml.de/installation.html) : for checking and parsing xml file

Optional :
Expand All @@ -39,10 +37,6 @@ Optional :

lxml has some additional dependencies that can be installed with your package manager (here with `apt-get`) :

.. note::

If you continue to use Python 2 you may need to change package names here (e.g. python3-numpy => python-numpy)

```bash
sudo apt-get install libxml2-dev libxslt-dev
```
Expand Down
18 changes: 16 additions & 2 deletions generator/mavgen_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def extend_with_type_info(extended, enable_type_annotations):
"mavlink_message_signed_callback": ('Callable[["MAVLink", int], bool]', None),
"dict_str_to_str_float_int": ("Dict[str, Union[str, float, int]]", None),
"dict_str_to_dict_int_to_enumentry": ("Dict[str, Dict[int, EnumEntry]]", None),
"dict_int_to_enumentry": ("Dict[int, EnumEntry]", None),
"dict_str_to_MavEnum": ("Dict[str, MavEnum]", None),
"dict_int_to_str": ("Dict[int, str]", None),
"dict_str_to_str": ("Dict[str, str]", None),
"dict_int_int_int_to_int": ("Dict[Tuple[int, int, int], int]", None),
Expand Down Expand Up @@ -457,14 +459,26 @@ def __init__(self, name${type_str}, description${type_str})${type_none_ret}:
self.has_location = False


enums${type_dict_str_to_dict_int_to_enumentry} = {}
class MavEnum(${type_dict_int_to_enumentry_cast}):
def __init__(self, bitmask${type_bool_default})${type_none_ret}:
super(MavEnum, self).__init__()
self.bitmask = bitmask

def is_bitmask(self)${type_bool_ret}:
return self.bitmask


enums${type_dict_str_to_MavEnum} = {}
""",
type_info,
)

for e in enums:
outf.write("\n# %s\n" % e.name)
outf.write('enums["%s"] = {}\n' % e.name)
mavenum_kwargs = ""
if bool(e.bitmask):
mavenum_kwargs = "bitmask=True"
outf.write('enums["%s"] = MavEnum(%s)\n' % (e.name, mavenum_kwargs))
for entry in e.entry:
outf.write("%s = %u\n" % (entry.name, entry.value))
description = entry.description.replace("\t", " ")
Expand Down
Loading