diff --git a/Makefile.ac b/Makefile.ac index 73fda7678d..f93ab6ecdf 100644 --- a/Makefile.ac +++ b/Makefile.ac @@ -46,7 +46,7 @@ SETTINGS_TELEMETRY=$(ACINCLUDE)/settings_telemetry.xml MAKEFILE_AC=$(ACINCLUDE)/Makefile.ac MODULES_H=$(AC_GENERATED)/modules.h MODULES_DIR=$(PAPARAZZI_HOME)/conf/modules/ -AUTOPILOT_H=$(AC_GENERATED)/autopilot.h +AUTOPILOT_H=$(AC_GENERATED)/autopilot_core.h AIRCRAFT_MD5=$(AIRCRAFT_CONF_DIR)/aircraft.md5 # "make Q=''" to get full echo diff --git a/conf/airframes/ENAC/fixed-wing/weasel.xml b/conf/airframes/ENAC/fixed-wing/weasel.xml index 8f6946c8f3..3a8b7c7ab7 100644 --- a/conf/airframes/ENAC/fixed-wing/weasel.xml +++ b/conf/airframes/ENAC/fixed-wing/weasel.xml @@ -8,6 +8,8 @@ + + diff --git a/conf/airframes/airframe.dtd b/conf/airframes/airframe.dtd index 5950084218..a8ce45cd30 100644 --- a/conf/airframes/airframe.dtd +++ b/conf/airframes/airframe.dtd @@ -1,6 +1,6 @@ - + @@ -25,6 +25,7 @@ + @@ -32,6 +33,10 @@ href CDATA #REQUIRED> + + lprintf out_h "\nstatic inline uint8_t autopilot_core_mode_exceptions(uint8_t mode) {\n"; right (); - lprintf out_h "switch ( mode ) { \n"; + lprintf out_h "switch ( mode ) {\n"; right (); List.iter (fun m -> (* Test exceptions for all modes *) lprintf out_h "case %s :\n" (print_mode_name (Xml.attrib m "name")); @@ -176,12 +175,12 @@ let print_set_mode = fun modes out_h -> left (); in let print_switch = fun var modes t -> - lprintf out_h "switch ( %s ) { \n" var; + lprintf out_h "// switch over %s functions\n" t; + lprintf out_h "switch ( %s ) {\n" var; right (); List.iter (fun m -> try - let stop = Xml.attrib m t in - print_case m stop + print_case m (Xml.attrib m t) with _ -> () ) modes; left (); @@ -193,10 +192,10 @@ let print_set_mode = fun modes out_h -> lprintf out_h "if (new_mode == private_autopilot_mode) return;\n\n"; (* set mode if different from current mode *) (* Print stop functions for each modes *) print_switch "private_autopilot_mode" modes "stop"; - lprintf out_h "\n"; + fprintf out_h "\n"; (* Print start functions for each modes *) print_switch "new_mode" modes "start"; - lprintf out_h "\n"; + fprintf out_h "\n"; lprintf out_h "last_autopilot_mode = private_autopilot_mode;\n"; lprintf out_h "private_autopilot_mode = new_mode;\n"; lprintf out_h "autopilot_mode = new_mode;\n"; @@ -227,7 +226,7 @@ let print_ap_periodic = fun modes ctrl_block main_freq out_h -> in (** Equivalent to the RunOnceEvery macro *) let print_prescaler = fun pre ctrl -> - lprintf out_h "{ \n"; + lprintf out_h "{\n"; right (); lprintf out_h "static uint16_t prescaler = 0;\n"; lprintf out_h "prescaler++;\n"; @@ -251,7 +250,7 @@ let print_ap_periodic = fun modes ctrl_block main_freq out_h -> lprintf out_h "mode = autopilot_core_mode_exceptions(mode);\n"; (* change mode according to exceptions *) lprintf out_h "mode = autopilot_core_global_exceptions(mode);\n"; (* change mode according to global exceptions *) lprintf out_h "autopilot_core_set_mode(mode);\n\n"; (* set new mode and call start/stop functions *) - lprintf out_h "switch ( private_autopilot_mode ) { \n"; + lprintf out_h "switch ( private_autopilot_mode ) {\n"; right (); List.iter (fun m -> (* Print control loops for each modes *) lprintf out_h "case %s :\n" (print_mode_name (Xml.attrib m "name")); @@ -337,6 +336,10 @@ let () = | Dtd.Prove_error e -> fprintf stderr "%s: DTD error:%s\n%!" xml_file (Dtd.prove_error e); exit 1 | Dtd.Check_error e -> fprintf stderr "%s: DTD error:%s\n%!" xml_file (Dtd.check_error e); exit 1 | Dtd.Parse_error e -> fprintf stderr "%s: DTD error:%s\n%!" xml_file (Dtd.parse_error e); exit 1 - | Not_found -> let out_h = open_out h_file in close_out out_h; exit 0 + | Not_found -> + let out_h = open_out h_file in + fprintf out_h "/*** Sorry, no autopilot file found ***/\n"; + close_out out_h; + exit 0 diff --git a/sw/tools/gen_common.ml b/sw/tools/gen_common.ml index db9afa9ddb..afe407b83b 100644 --- a/sw/tools/gen_common.ml +++ b/sw/tools/gen_common.ml @@ -65,11 +65,30 @@ let targets_of_field = fun field default -> with _ -> [] +(** [get_autopilot_of_airframe xml] + * Returns (autopilot xml, main freq) from airframe xml file *) +let get_autopilot_of_airframe = fun xml -> + (* extract all "modules" sections *) + let section = List.filter (fun s -> compare (Xml.tag s) "autopilot" = 0) (Xml.children xml) in + (* Raise error if more than one modules section *) + match section with + [autopilot] -> + let freq = try int_of_string (Xml.attrib autopilot "freq") with _ -> default_freq in + let ap = try Xml.attrib autopilot "name" with _ -> raise Not_found in + (autopilot_dir // ap, freq) + | [] -> raise Not_found + | _ -> failwith "Error: you have more than one 'autopilot' section in your airframe file" + (** [get_modules_of_airframe xml] * Returns a list of module configuration from airframe file *) let rec get_modules_of_airframe = fun xml -> (* extract all "modules" sections *) let section = List.filter (fun s -> compare (Xml.tag s) "modules" = 0) (Xml.children xml) in + (* get autopilot file if any *) + let ap_file = try + let (ap, _) = get_autopilot_of_airframe xml in + ap + with _ -> "" in (* Raise error if more than one modules section *) match section with [modules] -> @@ -80,15 +99,14 @@ let rec get_modules_of_airframe = fun xml -> let targets = singletonize (t @ targets_of_field m "") in { xml = ExtXml.parse_file file; file = file; param = Xml.children m; extra_targets = targets } in - List.flatten (List.map (fun m -> + let modules_list = List.map (fun m -> if compare (Xml.tag m) "load" <> 0 then Xml2h.xml_error "load"; - let airframe_module = [get_module m t_global] in - let ap_module = try - let ap_file = autopilot_dir // ExtXml.attrib m "autopilot" in - get_modules_of_airframe (ExtXml.parse_file ap_file) - with _ -> [] in - List.flatten [airframe_module @ ap_module] - ) (Xml.children modules)) + get_module m t_global + ) (Xml.children modules) in + let ap_modules = try + get_modules_of_airframe (ExtXml.parse_file ap_file) + with _ -> [] in + modules_list @ ap_modules | [] -> [] | _ -> failwith "Error: you have more than one 'modules' section in your airframe file" @@ -136,17 +154,3 @@ let get_modules_dir = fun modules -> let dir = List.map (fun m -> try Xml.attrib m.xml "dir" with _ -> ExtXml.attrib m.xml "name") modules in singletonize (List.sort compare dir) -(** [get_autopilot_of_airframe xml] - * Returns (autopilot xml, main freq) from airframe xml file *) -let get_autopilot_of_airframe = fun xml -> - (* extract all "modules" sections *) - let section = List.filter (fun s -> compare (Xml.tag s) "modules" = 0) (Xml.children xml) in - (* Raise error if more than one modules section *) - match section with - [modules] -> - let main_freq = try int_of_string (Xml.attrib modules "main_freq") with _ -> default_freq in - let ap = try Xml.attrib modules "autopilot" with _ -> raise Not_found in - (autopilot_dir // ap, main_freq) - | [] -> raise Not_found - | _ -> failwith "Error: you have more than one 'modules' section in your airframe file" - diff --git a/sw/tools/gen_common.mli b/sw/tools/gen_common.mli index 159b2970e1..295c1e67ff 100644 --- a/sw/tools/gen_common.mli +++ b/sw/tools/gen_common.mli @@ -68,7 +68,7 @@ val get_modules_dir : module_conf list -> string list (** [get_autopilot_of_airframe xml] * Returns (autopilot file, main freq) from airframe xml file - * Raise Not_found if no autopilot + * Raise Not_found if no autopilot * Fail if more than one *) val get_autopilot_of_airframe : Xml.xml -> (string * int)