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

Support reserved/default params in generated libraries #269

Merged
merged 2 commits into from
Mar 13, 2019
Merged
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
51 changes: 48 additions & 3 deletions generator/mavparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,27 @@ def base_fields(self):
return len(self.fields[:self.extensions_start])

class MAVEnumParam(object):
def __init__(self, index, description=''):
def __init__(self, index, description='', label='', units='', enum='', increment='', minValue='', maxValue='', reserved=False, default=''):
self.index = index
self.description = description
self.label = label
self.units = units
self.enum = enum
self.increment = increment
self.minValue = minValue
self.maxValue = maxValue
self.reserved = reserved
self.default = default
if self.reserved and not self.default:
self.default = '0'
self.set_description(description)

def set_description(self, description):
if not description.strip() and self.reserved:
self.description = 'Reserved (default:%s)' % self.default
else:
self.description = description
self.description = '%s: %s' % (self.index, self.description)

class MAVEnumEntry(object):
def __init__(self, name, value, description='', end_marker=False, autovalue=False, origin_file='', origin_line=0):
Expand Down Expand Up @@ -260,7 +278,13 @@ def start_element(name, attrs):
self.enum[-1].entry.append(MAVEnumEntry(attrs['name'], value, '', False, autovalue, self.filename, p.CurrentLineNumber))
elif in_element == "mavlink.enums.enum.entry.param":
check_attrs(attrs, ['index'], 'enum param')
self.enum[-1].entry[-1].param.append(MAVEnumParam(attrs['index']))
self.enum[-1].entry[-1].param.append(
MAVEnumParam(attrs['index'],
label=attrs.get('label', ''), units=attrs.get('units', ''),
enum=attrs.get('enum', ''), increment=attrs.get('increment', ''),
minValue=attrs.get('minValue', ''),
maxValue=attrs.get('maxValue', ''), default=attrs.get('default', '0'),
reserved=attrs.get('reserved', False) ))

def end_element(name):
in_element_list.pop()
Expand All @@ -277,7 +301,7 @@ def char_data(data):
elif in_element == "mavlink.enums.enum.entry.description":
self.enum[-1].entry[-1].description += data
elif in_element == "mavlink.enums.enum.entry.param":
self.enum[-1].entry[-1].param[-1].description += data
self.enum[-1].entry[-1].param[-1].set_description(data.strip())
elif in_element == "mavlink.version":
self.version = int(data)
elif in_element == "mavlink.include":
Expand All @@ -290,6 +314,27 @@ def char_data(data):
p.CharacterDataHandler = char_data
p.ParseFile(f)
f.close()


#Post process to add reserved params (for docs)
for current_enum in self.enum:
if not 'MAV_CMD' in current_enum.name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pythonically if 'MAV_CMD' not in current_enum.name:

continue
print(current_enum.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of debug still in here.

for enum_entry in current_enum.entry:
print(enum_entry.name)
if len(enum_entry.param) == 7:
continue
params_dict=dict()
for param_index in range (1,8):
params_dict[param_index] = MAVEnumParam(param_index, label='', units='', enum='', increment='',
minValue='', maxValue='', default='0', reserved='True')

for a_param in enum_entry.param:
params_dict[int(a_param.index)] = a_param
enum_entry.param=params_dict.values()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a space in here.

Generally it would be nice if flake8 didn't whinge about new stuff.




self.message_lengths = {}
self.message_min_lengths = {}
Expand Down