mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-10 23:35:45 +08:00
e49901bfa8
- pep8: 4 spaces - use 'in' instead of has_key for checking dicts - some fixes for settingsapp
142 lines
5.1 KiB
Python
Executable File
142 lines
5.1 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
from __future__ import absolute_import, print_function
|
|
|
|
import os
|
|
import sys
|
|
from lxml import etree
|
|
|
|
# Class for all settings
|
|
class PaparazziACSettings:
|
|
"Paparazzi Settings Class"
|
|
ac_id = 0
|
|
groups = []
|
|
lookup = []
|
|
name_lookup = {}
|
|
# Takes a string file path for settings XML file and
|
|
# returns a settings AC object
|
|
|
|
def __init__(self, ac_id):
|
|
self.ac_id = ac_id
|
|
paparazzi_home = os.getenv("PAPARAZZI_HOME")
|
|
paparazzi_conf = os.path.join(paparazzi_home, 'conf')
|
|
conf_xml_path = os.path.join(paparazzi_conf, 'conf.xml')
|
|
conf_tree = etree.parse(conf_xml_path)
|
|
# extract aircraft node from conf.xml file
|
|
ac_node = conf_tree.xpath('/conf/aircraft[@ac_id=%i]' % ac_id)
|
|
if (len(ac_node) != 1):
|
|
print("Aircraft ID %i not found." % ac_id)
|
|
|
|
# get settings file path from aircraft xml node
|
|
settings_xml_files = filter(None, ac_node[0].attrib['settings'].split(' '))
|
|
settings_xml_paths = [os.path.join(paparazzi_conf, s) for s in settings_xml_files]
|
|
#print("settings_xml_paths: %s" % settings_xml_paths)
|
|
|
|
# save AC name for reference
|
|
self.name = ac_node[0].attrib['name']
|
|
|
|
index = 0 # keep track of index/id of setting starting at 0
|
|
for settings_file in settings_xml_paths:
|
|
#print("parsing settings file", settings_file)
|
|
tree = etree.parse(settings_file)
|
|
|
|
for the_tab in tree.xpath("//dl_settings"):
|
|
try:
|
|
if 'NAME' in the_tab.attrib:
|
|
setting_group_name = the_tab.attrib['NAME']
|
|
else:
|
|
setting_group_name = the_tab.attrib['name']
|
|
except:
|
|
#print("Could not read name of settings group")
|
|
continue
|
|
|
|
#print("parsing setting group:", setting_group_name)
|
|
setting_group = PaparazziSettingsGroup(setting_group_name)
|
|
|
|
for the_setting in the_tab.xpath('dl_setting'):
|
|
try:
|
|
if 'shortname' in the_setting.attrib:
|
|
name = the_setting.attrib['shortname']
|
|
elif 'VAR' in the_setting.attrib:
|
|
name = the_setting.attrib['VAR']
|
|
else:
|
|
name = the_setting.attrib['var']
|
|
except:
|
|
print("Could not get name for setting in group", setting_group)
|
|
continue
|
|
|
|
settings = PaparazziSetting(name)
|
|
settings.index = index
|
|
print("add setting with index", index)
|
|
|
|
try:
|
|
if 'MIN' in the_setting.attrib:
|
|
settings.min_value = float(the_setting.attrib['MIN'])
|
|
else:
|
|
settings.min_value = float(the_setting.attrib['min'])
|
|
|
|
if 'MAX' in the_setting.attrib:
|
|
settings.max_value = float(the_setting.attrib['MAX'])
|
|
else:
|
|
settings.max_value = float(the_setting.attrib['max'])
|
|
|
|
if 'STEP' in the_setting.attrib:
|
|
settings.step = float(the_setting.attrib['STEP'])
|
|
else:
|
|
settings.step = float(the_setting.attrib['step'])
|
|
except:
|
|
print("Could not get min/max/step for setting", name)
|
|
continue
|
|
|
|
if 'values' in the_setting.attrib:
|
|
settings.values = the_setting.attrib['values'].split('|')
|
|
count = int((settings.max_value - settings.min_value + settings.step) / settings.step)
|
|
if (len(settings.values) != count):
|
|
print("Warning: possibly wrong number of values (%i) for %s (expected %i)" % (len(settings.values), name, count))
|
|
|
|
setting_group.member_list.append(settings)
|
|
self.lookup.append(settings)
|
|
self.name_lookup[name] = settings
|
|
index = index + 1
|
|
|
|
self.groups.append(setting_group)
|
|
|
|
def GetACName(self):
|
|
return self.name
|
|
|
|
# Class for named group of settings
|
|
class PaparazziSettingsGroup:
|
|
"Paparazzi Setting Group Class"
|
|
name = 0
|
|
member_list = []
|
|
|
|
def __init__(self, name):
|
|
self.name = name
|
|
self.member_list = []
|
|
|
|
# Class for a single paparazzi setting
|
|
class PaparazziSetting:
|
|
"Paparazzi Setting Class"
|
|
shortname = ""
|
|
min_value = 0
|
|
max_value = 1
|
|
step = 1
|
|
index = 0
|
|
value = None
|
|
values = None
|
|
|
|
def __init__(self, shortname):
|
|
self.shortname = shortname
|
|
|
|
|
|
def test():
|
|
ac_id = 164
|
|
ac_settings = PaparazziACSettings(ac_id)
|
|
for setting_group in ac_settings.groups:
|
|
print(setting_group.name)
|
|
for setting in setting_group.member_list:
|
|
print(" " + setting.shortname)
|
|
|
|
if __name__ == '__main__':
|
|
test()
|