From c697449e9852c2cd8b66c28b369dfaabcd3778e6 Mon Sep 17 00:00:00 2001 From: Gautier Hattenberger Date: Wed, 17 Feb 2016 23:11:03 +0100 Subject: [PATCH] [modules] allow to load modules from a flight plan --- Makefile.ac | 4 ++-- conf/airframes/examples/microjet_lisa_m.xml | 13 ----------- conf/flight_plans/flight_plan.dtd | 10 +++++++- conf/flight_plans/nav_modules.xml | 14 +++++++++++ sw/lib/ocaml/gen_common.ml | 20 ++++++++++++++++ sw/lib/ocaml/gen_common.mli | 4 ++++ sw/supervision/pc_aircraft.ml | 8 ++++--- sw/tools/generators/gen_aircraft.ml | 26 +++++++++++++-------- sw/tools/generators/gen_modules.ml | 12 ++++++---- 9 files changed, 77 insertions(+), 34 deletions(-) diff --git a/Makefile.ac b/Makefile.ac index b3b9b88439..b8b4a941bc 100644 --- a/Makefile.ac +++ b/Makefile.ac @@ -208,11 +208,11 @@ $(SETTINGS_H) : $(SETTINGS_XMLS_DEP) $(CONF_XML) $(SETTINGS_MODULES) $(SETTINGS_ $(Q)chmod a+r $@ $(Q)cp $(SETTINGS_XMLS_DEP) $(AIRCRAFT_CONF_DIR)/settings -$(MODULES_H) : $(CONF)/$(AIRFRAME_XML) $(GENERATORS)/gen_modules.out $(CONF)/modules/*.xml +$(MODULES_H) : $(CONF)/$(AIRFRAME_XML) $(FLIGHT_PLAN_XML) $(GENERATORS)/gen_modules.out $(CONF)/modules/*.xml $(Q)test -d $(AC_GENERATED) || mkdir -p $(AC_GENERATED) @echo GENERATE $@ $(eval $@_TMP := $(shell $(MKTEMP))) - $(Q)$(GENERATORS)/gen_modules.out $(SETTINGS_MODULES) $(DEFAULT_MODULES_FREQUENCY) $< > $($@_TMP) + $(Q)$(GENERATORS)/gen_modules.out $(SETTINGS_MODULES) $(DEFAULT_MODULES_FREQUENCY) $(FLIGHT_PLAN_XML) $< > $($@_TMP) $(Q)mv $($@_TMP) $@ $(Q)chmod a+r $@ diff --git a/conf/airframes/examples/microjet_lisa_m.xml b/conf/airframes/examples/microjet_lisa_m.xml index 09942f8f72..756740f9cd 100644 --- a/conf/airframes/examples/microjet_lisa_m.xml +++ b/conf/airframes/examples/microjet_lisa_m.xml @@ -51,19 +51,6 @@ - - - - - - - - - - - - - diff --git a/conf/flight_plans/flight_plan.dtd b/conf/flight_plans/flight_plan.dtd index 0d9e67e35c..3afaee44a7 100644 --- a/conf/flight_plans/flight_plan.dtd +++ b/conf/flight_plans/flight_plan.dtd @@ -1,6 +1,6 @@ - + @@ -17,6 +17,9 @@ + + + @@ -104,6 +107,11 @@ alt_unit CDATA #IMPLIED alt_unit_coef CDATA #IMPLIED values CDATA #IMPLIED> + + + diff --git a/conf/flight_plans/nav_modules.xml b/conf/flight_plans/nav_modules.xml index c8dc6e8cff..1cc99ee984 100644 --- a/conf/flight_plans/nav_modules.xml +++ b/conf/flight_plans/nav_modules.xml @@ -33,6 +33,20 @@ + + + + + + + + + + + + + + diff --git a/sw/lib/ocaml/gen_common.ml b/sw/lib/ocaml/gen_common.ml index 8f4490e817..9ffb319cdd 100644 --- a/sw/lib/ocaml/gen_common.ml +++ b/sw/lib/ocaml/gen_common.ml @@ -179,6 +179,26 @@ let rec get_modules_of_airframe = fun ?target xml -> | None -> modules | Some t -> List.filter (fun m -> test_targets t m.targets) modules + +(** [get_modules_of_flight_plan xml] + * Returns a list of module configuration from flight plan file *) +let get_modules_of_flight_plan = fun xml -> + let rec iter_modules = fun targets modules xml -> + match xml with + | Xml.PCData _ -> modules + | Xml.Element (tag, _attrs, children) when tag = "module" -> + begin try + let m = get_module xml targets in + List.fold_left + (fun acc xml -> iter_modules targets acc xml) + (m :: modules) children + with _ -> modules end + | Xml.Element (tag, _attrs, children) -> + List.fold_left + (fun acc xml -> iter_modules targets acc xml) modules children in + iter_modules [] [] xml + + (** [get_modules_name xml] * Returns a list of loaded modules' name *) let get_modules_name = fun xml -> diff --git a/sw/lib/ocaml/gen_common.mli b/sw/lib/ocaml/gen_common.mli index e0be687730..1ea06158fc 100644 --- a/sw/lib/ocaml/gen_common.mli +++ b/sw/lib/ocaml/gen_common.mli @@ -51,6 +51,10 @@ val get_module : Xml.xml -> string list -> module_conf * Returns a list of pair (modules ("load" node), targets) from airframe file *) val get_modules_of_airframe : ?target: string -> Xml.xml -> module_conf list +(** [get_modules_of_flight_plan xml] + * Returns a list of module configuration from flight plan file *) +val get_modules_of_flight_plan : Xml.xml -> module_conf list + (** [test_targets target targets] * Test if [target] is allowed [targets] * Return true if target is allowed, false if target is not in list or rejected (prefixed by !) *) diff --git a/sw/supervision/pc_aircraft.ml b/sw/supervision/pc_aircraft.ml index 7ac2477788..9b789a7e3c 100644 --- a/sw/supervision/pc_aircraft.ml +++ b/sw/supervision/pc_aircraft.ml @@ -165,9 +165,9 @@ let save_callback = fun ?user_save gui ac_combo tree tree_modules () -> type selected_t = Selected | Unselected | Unknown (* Get the settings (string list) with current modules *) -let get_settings_modules = fun ac_xml settings_modules -> +let get_settings_modules = fun ac_xml fp_xml settings_modules -> (* get modules *) - let modules = Gen_common.get_modules_of_airframe ac_xml in + let modules = Gen_common.get_modules_of_airframe ac_xml @ Gen_common.get_modules_of_flight_plan fp_xml in let modules = List.map (fun m -> m.Gen_common.xml, m.Gen_common.file ) modules in (* get list of settings files *) let settings = List.fold_left (fun l (m, f) -> @@ -316,8 +316,10 @@ let ac_combo_handler = fun gui (ac_combo:Gtk_tools.combo) target_combo flash_com log (sprintf "Error airframe file not found: %s\n" x); Xml.Element ("airframe", [], []); in + let fp_file = (Env.paparazzi_home // "conf" // (Xml.attrib aircraft "flight_plan")) in + let fp_xml = Xml.parse_file fp_file in let settings_modules = try - get_settings_modules af_xml (ExtXml.attrib_or_default aircraft "settings_modules" "") + get_settings_modules af_xml fp_xml (ExtXml.attrib_or_default aircraft "settings_modules" "") with | Failure x -> prerr_endline x; [] | _ -> [] diff --git a/sw/tools/generators/gen_aircraft.ml b/sw/tools/generators/gen_aircraft.ml index 43af402bbb..7b0add0262 100644 --- a/sw/tools/generators/gen_aircraft.ml +++ b/sw/tools/generators/gen_aircraft.ml @@ -145,8 +145,9 @@ let module_xml2mk = fun f target firmware m -> ) section ) m.xml -let modules_xml2mk = fun f target xml -> +let modules_xml2mk = fun f target xml fp -> let modules = Gen_common.get_modules_of_airframe ~target xml in + let modules = (modules @ Gen_common.get_modules_of_flight_plan fp) in (* print modules directories and includes for all targets *) fprintf f "\n# include modules directory for all targets\n"; (* get dir list *) @@ -205,7 +206,7 @@ let fallback_subsys_xml2mk = fun f global_targets firmware target xml -> ignore(Gen_common.get_module xml global_targets) with Gen_common.Subsystem _file -> subsystem_xml2mk f firmware xml -let parse_firmware = fun makefile_ac ac_xml firmware -> +let parse_firmware = fun makefile_ac ac_xml firmware fp -> let firmware_name = Xml.attrib firmware "name" in (* get the configures, targets, subsystems and defines for this firmware *) let config, rest = ExtXml.partition_tag "configure" (Xml.children firmware) in @@ -225,7 +226,7 @@ let parse_firmware = fun makefile_ac ac_xml firmware -> fprintf makefile_ac "\n###########\n# -target: '%s'\n" target_name; fprintf makefile_ac "ifeq ($(TARGET), %s)\n" target_name; let target_name = Xml.attrib target "name" in - let modules = modules_xml2mk makefile_ac target_name ac_xml in + let modules = modules_xml2mk makefile_ac target_name ac_xml fp in begin (* Check for "processor" attribute *) try let proc = Xml.attrib target "processor" in @@ -252,21 +253,22 @@ let parse_firmware = fun makefile_ac ac_xml firmware -> (** Search and dump the firmware section *) -let dump_firmware = fun f ac_xml firmware -> +let dump_firmware = fun f ac_xml firmware fp -> try fprintf f "\n####################################################\n"; fprintf f "# makefile firmware '%s'\n" (Xml.attrib firmware "name"); fprintf f "####################################################\n"; - parse_firmware f ac_xml firmware + parse_firmware f ac_xml firmware fp with Xml.No_attribute _ -> failwith "Warning: firmware name is undeclared" -let dump_firmware_sections = fun makefile_ac xml -> +let dump_firmware_sections = fun makefile_ac fp xml -> ExtXml.iter_tag "firmware" - (fun tag -> dump_firmware makefile_ac xml tag) xml + (fun tag -> dump_firmware makefile_ac xml tag fp) xml (** Extracts the makefile sections of an airframe file *) -let extract_makefile = fun ac_id airframe_file makefile_ac -> +let extract_makefile = fun ac_id airframe_file flight_plan_file makefile_ac -> let xml = Xml.parse_file airframe_file in + let fp = Xml.parse_file flight_plan_file in let f = open_out makefile_ac in fprintf f "# This file has been generated by gen_aircraft from %s by %s\n" airframe_file Sys.executable_name; @@ -277,7 +279,7 @@ let extract_makefile = fun ac_id airframe_file makefile_ac -> (** Search and dump makefile sections that have a "location" attribute set to "before" or no attribute *) dump_makefile_section xml f airframe_file "before"; (** Search and dump the firmware sections *) - dump_firmware_sections f xml; + dump_firmware_sections f fp xml; (** Search and dump makefile sections that have a "location" attribute set to "after" *) dump_makefile_section xml f airframe_file "after"; close_out f @@ -318,6 +320,9 @@ let () = let airframe_file = value "airframe" in let abs_airframe_file = paparazzi_conf // airframe_file in + let flight_plan_file = value "flight_plan" in + let abs_flight_plan_file = paparazzi_conf // flight_plan_file in + mkdir (Env.paparazzi_home // "var"); mkdir (Env.paparazzi_home // "var" // "aircrafts"); mkdir aircraft_dir; @@ -333,6 +338,7 @@ let () = let target = try Sys.getenv "TARGET" with _ -> "" in let modules = Gen_common.get_modules_of_airframe ~target (Xml.parse_file abs_airframe_file) in + let modules = (modules @ Gen_common.get_modules_of_flight_plan (Xml.parse_file abs_flight_plan_file)) in (* normal settings *) let settings = try Env.filter_settings (value "settings") with _ -> "" in (* remove settings if not supported for the current target *) @@ -410,7 +416,7 @@ let () = let temp_makefile_ac = Filename.temp_file "Makefile.ac" "tmp" in - let () = extract_makefile (value "ac_id") abs_airframe_file temp_makefile_ac in + let () = extract_makefile (value "ac_id") abs_airframe_file abs_flight_plan_file temp_makefile_ac in (* Create Makefile.ac only if needed *) let makefile_ac = aircraft_dir // "Makefile.ac" in diff --git a/sw/tools/generators/gen_modules.ml b/sw/tools/generators/gen_modules.ml index 17c02951a5..a6833e2782 100644 --- a/sw/tools/generators/gen_modules.ml +++ b/sw/tools/generators/gen_modules.ml @@ -378,9 +378,10 @@ let write_settings = fun xml_file out_set modules -> let h_name = "MODULES_H" let () = - if Array.length Sys.argv <> 4 then - failwith (Printf.sprintf "Usage: %s out_settings_file default_freq xml_file" Sys.argv.(0)); - let xml_file = Sys.argv.(3) + if Array.length Sys.argv <> 5 then + failwith (Printf.sprintf "Usage: %s out_settings_file default_freq fp_file xml_file" Sys.argv.(0)); + let xml_file = Sys.argv.(4) + and fp_file = Sys.argv.(3) and default_freq = int_of_string(Sys.argv.(2)) and out_set = open_out Sys.argv.(1) in try @@ -406,14 +407,15 @@ let () = let modules = try let target = Sys.getenv "TARGET" in - GC.get_modules_of_airframe ~target xml + prerr_endline fp_file; + (GC.get_modules_of_airframe ~target xml) @ (GC.get_modules_of_flight_plan (Xml.parse_file fp_file)) with | Not_found -> failwith "TARTGET env needs to be specified to generate modules files" in (* Extract modules names (file name and module name) *) let modules_name = (List.map (fun m -> try Xml.attrib m.GC.xml "name" with _ -> "") modules) @ - (List.map (fun m -> m.GC.filename) modules) in + (List.map (fun m -> prerr_endline m.GC.filename; m.GC.filename) modules) in (* Extract xml modules nodes *) let modules_list = List.map (fun m -> m.GC.xml) modules in check_dependencies modules_list modules_name;