forked from Archive/PX4-Autopilot
generate_params.py: extend params 'definitions' section to support a list
allows to add multiple entries for a multi-instance param with different instance_start
This commit is contained in:
parent
6f01b69f49
commit
db28ea9cfa
|
@ -50,49 +50,56 @@ def parse_yaml_parameters_config(yaml_config, ethernet_supported):
|
||||||
definitions = parameters_section['definitions']
|
definitions = parameters_section['definitions']
|
||||||
param_group = parameters_section.get('group', None)
|
param_group = parameters_section.get('group', None)
|
||||||
for param_name in definitions:
|
for param_name in definitions:
|
||||||
param = definitions[param_name]
|
# 'definitions' either contains the param definition directly (dict),
|
||||||
if param.get('requires_ethernet', False) and not ethernet_supported:
|
# or a list of definitions with that name (multiple entries for a
|
||||||
continue
|
# multi-instance param with different instance_start)
|
||||||
num_instances = param.get('num_instances', 1)
|
param_list = definitions[param_name]
|
||||||
instance_start = param.get('instance_start', 0) # offset
|
if not isinstance(param_list, list):
|
||||||
|
param_list = [param_list]
|
||||||
|
|
||||||
# get the type and extract all tags
|
for param in param_list:
|
||||||
tags = '@group {:}'.format(param_group)
|
if param.get('requires_ethernet', False) and not ethernet_supported:
|
||||||
if param['type'] == 'enum':
|
continue
|
||||||
param_type = 'INT32'
|
num_instances = param.get('num_instances', 1)
|
||||||
for key in param['values']:
|
instance_start = param.get('instance_start', 0) # offset
|
||||||
tags += '\n * @value {:} {:}'.format(key, param['values'][key])
|
|
||||||
elif param['type'] == 'boolean':
|
|
||||||
param_type = 'INT32'
|
|
||||||
tags += '\n * @boolean'
|
|
||||||
elif param['type'] == 'int32':
|
|
||||||
param_type = 'INT32'
|
|
||||||
elif param['type'] == 'float':
|
|
||||||
param_type = 'FLOAT'
|
|
||||||
else:
|
|
||||||
raise Exception("unknown param type {:}".format(param['type']))
|
|
||||||
|
|
||||||
for tag in ['decimal', 'increment', 'category', 'volatile', 'bit',
|
# get the type and extract all tags
|
||||||
'min', 'max', 'unit', 'reboot_required']:
|
tags = '@group {:}'.format(param_group)
|
||||||
if tag in param:
|
if param['type'] == 'enum':
|
||||||
tags += '\n * @{:} {:}'.format(tag, param[tag])
|
param_type = 'INT32'
|
||||||
|
for key in param['values']:
|
||||||
|
tags += '\n * @value {:} {:}'.format(key, param['values'][key])
|
||||||
|
elif param['type'] == 'boolean':
|
||||||
|
param_type = 'INT32'
|
||||||
|
tags += '\n * @boolean'
|
||||||
|
elif param['type'] == 'int32':
|
||||||
|
param_type = 'INT32'
|
||||||
|
elif param['type'] == 'float':
|
||||||
|
param_type = 'FLOAT'
|
||||||
|
else:
|
||||||
|
raise Exception("unknown param type {:}".format(param['type']))
|
||||||
|
|
||||||
for i in range(num_instances):
|
for tag in ['decimal', 'increment', 'category', 'volatile', 'bit',
|
||||||
# default value
|
'min', 'max', 'unit', 'reboot_required']:
|
||||||
default_value = 0
|
if tag in param:
|
||||||
if 'default' in param:
|
tags += '\n * @{:} {:}'.format(tag, param[tag])
|
||||||
# default can be a list of num_instances or a single value
|
|
||||||
if type(param['default']) == list:
|
|
||||||
assert len(param['default']) == num_instances
|
|
||||||
default_value = param['default'][i]
|
|
||||||
else:
|
|
||||||
default_value = param['default']
|
|
||||||
|
|
||||||
if type(default_value) == bool:
|
for i in range(num_instances):
|
||||||
default_value = int(default_value)
|
# default value
|
||||||
|
default_value = 0
|
||||||
|
if 'default' in param:
|
||||||
|
# default can be a list of num_instances or a single value
|
||||||
|
if type(param['default']) == list:
|
||||||
|
assert len(param['default']) == num_instances
|
||||||
|
default_value = param['default'][i]
|
||||||
|
else:
|
||||||
|
default_value = param['default']
|
||||||
|
|
||||||
# output the existing C-style format
|
if type(default_value) == bool:
|
||||||
ret += '''
|
default_value = int(default_value)
|
||||||
|
|
||||||
|
# output the existing C-style format
|
||||||
|
ret += '''
|
||||||
/**
|
/**
|
||||||
* {short_descr}
|
* {short_descr}
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue