mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
Tools/px_process_airframes: add markdown output
This commit is contained in:
71
Tools/px4airframes/markdownout.py
Normal file
71
Tools/px4airframes/markdownout.py
Normal file
@@ -0,0 +1,71 @@
|
||||
from xml.sax.saxutils import escape
|
||||
import codecs
|
||||
|
||||
class MarkdownTablesOutput():
|
||||
def __init__(self, groups, board):
|
||||
result = ("# Airframes Reference\n"
|
||||
"> **Note** **This list is auto-generated from the source code** and contains the most recent airframes documentation.\n"
|
||||
"\n")
|
||||
|
||||
# TODO: describe meaning of green + blue color...
|
||||
|
||||
for group in groups:
|
||||
|
||||
result += '## %s\n\n' % group.GetName()
|
||||
|
||||
# Display an image of the frame
|
||||
image_name = group.GetImageName()
|
||||
if image_name != 'AirframeUnknown':
|
||||
result += '<img src="images/airframes/types/%s.svg" width="25%%" style="max-height: 150px;"/>\n' % (image_name)
|
||||
|
||||
result += '<table style="width: 100%; table-layout:fixed; font-size:1.5rem;">\n'
|
||||
result += ' <colgroup><col style="width: 30%"><col style="width: 30%"><col style="width: 40%"></colgroup>\n'
|
||||
result += ' <thead>\n'
|
||||
result += ' <tr><th>Name</th><th></th><th>Outputs</th></tr>\n'
|
||||
result += ' </thead>\n'
|
||||
result += '<tbody>\n'
|
||||
|
||||
for param in group.GetParams():
|
||||
|
||||
# check if there is an exclude tag for this airframe
|
||||
excluded = False
|
||||
for code in param.GetArchCodes():
|
||||
if "CONFIG_ARCH_BOARD_{0}".format(code) == board and param.GetArchValue(code) == "exclude":
|
||||
excluded = True
|
||||
|
||||
if not excluded:
|
||||
#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 != '':
|
||||
maintainer_entry = '<p>Maintainer: %s</p>' % (maintainer)
|
||||
url = param.GetFieldValue('url')
|
||||
name_entry = name
|
||||
if url != '':
|
||||
name_entry = '<a href="%s">%s</a>' % (url, name)
|
||||
outputs = '<ul>'
|
||||
for code in param.GetOutputCodes():
|
||||
value = param.GetOutputValue(code)
|
||||
valstrs = value.split(";")
|
||||
output_name = code
|
||||
outputs += '<li><b>%s</b>: %s</li>' % (output_name, value)
|
||||
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>'
|
||||
|
||||
result += '<tr>\n <td style="vertical-align: top;">%s</td>\n <td style="vertical-align: top;">%s%s</td>\n <td style="vertical-align: top;">%s</td>\n</tr>\n' % (name_entry, maintainer_entry, airframe_id_entry, outputs)
|
||||
|
||||
|
||||
#Close the table.
|
||||
result += '</tbody></table>\n\n'
|
||||
|
||||
self.output = result
|
||||
|
||||
def Save(self, filename):
|
||||
with codecs.open(filename, 'w', 'utf-8') as f:
|
||||
f.write(self.output)
|
||||
@@ -102,6 +102,14 @@ class Parameter(object):
|
||||
"min": 5,
|
||||
"max": 4,
|
||||
"unit": 3,
|
||||
"AUX1": -10,
|
||||
"AUX2": -10,
|
||||
"AUX3": -10,
|
||||
"AUX4": -10,
|
||||
"AUX5": -10,
|
||||
"AUX6": -10,
|
||||
"AUX7": -10,
|
||||
"AUX8": -10,
|
||||
# all others == 0 (sorted alphabetically)
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ from __future__ import print_function
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
from px4airframes import srcscanner, srcparser, xmlout, rcout
|
||||
from px4airframes import srcscanner, srcparser, xmlout, rcout, markdownout
|
||||
|
||||
def main():
|
||||
# Parse command line arguments
|
||||
@@ -61,6 +61,12 @@ def main():
|
||||
metavar="FILENAME",
|
||||
help="Create XML file"
|
||||
" (default FILENAME: airframes.xml)")
|
||||
parser.add_argument("-m", "--markdown",
|
||||
nargs='?',
|
||||
const="airframes.md",
|
||||
metavar="FILENAME",
|
||||
help="Create Markdown file"
|
||||
" (default FILENAME: airframes.md)")
|
||||
parser.add_argument("-s", "--start-script",
|
||||
nargs='?',
|
||||
const="rc.autostart",
|
||||
@@ -75,7 +81,7 @@ def main():
|
||||
args = parser.parse_args()
|
||||
|
||||
# Check for valid command
|
||||
if not (args.xml) and not (args.start_script):
|
||||
if not (args.xml) and not (args.start_script) and not args.markdown:
|
||||
print("Error: You need to specify at least one output method!\n")
|
||||
parser.print_usage()
|
||||
sys.exit(1)
|
||||
@@ -99,6 +105,12 @@ def main():
|
||||
out = xmlout.XMLOutput(param_groups, args.board)
|
||||
out.Save(args.xml)
|
||||
|
||||
# Output to markdown file
|
||||
if args.markdown:
|
||||
if args.verbose: print("Creating markdown file " + args.markdown)
|
||||
out = markdownout.MarkdownTablesOutput(param_groups, args.board)
|
||||
out.Save(args.markdown)
|
||||
|
||||
if args.start_script:
|
||||
if args.verbose: print("Creating start script " + args.start_script)
|
||||
out = rcout.RCOutput(param_groups, args.board)
|
||||
|
||||
Reference in New Issue
Block a user