Airframe generator: Also generate autostart listing

This commit is contained in:
Lorenz Meier 2015-07-31 12:10:31 +02:00
parent ac0e645ab6
commit fde0c65d77
5 changed files with 75 additions and 6 deletions

View File

@ -1 +1 @@
__all__ = ["srcscanner", "srcparser", "xmlout", "dokuwikiout", "dokuwikirpc"]
__all__ = ["srcscanner", "srcparser", "xmlout", "rcout"]

View File

@ -0,0 +1,55 @@
from xml.sax.saxutils import escape
import codecs
class RCOutput():
def __init__(self, groups, board):
result = ( "#\n"
"#\n"
"# THIS FILE IS AUTO-GENERATED. DO NOT EDIT!\n"
"#\n"
"#\n"
"# SYS_AUTOSTART = 0 means no autostart (default)\n"
"#\n"
"# AUTOSTART PARTITION:\n"
"# 0 .. 999 Reserved (historical)\n"
"# 1000 .. 1999 Simulation setups\n"
"# 2000 .. 2999 Standard planes\n"
"# 3000 .. 3999 Flying wing\n"
"# 4000 .. 4999 Quadrotor x\n"
"# 5000 .. 5999 Quadrotor +\n"
"# 6000 .. 6999 Hexarotor x\n"
"# 7000 .. 7999 Hexarotor +\n"
"# 8000 .. 8999 Octorotor x\n"
"# 9000 .. 9999 Octorotor +\n"
"# 10000 .. 10999 Quadrotor Wide arm / H frame\n"
"# 11000 .. 11999 Hexa Cox\n"
"# 12000 .. 12999 Octo Cox\n"
"# 13000 .. 13999 VTOL\n"
"# 14000 .. 14999 Tri Y\n"
"\n")
for group in groups:
result += "# GROUP: %s \n\n" % group.GetName()
for param in group.GetParams():
name = param.GetName()
path = param.GetPath().rsplit('/', 1)[1]
id_val = param.GetId()
name = param.GetFieldValue("short_desc")
long_desc = param.GetFieldValue("long_desc")
result += "#\n"
result += "# %s\n" % name
result += "if param compare SYS_AUTOSTART %s\n" % id_val
result += "then\n"
result += " sh /etc/init.d/%s\n" % path
result += "fi\n"
#if long_desc is not None:
# result += "# %s\n" % long_desc
result += "\n"
result += "\n"
self.output = result;
def Save(self, filename):
with codecs.open(filename, 'w', 'utf-8') as f:
f.write(self.output)

View File

@ -46,14 +46,18 @@ class Parameter(object):
# all others == 0 (sorted alphabetically)
}
def __init__(self, name, airframe_type, airframe_id, maintainer):
def __init__(self, path, name, airframe_type, airframe_id, maintainer):
self.fields = {}
self.outputs = {}
self.path = path
self.name = name
self.type = airframe_type
self.id = airframe_id
self.maintainer = maintainer
def GetPath(self):
return self.path
def GetName(self):
return self.name
@ -259,7 +263,7 @@ class SourceParser(object):
return False
# We already know this is an airframe config, so add it
param = Parameter(airframe_name, airframe_type, airframe_id, maintainer)
param = Parameter(path, airframe_name, airframe_type, airframe_id, maintainer)
# Done with file, store
for tag in tags:

View File

@ -50,7 +50,7 @@ class XMLOutput():
elif (group.GetName() == "Simulation"):
xml_group.attrib["image"] = "AirframeSimulation.png"
else:
xml_group.attrib["image"] = "AirframeStandardPlane.png"
xml_group.attrib["image"] = ""
for param in group.GetParams():
if (last_param_name == param.GetName() and not board_specific_param_set) or last_param_name != param.GetName():
xml_param = ET.SubElement(xml_group, "airframe")

View File

@ -46,7 +46,7 @@ from __future__ import print_function
import sys
import os
import argparse
from px4airframes import srcscanner, srcparser, xmlout
from px4airframes import srcscanner, srcparser, xmlout, rcout
def main():
# Parse command line arguments
@ -61,6 +61,11 @@ def main():
metavar="FILENAME",
help="Create XML file"
" (default FILENAME: airframes.xml)")
parser.add_argument("-s", "--start-script",
nargs='?',
const="rc.autostart",
metavar="FILENAME",
help="Create start script file")
parser.add_argument("-b", "--board",
nargs='?',
const="",
@ -69,7 +74,7 @@ def main():
args = parser.parse_args()
# Check for valid command
if not (args.xml):
if not (args.xml) and not (args.start_script):
print("Error: You need to specify at least one output method!\n")
parser.print_usage()
sys.exit(1)
@ -93,6 +98,11 @@ def main():
out = xmlout.XMLOutput(param_groups, args.board)
out.Save(args.xml)
if args.start_script:
print("Creating start script " + args.start_script)
out = rcout.RCOutput(param_groups, args.board)
out.Save(args.start_script)
print("All done!")