[autopilot] reorganize autopilot code

- better structure for the autopilot tasks
- convergence between firmwares
- remove unused int_enable functions
- update generators
This commit is contained in:
Gautier Hattenberger
2021-05-14 10:06:46 +02:00
parent fe8bbd3bb0
commit 9d06398c56
36 changed files with 381 additions and 636 deletions
+11 -6
View File
@@ -106,7 +106,7 @@ let target_conf_add_module = fun conf target firmware name mtype load_type ->
{ conf with modules = conf.modules @ [(Unloaded, m)] } end
(* topological sort to load modules and their dependencies *)
let resolve_modules_dep = fun config_by_target firmware fail ->
let resolve_modules_dep = fun config_by_target firmware user_target ->
let resolved = ref [] in (* modules to load (fully resolved) *)
let unresolved = ref [] in (* modules no fully resolved (for cycle detection) *)
let unloaded = ref [] in (* modules not loaded for this target / firmware *)
@@ -155,8 +155,6 @@ let resolve_modules_dep = fun config_by_target firmware fail ->
) m.Module.autoloads;
(* add conflicts to list *)
conflicts := !conflicts @ dep.Module.conflicts;
(* add required to list (if not present) *)
(*required := List.fold_left add_unique !required dep.Module.requires_func;*)
(* add provides to list (if not present) *)
provided := List.fold_left add_unique !provided dep.Module.provides;
(* all dep and autoload resolved, add to list *)
@@ -191,8 +189,15 @@ let resolve_modules_dep = fun config_by_target firmware fail ->
conflicts := [];
required := [];
provided := [];
(* check if a board, target or firmware specific module is available *)
let target_module_name = Env.paparazzi_conf // "modules" // "targets" // target ^ ".xml" in
let target_module = if Sys.file_exists target_module_name then [GC.Var target_module_name] else [] in
let firmware_module_name = Env.paparazzi_conf // "modules" // "firmwares" // conf.firmware_name ^ ".xml" in
let firmware_module = if Sys.file_exists firmware_module_name then [GC.Var firmware_module_name] else [] in
let board_module_name = Env.paparazzi_conf // "modules" // "boards" // conf.board_type ^ ".xml" in
let board_module = if Sys.file_exists board_module_name then [GC.Var board_module_name] else [] in
(* iter on modules of this target from a meta module *)
let root_dep = { Module.empty_dep with Module.requires = (List.map (fun (_, m) -> GC.Var m.Module.name) conf.modules) } in
let root_dep = { Module.empty_dep with Module.requires = (List.map (fun (_, m) -> GC.Var m.Module.name) conf.modules) @ target_module @ firmware_module @ board_module } in
let root_module = {
Module.empty with
Module.name = "root";
@@ -201,7 +206,7 @@ let resolve_modules_dep = fun config_by_target firmware fail ->
} in
dep_resolve root_module target UserLoad;
(* test for conflicts and required functionalities and option if requested *)
if fail then begin
if (not (user_target = "")) && (target = user_target) then begin
(* check conflicts for resolved modules *)
List.iter (fun c ->
List.iter (fun (name, _) ->
@@ -440,7 +445,7 @@ let parse_aircraft = fun ?(parse_af=false) ?(parse_ap=false) ?(parse_fp=false) ?
(* resolve modules dep *)
(* don't fail if no target specified, execpt for cyclic dependencies *)
resolve_modules_dep config_by_target firmware (not (target = ""));
resolve_modules_dep config_by_target firmware target;
let loaded_types, loaded_modules = get_loaded_modules config_by_target target in
let all_modules = get_all_modules config_by_target in
+25 -18
View File
@@ -144,7 +144,8 @@ type periodic = {
delay: float option;
start: string option;
stop: string option;
autorun: autorun
autorun: autorun;
cond: string option
}
let parse_periodic = fun xml ->
@@ -177,25 +178,28 @@ let parse_periodic = fun xml ->
end
in
{ call; fname; period_freq; delay = getf "delay";
start = get "start"; stop = get "stop";
start = get "start"; stop = get "stop"; cond = get "cond";
autorun = match get "autorun" with
| None -> Lock
| Some "TRUE" | Some "true" -> True
| Some "FALSE" | Some "false" -> False
| Some "LOCK" | Some "lock" -> Lock
| Some _ -> failwith "Module.parse_periodic: unreachable" }
| Some a -> failwith ("Module.parse_periodic: unknown autorun: " ^ a) }
type event = { ev: string; handlers: string list }
type init = { iname: string; cond: string option }
let make_event = fun f handlers ->
let make_init = fun f cond ->
{ iname = f;
cond = cond
}
type event = { ev: string; cond: string option }
let make_event = fun f cond ->
{ ev = f;
handlers = List.map
(function
| Xml.Element ("handler", _, []) as xml -> Xml.attrib xml "fun"
| _ -> failwith "Module.make_event: unreachable"
) handlers }
cond = cond
}
let fprint_event = fun ch e -> Printf.fprintf ch "%s;\n" e.ev
type datalink = { message: string; func: string }
@@ -261,7 +265,7 @@ type t = {
autoloads: autoload list;
settings: Settings.t list;
headers: file list;
inits: string list;
inits: init list;
periodics: periodic list;
events: event list;
datalinks: datalink list;
@@ -282,8 +286,8 @@ let rec parse_xml m = function
and dir = ExtXml.attrib_opt xml "dir"
and task = ExtXml.attrib_opt xml "task" in
List.fold_left parse_xml { m with name; dir; task; xml } children
| Xml.Element ("doc", _, _) as xml -> { m with doc = xml }
(*| Xml.Element ("settings_file", [("name", name)], files) -> m (* TODO : remove unused *)*)
| Xml.Element ("doc", _, _) as xml ->
{ m with doc = xml }
| Xml.Element ("settings", _, _) as xml ->
{ m with settings = Settings.from_xml xml :: m.settings }
| Xml.Element ("dep", _, _) as xml ->
@@ -297,12 +301,15 @@ let rec parse_xml m = function
List.fold_left (fun acc f -> parse_file f :: acc) m.headers files
}
| Xml.Element ("init", _, []) as xml ->
{ m with inits = Xml.attrib xml "fun" :: m.inits }
let f = Xml.attrib xml "fun"
and c = ExtXml.attrib_opt xml "cond" in
{ m with inits = make_init f c :: m.inits }
| Xml.Element ("periodic", _, []) as xml ->
{ m with periodics = parse_periodic xml :: m.periodics }
| Xml.Element ("event", _, handlers) as xml ->
let f = Xml.attrib xml "fun" in
{ m with events = make_event f handlers :: m.events }
| Xml.Element ("event", _, []) as xml ->
let f = Xml.attrib xml "fun"
and c = ExtXml.attrib_opt xml "cond" in
{ m with events = make_event f c :: m.events }
| Xml.Element ("datalink", _, []) as xml ->
let message = Xml.attrib xml "message"
and func = Xml.attrib xml "fun" in