[settings] allow several groups of settings in modules

This commit is contained in:
Gautier Hattenberger
2014-09-30 18:49:28 +02:00
parent 7230aa4a92
commit 170e5b6843
5 changed files with 51 additions and 13 deletions
+3 -2
View File
@@ -42,6 +42,7 @@ FLIGHT_PLAN_H=$(AC_GENERATED)/flight_plan.h
FLIGHT_PLAN_XML=$(AIRCRAFT_BUILD_DIR)/flight_plan.xml
SETTINGS_H=$(AC_GENERATED)/settings.h
SETTINGS_XMLS=$(patsubst %,$(CONF)/%,$(SETTINGS))
SETTINGS_XMLS_DEP=$(filter-out %~,$(SETTINGS_XMLS))
SETTINGS_XML=$(AIRCRAFT_BUILD_DIR)/settings.xml
SETTINGS_MODULES=$(AIRCRAFT_BUILD_DIR)/settings_modules.xml
SETTINGS_TELEMETRY=$(AIRCRAFT_BUILD_DIR)/settings_telemetry.xml
@@ -164,14 +165,14 @@ $(FLIGHT_PLAN_XML) : $(CONF)/$(FLIGHT_PLAN) $(CONF_XML) $(GENERATORS)/gen_flight
$(Q)mv $($@_TMP) $@
$(Q)chmod a+r $@
$(SETTINGS_H) : $(SETTINGS_XMLS) $(CONF_XML) $(SETTINGS_MODULES) $(SETTINGS_TELEMETRY) $(GENERATORS)/gen_settings.out
$(SETTINGS_H) : $(SETTINGS_XMLS_DEP) $(CONF_XML) $(SETTINGS_MODULES) $(SETTINGS_TELEMETRY) $(GENERATORS)/gen_settings.out
$(Q)test -d $(AC_GENERATED) || mkdir -p $(AC_GENERATED)
@echo GENERATE $@
$(eval $@_TMP := $(shell $(MKTEMP)))
$(Q)$(GENERATORS)/gen_settings.out $(SETTINGS_XML) $(SETTINGS_TELEMETRY) $(SETTINGS_XMLS) $(SETTINGS_MODULES) > $($@_TMP)
$(Q)mv $($@_TMP) $@
$(Q)chmod a+r $@
$(Q)cp $(SETTINGS_XMLS) $(AIRCRAFT_CONF_DIR)/settings
$(Q)cp $(SETTINGS_XMLS_DEP) $(AIRCRAFT_CONF_DIR)/settings
$(MODULES_H) : $(CONF)/$(AIRFRAME_XML) $(GENERATORS)/gen_modules.out $(CONF)/modules/*.xml
$(Q)test -d $(AC_GENERATED) || mkdir -p $(AC_GENERATED)
+7
View File
@@ -22,6 +22,13 @@
</dl_settings>
</dl_settings>
</settings>
<settings name="Advanced">
<dl_settings name="control">
<dl_settings name="hackhd">
<dl_setting max="5" min="0" step="1" module="digital_cam/hackhd" var="hackhd.timer"/>
</dl_settings>
</dl_settings>
</settings>
<header>
<file name="hackhd.h"/>
</header>
+5 -1
View File
@@ -1,6 +1,6 @@
<!-- Paparazzi Modules DTD -->
<!ELEMENT module (doc?,settings_file*,settings?,depend?,header,init*,periodic*,event*,datalink*,makefile*)>
<!ELEMENT module (doc?,settings_file*,settings*,depend?,header,init*,periodic*,event*,datalink*,makefile*)>
<!ELEMENT doc (description|define|configure|section)*>
<!ELEMENT settings_file (file*)>
<!ELEMENT settings (dl_settings?)>
@@ -92,6 +92,10 @@ dir CDATA #IMPLIED>
name CDATA #REQUIRED
>
<!ATTLIST settings
name CDATA #IMPLIED
>
<!ATTLIST dl_settings
name CDATA #IMPLIED
>
+17 -7
View File
@@ -167,14 +167,24 @@ let get_settings_modules = fun ac_xml settings_modules ->
(* get list of settings files *)
let settings = List.fold_left (fun l (m, f) ->
(* get list of settings_file xml node if any *)
let set_list = List.filter (fun t -> Xml.tag t = "settings_file") (Xml.children m) in
let file_list = List.map (fun s -> "settings/"^(Xml.attrib s "name")) set_list in
let settings_file_list = List.filter (fun t -> Xml.tag t = "settings_file") (Xml.children m) in
let file_list = List.map (fun s -> "settings/"^(Xml.attrib s "name")) settings_file_list in
(* include module file in the list only if it has a 'settings' node *)
let module_file =
if List.exists (fun t -> Xml.tag t = "settings") (Xml.children m)
then [Env.filter_absolute_path f]
else [] in
l @ file_list @ module_file
let settings_list = List.filter (fun t -> Xml.tag t = "settings") (Xml.children m) in
let module_file = if List.length settings_list > 0 then [Env.filter_absolute_path f] else [] in
(* include module file with specific name if they exist *)
let settings_list = List.fold_left (fun l s ->
try
let name = Xml.attrib s "name" in
(* test if there is no white space in settings name *)
if Str.string_match (Str.regexp ".* .*") name 0
then failwith "Paparazzicenter: no white space allowed in modules settings name";
l @ [(Env.filter_absolute_path f)^"~"^name^"~"]
with
| Failure x -> prerr_endline x; l
| _ -> l
) [] settings_list in
l @ file_list @ module_file @ settings_list
) [] modules in
(* store current state in a hashtable *)
let current = Hashtbl.create 7 in
+19 -3
View File
@@ -270,6 +270,12 @@ let join_xml_files = fun xml_files ->
let dl_settings = ref []
and rc_settings = ref [] in
List.iter (fun xml_file ->
(* look for a specific name after settings file (in case of modules) *)
let split = Str.split (Str.regexp "~") xml_file in
let xml_file, name = match split with
| [f; n] -> f, n
| _ -> xml_file, ""
in
let xml = Xml.parse_file xml_file in
let these_rc_settings =
try Xml.children (ExtXml.child xml "rc_settings") with
@@ -277,9 +283,19 @@ let join_xml_files = fun xml_files ->
let these_dl_settings =
try
(* test if the file is plain settings file or a module file *)
let xml = if Xml.tag xml = "module" then (ExtXml.child xml "settings") else xml in
Xml.children (ExtXml.child xml "dl_settings") with
Not_found -> [] in
let xml =
if Xml.tag xml = "module"
then List.filter (fun t -> Xml.tag t = "settings") (Xml.children xml)
else [xml]
in
(* include settings if name is matching *)
List.fold_left (fun l x ->
if (ExtXml.attrib_or_default x "name" "") = name then
l @ (Xml.children (ExtXml.child x "dl_settings"))
else l
) [] xml
with
| Not_found -> [] in
rc_settings := these_rc_settings @ !rc_settings;
dl_settings := these_dl_settings @ !dl_settings)
xml_files;