[generators] autopilot modes exported in xml settings file

for a future use
This commit is contained in:
Gautier Hattenberger
2014-09-04 16:54:12 +02:00
parent f30047d852
commit 6839d4ccdd
4 changed files with 82 additions and 16 deletions
+3 -2
View File
@@ -45,6 +45,7 @@ SETTINGS_XMLS=$(patsubst %,$(CONF)/%,$(SETTINGS))
SETTINGS_XML=$(AIRCRAFT_BUILD_DIR)/settings.xml
SETTINGS_MODULES=$(AIRCRAFT_BUILD_DIR)/settings_modules.xml
SETTINGS_TELEMETRY=$(AIRCRAFT_BUILD_DIR)/settings_telemetry.xml
SETTINGS_AUTOPILOT=$(AIRCRAFT_BUILD_DIR)/settings_autopilot.xml
MAKEFILE_AC=$(AIRCRAFT_BUILD_DIR)/Makefile.ac
MODULES_H=$(AC_GENERATED)/modules.h
MODULES_DIR=$(PAPARAZZI_HOME)/conf/modules/
@@ -182,8 +183,8 @@ $(MODULES_H) : $(CONF)/$(AIRFRAME_XML) $(GENERATORS)/gen_modules.out $(CONF)/mod
autopilot_h : $(CONF)/$(AIRFRAME_XML) $(GENERATORS)/gen_autopilot.out $(CONF)/autopilot/*.xml
$(Q)test -d $(AC_GENERATED) || mkdir -p $(AC_GENERATED)
@echo GENERATE $@
$(Q)$(GENERATORS)/gen_autopilot.out $(CONF)/$(AIRFRAME_XML) $(AUTOPILOT_DIR)
@echo GENERATE autopilots in $(AUTOPILOT_DIR)
$(Q)$(GENERATORS)/gen_autopilot.out $(CONF)/$(AIRFRAME_XML) $(AUTOPILOT_DIR) $(SETTINGS_AUTOPILOT)
$(SETTINGS_MODULES) : $(MODULES_H)
$(SETTINGS_TELEMETRY) : $(PERIODIC_H)
+6 -2
View File
@@ -22,7 +22,9 @@ name CDATA #IMPLIED>
<!ATTLIST state_machine
name CDATA #REQUIRED
freq CDATA #REQUIRED>
freq CDATA #REQUIRED
gcs_mode CDATA #IMPLIED
settings_mode CDATA #IMPLIED>
<!ATTLIST control_block
name CDATA #REQUIRED>
@@ -30,7 +32,9 @@ name CDATA #REQUIRED>
<!ATTLIST mode
name CDATA #REQUIRED
start CDATA #IMPLIED
stop CDATA #IMPLIED>
stop CDATA #IMPLIED
gcs_name CDATA #IMPLIED
settings CDATA #IMPLIED>
<!ATTLIST exceptions>
+8 -4
View File
@@ -2,12 +2,16 @@
<autopilot name="Fixed Wing Autopilot">
<state_machine name="ap" freq="CONTROL_FREQUENCY">
<state_machine name="ap" freq="CONTROL_FREQUENCY" gcs_mode="true" settings_mode="true">
<!--modules>
<load name=""/>
</modules-->
<includes>
<!-- <include href=""/> -->
</includes>
<control_block name="actuators_ap">
<call fun="SetCommandsFromAP(commands)"/>
<call fun="SetActuatorsFromCommands(commands)"/>
@@ -22,7 +26,7 @@
<exception cond="too_far_from_home" deroute="HOME"/>
</exceptions>
<mode name="MANUAL">
<mode name="MANUAL" gcs_name="MANU">
<select cond="RCMode0()"/>
<control>
<call fun="SetCommandsFromRC(commands, rc_values)"/>
@@ -57,7 +61,7 @@
<exception cond="GPSLost()" deroute="GPS_LOST"/>
</mode>
<mode name="HOME">
<mode name="HOME" settings="hide">
<control freq="4">
<call fun="nav_home()"/>
</control>
@@ -68,7 +72,7 @@
<exception cond="GPSLost()" deroute="GPS_LOST"/>
</mode>
<mode name="GPS_LOST">
<mode name="GPS_LOST" gcs_name="NOGPS" settings="hide">
<control freq="4">
<call fun="nav_gps_lost()"/>
</control>
+65 -8
View File
@@ -59,6 +59,12 @@ let get_includes = fun sm ->
try ExtXml.child sm "includes"
with _ -> Xml.Element ("includes", [], [])
let has_modules = fun sm ->
try
let m = ExtXml.child sm "modules" in
List.length (Xml.children m) > 0
with _ -> false
let get_mode_exceptions = fun mode ->
List.filter (fun m -> (Xml.tag m) = "exception") (Xml.children mode)
@@ -323,7 +329,7 @@ let parse_and_gen_modes xml_file ap_name main_freq h_dir sm =
fprintf out_h "\n#ifdef AUTOPILOT_CORE_%s_C\n" name_up;
(* Print includes and private variables *)
print_includes (get_includes sm) out_h;
fprintf out_h "\n#include \"modules.h\"\n";
if has_modules sm then fprintf out_h "\n#include \"modules.h\"\n";
fprintf out_h "uint8_t private_autopilot_mode_%s;\n" name;
fprintf out_h "uint8_t last_autopilot_mode_%s;\n\n" name;
(* Print functions *)
@@ -349,16 +355,66 @@ let parse_and_gen_modes xml_file ap_name main_freq h_dir sm =
failwith (sprintf "gen_autopilot: fail to move tmp file %s to final location" tmp_file)
with _ -> Sys.remove tmp_file
(* Output settings xml file *)
let write_settings = fun xml_file out_set ap ->
fprintf out_set "<!-- This file has been generated from %s -->\n" xml_file;
fprintf out_set "<!-- Please DO NOT EDIT -->\n\n";
fprintf out_set "<settings>\n";
fprintf out_set " <dl_settings>\n";
(* Filter state machines that need to be displayed *)
let sm_filtered = List.filter (fun sm ->
try (String.lowercase (Xml.attrib sm "settings_mode")) = "true" with _ -> false
) (Xml.children ap) in
if List.length sm_filtered > 0 then begin
(* Create node if there is at least one to display *)
fprintf out_set " <dl_settings name=\"Autopilot\">\n";
let write_ap_mode = fun sm ->
let modes = get_modes sm in
let name = Xml.attrib sm "name" in
(* Iter on modes and store min, max and values *)
let (_, min, max, values) = List.fold_left (fun (current, min, max, values) m ->
let print = try String.lowercase (Xml.attrib m "settings") <> "hide" with _ -> true in
let name = Xml.attrib m "name" in
if print then begin
let min = match min with
| None -> Some current
| Some x -> Some x
in
let max = Some current in
let values = values @ [name] in
(current + 1, min, max, values)
end
else begin
let n = match min with None -> [] | _ -> [name] in
(current + 1, min, max, values @ n)
end
) (0, None, None, []) modes in
(* Print if at least one mode has been found *)
match min, max with
| Some min_idx, Some max_idx ->
fprintf out_set " <dl_setting min=\"%d\" max=\"%d\" step=\"1\" var=\"autopilot_mode_%s\" shortname=\"%s\" values=\"%s\"/>\n"
min_idx max_idx name name (String.concat "|" values)
| _, _ -> ()
in
(* Iter and call print function *)
List.iter write_ap_mode sm_filtered;
fprintf out_set " </dl_settings>\n";
end;
fprintf out_set " </dl_settings>\n";
fprintf out_set "</settings>\n"
(** Main generation function
* Usage: main_freq xml_file_input h_dir_output
*)
let gen_autopilot main_freq xml_file h_dir =
let gen_autopilot main_freq xml_file h_dir out_set =
try
let ap_xml = Xml.parse_file xml_file in
let ap_name = ExtXml.attrib_or_default ap_xml "name" "Autopilot" in
let state_machines = get_state_machines ap_xml in
List.iter (parse_and_gen_modes xml_file ap_name main_freq h_dir) state_machines
List.iter (parse_and_gen_modes xml_file ap_name main_freq h_dir) state_machines;
write_settings xml_file out_set ap_xml
with
Xml.Error e -> fprintf stderr "%s: XML error:%s\n" xml_file (Xml.error e); exit 1
| Dtd.Prove_error e -> fprintf stderr "%s: DTD error:%s\n%!" xml_file (Dtd.prove_error e); exit 1
@@ -367,10 +423,11 @@ let gen_autopilot main_freq xml_file h_dir =
(* Main call *)
let () =
if Array.length Sys.argv <> 3 then
failwith (Printf.sprintf "Usage: %s airframe_xml_file out_h_dir" Sys.argv.(0));
if Array.length Sys.argv <> 4 then
failwith (Printf.sprintf "Usage: %s airframe_xml_file out_h_dir out_settings" Sys.argv.(0));
let xml_file = Sys.argv.(1)
and h_dir = Sys.argv.(2) in
and h_dir = Sys.argv.(2)
and out_set = open_out Sys.argv.(3) in
let (autopilot, ap_freq) = try
Gen_common.get_autopilot_of_airframe (Xml.parse_file xml_file)
with
@@ -381,7 +438,7 @@ let () =
| Not_found -> exit 0 (* No autopilot file found *)
in
try
gen_autopilot ap_freq autopilot h_dir;
()
gen_autopilot ap_freq autopilot h_dir out_set;
close_out out_set
with
_ -> fprintf stderr "gen_autopilot: What the heck? Something went wrong...\n"; exit 1