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
|
2022-07-31 22:39:39 -03:00
|
|
|
**This list is [auto-generated](https://github.com/PX4/PX4-Autopilot/blob/main/Tools/px4airframes/markdownout.py) from the source code** using the build command: `make airframe_metadata`.
|
2021-07-14 22:40:05 -03:00
|
|
|
:::
|
|
|
|
|
|
|
|
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>
|
2021-07-31 05:34:25 -03:00
|
|
|
div.frame_common table, div.frame_common table {
|
2021-07-14 22:40:05 -03:00
|
|
|
display: table;
|
|
|
|
table-layout: fixed;
|
|
|
|
margin-bottom: 5px;
|
|
|
|
}
|
2021-07-31 05:34:25 -03:00
|
|
|
|
|
|
|
div.frame_common table {
|
2021-10-01 14:06:15 -03:00
|
|
|
float: right;
|
2021-07-14 22:40:05 -03:00
|
|
|
width: 70%;
|
|
|
|
}
|
2021-07-31 05:34:25 -03:00
|
|
|
|
|
|
|
div.frame_common img {
|
|
|
|
max-height: 180px;
|
|
|
|
width: 29%;
|
|
|
|
padding-top: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
div.frame_variant table {
|
2021-07-14 22:40:05 -03:00
|
|
|
width: 100%;
|
|
|
|
}
|
2021-07-31 05:34:25 -03:00
|
|
|
|
|
|
|
div.frame_variant th:nth-child(1) {
|
2021-07-14 22:40:05 -03:00
|
|
|
width: 30%;
|
|
|
|
}
|
|
|
|
|
2021-07-31 05:34:25 -03:00
|
|
|
div.frame_variant tr > * {
|
2021-07-14 22:40:05 -03:00
|
|
|
vertical-align : top;
|
|
|
|
}
|
2021-07-31 05:34:25 -03:00
|
|
|
|
|
|
|
div.frame_variant td, div.frame_variant th {
|
2021-07-14 22:40:05 -03:00
|
|
|
text-align : left;
|
|
|
|
}
|
|
|
|
</style>\n\n"""
|
2022-05-20 08:10:42 -03:00
|
|
|
|
2017-06-27 02:42:30 -03:00
|
|
|
type_set = set()
|
2022-05-20 08:10:42 -03:00
|
|
|
|
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
|
|
|
|
2022-05-20 08:10:42 -03:00
|
|
|
result += '### %s\n\n' % group.GetType()
|
2017-04-11 05:40:54 -03:00
|
|
|
|
|
|
|
# Display an image of the frame
|
|
|
|
image_name = group.GetImageName()
|
2021-07-31 05:34:25 -03:00
|
|
|
result += '<div class="frame_common">\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
|
2021-12-17 06:36:37 -04:00
|
|
|
all_outputs = {}
|
2022-05-20 08:10:42 -03:00
|
|
|
num_configs = len(group.GetAirframes())
|
|
|
|
for airframe in group.GetAirframes():
|
|
|
|
if not self.IsExcluded(airframe, board):
|
|
|
|
for output_name in airframe.GetOutputCodes():
|
|
|
|
value = airframe.GetOutputValue(output_name)
|
2021-12-17 06:36:37 -04:00
|
|
|
key_value_pair = (output_name, value)
|
|
|
|
if key_value_pair not in all_outputs:
|
|
|
|
all_outputs[key_value_pair] = 0
|
|
|
|
all_outputs[key_value_pair] += 1
|
|
|
|
has_common_outputs = any(all_outputs[k] == num_configs for k in all_outputs)
|
|
|
|
|
|
|
|
if has_common_outputs:
|
|
|
|
outputs_common = ''.join(['<li><b>{:}</b>: {:}</li>'.format(k[0], k[1]) \
|
|
|
|
for k in all_outputs if all_outputs[k] == num_configs])
|
2021-07-31 05:34:25 -03:00
|
|
|
result += '<table>\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'
|
2021-12-17 06:36:37 -04:00
|
|
|
result += '<tr>\n <td><ul>%s</ul></td>\n</tr>\n' % (outputs_common)
|
2017-04-12 11:59:40 -03:00
|
|
|
result += '</tbody></table>\n'
|
|
|
|
|
|
|
|
result += '</div>\n\n'
|
|
|
|
|
2021-07-31 05:34:25 -03:00
|
|
|
result += '<div class="frame_variant">\n'
|
|
|
|
result += '<table>\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'
|
|
|
|
|
2022-05-20 08:10:42 -03:00
|
|
|
for airframe in group.GetAirframes():
|
|
|
|
if not self.IsExcluded(airframe, board):
|
|
|
|
name = airframe.GetName()
|
|
|
|
airframe_id = airframe.GetId()
|
2017-04-11 05:40:54 -03:00
|
|
|
airframe_id_entry = '<p><code>SYS_AUTOSTART</code> = %s</p>' % (airframe_id)
|
2022-05-20 08:10:42 -03:00
|
|
|
maintainer = airframe.GetMaintainer()
|
2017-04-11 05:40:54 -03:00
|
|
|
maintainer_entry = ''
|
|
|
|
if maintainer != '':
|
2021-07-14 22:40:05 -03:00
|
|
|
maintainer_entry = 'Maintainer: %s' % (html.escape(maintainer))
|
2022-05-20 08:10:42 -03:00
|
|
|
url = airframe.GetFieldValue('url')
|
|
|
|
name_anchor='%s_%s_%s' % (group.GetClass(),group.GetType(),name)
|
2017-07-03 01:22:12 -03:00
|
|
|
name_anchor=name_anchor.replace(' ','_').lower()
|
2021-07-14 22:54:27 -03:00
|
|
|
name_anchor=name_anchor.replace('"','_').lower()
|
|
|
|
name_anchor='id="%s"' % name_anchor
|
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
|
2022-05-20 08:10:42 -03:00
|
|
|
for output_name in airframe.GetOutputCodes():
|
|
|
|
value = airframe.GetOutputValue(output_name)
|
2017-04-11 05:40:54 -03:00
|
|
|
valstrs = value.split(";")
|
2021-12-17 06:36:37 -04:00
|
|
|
key_value_pair = (output_name, value)
|
|
|
|
if all_outputs[key_value_pair] < num_configs:
|
2017-04-12 11:59:40 -03:00
|
|
|
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.
|
2021-07-31 05:34:25 -03:00
|
|
|
result += '</tbody>\n</table>\n</div>\n\n'
|
2017-04-11 05:40:54 -03:00
|
|
|
|
|
|
|
self.output = result
|
|
|
|
|
2022-05-20 08:10:42 -03:00
|
|
|
def IsExcluded(self, airframe, board):
|
|
|
|
for code in airframe.GetArchCodes():
|
|
|
|
if "CONFIG_ARCH_BOARD_{0}".format(code) == board and airframe.GetArchValue(code) == "exclude":
|
2017-04-12 11:59:40 -03:00
|
|
|
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)
|