2015-07-31 07:10:31 -03:00
|
|
|
from xml.sax.saxutils import escape
|
|
|
|
import codecs
|
2015-10-15 15:41:49 -03:00
|
|
|
import os
|
2015-07-31 07:10:31 -03:00
|
|
|
|
|
|
|
class RCOutput():
|
2022-05-20 08:10:42 -03:00
|
|
|
"""
|
|
|
|
Generates RC scripts for the airframes
|
|
|
|
"""
|
2019-07-20 15:09:42 -03:00
|
|
|
def __init__(self, groups, board, post_start=False):
|
2016-12-20 13:13:07 -04:00
|
|
|
|
2015-07-31 07:10:31 -03:00
|
|
|
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"
|
2020-01-27 11:21:52 -04:00
|
|
|
"# 17000 .. 17999 Autogyro\n"
|
2015-07-31 07:10:31 -03:00
|
|
|
"\n")
|
2019-07-31 02:37:40 -03:00
|
|
|
result += "\n"
|
|
|
|
result += "set AIRFRAME none\n"
|
|
|
|
result += "\n"
|
2015-07-31 07:10:31 -03:00
|
|
|
for group in groups:
|
2022-05-20 08:10:42 -03:00
|
|
|
result += "# GROUP: %s\n\n" % group.GetType()
|
|
|
|
for airframe in group.GetAirframes():
|
2016-12-20 13:13:07 -04:00
|
|
|
excluded = False
|
2022-05-20 08:10:42 -03:00
|
|
|
for code in airframe.GetArchCodes():
|
|
|
|
if "{0}".format(code) == board and airframe.GetArchValue(code) == "exclude":
|
2016-12-20 13:13:07 -04:00
|
|
|
excluded = True
|
|
|
|
if excluded:
|
|
|
|
continue
|
2019-07-20 15:09:42 -03:00
|
|
|
|
|
|
|
if post_start:
|
|
|
|
# Path to post-start sript
|
2022-05-20 08:10:42 -03:00
|
|
|
path = airframe.GetPostPath()
|
2019-07-20 15:09:42 -03:00
|
|
|
else:
|
|
|
|
# Path to start script
|
2022-05-20 08:10:42 -03:00
|
|
|
path = airframe.GetPath()
|
2019-07-20 15:09:42 -03:00
|
|
|
|
|
|
|
if not path:
|
|
|
|
continue
|
|
|
|
|
|
|
|
path = os.path.split(path)[1]
|
|
|
|
|
2022-05-20 08:10:42 -03:00
|
|
|
id_val = airframe.GetId()
|
|
|
|
name = airframe.GetFieldValue("short_desc")
|
|
|
|
long_desc = airframe.GetFieldValue("long_desc")
|
2015-07-31 07:10:31 -03:00
|
|
|
|
|
|
|
result += "#\n"
|
2022-05-20 08:10:42 -03:00
|
|
|
result += "# %s\n" % airframe.GetName()
|
2015-07-31 07:10:31 -03:00
|
|
|
result += "if param compare SYS_AUTOSTART %s\n" % id_val
|
|
|
|
result += "then\n"
|
2019-07-31 02:37:40 -03:00
|
|
|
result += "\tset AIRFRAME %s\n" % path
|
2015-07-31 07:10:31 -03:00
|
|
|
result += "fi\n"
|
|
|
|
|
|
|
|
#if long_desc is not None:
|
|
|
|
# result += "# %s\n" % long_desc
|
|
|
|
result += "\n"
|
|
|
|
|
|
|
|
result += "\n"
|
2019-07-31 02:37:40 -03:00
|
|
|
result += "\n"
|
|
|
|
result += "if [ ${AIRFRAME} != none ]\n"
|
|
|
|
result += "then\n"
|
2021-11-22 12:17:48 -04:00
|
|
|
result += "\techo \"Loading airframe: /etc/init.d/airframes/${AIRFRAME}\"\n"
|
2020-06-22 17:53:01 -03:00
|
|
|
result += "\t. /etc/init.d/airframes/${AIRFRAME}\n"
|
2019-07-31 02:37:40 -03:00
|
|
|
if not post_start:
|
|
|
|
result += "else\n"
|
2022-08-17 18:45:29 -03:00
|
|
|
result += "\techo \"ERROR [init] No file matches SYS_AUTOSTART value found in : /etc/init.d/airframes\"\n"
|
2019-12-25 19:04:50 -04:00
|
|
|
# Reset the configuration
|
|
|
|
result += "\tparam set SYS_AUTOSTART 0\n"
|
2019-07-31 02:37:40 -03:00
|
|
|
result += "\ttone_alarm ${TUNE_ERR}\n"
|
|
|
|
result += "fi\n"
|
|
|
|
result += "unset AIRFRAME"
|
2019-07-20 15:09:42 -03:00
|
|
|
self.output = result
|
2015-07-31 07:10:31 -03:00
|
|
|
|
|
|
|
def Save(self, filename):
|
|
|
|
with codecs.open(filename, 'w', 'utf-8') as f:
|
|
|
|
f.write(self.output)
|