2013-02-16 18:01:55 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from xml.sax.saxutils import escape, quoteattr
|
|
|
|
|
|
|
|
from emit import Emit
|
2017-05-02 07:36:14 -03:00
|
|
|
from param import known_param_fields, known_units
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2020-09-15 07:27:21 -03:00
|
|
|
INDENT2 = " "
|
|
|
|
INDENT4 = " "
|
|
|
|
INDENT6 = " "
|
|
|
|
INDENT8 = " "
|
|
|
|
INDENT10 = " "
|
2013-02-16 18:01:55 -04:00
|
|
|
|
|
|
|
# Emit APM documentation in an machine readable XML format
|
|
|
|
class XmlEmit(Emit):
|
|
|
|
def __init__(self):
|
2016-07-31 07:22:06 -03:00
|
|
|
Emit.__init__(self)
|
2020-09-15 07:27:21 -03:00
|
|
|
self.wiki_fname = 'apm.pdef.xml'
|
|
|
|
self.f = open(self.wiki_fname, mode='w')
|
|
|
|
self.preamble = '''<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<!-- Dynamically generated list of documented parameters (generated by param_parse.py) -->
|
|
|
|
'''
|
|
|
|
self.f.write(self.preamble)
|
|
|
|
self.f.write('''<paramfile>
|
|
|
|
<vehicles>\n''')
|
2016-07-31 07:22:06 -03:00
|
|
|
|
|
|
|
def close(self):
|
2020-09-15 07:27:21 -03:00
|
|
|
self.f.write(INDENT2 + '</libraries>\n')
|
2013-02-16 18:01:55 -04:00
|
|
|
self.f.write('''</paramfile>\n''')
|
2016-07-31 07:22:06 -03:00
|
|
|
self.f.close()
|
|
|
|
|
2013-02-16 18:01:55 -04:00
|
|
|
def emit_comment(self, s):
|
|
|
|
self.f.write("<!-- " + s + " -->")
|
|
|
|
|
|
|
|
def start_libraries(self):
|
2020-09-15 07:27:21 -03:00
|
|
|
self.f.write(INDENT2 + '</vehicles>\n')
|
|
|
|
self.f.write(INDENT2 + '<libraries>\n')
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2018-12-06 05:07:51 -04:00
|
|
|
def emit(self, g):
|
2020-09-15 07:27:21 -03:00
|
|
|
t = INDENT4 + '''<parameters name=%s>\n''' % quoteattr(g.name) # i.e. ArduPlane
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-02-16 18:01:55 -04:00
|
|
|
for param in g.params:
|
|
|
|
# Begin our parameter node
|
2016-07-31 07:22:06 -03:00
|
|
|
if hasattr(param, 'DisplayName'):
|
2020-09-15 07:27:21 -03:00
|
|
|
t += INDENT6 + '<param humanName=%s name=%s' % (quoteattr(param.DisplayName), quoteattr(param.name)) # i.e. ArduPlane (ArduPlane:FOOPARM)
|
2013-02-16 18:01:55 -04:00
|
|
|
else:
|
2020-09-15 07:27:21 -03:00
|
|
|
t += INDENT6 + '<param name=%s' % quoteattr(param.name)
|
2016-07-31 07:22:06 -03:00
|
|
|
|
|
|
|
if hasattr(param, 'Description'):
|
|
|
|
t += ' documentation=%s' % quoteattr(param.Description) # i.e. parameter docs
|
2013-04-15 21:51:01 -03:00
|
|
|
if hasattr(param, 'User'):
|
2016-07-31 07:22:06 -03:00
|
|
|
t += ' user=%s' % quoteattr(param.User) # i.e. Standard or Advanced
|
|
|
|
|
2020-02-01 20:56:29 -04:00
|
|
|
if hasattr(param, 'Calibration'):
|
|
|
|
t += ' calibration=%s' % quoteattr(param.Calibration) # i.e. Standard or Advanced
|
|
|
|
|
2013-02-16 18:01:55 -04:00
|
|
|
t += ">\n"
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-02-16 18:01:55 -04:00
|
|
|
# Add values as chidren of this node
|
|
|
|
for field in param.__dict__.keys():
|
|
|
|
if field not in ['name', 'DisplayName', 'Description', 'User'] and field in known_param_fields:
|
|
|
|
if field == 'Values' and Emit.prog_values_field.match(param.__dict__[field]):
|
2020-09-15 07:27:21 -03:00
|
|
|
t += INDENT8 + "<values>\n"
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-02-16 18:01:55 -04:00
|
|
|
values = (param.__dict__[field]).split(',')
|
|
|
|
for value in values:
|
|
|
|
v = value.split(':')
|
2018-03-25 22:35:13 -03:00
|
|
|
if len(v) != 2:
|
|
|
|
raise ValueError("Bad value (%s)" % v)
|
2020-09-15 07:27:21 -03:00
|
|
|
t += INDENT10 + '''<value code=%s>%s</value>\n''' % (quoteattr(v[0]), escape(v[1])) # i.e. numeric value, string label
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2020-09-15 07:27:21 -03:00
|
|
|
t += INDENT8 + "</values>\n"
|
2017-05-02 07:36:14 -03:00
|
|
|
elif field == 'Units':
|
|
|
|
abreviated_units = param.__dict__[field]
|
|
|
|
if abreviated_units != '':
|
|
|
|
units = known_units[abreviated_units] # use the known_units dictionary to convert the abreviated unit into a full textual one
|
2020-09-15 07:27:21 -03:00
|
|
|
t += INDENT8 + '''<field name=%s>%s</field>\n''' % (quoteattr(field), escape(abreviated_units)) # i.e. A/s
|
|
|
|
t += INDENT8 + '''<field name=%s>%s</field>\n''' % (quoteattr('UnitText'), escape(units)) # i.e. ampere per second
|
2013-02-16 18:01:55 -04:00
|
|
|
else:
|
2020-09-15 07:27:21 -03:00
|
|
|
t += INDENT8 + '''<field name=%s>%s</field>\n''' % (quoteattr(field), escape(param.__dict__[field])) # i.e. Range: 0 10
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2020-09-15 07:27:21 -03:00
|
|
|
t += INDENT6 + '''</param>\n'''
|
|
|
|
t += INDENT4 + '''</parameters>\n'''
|
2013-02-16 18:01:55 -04:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# print t
|
|
|
|
self.f.write(t)
|