mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-24 05:45:59 +08:00
cleanup trailing whitespaces in gen_* files
This commit is contained in:
+186
-186
@@ -41,35 +41,35 @@ let check_unique_id_and_name = fun conf ->
|
||||
let ids = Hashtbl.create 5
|
||||
and names = Hashtbl.create 5 in
|
||||
List.iter
|
||||
(fun x ->
|
||||
if String.lowercase (Xml.tag x) = "aircraft" then
|
||||
let id = ExtXml.attrib x "ac_id"
|
||||
and name = ExtXml.attrib x "name" in
|
||||
if Hashtbl.mem ids id then begin
|
||||
let other_name = Hashtbl.find ids id in
|
||||
failwith (sprintf "Error: A/C Id '%s' duplicated in %s (%s and %s)" id conf_xml name other_name)
|
||||
end;
|
||||
if Hashtbl.mem names name then begin
|
||||
let other_id = Hashtbl.find names name in
|
||||
failwith (sprintf "Error: A/C name '%s' duplicated in %s (ids %s and %s)" name conf_xml id other_id)
|
||||
end;
|
||||
Hashtbl.add ids id name;
|
||||
Hashtbl.add names name id)
|
||||
(Xml.children conf)
|
||||
(fun x ->
|
||||
if String.lowercase (Xml.tag x) = "aircraft" then
|
||||
let id = ExtXml.attrib x "ac_id"
|
||||
and name = ExtXml.attrib x "name" in
|
||||
if Hashtbl.mem ids id then begin
|
||||
let other_name = Hashtbl.find ids id in
|
||||
failwith (sprintf "Error: A/C Id '%s' duplicated in %s (%s and %s)" id conf_xml name other_name)
|
||||
end;
|
||||
if Hashtbl.mem names name then begin
|
||||
let other_id = Hashtbl.find names name in
|
||||
failwith (sprintf "Error: A/C name '%s' duplicated in %s (ids %s and %s)" name conf_xml id other_id)
|
||||
end;
|
||||
Hashtbl.add ids id name;
|
||||
Hashtbl.add names name id)
|
||||
(Xml.children conf)
|
||||
|
||||
|
||||
|
||||
let pipe_regexp = Str.regexp "|"
|
||||
let targets_of_field = fun field ->
|
||||
try
|
||||
Str.split pipe_regexp (ExtXml.attrib_or_default field "target" "ap|sim")
|
||||
Str.split pipe_regexp (ExtXml.attrib_or_default field "target" "ap|sim")
|
||||
with
|
||||
_ -> []
|
||||
_ -> []
|
||||
|
||||
(** singletonize a sorted list *)
|
||||
let rec singletonize = fun l ->
|
||||
match l with
|
||||
[] | [_] -> l
|
||||
[] | [_] -> l
|
||||
| x :: ((y :: t) as yt) -> if x = y then singletonize yt else x :: singletonize yt
|
||||
|
||||
(** union of two lists *)
|
||||
@@ -87,28 +87,28 @@ let union_of_lists = fun l ->
|
||||
let get_modules = fun dir xml ->
|
||||
(* extract all "modules" sections *)
|
||||
let modules = List.map (fun x ->
|
||||
match String.lowercase (Xml.tag x) with
|
||||
"modules" -> Xml.children x
|
||||
| _ -> []
|
||||
) (Xml.children xml) in
|
||||
match String.lowercase (Xml.tag x) with
|
||||
"modules" -> Xml.children x
|
||||
| _ -> []
|
||||
) (Xml.children xml) in
|
||||
(* flatten the list (result is a list of "load" xml nodes) *)
|
||||
let modules = List.flatten modules in
|
||||
(* build a list (file name, (xml, xml list of flags)) *)
|
||||
let extract = List.map (fun m ->
|
||||
match String.lowercase (Xml.tag m) with
|
||||
"load" -> let file = dir // ExtXml.attrib m "name" in
|
||||
(file, (ExtXml.parse_file file, Xml.children m))
|
||||
| tag -> failwith (sprintf "Warning: tag load is undefined; found '%s'" tag)
|
||||
) modules in
|
||||
match String.lowercase (Xml.tag m) with
|
||||
"load" -> let file = dir // ExtXml.attrib m "name" in
|
||||
(file, (ExtXml.parse_file file, Xml.children m))
|
||||
| tag -> failwith (sprintf "Warning: tag load is undefined; found '%s'" tag)
|
||||
) modules in
|
||||
(* return a list of name and a list of pairs (xml, xml list) *)
|
||||
List.split extract
|
||||
|
||||
(** [get_targets_of_module xml] Returns the list of targets of a module *)
|
||||
let get_targets_of_module = fun m ->
|
||||
let targets = List.map (fun x ->
|
||||
match String.lowercase (Xml.tag x) with
|
||||
"makefile" -> targets_of_field x
|
||||
| _ -> []
|
||||
match String.lowercase (Xml.tag x) with
|
||||
"makefile" -> targets_of_field x
|
||||
| _ -> []
|
||||
) (Xml.children m) in
|
||||
(* return a singletonized list *)
|
||||
singletonize (List.sort compare (List.flatten targets))
|
||||
@@ -120,8 +120,8 @@ let get_modules_dir = fun modules ->
|
||||
|
||||
(**
|
||||
Search and dump the module section :
|
||||
xml : the parsed airframe.xml
|
||||
f : makefile.ac
|
||||
xml : the parsed airframe.xml
|
||||
f : makefile.ac
|
||||
**)
|
||||
let dump_module_section = fun xml f ->
|
||||
(* get modules *)
|
||||
@@ -142,71 +142,71 @@ let dump_module_section = fun xml f ->
|
||||
List.iter (fun dir -> let dir_name = (String.uppercase dir)^"_DIR" in fprintf f "%s = modules/%s\n" dir_name dir) dir_list;
|
||||
(* parse each module *)
|
||||
List.iter (fun (m, flags) ->
|
||||
let name = ExtXml.attrib m "name" in
|
||||
let dir = try Xml.attrib m "dir" with _ -> name in
|
||||
let dir_name = (String.uppercase dir)^"_DIR" in
|
||||
(* get the list of all the targets for this module *)
|
||||
let module_target_list = get_targets_of_module m in
|
||||
(* print global flags as compilation defines and flags *)
|
||||
fprintf f "\n# makefile for module %s in modules/%s\n" name dir;
|
||||
List.iter (fun flag ->
|
||||
let name = ExtXml.attrib m "name" in
|
||||
let dir = try Xml.attrib m "dir" with _ -> name in
|
||||
let dir_name = (String.uppercase dir)^"_DIR" in
|
||||
(* get the list of all the targets for this module *)
|
||||
let module_target_list = get_targets_of_module m in
|
||||
(* print global flags as compilation defines and flags *)
|
||||
fprintf f "\n# makefile for module %s in modules/%s\n" name dir;
|
||||
List.iter (fun flag ->
|
||||
match String.lowercase (Xml.tag flag) with
|
||||
"define" ->
|
||||
let value = Xml.attrib flag "value"
|
||||
and name = Xml.attrib flag "name" in
|
||||
fprintf f "%s = %s\n" name value
|
||||
| "flag" | "param" ->
|
||||
List.iter (fun target ->
|
||||
let name = ExtXml.attrib flag "name"
|
||||
and value = try "="^(Xml.attrib flag "value") with _ -> "" in
|
||||
fprintf f "%s.CFLAGS += -D%s%s\n" target name value
|
||||
) module_target_list
|
||||
List.iter (fun target ->
|
||||
let name = ExtXml.attrib flag "name"
|
||||
and value = try "="^(Xml.attrib flag "value") with _ -> "" in
|
||||
fprintf f "%s.CFLAGS += -D%s%s\n" target name value
|
||||
) module_target_list
|
||||
| _ -> ()
|
||||
) flags;
|
||||
(* Look for makefile section *)
|
||||
List.iter (fun l ->
|
||||
if ExtXml.tag_is l "makefile" then begin
|
||||
let targets = targets_of_field l in
|
||||
(* Look for defines, flags, files, ... *)
|
||||
List.iter (fun field ->
|
||||
match String.lowercase (Xml.tag field) with
|
||||
"flag" ->
|
||||
List.iter (fun target ->
|
||||
let value = try "="^(Xml.attrib field "value") with _ -> ""
|
||||
and name = Xml.attrib field "name" in
|
||||
let flag_type = match (ExtXml.attrib_or_default field "type" "define") with
|
||||
"define" | "D" -> "D"
|
||||
| "include" | "I" -> "I"
|
||||
| _ -> "D" in
|
||||
fprintf f "%s.CFLAGS += -%s%s%s\n" target flag_type name value
|
||||
) targets
|
||||
| "file" ->
|
||||
let name = Xml.attrib field "name" in
|
||||
List.iter (fun target -> fprintf f "%s.srcs += $(%s)/%s\n" target dir_name name) targets
|
||||
| "file_arch" ->
|
||||
let name = Xml.attrib field "name" in
|
||||
List.iter (fun target -> fprintf f "%s.srcs += arch/$(ARCH)/$(%s)/%s\n" target dir_name name) targets
|
||||
| "file_hw" ->
|
||||
let name = Xml.attrib field "name" in
|
||||
List.iter (fun target -> fprintf f "%s.srcs += arch/$(ARCH)/$(%s)/%s\n" target dir_name name) targets
|
||||
| "define" ->
|
||||
let value = Xml.attrib field "value"
|
||||
and name = Xml.attrib field "name" in
|
||||
fprintf f "%s = %s\n" name value
|
||||
| "raw" ->
|
||||
begin match Xml.children field with
|
||||
[Xml.PCData s] -> fprintf f "%s\n" s
|
||||
| _ -> fprintf stderr "Warning: wrong makefile section in module '%s'\n" name
|
||||
end
|
||||
| _ -> ()
|
||||
) (Xml.children l)
|
||||
end) (Xml.children m)
|
||||
) modules;
|
||||
(* Look for makefile section *)
|
||||
List.iter (fun l ->
|
||||
if ExtXml.tag_is l "makefile" then begin
|
||||
let targets = targets_of_field l in
|
||||
(* Look for defines, flags, files, ... *)
|
||||
List.iter (fun field ->
|
||||
match String.lowercase (Xml.tag field) with
|
||||
"flag" ->
|
||||
List.iter (fun target ->
|
||||
let value = try "="^(Xml.attrib field "value") with _ -> ""
|
||||
and name = Xml.attrib field "name" in
|
||||
let flag_type = match (ExtXml.attrib_or_default field "type" "define") with
|
||||
"define" | "D" -> "D"
|
||||
| "include" | "I" -> "I"
|
||||
| _ -> "D" in
|
||||
fprintf f "%s.CFLAGS += -%s%s%s\n" target flag_type name value
|
||||
) targets
|
||||
| "file" ->
|
||||
let name = Xml.attrib field "name" in
|
||||
List.iter (fun target -> fprintf f "%s.srcs += $(%s)/%s\n" target dir_name name) targets
|
||||
| "file_arch" ->
|
||||
let name = Xml.attrib field "name" in
|
||||
List.iter (fun target -> fprintf f "%s.srcs += arch/$(ARCH)/$(%s)/%s\n" target dir_name name) targets
|
||||
| "file_hw" ->
|
||||
let name = Xml.attrib field "name" in
|
||||
List.iter (fun target -> fprintf f "%s.srcs += arch/$(ARCH)/$(%s)/%s\n" target dir_name name) targets
|
||||
| "define" ->
|
||||
let value = Xml.attrib field "value"
|
||||
and name = Xml.attrib field "name" in
|
||||
fprintf f "%s = %s\n" name value
|
||||
| "raw" ->
|
||||
begin match Xml.children field with
|
||||
[Xml.PCData s] -> fprintf f "%s\n" s
|
||||
| _ -> fprintf stderr "Warning: wrong makefile section in module '%s'\n" name
|
||||
end
|
||||
| _ -> ()
|
||||
) (Xml.children l)
|
||||
end) (Xml.children m)
|
||||
) modules;
|
||||
(** returns a list of modules file name *)
|
||||
files
|
||||
|
||||
(**
|
||||
Search and dump the makefile sections
|
||||
Search and dump the makefile sections
|
||||
**)
|
||||
let dump_makefile_section = fun xml makefile_ac airframe_infile location ->
|
||||
List.iter (fun x ->
|
||||
@@ -220,7 +220,7 @@ let dump_makefile_section = fun xml makefile_ac airframe_infile location ->
|
||||
| _ -> failwith (sprintf "Warning: wrong makefile section in '%s': %s\n" airframe_infile (Xml.to_string_fmt x))
|
||||
end
|
||||
| (_, _) -> ()
|
||||
end)
|
||||
end)
|
||||
(Xml.children xml)
|
||||
|
||||
(**
|
||||
@@ -326,10 +326,10 @@ let is_older = fun target_file dep_files ->
|
||||
not (Sys.file_exists target_file) ||
|
||||
let target_file_time = (U.stat target_file).U.st_mtime in
|
||||
let rec loop = function
|
||||
[] -> false
|
||||
| f::fs ->
|
||||
target_file_time < (U.stat f).U.st_mtime ||
|
||||
loop fs in
|
||||
[] -> false
|
||||
| f::fs ->
|
||||
target_file_time < (U.stat f).U.st_mtime ||
|
||||
loop fs in
|
||||
loop dep_files
|
||||
|
||||
|
||||
@@ -339,115 +339,115 @@ let make_element = fun t a c -> Xml.Element (t,a,c)
|
||||
(******************************* MAIN ****************************************)
|
||||
let () =
|
||||
try
|
||||
if Array.length Sys.argv <> 2 then
|
||||
failwith (sprintf "Usage: %s <A/C ident (conf.xml)>" Sys.argv.(0));
|
||||
let aircraft = Sys.argv.(1) in
|
||||
let conf = Xml.parse_file conf_xml in
|
||||
check_unique_id_and_name conf;
|
||||
let aircraft_xml =
|
||||
try
|
||||
ExtXml.child conf ~select:(fun x -> Xml.attrib x "name" = aircraft) "aircraft"
|
||||
with
|
||||
Not_found -> failwith (sprintf "Aircraft '%s' not found in '%s'" aircraft conf_xml)
|
||||
in
|
||||
if Array.length Sys.argv <> 2 then
|
||||
failwith (sprintf "Usage: %s <A/C ident (conf.xml)>" Sys.argv.(0));
|
||||
let aircraft = Sys.argv.(1) in
|
||||
let conf = Xml.parse_file conf_xml in
|
||||
check_unique_id_and_name conf;
|
||||
let aircraft_xml =
|
||||
try
|
||||
ExtXml.child conf ~select:(fun x -> Xml.attrib x "name" = aircraft) "aircraft"
|
||||
with
|
||||
Not_found -> failwith (sprintf "Aircraft '%s' not found in '%s'" aircraft conf_xml)
|
||||
in
|
||||
|
||||
let value = fun attrib -> ExtXml.attrib aircraft_xml attrib in
|
||||
let value = fun attrib -> ExtXml.attrib aircraft_xml attrib in
|
||||
|
||||
let aircraft_dir = Env.paparazzi_home // "var" // aircraft in
|
||||
let aircraft_conf_dir = aircraft_dir // "conf" in
|
||||
let aircraft_dir = Env.paparazzi_home // "var" // aircraft in
|
||||
let aircraft_conf_dir = aircraft_dir // "conf" in
|
||||
|
||||
mkdir (Env.paparazzi_home // "var");
|
||||
mkdir aircraft_dir;
|
||||
mkdir (aircraft_dir // "fbw");
|
||||
mkdir (aircraft_dir // "autopilot");
|
||||
mkdir (aircraft_dir // "sim");
|
||||
mkdir aircraft_conf_dir;
|
||||
mkdir (aircraft_conf_dir // "airframes");
|
||||
mkdir (aircraft_conf_dir // "flight_plans");
|
||||
mkdir (aircraft_conf_dir // "radios");
|
||||
mkdir (aircraft_conf_dir // "settings");
|
||||
mkdir (aircraft_conf_dir // "telemetry");
|
||||
mkdir (Env.paparazzi_home // "var");
|
||||
mkdir aircraft_dir;
|
||||
mkdir (aircraft_dir // "fbw");
|
||||
mkdir (aircraft_dir // "autopilot");
|
||||
mkdir (aircraft_dir // "sim");
|
||||
mkdir aircraft_conf_dir;
|
||||
mkdir (aircraft_conf_dir // "airframes");
|
||||
mkdir (aircraft_conf_dir // "flight_plans");
|
||||
mkdir (aircraft_conf_dir // "radios");
|
||||
mkdir (aircraft_conf_dir // "settings");
|
||||
mkdir (aircraft_conf_dir // "telemetry");
|
||||
|
||||
let settings =
|
||||
try value "settings" with
|
||||
_ ->
|
||||
fprintf stderr "\nWARNING: No 'settings' attribute specified for A/C '%s', using 'settings/basic.xml'\n\n%!" aircraft;
|
||||
"settings/basic.xml" in
|
||||
let settings =
|
||||
try value "settings" with
|
||||
_ ->
|
||||
fprintf stderr "\nWARNING: No 'settings' attribute specified for A/C '%s', using 'settings/basic.xml'\n\n%!" aircraft;
|
||||
"settings/basic.xml" in
|
||||
|
||||
(** Expands the configuration of the A/C into one single file *)
|
||||
let conf_aircraft = Env.expand_ac_xml aircraft_xml in
|
||||
let configuration =
|
||||
make_element
|
||||
"configuration"
|
||||
[]
|
||||
[make_element "conf" [] [conf_aircraft]; Pprz.messages_xml ()] in
|
||||
let conf_aircraft_file = aircraft_conf_dir // "conf_aircraft.xml" in
|
||||
let f = open_out conf_aircraft_file in
|
||||
Printf.fprintf f "%s\n" (ExtXml.to_string_fmt configuration);
|
||||
close_out f;
|
||||
(** Expands the configuration of the A/C into one single file *)
|
||||
let conf_aircraft = Env.expand_ac_xml aircraft_xml in
|
||||
let configuration =
|
||||
make_element
|
||||
"configuration"
|
||||
[]
|
||||
[make_element "conf" [] [conf_aircraft]; Pprz.messages_xml ()] in
|
||||
let conf_aircraft_file = aircraft_conf_dir // "conf_aircraft.xml" in
|
||||
let f = open_out conf_aircraft_file in
|
||||
Printf.fprintf f "%s\n" (ExtXml.to_string_fmt configuration);
|
||||
close_out f;
|
||||
|
||||
(** Computes and store a signature of the configuration *)
|
||||
let md5sum = Digest.to_hex (Digest.file conf_aircraft_file) in
|
||||
let md5sum_file = aircraft_conf_dir // "aircraft.md5" in
|
||||
(* Store only if different from previous one *)
|
||||
if not (Sys.file_exists md5sum_file
|
||||
&& md5sum = input_line (open_in md5sum_file)) then begin
|
||||
let f = open_out md5sum_file in
|
||||
Printf.fprintf f "%s\n" md5sum;
|
||||
close_out f;
|
||||
(** Computes and store a signature of the configuration *)
|
||||
let md5sum = Digest.to_hex (Digest.file conf_aircraft_file) in
|
||||
let md5sum_file = aircraft_conf_dir // "aircraft.md5" in
|
||||
(* Store only if different from previous one *)
|
||||
if not (Sys.file_exists md5sum_file
|
||||
&& md5sum = input_line (open_in md5sum_file)) then begin
|
||||
let f = open_out md5sum_file in
|
||||
Printf.fprintf f "%s\n" md5sum;
|
||||
close_out f;
|
||||
|
||||
(** Save the configuration for future use *)
|
||||
let d = U.localtime (U.gettimeofday ()) in
|
||||
let filename = sprintf "%02d_%02d_%02d__%02d_%02d_%02d_%s_%s.conf" (d.U.tm_year mod 100) (d.U.tm_mon+1) (d.U.tm_mday) (d.U.tm_hour) (d.U.tm_min) (d.U.tm_sec) md5sum aircraft in
|
||||
let d = Env.paparazzi_home // "var" // "conf" in
|
||||
mkdir d;
|
||||
let f = open_out (d // filename) in
|
||||
Printf.fprintf f "%s\n" (ExtXml.to_string_fmt configuration);
|
||||
close_out f end;
|
||||
(** Save the configuration for future use *)
|
||||
let d = U.localtime (U.gettimeofday ()) in
|
||||
let filename = sprintf "%02d_%02d_%02d__%02d_%02d_%02d_%s_%s.conf" (d.U.tm_year mod 100) (d.U.tm_mon+1) (d.U.tm_mday) (d.U.tm_hour) (d.U.tm_min) (d.U.tm_sec) md5sum aircraft in
|
||||
let d = Env.paparazzi_home // "var" // "conf" in
|
||||
mkdir d;
|
||||
let f = open_out (d // filename) in
|
||||
Printf.fprintf f "%s\n" (ExtXml.to_string_fmt configuration);
|
||||
close_out f end;
|
||||
|
||||
let airframe_file = value "airframe" in
|
||||
let airframe_file = value "airframe" in
|
||||
|
||||
let airframe_dir = Filename.dirname airframe_file in
|
||||
let var_airframe_dir = aircraft_conf_dir // airframe_dir in
|
||||
mkdir var_airframe_dir;
|
||||
assert (Sys.command (sprintf "cp %s %s" (paparazzi_conf // airframe_file) var_airframe_dir) = 0);
|
||||
let airframe_dir = Filename.dirname airframe_file in
|
||||
let var_airframe_dir = aircraft_conf_dir // airframe_dir in
|
||||
mkdir var_airframe_dir;
|
||||
assert (Sys.command (sprintf "cp %s %s" (paparazzi_conf // airframe_file) var_airframe_dir) = 0);
|
||||
|
||||
(** Calls the Makefile with target and options *)
|
||||
let make = fun target options ->
|
||||
let c = sprintf "make -f Makefile.ac AIRCRAFT=%s AC_ID=%s AIRFRAME_XML=%s TELEMETRY=%s SETTINGS=\"%s\" MD5SUM=\"%s\" %s %s" aircraft (value "ac_id") airframe_file (value "telemetry") settings md5sum options target in
|
||||
begin (** Quiet is speficied in the Makefile *)
|
||||
try if Sys.getenv "Q" <> "@" then raise Not_found with
|
||||
Not_found -> prerr_endline c
|
||||
end;
|
||||
let returned_code = Sys.command c in
|
||||
if returned_code <> 0 then
|
||||
exit returned_code in
|
||||
(** Calls the Makefile with target and options *)
|
||||
let make = fun target options ->
|
||||
let c = sprintf "make -f Makefile.ac AIRCRAFT=%s AC_ID=%s AIRFRAME_XML=%s TELEMETRY=%s SETTINGS=\"%s\" MD5SUM=\"%s\" %s %s" aircraft (value "ac_id") airframe_file (value "telemetry") settings md5sum options target in
|
||||
begin (** Quiet is speficied in the Makefile *)
|
||||
try if Sys.getenv "Q" <> "@" then raise Not_found with
|
||||
Not_found -> prerr_endline c
|
||||
end;
|
||||
let returned_code = Sys.command c in
|
||||
if returned_code <> 0 then
|
||||
exit returned_code in
|
||||
|
||||
(** Calls the makefile if the optional attribute is available *)
|
||||
let make_opt = fun target var attr ->
|
||||
try
|
||||
let value = Xml.attrib aircraft_xml attr in
|
||||
make target (sprintf "%s=%s" var value)
|
||||
with
|
||||
Xml.No_attribute _ -> () in
|
||||
(** Calls the makefile if the optional attribute is available *)
|
||||
let make_opt = fun target var attr ->
|
||||
try
|
||||
let value = Xml.attrib aircraft_xml attr in
|
||||
make target (sprintf "%s=%s" var value)
|
||||
with
|
||||
Xml.No_attribute _ -> () in
|
||||
|
||||
let temp_makefile_ac = Filename.temp_file "Makefile.ac" "tmp" in
|
||||
let abs_airframe_file = paparazzi_conf // airframe_file in
|
||||
let temp_makefile_ac = Filename.temp_file "Makefile.ac" "tmp" in
|
||||
let abs_airframe_file = paparazzi_conf // airframe_file in
|
||||
|
||||
let modules_files = extract_makefile abs_airframe_file temp_makefile_ac in
|
||||
let modules_files = extract_makefile abs_airframe_file temp_makefile_ac in
|
||||
|
||||
(* Create Makefile.ac only if needed *)
|
||||
let makefile_ac = aircraft_dir // "Makefile.ac" in
|
||||
if is_older makefile_ac (abs_airframe_file :: modules_files) then begin
|
||||
assert(Sys.command (sprintf "mv %s %s" temp_makefile_ac makefile_ac) = 0)
|
||||
end;
|
||||
(* Create Makefile.ac only if needed *)
|
||||
let makefile_ac = aircraft_dir // "Makefile.ac" in
|
||||
if is_older makefile_ac (abs_airframe_file :: modules_files) then begin
|
||||
assert(Sys.command (sprintf "mv %s %s" temp_makefile_ac makefile_ac) = 0)
|
||||
end;
|
||||
|
||||
(* Get TARGET env, needed to build modules.h according to the target *)
|
||||
let t = Printf.sprintf "TARGET=%s" (try Sys.getenv "TARGET" with _ -> "") in
|
||||
make "all_ac_h" t;
|
||||
make_opt "radio_ac_h" "RADIO" "radio";
|
||||
make_opt "flight_plan_ac_h" "FLIGHT_PLAN" "flight_plan"
|
||||
(* Get TARGET env, needed to build modules.h according to the target *)
|
||||
let t = Printf.sprintf "TARGET=%s" (try Sys.getenv "TARGET" with _ -> "") in
|
||||
make "all_ac_h" t;
|
||||
make_opt "radio_ac_h" "RADIO" "radio";
|
||||
make_opt "flight_plan_ac_h" "FLIGHT_PLAN" "flight_plan"
|
||||
with
|
||||
Failure f ->
|
||||
prerr_endline f;
|
||||
exit 1
|
||||
Failure f ->
|
||||
prerr_endline f;
|
||||
exit 1
|
||||
|
||||
+18
-18
@@ -2,7 +2,7 @@
|
||||
* $Id$
|
||||
*
|
||||
* XML preprocessing for airframe parameters
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2003-2006 Pascal Brisset, Antoine Drouin
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
@@ -20,7 +20,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*)
|
||||
|
||||
@@ -59,7 +59,7 @@ let define_macro name n x =
|
||||
| 2 -> printf "x1,x2) (%s*(x1)+ %s*(x2))\n" (a "coeff1") (a "coeff2")
|
||||
| 3 -> printf "x1,x2,x3) (%s*(x1)+ %s*(x2)+%s*(x3))\n" (a "coeff1") (a "coeff2") (a "coeff3")
|
||||
| _ -> failwith "define_macro"
|
||||
|
||||
|
||||
let define_integer name v n =
|
||||
let max_val = 1 lsl n in
|
||||
let print = fun name num den ->
|
||||
@@ -84,11 +84,11 @@ let define_integer name v n =
|
||||
let parse_element = fun prefix s ->
|
||||
match Xml.tag s with
|
||||
"define" -> begin
|
||||
try
|
||||
define (prefix^ExtXml.attrib s "name") (ExtXml.display_entities (ExtXml.attrib s "value"));
|
||||
define_integer (prefix^(ExtXml.attrib s "name")) (ExtXml.float_attrib s "value") (ExtXml.int_attrib s "integer");
|
||||
with _ -> ();
|
||||
end
|
||||
try
|
||||
define (prefix^ExtXml.attrib s "name") (ExtXml.display_entities (ExtXml.attrib s "value"));
|
||||
define_integer (prefix^(ExtXml.attrib s "name")) (ExtXml.float_attrib s "value") (ExtXml.int_attrib s "integer");
|
||||
with _ -> ();
|
||||
end
|
||||
| "linear" ->
|
||||
let name = ExtXml.attrib s "name"
|
||||
and n = int_of_string (ExtXml.attrib s "arity") in
|
||||
@@ -107,7 +107,7 @@ let parse_servo = fun driver c ->
|
||||
let min = fos (ExtXml.attrib c "min" )
|
||||
and neutral = fos (ExtXml.attrib c "neutral")
|
||||
and max = fos (ExtXml.attrib c "max" ) in
|
||||
|
||||
|
||||
let travel_up = (max-.neutral) /. max_pprz
|
||||
and travel_down = (neutral-.min) /. max_pprz in
|
||||
|
||||
@@ -153,7 +153,7 @@ let parse_command_laws = fun command ->
|
||||
let var = a "var"
|
||||
and value = a "value" in
|
||||
let v = preprocess_value value "values" "COMMAND" in
|
||||
printf " int16_t _var_%s = %s;\\\n" var v
|
||||
printf " int16_t _var_%s = %s;\\\n" var v
|
||||
| "define" ->
|
||||
parse_element "" command
|
||||
| _ -> xml_error "set|let"
|
||||
@@ -162,7 +162,7 @@ let parse_csc_fields = fun csc_fields ->
|
||||
let a = fun s -> ExtXml.attrib csc_fields s in
|
||||
match Xml.tag csc_fields with
|
||||
"field_map" ->
|
||||
let servo_id = a "servo_id"
|
||||
let servo_id = a "servo_id"
|
||||
and field = a "field" in
|
||||
printf " temp.%s = actuators[%s]; \\\n" field servo_id;
|
||||
| _ -> xml_error "field_map"
|
||||
@@ -171,8 +171,8 @@ let parse_csc_messages = (let msg_index_ref = ref 0 in fun csc_id csc_messages -
|
||||
let a = fun s -> ExtXml.attrib csc_messages s in
|
||||
match Xml.tag csc_messages with
|
||||
"msg" ->
|
||||
let msg_id = a "id"
|
||||
and msg_type = a "type"
|
||||
let msg_id = a "id"
|
||||
and msg_type = a "type"
|
||||
and msg_index = msg_index_ref.contents in
|
||||
msg_index_ref.contents <- msg_index + 1;
|
||||
printf "{\\\n struct Csc%s temp; \\\n" msg_type;
|
||||
@@ -204,7 +204,7 @@ let parse_rc_commands = fun rc ->
|
||||
let var = a "var"
|
||||
and value = a "value" in
|
||||
let v = preprocess_value value "rc_values" "RADIO" in
|
||||
printf " int16_t _var_%s = %s;\\\n" var v
|
||||
printf " int16_t _var_%s = %s;\\\n" var v
|
||||
| "define" ->
|
||||
parse_element "" rc
|
||||
| _ -> xml_error "set|let"
|
||||
@@ -221,7 +221,7 @@ let parse_ap_only_commands = fun ap_only ->
|
||||
let parse_subsystem_defines = fun options ->
|
||||
match Xml.tag options with
|
||||
"param" ->
|
||||
printf "// -param: %s\n" (ExtXml.attrib options "name")
|
||||
printf "// -param: %s\n" (ExtXml.attrib options "name")
|
||||
| "define" ->
|
||||
printf "#define %s %s\n" (ExtXml.attrib options "name") (ExtXml.attrib options "value")
|
||||
| _ -> xml_error "define|param"
|
||||
@@ -230,7 +230,7 @@ let parse_subsystem_defines = fun options ->
|
||||
let parse_subsystems = fun subsystem ->
|
||||
match Xml.tag subsystem with
|
||||
"param" ->
|
||||
printf "// subsystem parameter: %s\n" (ExtXml.attrib subsystem "name")
|
||||
printf "// subsystem parameter: %s\n" (ExtXml.attrib subsystem "name")
|
||||
| "subsystem" ->
|
||||
printf "// -%s:\n" (ExtXml.attrib subsystem "name");
|
||||
List.iter parse_subsystem_defines (Xml.children subsystem)
|
||||
@@ -307,7 +307,7 @@ let rec parse_section = fun s ->
|
||||
()
|
||||
(** Ignoring this section *)
|
||||
| _ -> ()
|
||||
|
||||
|
||||
|
||||
let h_name = "AIRFRAME_H"
|
||||
|
||||
@@ -319,7 +319,7 @@ let hex_to_bin = fun s ->
|
||||
b.[4*i] <- '\\';
|
||||
Scanf.sscanf (String.sub s (2*i) 2) "%2x"
|
||||
(fun x ->
|
||||
String.blit (sprintf "%03o" x) 0 b (4*i+1) 3)
|
||||
String.blit (sprintf "%03o" x) 0 b (4*i+1) 3)
|
||||
done;
|
||||
b
|
||||
|
||||
|
||||
+283
-284
File diff suppressed because it is too large
Load Diff
+11
-11
@@ -2,7 +2,7 @@
|
||||
* $Id$
|
||||
*
|
||||
* XML preprocessing for modules
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2009 Gautier Hattenberger
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
@@ -20,7 +20,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*)
|
||||
|
||||
@@ -102,7 +102,7 @@ let remove_dup = fun l ->
|
||||
match l with
|
||||
[] | [_] -> l
|
||||
| x::((x'::_) as xs) ->
|
||||
if x = x' then loop xs else x::loop xs in
|
||||
if x = x' then loop xs else x::loop xs in
|
||||
loop (List.sort compare l)
|
||||
|
||||
let print_periodic_functions = fun modules ->
|
||||
@@ -117,7 +117,7 @@ let print_periodic_functions = fun modules ->
|
||||
let functions_modulo = List.flatten (List.map (fun m ->
|
||||
let periodic = List.filter (fun i -> (String.compare (Xml.tag i) "periodic") == 0) (Xml.children m) in
|
||||
let module_name = ExtXml.attrib m "name" in
|
||||
List.map (fun x ->
|
||||
List.map (fun x ->
|
||||
try
|
||||
let p = float_of_string (Xml.attrib x "period") in
|
||||
let _ = try let _ = Xml.attrib x "freq" in fprintf stderr "Warning: both period and freq are defined but only period is used for function %s\n" (ExtXml.attrib x "fun") with _ -> () in
|
||||
@@ -178,7 +178,7 @@ let print_periodic_functions = fun modules ->
|
||||
lprintf out_h "}\n";
|
||||
end
|
||||
end
|
||||
else
|
||||
else
|
||||
begin
|
||||
if (test_delay func) then begin
|
||||
(** Delay is set by user *)
|
||||
@@ -267,16 +267,16 @@ let get_modules = fun dir m ->
|
||||
let name = ExtXml.attrib m "name" in
|
||||
let xml = Xml.parse_file (dir^name) in
|
||||
xml
|
||||
end
|
||||
end
|
||||
| _ -> xml_error "load"
|
||||
|
||||
let test_section_modules = fun xml ->
|
||||
List.fold_right (fun x r -> ExtXml.tag_is x "modules" || r) (Xml.children xml) false
|
||||
List.fold_right (fun x r -> ExtXml.tag_is x "modules" || r) (Xml.children xml) false
|
||||
|
||||
(** Check dependencies *)
|
||||
let pipe_regexp = Str.regexp "|"
|
||||
let dep_of_field = fun field att ->
|
||||
try
|
||||
try
|
||||
Str.split pipe_regexp (Xml.attrib field att)
|
||||
with
|
||||
_ -> []
|
||||
@@ -310,7 +310,7 @@ let write_settings = fun xml_file out_set modules ->
|
||||
match Xml.tag i with
|
||||
"periodic" ->
|
||||
if not (is_status_lock i) then begin
|
||||
if (not !setting_exist) then begin
|
||||
if (not !setting_exist) then begin
|
||||
fprintf out_set " <dl_settings name=\"Modules\">\n";
|
||||
setting_exist := true;
|
||||
end;
|
||||
@@ -326,7 +326,7 @@ let write_settings = fun xml_file out_set modules ->
|
||||
|
||||
let get_targets_of_module = fun m ->
|
||||
let pipe_regexp = Str.regexp "|" in
|
||||
let targets_of_field = fun field -> try
|
||||
let targets_of_field = fun field -> try
|
||||
Str.split pipe_regexp (ExtXml.attrib_or_default field "target" "ap|sim") with _ -> [] in
|
||||
let rec singletonize = fun l ->
|
||||
match l with
|
||||
@@ -380,7 +380,7 @@ let () =
|
||||
freq := main_freq;
|
||||
let modules_list = List.map (get_modules modules_dir) (Xml.children modules) in
|
||||
let modules_list = unload_unused_modules modules_list in
|
||||
let modules_name =
|
||||
let modules_name =
|
||||
(List.map (fun l -> try Xml.attrib l "name" with _ -> "") (Xml.children modules)) @
|
||||
(List.map (fun m -> try Xml.attrib m "name" with _ -> "") modules_list) in
|
||||
check_dependencies modules_list modules_name;
|
||||
|
||||
+33
-33
@@ -2,7 +2,7 @@
|
||||
* $Id$
|
||||
*
|
||||
* XML preprocessing for dynamic tuning
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2006 Pascal Brisset, Antoine Drouin
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
@@ -20,7 +20,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*)
|
||||
|
||||
@@ -44,50 +44,50 @@ let rec flatten = fun xml r ->
|
||||
match Xml.children xml with
|
||||
[] -> r
|
||||
| x::xs ->
|
||||
List.iter (fun y -> assert(ExtXml.tag_is y (Xml.tag x))) xs;
|
||||
List.fold_right flatten (x::xs) r
|
||||
List.iter (fun y -> assert(ExtXml.tag_is y (Xml.tag x))) xs;
|
||||
List.fold_right flatten (x::xs) r
|
||||
|
||||
|
||||
module StringSet = Set.Make(struct type t = string let compare = compare end)
|
||||
|
||||
|
||||
|
||||
let print_dl_settings = fun settings ->
|
||||
let settings = flatten settings [] in
|
||||
|
||||
(** include headers **)
|
||||
let modules = ref StringSet.empty in
|
||||
List.iter
|
||||
List.iter
|
||||
(fun s ->
|
||||
try
|
||||
modules := StringSet.add (ExtXml.attrib s "module") !modules
|
||||
modules := StringSet.add (ExtXml.attrib s "module") !modules
|
||||
with ExtXml.Error e -> ()
|
||||
)
|
||||
)
|
||||
settings;
|
||||
|
||||
lprintf "\n";
|
||||
StringSet.iter (fun m -> lprintf "#include \"%s.h\"\n" m) !modules;
|
||||
lprintf "#include \"modules.h\"\n";
|
||||
lprintf "\n";
|
||||
|
||||
|
||||
(** Macro to call to set one variable *)
|
||||
lprintf "#define DlSetting(_idx, _value) { \\\n";
|
||||
right ();
|
||||
lprintf "switch (_idx) { \\\n";
|
||||
right ();
|
||||
let idx = ref 0 in
|
||||
List.iter
|
||||
List.iter
|
||||
(fun s ->
|
||||
let v = ExtXml.attrib s "var" in
|
||||
begin
|
||||
try
|
||||
let h = ExtXml.attrib s "handler" and
|
||||
m = ExtXml.attrib s "module" in
|
||||
lprintf "case %d: %s_%s( _value ); _value = %s; break;\\\n" !idx (Filename.basename m) h v
|
||||
with
|
||||
ExtXml.Error e -> lprintf "case %d: %s = _value; break;\\\n" !idx v
|
||||
end;
|
||||
incr idx
|
||||
)
|
||||
begin
|
||||
try
|
||||
let h = ExtXml.attrib s "handler" and
|
||||
m = ExtXml.attrib s "module" in
|
||||
lprintf "case %d: %s_%s( _value ); _value = %s; break;\\\n" !idx (Filename.basename m) h v
|
||||
with
|
||||
ExtXml.Error e -> lprintf "case %d: %s = _value; break;\\\n" !idx v
|
||||
end;
|
||||
incr idx
|
||||
)
|
||||
settings;
|
||||
lprintf "default: break;\\\n";
|
||||
left ();
|
||||
@@ -106,10 +106,10 @@ let print_dl_settings = fun settings ->
|
||||
let idx = ref 0 in
|
||||
lprintf "switch (i) { \\\n";
|
||||
right ();
|
||||
List.iter
|
||||
List.iter
|
||||
(fun s ->
|
||||
let v = ExtXml.attrib s "var" in
|
||||
lprintf "case %d: var = %s; break;\\\n" !idx v; incr idx)
|
||||
let v = ExtXml.attrib s "var" in
|
||||
lprintf "case %d: var = %s; break;\\\n" !idx v; incr idx)
|
||||
settings;
|
||||
lprintf "default: var = 0.; break;\\\n";
|
||||
left ();
|
||||
@@ -126,16 +126,16 @@ let print_dl_settings = fun settings ->
|
||||
let idx = ref 0 in
|
||||
lprintf "switch (i) { \\\n";
|
||||
right ();
|
||||
List.iter
|
||||
List.iter
|
||||
(fun s ->
|
||||
let v = ExtXml.attrib s "var" in
|
||||
lprintf "case %d: return %s;\n" !idx v; incr idx)
|
||||
lprintf "case %d: return %s;\n" !idx v; incr idx)
|
||||
settings;
|
||||
lprintf "default: return 0.;\n";
|
||||
lprintf "}\n";
|
||||
left ();
|
||||
lprintf "}\n"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -190,12 +190,12 @@ let join_xml_files = fun xml_files ->
|
||||
and rc_settings = ref [] in
|
||||
List.iter (fun xml_file ->
|
||||
let xml = Xml.parse_file xml_file in
|
||||
let these_rc_settings =
|
||||
let these_rc_settings =
|
||||
try Xml.children (ExtXml.child xml "rc_settings") with
|
||||
Not_found -> [] in
|
||||
let these_dl_settings =
|
||||
try Xml.children (ExtXml.child xml "dl_settings") with
|
||||
Not_found -> [] in
|
||||
Not_found -> [] in
|
||||
let these_dl_settings =
|
||||
try Xml.children (ExtXml.child xml "dl_settings") with
|
||||
Not_found -> [] in
|
||||
rc_settings := these_rc_settings @ !rc_settings;
|
||||
dl_settings := these_dl_settings @ !dl_settings)
|
||||
xml_files;
|
||||
@@ -211,11 +211,11 @@ let _ =
|
||||
for i = 2 to Array.length Sys.argv - 1 do
|
||||
xml_files := Sys.argv.(i) :: !xml_files;
|
||||
done;
|
||||
|
||||
|
||||
try
|
||||
printf "/* This file has been generated from %s */\n" (String.concat " " !xml_files);
|
||||
printf "/* Please DO NOT EDIT */\n\n";
|
||||
|
||||
|
||||
printf "#ifndef %s\n" h_name;
|
||||
define h_name "";
|
||||
nl ();
|
||||
|
||||
Reference in New Issue
Block a user