2015-07-29 14:13:28 -03:00
|
|
|
import sys
|
|
|
|
import re
|
2015-10-15 15:41:49 -03:00
|
|
|
import os
|
2015-07-29 14:13:28 -03:00
|
|
|
|
2022-05-20 08:10:42 -03:00
|
|
|
class AirframeGroup(object):
|
2015-07-29 14:13:28 -03:00
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
Airframe group
|
|
|
|
|
|
|
|
type: specific vehicle type (e.g. VTOL Tiltrotor, VTOL Quadrotor, etc.)
|
|
|
|
class: vehicle class (e.g. Multicopter, Fixed Wing, etc.)
|
2015-07-29 14:13:28 -03:00
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
def __init__(self, type, af_class):
|
|
|
|
self.type = type
|
2017-06-27 08:32:39 -03:00
|
|
|
self.af_class = af_class
|
2022-05-20 08:10:42 -03:00
|
|
|
self.airframes = []
|
2015-07-29 14:13:28 -03:00
|
|
|
|
2017-06-27 02:42:30 -03:00
|
|
|
|
2022-05-20 08:10:42 -03:00
|
|
|
def AddAirframe(self, airframe):
|
2015-07-29 14:13:28 -03:00
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
Add airframe to the airframe group
|
2015-07-29 14:13:28 -03:00
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
self.airframes.append(airframe)
|
2015-07-29 14:13:28 -03:00
|
|
|
|
2022-05-20 08:10:42 -03:00
|
|
|
def GetType(self):
|
2015-07-29 14:13:28 -03:00
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
Get airframe group's vehicle type
|
|
|
|
|
|
|
|
e.g. VTOL Tiltrotor, VTOL Quadrotor, etc.
|
2015-07-29 14:13:28 -03:00
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
return self.type
|
2015-07-29 14:13:28 -03:00
|
|
|
|
2017-06-27 08:32:39 -03:00
|
|
|
def GetClass(self):
|
2017-06-27 02:42:30 -03:00
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
Get airframe group's vehicle class
|
|
|
|
|
|
|
|
e.g. Multicopter, Fixed Wing, etc.
|
2017-06-27 02:42:30 -03:00
|
|
|
"""
|
2017-06-27 08:32:39 -03:00
|
|
|
return self.af_class
|
2019-07-20 15:09:42 -03:00
|
|
|
|
2017-04-11 05:40:14 -03:00
|
|
|
def GetImageName(self):
|
|
|
|
"""
|
|
|
|
Get parameter group image base name (w/o extension)
|
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
if (self.type == "Standard Plane"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "Plane"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Flying Wing"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "FlyingWing"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Quadrotor x"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "QuadRotorX"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Quadrotor +"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "QuadRotorPlus"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Hexarotor x"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "HexaRotorX"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Hexarotor +"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "HexaRotorPlus"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Octorotor +"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "OctoRotorPlus"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Octorotor x"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "OctoRotorX"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Octorotor Coaxial"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "OctoRotorXCoaxial"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Octo Coax Wide"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "OctoRotorXCoaxial"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Quadrotor Wide"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "QuadRotorWide"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Quadrotor H"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "QuadRotorH"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Dodecarotor cox"):
|
2017-08-08 06:59:00 -03:00
|
|
|
return "DodecaRotorXCoaxial"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Simulation"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "AirframeSimulation"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Plane A-Tail"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "PlaneATail"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Plane V-Tail"):
|
2018-10-17 20:13:11 -03:00
|
|
|
return "PlaneVTail"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "VTOL Duo Tailsitter"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "VTOLDuoRotorTailSitter"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Standard VTOL"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "VTOLPlane"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "VTOL Quad Tailsitter"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "VTOLQuadRotorTailSitter"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "VTOL Tiltrotor"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "VTOLTiltRotor"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "VTOL Octoplane"):
|
2019-06-22 09:13:29 -03:00
|
|
|
return "VTOLPlaneOcto"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Coaxial Helicopter"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "HelicopterCoaxial"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Helicopter"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "Helicopter"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Hexarotor Coaxial"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "Y6B"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Y6A"):
|
2017-04-18 05:11:57 -03:00
|
|
|
return "Y6A"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Tricopter Y-"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "YMinus"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Tricopter Y+"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "YPlus"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Autogyro"):
|
2020-01-27 11:21:52 -04:00
|
|
|
return "Autogyro"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Airship"):
|
2020-08-10 03:52:51 -03:00
|
|
|
return "Airship"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Rover"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "Rover"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Boat"):
|
2017-04-11 05:40:14 -03:00
|
|
|
return "Boat"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Balloon"):
|
2020-12-07 09:43:12 -04:00
|
|
|
return "Balloon"
|
2022-05-20 08:10:42 -03:00
|
|
|
elif (self.type == "Vectored 6 DOF UUV"):
|
2021-04-21 05:18:25 -03:00
|
|
|
return "Vectored6DofUUV"
|
2017-04-11 05:40:14 -03:00
|
|
|
return "AirframeUnknown"
|
|
|
|
|
2022-05-20 08:10:42 -03:00
|
|
|
def GetAirframes(self):
|
2015-07-29 14:13:28 -03:00
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
Returns the parsed list of airframes objects. Note that returned
|
|
|
|
object is not a copy. Modifications affect state of the parser.
|
2015-07-29 14:13:28 -03:00
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
return sorted(self.airframes, key=lambda x: x.GetId())
|
2017-09-25 12:17:50 -03:00
|
|
|
|
2022-05-20 08:10:42 -03:00
|
|
|
class Airframe(object):
|
2015-07-29 14:13:28 -03:00
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
Single Airframe definition
|
2015-07-29 14:13:28 -03:00
|
|
|
"""
|
|
|
|
|
|
|
|
# Define sorting order of the fields
|
|
|
|
priority = {
|
|
|
|
"board": 9,
|
|
|
|
"short_desc": 8,
|
|
|
|
"long_desc": 7,
|
|
|
|
"min": 5,
|
|
|
|
"max": 4,
|
|
|
|
"unit": 3,
|
2017-04-11 05:40:54 -03:00
|
|
|
"AUX1": -10,
|
|
|
|
"AUX2": -10,
|
|
|
|
"AUX3": -10,
|
|
|
|
"AUX4": -10,
|
|
|
|
"AUX5": -10,
|
|
|
|
"AUX6": -10,
|
|
|
|
"AUX7": -10,
|
|
|
|
"AUX8": -10,
|
2015-07-29 14:13:28 -03:00
|
|
|
# all others == 0 (sorted alphabetically)
|
|
|
|
}
|
|
|
|
|
2019-07-20 15:09:42 -03:00
|
|
|
def __init__(self, path, post_path, name, airframe_type, airframe_class, airframe_id, maintainer):
|
2015-07-29 14:13:28 -03:00
|
|
|
self.fields = {}
|
|
|
|
self.outputs = {}
|
2016-12-20 13:13:07 -04:00
|
|
|
self.archs = {}
|
2015-07-31 07:10:31 -03:00
|
|
|
self.path = path
|
2019-07-20 15:09:42 -03:00
|
|
|
self.post_path = post_path
|
2015-07-29 14:13:28 -03:00
|
|
|
self.name = name
|
|
|
|
self.type = airframe_type
|
2017-06-27 03:44:53 -03:00
|
|
|
self.af_class = airframe_class
|
2015-07-29 14:13:28 -03:00
|
|
|
self.id = airframe_id
|
|
|
|
self.maintainer = maintainer
|
|
|
|
|
2015-07-31 07:10:31 -03:00
|
|
|
def GetPath(self):
|
2019-07-22 07:02:51 -03:00
|
|
|
"""
|
|
|
|
Get path to airframe startup script
|
|
|
|
"""
|
2015-07-31 07:10:31 -03:00
|
|
|
return self.path
|
|
|
|
|
2019-07-20 15:09:42 -03:00
|
|
|
def GetPostPath(self):
|
2019-07-22 07:02:51 -03:00
|
|
|
"""
|
|
|
|
Get path to airframe post startup script
|
|
|
|
"""
|
2019-07-20 15:09:42 -03:00
|
|
|
return self.post_path
|
|
|
|
|
2015-07-29 14:13:28 -03:00
|
|
|
def GetName(self):
|
2019-07-22 07:02:51 -03:00
|
|
|
"""
|
|
|
|
Get airframe name
|
|
|
|
"""
|
2015-07-29 14:13:28 -03:00
|
|
|
return self.name
|
|
|
|
|
|
|
|
def GetType(self):
|
2019-07-22 07:02:51 -03:00
|
|
|
"""
|
|
|
|
Get airframe type
|
|
|
|
"""
|
2015-07-29 14:13:28 -03:00
|
|
|
return self.type
|
|
|
|
|
2017-06-27 03:44:53 -03:00
|
|
|
def GetClass(self):
|
2019-07-22 07:02:51 -03:00
|
|
|
"""
|
|
|
|
Get airframe class
|
|
|
|
"""
|
2017-06-27 03:44:53 -03:00
|
|
|
return self.af_class
|
|
|
|
|
2015-07-29 14:13:28 -03:00
|
|
|
def GetId(self):
|
2019-07-22 07:02:51 -03:00
|
|
|
"""
|
|
|
|
Get airframe id
|
|
|
|
"""
|
2015-07-29 14:13:28 -03:00
|
|
|
return self.id
|
|
|
|
|
|
|
|
def GetMaintainer(self):
|
2019-07-22 07:02:51 -03:00
|
|
|
"""
|
|
|
|
Get airframe maintainer
|
|
|
|
"""
|
2015-07-29 14:13:28 -03:00
|
|
|
return self.maintainer
|
|
|
|
|
|
|
|
def SetField(self, code, value):
|
|
|
|
"""
|
|
|
|
Set named field value
|
|
|
|
"""
|
|
|
|
self.fields[code] = value
|
|
|
|
|
|
|
|
def SetOutput(self, code, value):
|
|
|
|
"""
|
|
|
|
Set named output value
|
|
|
|
"""
|
|
|
|
self.outputs[code] = value
|
|
|
|
|
2016-12-20 13:13:07 -04:00
|
|
|
def SetArch(self, code, value):
|
|
|
|
"""
|
|
|
|
Set named arch value
|
|
|
|
"""
|
|
|
|
self.archs[code] = value
|
|
|
|
|
2015-07-29 14:13:28 -03:00
|
|
|
def GetFieldCodes(self):
|
|
|
|
"""
|
|
|
|
Return list of existing field codes in convenient order
|
|
|
|
"""
|
|
|
|
keys = self.fields.keys()
|
|
|
|
keys = sorted(keys)
|
|
|
|
keys = sorted(keys, key=lambda x: self.priority.get(x, 0), reverse=True)
|
|
|
|
return keys
|
|
|
|
|
|
|
|
def GetFieldValue(self, code):
|
|
|
|
"""
|
|
|
|
Return value of the given field code or None if not found.
|
|
|
|
"""
|
|
|
|
fv = self.fields.get(code)
|
|
|
|
if not fv:
|
|
|
|
# required because python 3 sorted does not accept None
|
|
|
|
return ""
|
|
|
|
return self.fields.get(code)
|
|
|
|
|
|
|
|
def GetOutputCodes(self):
|
|
|
|
"""
|
|
|
|
Return list of existing output codes in convenient order
|
|
|
|
"""
|
|
|
|
keys = self.outputs.keys()
|
|
|
|
keys = sorted(keys)
|
|
|
|
keys = sorted(keys, key=lambda x: self.priority.get(x, 0), reverse=True)
|
|
|
|
return keys
|
|
|
|
|
|
|
|
def GetOutputValue(self, code):
|
|
|
|
"""
|
|
|
|
Return value of the given output code or None if not found.
|
|
|
|
"""
|
|
|
|
fv = self.outputs.get(code)
|
|
|
|
if not fv:
|
|
|
|
# required because python 3 sorted does not accept None
|
|
|
|
return ""
|
|
|
|
return self.outputs.get(code)
|
|
|
|
|
2016-12-20 13:13:07 -04:00
|
|
|
def GetArchCodes(self):
|
|
|
|
"""
|
|
|
|
Return list of existing arch codes in convenient order
|
|
|
|
"""
|
|
|
|
keys = self.archs.keys()
|
|
|
|
keys = sorted(keys)
|
|
|
|
keys = sorted(keys, key=lambda x: self.priority.get(x, 0), reverse=True)
|
|
|
|
return keys
|
|
|
|
|
|
|
|
def GetArchValue(self, code):
|
|
|
|
"""
|
|
|
|
Return value of the given arch code or None if not found.
|
|
|
|
"""
|
|
|
|
fv = self.archs.get(code)
|
|
|
|
if not fv:
|
|
|
|
# required because python 3 sorted does not accept None
|
|
|
|
return ""
|
|
|
|
return self.archs.get(code)
|
|
|
|
|
2015-07-29 14:13:28 -03:00
|
|
|
class SourceParser(object):
|
|
|
|
"""
|
|
|
|
Parses provided data and stores all found parameters internally.
|
|
|
|
"""
|
|
|
|
|
|
|
|
re_split_lines = re.compile(r'[\r\n]+')
|
|
|
|
re_comment_start = re.compile(r'^\#\s')
|
|
|
|
re_comment_content = re.compile(r'^\#\s*(.*)')
|
|
|
|
re_comment_tag = re.compile(r'@([a-zA-Z][a-zA-Z0-9_]*)\s*(.*)')
|
|
|
|
re_comment_end = re.compile(r'(.*?)\s*\#\n/')
|
|
|
|
re_cut_type_specifier = re.compile(r'[a-z]+$')
|
|
|
|
re_is_a_number = re.compile(r'^-?[0-9\.]')
|
|
|
|
re_remove_dots = re.compile(r'\.+$')
|
|
|
|
re_remove_carriage_return = re.compile('\n+')
|
|
|
|
|
2020-02-29 01:09:58 -04:00
|
|
|
valid_tags = set(["url", "maintainer", "output", "arch", "name", "type", "desc"])
|
2015-07-29 14:13:28 -03:00
|
|
|
|
|
|
|
# Order of parameter groups
|
|
|
|
priority = {
|
|
|
|
# All other groups = 0 (sort alphabetically)
|
|
|
|
"Miscellaneous": -10
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self):
|
2022-05-20 08:10:42 -03:00
|
|
|
self.airframe_groups = {}
|
2015-07-29 14:13:28 -03:00
|
|
|
|
|
|
|
def GetSupportedExtensions(self):
|
|
|
|
"""
|
|
|
|
Returns list of supported file extensions that can be parsed by this
|
|
|
|
parser. The parser uses any extension.
|
|
|
|
"""
|
2015-10-06 10:15:08 -03:00
|
|
|
return ["", ".hil"]
|
2015-07-29 14:13:28 -03:00
|
|
|
|
|
|
|
def Parse(self, path, contents):
|
|
|
|
"""
|
|
|
|
Incrementally parse program contents and append all found airframes
|
|
|
|
to the list.
|
|
|
|
"""
|
|
|
|
|
|
|
|
airframe_id = None
|
2015-10-15 15:41:49 -03:00
|
|
|
airframe_id = os.path.split(path)[1].split('_',1)[0]
|
2015-07-29 14:13:28 -03:00
|
|
|
|
|
|
|
# Skip if not numeric
|
|
|
|
if (not self.IsNumber(airframe_id)):
|
|
|
|
return True
|
|
|
|
|
|
|
|
# This code is essentially a comment-parsing grammar. "state"
|
|
|
|
# represents parser state. It contains human-readable state
|
|
|
|
# names.
|
|
|
|
state = None
|
|
|
|
tags = {}
|
|
|
|
outputs = {}
|
2016-12-20 13:13:07 -04:00
|
|
|
archs = {}
|
2015-07-29 14:13:28 -03:00
|
|
|
for line in self.re_split_lines.split(contents):
|
|
|
|
line = line.strip()
|
|
|
|
# Ignore empty lines
|
|
|
|
if line == "":
|
|
|
|
continue
|
|
|
|
if state is None and self.re_comment_start.match(line):
|
|
|
|
state = "wait-short"
|
|
|
|
short_desc = None
|
|
|
|
long_desc = None
|
|
|
|
if state is not None and state != "comment-processed":
|
|
|
|
m = self.re_comment_end.search(line)
|
|
|
|
if m:
|
|
|
|
line = m.group(1)
|
|
|
|
last_comment_line = True
|
|
|
|
else:
|
|
|
|
last_comment_line = False
|
|
|
|
m = self.re_comment_content.match(line)
|
|
|
|
if m:
|
|
|
|
comment_content = m.group(1)
|
|
|
|
if comment_content == "":
|
|
|
|
# When short comment ends with empty comment line,
|
|
|
|
# start waiting for the next part - long comment.
|
|
|
|
if state == "wait-short-end":
|
|
|
|
state = "wait-long"
|
|
|
|
else:
|
|
|
|
m = self.re_comment_tag.match(comment_content)
|
|
|
|
if m:
|
|
|
|
tag, desc = m.group(1, 2)
|
|
|
|
if (tag == "output"):
|
|
|
|
key, text = desc.split(' ', 1)
|
2022-05-20 08:10:42 -03:00
|
|
|
outputs[key] = text
|
2016-12-20 13:13:07 -04:00
|
|
|
elif (tag == "board"):
|
|
|
|
key, text = desc.split(' ', 1)
|
2022-05-20 08:10:42 -03:00
|
|
|
archs[key] = text
|
2015-07-29 14:13:28 -03:00
|
|
|
else:
|
|
|
|
tags[tag] = desc
|
|
|
|
current_tag = tag
|
|
|
|
state = "wait-tag-end"
|
|
|
|
elif state == "wait-short":
|
|
|
|
# Store first line of the short description
|
|
|
|
short_desc = comment_content
|
|
|
|
state = "wait-short-end"
|
|
|
|
elif state == "wait-short-end":
|
|
|
|
# Append comment line to the short description
|
|
|
|
short_desc += "\n" + comment_content
|
|
|
|
elif state == "wait-long":
|
|
|
|
# Store first line of the long description
|
|
|
|
long_desc = comment_content
|
|
|
|
state = "wait-long-end"
|
|
|
|
elif state == "wait-long-end":
|
|
|
|
# Append comment line to the long description
|
|
|
|
long_desc += "\n" + comment_content
|
|
|
|
elif state == "wait-tag-end":
|
|
|
|
# Append comment line to the tag text
|
|
|
|
tags[current_tag] += "\n" + comment_content
|
|
|
|
else:
|
|
|
|
raise AssertionError(
|
|
|
|
"Invalid parser state: %s" % state)
|
|
|
|
elif not last_comment_line:
|
|
|
|
# Invalid comment line (inside comment, but not starting with
|
|
|
|
# "*" or "*/". Reset parsed content.
|
|
|
|
state = None
|
|
|
|
if last_comment_line:
|
|
|
|
state = "comment-processed"
|
|
|
|
else:
|
|
|
|
state = None
|
|
|
|
|
|
|
|
# Process parsed content
|
|
|
|
airframe_type = None
|
|
|
|
maintainer = "John Doe <john@example.com>"
|
|
|
|
airframe_name = None
|
2017-06-27 03:44:53 -03:00
|
|
|
airframe_class = None
|
2015-07-29 14:13:28 -03:00
|
|
|
|
|
|
|
# Done with file, store
|
|
|
|
for tag in tags:
|
|
|
|
if tag == "maintainer":
|
|
|
|
maintainer = tags[tag]
|
2015-07-29 16:22:41 -03:00
|
|
|
elif tag == "type":
|
2015-07-29 14:13:28 -03:00
|
|
|
airframe_type = tags[tag]
|
2017-06-27 03:44:53 -03:00
|
|
|
elif tag == "class":
|
|
|
|
airframe_class = tags[tag]
|
2015-07-29 16:22:41 -03:00
|
|
|
elif tag == "name":
|
2015-07-29 14:13:28 -03:00
|
|
|
airframe_name = tags[tag]
|
2020-02-29 01:09:58 -04:00
|
|
|
elif tag == "desc":
|
|
|
|
# General documentation - not a parameter to be saved.
|
|
|
|
pass
|
2015-07-29 14:13:28 -03:00
|
|
|
elif tag not in self.valid_tags:
|
|
|
|
sys.stderr.write("Aborting due to invalid documentation tag: '%s'\n" % tag)
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Sanity check
|
|
|
|
if airframe_type == None:
|
|
|
|
sys.stderr.write("Aborting due to missing @type tag in file: '%s'\n" % path)
|
|
|
|
return False
|
|
|
|
|
2017-06-27 03:44:53 -03:00
|
|
|
if airframe_class == None:
|
|
|
|
sys.stderr.write("Aborting due to missing @class tag in file: '%s'\n" % path)
|
|
|
|
return False
|
|
|
|
|
2015-07-29 14:13:28 -03:00
|
|
|
if airframe_name == None:
|
|
|
|
sys.stderr.write("Aborting due to missing @name tag in file: '%s'\n" % path)
|
|
|
|
return False
|
|
|
|
|
2019-07-20 15:09:42 -03:00
|
|
|
# Check if a .post script exists
|
|
|
|
if os.path.isfile(path + '.post'):
|
|
|
|
post_path = path + '.post'
|
|
|
|
else:
|
|
|
|
post_path = None
|
|
|
|
|
2015-07-29 14:13:28 -03:00
|
|
|
# We already know this is an airframe config, so add it
|
2022-05-20 08:10:42 -03:00
|
|
|
airframe = Airframe(path, post_path, airframe_name, airframe_type, airframe_class, airframe_id, maintainer)
|
2015-07-29 14:13:28 -03:00
|
|
|
|
|
|
|
# Done with file, store
|
|
|
|
for tag in tags:
|
|
|
|
if tag == "maintainer":
|
|
|
|
maintainer = tags[tag]
|
|
|
|
if tag == "type":
|
|
|
|
airframe_type = tags[tag]
|
2017-06-27 03:44:53 -03:00
|
|
|
if tag == "class":
|
|
|
|
airframe_class = tags[tag]
|
2015-07-29 14:13:28 -03:00
|
|
|
if tag == "name":
|
|
|
|
airframe_name = tags[tag]
|
|
|
|
else:
|
2022-05-20 08:10:42 -03:00
|
|
|
airframe.SetField(tag, tags[tag])
|
2015-07-29 14:13:28 -03:00
|
|
|
|
|
|
|
# Store outputs
|
|
|
|
for output in outputs:
|
2022-05-20 08:10:42 -03:00
|
|
|
airframe.SetOutput(output, outputs[output])
|
2015-07-29 14:13:28 -03:00
|
|
|
|
2016-12-20 13:13:07 -04:00
|
|
|
# Store outputs
|
|
|
|
for arch in archs:
|
2022-05-20 08:10:42 -03:00
|
|
|
airframe.SetArch(arch, archs[arch])
|
2016-12-20 13:13:07 -04:00
|
|
|
|
2015-07-29 14:13:28 -03:00
|
|
|
# Store the parameter
|
2019-07-20 15:09:42 -03:00
|
|
|
|
|
|
|
# Create a class-specific airframe group. This is needed to catch cases where an airframe type might cross classes (e.g. simulation)
|
2022-05-20 08:10:42 -03:00
|
|
|
class_group_identifier=airframe_type + airframe_class
|
|
|
|
if class_group_identifier not in self.airframe_groups:
|
|
|
|
#self.airframe_groups[airframe_type] = ParameterGroup(airframe_type) #HW TEST REMOVE
|
|
|
|
self.airframe_groups[class_group_identifier] = AirframeGroup(airframe_type, airframe_class)
|
|
|
|
self.airframe_groups[class_group_identifier].AddAirframe(airframe)
|
2015-07-29 14:13:28 -03:00
|
|
|
|
|
|
|
return True
|
2016-12-20 13:13:07 -04:00
|
|
|
|
2015-07-29 14:13:28 -03:00
|
|
|
def IsNumber(self, numberString):
|
|
|
|
try:
|
|
|
|
float(numberString)
|
|
|
|
return True
|
|
|
|
except ValueError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def Validate(self):
|
|
|
|
"""
|
|
|
|
Validates the airframe meta data.
|
|
|
|
"""
|
|
|
|
seenParamNames = []
|
2022-05-20 08:10:42 -03:00
|
|
|
for group in self.GetAirframeGroups():
|
|
|
|
for param in group.GetAirframes():
|
2015-07-29 14:13:28 -03:00
|
|
|
name = param.GetName()
|
|
|
|
board = param.GetFieldValue("board")
|
|
|
|
# Check for duplicates
|
|
|
|
name_plus_board = name + "+" + board
|
|
|
|
for seenParamName in seenParamNames:
|
|
|
|
if seenParamName == name_plus_board:
|
|
|
|
sys.stderr.write("Duplicate parameter definition: {0}\n".format(name_plus_board))
|
|
|
|
return False
|
|
|
|
seenParamNames.append(name_plus_board)
|
2017-09-25 12:17:50 -03:00
|
|
|
|
2015-07-29 14:13:28 -03:00
|
|
|
return True
|
|
|
|
|
2022-05-20 08:10:42 -03:00
|
|
|
def GetAirframeGroups(self):
|
2015-07-29 14:13:28 -03:00
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
Returns the parsed list of Airframe groups. Every Airframe is an Airframe
|
2015-07-29 14:13:28 -03:00
|
|
|
object. Note that returned object is not a copy. Modifications affect
|
|
|
|
state of the parser.
|
|
|
|
"""
|
2022-05-20 08:10:42 -03:00
|
|
|
groups = self.airframe_groups.values()
|
|
|
|
groups = sorted(groups, key=lambda x: x.GetType())
|
2017-06-27 08:32:39 -03:00
|
|
|
groups = sorted(groups, key=lambda x: x.GetClass())
|
2022-05-20 08:10:42 -03:00
|
|
|
groups = sorted(groups, key=lambda x: self.priority.get(x.GetType(), 0), reverse=True)
|
2019-07-20 15:09:42 -03:00
|
|
|
|
2017-07-01 07:35:27 -03:00
|
|
|
#Rename duplicate groups to include the class (creating unique headings in page TOC)
|
|
|
|
duplicate_test=set()
|
|
|
|
duplicate_set=set()
|
|
|
|
for group in groups:
|
2022-05-20 08:10:42 -03:00
|
|
|
if group.GetType() in duplicate_test:
|
|
|
|
duplicate_set.add(group.GetType())
|
2017-07-01 07:35:27 -03:00
|
|
|
else:
|
2022-05-20 08:10:42 -03:00
|
|
|
duplicate_test.add(group.GetType() )
|
2017-07-01 07:35:27 -03:00
|
|
|
for group in groups:
|
2022-05-20 08:10:42 -03:00
|
|
|
if group.GetType() in duplicate_set:
|
|
|
|
group.name=group.GetType()+' (%s)' % group.GetClass()
|
2017-07-01 07:35:27 -03:00
|
|
|
|
2015-07-29 14:13:28 -03:00
|
|
|
return groups
|