2017-04-11 05:40:54 -03:00
|
|
|
from xml.sax.saxutils import escape
|
|
|
|
import codecs
|
2017-05-02 10:56:12 -03:00
|
|
|
import os
|
2021-01-19 18:28:09 -04:00
|
|
|
import html
|
2017-04-11 05:40:54 -03:00
|
|
|
|
|
|
|
class MarkdownTablesOutput():
|
2017-05-02 10:56:12 -03:00
|
|
|
def __init__(self, groups, board, image_path):
|
2021-07-14 22:40:05 -03:00
|
|
|
result = """# Airframes Reference
|
|
|
|
|
|
|
|
:::note
|
|
|
|
**This list is [auto-generated](https://github.com/PX4/PX4-Autopilot/blob/master/Tools/px4airframes/markdownout.py) from the source code** using the build command: `make airframe_metadata`.
|
|
|
|
:::
|
|
|
|
|
|
|
|
This page lists all supported airframes and types including the motor assignment and numbering.
|
|
|
|
The motors in **green** rotate clockwise, the ones in **blue** counterclockwise.
|
|
|
|
|
|
|
|
**AUX** channels may not be present on some flight controllers.
|
|
|
|
If present, PWM AUX channels are commonly labelled **AUX OUT**.
|
|
|
|
|
|
|
|
<style>
|
|
|
|
table {
|
|
|
|
display: table;
|
|
|
|
table-layout: fixed;
|
|
|
|
margin-bottom: 5px;
|
|
|
|
}
|
|
|
|
table.common {
|
|
|
|
float: right;
|
|
|
|
width: 70%;
|
|
|
|
}
|
|
|
|
table.airframes {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
table.airframes th:nth-child(1) {
|
|
|
|
width: 30%;
|
|
|
|
}
|
|
|
|
|
|
|
|
tr > * {
|
|
|
|
vertical-align : top;
|
|
|
|
}
|
|
|
|
td, th {
|
|
|
|
text-align : left;
|
|
|
|
}
|
|
|
|
img {
|
|
|
|
max-height: 180px;
|
|
|
|
width: 29%;
|
|
|
|
padding-top: 10px;
|
|
|
|
}
|
|
|
|
</style>\n\n"""
|
2017-06-27 02:42:30 -03:00
|
|
|
|
|
|
|
type_set = set()
|
|
|
|
|
2017-08-07 06:12:51 -03:00
|
|
|
if len(image_path) > 0 and image_path[-1] != '/':
|
|
|
|
image_path = image_path + '/'
|
2017-04-11 05:40:54 -03:00
|
|
|
|
|
|
|
for group in groups:
|
2017-06-27 08:32:39 -03:00
|
|
|
if group.GetClass() not in type_set:
|
|
|
|
result += '## %s\n\n' % group.GetClass()
|
|
|
|
type_set.add(group.GetClass())
|
2017-04-11 05:40:54 -03:00
|
|
|
|
2017-06-27 02:42:30 -03:00
|
|
|
result += '### %s\n\n' % group.GetName()
|
2017-04-11 05:40:54 -03:00
|
|
|
|
|
|
|
# Display an image of the frame
|
|
|
|
image_name = group.GetImageName()
|
2017-04-12 11:59:40 -03:00
|
|
|
result += '<div>\n'
|
2018-10-17 20:13:11 -03:00
|
|
|
image_name = image_path + image_name
|
2021-07-14 22:40:05 -03:00
|
|
|
result += '<img src="%s.svg"/>\n' % (image_name)
|
2017-04-11 05:40:54 -03:00
|
|
|
|
2017-04-12 11:59:40 -03:00
|
|
|
# check if all outputs are equal for the group: if so, show them
|
|
|
|
# only once
|
|
|
|
outputs_prev = ['', ''] # split into MAINx and others (AUXx)
|
|
|
|
outputs_match = [True, True]
|
|
|
|
for param in group.GetParams():
|
|
|
|
if not self.IsExcluded(param, board):
|
|
|
|
outputs_current = ['', '']
|
|
|
|
for output_name in param.GetOutputCodes():
|
|
|
|
value = param.GetOutputValue(output_name)
|
|
|
|
if output_name.lower().startswith('main'):
|
|
|
|
idx = 0
|
|
|
|
else:
|
|
|
|
idx = 1
|
|
|
|
outputs_current[idx] += '<li><b>%s</b>: %s</li>' % (output_name, value)
|
|
|
|
for i in range(2):
|
|
|
|
if len(outputs_current[i]) != 0:
|
|
|
|
if outputs_prev[i] == '':
|
|
|
|
outputs_prev[i] = outputs_current[i]
|
|
|
|
elif outputs_current[i] != outputs_prev[i]:
|
|
|
|
outputs_match[i] = False
|
|
|
|
|
|
|
|
for i in range(2):
|
|
|
|
if len(outputs_prev[i]) == 0:
|
|
|
|
outputs_match[i] = False
|
|
|
|
if not outputs_match[i]:
|
|
|
|
outputs_prev[i] = ''
|
|
|
|
|
|
|
|
if outputs_match[0] or outputs_match[1]:
|
2021-07-14 22:40:05 -03:00
|
|
|
result += '<table class="common">\n'
|
2017-04-12 11:59:40 -03:00
|
|
|
result += ' <thead>\n'
|
|
|
|
result += ' <tr><th>Common Outputs</th></tr>\n'
|
|
|
|
result += ' </thead>\n'
|
2021-07-14 22:40:05 -03:00
|
|
|
result += ' <tbody>\n'
|
|
|
|
result += '<tr>\n <td><ul>%s%s</ul></td>\n</tr>\n' % (outputs_prev[0], outputs_prev[1])
|
2017-04-12 11:59:40 -03:00
|
|
|
result += '</tbody></table>\n'
|
|
|
|
|
|
|
|
result += '</div>\n\n'
|
|
|
|
|
2021-07-14 22:40:05 -03:00
|
|
|
result += '<table class="generic">\n'
|
2017-04-11 05:40:54 -03:00
|
|
|
result += ' <thead>\n'
|
2017-04-18 05:11:57 -03:00
|
|
|
result += ' <tr><th>Name</th><th></th></tr>\n'
|
2017-04-11 05:40:54 -03:00
|
|
|
result += ' </thead>\n'
|
|
|
|
result += '<tbody>\n'
|
|
|
|
|
|
|
|
for param in group.GetParams():
|
2017-04-12 11:59:40 -03:00
|
|
|
if not self.IsExcluded(param, board):
|
2017-04-11 05:40:54 -03:00
|
|
|
#print("generating: {0} {1}".format(param.GetName(), excluded))
|
|
|
|
name = param.GetName()
|
|
|
|
airframe_id = param.GetId()
|
|
|
|
airframe_id_entry = '<p><code>SYS_AUTOSTART</code> = %s</p>' % (airframe_id)
|
|
|
|
maintainer = param.GetMaintainer()
|
|
|
|
maintainer_entry = ''
|
|
|
|
if maintainer != '':
|
2021-07-14 22:40:05 -03:00
|
|
|
maintainer_entry = 'Maintainer: %s' % (html.escape(maintainer))
|
2017-04-11 05:40:54 -03:00
|
|
|
url = param.GetFieldValue('url')
|
2017-07-03 01:22:12 -03:00
|
|
|
name_anchor='id="%s_%s_%s"' % (group.GetClass(),group.GetName(),name)
|
|
|
|
name_anchor=name_anchor.replace(' ','_').lower()
|
2017-04-11 05:40:54 -03:00
|
|
|
name_entry = name
|
|
|
|
if url != '':
|
|
|
|
name_entry = '<a href="%s">%s</a>' % (url, name)
|
|
|
|
outputs = '<ul>'
|
2017-04-18 05:11:57 -03:00
|
|
|
has_outputs = False
|
2017-04-12 11:59:40 -03:00
|
|
|
for output_name in param.GetOutputCodes():
|
|
|
|
value = param.GetOutputValue(output_name)
|
2017-04-11 05:40:54 -03:00
|
|
|
valstrs = value.split(";")
|
2017-04-12 11:59:40 -03:00
|
|
|
if output_name.lower().startswith('main'):
|
|
|
|
idx = 0
|
|
|
|
else:
|
|
|
|
idx = 1
|
|
|
|
if not outputs_match[idx]:
|
|
|
|
outputs += '<li><b>%s</b>: %s</li>' % (output_name, value)
|
2017-04-18 05:11:57 -03:00
|
|
|
has_outputs = True
|
2017-04-12 11:59:40 -03:00
|
|
|
|
2017-04-11 05:40:54 -03:00
|
|
|
for attrib in valstrs[1:]:
|
|
|
|
attribstrs = attrib.split(":")
|
|
|
|
# some airframes provide more info, like angle=60, direction=CCW
|
|
|
|
#print(output_name,value, attribstrs[0].strip(),attribstrs[1].strip())
|
|
|
|
outputs += '</ul>'
|
2017-04-18 05:11:57 -03:00
|
|
|
if has_outputs:
|
|
|
|
outputs_entry = '<p><b>Specific Outputs:</b>' + outputs + '</p>'
|
|
|
|
else:
|
|
|
|
outputs_entry = ''
|
|
|
|
|
2021-07-14 22:40:05 -03:00
|
|
|
result += ('<tr %s>\n <td>%s</td>\n <td>%s%s%s</td>\n</tr>\n' %
|
2017-07-03 01:22:12 -03:00
|
|
|
(name_anchor, name_entry, maintainer_entry, airframe_id_entry,
|
2017-04-18 05:11:57 -03:00
|
|
|
outputs_entry))
|
2017-04-11 05:40:54 -03:00
|
|
|
|
|
|
|
|
|
|
|
#Close the table.
|
|
|
|
result += '</tbody></table>\n\n'
|
|
|
|
|
|
|
|
self.output = result
|
|
|
|
|
2017-04-12 11:59:40 -03:00
|
|
|
def IsExcluded(self, param, board):
|
|
|
|
for code in param.GetArchCodes():
|
|
|
|
if "CONFIG_ARCH_BOARD_{0}".format(code) == board and param.GetArchValue(code) == "exclude":
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2017-04-11 05:40:54 -03:00
|
|
|
def Save(self, filename):
|
|
|
|
with codecs.open(filename, 'w', 'utf-8') as f:
|
|
|
|
f.write(self.output)
|