Path: blob/master/Tools/autotest/param_metadata/mdemit.py
9701 views
# flake8: noqa12"""3Emit parameter documentation in markdown format4"""56from param import known_param_fields7from emit import Emit8import re9import os1011# Parameter groups disabled at compile time (Vehicle-specific)12sub_blacklist = ['AVOID_', 'CIRCLE_', 'FLOW', 'MIS_', 'PRX', 'RALLY_', 'RCMAP_', 'RPM', 'TERRAIN_', 'WPNAV_']1314# Parameter groups with redundant information (ie RCn_, SERVOn_)15# We can keep the documentation concise by only documenting these once16nparams = ['RCn_', 'SERVOn_', 'SRn_', 'BTNn_']1718class MDEmit(Emit):1920def __init__(self, *args, **kwargs):21Emit.__init__(self, *args, **kwargs)22fname = 'Parameters.md'23self.nparams = []24self.f = open(fname, mode='w')2526self.blacklist = None2728# Flag to generate navigation header for BlueRobotics' ArduSub docs29if os.getenv('BRDOC') is not None:30self.header = """---\nlayout: default\ntitle: "Parameters"\npermalink: /parameters/\nnav:"""3132self.preamble = """\nThis is a complete list of the parameters which can be set via the MAVLink protocol in the EEPROM of your autopilot to control vehicle behaviour. This list is automatically generated from the latest ardupilot source code, and so may contain parameters which are not yet in the stable released versions of the code. Some parameters may only be available for developers, and are enabled at compile-time."""33self.t = ''3435def close(self):36# Write navigation header for BlueRobotics' ArduSub docs37if os.getenv('BRDOC') is not None:38self.f.write(self.header)39self.f.write('\n---\n')4041self.f.write(self.preamble)42self.f.write(self.t)43self.f.close()4445def start_libraries(self):46pass4748def emit(self, g):49nparam = False # Flag indicating this is a parameter group with redundant information (ie RCn_, SERVOn_)5051if g.reference == 'ArduSub':52self.blacklist = sub_blacklist5354if self.blacklist is not None and g.reference in self.blacklist:55return5657pname = g.reference5859# Check to see this is a parameter group with redundant information60rename = re.sub(r'\d+', 'n', g.reference)61if rename in nparams:62if rename in self.nparams:63return64else:65self.nparams.append(rename)66pname = rename67nparam = True6869# Markdown!70tag = '%s Parameters' % pname71tag = tag.replace('_', '')72link = tag.replace(' ', '-')7374# Add group to navigation header for BlueRobotics' ArduSub docs75if os.getenv('BRDOC') is not None:76self.header += "\n- %s: %s" % (link.split('-')[0],link.lower())7778t = '\n\n# %s' % tag7980for param in g.params:81if not self.should_emit_param(param):82continue83if not hasattr(param, 'DisplayName') or not hasattr(param, 'Description'):84continue85d = param.__dict__86name = param.name.split(':')[-1]87if nparam:88name = re.sub(r'\d+', 'n', name, 1)89tag = '%s: %s' % (name, param.DisplayName)90t += '\n\n## %s' % tag91if d.get('User', None) == 'Advanced':92t += '\n\n*Note: This parameter is for advanced users*'93t += "\n\n%s" % param.Description9495for field in param.__dict__.keys():96if not self.should_emit_field(param, field):97continue98if field not in ['name', 'DisplayName', 'Description', 'User', 'SortValues'] and field in known_param_fields:99if field == 'Values' and Emit.prog_values_field.match(param.__dict__[field]):100values = (param.__dict__[field]).split(',')101t += "\n\n|Value|Meaning|"102t += "\n|:---:|:---:|"103for value in values:104v = value.split(':')105if len(v) != 2:106raise ValueError("Bad value (%s)" % v)107t += "\n|%s|%s|" % (v[0], v[1])108else:109t += "\n\n- %s: %s" % (field, param.__dict__[field])110self.t += t111112113