diff --git a/Tools/px4airframes/__init__.py b/Tools/px4airframes/__init__.py index 3a9f1e2c6d..43e82d2643 100644 --- a/Tools/px4airframes/__init__.py +++ b/Tools/px4airframes/__init__.py @@ -1 +1 @@ -__all__ = ["srcscanner", "srcparser", "xmlout", "dokuwikiout", "dokuwikirpc"] \ No newline at end of file +__all__ = ["srcscanner", "srcparser", "xmlout", "rcout"] \ No newline at end of file diff --git a/Tools/px4airframes/rcout.py b/Tools/px4airframes/rcout.py new file mode 100644 index 0000000000..83bd047560 --- /dev/null +++ b/Tools/px4airframes/rcout.py @@ -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) diff --git a/Tools/px4airframes/srcparser.py b/Tools/px4airframes/srcparser.py index 130b0f24cf..699a2cdc3b 100644 --- a/Tools/px4airframes/srcparser.py +++ b/Tools/px4airframes/srcparser.py @@ -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: diff --git a/Tools/px4airframes/xmlout.py b/Tools/px4airframes/xmlout.py index a70e5dfbd7..427b1090a2 100644 --- a/Tools/px4airframes/xmlout.py +++ b/Tools/px4airframes/xmlout.py @@ -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") diff --git a/Tools/px_process_airframes.py b/Tools/px_process_airframes.py index 50aaa699ef..7d7d28a2b2 100755 --- a/Tools/px_process_airframes.py +++ b/Tools/px_process_airframes.py @@ -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!")